diff --git a/charmap.txt b/charmap.txt index 220ff2ed5..219897711 100644 --- a/charmap.txt +++ b/charmap.txt @@ -367,7 +367,7 @@ B_ATK_PARTNER_NAME = FD 0E B_ATK_NAME_WITH_PREFIX = FD 0F B_DEF_NAME_WITH_PREFIX = FD 10 B_EFF_NAME_WITH_PREFIX = FD 11 @ EFF = short for gEffectBattler -B_ACTIVE_NAME_WITH_PREFIX = FD 12 +@ FD 12 - preiously gActiveBattler with prefix B_SCR_ACTIVE_NAME_WITH_PREFIX = FD 13 B_CURRENT_MOVE = FD 14 B_LAST_MOVE = FD 15 @@ -409,8 +409,8 @@ B_ATK_TEAM2 = FD 38 B_DEF_NAME = FD 39 B_DEF_TEAM1 = FD 3A B_DEF_TEAM2 = FD 3B -B_ACTIVE_NAME = FD 3C -B_ACTIVE_NAME2 = FD 3D @ no Illusion check +@ FD 3C - preiously gActiveBattler +@ FD 3D - preiously gActiveBattler without Illusion Check @ indicates the end of a town/city name (before " TOWN" or " CITY") NAME_END = FC 00 diff --git a/data/battle_scripts_2.s b/data/battle_scripts_2.s index 0c6c133b5..5b0827ade 100644 --- a/data/battle_scripts_2.s +++ b/data/battle_scripts_2.s @@ -112,6 +112,7 @@ BattleScript_ItemSetFocusEnergy:: setfocusenergy playmoveanimation BS_ATTACKER, MOVE_FOCUS_ENERGY waitanimation + copybyte sBATTLER, gBattlerAttacker printstring STRINGID_PKMNUSEDXTOGETPUMPED waitmessage B_WAIT_TIME_LONG end diff --git a/graphics/battle_anims/sprites/monster_doll.png b/graphics/battle_anims/sprites/monster_doll.png index 55706275c..7cac68e10 100644 Binary files a/graphics/battle_anims/sprites/monster_doll.png and b/graphics/battle_anims/sprites/monster_doll.png differ diff --git a/graphics/battle_anims/sprites/substitute.png b/graphics/battle_anims/sprites/substitute.png index 0b6dea850..d4835d86a 100644 Binary files a/graphics/battle_anims/sprites/substitute.png and b/graphics/battle_anims/sprites/substitute.png differ diff --git a/graphics/battle_anims/sprites/substitute_back.png b/graphics/battle_anims/sprites/substitute_back.png index 8ea1f7ff8..47c46d0f8 100644 Binary files a/graphics/battle_anims/sprites/substitute_back.png and b/graphics/battle_anims/sprites/substitute_back.png differ diff --git a/graphics/battle_anims/sprites/substitute_back_new.png b/graphics/battle_anims/sprites/substitute_back_new.png deleted file mode 100644 index fd31e1063..000000000 Binary files a/graphics/battle_anims/sprites/substitute_back_new.png and /dev/null differ diff --git a/graphics/battle_anims/sprites/substitute_new.png b/graphics/battle_anims/sprites/substitute_new.png deleted file mode 100644 index 5d563900c..000000000 Binary files a/graphics/battle_anims/sprites/substitute_new.png and /dev/null differ diff --git a/include/battle.h b/include/battle.h index db29ab50d..f65c816ba 100644 --- a/include/battle.h +++ b/include/battle.h @@ -353,6 +353,7 @@ struct BattleResources struct BattleHistory *battleHistory; u8 bufferA[MAX_BATTLERS_COUNT][0x200]; u8 bufferB[MAX_BATTLERS_COUNT][0x200]; + u8 transferBuffer[0x100]; }; #define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)(gBattleResources->ai)) @@ -925,7 +926,6 @@ extern u8 gBattleTerrain; extern u32 gUnusedFirstBattleVar1; extern u8 *gBattleAnimBgTileBuffer; extern u8 *gBattleAnimBgTilemapBuffer; -extern u8 gActiveBattler; extern u32 gBattleControllerExecFlags; extern u8 gBattlersCount; extern u16 gBattlerPartyIndexes[MAX_BATTLERS_COUNT]; diff --git a/include/battle_ai_main.h b/include/battle_ai_main.h index 1d53a3f39..6e35c04a2 100644 --- a/include/battle_ai_main.h +++ b/include/battle_ai_main.h @@ -22,7 +22,7 @@ u8 ComputeBattleAiScores(u8 battler); void BattleAI_SetupItems(void); void BattleAI_SetupFlags(void); -void BattleAI_SetupAIData(u8 defaultScoreMoves); +void BattleAI_SetupAIData(u8 defaultScoreMoves, u32 battler); u8 BattleAI_ChooseMoveOrAction(void); void Ai_InitPartyStruct(void); void Ai_UpdateSwitchInData(u32 battler); diff --git a/include/battle_ai_switch_items.h b/include/battle_ai_switch_items.h index 622593b6d..9a7e5f7e7 100644 --- a/include/battle_ai_switch_items.h +++ b/include/battle_ai_switch_items.h @@ -2,8 +2,8 @@ #define GUARD_BATTLE_AI_SWITCH_ITEMS_H void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId); -void AI_TrySwitchOrUseItem(void); -u8 GetMostSuitableMonToSwitchInto(void); -bool32 ShouldSwitch(void); +void AI_TrySwitchOrUseItem(u32 battler); +u8 GetMostSuitableMonToSwitchInto(u32 battler); +bool32 ShouldSwitch(u32 battler); #endif // GUARD_BATTLE_AI_SWITCH_ITEMS_H diff --git a/include/battle_controllers.h b/include/battle_controllers.h index b9f9868fa..4e3ab7eb0 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -209,52 +209,52 @@ void SetUpBattleVarsAndBirchZigzagoon(void); void InitBattleControllers(void); bool32 IsValidForBattle(struct Pokemon *mon); void TryReceiveLinkBattleData(void); -void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data); +void PrepareBufferDataTransferLink(u32 battler, u32 bufferId, u16 size, u8 *data); // emitters -void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck); -void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data); -void BtlController_EmitLoadMonSprite(u8 bufferId); -void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit); -void BtlController_EmitReturnMonToBall(u8 bufferId, bool8 skipAnim); -void BtlController_EmitDrawTrainerPic(u8 bufferId); -void BtlController_EmitTrainerSlide(u8 bufferId); -void BtlController_EmitTrainerSlideBack(u8 bufferId); -void BtlController_EmitFaintAnimation(u8 bufferId); -void BtlController_EmitBallThrowAnim(u8 bufferId, u8 caseId); -void BtlController_EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit); -void BtlController_EmitPrintString(u8 bufferId, u16 stringId); -void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringId); -void BtlController_EmitChooseAction(u8 bufferId, u8 action, u16 itemId); -void BtlController_EmitYesNoBox(u8 bufferId); -void BtlController_EmitChooseMove(u8 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData); -void BtlController_EmitChooseItem(u8 bufferId, u8 *battlePartyOrder); -void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u16 abilityId, u8 *data); -void BtlController_EmitHealthBarUpdate(u8 bufferId, u16 hpValue); -void BtlController_EmitExpUpdate(u8 bufferId, u8 partyId, s32 expPoints); -void BtlController_EmitStatusIconUpdate(u8 bufferId, u32 status1, u32 status2); -void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status); -void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data); -void BtlController_EmitTwoReturnValues(u8 bufferId, u8 ret8, u32 ret32); -void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 partyId, u8 *battlePartyOrder); -void BtlController_EmitOneReturnValue(u8 bufferId, u16 ret); -void BtlController_EmitOneReturnValue_Duplicate(u8 bufferId, u16 ret); -void BtlController_EmitHitAnimation(u8 bufferId); -void BtlController_EmitCantSwitch(u8 bufferId); -void BtlController_EmitPlaySE(u8 bufferId, u16 songId); -void BtlController_EmitPlayFanfareOrBGM(u8 bufferId, u16 songId, bool8 playBGM); -void BtlController_EmitFaintingCry(u8 bufferId); -void BtlController_EmitIntroSlide(u8 bufferId, u8 terrainId); -void BtlController_EmitIntroTrainerBallThrow(u8 bufferId); -void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* hpAndStatus, u8 flags); -void BtlController_EmitHidePartyStatusSummary(u8 bufferId); -void BtlController_EmitEndBounceEffect(u8 bufferId); -void BtlController_EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible); -void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument); -void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 mode, bool32 record); -void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId); -void BtlController_EmitEndLinkBattle(u8 bufferId, u8 battleOutcome); -void BtlController_EmitDebugMenu(u8 bufferId); +void BtlController_EmitGetMonData(u32 battler, u32 bufferId, u8 requestId, u8 monToCheck); +void BtlController_EmitSetMonData(u32 battler, u32 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data); +void BtlController_EmitLoadMonSprite(u32 battler, u32 bufferId); +void BtlController_EmitSwitchInAnim(u32 battler, u32 bufferId, u8 partyId, bool8 dontClearSubstituteBit); +void BtlController_EmitReturnMonToBall(u32 battler, u32 bufferId, bool8 skipAnim); +void BtlController_EmitDrawTrainerPic(u32 battler, u32 bufferId); +void BtlController_EmitTrainerSlide(u32 battler, u32 bufferId); +void BtlController_EmitTrainerSlideBack(u32 battler, u32 bufferId); +void BtlController_EmitFaintAnimation(u32 battler, u32 bufferId); +void BtlController_EmitBallThrowAnim(u32 battler, u32 bufferId, u8 caseId); +void BtlController_EmitMoveAnimation(u32 battler, u32 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit); +void BtlController_EmitPrintString(u32 battler, u32 bufferId, u16 stringId); +void BtlController_EmitPrintSelectionString(u32 battler, u32 bufferId, u16 stringId); +void BtlController_EmitChooseAction(u32 battler, u32 bufferId, u8 action, u16 itemId); +void BtlController_EmitYesNoBox(u32 battler, u32 bufferId); +void BtlController_EmitChooseMove(u32 battler, u32 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData); +void BtlController_EmitChooseItem(u32 battler, u32 bufferId, u8 *battlePartyOrder); +void BtlController_EmitChoosePokemon(u32 battler, u32 bufferId, u8 caseId, u8 slotId, u16 abilityId, u8 *data); +void BtlController_EmitHealthBarUpdate(u32 battler, u32 bufferId, u16 hpValue); +void BtlController_EmitExpUpdate(u32 battler, u32 bufferId, u8 partyId, s32 expPoints); +void BtlController_EmitStatusIconUpdate(u32 battler, u32 bufferId, u32 status1, u32 status2); +void BtlController_EmitStatusAnimation(u32 battler, u32 bufferId, bool8 status2, u32 status); +void BtlController_EmitDataTransfer(u32 battler, u32 bufferId, u16 size, void *data); +void BtlController_EmitTwoReturnValues(u32 battler, u32 bufferId, u8 ret8, u32 ret32); +void BtlController_EmitChosenMonReturnValue(u32 battler, u32 bufferId, u8 partyId, u8 *battlePartyOrder); +void BtlController_EmitOneReturnValue(u32 battler, u32 bufferId, u16 ret); +void BtlController_EmitOneReturnValue_Duplicate(u32 battler, u32 bufferId, u16 ret); +void BtlController_EmitHitAnimation(u32 battler, u32 bufferId); +void BtlController_EmitCantSwitch(u32 battler, u32 bufferId); +void BtlController_EmitPlaySE(u32 battler, u32 bufferId, u16 songId); +void BtlController_EmitPlayFanfareOrBGM(u32 battler, u32 bufferId, u16 songId, bool8 playBGM); +void BtlController_EmitFaintingCry(u32 battler, u32 bufferId); +void BtlController_EmitIntroSlide(u32 battler, u32 bufferId, u8 terrainId); +void BtlController_EmitIntroTrainerBallThrow(u32 battler, u32 bufferId); +void BtlController_EmitDrawPartyStatusSummary(u32 battler, u32 bufferId, struct HpAndStatus* hpAndStatus, u8 flags); +void BtlController_EmitHidePartyStatusSummary(u32 battler, u32 bufferId); +void BtlController_EmitEndBounceEffect(u32 battler, u32 bufferId); +void BtlController_EmitSpriteInvisibility(u32 battler, u32 bufferId, bool8 isInvisible); +void BtlController_EmitBattleAnimation(u32 battler, u32 bufferId, u8 animationId, u16 argument); +void BtlController_EmitLinkStandbyMsg(u32 battler, u32 bufferId, u8 mode, bool32 record); +void BtlController_EmitResetActionMoveSelection(u32 battler, u32 bufferId, u8 caseId); +void BtlController_EmitEndLinkBattle(u32 battler, u32 bufferId, u8 battleOutcome); +void BtlController_EmitDebugMenu(u32 battler, u32 bufferId); void BattleControllerComplete(u32 battler); // Can be used for all the controllers. void BtlController_Empty(u32 battler); // Empty command, does nothing, only completes the execution. diff --git a/include/battle_gfx_sfx_util.h b/include/battle_gfx_sfx_util.h index 794447446..95c97caba 100644 --- a/include/battle_gfx_sfx_util.h +++ b/include/battle_gfx_sfx_util.h @@ -3,40 +3,40 @@ void AllocateBattleSpritesData(void); void FreeBattleSpritesData(void); -u16 ChooseMoveAndTargetInBattlePalace(void); +u16 ChooseMoveAndTargetInBattlePalace(u32 battler); void SpriteCB_WaitForBattlerBallReleaseAnim(struct Sprite *sprite); void SpriteCB_TrainerSlideIn(struct Sprite *sprite); -void InitAndLaunchChosenStatusAnimation(bool8 isStatus2, u32 status); +void InitAndLaunchChosenStatusAnimation(u32 battler, bool32 isStatus2, u32 status); bool8 TryHandleLaunchBattleTableAnimation(u8 activeBattlerId, u8 attacker, u8 target, u8 tableId, u16 argument); void InitAndLaunchSpecialAnimation(u8 activeBattlerId, u8 attacker, u8 target, u8 tableId); -bool8 IsBattleSEPlaying(u8 battlerId); -void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId); +bool8 IsBattleSEPlaying(u8 battler); +void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battler); void BattleGfxSfxDummy2(u16 species); -void DecompressTrainerFrontPic(u16 frontPicId, u8 battlerId); -void DecompressTrainerBackPic(u16 backPicId, u8 battlerId); +void DecompressTrainerFrontPic(u16 frontPicId, u8 battler); +void DecompressTrainerBackPic(u16 backPicId, u8 battler); void FreeTrainerFrontPicPalette(u16 frontPicId); bool8 BattleLoadAllHealthBoxesGfx(u8 state); void LoadBattleBarGfx(u8 unused); -bool8 BattleInitAllSprites(u8 *state1, u8 *battlerId); +bool8 BattleInitAllSprites(u8 *state1, u8 *battler); void ClearSpritesHealthboxAnimData(void); void CopyAllBattleSpritesInvisibilities(void); -void CopyBattleSpriteInvisibility(u8 battlerId); +void CopyBattleSpriteInvisibility(u8 battler); void HandleSpeciesGfxDataChange(u8 attacker, u8 target, bool32 megaEvo, bool8 trackEnemyPersonality); -void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite); -void LoadBattleMonGfxAndAnimate(u8 battlerId, bool8 loadMonSprite, u8 spriteId); -void TrySetBehindSubstituteSpriteBit(u8 battlerId, u16 move); -void ClearBehindSubstituteBit(u8 battlerId); -void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId); +void BattleLoadSubstituteOrMonSpriteGfx(u8 battler, bool8 loadMonSprite); +void LoadBattleMonGfxAndAnimate(u8 battler, bool8 loadMonSprite, u8 spriteId); +void TrySetBehindSubstituteSpriteBit(u8 battler, u16 move); +void ClearBehindSubstituteBit(u8 battler); +void HandleLowHpMusicChange(struct Pokemon *mon, u8 battler); void BattleStopLowHpSound(void); u8 GetMonHPBarLevel(struct Pokemon *mon); void HandleBattleLowHpMusicChange(void); void SetBattlerSpriteAffineMode(u8 affineMode); void LoadAndCreateEnemyShadowSprites(void); void SpriteCB_SetInvisible(struct Sprite *sprite); -void SetBattlerShadowSpriteCallback(u8 battlerId, u16 species); -void HideBattlerShadowSprite(u8 battlerId); +void SetBattlerShadowSpriteCallback(u8 battler, u16 species); +void HideBattlerShadowSprite(u8 battler); void FillAroundBattleWindows(void); -void ClearTemporarySpeciesSpriteData(u8 battlerId, bool8 dontClearSubstitute); +void ClearTemporarySpeciesSpriteData(u8 battler, bool8 dontClearSubstitute); void AllocateMonSpritesGfx(void); void FreeMonSpritesGfx(void); bool32 ShouldPlayNormalMonCry(struct Pokemon *mon); diff --git a/include/battle_main.h b/include/battle_main.h index 8a13213b8..0ae62cd35 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -53,10 +53,10 @@ void SpriteCB_TrainerThrowObject(struct Sprite *sprite); void AnimSetCenterToCornerVecX(struct Sprite *sprite); void BeginBattleIntroDummy(void); void BeginBattleIntro(void); -void SwitchInClearSetData(void); -void FaintClearSetData(void); +void SwitchInClearSetData(u32 battler); +void FaintClearSetData(u32 battler); void BattleTurnPassed(void); -u8 IsRunningFromBattleImpossible(void); +u8 IsRunningFromBattleImpossible(u32 battler); void SwitchPartyOrder(u8 battlerId); void SwapTurnOrder(u8 id1, u8 id2); u32 GetBattlerTotalSpeedStat(u8 battlerId); diff --git a/include/battle_message.h b/include/battle_message.h index 58d97bc4a..e01c916c3 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -27,7 +27,7 @@ #define B_TXT_ATK_NAME_WITH_PREFIX 0xF #define B_TXT_DEF_NAME_WITH_PREFIX 0x10 #define B_TXT_EFF_NAME_WITH_PREFIX 0x11 // EFF = short for gEffectBank -#define B_TXT_ACTIVE_NAME_WITH_PREFIX 0x12 +// #define B_TXT_ACTIVE_NAME_WITH_PREFIX 0x12 - removed #define B_TXT_SCR_ACTIVE_NAME_WITH_PREFIX 0x13 #define B_TXT_CURRENT_MOVE 0x14 #define B_TXT_LAST_MOVE 0x15 @@ -69,8 +69,8 @@ #define B_TXT_DEF_NAME 0x39 #define B_TXT_DEF_TEAM1 0x3A // Your/The opposing #define B_TXT_DEF_TEAM2 0x3B // your/the opposing -#define B_TXT_ACTIVE_NAME 0x3C -#define B_TXT_ACTIVE_NAME2 0x3D // no Illusion check +// #define B_TXT_SELECTION_NAME 0x3C - removed +// #define B_TXT_SELECTION_NAME2 0x3D no Illusion check - removed // for B_TXT_BUFF1, B_TXT_BUFF2 and B_TXT_BUFF3 @@ -240,13 +240,13 @@ enum TRAINER_SLIDE_BEFORE_FIRST_TURN, }; -void BufferStringBattle(u16 stringID); +void BufferStringBattle(u16 stringID, u32 battler); u32 BattleStringExpandPlaceholdersToDisplayedString(const u8 *src); u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst); void BattlePutTextOnWindow(const u8 *text, u8 windowId); -void SetPpNumbersPaletteInMoveSelection(void); +void SetPpNumbersPaletteInMoveSelection(u32 battler); u8 GetCurrentPpToMaxPpState(u8 currentPp, u8 maxPp); -u32 ShouldDoTrainerSlide(u32 battlerId, u32 which); // return 1 for TrainerA, 2 forTrainerB +u32 ShouldDoTrainerSlide(u32 battler, u32 which); // return 1 for TrainerA, 2 forTrainerB void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst); extern struct BattleMsgData *gBattleMsgDataPtr; diff --git a/include/battle_util.h b/include/battle_util.h index 8a1bce851..d0b34add7 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -114,22 +114,22 @@ u8 GetBattlerForBattleScript(u8 caseId); void PressurePPLose(u8 target, u8 attacker, u16 move); void PressurePPLoseOnUsingPerishSong(u8 attacker); void PressurePPLoseOnUsingImprison(u8 attacker); -bool32 IsBattlerMarkedForControllerExec(u8 battlerId); -void MarkBattlerForControllerExec(u8 battlerId); -void MarkBattlerReceivedLinkData(u8 battlerId); -void CancelMultiTurnMoves(u8 battlerId); -bool8 WasUnableToUseMove(u8 battlerId); -void PrepareStringBattle(u16 stringId, u8 battlerId); +bool32 IsBattlerMarkedForControllerExec(u8 battler); +void MarkBattlerForControllerExec(u8 battler); +void MarkBattlerReceivedLinkData(u8 battler); +void CancelMultiTurnMoves(u8 battler); +bool8 WasUnableToUseMove(u8 battler); +void PrepareStringBattle(u16 stringId, u8 battler); void ResetSentPokesToOpponentValue(void); -void OpponentSwitchInResetSentPokesToOpponentValue(u8 battlerId); -void UpdateSentPokesToOpponentValue(u8 battlerId); +void OpponentSwitchInResetSentPokesToOpponentValue(u8 battler); +void UpdateSentPokesToOpponentValue(u8 battler); void BattleScriptPush(const u8 *bsPtr); void BattleScriptPushCursor(void); void BattleScriptPop(void); -u8 TrySetCantSelectMoveBattleScript(void); -u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u16 check); -bool8 AreAllMovesUnusable(void); -u8 GetImprisonedMovesCount(u8 battlerId, u16 move); +u32 TrySetCantSelectMoveBattleScript(u32 battler); +u8 CheckMoveLimitations(u8 battler, u8 unusableMoves, u16 check); +bool32 AreAllMovesUnusable(u32 battler); +u8 GetImprisonedMovesCount(u8 battler, u16 move); u8 DoFieldEndTurnEffects(void); s32 GetDrainedBigRootHp(u32 battler, s32 hp); u8 DoBattlerEndTurnEffects(void); @@ -139,34 +139,34 @@ void TryClearRageAndFuryCutter(void); u8 AtkCanceller_UnableToUseMove(u32 moveType); void SetAtkCancellerForCalledMove(void); u8 AtkCanceller_UnableToUseMove2(void); -bool8 HasNoMonsToSwitch(u8 battlerId, u8 r1, u8 r2); +bool8 HasNoMonsToSwitch(u8 battler, u8 r1, u8 r2); bool32 TryChangeBattleWeather(u8 battler, u32 weatherEnumId, bool32 viaAbility); -u8 AbilityBattleEffects(u8 caseID, u8 battlerId, u16 ability, u8 special, u16 moveArg); -bool32 TryPrimalReversion(u8 battlerId); +u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 moveArg); +bool32 TryPrimalReversion(u8 battler); bool32 IsNeutralizingGasOnField(void); -u32 GetBattlerAbility(u8 battlerId); -u32 IsAbilityOnSide(u32 battlerId, u32 ability); -u32 IsAbilityOnOpposingSide(u32 battlerId, u32 ability); +u32 GetBattlerAbility(u8 battler); +u32 IsAbilityOnSide(u32 battler, u32 ability); +u32 IsAbilityOnOpposingSide(u32 battler, u32 ability); u32 IsAbilityOnField(u32 ability); -u32 IsAbilityOnFieldExcept(u32 battlerId, u32 ability); -u32 IsAbilityPreventingEscape(u32 battlerId); -bool32 IsBattlerProtected(u8 battlerId, u16 move); -bool32 CanBattlerEscape(u32 battlerId); // no ability check +u32 IsAbilityOnFieldExcept(u32 battler, u32 ability); +u32 IsAbilityPreventingEscape(u32 battler); +bool32 IsBattlerProtected(u8 battler, u16 move); +bool32 CanBattlerEscape(u32 battler); // no ability check void BattleScriptExecute(const u8 *BS_ptr); void BattleScriptPushCursorAndCallback(const u8 *BS_ptr); -u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn); -void ClearFuryCutterDestinyBondGrudge(u8 battlerId); +u8 ItemBattleEffects(u8 caseID, u8 battler, bool8 moveTurn); +void ClearFuryCutterDestinyBondGrudge(u8 battler); void HandleAction_RunBattleScript(void); -u32 SetRandomTarget(u32 battlerId); +u32 SetRandomTarget(u32 battler); u32 GetMoveTarget(u16 move, u8 setTarget); u8 IsMonDisobedient(void); -u32 GetBattlerHoldEffect(u8 battlerId, bool32 checkNegating); -u32 GetBattlerHoldEffectParam(u8 battlerId); +u32 GetBattlerHoldEffect(u8 battler, bool32 checkNegating); +u32 GetBattlerHoldEffectParam(u8 battler); bool32 IsMoveMakingContact(u16 move, u8 battlerAtk); -bool32 IsBattlerGrounded(u8 battlerId); -bool32 IsBattlerAlive(u8 battlerId); +bool32 IsBattlerGrounded(u8 battler); +bool32 IsBattlerAlive(u8 battler); u8 GetBattleMonMoveSlot(struct BattlePokemon *battleMon, u16 move); -u32 GetBattlerWeight(u8 battlerId); +u32 GetBattlerWeight(u8 battler); u32 CalcRolloutBasePower(u32 battlerAtk, u32 basePower, u32 rolloutTimer); u32 CalcFuryCutterBasePower(u32 basePower, u32 furyCutterCounter); s32 CalculateMoveDamage(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, s32 fixedBasePower, bool32 isCrit, bool32 randomFactor, bool32 updateFlags); @@ -174,46 +174,46 @@ s32 CalculateMoveDamageAndEffectiveness(u16 move, u8 battlerAtk, u8 battlerDef, uq4_12_t CalcTypeEffectivenessMultiplier(u16 move, u8 moveType, u8 battlerAtk, u8 battlerDef, bool32 recordAbilities); uq4_12_t CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, u16 abilityDef); uq4_12_t GetTypeModifier(u8 atkType, u8 defType); -s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId); +s32 GetStealthHazardDamage(u8 hazardType, u8 battler); s32 GetStealthHazardDamageByTypesAndHP(u8 hazardType, u8 type1, u8 type2, u32 maxHp); -bool32 CanMegaEvolve(u8 battlerId); -bool32 CanUltraBurst(u8 battlerId); -bool32 IsBattlerMegaEvolved(u8 battlerId); -bool32 IsBattlerPrimalReverted(u8 battlerId); -bool32 IsBattlerUltraBursted(u8 battlerId); -u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method); -bool32 TryBattleFormChange(u8 battlerId, u16 method); +bool32 CanMegaEvolve(u8 battler); +bool32 CanUltraBurst(u8 battler); +bool32 IsBattlerMegaEvolved(u8 battler); +bool32 IsBattlerPrimalReverted(u8 battler); +bool32 IsBattlerUltraBursted(u8 battler); +u16 GetBattleFormChangeTargetSpecies(u8 battler, u16 method); +bool32 TryBattleFormChange(u8 battler, u16 method); bool32 DoBattlersShareType(u32 battler1, u32 battler2); -bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId); -u32 GetIllusionMonSpecies(u32 battlerId); -struct Pokemon *GetIllusionMonPtr(u32 battlerId); -void ClearIllusionMon(u32 battlerId); -bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId); -bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId); +bool32 CanBattlerGetOrLoseItem(u8 battler, u16 itemId); +u32 GetIllusionMonSpecies(u32 battler); +struct Pokemon *GetIllusionMonPtr(u32 battler); +void ClearIllusionMon(u32 battler); +bool32 SetIllusionMon(struct Pokemon *mon, u32 battler); +bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battler); u8 GetBattleMoveSplit(u32 moveId); -bool32 CanFling(u8 battlerId); +bool32 CanFling(u8 battler); bool32 IsTelekinesisBannedSpecies(u16 species); bool32 IsHealBlockPreventingMove(u32 battler, u32 move); -bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId); -bool32 IsPartnerMonFromSameTrainer(u8 battlerId); -u8 GetSplitBasedOnStats(u8 battlerId); +bool32 HasEnoughHpToEatBerry(u32 battler, u32 hpFraction, u32 itemId); +bool32 IsPartnerMonFromSameTrainer(u8 battler); +u8 GetSplitBasedOnStats(u8 battler); bool32 TestSheerForceFlag(u8 battler, u16 move); void TryRestoreHeldItems(void); bool32 CanStealItem(u8 battlerStealing, u8 battlerItem, u16 item); -void TrySaveExchangedItem(u8 battlerId, u16 stolenItem); -bool32 IsPartnerMonFromSameTrainer(u8 battlerId); +void TrySaveExchangedItem(u8 battler, u16 stolenItem); +bool32 IsPartnerMonFromSameTrainer(u8 battler); u8 TryHandleSeed(u8 battler, u32 terrainFlag, u8 statId, u16 itemId, bool32 execute); -bool32 IsBattlerAffectedByHazards(u8 battlerId, bool32 toxicSpikes); +bool32 IsBattlerAffectedByHazards(u8 battler, bool32 toxicSpikes); void SortBattlersBySpeed(u8 *battlers, bool8 slowToFast); -bool32 CompareStat(u8 battlerId, u8 statId, u8 cmpTo, u8 cmpKind); -bool32 TryRoomService(u8 battlerId); -void BufferStatChange(u8 battlerId, u8 statId, u8 stringId); +bool32 CompareStat(u8 battler, u8 statId, u8 cmpTo, u8 cmpKind); +bool32 TryRoomService(u8 battler); +void BufferStatChange(u8 battler, u8 statId, u8 stringId); bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 checkTarget); u16 GetUsedHeldItem(u8 battler); -bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags); -u32 GetBattlerMoveTargetType(u8 battlerId, u16 move); +bool32 IsBattlerWeatherAffected(u8 battler, u32 weatherFlags); +u32 GetBattlerMoveTargetType(u8 battler, u16 move); bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move); -bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId); +bool8 IsMoveAffectedByParentalBond(u16 move, u8 battler); void CopyMonLevelAndBaseStatsToBattleMon(u32 battler, struct Pokemon *mon); void CopyMonAbilityAndTypesToBattleMon(u32 battler, struct Pokemon *mon); void RecalcBattlerStats(u32 battler, struct Pokemon *mon); @@ -228,21 +228,21 @@ bool32 IsGastroAcidBannedAbility(u16 ability); bool32 IsEntrainmentBannedAbilityAttacker(u16 ability); bool32 IsEntrainmentTargetOrSimpleBeamBannedAbility(u16 ability); -bool32 CanSleep(u8 battlerId); +bool32 CanSleep(u8 battler); bool32 CanBePoisoned(u8 battlerAttacker, u8 battlerTarget); -bool32 CanBeBurned(u8 battlerId); -bool32 CanBeParalyzed(u8 battlerId); -bool32 CanBeFrozen(u8 battlerId); -bool32 CanGetFrostbite(u8 battlerId); -bool32 CanBeConfused(u8 battlerId); -bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag); -u32 GetBattlerFriendshipScore(u8 battlerId); -u32 CountBattlerStatIncreases(u8 battlerId, bool32 countEvasionAcc); +bool32 CanBeBurned(u8 battler); +bool32 CanBeParalyzed(u8 battler); +bool32 CanBeFrozen(u8 battler); +bool32 CanGetFrostbite(u8 battler); +bool32 CanBeConfused(u8 battler); +bool32 IsBattlerTerrainAffected(u8 battler, u32 terrainFlag); +u32 GetBattlerFriendshipScore(u8 battler); +u32 CountBattlerStatIncreases(u8 battler, bool32 countEvasionAcc); bool32 IsMyceliumMightOnField(void); -bool8 ChangeTypeBasedOnTerrain(u8 battlerId); -void RemoveConfusionStatus(u8 battlerId); -u8 GetBattlerGender(u8 battlerId); +bool8 ChangeTypeBasedOnTerrain(u8 battler); +void RemoveConfusionStatus(u8 battler); +u8 GetBattlerGender(u8 battler); bool8 AreBattlersOfOppositeGender(u8 battler1, u8 battler2); -u32 CalcSecondaryEffectChance(u8 battlerId, u8 secondaryEffectChance); +u32 CalcSecondaryEffectChance(u8 battler, u8 secondaryEffectChance); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/battle_z_move.h b/include/battle_z_move.h index 44ed43454..8dea0bd7d 100644 --- a/include/battle_z_move.h +++ b/include/battle_z_move.h @@ -14,18 +14,18 @@ struct SignatureZMove }; bool8 IsZMove(u16 move); -void QueueZMove(u8 battlerId, u16 baseMove); -bool32 IsViableZMove(u8 battlerId, u16 move); -bool32 TryChangeZIndicator(u8 battlerId, u8 moveIndex); +void QueueZMove(u8 battler, u16 baseMove); +bool32 IsViableZMove(u8 battler, u16 move); +bool32 TryChangeZIndicator(u8 battler, u8 moveIndex); void CreateZMoveTriggerSprite(u8, bool8); void HideZMoveTriggerSprite(void); bool32 IsZMoveTriggerSpriteActive(void); void DestroyZMoveTriggerSprite(void); -bool32 MoveSelectionDisplayZMove(u16 zmove); +bool32 MoveSelectionDisplayZMove(u16 zmove, u32 battler); const u8 *GetZMoveName(u16 move); void SetZEffect(void); -bool32 IsZMoveUsable(u8 battlerId, u16 moveIndex); -void GetUsableZMoves(u8 battlerId, u16 *moves); +bool32 IsZMoveUsable(u8 battler, u16 moveIndex); +void GetUsableZMoves(u8 battler, u16 *moves); u16 GetZMovePower(u16 move); #endif // GUARD_BATTLE_Z_MOVE_H diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 3b54f9851..9b504eaec 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -305,10 +305,8 @@ // - Unown has 1 frame, presumably to avoid the work of animating all 28 of its forms #define MAX_MON_PIC_FRAMES 2 -#define BATTLE_ALIVE_EXCEPT_ACTIVE 0 -#define BATTLE_ALIVE_ATK_SIDE 1 -#define BATTLE_ALIVE_DEF_SIDE 2 -#define BATTLE_ALIVE_EXCEPT_ATTACKER 3 +#define BATTLE_ALIVE_EXCEPT_BATTLER 0 +#define BATTLE_ALIVE_SIDE 1 #define SKIP_FRONT_ANIM (1 << 7) diff --git a/include/graphics.h b/include/graphics.h index dd8f57b75..87635d43a 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -9322,9 +9322,9 @@ extern const u32 gConfetti_Gfx[]; extern const u32 gConfetti_Pal[]; extern const u32 gBattleInterfaceGfx_BattleBar[]; -extern const u32 gSubstituteDollBackGfx[]; -extern const u32 gSubstituteDollFrontGfx[]; -extern const u32 gSubstituteDollPal[]; +extern const u32 gBattleAnimSpriteGfx_Substitute[]; +extern const u32 gBattleAnimSpriteGfx_SubstituteBack[]; +extern const u32 gBattleAnimSpritePal_Substitute[]; extern const u32 gHealthboxSinglesPlayerGfx[]; extern const u32 gHealthboxSinglesOpponentGfx[]; extern const u32 gHealthboxDoublesPlayerGfx[]; @@ -10145,9 +10145,6 @@ extern const u32 gBattleAnimSpritePal_StonePillar[]; extern const u32 gBattleAnimSpriteGfx_StraightBeam[]; extern const u32 gBattleAnimSpritePal_StraightBeam[]; extern const u32 gBattleAnimSpritePal_Poltergeist[]; -extern const u32 gBattleAnimSpriteGfx_SubstituteBack[]; -extern const u32 gBattleAnimSpriteGfx_SubstituteFront[]; -extern const u32 gBattleAnimSpritePal_SubstituteFront[]; extern const u32 gBattleAnimSpritePal_NewSurf[]; extern const u32 gBattleAnimSpriteGfx_NewSword[]; extern const u32 gBattleAnimSpritePal_NewSword[]; diff --git a/include/pokeball.h b/include/pokeball.h index 602e9f973..498fa4dd1 100644 --- a/include/pokeball.h +++ b/include/pokeball.h @@ -48,7 +48,7 @@ extern const struct SpriteTemplate gBallSpriteTemplates[]; #define POKEBALL_PLAYER_SENDOUT 0xFF #define POKEBALL_OPPONENT_SENDOUT 0xFE -u8 DoPokeballSendOutAnimation(s16 pan, u8 kindOfThrow); +u8 DoPokeballSendOutAnimation(u32 battler, s16 pan, u8 kindOfThrow); void CreatePokeballSpriteToReleaseMon(u8 monSpriteId, u8 monPalNum, u8 x, u8 y, u8 oamPriority, u8 subpriority, u8 delay, u32 fadePalettes, u16 species); u8 CreateTradePokeballSprite(u8 monSpriteId, u8 monPalNum, u8 x, u8 y, u8 oamPriority, u8 subPriority, u8 delay, u32 fadePalettes); void StartHealthboxSlideIn(u8 battler); diff --git a/include/pokemon.h b/include/pokemon.h index 8303f3223..a37d5f010 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -490,7 +490,7 @@ void GiveBoxMonInitialMoveset_Fast(struct BoxPokemon *boxMon); u16 MonTryLearningNewMove(struct Pokemon *mon, bool8 firstMove); void DeleteFirstMoveAndGiveMoveToMon(struct Pokemon *mon, u16 move); void DeleteFirstMoveAndGiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move); -u8 CountAliveMonsInBattle(u8 caseId); +u8 CountAliveMonsInBattle(u8 caseId, u32 battler); u8 GetDefaultMoveTarget(u8 battlerId); u8 GetMonGender(struct Pokemon *mon); u8 GetBoxMonGender(struct BoxPokemon *boxMon); @@ -538,7 +538,7 @@ void CopyPlayerPartyMonToBattleData(u8 battlerId, u8 partyIndex); bool8 ExecuteTableBasedItemEffect(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex); bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex, u8 e); bool8 HealStatusConditions(struct Pokemon *mon, u32 battlePartyId, u32 healMask, u8 battlerId); -u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit); +u8 GetItemEffectParamOffset(u32 battler, u16 itemId, u8 effectByte, u8 effectBit); u8 *UseStatIncreaseItem(u16 itemId); u8 GetNature(struct Pokemon *mon); u8 GetNatureFromPersonality(u32 personality); diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 02bbe8fc3..e4fa1deb4 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -70,13 +70,13 @@ void PlayRecordedBattle(void (*CB2_After)(void)); u8 GetRecordedBattleFrontierFacility(void); u8 GetRecordedBattleFronterBrainSymbol(void); void RecordedBattle_SaveParties(void); -u8 GetActiveBattlerLinkPlayerGender(void); +u8 GetBattlerLinkPlayerGender(u32 battler); void RecordedBattle_ClearFrontierPassFlag(void); void RecordedBattle_SetFrontierPassFlagFromHword(u16 flags); u8 RecordedBattle_GetFrontierPassFlag(void); u8 GetBattleSceneInRecordedBattle(void); u8 GetTextSpeedInRecordedBattle(void); -void RecordedBattle_CopyBattlerMoves(void); +void RecordedBattle_CopyBattlerMoves(u32 battler); void RecordedBattle_CheckMovesetChanges(u8 mode); u32 GetAiScriptsInRecordedBattle(void); void RecordedBattle_SetPlaybackFinished(void); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 7f08b18e9..069312f68 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -180,7 +180,7 @@ void BattleAI_SetupFlags(void) } // sBattler_AI set in ComputeBattleAiScores -void BattleAI_SetupAIData(u8 defaultScoreMoves) +void BattleAI_SetupAIData(u8 defaultScoreMoves, u32 battler) { s32 i, move, dmg; u8 moveLimitations; @@ -201,7 +201,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) defaultScoreMoves >>= 1; } - moveLimitations = AI_DATA->moveLimitations[gActiveBattler]; + moveLimitations = AI_DATA->moveLimitations[battler]; // Ignore moves that aren't possible to use. for (i = 0; i < MAX_MON_MOVES; i++) @@ -210,7 +210,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) AI_THINKING_STRUCT->score[i] = 0; } - //sBattler_AI = gActiveBattler; + //sBattler_AI = battler; gBattlerTarget = SetRandomTarget(sBattler_AI); gBattleStruct->aiChosenTarget[sBattler_AI] = gBattlerTarget; } @@ -237,7 +237,7 @@ u8 BattleAI_ChooseMoveOrAction(void) u8 ComputeBattleAiScores(u8 battler) { sBattler_AI = battler; - BattleAI_SetupAIData(0xF); + BattleAI_SetupAIData(0xF, sBattler_AI); return BattleAI_ChooseMoveOrAction(); } @@ -335,15 +335,15 @@ void Ai_UpdateFaintData(u32 battler) aiMon->isFainted = TRUE; } -static void SetBattlerAiData(u8 battlerId) +static void SetBattlerAiData(u8 battler) { - AI_DATA->abilities[battlerId] = AI_GetAbility(battlerId); - AI_DATA->items[battlerId] = gBattleMons[battlerId].item; - AI_DATA->holdEffects[battlerId] = AI_GetHoldEffect(battlerId); - AI_DATA->holdEffectParams[battlerId] = GetBattlerHoldEffectParam(battlerId); - AI_DATA->predictedMoves[battlerId] = gLastMoves[battlerId]; - AI_DATA->hpPercents[battlerId] = GetHealthPercentage(battlerId); - AI_DATA->moveLimitations[battlerId] = CheckMoveLimitations(battlerId, 0, MOVE_LIMITATIONS_ALL); + AI_DATA->abilities[battler] = AI_GetAbility(battler); + AI_DATA->items[battler] = gBattleMons[battler].item; + AI_DATA->holdEffects[battler] = AI_GetHoldEffect(battler); + AI_DATA->holdEffectParams[battler] = GetBattlerHoldEffectParam(battler); + AI_DATA->predictedMoves[battler] = gLastMoves[battler]; + AI_DATA->hpPercents[battler] = GetHealthPercentage(battler); + AI_DATA->moveLimitations[battler] = CheckMoveLimitations(battler, 0, MOVE_LIMITATIONS_ALL); } void GetAiLogicData(void) @@ -399,48 +399,48 @@ void GetAiLogicData(void) } } -static bool32 AI_SwitchMonIfSuitable(u32 battlerId) +static bool32 AI_SwitchMonIfSuitable(u32 battler) { - u32 monToSwitchId = GetMostSuitableMonToSwitchInto(); + u32 monToSwitchId = GetMostSuitableMonToSwitchInto(battler); if (monToSwitchId != PARTY_SIZE) { - AI_DATA->shouldSwitchMon |= gBitTable[battlerId]; - AI_DATA->monToSwitchId[battlerId] = monToSwitchId; + AI_DATA->shouldSwitchMon |= gBitTable[battler]; + AI_DATA->monToSwitchId[battler] = monToSwitchId; return TRUE; } return FALSE; } -static bool32 AI_ShouldSwitchIfBadMoves(u32 battlerId, bool32 doubleBattle) +static bool32 AI_ShouldSwitchIfBadMoves(u32 battler, bool32 doubleBattle) { u32 i, j; // If can switch. - if (CountUsablePartyMons(battlerId) > 0 - && !IsBattlerTrapped(battlerId, TRUE) + if (CountUsablePartyMons(battler) > 0 + && !IsBattlerTrapped(battler, TRUE) && !(gBattleTypeFlags & (BATTLE_TYPE_ARENA | BATTLE_TYPE_PALACE)) && AI_THINKING_STRUCT->aiFlags & (AI_FLAG_CHECK_VIABILITY | AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_PREFER_BATON_PASS)) { // Consider switching if all moves are worthless to use. - if (GetTotalBaseStat(gBattleMons[battlerId].species) >= 310 // Mon is not weak. - && gBattleMons[battlerId].hp >= gBattleMons[battlerId].maxHP / 2) // Mon has more than 50% of its HP + if (GetTotalBaseStat(gBattleMons[battler].species) >= 310 // Mon is not weak. + && gBattleMons[battler].hp >= gBattleMons[battler].maxHP / 2) // Mon has more than 50% of its HP { s32 cap = AI_THINKING_STRUCT->aiFlags & (AI_FLAG_CHECK_VIABILITY) ? 95 : 93; if (doubleBattle) { for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - if (i != battlerId && IsBattlerAlive(i)) + if (i != battler && IsBattlerAlive(i)) { for (j = 0; j < MAX_MON_MOVES; j++) { - if (gBattleStruct->aiFinalScore[battlerId][i][j] > cap) + if (gBattleStruct->aiFinalScore[battler][i][j] > cap) break; } if (j != MAX_MON_MOVES) break; } } - if (i == MAX_BATTLERS_COUNT && AI_SwitchMonIfSuitable(battlerId)) + if (i == MAX_BATTLERS_COUNT && AI_SwitchMonIfSuitable(battler)) return TRUE; } else @@ -451,7 +451,7 @@ static bool32 AI_ShouldSwitchIfBadMoves(u32 battlerId, bool32 doubleBattle) break; } - if (i == MAX_MON_MOVES && AI_SwitchMonIfSuitable(battlerId)) + if (i == MAX_MON_MOVES && AI_SwitchMonIfSuitable(battler)) return TRUE; } @@ -459,11 +459,11 @@ static bool32 AI_ShouldSwitchIfBadMoves(u32 battlerId, bool32 doubleBattle) // Consider switching if your mon with truant is bodied by Protect spam. // Or is using a double turn semi invulnerable move(such as Fly) and is faster. - if (GetBattlerAbility(battlerId) == ABILITY_TRUANT - && IsTruantMonVulnerable(battlerId, gBattlerTarget) - && gDisableStructs[battlerId].truantCounter - && gBattleMons[battlerId].hp >= gBattleMons[battlerId].maxHP / 2 - && AI_SwitchMonIfSuitable(battlerId)) + if (GetBattlerAbility(battler) == ABILITY_TRUANT + && IsTruantMonVulnerable(battler, gBattlerTarget) + && gDisableStructs[battler].truantCounter + && gBattleMons[battler].hp >= gBattleMons[battler].maxHP / 2 + && AI_SwitchMonIfSuitable(battler)) { return TRUE; } @@ -502,8 +502,6 @@ static u8 ChooseMoveOrAction_Singles(void) if (AI_THINKING_STRUCT->aiAction & AI_ACTION_WATCH) return AI_CHOICE_WATCH; - gActiveBattler = sBattler_AI; - // Switch mon if there are no good moves to use. if (AI_ShouldSwitchIfBadMoves(sBattler_AI, FALSE)) return AI_CHOICE_SWITCH; @@ -556,9 +554,9 @@ static u8 ChooseMoveOrAction_Doubles(void) else { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) - BattleAI_SetupAIData(gBattleStruct->palaceFlags >> 4); + BattleAI_SetupAIData(gBattleStruct->palaceFlags >> 4, sBattler_AI); else - BattleAI_SetupAIData(0xF); + BattleAI_SetupAIData(0xF, sBattler_AI); gBattlerTarget = i; if ((i & BIT_SIDE) != (sBattler_AI & BIT_SIDE)) @@ -3761,7 +3759,7 @@ static s16 AI_CheckViability(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) } break; case EFFECT_BATON_PASS: - if (ShouldSwitch() && (gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE + if (ShouldSwitch(battlerAtk) && (gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE || (gStatuses3[battlerAtk] & (STATUS3_ROOTED | STATUS3_AQUA_RING | STATUS3_MAGNET_RISE | STATUS3_POWER_TRICK)) || AnyStatIsRaised(battlerAtk))) score += 5; diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 89abdaa77..1c12ecdfd 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -22,32 +22,32 @@ #include "constants/moves.h" // this file's functions -static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng); -static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent); -static bool8 ShouldUseItem(void); -static bool32 AiExpectsToFaintPlayer(void); -static bool32 AI_ShouldHeal(u32 healAmount); -static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount); -static bool32 IsAiPartyMonOHKOBy(u32 battlerAtk, struct Pokemon *aiMon); +static bool8 HasSuperEffectiveMoveAgainstOpponents(u32 battler, bool8 noRng); +static bool8 FindMonWithFlagsAndSuperEffective(u32 battler, u16 flags, u8 moduloPercent); +static bool8 ShouldUseItem(u32 battler); +static bool32 AiExpectsToFaintPlayer(u32 battler); +static bool32 AI_ShouldHeal(u32 battler, u32 healAmount); +static bool32 AI_OpponentCanFaintAiWithMod(u32 battler, u32 healAmount); +static bool32 IsAiPartyMonOHKOBy(u32 battlerAi, u32 battlerAtk, struct Pokemon *aiMon); -static bool32 IsAceMon(u32 battlerId, u32 monPartyId) +static bool32 IsAceMon(u32 battler, u32 monPartyId) { if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON - && !(gBattleStruct->forcedSwitch & gBitTable[battlerId]) + && !(gBattleStruct->forcedSwitch & gBitTable[battler]) && monPartyId == CalculateEnemyPartyCount()-1) return TRUE; return FALSE; } -void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId) +void GetAIPartyIndexes(u32 battler, s32 *firstId, s32 *lastId) { - if (BATTLE_TWO_VS_ONE_OPPONENT && (battlerId & BIT_SIDE) == B_SIDE_OPPONENT) + if (BATTLE_TWO_VS_ONE_OPPONENT && (battler & BIT_SIDE) == B_SIDE_OPPONENT) { *firstId = 0, *lastId = PARTY_SIZE; } else if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_TOWER_LINK_MULTI)) { - if ((battlerId & BIT_FLANK) == B_FLANK_LEFT) + if ((battler & BIT_FLANK) == B_FLANK_LEFT) *firstId = 0, *lastId = PARTY_SIZE / 2; else *firstId = PARTY_SIZE / 2, *lastId = PARTY_SIZE; @@ -58,13 +58,13 @@ void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId) } } -static bool8 ShouldSwitchIfAllBadMoves(void) +static bool8 ShouldSwitchIfAllBadMoves(u32 battler) { - if (AI_DATA->shouldSwitchMon & gBitTable[gActiveBattler]) + if (AI_DATA->shouldSwitchMon & gBitTable[battler]) { - AI_DATA->shouldSwitchMon &= ~(gBitTable[gActiveBattler]); - gBattleStruct->AI_monToSwitchIntoId[gActiveBattler] = AI_DATA->monToSwitchId[gActiveBattler]; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + AI_DATA->shouldSwitchMon &= ~(gBitTable[battler]); + gBattleStruct->AI_monToSwitchIntoId[battler] = AI_DATA->monToSwitchId[battler]; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } else @@ -73,7 +73,7 @@ static bool8 ShouldSwitchIfAllBadMoves(void) } } -static bool8 ShouldSwitchIfWonderGuard(void) +static bool8 ShouldSwitchIfWonderGuard(u32 battler) { u8 opposingPosition; u8 opposingBattler; @@ -86,7 +86,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) return FALSE; - opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); + opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(battler)); if (GetBattlerAbility(GetBattlerAtPosition(opposingPosition)) != ABILITY_WONDER_GUARD) return FALSE; @@ -94,18 +94,18 @@ static bool8 ShouldSwitchIfWonderGuard(void) // Check if Pokemon has a super effective move. for (opposingBattler = GetBattlerAtPosition(opposingPosition), i = 0; i < MAX_MON_MOVES; i++) { - move = gBattleMons[gActiveBattler].moves[i]; + move = gBattleMons[battler].moves[i]; if (move != MOVE_NONE) { - if (AI_GetTypeEffectiveness(move, gActiveBattler, opposingBattler) >= UQ_4_12(2.0)) + if (AI_GetTypeEffectiveness(move, battler, opposingBattler) >= UQ_4_12(2.0)) return FALSE; } } // Get party information. - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -115,9 +115,9 @@ static bool8 ShouldSwitchIfWonderGuard(void) { if (!IsValidForBattle(&party[i])) continue; - if (i == gBattlerPartyIndexes[gActiveBattler]) + if (i == gBattlerPartyIndexes[battler]) continue; - if (IsAceMon(gActiveBattler, i)) + if (IsAceMon(battler, i)) continue; for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++) @@ -125,11 +125,11 @@ static bool8 ShouldSwitchIfWonderGuard(void) move = GetMonData(&party[i], MON_DATA_MOVE1 + j); if (move != MOVE_NONE) { - if (AI_GetTypeEffectiveness(move, gActiveBattler, opposingBattler) >= UQ_4_12(2.0) && Random() % 3 < 2) + if (AI_GetTypeEffectiveness(move, battler, opposingBattler) >= UQ_4_12(2.0) && Random() % 3 < 2) { // We found a mon. - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + battler) = i; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } } @@ -139,60 +139,60 @@ static bool8 ShouldSwitchIfWonderGuard(void) return FALSE; // There is not a single Pokemon in the party that has a super effective move against a mon with Wonder Guard. } -static bool8 FindMonThatAbsorbsOpponentsMove(void) +static bool8 FindMonThatAbsorbsOpponentsMove(u32 battler) { u8 battlerIn1, battlerIn2; - u8 numAbsorbingAbilities = 0; + u8 numAbsorbingAbilities = 0; u16 absorbingTypeAbilities[3]; // Array size is maximum number of absorbing abilities for a single type s32 firstId; s32 lastId; // + 1 struct Pokemon *party; s32 i, j; - if (HasSuperEffectiveMoveAgainstOpponents(TRUE) && Random() % 3 != 0) + if (HasSuperEffectiveMoveAgainstOpponents(battler, TRUE) && Random() % 3 != 0) return FALSE; - if (gLastLandedMoves[gActiveBattler] == MOVE_NONE) + if (gLastLandedMoves[battler] == MOVE_NONE) return FALSE; - if (gLastLandedMoves[gActiveBattler] == MOVE_UNAVAILABLE) + if (gLastLandedMoves[battler] == MOVE_UNAVAILABLE) return FALSE; - if (IS_MOVE_STATUS(gLastLandedMoves[gActiveBattler])) + if (IS_MOVE_STATUS(gLastLandedMoves[battler])) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - battlerIn1 = gActiveBattler; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))]) + battlerIn2 = battler; else - battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))); } else { - battlerIn1 = gActiveBattler; - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + battlerIn2 = battler; } // Create an array of possible absorb abilities so the AI considers all of them - if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_FIRE) + if (gBattleMoves[gLastLandedMoves[battler]].type == TYPE_FIRE) { absorbingTypeAbilities[0] = ABILITY_FLASH_FIRE; numAbsorbingAbilities = 1; } - else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_WATER) + else if (gBattleMoves[gLastLandedMoves[battler]].type == TYPE_WATER) { absorbingTypeAbilities[0] = ABILITY_WATER_ABSORB; absorbingTypeAbilities[1] = ABILITY_STORM_DRAIN; absorbingTypeAbilities[2] = ABILITY_DRY_SKIN; numAbsorbingAbilities = 3; } - else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_ELECTRIC) + else if (gBattleMoves[gLastLandedMoves[battler]].type == TYPE_ELECTRIC) { absorbingTypeAbilities[0] = ABILITY_VOLT_ABSORB; absorbingTypeAbilities[1] = ABILITY_MOTOR_DRIVE; absorbingTypeAbilities[2] = ABILITY_LIGHTNING_ROD; numAbsorbingAbilities = 3; } - else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_GRASS) + else if (gBattleMoves[gLastLandedMoves[battler]].type == TYPE_GRASS) { absorbingTypeAbilities[0] = ABILITY_SAP_SIPPER; numAbsorbingAbilities = 1; @@ -205,13 +205,13 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) // Check current mon for all absorbing abilities for (i = 0; i < numAbsorbingAbilities; i++) { - if (AI_DATA->abilities[gActiveBattler] == absorbingTypeAbilities[i]) + if (AI_DATA->abilities[battler] == absorbingTypeAbilities[i]) return FALSE; } - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -230,7 +230,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (IsAceMon(gActiveBattler, i)) + if (IsAceMon(battler, i)) continue; monAbility = GetMonAbility(&party[i]); @@ -240,8 +240,8 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (absorbingTypeAbilities[j] == monAbility && Random() & 1) { // we found a mon. - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + battler) = i; + BtlController_EmitTwoReturnValues(battler, 1, B_ACTION_SWITCH, 0); return TRUE; } } @@ -249,12 +249,12 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) return FALSE; } -static bool8 ShouldSwitchIfGameStatePrompt(void) +static bool8 ShouldSwitchIfGameStatePrompt(u32 battler) { bool8 switchMon = FALSE; - u16 monAbility = AI_DATA->abilities[gActiveBattler]; - u16 holdEffect = AI_DATA->holdEffects[gActiveBattler]; - u8 opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); + u16 monAbility = AI_DATA->abilities[battler]; + u16 holdEffect = AI_DATA->holdEffects[battler]; + u8 opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(battler)); u8 opposingBattler = GetBattlerAtPosition(opposingPosition); s32 moduloChance = 4; //25% Chance Default s32 chanceReducer = 1; //No Reduce default. Increase to reduce @@ -263,22 +263,21 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) s32 i; struct Pokemon *party; - - if (AnyStatIsRaised(gActiveBattler)) + if (AnyStatIsRaised(battler)) chanceReducer = 5; // Reduce switchout probability by factor of 5 if setup //Perish Song - if (gStatuses3[gActiveBattler] & STATUS3_PERISH_SONG - && gDisableStructs[gActiveBattler].perishSongTimer == 0 + if (gStatuses3[battler] & STATUS3_PERISH_SONG + && gDisableStructs[battler].perishSongTimer == 0 && monAbility != ABILITY_SOUNDPROOF) switchMon = TRUE; if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_SMART_SWITCHING) { //Yawn - if (gStatuses3[gActiveBattler] & STATUS3_YAWN - && AI_CanSleep(gActiveBattler, monAbility) - && gBattleMons[gActiveBattler].hp > gBattleMons[gActiveBattler].maxHP / 3) + if (gStatuses3[battler] & STATUS3_YAWN + && AI_CanSleep(battler, monAbility) + && gBattleMons[battler].hp > gBattleMons[battler].maxHP / 3) { switchMon = TRUE; @@ -286,40 +285,40 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) //Check if partner can prevent sleep if (IsDoubleBattle()) { - if (IsBattlerAlive(BATTLE_PARTNER(gActiveBattler)) - && (GetAIChosenMove(BATTLE_PARTNER(gActiveBattler)) == MOVE_UPROAR) + if (IsBattlerAlive(BATTLE_PARTNER(battler)) + && (GetAIChosenMove(BATTLE_PARTNER(battler)) == MOVE_UPROAR) ) switchMon = FALSE; - if (IsBattlerAlive(BATTLE_PARTNER(gActiveBattler)) + if (IsBattlerAlive(BATTLE_PARTNER(battler)) && (gBattleMoves[AI_DATA->partnerMove].effect == EFFECT_MISTY_TERRAIN || gBattleMoves[AI_DATA->partnerMove].effect == EFFECT_ELECTRIC_TERRAIN) - && IsBattlerGrounded(gActiveBattler) + && IsBattlerGrounded(battler) ) switchMon = FALSE; - if (*(gBattleStruct->AI_monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)) != PARTY_SIZE) //Partner is switching + if (*(gBattleStruct->AI_monToSwitchIntoId + BATTLE_PARTNER(battler)) != PARTY_SIZE) //Partner is switching { - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; for (i = firstId; i < lastId; i++) { - if (IsAceMon(gActiveBattler, i)) + if (IsAceMon(battler, i)) continue; //Look for mon in party that is able to be switched into and has ability that sets terrain if (IsValidForBattle(&party[i]) - && i != gBattlerPartyIndexes[gActiveBattler] - && i != gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)] - && IsBattlerGrounded(gActiveBattler) + && i != gBattlerPartyIndexes[battler] + && i != gBattlerPartyIndexes[BATTLE_PARTNER(battler)] + && IsBattlerGrounded(battler) && (GetMonAbility(&party[i]) == ABILITY_MISTY_SURGE || GetMonAbility(&party[i]) == ABILITY_ELECTRIC_SURGE)) //Ally has Misty or Electric Surge { - *(gBattleStruct->AI_monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)) = i; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + BATTLE_PARTNER(battler)) = i; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); switchMon = FALSE; break; } @@ -329,7 +328,7 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) //Check if Active Pokemon can KO opponent instead of switching //Will still fall asleep, but take out opposing Pokemon first - if (AiExpectsToFaintPlayer()) + if (AiExpectsToFaintPlayer(battler)) switchMon = FALSE; //Checks to see if active Pokemon can do something against sleep @@ -337,56 +336,56 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) || monAbility == ABILITY_SHED_SKIN || monAbility == ABILITY_EARLY_BIRD) || holdEffect == (HOLD_EFFECT_CURE_SLP | HOLD_EFFECT_CURE_STATUS) - || HasMove(gActiveBattler, MOVE_SLEEP_TALK) - || (HasMoveEffect(gActiveBattler, MOVE_SNORE) && AI_GetTypeEffectiveness(MOVE_SNORE, gActiveBattler, opposingBattler) >= UQ_4_12(1.0)) - || (IsBattlerGrounded(gActiveBattler) - && (HasMove(gActiveBattler, MOVE_MISTY_TERRAIN) || HasMove(gActiveBattler, MOVE_ELECTRIC_TERRAIN))) + || HasMove(battler, MOVE_SLEEP_TALK) + || (HasMoveEffect(battler, MOVE_SNORE) && AI_GetTypeEffectiveness(MOVE_SNORE, battler, opposingBattler) >= UQ_4_12(1.0)) + || (IsBattlerGrounded(battler) + && (HasMove(battler, MOVE_MISTY_TERRAIN) || HasMove(battler, MOVE_ELECTRIC_TERRAIN))) ) switchMon = FALSE; //Check if Active Pokemon evasion boosted and might be able to dodge until awake - if (gBattleMons[gActiveBattler].statStages[STAT_EVASION] > (DEFAULT_STAT_STAGE + 3) + if (gBattleMons[battler].statStages[STAT_EVASION] > (DEFAULT_STAT_STAGE + 3) && AI_DATA->abilities[opposingBattler] != ABILITY_UNAWARE && AI_DATA->abilities[opposingBattler] != ABILITY_KEEN_EYE - && !(gBattleMons[gActiveBattler].status2 & STATUS2_FORESIGHT) - && !(gStatuses3[gActiveBattler] & STATUS3_MIRACLE_EYED)) + && !(gBattleMons[battler].status2 & STATUS2_FORESIGHT) + && !(gStatuses3[battler] & STATUS3_MIRACLE_EYED)) switchMon = FALSE; } //Secondary Damage if (monAbility != ABILITY_MAGIC_GUARD - && !AiExpectsToFaintPlayer()) + && !AiExpectsToFaintPlayer(battler)) { //Toxic moduloChance = 2; //50% - if (((gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_COUNTER) >= STATUS1_TOXIC_TURN(2)) - && gBattleMons[gActiveBattler].hp >= (gBattleMons[gActiveBattler].maxHP / 3) + if (((gBattleMons[battler].status1 & STATUS1_TOXIC_COUNTER) >= STATUS1_TOXIC_TURN(2)) + && gBattleMons[battler].hp >= (gBattleMons[battler].maxHP / 3) && (Random() % (moduloChance*chanceReducer)) == 0) switchMon = TRUE; //Cursed moduloChance = 2; //50% - if (gBattleMons[gActiveBattler].status2 & STATUS2_CURSED + if (gBattleMons[battler].status2 & STATUS2_CURSED && (Random() % (moduloChance*chanceReducer)) == 0) switchMon = TRUE; //Nightmare moduloChance = 3; //33.3% - if (gBattleMons[gActiveBattler].status2 & STATUS2_NIGHTMARE + if (gBattleMons[battler].status2 & STATUS2_NIGHTMARE && (Random() % (moduloChance*chanceReducer)) == 0) switchMon = TRUE; //Leech Seed moduloChance = 4; //25% - if (gStatuses3[gActiveBattler] & STATUS3_LEECHSEED + if (gStatuses3[battler] & STATUS3_LEECHSEED && (Random() % (moduloChance*chanceReducer)) == 0) switchMon = TRUE; } //Infatuation - if (gBattleMons[gActiveBattler].status2 & STATUS2_INFATUATION - && !AiExpectsToFaintPlayer()) + if (gBattleMons[battler].status2 & STATUS2_INFATUATION + && !AiExpectsToFaintPlayer(battler)) switchMon = TRUE; //Todo @@ -395,22 +394,22 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) //Semi-Invulnerable if (gStatuses3[opposingBattler] & STATUS3_SEMI_INVULNERABLE) { - if (FindMonThatAbsorbsOpponentsMove()) //If find absorber default to switch + if (FindMonThatAbsorbsOpponentsMove(battler)) //If find absorber default to switch switchMon = TRUE; - if (!AI_OpponentCanFaintAiWithMod(0) - && AnyStatIsRaised(gActiveBattler)) + if (!AI_OpponentCanFaintAiWithMod(battler, 0) + && AnyStatIsRaised(battler)) switchMon = FALSE; - if (AiExpectsToFaintPlayer() + if (AiExpectsToFaintPlayer(battler) && !WillAIStrikeFirst() - && !AI_OpponentCanFaintAiWithMod(0)) + && !AI_OpponentCanFaintAiWithMod(battler, 0)) switchMon = FALSE; } } if (switchMon) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + battler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } else @@ -419,32 +418,31 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) } } -static bool8 ShouldSwitchIfAbilityBenefit(void) +static bool8 ShouldSwitchIfAbilityBenefit(u32 battler) { s32 monToSwitchId; s32 moduloChance = 4; //25% Chance Default s32 chanceReducer = 1; //No Reduce default. Increase to reduce - u8 battlerId = GetBattlerPosition(gActiveBattler); - if (AnyStatIsRaised(battlerId)) + if (AnyStatIsRaised(battler)) chanceReducer = 5; // Reduce switchout probability by factor of 5 if setup //Check if ability is blocked - if (gStatuses3[gActiveBattler] & STATUS3_GASTRO_ACID + if (gStatuses3[battler] & STATUS3_GASTRO_ACID ||IsNeutralizingGasOnField()) return FALSE; - switch(AI_DATA->abilities[gActiveBattler]) { + switch(AI_DATA->abilities[battler]) { case ABILITY_NATURAL_CURE: moduloChance = 4; //25% //Attempt to cure bad ailment - if (gBattleMons[gActiveBattler].status1 & (STATUS1_SLEEP | STATUS1_FREEZE | STATUS1_TOXIC_POISON) - && GetMostSuitableMonToSwitchInto() != PARTY_SIZE) + if (gBattleMons[battler].status1 & (STATUS1_SLEEP | STATUS1_FREEZE | STATUS1_TOXIC_POISON) + && GetMostSuitableMonToSwitchInto(battler) != PARTY_SIZE) break; //Attempt to cure lesser ailment - if ((gBattleMons[gActiveBattler].status1 & STATUS1_ANY) - && (gBattleMons[gActiveBattler].hp >= gBattleMons[gActiveBattler].maxHP / 2) - && GetMostSuitableMonToSwitchInto() != PARTY_SIZE + if ((gBattleMons[battler].status1 & STATUS1_ANY) + && (gBattleMons[battler].hp >= gBattleMons[battler].maxHP / 2) + && GetMostSuitableMonToSwitchInto(battler) != PARTY_SIZE && Random() % (moduloChance*chanceReducer) == 0) break; @@ -453,10 +451,10 @@ static bool8 ShouldSwitchIfAbilityBenefit(void) case ABILITY_REGENERATOR: moduloChance = 2; //50% //Don't switch if ailment - if (gBattleMons[gActiveBattler].status1 & STATUS1_ANY) + if (gBattleMons[battler].status1 & STATUS1_ANY) return FALSE; - if ((gBattleMons[gActiveBattler].hp <= ((gBattleMons[gActiveBattler].maxHP * 2) / 3)) - && GetMostSuitableMonToSwitchInto() != PARTY_SIZE + if ((gBattleMons[battler].hp <= ((gBattleMons[battler].maxHP * 2) / 3)) + && GetMostSuitableMonToSwitchInto(battler) != PARTY_SIZE && Random() % (moduloChance*chanceReducer) == 0) break; @@ -466,31 +464,31 @@ static bool8 ShouldSwitchIfAbilityBenefit(void) return FALSE; } - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + battler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } -static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) +static bool8 HasSuperEffectiveMoveAgainstOpponents(u32 battler, bool8 noRng) { u8 opposingPosition; u8 opposingBattler; s32 i; u16 move; - opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); + opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(battler)); opposingBattler = GetBattlerAtPosition(opposingPosition); if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { for (i = 0; i < MAX_MON_MOVES; i++) { - move = gBattleMons[gActiveBattler].moves[i]; + move = gBattleMons[battler].moves[i]; if (move == MOVE_NONE) continue; - if (AI_GetTypeEffectiveness(move, gActiveBattler, opposingBattler) >= UQ_4_12(2.0)) + if (AI_GetTypeEffectiveness(move, battler, opposingBattler) >= UQ_4_12(2.0)) { if (noRng) return TRUE; @@ -508,11 +506,11 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) { for (i = 0; i < MAX_MON_MOVES; i++) { - move = gBattleMons[gActiveBattler].moves[i]; + move = gBattleMons[battler].moves[i]; if (move == MOVE_NONE) continue; - if (AI_GetTypeEffectiveness(move, gActiveBattler, opposingBattler) >= UQ_4_12(2.0)) + if (AI_GetTypeEffectiveness(move, battler, opposingBattler) >= UQ_4_12(2.0)) { if (noRng) return TRUE; @@ -525,21 +523,21 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) return FALSE; } -static bool8 AreStatsRaised(void) +static bool8 AreStatsRaised(u32 battler) { u8 buffedStatsValue = 0; s32 i; for (i = 0; i < NUM_BATTLE_STATS; i++) { - if (gBattleMons[gActiveBattler].statStages[i] > DEFAULT_STAT_STAGE) - buffedStatsValue += gBattleMons[gActiveBattler].statStages[i] - DEFAULT_STAT_STAGE; + if (gBattleMons[battler].statStages[i] > DEFAULT_STAT_STAGE) + buffedStatsValue += gBattleMons[battler].statStages[i] - DEFAULT_STAT_STAGE; } return (buffedStatsValue > 3); } -static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) +static bool8 FindMonWithFlagsAndSuperEffective(u32 battler, u16 flags, u8 moduloPercent) { u8 battlerIn1, battlerIn2; s32 firstId; @@ -548,32 +546,32 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) s32 i, j; u16 move; - if (gLastLandedMoves[gActiveBattler] == MOVE_NONE) + if (gLastLandedMoves[battler] == MOVE_NONE) return FALSE; - if (gLastLandedMoves[gActiveBattler] == MOVE_UNAVAILABLE) + if (gLastLandedMoves[battler] == MOVE_UNAVAILABLE) return FALSE; - if (gLastHitBy[gActiveBattler] == 0xFF) + if (gLastHitBy[battler] == 0xFF) return FALSE; - if (IS_MOVE_STATUS(gLastLandedMoves[gActiveBattler])) + if (IS_MOVE_STATUS(gLastLandedMoves[battler])) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - battlerIn1 = gActiveBattler; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))]) + battlerIn2 = battler; else - battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))); } else { - battlerIn1 = gActiveBattler; - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + battlerIn2 = battler; } - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -592,15 +590,15 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (IsAceMon(gActiveBattler, i)) + if (IsAceMon(battler, i)) continue; species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG); monAbility = GetMonAbility(&party[i]); - CalcPartyMonTypeEffectivenessMultiplier(gLastLandedMoves[gActiveBattler], species, monAbility); + CalcPartyMonTypeEffectivenessMultiplier(gLastLandedMoves[battler], species, monAbility); if (gMoveResultFlags & flags) { - battlerIn1 = gLastHitBy[gActiveBattler]; + battlerIn1 = gLastHitBy[battler]; for (j = 0; j < MAX_MON_MOVES; j++) { @@ -608,10 +606,10 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) if (move == 0) continue; - if (AI_GetTypeEffectiveness(move, gActiveBattler, battlerIn1) >= UQ_4_12(2.0) && Random() % moduloPercent == 0) + if (AI_GetTypeEffectiveness(move, battler, battlerIn1) >= UQ_4_12(2.0) && Random() % moduloPercent == 0) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + battler) = i; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } } @@ -621,7 +619,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) return FALSE; } -bool32 ShouldSwitch(void) +bool32 ShouldSwitch(u32 battler) { u8 battlerIn1, battlerIn2; s32 firstId; @@ -631,11 +629,11 @@ bool32 ShouldSwitch(void) s32 availableToSwitch; bool32 hasAceMon = FALSE; - if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + if (gBattleMons[battler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) return FALSE; - if (gStatuses3[gActiveBattler] & STATUS3_ROOTED) + if (gStatuses3[battler] & STATUS3_ROOTED) return FALSE; - if (IsAbilityPreventingEscape(gActiveBattler)) + if (IsAbilityPreventingEscape(battler)) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_ARENA) return FALSE; @@ -644,21 +642,21 @@ bool32 ShouldSwitch(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - battlerIn1 = gActiveBattler; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))]) + battlerIn2 = battler; else - battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))); } else { - battlerIn1 = gActiveBattler; - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + battlerIn2 = battler; } - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -675,7 +673,7 @@ bool32 ShouldSwitch(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (IsAceMon(gActiveBattler, i)) + if (IsAceMon(battler, i)) { hasAceMon = TRUE; continue; @@ -696,69 +694,69 @@ bool32 ShouldSwitch(void) //Since the order is sequencial, and some of these functions prompt switch to specific party members. //These Functions can prompt switch to specific party members - if (ShouldSwitchIfWonderGuard()) + if (ShouldSwitchIfWonderGuard(battler)) return TRUE; - if (ShouldSwitchIfGameStatePrompt()) + if (ShouldSwitchIfGameStatePrompt(battler)) return TRUE; - if (FindMonThatAbsorbsOpponentsMove()) + if (FindMonThatAbsorbsOpponentsMove(battler)) return TRUE; //These Functions can prompt switch to generic pary members - if (ShouldSwitchIfAllBadMoves()) + if (ShouldSwitchIfAllBadMoves(battler)) return TRUE; - if (ShouldSwitchIfAbilityBenefit()) + if (ShouldSwitchIfAbilityBenefit(battler)) return TRUE; //Removing switch capabilites under specific conditions //These Functions prevent the "FindMonWithFlagsAndSuperEffective" from getting out of hand. - if (HasSuperEffectiveMoveAgainstOpponents(FALSE)) + if (HasSuperEffectiveMoveAgainstOpponents(battler, FALSE)) return FALSE; - if (AreStatsRaised()) + if (AreStatsRaised(battler)) return FALSE; //Default Function //Can prompt switch if AI has a pokemon in party that resists current opponent & has super effective move - if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_DOESNT_AFFECT_FOE, 2) - || FindMonWithFlagsAndSuperEffective(MOVE_RESULT_NOT_VERY_EFFECTIVE, 3)) + if (FindMonWithFlagsAndSuperEffective(battler, MOVE_RESULT_DOESNT_AFFECT_FOE, 2) + || FindMonWithFlagsAndSuperEffective(battler, MOVE_RESULT_NOT_VERY_EFFECTIVE, 3)) return TRUE; return FALSE; } -void AI_TrySwitchOrUseItem(void) +void AI_TrySwitchOrUseItem(u32 battler) { struct Pokemon *party; u8 battlerIn1, battlerIn2; s32 firstId; s32 lastId; // + 1 - u8 battlerIdentity = GetBattlerPosition(gActiveBattler); + u8 battlerPosition = GetBattlerPosition(battler); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - if (ShouldSwitch()) + if (ShouldSwitch(battler)) { - if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) == PARTY_SIZE) + if (*(gBattleStruct->AI_monToSwitchIntoId + battler) == PARTY_SIZE) { - s32 monToSwitchId = GetMostSuitableMonToSwitchInto(); + s32 monToSwitchId = GetMostSuitableMonToSwitchInto(battler); if (monToSwitchId == PARTY_SIZE) { if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - battlerIn1 = GetBattlerAtPosition(battlerIdentity); + battlerIn1 = GetBattlerAtPosition(battlerPosition); battlerIn2 = battlerIn1; } else { - battlerIn1 = GetBattlerAtPosition(battlerIdentity); - battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(battlerIdentity)); + battlerIn1 = GetBattlerAtPosition(battlerPosition); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(battlerPosition)); } - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); for (monToSwitchId = (lastId-1); monToSwitchId >= firstId; monToSwitchId--) { @@ -772,31 +770,31 @@ void AI_TrySwitchOrUseItem(void) continue; if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (IsAceMon(gActiveBattler, monToSwitchId)) + if (IsAceMon(battler, monToSwitchId)) continue; break; } } - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = monToSwitchId; + *(gBattleStruct->AI_monToSwitchIntoId + battler) = monToSwitchId; } - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler); + *(gBattleStruct->monToSwitchIntoId + battler) = *(gBattleStruct->AI_monToSwitchIntoId + battler); return; } - else if (ShouldUseItem()) + else if (ShouldUseItem(battler)) { return; } } - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, BATTLE_OPPOSITE(gActiveBattler) << 8); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_MOVE, BATTLE_OPPOSITE(battler) << 8); } // If there are two(or more) mons to choose from, always choose one that has baton pass // as most often it can't do much on its own. -static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, int aliveCount, u32 opposingBattler) +static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, int aliveCount, u32 battler, u32 opposingBattler) { int i, j, bits = 0; @@ -804,7 +802,7 @@ static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u { if (invalidMons & gBitTable[i]) continue; - if (IsAiPartyMonOHKOBy(opposingBattler, &party[i])) + if (IsAiPartyMonOHKOBy(battler, opposingBattler, &party[i])) continue; for (j = 0; j < MAX_MON_MOVES; j++) @@ -829,7 +827,7 @@ static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u return PARTY_SIZE; } -static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 opposingBattler) +static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 battler, u32 opposingBattler) { int i, bits = 0; @@ -850,7 +848,7 @@ static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, u8 defType1 = gSpeciesInfo[species].types[0]; u8 defType2 = gSpeciesInfo[species].types[1]; - if (IsAiPartyMonOHKOBy(opposingBattler, &party[i])) + if (IsAiPartyMonOHKOBy(battler, opposingBattler, &party[i])) continue; typeEffectiveness = uq4_12_multiply(typeEffectiveness, (GetTypeModifier(atkType1, defType1))); @@ -876,7 +874,7 @@ static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, for (i = 0; i < MAX_MON_MOVES; i++) { u32 move = GetMonData(&party[bestMonId], MON_DATA_MOVE1 + i); - if (move != MOVE_NONE && AI_GetTypeEffectiveness(move, gActiveBattler, opposingBattler) >= UQ_4_12(2.0)) + if (move != MOVE_NONE && AI_GetTypeEffectiveness(move, battler, opposingBattler) >= UQ_4_12(2.0)) break; } @@ -894,7 +892,7 @@ static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, return PARTY_SIZE; } -static u32 GetBestMonDmg(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 opposingBattler) +static u32 GetBestMonDmg(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 battler, u32 opposingBattler) { int i, j; int dmg, bestDmg = 0; @@ -906,10 +904,10 @@ static u32 GetBestMonDmg(struct Pokemon *party, int firstId, int lastId, u8 inva { if (gBitTable[i] & invalidMons) continue; - if (IsAiPartyMonOHKOBy(opposingBattler, &party[i])) + if (IsAiPartyMonOHKOBy(battler, opposingBattler, &party[i])) continue; - dmg = AI_CalcPartyMonBestMoveDamage(gActiveBattler, opposingBattler, &party[i], NULL); + dmg = AI_CalcPartyMonBestMoveDamage(battler, opposingBattler, &party[i], NULL); if (bestDmg < dmg) { bestDmg = dmg; @@ -920,7 +918,7 @@ static u32 GetBestMonDmg(struct Pokemon *party, int firstId, int lastId, u8 inva return bestMonId; } -u8 GetMostSuitableMonToSwitchInto(void) +u8 GetMostSuitableMonToSwitchInto(u32 battler) { u32 opposingBattler = 0; u32 bestMonId = PARTY_SIZE; @@ -931,18 +929,18 @@ u8 GetMostSuitableMonToSwitchInto(void) s32 i, j, aliveCount = 0; u32 invalidMons = 0, aceMonId = PARTY_SIZE; - if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != PARTY_SIZE) - return *(gBattleStruct->monToSwitchIntoId + gActiveBattler); + if (*(gBattleStruct->monToSwitchIntoId + battler) != PARTY_SIZE) + return *(gBattleStruct->monToSwitchIntoId + battler); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) - return gBattlerPartyIndexes[gActiveBattler] + 1; + return gBattlerPartyIndexes[battler] + 1; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - battlerIn1 = gActiveBattler; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - battlerIn2 = gActiveBattler; + battlerIn1 = battler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))]) + battlerIn2 = battler; else - battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))); opposingBattler = BATTLE_OPPOSITE(battlerIn1); if (gAbsentBattlerFlags & gBitTable[opposingBattler]) @@ -950,14 +948,14 @@ u8 GetMostSuitableMonToSwitchInto(void) } else { - opposingBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler))); - battlerIn1 = gActiveBattler; - battlerIn2 = gActiveBattler; + opposingBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battler))); + battlerIn1 = battler; + battlerIn2 = battler; } - GetAIPartyIndexes(gActiveBattler, &firstId, &lastId); + GetAIPartyIndexes(battler, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -970,11 +968,11 @@ u8 GetMostSuitableMonToSwitchInto(void) || gBattlerPartyIndexes[battlerIn2] == i || i == *(gBattleStruct->monToSwitchIntoId + battlerIn1) || i == *(gBattleStruct->monToSwitchIntoId + battlerIn2) - || (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(gActiveBattler, opposingBattler))) // While not really invalid per say, not really wise to switch into this mon.) + || (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(battler, opposingBattler))) // While not really invalid per say, not really wise to switch into this mon.) { invalidMons |= gBitTable[i]; } - else if (IsAceMon(gActiveBattler, i))// Save Ace Pokemon for last. + else if (IsAceMon(battler, i))// Save Ace Pokemon for last. { aceMonId = i; invalidMons |= gBitTable[i]; @@ -985,15 +983,15 @@ u8 GetMostSuitableMonToSwitchInto(void) } } - bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount, opposingBattler); + bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount, battler, opposingBattler); if (bestMonId != PARTY_SIZE) return bestMonId; - bestMonId = GetBestMonTypeMatchup(party, firstId, lastId, invalidMons, opposingBattler); + bestMonId = GetBestMonTypeMatchup(party, firstId, lastId, invalidMons, battler, opposingBattler); if (bestMonId != PARTY_SIZE) return bestMonId; - bestMonId = GetBestMonDmg(party, firstId, lastId, invalidMons, opposingBattler); + bestMonId = GetBestMonDmg(party, firstId, lastId, invalidMons, battler, opposingBattler); if (bestMonId != PARTY_SIZE) return bestMonId; @@ -1004,18 +1002,18 @@ u8 GetMostSuitableMonToSwitchInto(void) return PARTY_SIZE; } -static bool32 AiExpectsToFaintPlayer(void) +static bool32 AiExpectsToFaintPlayer(u32 battler) { bool32 canFaintPlayer; u32 i; - u8 target = gBattleStruct->aiChosenTarget[gActiveBattler]; + u8 target = gBattleStruct->aiChosenTarget[battler]; - if (gBattleStruct->aiMoveOrAction[gActiveBattler] > 3) + if (gBattleStruct->aiMoveOrAction[battler] > 3) return FALSE; // AI not planning to use move - if (GetBattlerSide(target) != GetBattlerSide(gActiveBattler) - && CanIndexMoveFaintTarget(gActiveBattler, target, gBattleStruct->aiMoveOrAction[gActiveBattler], 0) - && AI_WhoStrikesFirst(gActiveBattler, target, GetAIChosenMove(gActiveBattler)) == AI_IS_FASTER) { + if (GetBattlerSide(target) != GetBattlerSide(battler) + && CanIndexMoveFaintTarget(battler, target, gBattleStruct->aiMoveOrAction[battler], 0) + && AI_WhoStrikesFirst(battler, target, GetAIChosenMove(battler)) == AI_IS_FASTER) { // We expect to faint the target and move first -> dont use an item return TRUE; } @@ -1023,7 +1021,7 @@ static bool32 AiExpectsToFaintPlayer(void) return FALSE; } -static bool8 ShouldUseItem(void) +static bool8 ShouldUseItem(u32 battler) { struct Pokemon *party; s32 i; @@ -1034,17 +1032,17 @@ static bool8 ShouldUseItem(void) return FALSE; // If teaming up with player and Pokemon is on the right, or Pokemon is currently held by Sky Drop - if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT) - || gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED) + if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT) + || gStatuses3[battler] & STATUS3_SKY_DROPPED) return FALSE; - if (gStatuses3[gActiveBattler] & STATUS3_EMBARGO) + if (gStatuses3[battler] & STATUS3_EMBARGO) return FALSE; - if (AiExpectsToFaintPlayer()) + if (AiExpectsToFaintPlayer(battler)) return FALSE; - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -1074,48 +1072,48 @@ static bool8 ShouldUseItem(void) switch (ItemId_GetBattleUsage(item)) { case EFFECT_ITEM_HEAL_AND_CURE_STATUS: - shouldUse = AI_ShouldHeal(0); + shouldUse = AI_ShouldHeal(battler, 0); break; case EFFECT_ITEM_RESTORE_HP: - shouldUse = AI_ShouldHeal(itemEffects[GetItemEffectParamOffset(item, 4, ITEM4_HEAL_HP)]); + shouldUse = AI_ShouldHeal(battler, itemEffects[GetItemEffectParamOffset(battler, item, 4, ITEM4_HEAL_HP)]); break; case EFFECT_ITEM_CURE_STATUS: - if (itemEffects[3] & ITEM3_SLEEP && gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) + if (itemEffects[3] & ITEM3_SLEEP && gBattleMons[battler].status1 & STATUS1_SLEEP) shouldUse = TRUE; - if (itemEffects[3] & ITEM3_POISON && (gBattleMons[gActiveBattler].status1 & STATUS1_POISON - || gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_POISON)) + if (itemEffects[3] & ITEM3_POISON && (gBattleMons[battler].status1 & STATUS1_POISON + || gBattleMons[battler].status1 & STATUS1_TOXIC_POISON)) shouldUse = TRUE; - if (itemEffects[3] & ITEM3_BURN && gBattleMons[gActiveBattler].status1 & STATUS1_BURN) + if (itemEffects[3] & ITEM3_BURN && gBattleMons[battler].status1 & STATUS1_BURN) shouldUse = TRUE; - if (itemEffects[3] & ITEM3_FREEZE && (gBattleMons[gActiveBattler].status1 & STATUS1_FREEZE || gBattleMons[gActiveBattler].status1 & STATUS1_FROSTBITE)) + if (itemEffects[3] & ITEM3_FREEZE && (gBattleMons[battler].status1 & STATUS1_FREEZE || gBattleMons[battler].status1 & STATUS1_FROSTBITE)) shouldUse = TRUE; - if (itemEffects[3] & ITEM3_PARALYSIS && gBattleMons[gActiveBattler].status1 & STATUS1_PARALYSIS) + if (itemEffects[3] & ITEM3_PARALYSIS && gBattleMons[battler].status1 & STATUS1_PARALYSIS) shouldUse = TRUE; - if (itemEffects[3] & ITEM3_CONFUSION && gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION) + if (itemEffects[3] & ITEM3_CONFUSION && gBattleMons[battler].status2 & STATUS2_CONFUSION) shouldUse = TRUE; break; case EFFECT_ITEM_INCREASE_STAT: case EFFECT_ITEM_INCREASE_ALL_STATS: - if (!gDisableStructs[gActiveBattler].isFirstTurn - || AI_OpponentCanFaintAiWithMod(0)) + if (!gDisableStructs[battler].isFirstTurn + || AI_OpponentCanFaintAiWithMod(battler, 0)) break; shouldUse = TRUE; break; case EFFECT_ITEM_SET_FOCUS_ENERGY: - if (!gDisableStructs[gActiveBattler].isFirstTurn - || gBattleMons[gActiveBattler].status2 & STATUS2_FOCUS_ENERGY - || AI_OpponentCanFaintAiWithMod(0)) + if (!gDisableStructs[battler].isFirstTurn + || gBattleMons[battler].status2 & STATUS2_FOCUS_ENERGY + || AI_OpponentCanFaintAiWithMod(battler, 0)) break; shouldUse = TRUE; break; case EFFECT_ITEM_SET_MIST: - battlerSide = GetBattlerSide(gActiveBattler); - if (gDisableStructs[gActiveBattler].isFirstTurn && gSideTimers[battlerSide].mistTimer == 0) + battlerSide = GetBattlerSide(battler); + if (gDisableStructs[battler].isFirstTurn && gSideTimers[battlerSide].mistTimer == 0) shouldUse = TRUE; break; case EFFECT_ITEM_REVIVE: - gBattleStruct->itemPartyIndex[gActiveBattler] = GetFirstFaintedPartyIndex(gActiveBattler); - if (gBattleStruct->itemPartyIndex[gActiveBattler] != PARTY_SIZE) // Revive if possible. + gBattleStruct->itemPartyIndex[battler] = GetFirstFaintedPartyIndex(battler); + if (gBattleStruct->itemPartyIndex[battler] != PARTY_SIZE) // Revive if possible. shouldUse = TRUE; break; default: @@ -1124,11 +1122,11 @@ static bool8 ShouldUseItem(void) if (shouldUse) { // Set selected party ID to current battler if none chosen. - if (gBattleStruct->itemPartyIndex[gActiveBattler] == PARTY_SIZE) - gBattleStruct->itemPartyIndex[gActiveBattler] = gBattlerPartyIndexes[gActiveBattler]; - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); - gBattleStruct->chosenItem[gActiveBattler] = item; - gBattleResources->battleHistory->trainerItems[i] = ITEM_NONE; + if (gBattleStruct->itemPartyIndex[battler] == PARTY_SIZE) + gBattleStruct->itemPartyIndex[battler] = gBattlerPartyIndexes[battler]; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_ITEM, 0); + gBattleStruct->chosenItem[battler] = item; + gBattleResources->battleHistory->trainerItems[i] = 0; return shouldUse; } } @@ -1136,27 +1134,27 @@ static bool8 ShouldUseItem(void) return FALSE; } -static bool32 AI_ShouldHeal(u32 healAmount) +static bool32 AI_ShouldHeal(u32 battler, u32 healAmount) { bool32 shouldHeal = FALSE; - if (gBattleMons[gActiveBattler].hp < gBattleMons[gActiveBattler].maxHP / 4 - || gBattleMons[gActiveBattler].hp == 0 - || (healAmount != 0 && gBattleMons[gActiveBattler].maxHP - gBattleMons[gActiveBattler].hp > healAmount)) { + if (gBattleMons[battler].hp < gBattleMons[battler].maxHP / 4 + || gBattleMons[battler].hp == 0 + || (healAmount != 0 && gBattleMons[battler].maxHP - gBattleMons[battler].hp > healAmount)) { // We have low enough HP to consider healing - shouldHeal = !AI_OpponentCanFaintAiWithMod(healAmount); // if target can kill us even after we heal, why bother + shouldHeal = !AI_OpponentCanFaintAiWithMod(battler, healAmount); // if target can kill us even after we heal, why bother } return shouldHeal; } -static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount) +static bool32 AI_OpponentCanFaintAiWithMod(u32 battler, u32 healAmount) { u32 i; // Check special cases to NOT heal for (i = 0; i < gBattlersCount; i++) { if (GetBattlerSide(i) == B_SIDE_PLAYER) { - if (CanTargetFaintAiWithMod(i, gActiveBattler, healAmount, 0)) { + if (CanTargetFaintAiWithMod(i, battler, healAmount, 0)) { // Target is expected to faint us return TRUE; } @@ -1165,12 +1163,12 @@ static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount) return FALSE; } -static bool32 IsAiPartyMonOHKOBy(u32 battlerAtk, struct Pokemon *aiMon) +static bool32 IsAiPartyMonOHKOBy(u32 battlerAi, u32 battlerAtk, struct Pokemon *aiMon) { bool32 ret = FALSE; struct BattlePokemon *savedBattleMons; s32 hp = GetMonData(aiMon, MON_DATA_HP); - s32 bestDmg = AI_CalcPartyMonBestMoveDamage(battlerAtk, gActiveBattler, NULL, aiMon); + s32 bestDmg = AI_CalcPartyMonBestMoveDamage(battlerAtk, battlerAi, NULL, aiMon); switch (GetNoOfHitsToKO(bestDmg, hp)) { @@ -1179,8 +1177,8 @@ static bool32 IsAiPartyMonOHKOBy(u32 battlerAtk, struct Pokemon *aiMon) break; case 2: // if AI mon is faster allow 2 turns savedBattleMons = AllocSaveBattleMons(); - PokemonToBattleMon(aiMon, &gBattleMons[gActiveBattler]); - if (AI_WhoStrikesFirst(gActiveBattler, battlerAtk, 0) == AI_IS_SLOWER) + PokemonToBattleMon(aiMon, &gBattleMons[battlerAi]); + if (AI_WhoStrikesFirst(battlerAi, battlerAtk, 0) == AI_IS_SLOWER) ret = TRUE; else ret = FALSE; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 71fb0f108..5072645bd 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2563,14 +2563,11 @@ enum { bool32 ShouldPivot(u8 battlerAtk, u8 battlerDef, u16 defAbility, u16 move, u8 moveIndex) { bool8 hasStatBoost = AnyUsefulStatIsRaised(battlerAtk) || gBattleMons[battlerDef].statStages[STAT_EVASION] >= 9; //Significant boost in evasion for any class - u8 backupBattler = gActiveBattler; bool32 shouldSwitch; u8 battlerToSwitch; - gActiveBattler = battlerAtk; - shouldSwitch = ShouldSwitch(); - battlerToSwitch = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler); - gActiveBattler = backupBattler; + shouldSwitch = ShouldSwitch(battlerAtk); + battlerToSwitch = *(gBattleStruct->AI_monToSwitchIntoId + battlerAtk); if (PartyBattlerShouldAvoidHazards(battlerAtk, battlerToSwitch)) return DONT_PIVOT; @@ -3322,7 +3319,7 @@ bool32 ShouldUseWishAromatherapy(u8 battlerAtk, u8 battlerDef, u16 move) GetAIPartyIndexes(battlerAtk, &firstId, &lastId); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battlerAtk) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 4f1c3da97..3a3cb7e8c 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -370,7 +370,7 @@ static void LinkOpponentBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index c4b4e2112..4b8daeb1e 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -196,7 +196,7 @@ static void LinkPartnerBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index d439048eb..a74ca529b 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -387,7 +387,7 @@ static void OpponentBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -511,7 +511,7 @@ static void OpponentHandlePrintString(u32 battler) static void OpponentHandleChooseAction(u32 battler) { - AI_TrySwitchOrUseItem(); + AI_TrySwitchOrUseItem(battler); OpponentBufferExecCompleted(battler); } @@ -525,7 +525,7 @@ static void OpponentHandleChooseMove(u32 battler) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace(battler)); } else { @@ -534,16 +534,16 @@ static void OpponentHandleChooseMove(u32 battler) switch (chosenMoveId) { case AI_CHOICE_WATCH: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0); break; case AI_CHOICE_FLEE: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_RUN, 0); break; case AI_CHOICE_SWITCH: - BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, 0xFFFF); break; case 6: - BtlController_EmitTwoReturnValues(BUFFER_B, 15, gBattlerTarget); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 15, gBattlerTarget); break; default: { @@ -560,11 +560,11 @@ static void OpponentHandleChooseMove(u32 battler) if (ShouldUseZMove(battler, gBattlerTarget, chosenMove)) QueueZMove(battler, chosenMove); if (CanMegaEvolve(battler)) // If opponent can mega evolve, do it. - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); - else if (CanUltraBurst(gActiveBattler)) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_ULTRA_BURST) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); + else if (CanUltraBurst(battler)) + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_ULTRA_BURST) | (gBattlerTarget << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); } break; } @@ -582,7 +582,7 @@ static void OpponentHandleChooseMove(u32 battler) } while (move == MOVE_NONE); if (GetBattlerMoveTargetType(battler, move) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER)) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (battler << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (battler << 8)); else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { do { @@ -616,16 +616,16 @@ static void OpponentHandleChooseMove(u32 battler) } } if (isPartnerEnemy && CanTargetBattler(battler, target, move)) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(battler)) << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(battler)) << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else #endif - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); OpponentBufferExecCompleted(battler); } @@ -633,7 +633,7 @@ static void OpponentHandleChooseMove(u32 battler) static void OpponentHandleChooseItem(u32 battler) { - BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[battler]); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gBattleStruct->chosenItem[battler]); OpponentBufferExecCompleted(battler); } @@ -650,7 +650,7 @@ static void OpponentHandleChoosePokemon(u32 battler) // Switching out else if (*(gBattleStruct->AI_monToSwitchIntoId + battler) == PARTY_SIZE) { - chosenMonId = GetMostSuitableMonToSwitchInto(); + chosenMonId = GetMostSuitableMonToSwitchInto(battler); if (chosenMonId == PARTY_SIZE) { s32 battler1, battler2, firstId, lastId; @@ -689,7 +689,7 @@ static void OpponentHandleChoosePokemon(u32 battler) *(gBattleStruct->AI_monToSwitchIntoId + battler) = PARTY_SIZE; *(gBattleStruct->monToSwitchIntoId + battler) = chosenMonId; } - BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, chosenMonId, NULL); OpponentBufferExecCompleted(battler); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index ba0aac220..79de66952 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -173,7 +173,7 @@ static void PlayerBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -303,7 +303,7 @@ static void HandleInputChooseAction(u32 battler) PlaySE(SE_SELECT); ArrowsChangeColorLastBallCycle(FALSE); TryHideLastUsedBall(); - BtlController_EmitTwoReturnValues(1, B_ACTION_THROW_BALL, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_THROW_BALL, 0); PlayerBufferExecCompleted(battler); } return; @@ -318,16 +318,16 @@ static void HandleInputChooseAction(u32 battler) switch (gActionSelectionCursor[battler]) { case 0: // Top left - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_MOVE, 0); break; case 1: // Top right - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_ITEM, 0); break; case 2: // Bottom left - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SWITCH, 0); break; case 3: // Bottom right - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_RUN, 0); break; } PlayerBufferExecCompleted(battler); @@ -385,7 +385,7 @@ static void HandleInputChooseAction(u32 battler) AddBagItem(itemId, 1); } PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_CANCEL_PARTNER, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_CANCEL_PARTNER, 0); PlayerBufferExecCompleted(battler); } } @@ -396,7 +396,7 @@ static void HandleInputChooseAction(u32 battler) #if DEBUG_BATTLE_MENU == TRUE else if (JOY_NEW(SELECT_BUTTON)) { - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_DEBUG, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_DEBUG, 0); PlayerBufferExecCompleted(battler); } #endif @@ -405,7 +405,7 @@ static void HandleInputChooseAction(u32 battler) { PlaySE(SE_SELECT); TryHideLastUsedBall(); - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_THROW_BALL, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_THROW_BALL, 0); PlayerBufferExecCompleted(battler); } #endif @@ -435,11 +435,11 @@ static void HandleInputChooseTarget(u32 battler) PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCB_HideAsMoveTarget; if (gBattleStruct->mega.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else if (gBattleStruct->burst.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); TryHideLastUsedBall(); HideTriggerSprites(); @@ -595,11 +595,11 @@ static void HandleInputShowEntireFieldTargets(u32 battler) PlaySE(SE_SELECT); HideAllTargets(); if (gBattleStruct->mega.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else if (gBattleStruct->burst.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); HideTriggerSprites(); PlayerBufferExecCompleted(battler); } @@ -625,11 +625,11 @@ static void HandleInputShowTargets(u32 battler) PlaySE(SE_SELECT); HideShownTargets(battler); if (gBattleStruct->mega.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else if (gBattleStruct->burst.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); HideTriggerSprites(); TryHideLastUsedBall(); PlayerBufferExecCompleted(battler); @@ -644,12 +644,12 @@ static void HandleInputShowTargets(u32 battler) } } -static void TryShowAsTarget(u32 battlerId) +static void TryShowAsTarget(u32 battler) { - if (IsBattlerAlive(battlerId)) + if (IsBattlerAlive(battler)) { - DoBounceEffect(battlerId, BOUNCE_HEALTHBOX, 15, 1); - gSprites[gBattlerSpriteIds[battlerId]].callback = SpriteCB_ShowAsMoveTarget; + DoBounceEffect(battler, BOUNCE_HEALTHBOX, 15, 1); + gSprites[gBattlerSpriteIds[battler]].callback = SpriteCB_ShowAsMoveTarget; } } @@ -710,7 +710,7 @@ static void HandleInputChooseMove(u32 battler) { canSelectTarget = 0; } - else if (!(moveTarget & (MOVE_TARGET_USER | MOVE_TARGET_USER_OR_SELECTED)) && CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ACTIVE) <= 1) + else if (!(moveTarget & (MOVE_TARGET_USER | MOVE_TARGET_USER_OR_SELECTED)) && CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_BATTLER, battler) <= 1) { gMultiUsePlayerCursor = GetDefaultMoveTarget(battler); canSelectTarget = 0; @@ -742,11 +742,11 @@ static void HandleInputChooseMove(u32 battler) case 0: default: if (gBattleStruct->mega.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else if (gBattleStruct->burst.playerSelect) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | RET_ULTRA_BURST | (gMultiUsePlayerCursor << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, gMoveSelectionCursor[battler] | (gMultiUsePlayerCursor << 8)); HideTriggerSprites(); TryHideLastUsedBall(); PlayerBufferExecCompleted(battler); @@ -783,7 +783,7 @@ static void HandleInputChooseMove(u32 battler) gBattleStruct->mega.playerSelect = FALSE; gBattleStruct->burst.playerSelect = FALSE; gBattleStruct->zmove.viable = FALSE; - BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, 0xFFFF); HideTriggerSprites(); PlayerBufferExecCompleted(battler); } @@ -866,7 +866,7 @@ static void HandleInputChooseMove(u32 battler) ChangeMegaTriggerSprite(gBattleStruct->mega.triggerSpriteId, gBattleStruct->mega.playerSelect); PlaySE(SE_SELECT); } - else if (CanUltraBurst(gActiveBattler)) + else if (CanUltraBurst(battler)) { gBattleStruct->burst.playerSelect ^= 1; ChangeBurstTriggerSprite(gBattleStruct->burst.triggerSpriteId, gBattleStruct->burst.playerSelect); @@ -878,7 +878,7 @@ static void HandleInputChooseMove(u32 battler) //TODO: brighten z move symbol PlaySE(SE_SELECT); if (!gBattleStruct->zmove.viewing) - MoveSelectionDisplayZMove(gBattleStruct->zmove.chosenZMove); + MoveSelectionDisplayZMove(gBattleStruct->zmove.chosenZMove, battler); else ReloadMoveNames(battler); } @@ -1398,12 +1398,11 @@ static s32 GetTaskExpValue(u8 taskId) static void Task_GiveExpToMon(u8 taskId) { - u32 savedActiveBattler; u32 monId = (u8)(gTasks[taskId].tExpTask_monId); - u8 battlerId = gTasks[taskId].tExpTask_battler; + u8 battler = gTasks[taskId].tExpTask_battler; s32 gainedExp = GetTaskExpValue(taskId); - if (WhichBattleCoords(battlerId) == 1 || monId != gBattlerPartyIndexes[battlerId]) // Give exp without moving the expbar. + if (WhichBattleCoords(battler) == 1 || monId != gBattlerPartyIndexes[battler]) // Give exp without moving the expbar. { struct Pokemon *mon = &gPlayerParty[monId]; u16 species = GetMonData(mon, MON_DATA_SPECIES); @@ -1416,13 +1415,10 @@ static void Task_GiveExpToMon(u8 taskId) SetMonData(mon, MON_DATA_EXP, &nextLvlExp); CalculateMonStats(mon); gainedExp -= nextLvlExp - currExp; - savedActiveBattler = gActiveBattler; - gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); - gActiveBattler = savedActiveBattler; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); if (IsDoubleBattle() == TRUE - && (monId == gBattlerPartyIndexes[battlerId] || monId == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)])) + && (monId == gBattlerPartyIndexes[battler] || monId == gBattlerPartyIndexes[BATTLE_PARTNER(battler)])) gTasks[taskId].func = Task_LaunchLvlUpAnim; else gTasks[taskId].func = Task_SetControllerToWaitForString; @@ -1431,7 +1427,7 @@ static void Task_GiveExpToMon(u8 taskId) { currExp += gainedExp; SetMonData(mon, MON_DATA_EXP, &currExp); - gBattlerControllerFuncs[battlerId] = Controller_WaitForString; + gBattlerControllerFuncs[battler] = Controller_WaitForString; DestroyTask(taskId); } } @@ -1445,7 +1441,7 @@ static void Task_PrepareToGiveExpWithExpBar(u8 taskId) { u8 monIndex = gTasks[taskId].tExpTask_monId; s32 gainedExp = GetTaskExpValue(taskId); - u8 battlerId = gTasks[taskId].tExpTask_battler; + u8 battler = gTasks[taskId].tExpTask_battler; struct Pokemon *mon = &gPlayerParty[monIndex]; u8 level = GetMonData(mon, MON_DATA_LEVEL); u16 species = GetMonData(mon, MON_DATA_SPECIES); @@ -1455,7 +1451,7 @@ static void Task_PrepareToGiveExpWithExpBar(u8 taskId) exp -= currLvlExp; expToNextLvl = gExperienceTables[gSpeciesInfo[species].growthRate][level + 1] - currLvlExp; - SetBattleBarStruct(battlerId, gHealthboxSpriteIds[battlerId], expToNextLvl, exp, -gainedExp); + SetBattleBarStruct(battler, gHealthboxSpriteIds[battler], expToNextLvl, exp, -gainedExp); PlaySE(SE_EXP); gTasks[taskId].func = Task_GiveExpWithExpBar; } @@ -1474,10 +1470,10 @@ static void Task_GiveExpWithExpBar(u8 taskId) { u8 monId = gTasks[taskId].tExpTask_monId; s32 gainedExp = GetTaskExpValue(taskId); - u8 battlerId = gTasks[taskId].tExpTask_battler; + u8 battler = gTasks[taskId].tExpTask_battler; - newExpPoints = MoveBattleBar(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[battlerId]); + newExpPoints = MoveBattleBar(battler, gHealthboxSpriteIds[battler], EXP_BAR, 0); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[battler]); if (newExpPoints == -1) // The bar has been filled with given exp points. { m4aSongNumStop(SE_EXP); @@ -1488,22 +1484,17 @@ static void Task_GiveExpWithExpBar(u8 taskId) if (currExp + gainedExp >= expOnNextLvl) { - u8 savedActiveBattler; - SetMonData(&gPlayerParty[monId], MON_DATA_EXP, &expOnNextLvl); CalculateMonStats(&gPlayerParty[monId]); gainedExp -= expOnNextLvl - currExp; - savedActiveBattler = gActiveBattler; - gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); - gActiveBattler = savedActiveBattler; + BtlController_EmitTwoReturnValues(battler, BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); gTasks[taskId].func = Task_LaunchLvlUpAnim; } else { currExp += gainedExp; SetMonData(&gPlayerParty[monId], MON_DATA_EXP, &currExp); - gBattlerControllerFuncs[battlerId] = Controller_WaitForString; + gBattlerControllerFuncs[battler] = Controller_WaitForString; DestroyTask(taskId); } } @@ -1512,28 +1503,28 @@ static void Task_GiveExpWithExpBar(u8 taskId) static void Task_LaunchLvlUpAnim(u8 taskId) { - u8 battlerId = gTasks[taskId].tExpTask_battler; + u8 battler = gTasks[taskId].tExpTask_battler; u8 monIndex = gTasks[taskId].tExpTask_monId; - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) - battlerId ^= BIT_FLANK; + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battler)]) + battler ^= BIT_FLANK; - InitAndLaunchSpecialAnimation(battlerId, battlerId, battlerId, B_ANIM_LVL_UP); + InitAndLaunchSpecialAnimation(battler, battler, battler, B_ANIM_LVL_UP); gTasks[taskId].func = Task_UpdateLvlInHealthbox; } static void Task_UpdateLvlInHealthbox(u8 taskId) { - u8 battlerId = gTasks[taskId].tExpTask_battler; + u8 battler = gTasks[taskId].tExpTask_battler; - if (!gBattleSpritesDataPtr->healthBoxesData[battlerId].specialAnimActive) + if (!gBattleSpritesDataPtr->healthBoxesData[battler].specialAnimActive) { u8 monIndex = gTasks[taskId].tExpTask_monId; - if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]) - UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(battlerId)], &gPlayerParty[monIndex], HEALTHBOX_ALL); + if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[BATTLE_PARTNER(battler)]) + UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(battler)], &gPlayerParty[monIndex], HEALTHBOX_ALL); else - UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId], &gPlayerParty[monIndex], HEALTHBOX_ALL); + UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], &gPlayerParty[monIndex], HEALTHBOX_ALL); gTasks[taskId].func = Task_SetControllerToWaitForString; } @@ -1541,8 +1532,8 @@ static void Task_UpdateLvlInHealthbox(u8 taskId) static void Task_SetControllerToWaitForString(u8 taskId) { - u8 battlerId = gTasks[taskId].tExpTask_battler; - gBattlerControllerFuncs[battlerId] = Controller_WaitForString; + u8 battler = gTasks[taskId].tExpTask_battler; + gBattlerControllerFuncs[battler] = Controller_WaitForString; DestroyTask(taskId); } @@ -1565,9 +1556,9 @@ static void WaitForMonSelection(u32 battler) if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { if (gPartyMenuUseExitCallback == TRUE) - BtlController_EmitChosenMonReturnValue(BUFFER_B, gSelectedMonPartyId, gBattlePartyCurrentOrder); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, gSelectedMonPartyId, gBattlePartyCurrentOrder); else - BtlController_EmitChosenMonReturnValue(BUFFER_B, PARTY_SIZE, NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, PARTY_SIZE, NULL); if ((gBattleResources->bufferA[battler][1] & 0xF) == 1) PrintLinkStandbyMsg(); @@ -1591,7 +1582,7 @@ static void CompleteWhenChoseItem(u32 battler) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gSpecialVar_ItemId); PlayerBufferExecCompleted(battler); } } @@ -1618,9 +1609,9 @@ static void PlayerHandleYesNoInput(u32 battler) PlaySE(SE_SELECT); if (gMultiUsePlayerCursor != 0) - BtlController_EmitTwoReturnValues(BUFFER_B, 0xE, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 0xE, 0); else - BtlController_EmitTwoReturnValues(BUFFER_B, 0xD, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 0xD, 0); PlayerBufferExecCompleted(battler); } @@ -1663,7 +1654,7 @@ static void MoveSelectionDisplayPpNumber(u32 battler) if (gBattleResources->bufferA[battler][2] == TRUE) // check if we didn't want to display pp number return; - SetPpNumbersPaletteInMoveSelection(); + SetPpNumbersPaletteInMoveSelection(battler); moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); txtPtr = ConvertIntToDecimalStringN(gDisplayedStringBattle, moveInfo->currentPp[gMoveSelectionCursor[battler]], STR_CONV_MODE_RIGHT_ALIGN, 2); *(txtPtr)++ = CHAR_SLASH; @@ -1915,6 +1906,7 @@ static void PlayerHandleChooseAction(u32 battler) TryRestoreLastUsedBall(); ActionSelectionCreateCursorAt(gActionSelectionCursor[battler], 0); + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, battler, gBattlerPartyIndexes[battler]); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillPkmnDo); BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_ACTION_PROMPT); } @@ -1952,7 +1944,7 @@ static void PlayerChooseMoveInBattlePalace(u32 battler) if (--*(gBattleStruct->arenaMindPoints + battler) == 0) { gBattlePalaceMoveSelectionRngValue = gRngValue; - BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace(battler)); PlayerBufferExecCompleted(battler); } } @@ -2021,7 +2013,7 @@ static void PlayerHandleChoosePokemon(u32 battler) if (gBattleTypeFlags & BATTLE_TYPE_ARENA && (gBattleResources->bufferA[battler][1] & 0xF) != PARTY_ACTION_CANT_SWITCH && (gBattleResources->bufferA[battler][1] & 0xF) != PARTY_ACTION_CHOOSE_FAINTED_MON) { - BtlController_EmitChosenMonReturnValue(BUFFER_B, gBattlerPartyIndexes[battler] + 1, gBattlePartyCurrentOrder); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, gBattlerPartyIndexes[battler] + 1, gBattlePartyCurrentOrder); PlayerBufferExecCompleted(battler); } else @@ -2120,25 +2112,25 @@ static void PlayerHandlePlayBGM(u32 battler) static void PlayerHandleTwoReturnValues(u32 battler) { - BtlController_EmitTwoReturnValues(BUFFER_B, 0, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 0, 0); PlayerBufferExecCompleted(battler); } static void PlayerHandleChosenMonReturnValue(u32 battler) { - BtlController_EmitChosenMonReturnValue(BUFFER_B, 0, NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, 0, NULL); PlayerBufferExecCompleted(battler); } static void PlayerHandleOneReturnValue(u32 battler) { - BtlController_EmitOneReturnValue(BUFFER_B, 0); + BtlController_EmitOneReturnValue(battler, BUFFER_B, 0); PlayerBufferExecCompleted(battler); } static void PlayerHandleOneReturnValue_Duplicate(u32 battler) { - BtlController_EmitOneReturnValue_Duplicate(BUFFER_B, 0); + BtlController_EmitOneReturnValue_Duplicate(battler, BUFFER_B, 0); PlayerBufferExecCompleted(battler); } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 5a00d8cbd..44c10c55c 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -267,7 +267,7 @@ static void PlayerPartnerBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -346,7 +346,7 @@ static void PlayerPartnerHandlePrintString(u32 battler) static void PlayerPartnerHandleChooseAction(u32 battler) { - AI_TrySwitchOrUseItem(); + AI_TrySwitchOrUseItem(battler); PlayerPartnerBufferExecCompleted(battler); } @@ -360,7 +360,7 @@ static void PlayerPartnerHandleChooseMove(u32 battler) if (chosenMoveId == AI_CHOICE_SWITCH) { - BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, 0xFFFF); } else { @@ -378,11 +378,11 @@ static void PlayerPartnerHandleChooseMove(u32 battler) // If partner can mega evolve, do it. if (CanMegaEvolve(battler)) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); else if (CanUltraBurst(battler)) - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_ULTRA_BURST) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_ULTRA_BURST) | (gBattlerTarget << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); } PlayerPartnerBufferExecCompleted(battler); @@ -399,7 +399,7 @@ static void PlayerPartnerHandleChoosePokemon(u32 battler) // Switching out else if (gBattleStruct->monToSwitchIntoId[battler] == PARTY_SIZE) { - chosenMonId = GetMostSuitableMonToSwitchInto(); + chosenMonId = GetMostSuitableMonToSwitchInto(battler); if (chosenMonId == PARTY_SIZE) // just switch to the next mon { u8 playerMonIdentity = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); @@ -420,10 +420,10 @@ static void PlayerPartnerHandleChoosePokemon(u32 battler) else // Mon to switch out has been already chosen. { chosenMonId = gBattleStruct->monToSwitchIntoId[battler]; - *(gBattleStruct->AI_monToSwitchIntoId + battler) = PARTY_SIZE; - *(gBattleStruct->monToSwitchIntoId + battler) = chosenMonId; + gBattleStruct->AI_monToSwitchIntoId[battler] = PARTY_SIZE; + gBattleStruct->monToSwitchIntoId[battler] = chosenMonId; } - BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, chosenMonId, NULL); PlayerPartnerBufferExecCompleted(battler); } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 478970888..2443b56f7 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -140,7 +140,7 @@ static void RecordedOpponentBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -404,7 +404,7 @@ static void RecordedOpponentHandleDrawTrainerPic(u32 battler) } else { - trainerPicId = PlayerGenderToFrontTrainerPicId(GetActiveBattlerLinkPlayerGender()); + trainerPicId = PlayerGenderToFrontTrainerPicId(GetBattlerLinkPlayerGender(battler)); } } else @@ -442,7 +442,7 @@ static void RecordedOpponentHandlePrintString(u32 battler) gBattle_BG0_X = 0; gBattle_BG0_Y = 0; stringId = (u16 *)(&gBattleResources->bufferA[battler][2]); - BufferStringBattle(*stringId); + BufferStringBattle(*stringId, battler); if (gTestRunnerEnabled) { @@ -460,7 +460,7 @@ static void RecordedOpponentHandlePrintString(u32 battler) static void RecordedOpponentHandleChooseAction(u32 battler) { - BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_ACTION_TYPE, battler), 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_ACTION_TYPE, battler), 0); RecordedOpponentBufferExecCompleted(battler); } @@ -468,13 +468,13 @@ static void RecordedOpponentHandleChooseMove(u32 battler) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace(battler)); } else { u8 moveId = RecordedBattle_GetBattlerAction(RECORDED_MOVE_SLOT, battler); u8 target = RecordedBattle_GetBattlerAction(RECORDED_MOVE_TARGET, battler); - BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, moveId | (target << 8)); } RecordedOpponentBufferExecCompleted(battler); @@ -487,7 +487,7 @@ static void RecordedOpponentHandleChooseItem(u32 battler) gBattleStruct->chosenItem[battler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[battler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, battler); gBattleStruct->itemMoveIndex[battler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, battler); - BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[battler]); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gBattleStruct->chosenItem[battler]); RecordedOpponentBufferExecCompleted(battler); } @@ -495,7 +495,7 @@ static void RecordedOpponentHandleChoosePokemon(u32 battler) { *(gBattleStruct->monToSwitchIntoId + battler) = RecordedBattle_GetBattlerAction(RECORDED_PARTY_INDEX, battler); gSelectedMonPartyId = gBattleStruct->monToSwitchIntoId[battler]; // Revival Blessing - BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + battler), NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, *(gBattleStruct->monToSwitchIntoId + battler), NULL); RecordedOpponentBufferExecCompleted(battler); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index aac42824c..9c8acdbd1 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -346,7 +346,7 @@ static void RecordedPlayerBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -374,7 +374,7 @@ static void RecordedPlayerHandleDrawTrainerPic(u32 battler) if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - trainerPicId = GetActiveBattlerLinkPlayerGender(); + trainerPicId = GetBattlerLinkPlayerGender(battler); else trainerPicId = gLinkPlayers[gRecordedBattleMultiplayerId].gender; } @@ -432,7 +432,7 @@ static void RecordedPlayerHandlePrintString(u32 battler) gBattle_BG0_X = 0; gBattle_BG0_Y = 0; stringId = (u16 *)(&gBattleResources->bufferA[battler][2]); - BufferStringBattle(*stringId); + BufferStringBattle(*stringId, battler); if (gTestRunnerEnabled) { @@ -452,7 +452,7 @@ static void ChooseActionInBattlePalace(u32 battler) { if (gBattleCommunication[4] >= gBattlersCount / 2) { - BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_BATTLE_PALACE_ACTION, battler), 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_BATTLE_PALACE_ACTION, battler), 0); RecordedPlayerBufferExecCompleted(battler); } } @@ -465,7 +465,7 @@ static void RecordedPlayerHandleChooseAction(u32 battler) } else { - BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_ACTION_TYPE, battler), 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, RecordedBattle_GetBattlerAction(RECORDED_ACTION_TYPE, battler), 0); RecordedPlayerBufferExecCompleted(battler); } } @@ -474,13 +474,13 @@ static void RecordedPlayerHandleChooseMove(u32 battler) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace(battler)); } else { u8 moveId = RecordedBattle_GetBattlerAction(RECORDED_MOVE_SLOT, battler); u8 target = RecordedBattle_GetBattlerAction(RECORDED_MOVE_TARGET, battler); - BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8)); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, moveId | (target << 8)); } RecordedPlayerBufferExecCompleted(battler); @@ -493,7 +493,7 @@ static void RecordedPlayerHandleChooseItem(u32 battler) gBattleStruct->chosenItem[battler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[battler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, battler); gBattleStruct->itemMoveIndex[battler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, battler); - BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[battler]); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gBattleStruct->chosenItem[battler]); RecordedPlayerBufferExecCompleted(battler); } @@ -501,7 +501,7 @@ static void RecordedPlayerHandleChoosePokemon(u32 battler) { *(gBattleStruct->monToSwitchIntoId + battler) = RecordedBattle_GetBattlerAction(RECORDED_PARTY_INDEX, battler); gSelectedMonPartyId = gBattleStruct->monToSwitchIntoId[battler]; // Revival Blessing - BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + battler), NULL); + BtlController_EmitChosenMonReturnValue(battler, BUFFER_B, *(gBattleStruct->monToSwitchIntoId + battler), NULL); RecordedPlayerBufferExecCompleted(battler); } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 5f9183f1b..2069082d8 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -130,16 +130,16 @@ static void HandleInputChooseAction(u32 battler) switch (gActionSelectionCursor[battler]) { case 0: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_BALL, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SAFARI_BALL, 0); break; case 1: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_POKEBLOCK, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SAFARI_POKEBLOCK, 0); break; case 2: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_GO_NEAR, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SAFARI_GO_NEAR, 0); break; case 3: - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_RUN, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_SAFARI_RUN, 0); break; } SafariBufferExecCompleted(battler); @@ -216,7 +216,7 @@ static void CompleteWhenChosePokeblock(u32 battler) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gSpecialVar_ItemId); SafariBufferExecCompleted(battler); } } @@ -228,7 +228,7 @@ static void SafariBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index cff966567..a262886f4 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -149,7 +149,7 @@ static void WallyHandleActions(u32 battler) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_MOVE, 0); WallyBufferExecCompleted(battler); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -160,7 +160,7 @@ static void WallyHandleActions(u32 battler) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_MOVE, 0); WallyBufferExecCompleted(battler); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -170,7 +170,7 @@ static void WallyHandleActions(u32 battler) case 3: if (--gBattleStruct->wallyWaitFrames == 0) { - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_WALLY_THROW, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_WALLY_THROW, 0); WallyBufferExecCompleted(battler); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -191,7 +191,7 @@ static void WallyHandleActions(u32 battler) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, B_ACTION_USE_ITEM, 0); WallyBufferExecCompleted(battler); } break; @@ -213,7 +213,7 @@ static void CompleteOnChosenItem(u32 battler) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(battler, BUFFER_B, gSpecialVar_ItemId); WallyBufferExecCompleted(battler); } } @@ -283,7 +283,7 @@ static void WallyBufferExecCompleted(u32 battler) { u8 playerId = GetMultiplayerId(); - PrepareBufferDataTransferLink(2, 4, &playerId); + PrepareBufferDataTransferLink(battler, 2, 4, &playerId); gBattleResources->bufferA[battler][0] = CONTROLLER_TERMINATOR_NOP; } else @@ -382,7 +382,7 @@ static void WallyHandleChooseMove(u32 battler) if (--gBattleStruct->wallyMoveFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0x100); + BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, 0x100); WallyBufferExecCompleted(battler); } break; diff --git a/src/battle_controllers.c b/src/battle_controllers.c index bb2fc2905..7c835a241 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -27,7 +27,6 @@ static EWRAM_DATA u8 sLinkSendTaskId = 0; static EWRAM_DATA u8 sLinkReceiveTaskId = 0; EWRAM_DATA struct UnusedControllerStruct gUnusedControllerStruct = {}; // Debug? Unused code that writes to it, never read -static EWRAM_DATA u8 sBattleBuffersTransferData[0x100] = {}; void (*gBattlerControllerFuncs[MAX_BATTLERS_COUNT])(u32 battler); u8 gBattleControllerData[MAX_BATTLERS_COUNT]; // Used by the battle controllers to store misc sprite/task IDs for each battler @@ -680,13 +679,13 @@ static void SetBattlePartyIds(void) } } -static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size) +static void PrepareBufferDataTransfer(u32 battler, u32 bufferId, u8 *data, u16 size) { s32 i; if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - PrepareBufferDataTransferLink(bufferId, size, data); + PrepareBufferDataTransferLink(battler, bufferId, size, data); } else { @@ -694,11 +693,11 @@ static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size) { case BUFFER_A: for (i = 0; i < size; data++, i++) - gBattleResources->bufferA[gActiveBattler][i] = *data; + gBattleResources->bufferA[battler][i] = *data; break; case BUFFER_B: for (i = 0; i < size; data++, i++) - gBattleResources->bufferB[gActiveBattler][i] = *data; + gBattleResources->bufferB[battler][i] = *data; break; } } @@ -733,7 +732,7 @@ enum LINK_BUFF_DATA, }; -void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data) +void PrepareBufferDataTransferLink(u32 battler, u32 bufferId, u16 size, u8 *data) { s32 alignedSize; s32 i; @@ -745,7 +744,7 @@ void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data) gTasks[sLinkSendTaskId].data[14] = 0; } gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_BUFFER_ID] = bufferId; - gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ACTIVE_BATTLER] = gActiveBattler; + gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ACTIVE_BATTLER] = battler; gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ATTACKER] = gBattlerAttacker; gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_TARGET] = gBattlerTarget; gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_SIZE_LO] = alignedSize; @@ -927,191 +926,191 @@ static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId) } } -void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck) +void BtlController_EmitGetMonData(u32 battler, u32 bufferId, u8 requestId, u8 monToCheck) { - sBattleBuffersTransferData[0] = CONTROLLER_GETMONDATA; - sBattleBuffersTransferData[1] = requestId; - sBattleBuffersTransferData[2] = monToCheck; - sBattleBuffersTransferData[3] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_GETMONDATA; + gBattleResources->transferBuffer[1] = requestId; + gBattleResources->transferBuffer[2] = monToCheck; + gBattleResources->transferBuffer[3] = 0; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitGetRawMonData(u8 bufferId, u8 monId, u8 bytes) +static void BtlController_EmitGetRawMonData(u32 battler, u32 bufferId, u8 monId, u8 bytes) { - sBattleBuffersTransferData[0] = CONTROLLER_GETRAWMONDATA; - sBattleBuffersTransferData[1] = monId; - sBattleBuffersTransferData[2] = bytes; - sBattleBuffersTransferData[3] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_GETRAWMONDATA; + gBattleResources->transferBuffer[1] = monId; + gBattleResources->transferBuffer[2] = bytes; + gBattleResources->transferBuffer[3] = 0; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data) +void BtlController_EmitSetMonData(u32 battler, u32 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_SETMONDATA; - sBattleBuffersTransferData[1] = requestId; - sBattleBuffersTransferData[2] = monToCheck; + gBattleResources->transferBuffer[0] = CONTROLLER_SETMONDATA; + gBattleResources->transferBuffer[1] = requestId; + gBattleResources->transferBuffer[2] = monToCheck; for (i = 0; i < bytes; i++) - sBattleBuffersTransferData[3 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 3 + bytes); + gBattleResources->transferBuffer[3 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 3 + bytes); } // Unused -static void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data) +static void BtlController_EmitSetRawMonData(u32 battler, u32 bufferId, u8 monId, u8 bytes, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_SETRAWMONDATA; - sBattleBuffersTransferData[1] = monId; - sBattleBuffersTransferData[2] = bytes; + gBattleResources->transferBuffer[0] = CONTROLLER_SETRAWMONDATA; + gBattleResources->transferBuffer[1] = monId; + gBattleResources->transferBuffer[2] = bytes; for (i = 0; i < bytes; i++) - sBattleBuffersTransferData[3 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, bytes + 3); + gBattleResources->transferBuffer[3 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, bytes + 3); } -void BtlController_EmitLoadMonSprite(u8 bufferId) +void BtlController_EmitLoadMonSprite(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_LOADMONSPRITE; - sBattleBuffersTransferData[1] = CONTROLLER_LOADMONSPRITE; - sBattleBuffersTransferData[2] = CONTROLLER_LOADMONSPRITE; - sBattleBuffersTransferData[3] = CONTROLLER_LOADMONSPRITE; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_LOADMONSPRITE; + gBattleResources->transferBuffer[1] = CONTROLLER_LOADMONSPRITE; + gBattleResources->transferBuffer[2] = CONTROLLER_LOADMONSPRITE; + gBattleResources->transferBuffer[3] = CONTROLLER_LOADMONSPRITE; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit) +void BtlController_EmitSwitchInAnim(u32 battler, u32 bufferId, u8 partyId, bool8 dontClearSubstituteBit) { - sBattleBuffersTransferData[0] = CONTROLLER_SWITCHINANIM; - sBattleBuffersTransferData[1] = partyId; - sBattleBuffersTransferData[2] = dontClearSubstituteBit; - sBattleBuffersTransferData[3] = 5; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_SWITCHINANIM; + gBattleResources->transferBuffer[1] = partyId; + gBattleResources->transferBuffer[2] = dontClearSubstituteBit; + gBattleResources->transferBuffer[3] = 5; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitReturnMonToBall(u8 bufferId, bool8 skipAnim) +void BtlController_EmitReturnMonToBall(u32 battler, u32 bufferId, bool8 skipAnim) { - sBattleBuffersTransferData[0] = CONTROLLER_RETURNMONTOBALL; - sBattleBuffersTransferData[1] = skipAnim; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_RETURNMONTOBALL; + gBattleResources->transferBuffer[1] = skipAnim; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } -void BtlController_EmitDrawTrainerPic(u8 bufferId) +void BtlController_EmitDrawTrainerPic(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_DRAWTRAINERPIC; - sBattleBuffersTransferData[1] = CONTROLLER_DRAWTRAINERPIC; - sBattleBuffersTransferData[2] = CONTROLLER_DRAWTRAINERPIC; - sBattleBuffersTransferData[3] = CONTROLLER_DRAWTRAINERPIC; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_DRAWTRAINERPIC; + gBattleResources->transferBuffer[1] = CONTROLLER_DRAWTRAINERPIC; + gBattleResources->transferBuffer[2] = CONTROLLER_DRAWTRAINERPIC; + gBattleResources->transferBuffer[3] = CONTROLLER_DRAWTRAINERPIC; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitTrainerSlide(u8 bufferId) +void BtlController_EmitTrainerSlide(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_TRAINERSLIDE; - sBattleBuffersTransferData[1] = CONTROLLER_TRAINERSLIDE; - sBattleBuffersTransferData[2] = CONTROLLER_TRAINERSLIDE; - sBattleBuffersTransferData[3] = CONTROLLER_TRAINERSLIDE; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_TRAINERSLIDE; + gBattleResources->transferBuffer[1] = CONTROLLER_TRAINERSLIDE; + gBattleResources->transferBuffer[2] = CONTROLLER_TRAINERSLIDE; + gBattleResources->transferBuffer[3] = CONTROLLER_TRAINERSLIDE; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitTrainerSlideBack(u8 bufferId) +void BtlController_EmitTrainerSlideBack(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_TRAINERSLIDEBACK; - sBattleBuffersTransferData[1] = CONTROLLER_TRAINERSLIDEBACK; - sBattleBuffersTransferData[2] = CONTROLLER_TRAINERSLIDEBACK; - sBattleBuffersTransferData[3] = CONTROLLER_TRAINERSLIDEBACK; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_TRAINERSLIDEBACK; + gBattleResources->transferBuffer[1] = CONTROLLER_TRAINERSLIDEBACK; + gBattleResources->transferBuffer[2] = CONTROLLER_TRAINERSLIDEBACK; + gBattleResources->transferBuffer[3] = CONTROLLER_TRAINERSLIDEBACK; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitFaintAnimation(u8 bufferId) +void BtlController_EmitFaintAnimation(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_FAINTANIMATION; - sBattleBuffersTransferData[1] = CONTROLLER_FAINTANIMATION; - sBattleBuffersTransferData[2] = CONTROLLER_FAINTANIMATION; - sBattleBuffersTransferData[3] = CONTROLLER_FAINTANIMATION; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_FAINTANIMATION; + gBattleResources->transferBuffer[1] = CONTROLLER_FAINTANIMATION; + gBattleResources->transferBuffer[2] = CONTROLLER_FAINTANIMATION; + gBattleResources->transferBuffer[3] = CONTROLLER_FAINTANIMATION; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitPaletteFade(u8 bufferId) +static void BtlController_EmitPaletteFade(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_PALETTEFADE; - sBattleBuffersTransferData[1] = CONTROLLER_PALETTEFADE; - sBattleBuffersTransferData[2] = CONTROLLER_PALETTEFADE; - sBattleBuffersTransferData[3] = CONTROLLER_PALETTEFADE; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_PALETTEFADE; + gBattleResources->transferBuffer[1] = CONTROLLER_PALETTEFADE; + gBattleResources->transferBuffer[2] = CONTROLLER_PALETTEFADE; + gBattleResources->transferBuffer[3] = CONTROLLER_PALETTEFADE; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitSuccessBallThrowAnim(u8 bufferId) +static void BtlController_EmitSuccessBallThrowAnim(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_SUCCESSBALLTHROWANIM; - sBattleBuffersTransferData[1] = CONTROLLER_SUCCESSBALLTHROWANIM; - sBattleBuffersTransferData[2] = CONTROLLER_SUCCESSBALLTHROWANIM; - sBattleBuffersTransferData[3] = CONTROLLER_SUCCESSBALLTHROWANIM; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_SUCCESSBALLTHROWANIM; + gBattleResources->transferBuffer[1] = CONTROLLER_SUCCESSBALLTHROWANIM; + gBattleResources->transferBuffer[2] = CONTROLLER_SUCCESSBALLTHROWANIM; + gBattleResources->transferBuffer[3] = CONTROLLER_SUCCESSBALLTHROWANIM; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitBallThrowAnim(u8 bufferId, u8 caseId) +void BtlController_EmitBallThrowAnim(u32 battler, u32 bufferId, u8 caseId) { - sBattleBuffersTransferData[0] = CONTROLLER_BALLTHROWANIM; - sBattleBuffersTransferData[1] = caseId; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_BALLTHROWANIM; + gBattleResources->transferBuffer[1] = caseId; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } // Unused -static void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data) +static void BtlController_EmitPause(u32 battler, u32 bufferId, u8 toWait, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_PAUSE; - sBattleBuffersTransferData[1] = toWait; + gBattleResources->transferBuffer[0] = CONTROLLER_PAUSE; + gBattleResources->transferBuffer[1] = toWait; for (i = 0; i < toWait * 3; i++) - sBattleBuffersTransferData[2 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, toWait * 3 + 2); + gBattleResources->transferBuffer[2 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, toWait * 3 + 2); } -void BtlController_EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit) +void BtlController_EmitMoveAnimation(u32 battler, u32 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit) { - sBattleBuffersTransferData[0] = CONTROLLER_MOVEANIMATION; - sBattleBuffersTransferData[1] = move; - sBattleBuffersTransferData[2] = (move & 0xFF00) >> 8; - sBattleBuffersTransferData[3] = turnOfMove; - sBattleBuffersTransferData[4] = movePower; - sBattleBuffersTransferData[5] = (movePower & 0xFF00) >> 8; - sBattleBuffersTransferData[6] = dmg; - sBattleBuffersTransferData[7] = (dmg & 0x0000FF00) >> 8; - sBattleBuffersTransferData[8] = (dmg & 0x00FF0000) >> 16; - sBattleBuffersTransferData[9] = (dmg & 0xFF000000) >> 24; - sBattleBuffersTransferData[10] = friendship; - sBattleBuffersTransferData[11] = multihit; + gBattleResources->transferBuffer[0] = CONTROLLER_MOVEANIMATION; + gBattleResources->transferBuffer[1] = move; + gBattleResources->transferBuffer[2] = (move & 0xFF00) >> 8; + gBattleResources->transferBuffer[3] = turnOfMove; + gBattleResources->transferBuffer[4] = movePower; + gBattleResources->transferBuffer[5] = (movePower & 0xFF00) >> 8; + gBattleResources->transferBuffer[6] = dmg; + gBattleResources->transferBuffer[7] = (dmg & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[8] = (dmg & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[9] = (dmg & 0xFF000000) >> 24; + gBattleResources->transferBuffer[10] = friendship; + gBattleResources->transferBuffer[11] = multihit; if (WEATHER_HAS_EFFECT) { - sBattleBuffersTransferData[12] = gBattleWeather; - sBattleBuffersTransferData[13] = (gBattleWeather & 0xFF00) >> 8; + gBattleResources->transferBuffer[12] = gBattleWeather; + gBattleResources->transferBuffer[13] = (gBattleWeather & 0xFF00) >> 8; } else { - sBattleBuffersTransferData[12] = 0; - sBattleBuffersTransferData[13] = 0; + gBattleResources->transferBuffer[12] = 0; + gBattleResources->transferBuffer[13] = 0; } - sBattleBuffersTransferData[14] = 0; - sBattleBuffersTransferData[15] = 0; - memcpy(&sBattleBuffersTransferData[16], disableStructPtr, sizeof(struct DisableStruct)); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 16 + sizeof(struct DisableStruct)); + gBattleResources->transferBuffer[14] = 0; + gBattleResources->transferBuffer[15] = 0; + memcpy(&gBattleResources->transferBuffer[16], disableStructPtr, sizeof(struct DisableStruct)); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 16 + sizeof(struct DisableStruct)); } -void BtlController_EmitPrintString(u8 bufferId, u16 stringID) +void BtlController_EmitPrintString(u32 battler, u32 bufferId, u16 stringID) { s32 i; struct BattleMsgData *stringInfo; - sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRING; - sBattleBuffersTransferData[1] = gBattleOutcome; - sBattleBuffersTransferData[2] = stringID; - sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_PRINTSTRING; + gBattleResources->transferBuffer[1] = gBattleOutcome; + gBattleResources->transferBuffer[2] = stringID; + gBattleResources->transferBuffer[3] = (stringID & 0xFF00) >> 8; - stringInfo = (struct BattleMsgData *)(&sBattleBuffersTransferData[4]); + stringInfo = (struct BattleMsgData *)(&gBattleResources->transferBuffer[4]); stringInfo->currentMove = gCurrentMove; stringInfo->originallyUsedMove = gChosenMove; stringInfo->lastItem = gLastUsedItem; @@ -1130,20 +1129,20 @@ void BtlController_EmitPrintString(u8 bufferId, u16 stringID) stringInfo->textBuffs[1][i] = gBattleTextBuff2[i]; stringInfo->textBuffs[2][i] = gBattleTextBuff3[i]; } - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, sizeof(struct BattleMsgData) + 4); } -void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) +void BtlController_EmitPrintSelectionString(u32 battler, u32 bufferId, u16 stringID) { s32 i; struct BattleMsgData *stringInfo; - sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRINGPLAYERONLY; - sBattleBuffersTransferData[1] = CONTROLLER_PRINTSTRINGPLAYERONLY; - sBattleBuffersTransferData[2] = stringID; - sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_PRINTSTRINGPLAYERONLY; + gBattleResources->transferBuffer[1] = CONTROLLER_PRINTSTRINGPLAYERONLY; + gBattleResources->transferBuffer[2] = stringID; + gBattleResources->transferBuffer[3] = (stringID & 0xFF00) >> 8; - stringInfo = (struct BattleMsgData *)(&sBattleBuffersTransferData[4]); + stringInfo = (struct BattleMsgData *)(&gBattleResources->transferBuffer[4]); stringInfo->currentMove = gCurrentMove; stringInfo->originallyUsedMove = gChosenMove; stringInfo->lastItem = gLastUsedItem; @@ -1159,414 +1158,413 @@ void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) stringInfo->textBuffs[1][i] = gBattleTextBuff2[i]; stringInfo->textBuffs[2][i] = gBattleTextBuff3[i]; } - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, sizeof(struct BattleMsgData) + 4); } // itemId only relevant for B_ACTION_USE_ITEM -void BtlController_EmitChooseAction(u8 bufferId, u8 action, u16 itemId) +void BtlController_EmitChooseAction(u32 battler, u32 bufferId, u8 action, u16 itemId) { - sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEACTION; - sBattleBuffersTransferData[1] = action; - sBattleBuffersTransferData[2] = itemId; - sBattleBuffersTransferData[3] = (itemId & 0xFF00) >> 8; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_CHOOSEACTION; + gBattleResources->transferBuffer[1] = action; + gBattleResources->transferBuffer[2] = itemId; + gBattleResources->transferBuffer[3] = (itemId & 0xFF00) >> 8; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Only used by the forfeit prompt in the Battle Frontier // For other Yes/No boxes in battle, see Cmd_yesnobox -void BtlController_EmitYesNoBox(u8 bufferId) +void BtlController_EmitYesNoBox(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_YESNOBOX; - sBattleBuffersTransferData[1] = CONTROLLER_YESNOBOX; - sBattleBuffersTransferData[2] = CONTROLLER_YESNOBOX; - sBattleBuffersTransferData[3] = CONTROLLER_YESNOBOX; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_YESNOBOX; + gBattleResources->transferBuffer[1] = CONTROLLER_YESNOBOX; + gBattleResources->transferBuffer[2] = CONTROLLER_YESNOBOX; + gBattleResources->transferBuffer[3] = CONTROLLER_YESNOBOX; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitChooseMove(u8 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData) +void BtlController_EmitChooseMove(u32 battler, u32 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEMOVE; - sBattleBuffersTransferData[1] = isDoubleBattle; - sBattleBuffersTransferData[2] = NoPpNumber; - sBattleBuffersTransferData[3] = 0; + gBattleResources->transferBuffer[0] = CONTROLLER_CHOOSEMOVE; + gBattleResources->transferBuffer[1] = isDoubleBattle; + gBattleResources->transferBuffer[2] = NoPpNumber; + gBattleResources->transferBuffer[3] = 0; for (i = 0; i < sizeof(*movePpData); i++) - sBattleBuffersTransferData[4 + i] = *((u8 *)(movePpData) + i); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(*movePpData) + 4); + gBattleResources->transferBuffer[4 + i] = *((u8 *)(movePpData) + i); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, sizeof(*movePpData) + 4); } -void BtlController_EmitChooseItem(u8 bufferId, u8 *battlePartyOrder) +void BtlController_EmitChooseItem(u32 battler, u32 bufferId, u8 *battlePartyOrder) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_OPENBAG; + gBattleResources->transferBuffer[0] = CONTROLLER_OPENBAG; for (i = 0; i < PARTY_SIZE / 2; i++) - sBattleBuffersTransferData[1 + i] = battlePartyOrder[i]; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[1 + i] = battlePartyOrder[i]; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u16 abilityId, u8 *data) +void BtlController_EmitChoosePokemon(u32 battler, u32 bufferId, u8 caseId, u8 slotId, u16 abilityId, u8 *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEPOKEMON; - sBattleBuffersTransferData[1] = caseId; - sBattleBuffersTransferData[2] = slotId; - sBattleBuffersTransferData[3] = abilityId & 0xFF; - sBattleBuffersTransferData[7] = (abilityId >> 8) & 0xFF; + gBattleResources->transferBuffer[0] = CONTROLLER_CHOOSEPOKEMON; + gBattleResources->transferBuffer[1] = caseId; + gBattleResources->transferBuffer[2] = slotId; + gBattleResources->transferBuffer[3] = abilityId & 0xFF; + gBattleResources->transferBuffer[7] = (abilityId >> 8) & 0xFF; for (i = 0; i < 3; i++) - sBattleBuffersTransferData[4 + i] = data[i]; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // Only 7 bytes were written. + gBattleResources->transferBuffer[4 + i] = data[i]; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 8); // Only 7 bytes were written. } // Unused -static void BtlController_EmitCmd23(u8 bufferId) +static void BtlController_EmitCmd23(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_23; - sBattleBuffersTransferData[1] = CONTROLLER_23; - sBattleBuffersTransferData[2] = CONTROLLER_23; - sBattleBuffersTransferData[3] = CONTROLLER_23; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_23; + gBattleResources->transferBuffer[1] = CONTROLLER_23; + gBattleResources->transferBuffer[2] = CONTROLLER_23; + gBattleResources->transferBuffer[3] = CONTROLLER_23; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // why is the argument u16 if it's being cast to s16 anyway? -void BtlController_EmitHealthBarUpdate(u8 bufferId, u16 hpValue) +void BtlController_EmitHealthBarUpdate(u32 battler, u32 bufferId, u16 hpValue) { - sBattleBuffersTransferData[0] = CONTROLLER_HEALTHBARUPDATE; - sBattleBuffersTransferData[1] = 0; - sBattleBuffersTransferData[2] = (s16)hpValue; - sBattleBuffersTransferData[3] = ((s16)hpValue & 0xFF00) >> 8; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_HEALTHBARUPDATE; + gBattleResources->transferBuffer[1] = 0; + gBattleResources->transferBuffer[2] = (s16)hpValue; + gBattleResources->transferBuffer[3] = ((s16)hpValue & 0xFF00) >> 8; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitExpUpdate(u8 bufferId, u8 partyId, s32 expPoints) +void BtlController_EmitExpUpdate(u32 battler, u32 bufferId, u8 partyId, s32 expPoints) { - sBattleBuffersTransferData[0] = CONTROLLER_EXPUPDATE; - sBattleBuffersTransferData[1] = partyId; - sBattleBuffersTransferData[2] = expPoints; - sBattleBuffersTransferData[3] = (expPoints & 0x0000FF00) >> 8; - sBattleBuffersTransferData[4] = (expPoints & 0x00FF0000) >> 16; - sBattleBuffersTransferData[5] = (expPoints & 0xFF000000) >> 24; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 6); + gBattleResources->transferBuffer[0] = CONTROLLER_EXPUPDATE; + gBattleResources->transferBuffer[1] = partyId; + gBattleResources->transferBuffer[2] = expPoints; + gBattleResources->transferBuffer[3] = (expPoints & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[4] = (expPoints & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[5] = (expPoints & 0xFF000000) >> 24; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 6); } -void BtlController_EmitStatusIconUpdate(u8 bufferId, u32 status1, u32 status2) +void BtlController_EmitStatusIconUpdate(u32 battler, u32 bufferId, u32 status1, u32 status2) { - sBattleBuffersTransferData[0] = CONTROLLER_STATUSICONUPDATE; - sBattleBuffersTransferData[1] = status1; - sBattleBuffersTransferData[2] = (status1 & 0x0000FF00) >> 8; - sBattleBuffersTransferData[3] = (status1 & 0x00FF0000) >> 16; - sBattleBuffersTransferData[4] = (status1 & 0xFF000000) >> 24; - sBattleBuffersTransferData[5] = status2; - sBattleBuffersTransferData[6] = (status2 & 0x0000FF00) >> 8; - sBattleBuffersTransferData[7] = (status2 & 0x00FF0000) >> 16; - sBattleBuffersTransferData[8] = (status2 & 0xFF000000) >> 24; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 9); + gBattleResources->transferBuffer[0] = CONTROLLER_STATUSICONUPDATE; + gBattleResources->transferBuffer[1] = status1; + gBattleResources->transferBuffer[2] = (status1 & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[3] = (status1 & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[4] = (status1 & 0xFF000000) >> 24; + gBattleResources->transferBuffer[5] = status2; + gBattleResources->transferBuffer[6] = (status2 & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[7] = (status2 & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[8] = (status2 & 0xFF000000) >> 24; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 9); } -void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status) +void BtlController_EmitStatusAnimation(u32 battler, u32 bufferId, bool8 status2, u32 status) { - sBattleBuffersTransferData[0] = CONTROLLER_STATUSANIMATION; - sBattleBuffersTransferData[1] = status2; - sBattleBuffersTransferData[2] = status; - sBattleBuffersTransferData[3] = (status & 0x0000FF00) >> 8; - sBattleBuffersTransferData[4] = (status & 0x00FF0000) >> 16; - sBattleBuffersTransferData[5] = (status & 0xFF000000) >> 24; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 6); + gBattleResources->transferBuffer[0] = CONTROLLER_STATUSANIMATION; + gBattleResources->transferBuffer[1] = status2; + gBattleResources->transferBuffer[2] = status; + gBattleResources->transferBuffer[3] = (status & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[4] = (status & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[5] = (status & 0xFF000000) >> 24; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 6); } // Unused -static void BtlController_EmitStatusXor(u8 bufferId, u8 b) +static void BtlController_EmitStatusXor(u32 battler, u32 bufferId, u8 b) { - sBattleBuffersTransferData[0] = CONTROLLER_STATUSXOR; - sBattleBuffersTransferData[1] = b; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_STATUSXOR; + gBattleResources->transferBuffer[1] = b; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } -void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data) +void BtlController_EmitDataTransfer(u32 battler, u32 bufferId, u16 size, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_DATATRANSFER; - sBattleBuffersTransferData[1] = CONTROLLER_DATATRANSFER; - sBattleBuffersTransferData[2] = size; - sBattleBuffersTransferData[3] = (size & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_DATATRANSFER; + gBattleResources->transferBuffer[1] = CONTROLLER_DATATRANSFER; + gBattleResources->transferBuffer[2] = size; + gBattleResources->transferBuffer[3] = (size & 0xFF00) >> 8; for (i = 0; i < size; i++) - sBattleBuffersTransferData[4 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 4); + gBattleResources->transferBuffer[4 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, size + 4); } // Unused -static void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data) +static void BtlController_EmitDMA3Transfer(u32 battler, u32 bufferId, void *dst, u16 size, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_DMA3TRANSFER; - sBattleBuffersTransferData[1] = (u32)(dst); - sBattleBuffersTransferData[2] = ((u32)(dst) & 0x0000FF00) >> 8; - sBattleBuffersTransferData[3] = ((u32)(dst) & 0x00FF0000) >> 16; - sBattleBuffersTransferData[4] = ((u32)(dst) & 0xFF000000) >> 24; - sBattleBuffersTransferData[5] = size; - sBattleBuffersTransferData[6] = (size & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_DMA3TRANSFER; + gBattleResources->transferBuffer[1] = (u32)(dst); + gBattleResources->transferBuffer[2] = ((u32)(dst) & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[3] = ((u32)(dst) & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[4] = ((u32)(dst) & 0xFF000000) >> 24; + gBattleResources->transferBuffer[5] = size; + gBattleResources->transferBuffer[6] = (size & 0xFF00) >> 8; for (i = 0; i < size; i++) - sBattleBuffersTransferData[7 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 7); + gBattleResources->transferBuffer[7 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, size + 7); } // Unused -static void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data) +static void BtlController_EmitPlayBGM(u32 battler, u32 bufferId, u16 songId, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_PLAYBGM; - sBattleBuffersTransferData[1] = songId; - sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_PLAYBGM; + gBattleResources->transferBuffer[1] = songId; + gBattleResources->transferBuffer[2] = (songId & 0xFF00) >> 8; // Nonsense loop using songId as a size // Would go out of bounds for any song id after SE_RG_BAG_POCKET (253) for (i = 0; i < songId; i++) - sBattleBuffersTransferData[3 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, songId + 3); + gBattleResources->transferBuffer[3 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, songId + 3); } // Unused -static void BtlController_EmitCmd32(u8 bufferId, u16 size, void *data) +static void BtlController_EmitCmd32(u32 battler, u32 bufferId, u16 size, void *data) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_32; - sBattleBuffersTransferData[1] = size; - sBattleBuffersTransferData[2] = (size & 0xFF00) >> 8; + gBattleResources->transferBuffer[0] = CONTROLLER_32; + gBattleResources->transferBuffer[1] = size; + gBattleResources->transferBuffer[2] = (size & 0xFF00) >> 8; for (i = 0; i < size; i++) - sBattleBuffersTransferData[3 + i] = *(u8 *)(data++); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 3); + gBattleResources->transferBuffer[3 + i] = *(u8 *)(data++); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, size + 3); } -void BtlController_EmitTwoReturnValues(u8 bufferId, u8 ret8, u32 ret32) +void BtlController_EmitTwoReturnValues(u32 battler, u32 bufferId, u8 ret8, u32 ret32) { - sBattleBuffersTransferData[0] = CONTROLLER_TWORETURNVALUES; - sBattleBuffersTransferData[1] = ret8; - sBattleBuffersTransferData[2] = ret32; - sBattleBuffersTransferData[3] = (ret32 & 0x0000FF00) >> 8; - sBattleBuffersTransferData[4] = (ret32 & 0x00FF0000) >> 16; - sBattleBuffersTransferData[5] = (ret32 & 0xFF000000) >> 24; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 6); + gBattleResources->transferBuffer[0] = CONTROLLER_TWORETURNVALUES; + gBattleResources->transferBuffer[1] = ret8; + gBattleResources->transferBuffer[2] = ret32; + gBattleResources->transferBuffer[3] = (ret32 & 0x0000FF00) >> 8; + gBattleResources->transferBuffer[4] = (ret32 & 0x00FF0000) >> 16; + gBattleResources->transferBuffer[5] = (ret32 & 0xFF000000) >> 24; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 6); } -void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 partyId, u8 *battlePartyOrder) +void BtlController_EmitChosenMonReturnValue(u32 battler, u32 bufferId, u8 partyId, u8 *battlePartyOrder) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_CHOSENMONRETURNVALUE; - sBattleBuffersTransferData[1] = partyId; + gBattleResources->transferBuffer[0] = CONTROLLER_CHOSENMONRETURNVALUE; + gBattleResources->transferBuffer[1] = partyId; for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) - sBattleBuffersTransferData[2 + i] = battlePartyOrder[i]; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 5); + gBattleResources->transferBuffer[2 + i] = battlePartyOrder[i]; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 5); } -void BtlController_EmitOneReturnValue(u8 bufferId, u16 ret) +void BtlController_EmitOneReturnValue(u32 battler, u32 bufferId, u16 ret) { - sBattleBuffersTransferData[0] = CONTROLLER_ONERETURNVALUE; - sBattleBuffersTransferData[1] = ret; - sBattleBuffersTransferData[2] = (ret & 0xFF00) >> 8; - sBattleBuffersTransferData[3] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_ONERETURNVALUE; + gBattleResources->transferBuffer[1] = ret; + gBattleResources->transferBuffer[2] = (ret & 0xFF00) >> 8; + gBattleResources->transferBuffer[3] = 0; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitOneReturnValue_Duplicate(u8 bufferId, u16 ret) +void BtlController_EmitOneReturnValue_Duplicate(u32 battler, u32 bufferId, u16 ret) { - sBattleBuffersTransferData[0] = CONTROLLER_ONERETURNVALUE_DUPLICATE; - sBattleBuffersTransferData[1] = ret; - sBattleBuffersTransferData[2] = (ret & 0xFF00) >> 8; - sBattleBuffersTransferData[3] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_ONERETURNVALUE_DUPLICATE; + gBattleResources->transferBuffer[1] = ret; + gBattleResources->transferBuffer[2] = (ret & 0xFF00) >> 8; + gBattleResources->transferBuffer[3] = 0; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitClearUnkVar(u8 bufferId) +static void BtlController_EmitClearUnkVar(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_CLEARUNKVAR; - sBattleBuffersTransferData[1] = CONTROLLER_CLEARUNKVAR; - sBattleBuffersTransferData[2] = CONTROLLER_CLEARUNKVAR; - sBattleBuffersTransferData[3] = CONTROLLER_CLEARUNKVAR; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_CLEARUNKVAR; + gBattleResources->transferBuffer[1] = CONTROLLER_CLEARUNKVAR; + gBattleResources->transferBuffer[2] = CONTROLLER_CLEARUNKVAR; + gBattleResources->transferBuffer[3] = CONTROLLER_CLEARUNKVAR; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitSetUnkVar(u8 bufferId, u8 b) +static void BtlController_EmitSetUnkVar(u32 battler, u32 bufferId, u8 b) { - sBattleBuffersTransferData[0] = CONTROLLER_SETUNKVAR; - sBattleBuffersTransferData[1] = b; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_SETUNKVAR; + gBattleResources->transferBuffer[1] = b; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } // Unused -static void BtlController_EmitClearUnkFlag(u8 bufferId) +static void BtlController_EmitClearUnkFlag(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_CLEARUNKFLAG; - sBattleBuffersTransferData[1] = CONTROLLER_CLEARUNKFLAG; - sBattleBuffersTransferData[2] = CONTROLLER_CLEARUNKFLAG; - sBattleBuffersTransferData[3] = CONTROLLER_CLEARUNKFLAG; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_CLEARUNKFLAG; + gBattleResources->transferBuffer[1] = CONTROLLER_CLEARUNKFLAG; + gBattleResources->transferBuffer[2] = CONTROLLER_CLEARUNKFLAG; + gBattleResources->transferBuffer[3] = CONTROLLER_CLEARUNKFLAG; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // Unused -static void BtlController_EmitToggleUnkFlag(u8 bufferId) +static void BtlController_EmitToggleUnkFlag(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_TOGGLEUNKFLAG; - sBattleBuffersTransferData[1] = CONTROLLER_TOGGLEUNKFLAG; - sBattleBuffersTransferData[2] = CONTROLLER_TOGGLEUNKFLAG; - sBattleBuffersTransferData[3] = CONTROLLER_TOGGLEUNKFLAG; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_TOGGLEUNKFLAG; + gBattleResources->transferBuffer[1] = CONTROLLER_TOGGLEUNKFLAG; + gBattleResources->transferBuffer[2] = CONTROLLER_TOGGLEUNKFLAG; + gBattleResources->transferBuffer[3] = CONTROLLER_TOGGLEUNKFLAG; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitHitAnimation(u8 bufferId) +void BtlController_EmitHitAnimation(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_HITANIMATION; - sBattleBuffersTransferData[1] = CONTROLLER_HITANIMATION; - sBattleBuffersTransferData[2] = CONTROLLER_HITANIMATION; - sBattleBuffersTransferData[3] = CONTROLLER_HITANIMATION; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_HITANIMATION; + gBattleResources->transferBuffer[1] = CONTROLLER_HITANIMATION; + gBattleResources->transferBuffer[2] = CONTROLLER_HITANIMATION; + gBattleResources->transferBuffer[3] = CONTROLLER_HITANIMATION; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitCantSwitch(u8 bufferId) +void BtlController_EmitCantSwitch(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_CANTSWITCH; - sBattleBuffersTransferData[1] = CONTROLLER_CANTSWITCH; - sBattleBuffersTransferData[2] = CONTROLLER_CANTSWITCH; - sBattleBuffersTransferData[3] = CONTROLLER_CANTSWITCH; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_CANTSWITCH; + gBattleResources->transferBuffer[1] = CONTROLLER_CANTSWITCH; + gBattleResources->transferBuffer[2] = CONTROLLER_CANTSWITCH; + gBattleResources->transferBuffer[3] = CONTROLLER_CANTSWITCH; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitPlaySE(u8 bufferId, u16 songId) +void BtlController_EmitPlaySE(u32 battler, u32 bufferId, u16 songId) { - sBattleBuffersTransferData[0] = CONTROLLER_PLAYSE; - sBattleBuffersTransferData[1] = songId; - sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8; - sBattleBuffersTransferData[3] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_PLAYSE; + gBattleResources->transferBuffer[1] = songId; + gBattleResources->transferBuffer[2] = (songId & 0xFF00) >> 8; + gBattleResources->transferBuffer[3] = 0; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitPlayFanfareOrBGM(u8 bufferId, u16 songId, bool8 playBGM) +void BtlController_EmitPlayFanfareOrBGM(u32 battler, u32 bufferId, u16 songId, bool8 playBGM) { - sBattleBuffersTransferData[0] = CONTROLLER_PLAYFANFAREORBGM; - sBattleBuffersTransferData[1] = songId; - sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8; - sBattleBuffersTransferData[3] = playBGM; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_PLAYFANFAREORBGM; + gBattleResources->transferBuffer[1] = songId; + gBattleResources->transferBuffer[2] = (songId & 0xFF00) >> 8; + gBattleResources->transferBuffer[3] = playBGM; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitFaintingCry(u8 bufferId) +void BtlController_EmitFaintingCry(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_FAINTINGCRY; - sBattleBuffersTransferData[1] = CONTROLLER_FAINTINGCRY; - sBattleBuffersTransferData[2] = CONTROLLER_FAINTINGCRY; - sBattleBuffersTransferData[3] = CONTROLLER_FAINTINGCRY; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_FAINTINGCRY; + gBattleResources->transferBuffer[1] = CONTROLLER_FAINTINGCRY; + gBattleResources->transferBuffer[2] = CONTROLLER_FAINTINGCRY; + gBattleResources->transferBuffer[3] = CONTROLLER_FAINTINGCRY; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitIntroSlide(u8 bufferId, u8 terrainId) +void BtlController_EmitIntroSlide(u32 battler, u32 bufferId, u8 terrainId) { - sBattleBuffersTransferData[0] = CONTROLLER_INTROSLIDE; - sBattleBuffersTransferData[1] = terrainId; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_INTROSLIDE; + gBattleResources->transferBuffer[1] = terrainId; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } -void BtlController_EmitIntroTrainerBallThrow(u8 bufferId) +void BtlController_EmitIntroTrainerBallThrow(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_INTROTRAINERBALLTHROW; - sBattleBuffersTransferData[1] = CONTROLLER_INTROTRAINERBALLTHROW; - sBattleBuffersTransferData[2] = CONTROLLER_INTROTRAINERBALLTHROW; - sBattleBuffersTransferData[3] = CONTROLLER_INTROTRAINERBALLTHROW; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_INTROTRAINERBALLTHROW; + gBattleResources->transferBuffer[1] = CONTROLLER_INTROTRAINERBALLTHROW; + gBattleResources->transferBuffer[2] = CONTROLLER_INTROTRAINERBALLTHROW; + gBattleResources->transferBuffer[3] = CONTROLLER_INTROTRAINERBALLTHROW; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* hpAndStatus, u8 flags) +void BtlController_EmitDrawPartyStatusSummary(u32 battler, u32 bufferId, struct HpAndStatus* hpAndStatus, u8 flags) { s32 i; - sBattleBuffersTransferData[0] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; - sBattleBuffersTransferData[1] = flags & ~PARTY_SUMM_SKIP_DRAW_DELAY; // If true, skip player side - sBattleBuffersTransferData[2] = (flags & PARTY_SUMM_SKIP_DRAW_DELAY) >> 7; // If true, skip delay after drawing. True during intro - sBattleBuffersTransferData[3] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; + gBattleResources->transferBuffer[0] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; + gBattleResources->transferBuffer[1] = flags & ~PARTY_SUMM_SKIP_DRAW_DELAY; // If true, skip player side + gBattleResources->transferBuffer[2] = (flags & PARTY_SUMM_SKIP_DRAW_DELAY) >> 7; // If true, skip delay after drawing. True during intro + gBattleResources->transferBuffer[3] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; for (i = 0; i < (s32)(sizeof(struct HpAndStatus) * PARTY_SIZE); i++) - sBattleBuffersTransferData[4 + i] = *(i + (u8 *)(hpAndStatus)); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct HpAndStatus) * PARTY_SIZE + 4); + gBattleResources->transferBuffer[4 + i] = *(i + (u8 *)(hpAndStatus)); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, sizeof(struct HpAndStatus) * PARTY_SIZE + 4); } -void BtlController_EmitHidePartyStatusSummary(u8 bufferId) +void BtlController_EmitHidePartyStatusSummary(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; - sBattleBuffersTransferData[1] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; - sBattleBuffersTransferData[2] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; - sBattleBuffersTransferData[3] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + gBattleResources->transferBuffer[1] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + gBattleResources->transferBuffer[2] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + gBattleResources->transferBuffer[3] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitEndBounceEffect(u8 bufferId) +void BtlController_EmitEndBounceEffect(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_ENDBOUNCE; - sBattleBuffersTransferData[1] = CONTROLLER_ENDBOUNCE; - sBattleBuffersTransferData[2] = CONTROLLER_ENDBOUNCE; - sBattleBuffersTransferData[3] = CONTROLLER_ENDBOUNCE; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_ENDBOUNCE; + gBattleResources->transferBuffer[1] = CONTROLLER_ENDBOUNCE; + gBattleResources->transferBuffer[2] = CONTROLLER_ENDBOUNCE; + gBattleResources->transferBuffer[3] = CONTROLLER_ENDBOUNCE; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible) +void BtlController_EmitSpriteInvisibility(u32 battler, u32 bufferId, bool8 isInvisible) { - sBattleBuffersTransferData[0] = CONTROLLER_SPRITEINVISIBILITY; - sBattleBuffersTransferData[1] = isInvisible; - sBattleBuffersTransferData[2] = CONTROLLER_SPRITEINVISIBILITY; - sBattleBuffersTransferData[3] = CONTROLLER_SPRITEINVISIBILITY; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_SPRITEINVISIBILITY; + gBattleResources->transferBuffer[1] = isInvisible; + gBattleResources->transferBuffer[2] = CONTROLLER_SPRITEINVISIBILITY; + gBattleResources->transferBuffer[3] = CONTROLLER_SPRITEINVISIBILITY; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } -void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument) +void BtlController_EmitBattleAnimation(u32 battler, u32 bufferId, u8 animationId, u16 argument) { - sBattleBuffersTransferData[0] = CONTROLLER_BATTLEANIMATION; - sBattleBuffersTransferData[1] = animationId; - sBattleBuffersTransferData[2] = argument; - sBattleBuffersTransferData[3] = (argument & 0xFF00) >> 8; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); + gBattleResources->transferBuffer[0] = CONTROLLER_BATTLEANIMATION; + gBattleResources->transferBuffer[1] = animationId; + gBattleResources->transferBuffer[2] = argument; + gBattleResources->transferBuffer[3] = (argument & 0xFF00) >> 8; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 4); } // mode is a LINK_STANDBY_* constant -void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 mode, bool32 record) +void BtlController_EmitLinkStandbyMsg(u32 battler, u32 bufferId, u8 mode, bool32 record) { - bool8 record_ = record; - sBattleBuffersTransferData[0] = CONTROLLER_LINKSTANDBYMSG; - sBattleBuffersTransferData[1] = mode; + gBattleResources->transferBuffer[0] = CONTROLLER_LINKSTANDBYMSG; + gBattleResources->transferBuffer[1] = mode; - if (record_) - sBattleBuffersTransferData[3] = sBattleBuffersTransferData[2] = RecordedBattle_BufferNewBattlerData(&sBattleBuffersTransferData[4]); + if (record) + gBattleResources->transferBuffer[3] = gBattleResources->transferBuffer[2] = RecordedBattle_BufferNewBattlerData(&gBattleResources->transferBuffer[4]); else - sBattleBuffersTransferData[3] = sBattleBuffersTransferData[2] = 0; + gBattleResources->transferBuffer[3] = gBattleResources->transferBuffer[2] = 0; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sBattleBuffersTransferData[2] + 4); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, gBattleResources->transferBuffer[2] + 4); } -void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId) +void BtlController_EmitResetActionMoveSelection(u32 battler, u32 bufferId, u8 caseId) { - sBattleBuffersTransferData[0] = CONTROLLER_RESETACTIONMOVESELECTION; - sBattleBuffersTransferData[1] = caseId; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); + gBattleResources->transferBuffer[0] = CONTROLLER_RESETACTIONMOVESELECTION; + gBattleResources->transferBuffer[1] = caseId; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 2); } -void BtlController_EmitEndLinkBattle(u8 bufferId, u8 battleOutcome) +void BtlController_EmitEndLinkBattle(u32 battler, u32 bufferId, u8 battleOutcome) { - sBattleBuffersTransferData[0] = CONTROLLER_ENDLINKBATTLE; - sBattleBuffersTransferData[1] = battleOutcome; - sBattleBuffersTransferData[2] = gSaveBlock2Ptr->frontier.disableRecordBattle; - sBattleBuffersTransferData[3] = gSaveBlock2Ptr->frontier.disableRecordBattle; - sBattleBuffersTransferData[5] = sBattleBuffersTransferData[4] = RecordedBattle_BufferNewBattlerData(&sBattleBuffersTransferData[6]); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sBattleBuffersTransferData[4] + 6); + gBattleResources->transferBuffer[0] = CONTROLLER_ENDLINKBATTLE; + gBattleResources->transferBuffer[1] = battleOutcome; + gBattleResources->transferBuffer[2] = gSaveBlock2Ptr->frontier.disableRecordBattle; + gBattleResources->transferBuffer[3] = gSaveBlock2Ptr->frontier.disableRecordBattle; + gBattleResources->transferBuffer[5] = gBattleResources->transferBuffer[4] = RecordedBattle_BufferNewBattlerData(&gBattleResources->transferBuffer[6]); + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, gBattleResources->transferBuffer[4] + 6); } -void BtlController_EmitDebugMenu(u8 bufferId) +void BtlController_EmitDebugMenu(u32 battler, u32 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_DEBUGMENU; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 1); + gBattleResources->transferBuffer[0] = CONTROLLER_DEBUGMENU; + PrepareBufferDataTransfer(battler, bufferId, gBattleResources->transferBuffer, 1); } // Standardized Controller functions @@ -2133,7 +2131,7 @@ void StartSendOutAnim(u32 battler, bool32 dontClearSubstituteBit) gSprites[gBattleControllerData[battler]].data[1] = gBattlerSpriteIds[battler]; gSprites[gBattleControllerData[battler]].data[2] = battler; - gSprites[gBattleControllerData[battler]].data[0] = DoPokeballSendOutAnimation(0, (side == B_SIDE_OPPONENT) ? POKEBALL_OPPONENT_SENDOUT : POKEBALL_PLAYER_SENDOUT); + gSprites[gBattleControllerData[battler]].data[0] = DoPokeballSendOutAnimation(battler, 0, (side == B_SIDE_OPPONENT) ? POKEBALL_OPPONENT_SENDOUT : POKEBALL_PLAYER_SENDOUT); } static void FreeMonSprite(u32 battler) @@ -2372,7 +2370,7 @@ void BtlController_HandleGetMonData(u32 battler) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(BUFFER_B, size, monData); + BtlController_EmitDataTransfer(battler, BUFFER_B, size, monData); BattleControllerComplete(battler); } @@ -2388,7 +2386,7 @@ void BtlController_HandleGetRawMonData(u32 battler) for (i = 0; i < gBattleResources->bufferA[battler][2]; i++) dst[i] = src[i]; - BtlController_EmitDataTransfer(BUFFER_B, gBattleResources->bufferA[battler][2], dst); + BtlController_EmitDataTransfer(battler, BUFFER_B, gBattleResources->bufferA[battler][2], dst); BattleControllerComplete(battler); } @@ -2573,19 +2571,19 @@ void BtlController_HandleTrainerSlide(u32 battler, u32 trainerPicId) #undef sSpeedX -void BtlController_HandleTrainerSlideBack(u32 battlerId, s16 data0, bool32 startAnim) +void BtlController_HandleTrainerSlideBack(u32 battler, s16 data0, bool32 startAnim) { - u32 side = GetBattlerSide(battlerId); + u32 side = GetBattlerSide(battler); - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[battlerId]]); - gSprites[gBattlerSpriteIds[battlerId]].data[0] = data0; - gSprites[gBattlerSpriteIds[battlerId]].data[2] = (side == B_SIDE_PLAYER) ? -40 : 280; - gSprites[gBattlerSpriteIds[battlerId]].data[4] = gSprites[gBattlerSpriteIds[battlerId]].y; - gSprites[gBattlerSpriteIds[battlerId]].callback = StartAnimLinearTranslation; - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battlerId]], SpriteCallbackDummy); + SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[battler]]); + gSprites[gBattlerSpriteIds[battler]].data[0] = data0; + gSprites[gBattlerSpriteIds[battler]].data[2] = (side == B_SIDE_PLAYER) ? -40 : 280; + gSprites[gBattlerSpriteIds[battler]].data[4] = gSprites[gBattlerSpriteIds[battler]].y; + gSprites[gBattlerSpriteIds[battler]].callback = StartAnimLinearTranslation; + StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battler]], SpriteCallbackDummy); if (startAnim) - StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerId]], 1); - gBattlerControllerFuncs[battlerId] = Controller_HandleTrainerSlideBack; + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], 1); + gBattlerControllerFuncs[battler] = Controller_HandleTrainerSlideBack; } #define sSpeedX data[1] @@ -2678,7 +2676,7 @@ void BtlController_HandlePrintString(u32 battler, bool32 updateTvData, bool32 ar gBattle_BG0_X = 0; gBattle_BG0_Y = 0; stringId = (u16 *)(&gBattleResources->bufferA[battler][2]); - BufferStringBattle(*stringId); + BufferStringBattle(*stringId, battler); BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); gBattlerControllerFuncs[battler] = Controller_WaitForString; if (updateTvData) @@ -2735,7 +2733,7 @@ void BtlController_HandleStatusAnimation(u32 battler) { if (!IsBattleSEPlaying(battler)) { - InitAndLaunchChosenStatusAnimation(gBattleResources->bufferA[battler][1], + InitAndLaunchChosenStatusAnimation(battler, gBattleResources->bufferA[battler][1], gBattleResources->bufferA[battler][2] | (gBattleResources->bufferA[battler][3] << 8) | (gBattleResources->bufferA[battler][4] << 16) | (gBattleResources->bufferA[battler][5] << 24)); gBattlerControllerFuncs[battler] = Controller_WaitForStatusAnimation; } @@ -2939,26 +2937,25 @@ static void Task_StartSendOutAnim(u8 taskId) } else { - u8 savedActiveBattler = gActiveBattler; + u32 battlerPartner; + u32 battler = gTasks[taskId].tBattlerId; - gActiveBattler = gTasks[taskId].tBattlerId; - if (TwoMonsAtSendOut(gActiveBattler)) + if (TwoMonsAtSendOut(battler)) { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; + gBattleResources->bufferA[battler][1] = gBattlerPartyIndexes[battler]; + StartSendOutAnim(battler, FALSE); + + battlerPartner = battler ^ BIT_FLANK; + gBattleResources->bufferA[battlerPartner][1] = gBattlerPartyIndexes[battlerPartner]; + BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerPartner]], battlerPartner); + StartSendOutAnim(battlerPartner, FALSE); } else { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); + gBattleResources->bufferA[battler][1] = gBattlerPartyIndexes[battler]; + StartSendOutAnim(battler, FALSE); } - gBattlerControllerFuncs[gActiveBattler] = (void*)(GetWordTaskArg(taskId, tControllerFunc_1)); - gActiveBattler = savedActiveBattler; + gBattlerControllerFuncs[battler] = (void*)(GetWordTaskArg(taskId, tControllerFunc_1)); DestroyTask(taskId); } } diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 0dc464702..3bcbe3ae5 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -31,8 +31,8 @@ extern const struct CompressedSpriteSheet gSpriteSheet_EnemyShadow; extern const struct SpriteTemplate gSpriteTemplate_EnemyShadow; // this file's functions -static u8 GetBattlePalaceMoveGroup(u8 battlerId, u16 move); -static u16 GetBattlePalaceTarget(void); +static u8 GetBattlePalaceMoveGroup(u8 battler, u16 move); +static u16 GetBattlePalaceTarget(u32 battler); static void SpriteCB_TrainerSlideVertical(struct Sprite *sprite); static bool8 ShouldAnimBeDoneRegardlessOfSubstitute(u8 animId); static void Task_ClearBitWhenBattleTableAnimDone(u8 taskId); @@ -104,12 +104,12 @@ void FreeBattleSpritesData(void) } // Pokemon chooses move to use in Battle Palace rather than player -u16 ChooseMoveAndTargetInBattlePalace(void) +u16 ChooseMoveAndTargetInBattlePalace(u32 battler) { s32 i, var1, var2; s32 chosenMoveId = -1; - struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]); - u8 unusableMovesBits = CheckMoveLimitations(gActiveBattler, 0, MOVE_LIMITATIONS_ALL); + struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); + u8 unusableMovesBits = CheckMoveLimitations(battler, 0, MOVE_LIMITATIONS_ALL); s32 percent = Random() % 100; // Heavy variable re-use here makes this hard to read without defines @@ -125,7 +125,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) // If battler is < 50% HP and not asleep, use second set of move group likelihoods // otherwise use first set - i = (gBattleStruct->palaceFlags & gBitTable[gActiveBattler]) ? 2 : 0; + i = (gBattleStruct->palaceFlags & gBitTable[battler]) ? 2 : 0; minGroupNum = i; maxGroupNum = i + 2; // + 2 because there are two percentages per set of likelihoods @@ -136,7 +136,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) // Otherwise use move from "Support" group for (; i < maxGroupNum; i++) { - if (gBattlePalaceNatureToMoveGroupLikelihood[GetNatureFromPersonality(gBattleMons[gActiveBattler].personality)][i] > percent) + if (gBattlePalaceNatureToMoveGroupLikelihood[GetNatureFromPersonality(gBattleMons[battler].personality)][i] > percent) break; } selectedGroup = i - minGroupNum; @@ -148,7 +148,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) { if (moveInfo->moves[i] == MOVE_NONE) break; - if (selectedGroup == GetBattlePalaceMoveGroup(gActiveBattler, moveInfo->moves[i]) && moveInfo->currentPp[i] != 0) + if (selectedGroup == GetBattlePalaceMoveGroup(battler, moveInfo->moves[i]) && moveInfo->currentPp[i] != 0) selectedMoves |= gBitTable[i]; } @@ -159,8 +159,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) // Clear the rest of palaceFlags, then set the selected moves in the upper 4 bits. gBattleStruct->palaceFlags &= (1 << MAX_BATTLERS_COUNT) - 1; gBattleStruct->palaceFlags |= (selectedMoves << MAX_BATTLERS_COUNT); - sBattler_AI = gActiveBattler; - BattleAI_SetupAIData(selectedMoves); + BattleAI_SetupAIData(selectedMoves, battler); chosenMoveId = BattleAI_ChooseMoveOrAction(); } @@ -178,11 +177,11 @@ u16 ChooseMoveAndTargetInBattlePalace(void) { // Count the number of usable moves the battler has in each move group. // The totals will be stored separately in 3 groups of 4 bits each in numMovesPerGroup. - if (GetBattlePalaceMoveGroup(gActiveBattler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_ATTACK && !(gBitTable[i] & unusableMovesBits)) + if (GetBattlePalaceMoveGroup(battler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_ATTACK && !(gBitTable[i] & unusableMovesBits)) numMovesPerGroup += (1 << 0); - if (GetBattlePalaceMoveGroup(gActiveBattler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_DEFENSE && !(gBitTable[i] & unusableMovesBits)) + if (GetBattlePalaceMoveGroup(battler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_DEFENSE && !(gBitTable[i] & unusableMovesBits)) numMovesPerGroup += (1 << 4); - if (GetBattlePalaceMoveGroup(gActiveBattler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_SUPPORT && !(gBitTable[i] & unusableMovesBits)) + if (GetBattlePalaceMoveGroup(battler, moveInfo->moves[i]) == PALACE_MOVE_GROUP_SUPPORT && !(gBitTable[i] & unusableMovesBits)) numMovesPerGroup += (1 << 8); } @@ -241,7 +240,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) do { i = Random() % MAX_MON_MOVES; - if (!(gBitTable[i] & unusableMovesBits) && randSelectGroup == GetBattlePalaceMoveGroup(gActiveBattler, moveInfo->moves[i])) + if (!(gBitTable[i] & unusableMovesBits) && randSelectGroup == GetBattlePalaceMoveGroup(battler, moveInfo->moves[i])) chosenMoveId = i; } while (chosenMoveId == -1); } @@ -250,14 +249,14 @@ u16 ChooseMoveAndTargetInBattlePalace(void) // that it will be unable to use it. This could have been checked earlier to avoid the above work. if (Random() % 100 >= 50) { - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; return 0; } } else { // All the battler's moves were flagged as unusable. - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; return 0; } } @@ -271,15 +270,15 @@ u16 ChooseMoveAndTargetInBattlePalace(void) } else { - moveTarget = GetBattlerMoveTargetType(gActiveBattler, moveInfo->moves[chosenMoveId]); + moveTarget = GetBattlerMoveTargetType(battler, moveInfo->moves[chosenMoveId]); } if (moveTarget & MOVE_TARGET_USER) - chosenMoveId |= (gActiveBattler << 8); + chosenMoveId |= (battler << 8); else if (moveTarget == MOVE_TARGET_SELECTED) - chosenMoveId |= GetBattlePalaceTarget(); + chosenMoveId |= GetBattlePalaceTarget(battler); else - chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gActiveBattler))) << 8); + chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(battler))) << 8); return chosenMoveId; } @@ -293,9 +292,9 @@ u16 ChooseMoveAndTargetInBattlePalace(void) #undef numMultipleMoveGroups #undef randSelectGroup -static u8 GetBattlePalaceMoveGroup(u8 battlerId, u16 move) +static u8 GetBattlePalaceMoveGroup(u8 battler, u16 move) { - switch (GetBattlerMoveTargetType(battlerId, move)) + switch (GetBattlerMoveTargetType(battler, move)) { case MOVE_TARGET_SELECTED: case MOVE_TARGET_USER_OR_SELECTED: @@ -317,13 +316,13 @@ static u8 GetBattlePalaceMoveGroup(u8 battlerId, u16 move) } } -static u16 GetBattlePalaceTarget(void) +static u16 GetBattlePalaceTarget(u32 battler) { if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { u8 opposing1, opposing2; - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { opposing1 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); opposing2 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); @@ -335,9 +334,9 @@ static u16 GetBattlePalaceTarget(void) } if (gBattleMons[opposing1].hp == gBattleMons[opposing2].hp) - return (BATTLE_OPPOSITE(gActiveBattler & BIT_SIDE) + (Random() & 2)) << 8; + return (BATTLE_OPPOSITE(battler & BIT_SIDE) + (Random() & 2)) << 8; - switch (gBattlePalaceNatureToMoveTarget[GetNatureFromPersonality(gBattleMons[gActiveBattler].personality)]) + switch (gBattlePalaceNatureToMoveTarget[GetNatureFromPersonality(gBattleMons[battler].personality)]) { case PALACE_TARGET_STRONGER: if (gBattleMons[opposing1].hp > gBattleMons[opposing2].hp) @@ -350,11 +349,11 @@ static u16 GetBattlePalaceTarget(void) else return opposing2 << 8; case PALACE_TARGET_RANDOM: - return (BATTLE_OPPOSITE(gActiveBattler & BIT_SIDE) + (Random() & 2)) << 8; + return (BATTLE_OPPOSITE(battler & BIT_SIDE) + (Random() & 2)) << 8; } } - return BATTLE_OPPOSITE(gActiveBattler) << 8; + return BATTLE_OPPOSITE(battler) << 8; } // Wait for the pokemon to finish appearing out from the pokeball on send out @@ -418,38 +417,38 @@ static void SpriteCB_TrainerSlideVertical(struct Sprite *sprite) #undef sSpeedX -void InitAndLaunchChosenStatusAnimation(bool8 isStatus2, u32 status) +void InitAndLaunchChosenStatusAnimation(u32 battler, bool32 isStatus2, u32 status) { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].statusAnimActive = 1; + gBattleSpritesDataPtr->healthBoxesData[battler].statusAnimActive = 1; if (!isStatus2) { if (status == STATUS1_FREEZE || status == STATUS1_FROSTBITE) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_FRZ); + LaunchStatusAnimation(battler, B_ANIM_STATUS_FRZ); else if (status == STATUS1_POISON || status & STATUS1_TOXIC_POISON) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_PSN); + LaunchStatusAnimation(battler, B_ANIM_STATUS_PSN); else if (status == STATUS1_BURN) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_BRN); + LaunchStatusAnimation(battler, B_ANIM_STATUS_BRN); else if (status & STATUS1_SLEEP) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_SLP); + LaunchStatusAnimation(battler, B_ANIM_STATUS_SLP); else if (status == STATUS1_PARALYSIS) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_PRZ); + LaunchStatusAnimation(battler, B_ANIM_STATUS_PRZ); else // no animation - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].statusAnimActive = 0; + gBattleSpritesDataPtr->healthBoxesData[battler].statusAnimActive = 0; } else { if (status & STATUS2_INFATUATION) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_INFATUATION); + LaunchStatusAnimation(battler, B_ANIM_STATUS_INFATUATION); else if (status & STATUS2_CONFUSION) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_CONFUSION); + LaunchStatusAnimation(battler, B_ANIM_STATUS_CONFUSION); else if (status & STATUS2_CURSED) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_CURSED); + LaunchStatusAnimation(battler, B_ANIM_STATUS_CURSED); else if (status & STATUS2_NIGHTMARE) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_NIGHTMARE); + LaunchStatusAnimation(battler, B_ANIM_STATUS_NIGHTMARE); else if (status & STATUS2_WRAPPED) - LaunchStatusAnimation(gActiveBattler, B_ANIM_STATUS_WRAPPED); // this animation doesn't actually exist + LaunchStatusAnimation(battler, B_ANIM_STATUS_WRAPPED); // this animation doesn't actually exist else // no animation - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].statusAnimActive = 0; + gBattleSpritesDataPtr->healthBoxesData[battler].statusAnimActive = 0; } } @@ -546,14 +545,14 @@ static void Task_ClearBitWhenSpecialAnimDone(u8 taskId) #undef tBattlerId // Check if SE has finished or 30 calls, whichever comes first -bool8 IsBattleSEPlaying(u8 battlerId) +bool8 IsBattleSEPlaying(u8 battler) { u8 zero = 0; if (IsSEPlaying()) { - gBattleSpritesDataPtr->healthBoxesData[battlerId].soundTimer++; - if (gBattleSpritesDataPtr->healthBoxesData[battlerId].soundTimer < 30) + gBattleSpritesDataPtr->healthBoxesData[battler].soundTimer++; + if (gBattleSpritesDataPtr->healthBoxesData[battler].soundTimer < 30) return TRUE; m4aMPlayStop(&gMPlayInfo_SE1); @@ -561,7 +560,7 @@ bool8 IsBattleSEPlaying(u8 battlerId) } if (zero == 0) { - gBattleSpritesDataPtr->healthBoxesData[battlerId].soundTimer = 0; + gBattleSpritesDataPtr->healthBoxesData[battler].soundTimer = 0; return FALSE; } @@ -569,11 +568,11 @@ bool8 IsBattleSEPlaying(u8 battlerId) return TRUE; } -void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId) +void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battler) { u32 monsPersonality, currentPersonality, otId, currentOtId, species, paletteOffset, position; const void *lzPaletteData; - struct Pokemon *illusionMon = GetIllusionMonPtr(battlerId); + struct Pokemon *illusionMon = GetIllusionMonPtr(battler); if (illusionMon != NULL) mon = illusionMon; @@ -583,7 +582,7 @@ void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId) monsPersonality = GetMonData(mon, MON_DATA_PERSONALITY); otId = GetMonData(mon, MON_DATA_OT_ID); - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies == SPECIES_NONE) + if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies == SPECIES_NONE) { species = GetMonData(mon, MON_DATA_SPECIES); currentPersonality = monsPersonality; @@ -591,18 +590,18 @@ void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId) } else { - species = gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies; + species = gBattleSpritesDataPtr->battlerData[battler].transformSpecies; #if B_TRANSFORM_SHINY >= GEN_4 - currentPersonality = gTransformedPersonalities[battlerId]; - currentOtId = gTransformedOtIds[battlerId]; + currentPersonality = gTransformedPersonalities[battler]; + currentOtId = gTransformedOtIds[battler]; #else currentPersonality = monsPersonality; currentOtId = otId; #endif } - position = GetBattlerPosition(battlerId); - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) + position = GetBattlerPosition(battler); + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) { HandleLoadSpecialPokePic(TRUE, gMonSpritesGfxPtr->sprites.ptr[position], @@ -615,19 +614,19 @@ void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId) species, currentPersonality); } - paletteOffset = OBJ_PLTT_ID(battlerId); + paletteOffset = OBJ_PLTT_ID(battler); - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies == SPECIES_NONE) + if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies == SPECIES_NONE) lzPaletteData = GetMonFrontSpritePal(mon); else lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(species, currentOtId, currentPersonality); LZDecompressWram(lzPaletteData, gDecompressionBuffer); LoadPalette(gDecompressionBuffer, paletteOffset, PLTT_SIZE_4BPP); - LoadPalette(gDecompressionBuffer, BG_PLTT_ID(8) + BG_PLTT_ID(battlerId), PLTT_SIZE_4BPP); + LoadPalette(gDecompressionBuffer, BG_PLTT_ID(8) + BG_PLTT_ID(battler), PLTT_SIZE_4BPP); // transform's pink color - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) + if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies != SPECIES_NONE) { BlendPalette(paletteOffset, 16, 6, RGB_WHITE); CpuCopy32(&gPlttBufferFaded[paletteOffset], &gPlttBufferUnfaded[paletteOffset], PLTT_SIZEOF(16)); @@ -638,23 +637,23 @@ void BattleGfxSfxDummy2(u16 species) { } -void DecompressTrainerFrontPic(u16 frontPicId, u8 battlerId) +void DecompressTrainerFrontPic(u16 frontPicId, u8 battler) { - u8 position = GetBattlerPosition(battlerId); + u8 position = GetBattlerPosition(battler); DecompressPicFromTable(&gTrainerFrontPicTable[frontPicId], gMonSpritesGfxPtr->sprites.ptr[position], SPECIES_NONE); LoadCompressedSpritePalette(&gTrainerFrontPicPaletteTable[frontPicId]); } -void DecompressTrainerBackPic(u16 backPicId, u8 battlerId) +void DecompressTrainerBackPic(u16 backPicId, u8 battler) { - u8 position = GetBattlerPosition(battlerId); + u8 position = GetBattlerPosition(battler); DecompressPicFromTable(&gTrainerBackPicTable[backPicId], gMonSpritesGfxPtr->sprites.ptr[position], SPECIES_NONE); LoadCompressedPalette(gTrainerBackPicPaletteTable[backPicId].data, - OBJ_PLTT_ID(battlerId), PLTT_SIZE_4BPP); + OBJ_PLTT_ID(battler), PLTT_SIZE_4BPP); } void FreeTrainerFrontPicPalette(u16 frontPicId) @@ -754,7 +753,7 @@ void LoadBattleBarGfx(u8 unused) LZDecompressWram(gBattleInterfaceGfx_BattleBar, gMonSpritesGfxPtr->barFontGfx); } -bool8 BattleInitAllSprites(u8 *state1, u8 *battlerId) +bool8 BattleInitAllSprites(u8 *state1, u8 *battler) { bool8 retVal = FALSE; @@ -765,13 +764,13 @@ bool8 BattleInitAllSprites(u8 *state1, u8 *battlerId) (*state1)++; break; case 1: - if (!BattleLoadAllHealthBoxesGfx(*battlerId)) + if (!BattleLoadAllHealthBoxesGfx(*battler)) { - (*battlerId)++; + (*battler)++; } else { - *battlerId = 0; + *battler = 0; (*state1)++; } break; @@ -779,47 +778,47 @@ bool8 BattleInitAllSprites(u8 *state1, u8 *battlerId) (*state1)++; break; case 3: - if ((gBattleTypeFlags & BATTLE_TYPE_SAFARI) && *battlerId == 0) - gHealthboxSpriteIds[*battlerId] = CreateSafariPlayerHealthboxSprites(); + if ((gBattleTypeFlags & BATTLE_TYPE_SAFARI) && *battler == 0) + gHealthboxSpriteIds[*battler] = CreateSafariPlayerHealthboxSprites(); else - gHealthboxSpriteIds[*battlerId] = CreateBattlerHealthboxSprites(*battlerId); + gHealthboxSpriteIds[*battler] = CreateBattlerHealthboxSprites(*battler); - (*battlerId)++; - if (*battlerId == gBattlersCount) + (*battler)++; + if (*battler == gBattlersCount) { - *battlerId = 0; + *battler = 0; (*state1)++; } break; case 4: - InitBattlerHealthboxCoords(*battlerId); - if (gBattlerPositions[*battlerId] <= B_POSITION_OPPONENT_LEFT) - DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battlerId], FALSE); + InitBattlerHealthboxCoords(*battler); + if (gBattlerPositions[*battler] <= B_POSITION_OPPONENT_LEFT) + DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battler], FALSE); else - DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battlerId], TRUE); + DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battler], TRUE); - (*battlerId)++; - if (*battlerId == gBattlersCount) + (*battler)++; + if (*battler == gBattlersCount) { - *battlerId = 0; + *battler = 0; (*state1)++; } break; case 5: - if (GetBattlerSide(*battlerId) == B_SIDE_PLAYER) + if (GetBattlerSide(*battler) == B_SIDE_PLAYER) { if (!(gBattleTypeFlags & BATTLE_TYPE_SAFARI)) - UpdateHealthboxAttribute(gHealthboxSpriteIds[*battlerId], &gPlayerParty[gBattlerPartyIndexes[*battlerId]], HEALTHBOX_ALL); + UpdateHealthboxAttribute(gHealthboxSpriteIds[*battler], &gPlayerParty[gBattlerPartyIndexes[*battler]], HEALTHBOX_ALL); } else { - UpdateHealthboxAttribute(gHealthboxSpriteIds[*battlerId], &gEnemyParty[gBattlerPartyIndexes[*battlerId]], HEALTHBOX_ALL); + UpdateHealthboxAttribute(gHealthboxSpriteIds[*battler], &gEnemyParty[gBattlerPartyIndexes[*battler]], HEALTHBOX_ALL); } - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[*battlerId]); - (*battlerId)++; - if (*battlerId == gBattlersCount) + SetHealthboxSpriteInvisible(gHealthboxSpriteIds[*battler]); + (*battler)++; + if (*battler == gBattlersCount) { - *battlerId = 0; + *battler = 0; (*state1)++; } break; @@ -853,9 +852,9 @@ void CopyAllBattleSpritesInvisibilities(void) gBattleSpritesDataPtr->battlerData[i].invisible = gSprites[gBattlerSpriteIds[i]].invisible; } -void CopyBattleSpriteInvisibility(u8 battlerId) +void CopyBattleSpriteInvisibility(u8 battler) { - gBattleSpritesDataPtr->battlerData[battlerId].invisible = gSprites[gBattlerSpriteIds[battlerId]].invisible; + gBattleSpritesDataPtr->battlerData[battler].invisible = gSprites[gBattlerSpriteIds[battler]].invisible; } void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool32 megaEvo, bool8 trackEnemyPersonality) @@ -950,84 +949,85 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool32 megaEvo, bo StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerAtk]], 0); } -void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite) +void BattleLoadSubstituteOrMonSpriteGfx(u8 battler, bool8 loadMonSprite) { s32 i, position, palOffset; if (!loadMonSprite) { + if (IsContest()) position = B_POSITION_PLAYER_LEFT; else - position = GetBattlerPosition(battlerId); + position = GetBattlerPosition(battler); if (IsContest()) - LZDecompressVram(gSubstituteDollBackGfx, gMonSpritesGfxPtr->sprites.ptr[position]); - else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - LZDecompressVram(gSubstituteDollFrontGfx, gMonSpritesGfxPtr->sprites.ptr[position]); + LZDecompressVram(gBattleAnimSpriteGfx_SubstituteBack, gMonSpritesGfxPtr->sprites.ptr[position]); + else if (GetBattlerSide(battler) != B_SIDE_PLAYER) + LZDecompressVram(gBattleAnimSpriteGfx_Substitute, gMonSpritesGfxPtr->sprites.ptr[position]); else - LZDecompressVram(gSubstituteDollBackGfx, gMonSpritesGfxPtr->sprites.ptr[position]); + LZDecompressVram(gBattleAnimSpriteGfx_SubstituteBack, gMonSpritesGfxPtr->sprites.ptr[position]); for (i = 1; i < 4; i++) { Dma3CopyLarge32_(gMonSpritesGfxPtr->sprites.ptr[position], &gMonSpritesGfxPtr->sprites.byte[position][MON_PIC_SIZE * i], MON_PIC_SIZE); } - palOffset = OBJ_PLTT_ID(battlerId); - LoadCompressedPalette(gSubstituteDollPal, palOffset, PLTT_SIZE_4BPP); + palOffset = OBJ_PLTT_ID(battler); + LoadCompressedPalette(gBattleAnimSpritePal_Substitute, palOffset, PLTT_SIZE_4BPP); } else { if (!IsContest()) - BattleLoadMonSpriteGfx(&GetBattlerParty(battlerId)[gBattlerPartyIndexes[battlerId]], battlerId); + BattleLoadMonSpriteGfx(&GetBattlerParty(battler)[gBattlerPartyIndexes[battler]], battler); } } -void LoadBattleMonGfxAndAnimate(u8 battlerId, bool8 loadMonSprite, u8 spriteId) +void LoadBattleMonGfxAndAnimate(u8 battler, bool8 loadMonSprite, u8 spriteId) { - BattleLoadSubstituteOrMonSpriteGfx(battlerId, loadMonSprite); + BattleLoadSubstituteOrMonSpriteGfx(battler, loadMonSprite); StartSpriteAnim(&gSprites[spriteId], 0); if (!loadMonSprite) - gSprites[spriteId].y = GetSubstituteSpriteDefault_Y(battlerId); + gSprites[spriteId].y = GetSubstituteSpriteDefault_Y(battler); else - gSprites[spriteId].y = GetBattlerSpriteDefault_Y(battlerId); + gSprites[spriteId].y = GetBattlerSpriteDefault_Y(battler); } -void TrySetBehindSubstituteSpriteBit(u8 battlerId, u16 move) +void TrySetBehindSubstituteSpriteBit(u8 battler, u16 move) { if (move == MOVE_SUBSTITUTE) - gBattleSpritesDataPtr->battlerData[battlerId].behindSubstitute = 1; + gBattleSpritesDataPtr->battlerData[battler].behindSubstitute = 1; } -void ClearBehindSubstituteBit(u8 battlerId) +void ClearBehindSubstituteBit(u8 battler) { - gBattleSpritesDataPtr->battlerData[battlerId].behindSubstitute = 0; + gBattleSpritesDataPtr->battlerData[battler].behindSubstitute = 0; } -void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId) +void HandleLowHpMusicChange(struct Pokemon *mon, u8 battler) { u16 hp = GetMonData(mon, MON_DATA_HP); u16 maxHP = GetMonData(mon, MON_DATA_MAX_HP); if (GetHPBarLevel(hp, maxHP) == HP_BAR_RED) { - if (!gBattleSpritesDataPtr->battlerData[battlerId].lowHpSong) + if (!gBattleSpritesDataPtr->battlerData[battler].lowHpSong) { - if (!gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battlerId)].lowHpSong) + if (!gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battler)].lowHpSong) PlaySE(SE_LOW_HEALTH); - gBattleSpritesDataPtr->battlerData[battlerId].lowHpSong = 1; + gBattleSpritesDataPtr->battlerData[battler].lowHpSong = 1; } } else { - gBattleSpritesDataPtr->battlerData[battlerId].lowHpSong = 0; + gBattleSpritesDataPtr->battlerData[battler].lowHpSong = 0; if (!IsDoubleBattle()) { m4aSongNumStop(SE_LOW_HEALTH); return; } - if (IsDoubleBattle() && !gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battlerId)].lowHpSong) + if (IsDoubleBattle() && !gBattleSpritesDataPtr->battlerData[BATTLE_PARTNER(battler)].lowHpSong) { m4aSongNumStop(SE_LOW_HEALTH); return; @@ -1096,46 +1096,46 @@ void SetBattlerSpriteAffineMode(u8 affineMode) void LoadAndCreateEnemyShadowSprites(void) { - u8 battlerId; + u8 battler; LoadCompressedSpriteSheet(&gSpriteSheet_EnemyShadow); - battlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow, - GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X), - GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 29, + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow, + GetBattlerSpriteCoord(battler, BATTLER_COORD_X), + GetBattlerSpriteCoord(battler, BATTLER_COORD_Y) + 29, 0xC8); - gSprites[gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId].data[0] = battlerId; + gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].data[0] = battler; if (IsDoubleBattle()) { - battlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow, - GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X), - GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 29, + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow, + GetBattlerSpriteCoord(battler, BATTLER_COORD_X), + GetBattlerSpriteCoord(battler, BATTLER_COORD_Y) + 29, 0xC8); - gSprites[gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId].data[0] = battlerId; + gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].data[0] = battler; } } void SpriteCB_EnemyShadow(struct Sprite *shadowSprite) { bool8 invisible = FALSE; - u8 battlerId = shadowSprite->tBattlerId; - struct Sprite *battlerSprite = &gSprites[gBattlerSpriteIds[battlerId]]; + u8 battler = shadowSprite->tBattlerId; + struct Sprite *battlerSprite = &gSprites[gBattlerSpriteIds[battler]]; - if (!battlerSprite->inUse || !IsBattlerSpritePresent(battlerId)) + if (!battlerSprite->inUse || !IsBattlerSpritePresent(battler)) { shadowSprite->callback = SpriteCB_SetInvisible; return; } if (gAnimScriptActive || battlerSprite->invisible) invisible = TRUE; - else if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE - && gEnemyMonElevation[gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies] == 0) + else if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies != SPECIES_NONE + && gEnemyMonElevation[gBattleSpritesDataPtr->battlerData[battler].transformSpecies] == 0) invisible = TRUE; - if (gBattleSpritesDataPtr->battlerData[battlerId].behindSubstitute) + if (gBattleSpritesDataPtr->battlerData[battler].behindSubstitute) invisible = TRUE; shadowSprite->x = battlerSprite->x; @@ -1150,24 +1150,24 @@ void SpriteCB_SetInvisible(struct Sprite *sprite) sprite->invisible = TRUE; } -void SetBattlerShadowSpriteCallback(u8 battlerId, u16 species) +void SetBattlerShadowSpriteCallback(u8 battler, u16 species) { // The player's shadow is never seen. - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER || gBattleScripting.monCaught) + if (GetBattlerSide(battler) == B_SIDE_PLAYER || gBattleScripting.monCaught) return; - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) - species = gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies; + if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies != SPECIES_NONE) + species = gBattleSpritesDataPtr->battlerData[battler].transformSpecies; if (gEnemyMonElevation[species] != 0) - gSprites[gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId].callback = SpriteCB_EnemyShadow; + gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].callback = SpriteCB_EnemyShadow; else - gSprites[gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId].callback = SpriteCB_SetInvisible; + gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].callback = SpriteCB_SetInvisible; } -void HideBattlerShadowSprite(u8 battlerId) +void HideBattlerShadowSprite(u8 battler) { - gSprites[gBattleSpritesDataPtr->healthBoxesData[battlerId].shadowSpriteId].callback = SpriteCB_SetInvisible; + gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].callback = SpriteCB_SetInvisible; } // Color the background tiles surrounding the action selection and move windows @@ -1194,11 +1194,11 @@ void FillAroundBattleWindows(void) } } -void ClearTemporarySpeciesSpriteData(u8 battlerId, bool8 dontClearSubstitute) +void ClearTemporarySpeciesSpriteData(u8 battler, bool8 dontClearSubstitute) { - gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies = SPECIES_NONE; + gBattleSpritesDataPtr->battlerData[battler].transformSpecies = SPECIES_NONE; if (!dontClearSubstitute) - ClearBehindSubstituteBit(battlerId); + ClearBehindSubstituteBit(battler); } void AllocateMonSpritesGfx(void) diff --git a/src/battle_main.c b/src/battle_main.c index 09d39f73d..db550e58f 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -100,7 +100,7 @@ static void TryDoEventsBeforeFirstTurn(void); static void HandleTurnActionSelectionState(void); static void RunTurnActionsFunctions(void); static void SetActionsAndBattlersTurnOrder(void); -static void UpdateBattlerPartyOrdersOnSwitch(void); +static void UpdateBattlerPartyOrdersOnSwitch(u32 battler); static bool8 AllAtActionConfirmed(void); static void TryChangeTurnOrder(void); static void CheckChosenMoveForEffectsBeforeTurnStarts(void); @@ -151,7 +151,6 @@ EWRAM_DATA struct MultiPartnerMenuPokemon gMultiPartnerParty[MULTI_PARTY_SIZE] = EWRAM_DATA static struct MultiPartnerMenuPokemon* sMultiPartnerPartyBuffer = NULL; EWRAM_DATA u8 *gBattleAnimBgTileBuffer = NULL; EWRAM_DATA u8 *gBattleAnimBgTilemapBuffer = NULL; -EWRAM_DATA u8 gActiveBattler = 0; EWRAM_DATA u32 gBattleControllerExecFlags = 0; EWRAM_DATA u8 gBattlersCount = 0; EWRAM_DATA u16 gBattlerPartyIndexes[MAX_BATTLERS_COUNT] = {0}; @@ -752,7 +751,7 @@ static void SetAllPlayersBerryData(void) { s32 numPlayers; struct BattleEnigmaBerry *src; - u8 battlerId; + u8 battler; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -764,17 +763,17 @@ static void SetAllPlayersBerryData(void) for (i = 0; i < numPlayers; i++) { src = (struct BattleEnigmaBerry *)(gBlockRecvBuffer[i] + 2); - battlerId = gLinkPlayers[i].id; + battler = gLinkPlayers[i].id; for (j = 0; j < BERRY_NAME_LENGTH; j++) - gEnigmaBerries[battlerId].name[j] = src->name[j]; - gEnigmaBerries[battlerId].name[j] = EOS; + gEnigmaBerries[battler].name[j] = src->name[j]; + gEnigmaBerries[battler].name[j] = EOS; for (j = 0; j < BERRY_ITEM_EFFECT_COUNT; j++) - gEnigmaBerries[battlerId].itemEffect[j] = src->itemEffect[j]; + gEnigmaBerries[battler].itemEffect[j] = src->itemEffect[j]; - gEnigmaBerries[battlerId].holdEffect = src->holdEffect; - gEnigmaBerries[battlerId].holdEffectParam = src->holdEffectParam; + gEnigmaBerries[battler].holdEffect = src->holdEffect; + gEnigmaBerries[battler].holdEffectParam = src->holdEffectParam; } } else @@ -2994,10 +2993,11 @@ void BeginBattleIntro(void) static void BattleMainCB1(void) { - gBattleMainFunc(); + u32 battler; - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - gBattlerControllerFuncs[gActiveBattler](gActiveBattler); + gBattleMainFunc(); + for (battler = 0; battler < gBattlersCount; battler++) + gBattlerControllerFuncs[battler](battler); } static void BattleStartClearSetData(void) @@ -3128,21 +3128,21 @@ static void BattleStartClearSetData(void) gSelectedMonPartyId = PARTY_SIZE; // Revival Blessing } -void SwitchInClearSetData(void) +void SwitchInClearSetData(u32 battler) { s32 i; - struct DisableStruct disableStructCopy = gDisableStructs[gActiveBattler]; + struct DisableStruct disableStructCopy = gDisableStructs[battler]; - ClearIllusionMon(gActiveBattler); + ClearIllusionMon(battler); if (gBattleMoves[gCurrentMove].effect != EFFECT_BATON_PASS) { 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++) { - 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; - 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; gDisableStructs[i].battlerWithSureHit = 0; @@ -3151,96 +3151,96 @@ void SwitchInClearSetData(void) } if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) { - gBattleMons[gActiveBattler].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 + gBattleMons[battler].status2 &= (STATUS2_CONFUSION | STATUS2_FOCUS_ENERGY | STATUS2_SUBSTITUTE | STATUS2_ESCAPE_PREVENTION | STATUS2_CURSED); + 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_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++) { - if (GetBattlerSide(gActiveBattler) != GetBattlerSide(i) + if (GetBattlerSide(battler) != GetBattlerSide(i) && (gStatuses3[i] & STATUS3_ALWAYS_HITS) != 0 - && (gDisableStructs[i].battlerWithSureHit == gActiveBattler)) + && (gDisableStructs[i].battlerWithSureHit == battler)) { gStatuses3[i] &= ~STATUS3_ALWAYS_HITS; gStatuses3[i] |= STATUS3_ALWAYS_HITS_TURN(2); } } - if (gStatuses3[gActiveBattler] & STATUS3_POWER_TRICK) - SWAP(gBattleMons[gActiveBattler].attack, gBattleMons[gActiveBattler].defense, i); + if (gStatuses3[battler] & STATUS3_POWER_TRICK) + SWAP(gBattleMons[battler].attack, gBattleMons[battler].defense, i); } else { - gBattleMons[gActiveBattler].status2 = 0; - gStatuses3[gActiveBattler] = 0; - gStatuses4[gActiveBattler] = 0; + gBattleMons[battler].status2 = 0; + gStatuses3[battler] = 0; + gStatuses4[battler] = 0; } for (i = 0; i < gBattlersCount; i++) { - if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(gActiveBattler)) - gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(gActiveBattler); - if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == gActiveBattler) + if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(battler)) + gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(battler); + if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == battler) gBattleMons[i].status2 &= ~STATUS2_WRAPPED; } - gActionSelectionCursor[gActiveBattler] = 0; - gMoveSelectionCursor[gActiveBattler] = 0; + gActionSelectionCursor[battler] = 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) { - gDisableStructs[gActiveBattler].substituteHP = disableStructCopy.substituteHP; - gDisableStructs[gActiveBattler].battlerWithSureHit = disableStructCopy.battlerWithSureHit; - gDisableStructs[gActiveBattler].perishSongTimer = disableStructCopy.perishSongTimer; - gDisableStructs[gActiveBattler].battlerPreventingEscape = disableStructCopy.battlerPreventingEscape; + gDisableStructs[battler].substituteHP = disableStructCopy.substituteHP; + gDisableStructs[battler].battlerWithSureHit = disableStructCopy.battlerWithSureHit; + gDisableStructs[battler].perishSongTimer = disableStructCopy.perishSongTimer; + gDisableStructs[battler].battlerPreventingEscape = disableStructCopy.battlerPreventingEscape; } gMoveResultFlags = 0; - gDisableStructs[gActiveBattler].isFirstTurn = 2; - gDisableStructs[gActiveBattler].truantSwitchInHack = disableStructCopy.truantSwitchInHack; - gLastMoves[gActiveBattler] = MOVE_NONE; - gLastLandedMoves[gActiveBattler] = MOVE_NONE; - gLastHitByType[gActiveBattler] = 0; - gLastResultingMoves[gActiveBattler] = MOVE_NONE; - gLastPrintedMoves[gActiveBattler] = MOVE_NONE; - gLastHitBy[gActiveBattler] = 0xFF; + gDisableStructs[battler].isFirstTurn = 2; + gDisableStructs[battler].truantSwitchInHack = disableStructCopy.truantSwitchInHack; + gLastMoves[battler] = MOVE_NONE; + gLastLandedMoves[battler] = MOVE_NONE; + gLastHitByType[battler] = 0; + gLastResultingMoves[battler] = MOVE_NONE; + gLastPrintedMoves[battler] = MOVE_NONE; + gLastHitBy[battler] = 0xFF; - gBattleStruct->lastTakenMove[gActiveBattler] = 0; - gBattleStruct->sameMoveTurns[gActiveBattler] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; - gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]); - gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); + gBattleStruct->lastTakenMove[battler] = 0; + gBattleStruct->sameMoveTurns[battler] = 0; + gBattleStruct->lastTakenMoveFrom[battler][0] = 0; + gBattleStruct->lastTakenMoveFrom[battler][1] = 0; + gBattleStruct->lastTakenMoveFrom[battler][2] = 0; + gBattleStruct->lastTakenMoveFrom[battler][3] = 0; + gBattleStruct->lastMoveFailed &= ~(gBitTable[battler]); + gBattleStruct->palaceFlags &= ~(gBitTable[battler]); for (i = 0; i < ARRAY_COUNT(gSideTimers); i++) { // 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; } 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->lastTakenMoveFrom[i][gActiveBattler] = 0; + gBattleStruct->lastTakenMoveFrom[i][battler] = 0; } - gBattleStruct->choicedMove[gActiveBattler] = MOVE_NONE; - gBattleResources->flags->flags[gActiveBattler] = 0; + gBattleStruct->choicedMove[battler] = MOVE_NONE; + gBattleResources->flags->flags[battler] = 0; gCurrentMove = MOVE_NONE; gBattleStruct->arenaTurnCounter = 0xFF; // Reset damage to prevent things like red card activating if the switched-in mon is holding it - gSpecialStatuses[gActiveBattler].physicalDmg = 0; - gSpecialStatuses[gActiveBattler].specialDmg = 0; + gSpecialStatuses[battler].physicalDmg = 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. gSelectedMonPartyId = PARTY_SIZE; @@ -3248,126 +3248,126 @@ void SwitchInClearSetData(void) // Allow for illegal abilities within tests. if (gTestRunnerEnabled) { - u32 side = GetBattlerSide(gActiveBattler); - u32 partyIndex = gBattlerPartyIndexes[gActiveBattler]; + u32 side = GetBattlerSide(battler); + u32 partyIndex = gBattlerPartyIndexes[battler]; if (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; 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; - gStatuses3[gActiveBattler] = 0; - gStatuses4[gActiveBattler] = 0; + gBattleMons[battler].status2 = 0; + gStatuses3[battler] = 0; + gStatuses4[battler] = 0; 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; - if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(gActiveBattler)) - gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(gActiveBattler); - if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == gActiveBattler) + if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(battler)) + gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(battler); + if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == battler) gBattleMons[i].status2 &= ~STATUS2_WRAPPED; } - gActionSelectionCursor[gActiveBattler] = 0; - gMoveSelectionCursor[gActiveBattler] = 0; + gActionSelectionCursor[battler] = 0; + gMoveSelectionCursor[battler] = 0; - memset(&gDisableStructs[gActiveBattler], 0, sizeof(struct DisableStruct)); + memset(&gDisableStructs[battler], 0, sizeof(struct DisableStruct)); - gProtectStructs[gActiveBattler].protected = FALSE; - gProtectStructs[gActiveBattler].spikyShielded = FALSE; - gProtectStructs[gActiveBattler].kingsShielded = FALSE; - gProtectStructs[gActiveBattler].banefulBunkered = FALSE; - gProtectStructs[gActiveBattler].quash = FALSE; - gProtectStructs[gActiveBattler].obstructed = FALSE; - gProtectStructs[gActiveBattler].silkTrapped = FALSE; - gProtectStructs[gActiveBattler].endured = FALSE; - gProtectStructs[gActiveBattler].noValidMoves = FALSE; - gProtectStructs[gActiveBattler].helpingHand = FALSE; - gProtectStructs[gActiveBattler].bounceMove = FALSE; - gProtectStructs[gActiveBattler].stealMove = FALSE; - gProtectStructs[gActiveBattler].prlzImmobility = FALSE; - gProtectStructs[gActiveBattler].confusionSelfDmg = FALSE; - gProtectStructs[gActiveBattler].targetAffected = FALSE; - gProtectStructs[gActiveBattler].chargingTurn = FALSE; - gProtectStructs[gActiveBattler].fleeType = 0; - gProtectStructs[gActiveBattler].usedImprisonedMove = FALSE; - gProtectStructs[gActiveBattler].loveImmobility = FALSE; - gProtectStructs[gActiveBattler].usedDisabledMove = FALSE; - gProtectStructs[gActiveBattler].usedTauntedMove = FALSE; - gProtectStructs[gActiveBattler].flag2Unknown = FALSE; - gProtectStructs[gActiveBattler].flinchImmobility = FALSE; - gProtectStructs[gActiveBattler].notFirstStrike = FALSE; - gProtectStructs[gActiveBattler].usedHealBlockedMove = FALSE; - gProtectStructs[gActiveBattler].usesBouncedMove = FALSE; - gProtectStructs[gActiveBattler].usedGravityPreventedMove = FALSE; - gProtectStructs[gActiveBattler].usedThroatChopPreventedMove = FALSE; - gProtectStructs[gActiveBattler].statRaised = FALSE; - gProtectStructs[gActiveBattler].statFell = FALSE; - gProtectStructs[gActiveBattler].pranksterElevated = FALSE; + gProtectStructs[battler].protected = FALSE; + gProtectStructs[battler].spikyShielded = FALSE; + gProtectStructs[battler].kingsShielded = FALSE; + gProtectStructs[battler].banefulBunkered = FALSE; + gProtectStructs[battler].quash = FALSE; + gProtectStructs[battler].obstructed = FALSE; + gProtectStructs[battler].silkTrapped = FALSE; + gProtectStructs[battler].endured = FALSE; + gProtectStructs[battler].noValidMoves = FALSE; + gProtectStructs[battler].helpingHand = FALSE; + gProtectStructs[battler].bounceMove = FALSE; + gProtectStructs[battler].stealMove = FALSE; + gProtectStructs[battler].prlzImmobility = FALSE; + gProtectStructs[battler].confusionSelfDmg = FALSE; + gProtectStructs[battler].targetAffected = FALSE; + gProtectStructs[battler].chargingTurn = FALSE; + gProtectStructs[battler].fleeType = 0; + gProtectStructs[battler].usedImprisonedMove = FALSE; + gProtectStructs[battler].loveImmobility = FALSE; + gProtectStructs[battler].usedDisabledMove = FALSE; + gProtectStructs[battler].usedTauntedMove = FALSE; + gProtectStructs[battler].flag2Unknown = FALSE; + gProtectStructs[battler].flinchImmobility = FALSE; + gProtectStructs[battler].notFirstStrike = FALSE; + gProtectStructs[battler].usedHealBlockedMove = FALSE; + gProtectStructs[battler].usesBouncedMove = FALSE; + gProtectStructs[battler].usedGravityPreventedMove = FALSE; + gProtectStructs[battler].usedThroatChopPreventedMove = FALSE; + gProtectStructs[battler].statRaised = FALSE; + gProtectStructs[battler].statFell = FALSE; + gProtectStructs[battler].pranksterElevated = FALSE; - gDisableStructs[gActiveBattler].isFirstTurn = 2; + gDisableStructs[battler].isFirstTurn = 2; - gLastMoves[gActiveBattler] = MOVE_NONE; - gLastLandedMoves[gActiveBattler] = MOVE_NONE; - gLastHitByType[gActiveBattler] = 0; - gLastResultingMoves[gActiveBattler] = MOVE_NONE; - gLastPrintedMoves[gActiveBattler] = MOVE_NONE; - gLastHitBy[gActiveBattler] = 0xFF; + gLastMoves[battler] = MOVE_NONE; + gLastLandedMoves[battler] = MOVE_NONE; + gLastHitByType[battler] = 0; + gLastResultingMoves[battler] = MOVE_NONE; + gLastPrintedMoves[battler] = MOVE_NONE; + gLastHitBy[battler] = 0xFF; - gBattleStruct->choicedMove[gActiveBattler] = MOVE_NONE; - gBattleStruct->sameMoveTurns[gActiveBattler] = 0; - gBattleStruct->lastTakenMove[gActiveBattler] = MOVE_NONE; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0; - gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; + gBattleStruct->choicedMove[battler] = MOVE_NONE; + gBattleStruct->sameMoveTurns[battler] = 0; + gBattleStruct->lastTakenMove[battler] = MOVE_NONE; + gBattleStruct->lastTakenMoveFrom[battler][0] = 0; + gBattleStruct->lastTakenMoveFrom[battler][1] = 0; + gBattleStruct->lastTakenMoveFrom[battler][2] = 0; + gBattleStruct->lastTakenMoveFrom[battler][3] = 0; - gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); + gBattleStruct->palaceFlags &= ~(gBitTable[battler]); for (i = 0; i < ARRAY_COUNT(gSideTimers); i++) { // 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; } 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->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[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1]; - gBattleMons[gActiveBattler].type3 = TYPE_MYSTERY; + gBattleMons[battler].type1 = gSpeciesInfo[gBattleMons[battler].species].types[0]; + gBattleMons[battler].type2 = gSpeciesInfo[gBattleMons[battler].species].types[1]; + gBattleMons[battler].type3 = TYPE_MYSTERY; - Ai_UpdateFaintData(gActiveBattler); - TryBattleFormChange(gActiveBattler, FORM_CHANGE_FAINT); + Ai_UpdateFaintData(battler); + 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 (gBattleStruct->skyDropTargets[gActiveBattler] != 0xFF) + if (gBattleStruct->skyDropTargets[battler] != 0xFF) { // 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 - gBattleStruct->skyDropTargets[gActiveBattler] = 0xFF; + gBattleStruct->skyDropTargets[battler] = 0xFF; gBattleStruct->skyDropTargets[otherSkyDropper] = 0xFF; // If the other Pokemon involved in this Sky Drop was the target, not the attacker @@ -3401,21 +3401,22 @@ void FaintClearSetData(void) // Clear Z-Move data gBattleStruct->zmove.active = FALSE; - gBattleStruct->zmove.toBeUsed[gActiveBattler] = MOVE_NONE; + gBattleStruct->zmove.toBeUsed[battler] = MOVE_NONE; gBattleStruct->zmove.effect = EFFECT_HIT; } static void DoBattleIntro(void) { s32 i; + u32 battler; u8 *state = &gBattleStruct->introState; switch (*state) { case 0: // Get Data of all battlers. - gActiveBattler = gBattleCommunication[1]; - BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0); - MarkBattlerForControllerExec(gActiveBattler); + battler = gBattleCommunication[1]; + BtlController_EmitGetMonData(battler, BUFFER_A, REQUEST_ALL_BATTLE, 0); + MarkBattlerForControllerExec(battler); (*state)++; break; case 1: // Loop through all battlers. @@ -3430,9 +3431,9 @@ static void DoBattleIntro(void) case 2: // Start graphical intro slide. if (!gBattleControllerExecFlags) { - gActiveBattler = GetBattlerAtPosition(0); - BtlController_EmitIntroSlide(BUFFER_A, gBattleTerrain); - MarkBattlerForControllerExec(gActiveBattler); + battler = GetBattlerAtPosition(0); + BtlController_EmitIntroSlide(battler, BUFFER_A, gBattleTerrain); + MarkBattlerForControllerExec(battler); gBattleCommunication[0] = 0; gBattleCommunication[1] = 0; (*state)++; @@ -3443,50 +3444,50 @@ static void DoBattleIntro(void) (*state)++; break; case 4: // Copy battler data gotten in cases 0 and 1. Draw trainer/mon sprite. - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if ((gBattleTypeFlags & BATTLE_TYPE_SAFARI) && GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if ((gBattleTypeFlags & BATTLE_TYPE_SAFARI) && GetBattlerSide(battler) == B_SIDE_PLAYER) { - memset(&gBattleMons[gActiveBattler], 0, sizeof(struct BattlePokemon)); + memset(&gBattleMons[battler], 0, sizeof(struct BattlePokemon)); } else { - memcpy(&gBattleMons[gActiveBattler], &gBattleResources->bufferB[gActiveBattler][4], sizeof(struct BattlePokemon)); - gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0]; - gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1]; - gBattleMons[gActiveBattler].type3 = TYPE_MYSTERY; - gBattleMons[gActiveBattler].ability = GetAbilityBySpecies(gBattleMons[gActiveBattler].species, gBattleMons[gActiveBattler].abilityNum); - gBattleStruct->hpOnSwitchout[GetBattlerSide(gActiveBattler)] = gBattleMons[gActiveBattler].hp; - gBattleMons[gActiveBattler].status2 = 0; + memcpy(&gBattleMons[battler], &gBattleResources->bufferB[battler][4], sizeof(struct BattlePokemon)); + gBattleMons[battler].type1 = gSpeciesInfo[gBattleMons[battler].species].types[0]; + gBattleMons[battler].type2 = gSpeciesInfo[gBattleMons[battler].species].types[1]; + gBattleMons[battler].type3 = TYPE_MYSTERY; + gBattleMons[battler].ability = GetAbilityBySpecies(gBattleMons[battler].species, gBattleMons[battler].abilityNum); + gBattleStruct->hpOnSwitchout[GetBattlerSide(battler)] = gBattleMons[battler].hp; + gBattleMons[battler].status2 = 0; for (i = 0; i < NUM_BATTLE_STATS; i++) - gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE; + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; } // Draw sprite. - switch (GetBattlerPosition(gActiveBattler)) + switch (GetBattlerPosition(battler)) { case B_POSITION_PLAYER_LEFT: // player sprite - BtlController_EmitDrawTrainerPic(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDrawTrainerPic(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); break; case B_POSITION_OPPONENT_LEFT: if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) // opponent 1 sprite { - BtlController_EmitDrawTrainerPic(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDrawTrainerPic(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } else // wild mon 1 { - BtlController_EmitLoadMonSprite(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); - gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); + BtlController_EmitLoadMonSprite(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); + gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL); } break; case B_POSITION_PLAYER_RIGHT: if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER)) // partner sprite { - BtlController_EmitDrawTrainerPic(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDrawTrainerPic(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } break; case B_POSITION_OPPONENT_RIGHT: @@ -3494,15 +3495,15 @@ static void DoBattleIntro(void) { if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS) && !BATTLE_TWO_VS_ONE_OPPONENT) // opponent 2 if exists { - BtlController_EmitDrawTrainerPic(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDrawTrainerPic(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } } - else if (IsBattlerAlive(gActiveBattler)) // wild mon 2 if alive + else if (IsBattlerAlive(battler)) // wild mon 2 if alive { - BtlController_EmitLoadMonSprite(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); - gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); + BtlController_EmitLoadMonSprite(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); + gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL); } break; } @@ -3544,9 +3545,9 @@ static void DoBattleIntro(void) } } - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); - MarkBattlerForControllerExec(gActiveBattler); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + BtlController_EmitDrawPartyStatusSummary(battler, BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); + MarkBattlerForControllerExec(battler); for (i = 0; i < PARTY_SIZE; i++) { @@ -3563,9 +3564,9 @@ static void DoBattleIntro(void) } } - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); - MarkBattlerForControllerExec(gActiveBattler); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + BtlController_EmitDrawPartyStatusSummary(battler, BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); + MarkBattlerForControllerExec(battler); (*state)++; } @@ -3611,12 +3612,12 @@ static void DoBattleIntro(void) break; case 11: // first opponent's mon send out animation if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - BtlController_EmitIntroTrainerBallThrow(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitIntroTrainerBallThrow(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); (*state)++; break; case 12: // nothing @@ -3625,12 +3626,12 @@ static void DoBattleIntro(void) if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS) && !BATTLE_TWO_VS_ONE_OPPONENT) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - BtlController_EmitIntroTrainerBallThrow(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitIntroTrainerBallThrow(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } #if B_FAST_INTRO == TRUE if (!(gBattleTypeFlags & (BATTLE_TYPE_RECORDED | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_RECORDED_IS_MASTER | BATTLE_TYPE_LINK))) @@ -3651,21 +3652,21 @@ static void DoBattleIntro(void) if (!(gBattleTypeFlags & BATTLE_TYPE_SAFARI)) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); // A hack that makes fast intro work in trainer battles too. #if B_FAST_INTRO == TRUE if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & (BATTLE_TYPE_RECORDED | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_RECORDED_IS_MASTER | BATTLE_TYPE_LINK)) - && gSprites[gHealthboxSpriteIds[gActiveBattler ^ BIT_SIDE]].callback == SpriteCallbackDummy) + && gSprites[gHealthboxSpriteIds[battler ^ BIT_SIDE]].callback == SpriteCallbackDummy) { return; } #endif - PrepareStringBattle(STRINGID_INTROSENDOUT, gActiveBattler); + PrepareStringBattle(STRINGID_INTROSENDOUT, battler); } (*state)++; break; @@ -3673,50 +3674,50 @@ static void DoBattleIntro(void) if (!(gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleControllerExecFlags)) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - if (!IsBattlerMarkedForControllerExec(gActiveBattler)) + if (!IsBattlerMarkedForControllerExec(battler)) (*state)++; } break; case 18: // player 1 send out if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - BtlController_EmitIntroTrainerBallThrow(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitIntroTrainerBallThrow(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); (*state)++; break; case 19: // player 2 send out if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER)) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && !(gBattleTypeFlags & BATTLE_TYPE_RECORDED_IS_MASTER)) - gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + battler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); else - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + battler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - BtlController_EmitIntroTrainerBallThrow(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitIntroTrainerBallThrow(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } (*state)++; break; case 20: // set dex and battle vars if (!gBattleControllerExecFlags) { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && !(gBattleTypeFlags & (BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_TRAINER_HILL))) { - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality); + HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); } } @@ -3970,23 +3971,23 @@ void BattleTurnPassed(void) BattleScriptExecute(i == 1 ? BattleScript_TrainerASlideMsgEnd2 : BattleScript_TrainerBSlideMsgEnd2); } -u8 IsRunningFromBattleImpossible(void) +u8 IsRunningFromBattleImpossible(u32 battler) { u32 holdEffect, i; - if (gBattleMons[gActiveBattler].item == ITEM_ENIGMA_BERRY_E_READER) - holdEffect = gEnigmaBerries[gActiveBattler].holdEffect; + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER) + holdEffect = gEnigmaBerries[battler].holdEffect; 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. { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DONT_LEAVE_BIRCH; 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. { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE; @@ -3996,15 +3997,15 @@ u8 IsRunningFromBattleImpossible(void) if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) return BATTLE_RUN_SUCCESS; #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; #endif if (gBattleTypeFlags & BATTLE_TYPE_LINK) return BATTLE_RUN_SUCCESS; - if (GetBattlerAbility(gActiveBattler) == ABILITY_RUN_AWAY) + if (GetBattlerAbility(battler) == ABILITY_RUN_AWAY) return BATTLE_RUN_SUCCESS; - if ((i = IsAbilityPreventingEscape(gActiveBattler))) + if ((i = IsAbilityPreventingEscape(battler))) { gBattleScripting.battler = i - 1; gLastUsedAbility = gBattleMons[i - 1].ability; @@ -4012,7 +4013,7 @@ u8 IsRunningFromBattleImpossible(void) return BATTLE_RUN_FAILURE; } - if (!CanBattlerEscape(gActiveBattler)) + if (!CanBattlerEscape(battler)) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE; return BATTLE_RUN_FORBIDDEN; @@ -4065,47 +4066,47 @@ enum static void HandleTurnActionSelectionState(void) { - s32 i; + s32 i, battler; gBattleCommunication[ACTIONS_CONFIRMED_COUNT] = 0; - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - u8 position = GetBattlerPosition(gActiveBattler); - switch (gBattleCommunication[gActiveBattler]) + u8 position = GetBattlerPosition(battler); + switch (gBattleCommunication[battler]) { case STATE_TURN_START_RECORD: // Recorded battle related action on start of every turn. - RecordedBattle_CopyBattlerMoves(); - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_CopyBattlerMoves(battler); + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; // Do AI score computations here so we can use them in AI_TrySwitchOrUseItem if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart()) - && (BattlerHasAi(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_PALACE))) + && (BattlerHasAi(battler) && !(gBattleTypeFlags & BATTLE_TYPE_PALACE))) { - gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler); + gBattleStruct->aiMoveOrAction[battler] = ComputeBattleAiScores(battler); } break; case STATE_BEFORE_ACTION_CHOSEN: // Choose an action. - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; + *(gBattleStruct->monToSwitchIntoId + battler) = PARTY_SIZE; if (gBattleTypeFlags & BATTLE_TYPE_MULTI || (position & BIT_FLANK) == B_FLANK_LEFT || gBattleStruct->absentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))] || gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == STATE_WAIT_ACTION_CONFIRMED) { - if (gBattleStruct->absentBattlerFlags & gBitTable[gActiveBattler]) + if (gBattleStruct->absentBattlerFlags & gBitTable[battler]) { - gChosenActionByBattler[gActiveBattler] = B_ACTION_NOTHING_FAINTED; + gChosenActionByBattler[battler] = B_ACTION_NOTHING_FAINTED; if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED; + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED; else - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; } else { - if (gBattleMons[gActiveBattler].status2 & STATUS2_MULTIPLETURNS - || gBattleMons[gActiveBattler].status2 & STATUS2_RECHARGE) + if (gBattleMons[battler].status2 & STATUS2_MULTIPLETURNS + || gBattleMons[battler].status2 & STATUS2_RECHARGE) { - gChosenActionByBattler[gActiveBattler] = B_ACTION_USE_MOVE; - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gChosenActionByBattler[battler] = B_ACTION_USE_MOVE; + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; } else if (WILD_DOUBLE_BATTLE && position == B_POSITION_PLAYER_RIGHT @@ -4113,41 +4114,41 @@ static void HandleTurnActionSelectionState(void) && gChosenActionByBattler[GetBattlerAtPosition(B_POSITION_PLAYER_LEFT)] != B_ACTION_NOTHING_FAINTED) { gBattleStruct->throwingPokeBall = FALSE; - gChosenActionByBattler[gActiveBattler] = B_ACTION_NOTHING_FAINTED; // Not fainted, but it cannot move, because of the throwing ball. - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gChosenActionByBattler[battler] = B_ACTION_NOTHING_FAINTED; // Not fainted, but it cannot move, because of the throwing ball. + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; } else { - gBattleStruct->itemPartyIndex[gActiveBattler] = PARTY_SIZE; - BtlController_EmitChooseAction(BUFFER_A, gChosenActionByBattler[0], gBattleResources->bufferB[0][1] | (gBattleResources->bufferB[0][2] << 8)); - MarkBattlerForControllerExec(gActiveBattler); - gBattleCommunication[gActiveBattler]++; + gBattleStruct->itemPartyIndex[battler] = PARTY_SIZE; + BtlController_EmitChooseAction(battler, BUFFER_A, gChosenActionByBattler[0], gBattleResources->bufferB[0][1] | (gBattleResources->bufferB[0][2] << 8)); + MarkBattlerForControllerExec(battler); + gBattleCommunication[battler]++; } } } break; case STATE_WAIT_ACTION_CHOSEN: // Try to perform an action. - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { - RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][1]); - gChosenActionByBattler[gActiveBattler] = gBattleResources->bufferB[gActiveBattler][1]; + RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][1]); + gChosenActionByBattler[battler] = gBattleResources->bufferB[battler][1]; - switch (gBattleResources->bufferB[gActiveBattler][1]) + switch (gBattleResources->bufferB[battler][1]) { case B_ACTION_USE_MOVE: - if (AreAllMovesUnusable()) + if (AreAllMovesUnusable(battler)) { - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_WAIT_ACTION_CONFIRMED_STANDBY; - *(gBattleStruct->moveTarget + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][3]; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + *(gBattleStruct->moveTarget + battler) = gBattleResources->bufferB[battler][3]; return; } - else if (gDisableStructs[gActiveBattler].encoredMove != 0) + else if (gDisableStructs[battler].encoredMove != 0) { - gChosenMoveByBattler[gActiveBattler] = gDisableStructs[gActiveBattler].encoredMove; - *(gBattleStruct->chosenMovePositions + gActiveBattler) = gDisableStructs[gActiveBattler].encoredMovePos; - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gChosenMoveByBattler[battler] = gDisableStructs[battler].encoredMove; + *(gBattleStruct->chosenMovePositions + battler) = gDisableStructs[battler].encoredMovePos; + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; return; } else @@ -4156,33 +4157,33 @@ static void HandleTurnActionSelectionState(void) moveInfo.zmove = gBattleStruct->zmove; moveInfo.mega = gBattleStruct->mega; - moveInfo.species = gBattleMons[gActiveBattler].species; - moveInfo.monType1 = gBattleMons[gActiveBattler].type1; - moveInfo.monType2 = gBattleMons[gActiveBattler].type2; - moveInfo.monType3 = gBattleMons[gActiveBattler].type3; + moveInfo.species = gBattleMons[battler].species; + moveInfo.monType1 = gBattleMons[battler].type1; + moveInfo.monType2 = gBattleMons[battler].type2; + moveInfo.monType3 = gBattleMons[battler].type3; for (i = 0; i < MAX_MON_MOVES; i++) { - moveInfo.moves[i] = gBattleMons[gActiveBattler].moves[i]; - moveInfo.currentPp[i] = gBattleMons[gActiveBattler].pp[i]; + moveInfo.moves[i] = gBattleMons[battler].moves[i]; + moveInfo.currentPp[i] = gBattleMons[battler].pp[i]; moveInfo.maxPp[i] = CalculatePPWithBonus( - gBattleMons[gActiveBattler].moves[i], - gBattleMons[gActiveBattler].ppBonuses, + gBattleMons[battler].moves[i], + gBattleMons[battler].ppBonuses, i); } - BtlController_EmitChooseMove(BUFFER_A, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitChooseMove(battler, BUFFER_A, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo); + MarkBattlerForControllerExec(battler); } break; case B_ACTION_USE_ITEM: if (FlagGet(B_FLAG_NO_BAG_USE)) { - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); - gSelectionBattleScripts[gActiveBattler] = BattleScript_ActionSelectionItemsCantBeUsed; - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); + gSelectionBattleScripts[battler] = BattleScript_ActionSelectionItemsCantBeUsed; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_BEFORE_ACTION_CHOSEN; return; } @@ -4192,145 +4193,145 @@ static void HandleTurnActionSelectionState(void) | BATTLE_TYPE_RECORDED_LINK)) && !gTestRunnerEnabled) // Or if currently held by Sky Drop - || gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED) + || gStatuses3[battler] & STATUS3_SKY_DROPPED) { - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); - gSelectionBattleScripts[gActiveBattler] = BattleScript_ActionSelectionItemsCantBeUsed; - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); + gSelectionBattleScripts[battler] = BattleScript_ActionSelectionItemsCantBeUsed; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_BEFORE_ACTION_CHOSEN; return; } else { - BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitChooseItem(battler, BUFFER_A, gBattleStruct->battlerPartyOrders[battler]); + MarkBattlerForControllerExec(battler); } break; case B_ACTION_SWITCH: - *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + *(gBattleStruct->battlerPartyIndexes + battler) = gBattlerPartyIndexes[battler]; if (gBattleTypeFlags & BATTLE_TYPE_ARENA - || !CanBattlerEscape(gActiveBattler)) + || !CanBattlerEscape(battler)) { - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); + BtlController_EmitChoosePokemon(battler, BUFFER_A, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); } - else if (ItemId_GetHoldEffect(gBattleMons[gActiveBattler].item) != HOLD_EFFECT_SHED_SHELL - && (i = IsAbilityPreventingEscape(gActiveBattler))) // must be last to keep i value integrity + else if (ItemId_GetHoldEffect(gBattleMons[battler].item) != HOLD_EFFECT_SHED_SHELL + && (i = IsAbilityPreventingEscape(battler))) // must be last to keep i value integrity { - BtlController_EmitChoosePokemon(BUFFER_A, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gBattleMons[i - 1].ability, gBattleStruct->battlerPartyOrders[gActiveBattler]); + BtlController_EmitChoosePokemon(battler, BUFFER_A, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gBattleMons[i - 1].ability, gBattleStruct->battlerPartyOrders[battler]); } else { - if (gActiveBattler == 2 && gChosenActionByBattler[0] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); - else if (gActiveBattler == 3 && gChosenActionByBattler[1] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); + if (battler == 2 && gChosenActionByBattler[0] == B_ACTION_SWITCH) + BtlController_EmitChoosePokemon(battler, BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); + else if (battler == 3 && gChosenActionByBattler[1] == B_ACTION_SWITCH) + BtlController_EmitChoosePokemon(battler, BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); else - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); + BtlController_EmitChoosePokemon(battler, BUFFER_A, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); } - MarkBattlerForControllerExec(gActiveBattler); + MarkBattlerForControllerExec(battler); break; case B_ACTION_SAFARI_BALL: if (IsPlayerPartyAndPokemonStorageFull()) { - gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintFullBox; - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSelectionBattleScripts[battler] = BattleScript_PrintFullBox; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_BEFORE_ACTION_CHOSEN; return; } break; case B_ACTION_SAFARI_POKEBLOCK: - BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitChooseItem(battler, BUFFER_A, gBattleStruct->battlerPartyOrders[battler]); + MarkBattlerForControllerExec(battler); break; case B_ACTION_CANCEL_PARTNER: - gBattleCommunication[gActiveBattler] = STATE_WAIT_SET_BEFORE_ACTION; - gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] = STATE_BEFORE_ACTION_CHOSEN; - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); - if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_MULTIPLETURNS - || gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_RECHARGE) + gBattleCommunication[battler] = STATE_WAIT_SET_BEFORE_ACTION; + gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))] = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); + if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))].status2 & STATUS2_MULTIPLETURNS + || gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))].status2 & STATUS2_RECHARGE) { - BtlController_EmitEndBounceEffect(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitEndBounceEffect(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); return; } - else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] == B_ACTION_SWITCH) + else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))] == B_ACTION_SWITCH) { - RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 2); + RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))), 2); } - else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] == B_ACTION_RUN) + else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))] == B_ACTION_RUN) { - RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 1); + RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))), 1); } - else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] == B_ACTION_USE_MOVE - && (gProtectStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].noValidMoves - || gDisableStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].encoredMove)) + else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))] == B_ACTION_USE_MOVE + && (gProtectStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))].noValidMoves + || gDisableStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))].encoredMove)) { - RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 1); + RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))), 1); } else if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] == B_ACTION_USE_MOVE) + && gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler)))] == B_ACTION_USE_MOVE) { gRngValue = gBattlePalaceMoveSelectionRngValue; - RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 1); + RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))), 1); } else { - RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 3); + RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(battler))), 3); } - gBattleStruct->mega.toEvolve &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))]); - gBattleStruct->burst.toBurst &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))]); - gBattleStruct->zmove.toBeUsed[BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))] = MOVE_NONE; - BtlController_EmitEndBounceEffect(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gBattleStruct->mega.toEvolve &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(battler))]); + gBattleStruct->burst.toBurst &= ~(gBitTable[BATTLE_PARTNER(GetBattlerPosition(battler))]); + gBattleStruct->zmove.toBeUsed[BATTLE_PARTNER(GetBattlerPosition(battler))] = MOVE_NONE; + BtlController_EmitEndBounceEffect(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); return; case B_ACTION_DEBUG: - BtlController_EmitDebugMenu(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDebugMenu(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); break; } if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) - && gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_RUN) + && gBattleResources->bufferB[battler][1] == B_ACTION_RUN) { - gSelectionBattleScripts[gActiveBattler] = BattleScript_AskIfWantsToForfeitMatch; - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT_MAY_RUN; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSelectionBattleScripts[battler] = BattleScript_AskIfWantsToForfeitMatch; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT_MAY_RUN; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_BEFORE_ACTION_CHOSEN; return; } else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK)) - && gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_RUN) + && gBattleResources->bufferB[battler][1] == B_ACTION_RUN) { BattleScriptExecute(BattleScript_PrintCantRunFromTrainer); - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; } - else if (IsRunningFromBattleImpossible() != BATTLE_RUN_SUCCESS - && gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_RUN) + else if (IsRunningFromBattleImpossible(battler) != BATTLE_RUN_SUCCESS + && gBattleResources->bufferB[battler][1] == B_ACTION_RUN) { - gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintCantEscapeFromBattle; - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; + gSelectionBattleScripts[battler] = BattleScript_PrintCantEscapeFromBattle; + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_BEFORE_ACTION_CHOSEN; return; } else { - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; } } break; case STATE_WAIT_ACTION_CASE_CHOSEN: - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { - switch (gChosenActionByBattler[gActiveBattler]) + switch (gChosenActionByBattler[battler]) { case B_ACTION_USE_MOVE: - switch (gBattleResources->bufferB[gActiveBattler][1]) + switch (gBattleResources->bufferB[battler][1]) { case 3: case 4: @@ -4339,114 +4340,115 @@ static void HandleTurnActionSelectionState(void) case 7: case 8: case 9: - gChosenActionByBattler[gActiveBattler] = gBattleResources->bufferB[gActiveBattler][1]; + gChosenActionByBattler[battler] = gBattleResources->bufferB[battler][1]; return; case 15: - gChosenActionByBattler[gActiveBattler] = B_ACTION_SWITCH; - UpdateBattlerPartyOrdersOnSwitch(); + gChosenActionByBattler[battler] = B_ACTION_SWITCH; + UpdateBattlerPartyOrdersOnSwitch(battler); return; default: RecordedBattle_CheckMovesetChanges(B_RECORD_MODE_PLAYBACK); - if ((gBattleResources->bufferB[gActiveBattler][2] | (gBattleResources->bufferB[gActiveBattler][3] << 8)) == 0xFFFF) + if ((gBattleResources->bufferB[battler][2] | (gBattleResources->bufferB[battler][3] << 8)) == 0xFFFF) { - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); } - else if (TrySetCantSelectMoveBattleScript()) + else if (TrySetCantSelectMoveBattleScript(battler)) { - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); - gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT; - *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; - gBattleResources->bufferB[gActiveBattler][1] = B_ACTION_USE_MOVE; - *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_WAIT_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); + gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; + *(gBattleStruct->selectionScriptFinished + battler) = FALSE; + gBattleResources->bufferB[battler][1] = B_ACTION_USE_MOVE; + *(gBattleStruct->stateIdAfterSelScript + battler) = STATE_WAIT_ACTION_CHOSEN; return; } else { if (!(gBattleTypeFlags & BATTLE_TYPE_PALACE)) { - RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][2]); - RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][3]); + RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][2]); + RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][3]); } - *(gBattleStruct->chosenMovePositions + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][2] & ~(RET_MEGA_EVOLUTION | RET_ULTRA_BURST); - gChosenMoveByBattler[gActiveBattler] = gBattleMons[gActiveBattler].moves[*(gBattleStruct->chosenMovePositions + gActiveBattler)]; - *(gBattleStruct->moveTarget + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][3]; - if (gBattleResources->bufferB[gActiveBattler][2] & RET_MEGA_EVOLUTION) - gBattleStruct->mega.toEvolve |= gBitTable[gActiveBattler]; - else if (gBattleResources->bufferB[gActiveBattler][2] & RET_ULTRA_BURST) - gBattleStruct->burst.toBurst |= gBitTable[gActiveBattler]; - gBattleCommunication[gActiveBattler]++; + + gBattleStruct->chosenMovePositions[battler] = gBattleResources->bufferB[battler][2] & ~(RET_MEGA_EVOLUTION | RET_ULTRA_BURST); + gChosenMoveByBattler[battler] = gBattleMons[battler].moves[gBattleStruct->chosenMovePositions[battler]]; + gBattleStruct->moveTarget[battler] = gBattleResources->bufferB[battler][3]; + if (gBattleResources->bufferB[battler][2] & RET_MEGA_EVOLUTION) + gBattleStruct->mega.toEvolve |= gBitTable[battler]; + else if (gBattleResources->bufferB[battler][2] & RET_ULTRA_BURST) + gBattleStruct->burst.toBurst |= gBitTable[battler]; + gBattleCommunication[battler]++; } break; } break; case B_ACTION_USE_ITEM: - if ((gBattleResources->bufferB[gActiveBattler][1] | (gBattleResources->bufferB[gActiveBattler][2] << 8)) == 0) + if ((gBattleResources->bufferB[battler][1] | (gBattleResources->bufferB[battler][2] << 8)) == 0) { - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; } else { - gLastUsedItem = (gBattleResources->bufferB[gActiveBattler][1] | (gBattleResources->bufferB[gActiveBattler][2] << 8)); + gLastUsedItem = (gBattleResources->bufferB[battler][1] | (gBattleResources->bufferB[battler][2] << 8)); if (ItemId_GetPocket(gLastUsedItem) == POCKET_POKE_BALLS) gBattleStruct->throwingPokeBall = TRUE; - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; } break; case B_ACTION_SWITCH: - if (gBattleResources->bufferB[gActiveBattler][1] == PARTY_SIZE) + if (gBattleResources->bufferB[battler][1] == PARTY_SIZE) { - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; + RecordedBattle_ClearBattlerAction(battler, 1); } else { - UpdateBattlerPartyOrdersOnSwitch(); - gBattleCommunication[gActiveBattler]++; + UpdateBattlerPartyOrdersOnSwitch(battler); + gBattleCommunication[battler]++; } break; case B_ACTION_RUN: gHitMarker |= HITMARKER_RUN; - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_SAFARI_WATCH_CAREFULLY: - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_SAFARI_BALL: - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_THROW_BALL: gBattleStruct->throwingPokeBall = TRUE; - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_SAFARI_POKEBLOCK: - if ((gBattleResources->bufferB[gActiveBattler][1] | (gBattleResources->bufferB[gActiveBattler][2] << 8)) != 0) - gBattleCommunication[gActiveBattler]++; + if ((gBattleResources->bufferB[battler][1] | (gBattleResources->bufferB[battler][2] << 8)) != 0) + gBattleCommunication[battler]++; else - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; break; case B_ACTION_SAFARI_GO_NEAR: - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_SAFARI_RUN: gHitMarker |= HITMARKER_RUN; - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_WALLY_THROW: - gBattleCommunication[gActiveBattler]++; + gBattleCommunication[battler]++; break; case B_ACTION_DEBUG: - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; break; } } break; case STATE_WAIT_ACTION_CONFIRMED_STANDBY: - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) - | (gBitTable[gActiveBattler] << 4) - | (gBitTable[gActiveBattler] << 8) - | (gBitTable[gActiveBattler] << 12)))) + | (gBitTable[battler] << 4) + | (gBitTable[battler] << 8) + | (gBitTable[battler] << 12)))) { if (AllAtActionConfirmed()) i = TRUE; @@ -4457,68 +4459,68 @@ static void HandleTurnActionSelectionState(void) || (position & BIT_FLANK) != B_FLANK_LEFT || (*(&gBattleStruct->absentBattlerFlags) & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))])) { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_STOP_BOUNCE, i); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_STOP_BOUNCE, i); } else { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_STOP_BOUNCE_ONLY, i); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_STOP_BOUNCE_ONLY, i); } - MarkBattlerForControllerExec(gActiveBattler); - gBattleCommunication[gActiveBattler]++; + MarkBattlerForControllerExec(battler); + gBattleCommunication[battler]++; } break; case STATE_WAIT_ACTION_CONFIRMED: - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { gBattleCommunication[ACTIONS_CONFIRMED_COUNT]++; } break; case STATE_SELECTION_SCRIPT: - if (*(gBattleStruct->selectionScriptFinished + gActiveBattler)) + if (*(gBattleStruct->selectionScriptFinished + battler)) { - gBattleCommunication[gActiveBattler] = *(gBattleStruct->stateIdAfterSelScript + gActiveBattler); + gBattleCommunication[battler] = *(gBattleStruct->stateIdAfterSelScript + battler); } else { - gBattlerAttacker = gActiveBattler; - gBattlescriptCurrInstr = gSelectionBattleScripts[gActiveBattler]; - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + gBattlerAttacker = battler; + gBattlescriptCurrInstr = gSelectionBattleScripts[battler]; + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } - gSelectionBattleScripts[gActiveBattler] = gBattlescriptCurrInstr; + gSelectionBattleScripts[battler] = gBattlescriptCurrInstr; } break; case STATE_WAIT_SET_BEFORE_ACTION: - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { - gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; + gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; } break; case STATE_SELECTION_SCRIPT_MAY_RUN: - if (*(gBattleStruct->selectionScriptFinished + gActiveBattler)) + if (*(gBattleStruct->selectionScriptFinished + battler)) { - if (gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_NOTHING_FAINTED) + if (gBattleResources->bufferB[battler][1] == B_ACTION_NOTHING_FAINTED) { gHitMarker |= HITMARKER_RUN; - gChosenActionByBattler[gActiveBattler] = B_ACTION_RUN; - gBattleCommunication[gActiveBattler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; + gChosenActionByBattler[battler] = B_ACTION_RUN; + gBattleCommunication[battler] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; } else { - RecordedBattle_ClearBattlerAction(gActiveBattler, 1); - gBattleCommunication[gActiveBattler] = *(gBattleStruct->stateIdAfterSelScript + gActiveBattler); + RecordedBattle_ClearBattlerAction(battler, 1); + gBattleCommunication[battler] = *(gBattleStruct->stateIdAfterSelScript + battler); } } else { - gBattlerAttacker = gActiveBattler; - gBattlescriptCurrInstr = gSelectionBattleScripts[gActiveBattler]; - if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12)))) + gBattlerAttacker = battler; + gBattlescriptCurrInstr = gSelectionBattleScripts[battler]; + if (!(gBattleControllerExecFlags & ((gBitTable[battler]) | (0xF << 28) | (gBitTable[battler] << 4) | (gBitTable[battler] << 8) | (gBitTable[battler] << 12)))) { gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } - gSelectionBattleScripts[gActiveBattler] = gBattlescriptCurrInstr; + gSelectionBattleScripts[battler] = gBattlescriptCurrInstr; } break; } @@ -4571,20 +4573,20 @@ static bool8 AllAtActionConfirmed(void) return FALSE; } -static void UpdateBattlerPartyOrdersOnSwitch(void) +static void UpdateBattlerPartyOrdersOnSwitch(u32 battler) { - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][1]; - RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][1]); + gBattleStruct->monToSwitchIntoId[battler] = gBattleResources->bufferB[battler][1]; + RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][1]); if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) { - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0); - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[gActiveBattler][3]; + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0); + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[battler][3]; - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0) >> 4; - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[gActiveBattler][3]; + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0) >> 4; + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[battler][3]; } } @@ -4596,12 +4598,12 @@ void SwapTurnOrder(u8 id1, u8 id2) SWAP(gBattlerByTurnOrder[id1], gBattlerByTurnOrder[id2], temp); } -u32 GetBattlerTotalSpeedStat(u8 battlerId) +u32 GetBattlerTotalSpeedStat(u8 battler) { - u32 speed = gBattleMons[battlerId].speed; - u32 ability = GetBattlerAbility(battlerId); - u32 holdEffect = GetBattlerHoldEffect(battlerId, TRUE); - u32 highestStat = GetHighestStatId(battlerId); + u32 speed = gBattleMons[battler].speed; + u32 ability = GetBattlerAbility(battler); + u32 holdEffect = GetBattlerHoldEffect(battler, TRUE); + u32 highestStat = GetHighestStatId(battler); // weather abilities if (WEATHER_HAS_EFFECT) @@ -4617,11 +4619,11 @@ u32 GetBattlerTotalSpeedStat(u8 battlerId) } // other abilities - if (ability == ABILITY_QUICK_FEET && gBattleMons[battlerId].status1 & STATUS1_ANY) + if (ability == ABILITY_QUICK_FEET && gBattleMons[battler].status1 & STATUS1_ANY) speed = (speed * 150) / 100; else if (ability == ABILITY_SURGE_SURFER && gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) speed *= 2; - else if (ability == ABILITY_SLOW_START && gDisableStructs[battlerId].slowStartTimer != 0) + else if (ability == ABILITY_SLOW_START && gDisableStructs[battler].slowStartTimer != 0) speed /= 2; else if (ability == ABILITY_PROTOSYNTHESIS && gBattleWeather & B_WEATHER_SUN && highestStat == STAT_SPEED) speed = (speed * 150) / 100; @@ -4629,13 +4631,13 @@ u32 GetBattlerTotalSpeedStat(u8 battlerId) speed = (speed * 150) / 100; // stat stages - speed *= gStatStageRatios[gBattleMons[battlerId].statStages[STAT_SPEED]][0]; - speed /= gStatStageRatios[gBattleMons[battlerId].statStages[STAT_SPEED]][1]; + speed *= gStatStageRatios[gBattleMons[battler].statStages[STAT_SPEED]][0]; + speed /= gStatStageRatios[gBattleMons[battler].statStages[STAT_SPEED]][1]; // player's badge boost if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_FRONTIER)) - && ShouldGetStatBadgeBoost(FLAG_BADGE03_GET, battlerId) - && GetBattlerSide(battlerId) == B_SIDE_PLAYER) + && ShouldGetStatBadgeBoost(FLAG_BADGE03_GET, battler) + && GetBattlerSide(battler) == B_SIDE_PLAYER) { speed = (speed * 110) / 100; } @@ -4647,17 +4649,17 @@ u32 GetBattlerTotalSpeedStat(u8 battlerId) speed /= 2; else if (holdEffect == HOLD_EFFECT_CHOICE_SCARF) speed = (speed * 150) / 100; - else if (holdEffect == HOLD_EFFECT_QUICK_POWDER && gBattleMons[battlerId].species == SPECIES_DITTO && !(gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED)) + else if (holdEffect == HOLD_EFFECT_QUICK_POWDER && gBattleMons[battler].species == SPECIES_DITTO && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED)) speed *= 2; // various effects - if (gSideStatuses[GET_BATTLER_SIDE(battlerId)] & SIDE_STATUS_TAILWIND) + if (gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_TAILWIND) speed *= 2; - if (gBattleResources->flags->flags[battlerId] & RESOURCE_FLAG_UNBURDEN) + if (gBattleResources->flags->flags[battler] & RESOURCE_FLAG_UNBURDEN) speed *= 2; // paralysis drop - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS && ability != ABILITY_QUICK_FEET) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS && ability != ABILITY_QUICK_FEET) #if B_PARALYSIS_SPEED >= GEN_7 speed /= 2; #else @@ -4667,28 +4669,28 @@ u32 GetBattlerTotalSpeedStat(u8 battlerId) return speed; } -s8 GetChosenMovePriority(u32 battlerId) +s8 GetChosenMovePriority(u32 battler) { u16 move; - gProtectStructs[battlerId].pranksterElevated = 0; - if (gProtectStructs[battlerId].noValidMoves) + gProtectStructs[battler].pranksterElevated = 0; + if (gProtectStructs[battler].noValidMoves) move = MOVE_STRUGGLE; else - move = gBattleMons[battlerId].moves[*(gBattleStruct->chosenMovePositions + battlerId)]; + move = gBattleMons[battler].moves[*(gBattleStruct->chosenMovePositions + battler)]; - return GetMovePriority(battlerId, move); + return GetMovePriority(battler, move); } -s8 GetMovePriority(u32 battlerId, u16 move) +s8 GetMovePriority(u32 battler, u16 move) { s8 priority; - u16 ability = GetBattlerAbility(battlerId); + u16 ability = GetBattlerAbility(battler); priority = gBattleMoves[move].priority; if (ability == ABILITY_GALE_WINGS #if B_GALE_WINGS >= GEN_7 - && BATTLER_MAX_HP(battlerId) + && BATTLER_MAX_HP(battler) #endif && gBattleMoves[move].type == TYPE_FLYING) { @@ -4696,10 +4698,10 @@ s8 GetMovePriority(u32 battlerId, u16 move) } else if (ability == ABILITY_PRANKSTER && IS_MOVE_STATUS(move)) { - gProtectStructs[battlerId].pranksterElevated = 1; + gProtectStructs[battler].pranksterElevated = 1; priority++; } - else if (gBattleMoves[move].effect == EFFECT_GRASSY_GLIDE && gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN && IsBattlerGrounded(battlerId)) + else if (gBattleMoves[move].effect == EFFECT_GRASSY_GLIDE && gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN && IsBattlerGrounded(battler)) { priority++; } @@ -4725,7 +4727,7 @@ s8 GetMovePriority(u32 battlerId, u16 move) } } - if (gProtectStructs[battlerId].quash) + if (gProtectStructs[battler].quash) priority = -8; return priority; @@ -4836,14 +4838,14 @@ u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves) static void SetActionsAndBattlersTurnOrder(void) { s32 turnOrderId = 0; - s32 i, j; + s32 i, j, battler; if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[battler]; + gBattlerByTurnOrder[turnOrderId] = battler; turnOrderId++; } } @@ -4851,9 +4853,9 @@ static void SetActionsAndBattlersTurnOrder(void) { if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + if (gChosenActionByBattler[battler] == B_ACTION_RUN) { turnOrderId = 5; break; @@ -4864,24 +4866,24 @@ static void SetActionsAndBattlersTurnOrder(void) { if (gChosenActionByBattler[0] == B_ACTION_RUN) { - gActiveBattler = 0; + battler = 0; turnOrderId = 5; } if (gChosenActionByBattler[2] == B_ACTION_RUN) { - gActiveBattler = 2; + battler = 2; turnOrderId = 5; } } if (turnOrderId == 5) // One of battlers wants to run. { - gActionsByTurnOrder[0] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[0] = gActiveBattler; + gActionsByTurnOrder[0] = gChosenActionByBattler[battler]; + gBattlerByTurnOrder[0] = battler; turnOrderId = 1; for (i = 0; i < gBattlersCount; i++) { - if (i != gActiveBattler) + if (i != battler) { gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[i]; gBattlerByTurnOrder[turnOrderId] = i; @@ -4891,25 +4893,25 @@ static void SetActionsAndBattlersTurnOrder(void) } else { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM - || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH - || gChosenActionByBattler[gActiveBattler] == B_ACTION_THROW_BALL) + if (gChosenActionByBattler[battler] == B_ACTION_USE_ITEM + || gChosenActionByBattler[battler] == B_ACTION_SWITCH + || gChosenActionByBattler[battler] == B_ACTION_THROW_BALL) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[battler]; + gBattlerByTurnOrder[turnOrderId] = battler; turnOrderId++; } } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM - && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH - && gChosenActionByBattler[gActiveBattler] != B_ACTION_THROW_BALL) + if (gChosenActionByBattler[battler] != B_ACTION_USE_ITEM + && gChosenActionByBattler[battler] != B_ACTION_SWITCH + && gChosenActionByBattler[battler] != B_ACTION_THROW_BALL) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[battler]; + gBattlerByTurnOrder[turnOrderId] = battler; turnOrderId++; } } @@ -4941,35 +4943,35 @@ static void TurnValuesCleanUp(bool8 var0) { s32 i; - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (i = 0; i < gBattlersCount; i++) { if (var0) { - gProtectStructs[gActiveBattler].protected = FALSE; - gProtectStructs[gActiveBattler].spikyShielded = FALSE; - gProtectStructs[gActiveBattler].kingsShielded = FALSE; - gProtectStructs[gActiveBattler].banefulBunkered = FALSE; - gProtectStructs[gActiveBattler].quash = FALSE; + gProtectStructs[i].protected = FALSE; + gProtectStructs[i].spikyShielded = FALSE; + gProtectStructs[i].kingsShielded = FALSE; + gProtectStructs[i].banefulBunkered = FALSE; + gProtectStructs[i].quash = FALSE; } else { - memset(&gProtectStructs[gActiveBattler], 0, sizeof(struct ProtectStruct)); + memset(&gProtectStructs[i], 0, sizeof(struct ProtectStruct)); - if (gDisableStructs[gActiveBattler].isFirstTurn) - gDisableStructs[gActiveBattler].isFirstTurn--; + if (gDisableStructs[i].isFirstTurn) + gDisableStructs[i].isFirstTurn--; - if (gDisableStructs[gActiveBattler].rechargeTimer) + if (gDisableStructs[i].rechargeTimer) { - gDisableStructs[gActiveBattler].rechargeTimer--; - if (gDisableStructs[gActiveBattler].rechargeTimer == 0) - gBattleMons[gActiveBattler].status2 &= ~STATUS2_RECHARGE; + gDisableStructs[i].rechargeTimer--; + if (gDisableStructs[i].rechargeTimer == 0) + gBattleMons[i].status2 &= ~STATUS2_RECHARGE; } } - if (gDisableStructs[gActiveBattler].substituteHP == 0) - gBattleMons[gActiveBattler].status2 &= ~STATUS2_SUBSTITUTE; + if (gDisableStructs[i].substituteHP == 0) + 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); @@ -4994,7 +4996,7 @@ static bool32 TryDoMegaEvosBeforeMoves(void) { if (!(gHitMarker & HITMARKER_RUN) && (gBattleStruct->mega.toEvolve || gBattleStruct->burst.toBurst)) { - u32 i; + u32 i, battler; struct Pokemon *party; struct Pokemon *mon; u8 megaOrder[MAX_BATTLERS_COUNT]; @@ -5006,12 +5008,12 @@ static bool32 TryDoMegaEvosBeforeMoves(void) if (gBattleStruct->mega.toEvolve & gBitTable[megaOrder[i]] && !(gProtectStructs[megaOrder[i]].noValidMoves)) { - gActiveBattler = gBattlerAttacker = megaOrder[i]; - gBattleStruct->mega.toEvolve &= ~(gBitTable[gActiveBattler]); - gLastUsedItem = gBattleMons[gActiveBattler].item; - party = GetBattlerParty(gActiveBattler); - mon = &party[gBattlerPartyIndexes[gActiveBattler]]; - if (GetBattleFormChangeTargetSpecies(gActiveBattler, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE) != SPECIES_NONE) + gBattlerAttacker = megaOrder[i]; + gBattleStruct->mega.toEvolve &= ~(gBitTable[gBattlerAttacker]); + gLastUsedItem = gBattleMons[gBattlerAttacker].item; + party = GetBattlerParty(gBattlerAttacker); + mon = &party[gBattlerPartyIndexes[gBattlerAttacker]]; + if (GetBattleFormChangeTargetSpecies(gBattlerAttacker, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE) != SPECIES_NONE) BattleScriptExecute(BattleScript_WishMegaEvolution); else BattleScriptExecute(BattleScript_MegaEvolution); @@ -5021,11 +5023,11 @@ static bool32 TryDoMegaEvosBeforeMoves(void) if (gBattleStruct->burst.toBurst & gBitTable[megaOrder[i]] && !(gProtectStructs[megaOrder[i]].noValidMoves)) { - gActiveBattler = gBattlerAttacker = megaOrder[i]; - gBattleStruct->burst.toBurst &= ~(gBitTable[gActiveBattler]); - gLastUsedItem = gBattleMons[gActiveBattler].item; - party = GetBattlerParty(gActiveBattler); - mon = &party[gBattlerPartyIndexes[gActiveBattler]]; + battler = gBattlerAttacker = megaOrder[i]; + gBattleStruct->burst.toBurst &= ~(gBitTable[battler]); + gLastUsedItem = gBattleMons[battler].item; + party = GetBattlerParty(battler); + mon = &party[gBattlerPartyIndexes[battler]]; BattleScriptExecute(BattleScript_UltraBurst); return TRUE; } @@ -5056,8 +5058,8 @@ static bool32 TryDoMoveEffectsBeforeMoves(void) && !(gProtectStructs[battlers[i]].noValidMoves)) { gBattleStruct->focusPunchBattlers |= gBitTable[battlers[i]]; - gActiveBattler = gBattlerAttacker = battlers[i]; - switch (gChosenMoveByBattler[gActiveBattler]) + gBattlerAttacker = battlers[i]; + switch (gChosenMoveByBattler[gBattlerAttacker]) { case MOVE_FOCUS_PUNCH: BattleScriptExecute(BattleScript_FocusPunchSetUp); @@ -5099,44 +5101,44 @@ static void TryChangeTurnOrder(void) static void CheckQuickClaw_CustapBerryActivation(void) { - u32 i; + u32 i, battler; if (!(gHitMarker & HITMARKER_RUN)) { while (gBattleStruct->quickClawBattlerId < gBattlersCount) { - gActiveBattler = gBattlerAttacker = gBattleStruct->quickClawBattlerId; + battler = gBattlerAttacker = gBattleStruct->quickClawBattlerId; gBattleStruct->quickClawBattlerId++; - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_MOVE - && gChosenMoveByBattler[gActiveBattler] != MOVE_FOCUS_PUNCH // quick claw message doesn't need to activate here - && (gProtectStructs[gActiveBattler].usedCustapBerry || gProtectStructs[gActiveBattler].quickDraw) - && !(gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) + if (gChosenActionByBattler[battler] == B_ACTION_USE_MOVE + && gChosenMoveByBattler[battler] != MOVE_FOCUS_PUNCH // quick claw message doesn't need to activate here + && (gProtectStructs[battler].usedCustapBerry || gProtectStructs[battler].quickDraw) + && !(gBattleMons[battler].status1 & STATUS1_SLEEP) && !(gDisableStructs[gBattlerAttacker].truantCounter) - && !(gProtectStructs[gActiveBattler].noValidMoves)) + && !(gProtectStructs[battler].noValidMoves)) { - if (gProtectStructs[gActiveBattler].usedCustapBerry) + if (gProtectStructs[battler].usedCustapBerry) { - gProtectStructs[gActiveBattler].usedCustapBerry = FALSE; - gLastUsedItem = gBattleMons[gActiveBattler].item; + gProtectStructs[battler].usedCustapBerry = FALSE; + gLastUsedItem = gBattleMons[battler].item; PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); - if (GetBattlerHoldEffect(gActiveBattler, FALSE) == HOLD_EFFECT_CUSTAP_BERRY) + if (GetBattlerHoldEffect(battler, FALSE) == HOLD_EFFECT_CUSTAP_BERRY) { // don't record berry since its gone now BattleScriptExecute(BattleScript_CustapBerryActivation); } else { - RecordItemEffectBattle(gActiveBattler, GetBattlerHoldEffect(gActiveBattler, FALSE)); + RecordItemEffectBattle(battler, GetBattlerHoldEffect(battler, FALSE)); BattleScriptExecute(BattleScript_QuickClawActivation); } } - else if (gProtectStructs[gActiveBattler].quickDraw) + else if (gProtectStructs[battler].quickDraw) { - gBattlerAbility = gActiveBattler; - gProtectStructs[gActiveBattler].quickDraw = FALSE; - gLastUsedAbility = gBattleMons[gActiveBattler].ability; + gBattlerAbility = battler; + gProtectStructs[battler].quickDraw = FALSE; + gLastUsedAbility = gBattleMons[battler].ability; PREPARE_ABILITY_BUFFER(gBattleTextBuff1, gLastUsedAbility); - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); + RecordAbilityBattle(battler, gLastUsedAbility); BattleScriptExecute(BattleScript_QuickDrawActivation); } return; @@ -5189,7 +5191,7 @@ static void RunTurnActionsFunctions(void) } else { - if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battler { gHitMarker &= ~HITMARKER_NO_ATTACKSTRING; gHitMarker &= ~HITMARKER_UNABLE_TO_USE_MOVE; @@ -5337,7 +5339,7 @@ static void HandleEndTurn_MonFled(void) static void HandleEndTurn_FinishBattle(void) { - u32 i; + u32 i, battler; if (gCurrentActionFuncId == B_ACTION_TRY_FINISH || gCurrentActionFuncId == B_ACTION_FINISHED) { @@ -5349,19 +5351,19 @@ static void HandleEndTurn_FinishBattle(void) | BATTLE_TYPE_WALLY_TUTORIAL | 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) { - gBattleResults.playerMon1Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); - GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, gBattleResults.playerMon1Name); + gBattleResults.playerMon1Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL); + GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_NICKNAME, gBattleResults.playerMon1Name); } else { - gBattleResults.playerMon2Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); - GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, gBattleResults.playerMon2Name); + gBattleResults.playerMon2Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL); + GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_NICKNAME, gBattleResults.playerMon2Name); } } } @@ -5708,20 +5710,20 @@ void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk) // special to set a field's totem boost(s) // inputs: -// var8000: battlerId +// var8000: battler // var8001 - var8007: stat changes void SetTotemBoost(void) { - u8 battlerId = gSpecialVar_0x8000; + u8 battler = gSpecialVar_0x8000; u8 i; for (i = 0; i < (NUM_BATTLE_STATS - 1); i++) { if (*(&gSpecialVar_0x8001 + i)) { - gTotemBoosts[battlerId].stats |= (1 << i); - gTotemBoosts[battlerId].statChanges[i] = *(&gSpecialVar_0x8001 + i); - gTotemBoosts[battlerId].stats |= 0x80; // used as a flag for the "totem flared to life" script + gTotemBoosts[battler].stats |= (1 << i); + gTotemBoosts[battler].statChanges[i] = *(&gSpecialVar_0x8001 + i); + gTotemBoosts[battler].stats |= 0x80; // used as a flag for the "totem flared to life" script } } } diff --git a/src/battle_message.c b/src/battle_message.c index a20aff965..c5972c548 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -266,17 +266,17 @@ static const u8 sText_XFoundOneY[] = _("{B_ATK_NAME_WITH_PREFIX} found\none {B_L static const u8 sText_SoothingAroma[] = _("A soothing aroma wafted\nthrough the area!"); static const u8 sText_ItemsCantBeUsedNow[] = _("Items can't be used now.{PAUSE 64}"); static const u8 sText_ForXCommaYZ[] = _("For {B_SCR_ACTIVE_NAME_WITH_PREFIX},\n{B_LAST_ITEM} {B_BUFF1}"); -static const u8 sText_PkmnUsedXToGetPumped[] = _("{B_ACTIVE_NAME_WITH_PREFIX} used\n{B_LAST_ITEM} to get pumped!"); +static const u8 sText_PkmnUsedXToGetPumped[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} used\n{B_LAST_ITEM} to get pumped!"); static const u8 sText_PkmnLostFocus[] = _("{B_ATK_NAME_WITH_PREFIX} lost its\nfocus and couldn't move!"); static const u8 sText_PkmnWasDraggedOut[] = _("{B_DEF_NAME_WITH_PREFIX} was\ndragged out!\p"); static const u8 sText_TheWallShattered[] = _("The wall shattered!"); static const u8 sText_ButNoEffect[] = _("But it had no effect!"); -static const u8 sText_PkmnHasNoMovesLeft[] = _("{B_ACTIVE_NAME_WITH_PREFIX} has no\nmoves left!\p"); -static const u8 sText_PkmnMoveIsDisabled[] = _("{B_ACTIVE_NAME_WITH_PREFIX}'s {B_CURRENT_MOVE}\nis disabled!\p"); -static const u8 sText_PkmnCantUseMoveTorment[] = _("{B_ACTIVE_NAME_WITH_PREFIX} can't use the same\nmove in a row due to the Torment!\p"); -static const u8 sText_PkmnCantUseMoveTaunt[] = _("{B_ACTIVE_NAME_WITH_PREFIX} can't use\n{B_CURRENT_MOVE} after the Taunt!\p"); -static const u8 sText_PkmnCantUseMoveSealed[] = _("{B_ACTIVE_NAME_WITH_PREFIX} can't use the\nsealed {B_CURRENT_MOVE}!\p"); -static const u8 sText_PkmnCantUseMoveThroatChop[] = _("{B_ACTIVE_NAME_WITH_PREFIX} can't use\n{B_CURRENT_MOVE} due to Throat Chop!\p"); +static const u8 sText_PkmnHasNoMovesLeft[] = _("{B_ATK_NAME_WITH_PREFIX} has no\nmoves left!\p"); +static const u8 sText_PkmnMoveIsDisabled[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_CURRENT_MOVE}\nis disabled!\p"); +static const u8 sText_PkmnCantUseMoveTorment[] = _("{B_ATK_NAME_WITH_PREFIX} can't use the same\nmove in a row due to the Torment!\p"); +static const u8 sText_PkmnCantUseMoveTaunt[] = _("{B_ATK_NAME_WITH_PREFIX} can't use\n{B_CURRENT_MOVE} after the Taunt!\p"); +static const u8 sText_PkmnCantUseMoveSealed[] = _("{B_ATK_NAME_WITH_PREFIX} can't use the\nsealed {B_CURRENT_MOVE}!\p"); +static const u8 sText_PkmnCantUseMoveThroatChop[] = _("{B_ATK_NAME_WITH_PREFIX} can't use\n{B_CURRENT_MOVE} due to Throat Chop!\p"); static const u8 sText_PkmnMadeItRain[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_SCR_ACTIVE_ABILITY}\nmade it rain!"); static const u8 sText_PkmnRaisedSpeed[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_SCR_ACTIVE_ABILITY}\nraised its SPEED!"); static const u8 sText_PkmnProtectedBy[] = _("{B_DEF_NAME_WITH_PREFIX} was protected\nby {B_DEF_ABILITY}!"); @@ -1955,7 +1955,7 @@ const u8 gText_PkmnIsEvolving[] = _("What?\n{STR_VAR_1} is evolving!"); const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{WAIT_SE}\p"); const u8 gText_PkmnStoppedEvolving[] = _("Huh? {STR_VAR_1}\nstopped evolving!\p"); const u8 gText_EllipsisQuestionMark[] = _("……?\p"); -const u8 gText_WhatWillPkmnDo[] = _("What will\n{B_ACTIVE_NAME2} do?"); +const u8 gText_WhatWillPkmnDo[] = _("What will\n{B_BUFF1} do?"); const u8 gText_WhatWillPkmnDo2[] = _("What will\n{B_PLAYER_NAME} do?"); const u8 gText_WhatWillWallyDo[] = _("What will\nWALLY do?"); const u8 gText_LinkStandby[] = _("{PAUSE 16}Link standby…"); @@ -2642,12 +2642,12 @@ static const struct BattleWindowText *const sBattleTextOnWindowsInfo[] = static const u8 sRecordedBattleTextSpeeds[] = {8, 4, 1, 0}; -void BufferStringBattle(u16 stringID) +void BufferStringBattle(u16 stringID, u32 battler) { s32 i; const u8 *stringPtr = NULL; - gBattleMsgDataPtr = (struct BattleMsgData *)(&gBattleResources->bufferA[gActiveBattler][4]); + gBattleMsgDataPtr = (struct BattleMsgData *)(&gBattleResources->bufferA[battler][4]); gLastUsedItem = gBattleMsgDataPtr->lastItem; gLastUsedAbility = gBattleMsgDataPtr->lastAbility; gBattleScripting.battler = gBattleMsgDataPtr->scrActive; @@ -2720,9 +2720,9 @@ void BufferStringBattle(u16 stringID) } break; case STRINGID_INTROSENDOUT: // poke first send-out - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]])) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(battler)]])) { if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) stringPtr = sText_InGamePartnerSentOutZGoN; @@ -2740,7 +2740,7 @@ void BufferStringBattle(u16 stringID) } else { - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]])) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battler)]])) { if (BATTLE_TWO_VS_ONE_OPPONENT) stringPtr = sText_Trainer1SentOutTwoPkmn; @@ -2767,7 +2767,7 @@ void BufferStringBattle(u16 stringID) } break; case STRINGID_RETURNMON: // sending poke to ball msg - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { if (*(&gBattleStruct->hpScale) == 0) stringPtr = sText_PkmnThatsEnough; @@ -2856,7 +2856,7 @@ void BufferStringBattle(u16 stringID) if (gBattleTextBuff1[0] & B_OUTCOME_LINK_BATTLE_RAN) { gBattleTextBuff1[0] &= ~(B_OUTCOME_LINK_BATTLE_RAN); - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT && gBattleTextBuff1[0] != B_OUTCOME_DREW) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && gBattleTextBuff1[0] != B_OUTCOME_DREW) gBattleTextBuff1[0] ^= (B_OUTCOME_LOST | B_OUTCOME_WON); if (gBattleTextBuff1[0] == B_OUTCOME_LOST || gBattleTextBuff1[0] == B_OUTCOME_DREW) @@ -2868,7 +2868,7 @@ void BufferStringBattle(u16 stringID) } else { - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT && gBattleTextBuff1[0] != B_OUTCOME_DREW) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && gBattleTextBuff1[0] != B_OUTCOME_DREW) gBattleTextBuff1[0] ^= (B_OUTCOME_LOST | B_OUTCOME_WON); if (gBattleTypeFlags & BATTLE_TYPE_MULTI) @@ -2975,24 +2975,24 @@ static const u8 *TryGetStatusString(u8 *src) return NULL; } -static void GetBattlerNick(u32 battlerId, u8 *dst) +static void GetBattlerNick(u32 battler, u8 *dst) { struct Pokemon *mon, *illusionMon; - if (GET_BATTLER_SIDE(battlerId) == B_SIDE_PLAYER) - mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; + if (GET_BATTLER_SIDE(battler) == B_SIDE_PLAYER) + mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; else - mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; + mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; - illusionMon = GetIllusionMonPtr(battlerId); + illusionMon = GetIllusionMonPtr(battler); if (illusionMon != NULL) mon = illusionMon; GetMonData(mon, MON_DATA_NICKNAME, dst); StringGet_Nickname(dst); } -#define HANDLE_NICKNAME_STRING_CASE(battlerId) \ - if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) \ +#define HANDLE_NICKNAME_STRING_CASE(battler) \ + if (GetBattlerSide(battler) != B_SIDE_PLAYER) \ { \ if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) \ toCpy = sText_FoePkmnPrefix; \ @@ -3005,10 +3005,10 @@ static void GetBattlerNick(u32 battlerId, u8 *dst) toCpy++; \ } \ } \ - GetBattlerNick(battlerId, text); \ + GetBattlerNick(battler, text); \ toCpy = text; -static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, u8 multiplayerId, u8 battlerId) +static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, u8 multiplayerId, u8 battler) { const u8 *toCpy; @@ -3028,9 +3028,9 @@ static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, else if (trainerId == TRAINER_LINK_OPPONENT) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - toCpy = gLinkPlayers[GetBattlerMultiplayerId(battlerId)].name; + toCpy = gLinkPlayers[GetBattlerMultiplayerId(battler)].name; else - toCpy = gLinkPlayers[GetBattlerMultiplayerId(battlerId) & BIT_SIDE].name; + toCpy = gLinkPlayers[GetBattlerMultiplayerId(battler) & BIT_SIDE].name; } else if (trainerId == TRAINER_FRONTIER_BRAIN) { @@ -3060,31 +3060,31 @@ static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, return toCpy; } -static const u8 *BattleStringGetOpponentName(u8 *text, u8 multiplayerId, u8 battlerId) +static const u8 *BattleStringGetOpponentName(u8 *text, u8 multiplayerId, u8 battler) { const u8 *toCpy; - switch (GetBattlerPosition(battlerId)) + switch (GetBattlerPosition(battler)) { case B_POSITION_OPPONENT_LEFT: - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battlerId); + toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battler); break; case B_POSITION_OPPONENT_RIGHT: if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI) && !BATTLE_TWO_VS_ONE_OPPONENT) - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, battlerId); + toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, battler); else - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battlerId); + toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battler); break; } return toCpy; } -static const u8 *BattleStringGetPlayerName(u8 *text, u8 battlerId) +static const u8 *BattleStringGetPlayerName(u8 *text, u8 battler) { const u8 *toCpy; - switch (GetBattlerPosition(battlerId)) + switch (GetBattlerPosition(battler)) { case B_POSITION_PLAYER_LEFT: if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) @@ -3117,12 +3117,12 @@ static const u8 *BattleStringGetPlayerName(u8 *text, u8 battlerId) return toCpy; } -static const u8 *BattleStringGetTrainerName(u8 *text, u8 multiplayerId, u8 battlerId) +static const u8 *BattleStringGetTrainerName(u8 *text, u8 multiplayerId, u8 battler) { - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) - return BattleStringGetPlayerName(text, battlerId); + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + return BattleStringGetPlayerName(text, battler); else - return BattleStringGetOpponentName(text, multiplayerId, battlerId); + return BattleStringGetOpponentName(text, multiplayerId, battler); } static const u8 *BattleStringGetOpponentClassByTrainerId(u16 trainerId) @@ -3261,25 +3261,10 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) GetBattlerNick(gBattlerTarget, text); toCpy = text; break; - case B_TXT_ACTIVE_NAME: // active name - GetBattlerNick(gActiveBattler, text); - toCpy = text; - break; - case B_TXT_ACTIVE_NAME2: // active battlerId name with prefix, no illusion - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, text); - else - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, text); - StringGet_Nickname(text); - toCpy = text; - break; - case B_TXT_EFF_NAME_WITH_PREFIX: // effect battlerId name with prefix + case B_TXT_EFF_NAME_WITH_PREFIX: // effect battler name with prefix HANDLE_NICKNAME_STRING_CASE(gEffectBattler) break; - case B_TXT_ACTIVE_NAME_WITH_PREFIX: // active battlerId name with prefix - HANDLE_NICKNAME_STRING_CASE(gActiveBattler) - break; - case B_TXT_SCR_ACTIVE_NAME_WITH_PREFIX: // scripting active battlerId name with prefix + case B_TXT_SCR_ACTIVE_NAME_WITH_PREFIX: // scripting active battler name with prefix HANDLE_NICKNAME_STRING_CASE(gBattleScripting.battler) break; case B_TXT_CURRENT_MOVE: // current move name @@ -3353,7 +3338,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) case B_TXT_SCR_ACTIVE_ABILITY: // scripting active ability toCpy = gAbilityNames[sBattlerAbilities[gBattleScripting.battler]]; break; - case B_TXT_EFF_ABILITY: // effect battlerId ability + case B_TXT_EFF_ABILITY: // effect battler ability toCpy = gAbilityNames[sBattlerAbilities[gEffectBattler]]; break; case B_TXT_TRAINER1_CLASS: // trainer class name @@ -3592,7 +3577,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) return dstID; } -static void IllusionNickHack(u32 battlerId, u32 partyId, u8 *dst) +static void IllusionNickHack(u32 battler, u32 partyId, u8 *dst) { s32 id, i; // we know it's gEnemyParty @@ -3600,8 +3585,8 @@ static void IllusionNickHack(u32 battlerId, u32 partyId, u8 *dst) if (GetMonAbility(mon) == ABILITY_ILLUSION) { - if (IsBattlerAlive(BATTLE_PARTNER(battlerId))) - partnerMon = &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]]; + if (IsBattlerAlive(BATTLE_PARTNER(battler))) + partnerMon = &gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battler)]]; else partnerMon = mon; @@ -3905,17 +3890,17 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) } } -void SetPpNumbersPaletteInMoveSelection(void) +void SetPpNumbersPaletteInMoveSelection(u32 battler) { - struct ChooseMoveStruct *chooseMoveStruct = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]); + struct ChooseMoveStruct *chooseMoveStruct = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); const u16 *palPtr = gPPTextPalette; u8 var; if (!gBattleStruct->zmove.viewing) - var = GetCurrentPpToMaxPpState(chooseMoveStruct->currentPp[gMoveSelectionCursor[gActiveBattler]], - chooseMoveStruct->maxPp[gMoveSelectionCursor[gActiveBattler]]); + var = GetCurrentPpToMaxPpState(chooseMoveStruct->currentPp[gMoveSelectionCursor[battler]], + chooseMoveStruct->maxPp[gMoveSelectionCursor[battler]]); else - var = GetCurrentPpToMaxPpState(chooseMoveStruct->currentPp[gMoveSelectionCursor[gActiveBattler]], gBattleMoves[gMoveSelectionCursor[gActiveBattler]].pp); + var = GetCurrentPpToMaxPpState(chooseMoveStruct->currentPp[gMoveSelectionCursor[battler]], gBattleMoves[gMoveSelectionCursor[battler]].pp); gPlttBufferUnfaded[BG_PLTT_ID(5) + 12] = palPtr[(var * 2) + 0]; gPlttBufferUnfaded[BG_PLTT_ID(5) + 11] = palPtr[(var * 2) + 1]; @@ -4022,38 +4007,38 @@ enum NOT_EQUAL, }; -u32 BattlerHPPercentage(u32 battlerId, u32 operation, u32 threshold) +u32 BattlerHPPercentage(u32 battler, u32 operation, u32 threshold) { switch (operation) { case LESS_THAN: - return gBattleMons[battlerId].hp < (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp < (gBattleMons[battler].maxHP / threshold); case EQUAL: - return gBattleMons[battlerId].hp == (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp == (gBattleMons[battler].maxHP / threshold); case GREATER_THAN: - return gBattleMons[battlerId].hp > (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp > (gBattleMons[battler].maxHP / threshold); case LESS_THAN_OR_EQUAL: - return gBattleMons[battlerId].hp <= (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp <= (gBattleMons[battler].maxHP / threshold); case GREATER_THAN_OR_EQUAL: - return gBattleMons[battlerId].hp >= (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp >= (gBattleMons[battler].maxHP / threshold); case NOT_EQUAL: - return gBattleMons[battlerId].hp != (gBattleMons[battlerId].maxHP / threshold); + return gBattleMons[battler].hp != (gBattleMons[battler].maxHP / threshold); default: break; } } -u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) +u32 ShouldDoTrainerSlide(u32 battler, u32 which) { u32 i, firstId, lastId, trainerId, retValue = 1; - if (!(gBattleTypeFlags & BATTLE_TYPE_TRAINER) || GetBattlerSide(battlerId) != B_SIDE_OPPONENT) + if (!(gBattleTypeFlags & BATTLE_TYPE_TRAINER) || GetBattlerSide(battler) != B_SIDE_OPPONENT) return 0; // Two opponents support. if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { - if (gBattlerPartyIndexes[battlerId] >= 3) + if (gBattlerPartyIndexes[battler] >= 3) { firstId = 3, lastId = PARTY_SIZE; trainerId = gTrainerBattleOpponent_B; @@ -4077,11 +4062,11 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) && (((gBattleTypeFlags & BATTLE_TYPE_FRONTIER) && sTrainerSlides[i].isFrontierTrainer) || (!(gBattleTypeFlags & BATTLE_TYPE_FRONTIER) && !sTrainerSlides[i].isFrontierTrainer))) { - gBattleScripting.battler = battlerId; + gBattleScripting.battler = battler; switch (which) { case TRAINER_SLIDE_LAST_SWITCHIN: - if (sTrainerSlides[i].msgLastSwitchIn != NULL && !CanBattlerSwitch(battlerId)) + if (sTrainerSlides[i].msgLastSwitchIn != NULL && !CanBattlerSwitch(battler)) { gBattleStruct->trainerSlideMsg = sTrainerSlides[i].msgLastSwitchIn; return retValue; @@ -4090,7 +4075,7 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) case TRAINER_SLIDE_LAST_LOW_HP: if (sTrainerSlides[i].msgLastLowHp != NULL && GetEnemyMonCount(firstId, lastId, TRUE) == 1 - && BattlerHPPercentage(battlerId, GREATER_THAN_OR_EQUAL, 4) + && BattlerHPPercentage(battler, GREATER_THAN_OR_EQUAL, 4) && !gBattleStruct->trainerSlideLowHpMsgDone) { gBattleStruct->trainerSlideLowHpMsgDone = TRUE; @@ -4108,7 +4093,7 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) case TRAINER_SLIDE_LAST_HALF_HP: if (sTrainerSlides[i].msgLastHalfHp != NULL && GetEnemyMonCount(firstId, lastId, TRUE) == GetEnemyMonCount(firstId, lastId, FALSE) - 1 - && BattlerHPPercentage(battlerId, LESS_THAN_OR_EQUAL, 2) && BattlerHPPercentage(battlerId, GREATER_THAN, 4) + && BattlerHPPercentage(battler, LESS_THAN_OR_EQUAL, 2) && BattlerHPPercentage(battler, GREATER_THAN, 4) && !gBattleStruct->trainerSlideHalfHpMsgDone) { gBattleStruct->trainerSlideHalfHpMsgDone = TRUE; @@ -4127,7 +4112,7 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) case TRAINER_SLIDE_FIRST_SUPER_EFFECTIVE_HIT: if (sTrainerSlides[i].msgFirstSuperEffectiveHit != NULL && gBattleStruct->trainerSlideFirstSuperEffectiveHitMsgState == 1 - && gBattleMons[battlerId].hp) + && gBattleMons[battler].hp) { gBattleStruct->trainerSlideFirstSuperEffectiveHitMsgState = 2; gBattleStruct->trainerSlideMsg = sTrainerSlides[i].msgFirstSuperEffectiveHit; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 5627f0d38..dfadd828f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -338,7 +338,7 @@ static const u16 sWhiteOutBadgeMoney[9] = { 8, 16, 24, 36, 48, 64, 80, 100, 120 static bool8 IsTwoTurnsMove(u16 move); static void TrySetDestinyBondToHappen(void); -static u8 AttacksThisTurn(u8 battlerId, u16 move); // Note: returns 1 if it's a charging turn, otherwise 2. +static u8 AttacksThisTurn(u8 battler, u16 move); // Note: returns 1 if it's a charging turn, otherwise 2. static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr); static bool32 IsMonGettingExpSentOut(void); static void InitLevelUpBanner(void); @@ -1200,12 +1200,12 @@ static const u8 sBattlePalaceNatureToFlavorTextId[NUM_NATURES] = [NATURE_QUIRKY] = B_MSG_EAGER_FOR_MORE, }; -static bool32 NoTargetPresent(u8 battlerId, u32 move) +static bool32 NoTargetPresent(u8 battler, u32 move) { if (!IsBattlerAlive(gBattlerTarget)) gBattlerTarget = GetMoveTarget(move, NO_TARGET_OVERRIDE); - switch (GetBattlerMoveTargetType(battlerId, move)) + switch (GetBattlerMoveTargetType(battler, move)) { case MOVE_TARGET_SELECTED: case MOVE_TARGET_DEPENDS: @@ -1879,8 +1879,7 @@ static void Cmd_ppreduce(void) if (MOVE_IS_PERMANENT(gBattlerAttacker, gCurrMovePos)) { - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0, + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0, sizeof(gBattleMons[gBattlerAttacker].pp[gCurrMovePos]), &gBattleMons[gBattlerAttacker].pp[gCurrMovePos]); MarkBattlerForControllerExec(gBattlerAttacker); @@ -2212,8 +2211,6 @@ static void Cmd_attackanimation(void) { u8 multihit; - gActiveBattler = gBattlerAttacker; - if (gBattleMons[gBattlerTarget].status2 & STATUS2_SUBSTITUTE) multihit = gMultiHitCounter; else if (gMultiHitCounter != 0 && gMultiHitCounter != 1) @@ -2226,7 +2223,7 @@ static void Cmd_attackanimation(void) else multihit = gMultiHitCounter; - BtlController_EmitMoveAnimation(BUFFER_A, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit); + BtlController_EmitMoveAnimation(gBattlerAttacker, BUFFER_A, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit); gBattleScripting.animTurn++; gBattleScripting.animTargetsHit++; MarkBattlerForControllerExec(gBattlerAttacker); @@ -2257,20 +2254,20 @@ static void Cmd_healthbarupdate(void) if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) || (gHitMarker & HITMARKER_PASSIVE_DAMAGE)) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + u32 battler = GetBattlerForBattleScript(cmd->battler); - if (DoesSubstituteBlockMove(gBattlerAttacker, gActiveBattler, gCurrentMove) && gDisableStructs[gActiveBattler].substituteHP && !(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE)) + if (DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && gDisableStructs[battler].substituteHP && !(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE)) { - PrepareStringBattle(STRINGID_SUBSTITUTEDAMAGED, gActiveBattler); + PrepareStringBattle(STRINGID_SUBSTITUTEDAMAGED, battler); } - else if (!DoesDisguiseBlockMove(gBattlerAttacker, gActiveBattler, gCurrentMove)) + else if (!DoesDisguiseBlockMove(gBattlerAttacker, battler, gCurrentMove)) { s16 healthValue = min(gBattleMoveDamage, 10000); // Max damage (10000) not present in R/S, ensures that huge damage values don't change sign - BtlController_EmitHealthBarUpdate(BUFFER_A, healthValue); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitHealthBarUpdate(battler, BUFFER_A, healthValue); + MarkBattlerForControllerExec(battler); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleMoveDamage > 0) + if (GetBattlerSide(battler) == B_SIDE_PLAYER && gBattleMoveDamage > 0) gBattleResults.playerMonWasDamaged = TRUE; } } @@ -2282,7 +2279,7 @@ static void Cmd_datahpupdate(void) { CMD_ARGS(u8 battler); - u32 moveType; + u32 battler, moveType; if (gBattleControllerExecFlags) return; @@ -2296,25 +2293,25 @@ static void Cmd_datahpupdate(void) if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) || (gHitMarker & HITMARKER_PASSIVE_DAMAGE)) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (DoesSubstituteBlockMove(gBattlerAttacker, gActiveBattler, gCurrentMove) && gDisableStructs[gActiveBattler].substituteHP && !(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE)) + battler = GetBattlerForBattleScript(cmd->battler); + if (DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && gDisableStructs[battler].substituteHP && !(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE)) { - if (gDisableStructs[gActiveBattler].substituteHP >= gBattleMoveDamage) + if (gDisableStructs[battler].substituteHP >= gBattleMoveDamage) { - if (gSpecialStatuses[gActiveBattler].dmg == 0) - gSpecialStatuses[gActiveBattler].dmg = gBattleMoveDamage; - gDisableStructs[gActiveBattler].substituteHP -= gBattleMoveDamage; + if (gSpecialStatuses[battler].dmg == 0) + gSpecialStatuses[battler].dmg = gBattleMoveDamage; + gDisableStructs[battler].substituteHP -= gBattleMoveDamage; gHpDealt = gBattleMoveDamage; } else { - if (gSpecialStatuses[gActiveBattler].dmg == 0) - gSpecialStatuses[gActiveBattler].dmg = gDisableStructs[gActiveBattler].substituteHP; - gHpDealt = gDisableStructs[gActiveBattler].substituteHP; - gDisableStructs[gActiveBattler].substituteHP = 0; + if (gSpecialStatuses[battler].dmg == 0) + gSpecialStatuses[battler].dmg = gDisableStructs[battler].substituteHP; + gHpDealt = gDisableStructs[battler].substituteHP; + gDisableStructs[battler].substituteHP = 0; } // check substitute fading - if (gDisableStructs[gActiveBattler].substituteHP == 0) + if (gDisableStructs[battler].substituteHP == 0) { gBattlescriptCurrInstr = cmd->nextInstr; BattleScriptPushCursor(); @@ -2322,9 +2319,9 @@ static void Cmd_datahpupdate(void) return; } } - else if (DoesDisguiseBlockMove(gBattlerAttacker, gActiveBattler, gCurrentMove)) + else if (DoesDisguiseBlockMove(gBattlerAttacker, battler, gCurrentMove)) { - gBattleMons[gActiveBattler].species = SPECIES_MIMIKYU_BUSTED; + gBattleMons[battler].species = SPECIES_MIMIKYU_BUSTED; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = BattleScript_TargetFormChange; return; @@ -2334,9 +2331,9 @@ static void Cmd_datahpupdate(void) gHitMarker &= ~HITMARKER_IGNORE_SUBSTITUTE; if (gBattleMoveDamage < 0) // hp goes up { - gBattleMons[gActiveBattler].hp -= gBattleMoveDamage; - if (gBattleMons[gActiveBattler].hp > gBattleMons[gActiveBattler].maxHP) - gBattleMons[gActiveBattler].hp = gBattleMons[gActiveBattler].maxHP; + gBattleMons[battler].hp -= gBattleMoveDamage; + if (gBattleMons[battler].hp > gBattleMons[battler].maxHP) + gBattleMons[battler].hp = gBattleMons[battler].maxHP; } else // hp goes down @@ -2347,68 +2344,68 @@ static void Cmd_datahpupdate(void) } else { - gTakenDmg[gActiveBattler] += gBattleMoveDamage; + gTakenDmg[battler] += gBattleMoveDamage; if (cmd->battler == BS_TARGET) - gTakenDmgByBattler[gActiveBattler] = gBattlerAttacker; + gTakenDmgByBattler[battler] = gBattlerAttacker; else - gTakenDmgByBattler[gActiveBattler] = gBattlerTarget; + gTakenDmgByBattler[battler] = gBattlerTarget; } - if (gBattleMons[gActiveBattler].hp > gBattleMoveDamage) + if (gBattleMons[battler].hp > gBattleMoveDamage) { - gBattleMons[gActiveBattler].hp -= gBattleMoveDamage; + gBattleMons[battler].hp -= gBattleMoveDamage; gHpDealt = gBattleMoveDamage; } else { - gHpDealt = gBattleMons[gActiveBattler].hp; - gBattleMons[gActiveBattler].hp = 0; + gHpDealt = gBattleMons[battler].hp; + gBattleMons[battler].hp = 0; } - if (!gSpecialStatuses[gActiveBattler].dmg && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE)) - gSpecialStatuses[gActiveBattler].dmg = gHpDealt; + if (!gSpecialStatuses[battler].dmg && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE)) + gSpecialStatuses[battler].dmg = gHpDealt; if (IS_MOVE_PHYSICAL(gCurrentMove) && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE) && gCurrentMove != MOVE_PAIN_SPLIT) { - gProtectStructs[gActiveBattler].physicalDmg = gHpDealt; - gSpecialStatuses[gActiveBattler].physicalDmg = gHpDealt; + gProtectStructs[battler].physicalDmg = gHpDealt; + gSpecialStatuses[battler].physicalDmg = gHpDealt; if (cmd->battler == BS_TARGET) { - gProtectStructs[gActiveBattler].physicalBattlerId = gBattlerAttacker; - gSpecialStatuses[gActiveBattler].physicalBattlerId = gBattlerAttacker; + gProtectStructs[battler].physicalBattlerId = gBattlerAttacker; + gSpecialStatuses[battler].physicalBattlerId = gBattlerAttacker; } else { - gProtectStructs[gActiveBattler].physicalBattlerId = gBattlerTarget; - gSpecialStatuses[gActiveBattler].physicalBattlerId = gBattlerTarget; + gProtectStructs[battler].physicalBattlerId = gBattlerTarget; + gSpecialStatuses[battler].physicalBattlerId = gBattlerTarget; } } else if (!IS_MOVE_PHYSICAL(gCurrentMove) && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE)) { - gProtectStructs[gActiveBattler].specialDmg = gHpDealt; - gSpecialStatuses[gActiveBattler].specialDmg = gHpDealt; + gProtectStructs[battler].specialDmg = gHpDealt; + gSpecialStatuses[battler].specialDmg = gHpDealt; if (cmd->battler == BS_TARGET) { - gProtectStructs[gActiveBattler].specialBattlerId = gBattlerAttacker; - gSpecialStatuses[gActiveBattler].specialBattlerId = gBattlerAttacker; + gProtectStructs[battler].specialBattlerId = gBattlerAttacker; + gSpecialStatuses[battler].specialBattlerId = gBattlerAttacker; } else { - gProtectStructs[gActiveBattler].specialBattlerId = gBattlerTarget; - gSpecialStatuses[gActiveBattler].specialBattlerId = gBattlerTarget; + gProtectStructs[battler].specialBattlerId = gBattlerTarget; + gSpecialStatuses[battler].specialBattlerId = gBattlerTarget; } } } gHitMarker &= ~HITMARKER_PASSIVE_DAMAGE; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[battler].hp), &gBattleMons[battler].hp); + MarkBattlerForControllerExec(battler); } } else { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (gSpecialStatuses[gActiveBattler].dmg == 0) - gSpecialStatuses[gActiveBattler].dmg = 0xFFFF; + battler = GetBattlerForBattleScript(cmd->battler); + if (gSpecialStatuses[battler].dmg == 0) + gSpecialStatuses[battler].dmg = 0xFFFF; } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -2440,18 +2437,17 @@ static void Cmd_effectivenesssound(void) if (gBattleControllerExecFlags) return; - gActiveBattler = gBattlerTarget; if (!(gMoveResultFlags & MOVE_RESULT_MISSED)) { switch (gMoveResultFlags & ~MOVE_RESULT_MISSED) { case MOVE_RESULT_SUPER_EFFECTIVE: - BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerTarget, BUFFER_A, SE_SUPER_EFFECTIVE); + MarkBattlerForControllerExec(gBattlerTarget); break; case MOVE_RESULT_NOT_VERY_EFFECTIVE: - BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerTarget, BUFFER_A, SE_NOT_EFFECTIVE); + MarkBattlerForControllerExec(gBattlerTarget); break; case MOVE_RESULT_DOESNT_AFFECT_FOE: case MOVE_RESULT_FAILED: @@ -2464,18 +2460,18 @@ static void Cmd_effectivenesssound(void) default: if (gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) { - BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerTarget, BUFFER_A, SE_SUPER_EFFECTIVE); + MarkBattlerForControllerExec(gBattlerTarget); } else if (gMoveResultFlags & MOVE_RESULT_NOT_VERY_EFFECTIVE) { - BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerTarget, BUFFER_A, SE_NOT_EFFECTIVE); + MarkBattlerForControllerExec(gBattlerTarget); } else if (!(gMoveResultFlags & (MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED))) { - BtlController_EmitPlaySE(BUFFER_A, SE_EFFECTIVE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerTarget, BUFFER_A, SE_EFFECTIVE); + MarkBattlerForControllerExec(gBattlerTarget); } break; } @@ -2629,10 +2625,8 @@ static void Cmd_printselectionstring(void) { CMD_ARGS(u16 id); - gActiveBattler = gBattlerAttacker; - - BtlController_EmitPrintSelectionString(BUFFER_A, cmd->id); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPrintSelectionString(gBattlerAttacker, BUFFER_A, cmd->id); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; gBattleCommunication[MSG_DISPLAY] = 1; @@ -2685,32 +2679,31 @@ static void Cmd_printselectionstringfromtable(void) const u16 *ptr = cmd->ptr; ptr += gBattleCommunication[MULTISTRING_CHOOSER]; - gActiveBattler = gBattlerAttacker; - BtlController_EmitPrintSelectionString(BUFFER_A, *ptr); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPrintSelectionString(gBattlerAttacker, BUFFER_A, *ptr); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; gBattleCommunication[MSG_DISPLAY] = 1; } } -u8 GetBattlerTurnOrderNum(u8 battlerId) +u8 GetBattlerTurnOrderNum(u8 battler) { s32 i; for (i = 0; i < gBattlersCount; i++) { - if (gBattlerByTurnOrder[i] == battlerId) + if (gBattlerByTurnOrder[i] == battler) break; } return i; } -static void CheckSetUnburden(u8 battlerId) +static void CheckSetUnburden(u8 battler) { - if (GetBattlerAbility(battlerId) == ABILITY_UNBURDEN) + if (GetBattlerAbility(battler) == ABILITY_UNBURDEN) { - gBattleResources->flags->flags[battlerId] |= RESOURCE_FLAG_UNBURDEN; - RecordAbilityBattle(battlerId, ABILITY_UNBURDEN); + gBattleResources->flags->flags[battler] |= RESOURCE_FLAG_UNBURDEN; + RecordAbilityBattle(battler, ABILITY_UNBURDEN); } } @@ -2727,12 +2720,10 @@ void StealTargetItem(u8 battlerStealer, u8 battlerItem) CheckSetUnburden(battlerItem); gBattleResources->flags->flags[battlerStealer] &= ~RESOURCE_FLAG_UNBURDEN; - gActiveBattler = battlerStealer; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gLastUsedItem), &gLastUsedItem); // set attacker item + BtlController_EmitSetMonData(battlerStealer, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gLastUsedItem), &gLastUsedItem); // set attacker item MarkBattlerForControllerExec(battlerStealer); - gActiveBattler = battlerItem; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[battlerItem].item); // remove target item + BtlController_EmitSetMonData(battlerItem, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[battlerItem].item); // remove target item MarkBattlerForControllerExec(battlerItem); gBattleStruct->choicedMove[battlerItem] = 0; @@ -2790,7 +2781,7 @@ void SetMoveEffect(bool32 primary, u32 certain) if (gBattleScripting.moveEffect & MOVE_EFFECT_AFFECTS_USER) { - gEffectBattler = gBattlerAttacker; // battlerId that effects get applied on + gEffectBattler = gBattlerAttacker; // battler that effects get applied on gBattleScripting.moveEffect &= ~MOVE_EFFECT_AFFECTS_USER; affectsUser = MOVE_EFFECT_AFFECTS_USER; gBattleScripting.battler = gBattlerTarget; // theoretically the attacker @@ -2840,15 +2831,15 @@ void SetMoveEffect(bool32 primary, u32 certain) // check active uproar if (battlerAbility != ABILITY_SOUNDPROOF) { - for (gActiveBattler = 0; - gActiveBattler < gBattlersCount && !(gBattleMons[gActiveBattler].status2 & STATUS2_UPROAR); - gActiveBattler++) + for (i = 0; i < gBattlersCount && !(gBattleMons[i].status2 & STATUS2_UPROAR); i++) ; } else - gActiveBattler = gBattlersCount; + { + i = gBattlersCount; + } - if (gActiveBattler != gBattlersCount) + if (i != gBattlersCount) break; if (!CanSleep(gEffectBattler)) break; @@ -3048,9 +3039,8 @@ void SetMoveEffect(bool32 primary, u32 certain) gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleScripting.moveEffect]; - gActiveBattler = gEffectBattler; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].status1), &gBattleMons[gEffectBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gEffectBattler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].status1), &gBattleMons[gEffectBattler].status1); + MarkBattlerForControllerExec(gEffectBattler); if (gHitMarker & HITMARKER_IGNORE_SAFEGUARD) { @@ -3578,9 +3568,8 @@ void SetMoveEffect(bool32 primary, u32 certain) gBattleMons[gEffectBattler].item = 0; CheckSetUnburden(gEffectBattler); - gActiveBattler = gEffectBattler; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gEffectBattler, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item); + MarkBattlerForControllerExec(gEffectBattler); BattleScriptPush(gBattlescriptCurrInstr + 1); gBattlescriptCurrInstr = BattleScript_MoveEffectIncinerate; } @@ -3593,10 +3582,9 @@ void SetMoveEffect(bool32 primary, u32 certain) gLastUsedItem = gBattleMons[gEffectBattler].item; gBattleMons[gEffectBattler].item = 0; CheckSetUnburden(gEffectBattler); - gActiveBattler = gEffectBattler; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gEffectBattler, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item); + MarkBattlerForControllerExec(gEffectBattler); BattleScriptPush(gBattlescriptCurrInstr + 1); gBattlescriptCurrInstr = BattleScript_MoveEffectBugBite; } @@ -3753,12 +3741,12 @@ static void Cmd_clearstatusfromeffect(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + u32 battler = GetBattlerForBattleScript(cmd->battler); if (gBattleScripting.moveEffect <= PRIMARY_STATUS_MOVE_EFFECT) - gBattleMons[gActiveBattler].status1 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); + gBattleMons[battler].status1 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); else - gBattleMons[gActiveBattler].status2 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); + gBattleMons[battler].status2 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); gBattleScripting.moveEffect = 0; gBattlescriptCurrInstr = cmd->nextInstr; @@ -3768,18 +3756,17 @@ static void Cmd_clearstatusfromeffect(void) static void Cmd_tryfaintmon(void) { 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) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (gHitMarker & HITMARKER_FAINTED(gActiveBattler)) + if (gHitMarker & HITMARKER_FAINTED(battler)) { - instr = cmd->instr; - BattleScriptPop(); - gBattlescriptCurrInstr = instr; - gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); + gBattlescriptCurrInstr = cmd->instr; + gSideStatuses[GetBattlerSide(battler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); } else { @@ -3788,46 +3775,42 @@ static void Cmd_tryfaintmon(void) } else { - u8 battlerId; - if (cmd->battler == BS_ATTACKER) { - gActiveBattler = gBattlerAttacker; - battlerId = gBattlerTarget; - instr = BattleScript_FaintAttacker; + destinyBondBattler = gBattlerTarget; + faintScript = BattleScript_FaintAttacker; } else { - gActiveBattler = gBattlerTarget; - battlerId = gBattlerAttacker; - instr = BattleScript_FaintTarget; + destinyBondBattler = gBattlerAttacker; + faintScript = BattleScript_FaintTarget; } - if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler]) - && gBattleMons[gActiveBattler].hp == 0) + if (!(gAbsentBattlerFlags & gBitTable[battler]) + && gBattleMons[battler].hp == 0) { - gHitMarker |= HITMARKER_FAINTED(gActiveBattler); + gHitMarker |= HITMARKER_FAINTED(battler); BattleScriptPush(cmd->nextInstr); - gBattlescriptCurrInstr = instr; - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + gBattlescriptCurrInstr = faintScript; + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { gHitMarker |= HITMARKER_PLAYER_FAINTED; if (gBattleResults.playerFaintCounter < 255) gBattleResults.playerFaintCounter++; - AdjustFriendshipOnBattleFaint(gActiveBattler); + AdjustFriendshipOnBattleFaint(battler); gSideTimers[B_SIDE_PLAYER].retaliateTimer = 2; } else { if (gBattleResults.opponentFaintCounter < 255) 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; } if ((gHitMarker & HITMARKER_DESTINYBOND) && gBattleMons[gBattlerAttacker].hp != 0) { gHitMarker &= ~HITMARKER_DESTINYBOND; BattleScriptPush(gBattlescriptCurrInstr); - gBattleMoveDamage = gBattleMons[battlerId].hp; + gBattleMoveDamage = gBattleMons[destinyBondBattler].hp; gBattlescriptCurrInstr = BattleScript_DestinyBondTakesLife; } if ((gStatuses3[gBattlerTarget] & STATUS3_GRUDGE) @@ -3841,9 +3824,8 @@ static void Cmd_tryfaintmon(void) gBattleMons[gBattlerAttacker].pp[moveIndex] = 0; BattleScriptPush(gBattlescriptCurrInstr); gBattlescriptCurrInstr = BattleScript_GrudgeTakesPp; - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].pp[moveIndex]), &gBattleMons[gActiveBattler].pp[moveIndex]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, sizeof(gBattleMons[gBattlerAttacker].pp[moveIndex]), &gBattleMons[gBattlerAttacker].pp[moveIndex]); + MarkBattlerForControllerExec(gBattlerAttacker); PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].moves[moveIndex]) } @@ -3861,9 +3843,9 @@ static void Cmd_dofaintanimation(void) if (gBattleControllerExecFlags == 0) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitFaintAnimation(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitFaintAnimation(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -3874,16 +3856,16 @@ static void Cmd_cleareffectsonfaint(void) if (gBattleControllerExecFlags == 0) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + u32 battler = GetBattlerForBattleScript(cmd->battler); - if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[gActiveBattler].hp == 0) + if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[battler].hp == 0) { - gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMons[battler].status1 = 0; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } - FaintClearSetData(); // Effects like attractions, trapping, etc. + FaintClearSetData(battler); // Effects like attractions, trapping, etc. gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -3892,11 +3874,11 @@ static void Cmd_jumpifstatus(void) { CMD_ARGS(u8 battler, u32 flags, const u8 *jumpInstr); - u8 battlerId = GetBattlerForBattleScript(cmd->battler); + u8 battler = GetBattlerForBattleScript(cmd->battler); u32 flags = cmd->flags; const u8 *jumpInstr = cmd->jumpInstr; - if (gBattleMons[battlerId].status1 & flags && gBattleMons[battlerId].hp != 0) + if (gBattleMons[battler].status1 & flags && gBattleMons[battler].hp != 0) gBattlescriptCurrInstr = jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -3906,11 +3888,11 @@ static void Cmd_jumpifstatus2(void) { CMD_ARGS(u8 battler, u32 flags, const u8 *jumpInstr); - u8 battlerId = GetBattlerForBattleScript(cmd->battler); + u8 battler = GetBattlerForBattleScript(cmd->battler); u32 flags = cmd->flags; const u8 *jumpInstr = cmd->jumpInstr; - if (gBattleMons[battlerId].status2 & flags && gBattleMons[battlerId].hp != 0) + if (gBattleMons[battler].status2 & flags && gBattleMons[battler].hp != 0) gBattlescriptCurrInstr = jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -3920,30 +3902,30 @@ static void Cmd_jumpifability(void) { CMD_ARGS(u8 battler, u16 ability, const u8 *jumpInstr); - u32 battlerId; + u32 battler; bool32 hasAbility = FALSE; u32 ability = cmd->ability; switch (cmd->battler) { default: - battlerId = GetBattlerForBattleScript(cmd->battler); - if (GetBattlerAbility(battlerId) == ability) + battler = GetBattlerForBattleScript(cmd->battler); + if (GetBattlerAbility(battler) == ability) hasAbility = TRUE; break; case BS_ATTACKER_SIDE: - battlerId = IsAbilityOnSide(gBattlerAttacker, ability); - if (battlerId) + battler = IsAbilityOnSide(gBattlerAttacker, ability); + if (battler) { - battlerId--; + battler--; hasAbility = TRUE; } break; case BS_TARGET_SIDE: - battlerId = IsAbilityOnOpposingSide(gBattlerAttacker, ability); - if (battlerId) + battler = IsAbilityOnOpposingSide(gBattlerAttacker, ability); + if (battler) { - battlerId--; + battler--; hasAbility = TRUE; } break; @@ -3953,8 +3935,8 @@ static void Cmd_jumpifability(void) { gLastUsedAbility = ability; gBattlescriptCurrInstr = cmd->jumpInstr; - RecordAbilityBattle(battlerId, gLastUsedAbility); - gBattlerAbility = battlerId; + RecordAbilityBattle(battler, gLastUsedAbility); + gBattlerAbility = battler; } else { @@ -3985,12 +3967,12 @@ static void Cmd_jumpifstat(void) CMD_ARGS(u8 battler, u8 comparison, u8 stat, u8 value, const u8 *jumpInstr); bool32 ret = 0; - u8 battlerId = GetBattlerForBattleScript(cmd->battler); + u8 battler = GetBattlerForBattleScript(cmd->battler); u8 stat = cmd->stat; u8 value = cmd->value; u8 comparison = cmd->comparison; - ret = CompareStat(battlerId, stat, value, comparison); + ret = CompareStat(battler, stat, value, comparison); if (ret) gBattlescriptCurrInstr = cmd->jumpInstr; @@ -4002,24 +3984,18 @@ static void Cmd_jumpifstatus3condition(void) { CMD_ARGS(u8 battler, u32 flags, bool8 jumpIfTrue, const u8 *jumpInstr); - u32 flags; - const u8 *jumpInstr; - - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - flags = cmd->flags; - jumpInstr = cmd->jumpInstr; - + u32 battler = GetBattlerForBattleScript(cmd->battler); if (cmd->jumpIfTrue) { - if ((gStatuses3[gActiveBattler] & flags) != 0) + if ((gStatuses3[battler] & cmd->flags) != 0) gBattlescriptCurrInstr = cmd->nextInstr; else - gBattlescriptCurrInstr = jumpInstr; + gBattlescriptCurrInstr = cmd->jumpInstr; } else { - if ((gStatuses3[gActiveBattler] & flags) != 0) - gBattlescriptCurrInstr = jumpInstr; + if ((gStatuses3[battler] & cmd->flags) != 0) + gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; } @@ -4029,14 +4005,14 @@ static void Cmd_jumpbasedontype(void) { CMD_ARGS(u8 battler, u8 type, u8 jumpIfType, const u8 *jumpInstr); - u8 battlerId = GetBattlerForBattleScript(cmd->battler); + u8 battler = GetBattlerForBattleScript(cmd->battler); u8 type = cmd->type; const u8 *jumpInstr = cmd->jumpInstr; // jumpiftype if (cmd->jumpIfType) { - if (IS_BATTLER_OF_TYPE(battlerId, type)) + if (IS_BATTLER_OF_TYPE(battler, type)) gBattlescriptCurrInstr = jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -4044,7 +4020,7 @@ static void Cmd_jumpbasedontype(void) // jumpifnottype else { - if (!IS_BATTLER_OF_TYPE(battlerId, type)) + if (!IS_BATTLER_OF_TYPE(battler, type)) gBattlescriptCurrInstr = jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -4239,7 +4215,7 @@ static void Cmd_getexp(void) i = STRINGID_EMPTYSTRING4; } - // get exp getter battlerId + // get exp getter battler if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { if (gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId && !(gAbsentBattlerFlags & gBitTable[2])) @@ -4283,9 +4259,8 @@ static void Cmd_getexp(void) gBattleResources->beforeLvlUp->stats[STAT_SPATK] = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPATK); gBattleResources->beforeLvlUp->stats[STAT_SPDEF] = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF); - gActiveBattler = gBattleStruct->expGetterBattlerId; - BtlController_EmitExpUpdate(BUFFER_A, gBattleStruct->expGetterMonId, gBattleMoveDamage); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitExpUpdate(gBattleStruct->expGetterBattlerId, BUFFER_A, gBattleStruct->expGetterMonId, gBattleMoveDamage); + MarkBattlerForControllerExec(gBattleStruct->expGetterBattlerId); } gBattleScripting.getexpState++; } @@ -4293,33 +4268,33 @@ static void Cmd_getexp(void) case 4: // lvl up if necessary if (gBattleControllerExecFlags == 0) { - gActiveBattler = gBattleStruct->expGetterBattlerId; - if (gBattleResources->bufferB[gActiveBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleResources->bufferB[gActiveBattler][1] == RET_VALUE_LEVELED_UP) + u32 expBattler = gBattleStruct->expGetterBattlerId; + if (gBattleResources->bufferB[expBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleResources->bufferB[expBattler][1] == RET_VALUE_LEVELED_UP) { - u16 temp, battlerId = 0xFF; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId) - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); + u16 temp, battler = 0xFF; + if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattlerPartyIndexes[expBattler] == gBattleStruct->expGetterMonId) + 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)); BattleScriptPushCursor(); gLeveledUpInBattle |= gBitTable[gBattleStruct->expGetterMonId]; 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); // update battle mon structure after level up if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId && gBattleMons[0].hp) - battlerId = 0; + battler = 0; else if (gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId && gBattleMons[2].hp && (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - battlerId = 2; + battler = 2; - if (battlerId != 0xFF) + if (battler != 0xFF) { - CopyMonLevelAndBaseStatsToBattleMon(battlerId, &gPlayerParty[gBattleStruct->expGetterMonId]); - if (gStatuses3[battlerId] & STATUS3_POWER_TRICK) - SWAP(gBattleMons[battlerId].attack, gBattleMons[battlerId].defense, temp); + CopyMonLevelAndBaseStatsToBattleMon(battler, &gPlayerParty[gBattleStruct->expGetterMonId]); + if (gStatuses3[battler] & STATUS3_POWER_TRICK) + SWAP(gBattleMons[battler].attack, gBattleMons[battler].defense, temp); } gBattleScripting.getexpState = 5; @@ -4859,14 +4834,15 @@ static void Cmd_waitstate(void) static void Cmd_healthbar_update(void) { CMD_ARGS(u8 battler); + u32 battler; if (cmd->battler == BS_TARGET) - gActiveBattler = gBattlerTarget; + battler = gBattlerTarget; else - gActiveBattler = gBattlerAttacker; + battler = gBattlerAttacker; - BtlController_EmitHealthBarUpdate(BUFFER_A, gBattleMoveDamage); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitHealthBarUpdate(battler, BUFFER_A, gBattleMoveDamage); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -4883,7 +4859,6 @@ static void Cmd_end(void) BattleArena_AddSkillPoints(gBattlerAttacker); gMoveResultFlags = 0; - gActiveBattler = 0; gCurrentActionFuncId = B_ACTION_TRY_FINISH; } @@ -4891,7 +4866,6 @@ static void Cmd_end2(void) { CMD_ARGS(); - gActiveBattler = 0; gCurrentActionFuncId = B_ACTION_TRY_FINISH; } @@ -4975,21 +4949,13 @@ static void Cmd_endselectionscript(void) *(gBattlerAttacker + gBattleStruct->selectionScriptFinished) = TRUE; } -static void Cmd_playanimation(void) +static void PlayAnimation(u32 battler, u8 animId, const u16 *argPtr, const u8 *nextInstr) { - CMD_ARGS(u8 battler, u8 animId, const u16 *argPtr); - - const u16 *argPtr; - u8 animId = cmd->animId; - - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - argPtr = cmd->argPtr; - #if B_TERRAIN_BG_CHANGE == FALSE if (animId == B_ANIM_RESTORE_BG) { // workaround for .if not working - gBattlescriptCurrInstr = cmd->nextInstr; + gBattlescriptCurrInstr = nextInstr; return; } #endif @@ -5003,13 +4969,13 @@ static void Cmd_playanimation(void) || animId == B_ANIM_PRIMAL_REVERSION || animId == B_ANIM_ULTRA_BURST) { - BtlController_EmitBattleAnimation(BUFFER_A, animId, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; + BtlController_EmitBattleAnimation(battler, BUFFER_A, animId, *argPtr); + MarkBattlerForControllerExec(battler); + gBattlescriptCurrInstr = nextInstr; } else if (gHitMarker & HITMARKER_NO_ANIMATIONS && animId != B_ANIM_RESTORE_BG) { - BattleScriptPush(cmd->nextInstr); + BattleScriptPush(nextInstr); gBattlescriptCurrInstr = BattleScript_Pausex20; } else if (animId == B_ANIM_RAIN_CONTINUES @@ -5018,71 +4984,37 @@ static void Cmd_playanimation(void) || animId == B_ANIM_HAIL_CONTINUES || animId == B_ANIM_SNOW_CONTINUES) { - BtlController_EmitBattleAnimation(BUFFER_A, animId, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; + BtlController_EmitBattleAnimation(battler, BUFFER_A, animId, *argPtr); + MarkBattlerForControllerExec(battler); + gBattlescriptCurrInstr = nextInstr; } - else if (gStatuses3[gActiveBattler] & STATUS3_SEMI_INVULNERABLE) + else if (gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) { - gBattlescriptCurrInstr = cmd->nextInstr; + gBattlescriptCurrInstr = nextInstr; } else { - BtlController_EmitBattleAnimation(BUFFER_A, animId, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; + BtlController_EmitBattleAnimation(battler, BUFFER_A, animId, *argPtr); + MarkBattlerForControllerExec(battler); + gBattlescriptCurrInstr = nextInstr; } } +static void Cmd_playanimation(void) +{ + CMD_ARGS(u8 battler, u8 animId, const u16 *argPtr); + + u32 battler = GetBattlerForBattleScript(cmd->battler); + PlayAnimation(battler, cmd->animId, cmd->argPtr, cmd->nextInstr); +} + // Same as playanimation, except it takes a pointer to some animation id, instead of taking the value directly static void Cmd_playanimation_var(void) { CMD_ARGS(u8 battler, const u8 *animIdPtr, const u16 *argPtr); - const u16 *argPtr; - const u8 *animIdPtr; - - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - animIdPtr = cmd->animIdPtr; - argPtr = cmd->argPtr; - - if (*animIdPtr == B_ANIM_STATS_CHANGE - || *animIdPtr == B_ANIM_SNATCH_MOVE - || *animIdPtr == B_ANIM_MEGA_EVOLUTION - || *animIdPtr == B_ANIM_ILLUSION_OFF - || *animIdPtr == B_ANIM_FORM_CHANGE - || *animIdPtr == B_ANIM_SUBSTITUTE_FADE - || *animIdPtr == B_ANIM_PRIMAL_REVERSION - || *animIdPtr == B_ANIM_ULTRA_BURST) - { - BtlController_EmitBattleAnimation(BUFFER_A, *animIdPtr, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; - } - else if (gHitMarker & HITMARKER_NO_ANIMATIONS) - { - gBattlescriptCurrInstr = cmd->nextInstr; - } - else if (*animIdPtr == B_ANIM_RAIN_CONTINUES - || *animIdPtr == B_ANIM_SUN_CONTINUES - || *animIdPtr == B_ANIM_SANDSTORM_CONTINUES - || *animIdPtr == B_ANIM_HAIL_CONTINUES - || *animIdPtr == B_ANIM_SNOW_CONTINUES) - { - BtlController_EmitBattleAnimation(BUFFER_A, *animIdPtr, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; - } - else if (gStatuses3[gActiveBattler] & STATUS3_SEMI_INVULNERABLE) - { - gBattlescriptCurrInstr = cmd->nextInstr; - } - else - { - BtlController_EmitBattleAnimation(BUFFER_A, *animIdPtr, *argPtr); - MarkBattlerForControllerExec(gActiveBattler); - gBattlescriptCurrInstr = cmd->nextInstr; - } + u32 battler = GetBattlerForBattleScript(cmd->battler); + PlayAnimation(battler, *(cmd->animIdPtr), cmd->argPtr, cmd->nextInstr); } static void Cmd_setgraphicalstatchangevalues(void) @@ -5127,17 +5059,14 @@ static void Cmd_playstatchangeanimation(void) { CMD_ARGS(u8 battler, u8 stats, u8 flags); - u32 ability; u32 currStat = 0; u32 statAnimId = 0; u32 changeableStatsCount = 0; - u32 stats = 0; u32 startingStatAnimId = 0; u32 flags = cmd->flags; - - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - ability = GetBattlerAbility(gActiveBattler); - stats = cmd->stats; + u32 battler = GetBattlerForBattleScript(cmd->battler); + u32 ability = GetBattlerAbility(battler); + u32 stats = cmd->stats; // Handle Contrary and Simple if (ability == ABILITY_CONTRARY) @@ -5158,14 +5087,14 @@ static void Cmd_playstatchangeanimation(void) { if (flags & STAT_CHANGE_CANT_PREVENT) { - if (gBattleMons[gActiveBattler].statStages[currStat] > MIN_STAT_STAGE) + if (gBattleMons[battler].statStages[currStat] > MIN_STAT_STAGE) { statAnimId = startingStatAnimId + currStat; changeableStatsCount++; } } - else if (!gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].mistTimer - && GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_CLEAR_AMULET + else if (!gSideTimers[GET_BATTLER_SIDE(battler)].mistTimer + && GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_CLEAR_AMULET && ability != ABILITY_CLEAR_BODY && ability != ABILITY_FULL_METAL_BODY && ability != ABILITY_WHITE_SMOKE @@ -5173,7 +5102,7 @@ static void Cmd_playstatchangeanimation(void) && !(ability == ABILITY_HYPER_CUTTER && currStat == STAT_ATK) && !(ability == ABILITY_BIG_PECKS && currStat == STAT_DEF)) { - if (gBattleMons[gActiveBattler].statStages[currStat] > MIN_STAT_STAGE) + if (gBattleMons[battler].statStages[currStat] > MIN_STAT_STAGE) { statAnimId = startingStatAnimId + currStat; changeableStatsCount++; @@ -5200,7 +5129,7 @@ static void Cmd_playstatchangeanimation(void) while (stats != 0) { - if (stats & 1 && gBattleMons[gActiveBattler].statStages[currStat] < MAX_STAT_STAGE) + if (stats & 1 && gBattleMons[battler].statStages[currStat] < MAX_STAT_STAGE) { statAnimId = startingStatAnimId + currStat; changeableStatsCount++; @@ -5223,8 +5152,8 @@ static void Cmd_playstatchangeanimation(void) } else if (changeableStatsCount != 0 && !gBattleScripting.statAnimPlayed) { - BtlController_EmitBattleAnimation(BUFFER_A, B_ANIM_STATS_CHANGE, statAnimId); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitBattleAnimation(battler, BUFFER_A, B_ANIM_STATS_CHANGE, statAnimId); + MarkBattlerForControllerExec(battler); if (flags & STAT_CHANGE_MULTIPLE_STATS && changeableStatsCount > 1) gBattleScripting.statAnimPlayed = TRUE; gBattlescriptCurrInstr = cmd->nextInstr; @@ -5388,9 +5317,8 @@ static void Cmd_moveend(void) { gProtectStructs[gBattlerAttacker].touchedProtectLike = FALSE; gBattleMons[gBattlerAttacker].status1 = STATUS1_BURN; - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerAttacker].status1), &gBattleMons[gBattlerAttacker].status1); + MarkBattlerForControllerExec(gBattlerAttacker); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BeakBlastBurn; effect = 1; @@ -5427,9 +5355,8 @@ static void Cmd_moveend(void) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) { gBattleMons[gBattlerTarget].status1 &= ~STATUS1_FREEZE; - gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerTarget, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); + MarkBattlerForControllerExec(gBattlerTarget); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_DefrostedViaFireMove; effect = TRUE; @@ -5441,9 +5368,8 @@ static void Cmd_moveend(void) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) { gBattleMons[gBattlerTarget].status1 &= ~STATUS1_FROSTBITE; - gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerTarget, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); + MarkBattlerForControllerExec(gBattlerTarget); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_FrostbiteHealedViaFireMove; effect = TRUE; @@ -5583,9 +5509,8 @@ static void Cmd_moveend(void) { gBattleMons[gBattlerTarget].status1 &= ~(gBattleMoves[gCurrentMove].argument); - gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerTarget, 0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gBattlerTarget].status1); + MarkBattlerForControllerExec(gBattlerTarget); effect = TRUE; BattleScriptPush(gBattlescriptCurrInstr); switch (gBattleMoves[gCurrentMove].argument) @@ -5623,9 +5548,8 @@ static void Cmd_moveend(void) if (gStatuses3[gBattlerAttacker] & (STATUS3_SEMI_INVULNERABLE) && gHitMarker & HITMARKER_NO_ANIMATIONS) { - gActiveBattler = gBattlerAttacker; - BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSpriteInvisibility(gBattlerAttacker, BUFFER_A, TRUE); + MarkBattlerForControllerExec(gBattlerAttacker); gBattleScripting.moveendState++; return; } @@ -5636,9 +5560,8 @@ static void Cmd_moveend(void) || !(gStatuses3[gBattlerAttacker] & (STATUS3_SEMI_INVULNERABLE)) || WasUnableToUseMove(gBattlerAttacker)) { - gActiveBattler = gBattlerAttacker; - BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSpriteInvisibility(gBattlerAttacker, BUFFER_A, FALSE); + MarkBattlerForControllerExec(gBattlerAttacker); gStatuses3[gBattlerAttacker] &= ~STATUS3_SEMI_INVULNERABLE; gSpecialStatuses[gBattlerAttacker].restoredBattlerSprite = TRUE; gBattleScripting.moveendState++; @@ -5650,9 +5573,8 @@ static void Cmd_moveend(void) if (!gSpecialStatuses[gBattlerTarget].restoredBattlerSprite && gBattlerTarget < gBattlersCount && !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE)) { - gActiveBattler = gBattlerTarget; - BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSpriteInvisibility(gBattlerTarget, BUFFER_A, FALSE); + MarkBattlerForControllerExec(gBattlerTarget); gStatuses3[gBattlerTarget] &= ~STATUS3_SEMI_INVULNERABLE; gBattleScripting.moveendState++; return; @@ -5718,9 +5640,8 @@ static void Cmd_moveend(void) if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) { - gActiveBattler = gBattlerAttacker; - gBattlerAttacker = gBattlerTarget; - gBattlerTarget = gActiveBattler; + u8 temp; + SWAP(gBattlerAttacker, gBattlerTarget, temp); gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET; } if (!gSpecialStatuses[gBattlerAttacker].dancerUsedMove) @@ -5945,7 +5866,7 @@ static void Cmd_moveend(void) && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0) && CountUsablePartyMons(battler) > 0) // Has mon to switch into { - gActiveBattler = gBattleScripting.battler = battler; + gBattleScripting.battler = battler; gLastUsedItem = gBattleMons[battler].item; if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE) gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection @@ -5981,7 +5902,7 @@ static void Cmd_moveend(void) && CanBattlerSwitch(gBattlerAttacker)) { 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; if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE) gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection @@ -6009,7 +5930,7 @@ static void Cmd_moveend(void) && CountUsablePartyMons(battler) > 0) // Has mon to switch into { gProtectStructs[battler].statFell = FALSE; - gActiveBattler = gBattleScripting.battler = battler; + gBattleScripting.battler = battler; gLastUsedItem = gBattleMons[battler].item; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_EjectPackActivates; @@ -6208,11 +6129,10 @@ static void Cmd_returnatktoball(void) { CMD_ARGS(); - gActiveBattler = gBattlerAttacker; - if (!(gHitMarker & HITMARKER_FAINTED(gActiveBattler))) + if (!(gHitMarker & HITMARKER_FAINTED(gBattlerAttacker))) { - BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitReturnMonToBall(gBattlerAttacker, BUFFER_A, FALSE); + MarkBattlerForControllerExec(gBattlerAttacker); } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -6221,15 +6141,14 @@ static void Cmd_getswitchedmondata(void) { CMD_ARGS(u8 battler); + u32 battler = GetBattlerForBattleScript(cmd->battler); if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + gBattlerPartyIndexes[battler] = gBattleStruct->monToSwitchIntoId[battler]; - gBattlerPartyIndexes[gActiveBattler] = *(gBattleStruct->monToSwitchIntoId + gActiveBattler); - - BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitGetMonData(battler, BUFFER_A, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[battler]]); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -6239,78 +6158,80 @@ static void Cmd_switchindataupdate(void) CMD_ARGS(u8 battler); struct BattlePokemon oldData; - s32 i; + u32 battler, i; u8 *monData; if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - oldData = gBattleMons[gActiveBattler]; - monData = (u8 *)(&gBattleMons[gActiveBattler]); + battler = GetBattlerForBattleScript(cmd->battler); + oldData = gBattleMons[battler]; + monData = (u8 *)(&gBattleMons[battler]); for (i = 0; i < sizeof(struct BattlePokemon); i++) - monData[i] = gBattleResources->bufferB[gActiveBattler][4 + i]; + monData[i] = gBattleResources->bufferB[battler][4 + i]; - gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0]; - gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1]; - gBattleMons[gActiveBattler].type3 = TYPE_MYSTERY; - gBattleMons[gActiveBattler].ability = GetAbilityBySpecies(gBattleMons[gActiveBattler].species, gBattleMons[gActiveBattler].abilityNum); + gBattleMons[battler].type1 = gSpeciesInfo[gBattleMons[battler].species].types[0]; + gBattleMons[battler].type2 = gSpeciesInfo[gBattleMons[battler].species].types[1]; + gBattleMons[battler].type3 = TYPE_MYSTERY; + gBattleMons[battler].ability = GetAbilityBySpecies(gBattleMons[battler].species, gBattleMons[battler].abilityNum); // check knocked off item - i = GetBattlerSide(gActiveBattler); - if (gWishFutureKnock.knockedOffMons[i] & gBitTable[gBattlerPartyIndexes[gActiveBattler]]) + i = GetBattlerSide(battler); + if (gWishFutureKnock.knockedOffMons[i] & gBitTable[gBattlerPartyIndexes[battler]]) { - gBattleMons[gActiveBattler].item = ITEM_NONE; + gBattleMons[battler].item = ITEM_NONE; } if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) { for (i = 0; i < NUM_BATTLE_STATS; i++) { - gBattleMons[gActiveBattler].statStages[i] = oldData.statStages[i]; + gBattleMons[battler].statStages[i] = oldData.statStages[i]; } - gBattleMons[gActiveBattler].status2 = oldData.status2; + gBattleMons[battler].status2 = oldData.status2; } - SwitchInClearSetData(); + SwitchInClearSetData(battler); if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gBattleMons[gActiveBattler].maxHP / 2 >= gBattleMons[gActiveBattler].hp - && gBattleMons[gActiveBattler].hp != 0 - && !(gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP)) + && gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp + && gBattleMons[battler].hp != 0 + && !(gBattleMons[battler].status1 & STATUS1_SLEEP)) { - gBattleStruct->palaceFlags |= gBitTable[gActiveBattler]; + gBattleStruct->palaceFlags |= gBitTable[battler]; } - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gActiveBattler, gBattlerPartyIndexes[gActiveBattler]); + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, battler, gBattlerPartyIndexes[battler]); gBattlescriptCurrInstr = cmd->nextInstr; } static void Cmd_switchinanim(void) { + u32 battler; + CMD_ARGS(u8 battler, bool8 dontClearSubstitute); if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + battler = GetBattlerForBattleScript(cmd->battler); - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_TRAINER_HILL | BATTLE_TYPE_FRONTIER))) - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality); + HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); - gAbsentBattlerFlags &= ~(gBitTable[gActiveBattler]); + gAbsentBattlerFlags &= ~(gBitTable[battler]); - BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], cmd->dontClearSubstitute); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSwitchInAnim(battler, BUFFER_A, gBattlerPartyIndexes[battler], cmd->dontClearSubstitute); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; @@ -6318,13 +6239,13 @@ static void Cmd_switchinanim(void) BattleArena_InitPoints(); } -bool32 CanBattlerSwitch(u32 battlerId) +bool32 CanBattlerSwitch(u32 battler) { s32 i, lastMonId, battlerIn1, battlerIn2; bool32 ret = FALSE; struct Pokemon *party; - if (BATTLE_TWO_VS_ONE_OPPONENT && GetBattlerSide(battlerId) == B_SIDE_OPPONENT) + if (BATTLE_TWO_VS_ONE_OPPONENT && GetBattlerSide(battler) == B_SIDE_OPPONENT) { battlerIn1 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); battlerIn2 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); @@ -6343,10 +6264,10 @@ bool32 CanBattlerSwitch(u32 battlerId) } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - party = GetBattlerParty(battlerId); + party = GetBattlerParty(battler); lastMonId = 0; - if (battlerId & 2) + if (battler & 2) lastMonId = MULTI_PARTY_SIZE; for (i = lastMonId; i < lastMonId + MULTI_PARTY_SIZE; i++) @@ -6354,7 +6275,7 @@ bool32 CanBattlerSwitch(u32 battlerId) if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) && GetMonData(&party[i], MON_DATA_HP) != 0 - && gBattlerPartyIndexes[battlerId] != i) + && gBattlerPartyIndexes[battler] != i) break; } @@ -6364,19 +6285,19 @@ bool32 CanBattlerSwitch(u32 battlerId) { if (gBattleTypeFlags & BATTLE_TYPE_TOWER_LINK_MULTI) { - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { party = gPlayerParty; lastMonId = 0; - if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(battlerId)) == TRUE) + if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(battler)) == TRUE) lastMonId = MULTI_PARTY_SIZE; } else { party = gEnemyParty; - if (battlerId == 1) + if (battler == 1) lastMonId = 0; else lastMonId = MULTI_PARTY_SIZE; @@ -6384,10 +6305,10 @@ bool32 CanBattlerSwitch(u32 battlerId) } else { - party = GetBattlerParty(battlerId); + party = GetBattlerParty(battler); lastMonId = 0; - if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(battlerId)) == TRUE) + if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(battler)) == TRUE) lastMonId = MULTI_PARTY_SIZE; } @@ -6396,18 +6317,18 @@ bool32 CanBattlerSwitch(u32 battlerId) if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) && GetMonData(&party[i], MON_DATA_HP) != 0 - && gBattlerPartyIndexes[battlerId] != i) + && gBattlerPartyIndexes[battler] != i) break; } ret = (i != lastMonId + MULTI_PARTY_SIZE); } - else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerSide(battlerId) == B_SIDE_OPPONENT) + else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerSide(battler) == B_SIDE_OPPONENT) { party = gEnemyParty; lastMonId = 0; - if (battlerId == B_POSITION_OPPONENT_RIGHT) + if (battler == B_POSITION_OPPONENT_RIGHT) lastMonId = PARTY_SIZE / 2; for (i = lastMonId; i < lastMonId + (PARTY_SIZE / 2); i++) @@ -6415,7 +6336,7 @@ bool32 CanBattlerSwitch(u32 battlerId) if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&party[i], MON_DATA_IS_EGG) && GetMonData(&party[i], MON_DATA_HP) != 0 - && gBattlerPartyIndexes[battlerId] != i) + && gBattlerPartyIndexes[battler] != i) break; } @@ -6423,7 +6344,7 @@ bool32 CanBattlerSwitch(u32 battlerId) } else { - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) { battlerIn1 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); @@ -6465,15 +6386,14 @@ static void Cmd_jumpifcantswitch(void) { CMD_ARGS(u8 battler:7, u8 ignoreEscapePrevention:1, const u8 *jumpInstr); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - - if (!cmd->ignoreEscapePrevention && !CanBattlerEscape(gActiveBattler)) + u32 battler = GetBattlerForBattleScript(cmd->battler); + if (!cmd->ignoreEscapePrevention && !CanBattlerEscape(battler)) { gBattlescriptCurrInstr = cmd->jumpInstr; } else { - if (CanBattlerSwitch(gActiveBattler)) + if (CanBattlerSwitch(battler)) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->jumpInstr; @@ -6483,54 +6403,50 @@ static void Cmd_jumpifcantswitch(void) // Opens the party screen to choose a new Pokémon to send out. // slotId is the Pokémon to replace. // Note that this is not used by the Switch action, only replacing fainted Pokémon or Baton Pass -static void ChooseMonToSendOut(u8 slotId) +static void ChooseMonToSendOut(u32 battler, u8 slotId) { - *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); + gBattleStruct->battlerPartyIndexes[battler] = gBattlerPartyIndexes[battler]; + gBattleStruct->monToSwitchIntoId[battler] = PARTY_SIZE; + gBattleStruct->field_93 &= ~(gBitTable[battler]); - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitChoosePokemon(battler, BUFFER_A, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); + MarkBattlerForControllerExec(battler); } static void Cmd_openpartyscreen(void) { CMD_ARGS(u8 battler:7, u8 partyScreenOptional:1, const u8 *failInstr); - u32 flags; - u8 hitmarkerFaintBits; - u8 battlerId; - const u8 *failInstr; - - battlerId = 0; - flags = 0; - failInstr = cmd->failInstr; + u32 flags = 0; + u8 hitmarkerFaintBits = 0; + u32 i, battler = 0; + const u8 *failInstr = cmd->failInstr; if (cmd->battler == BS_FAINTED_LINK_MULTIPLE_1) { if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) || !(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (gHitMarker & HITMARKER_FAINTED(gActiveBattler)) + if (gHitMarker & HITMARKER_FAINTED(battler)) { - if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) + if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(PARTY_SIZE); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, PARTY_SIZE); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } } else { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } } } @@ -6542,88 +6458,88 @@ static void Cmd_openpartyscreen(void) if (gBitTable[0] & hitmarkerFaintBits) { - gActiveBattler = 0; - if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) + battler = 0; + if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[2]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[2]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } else { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); flags |= 1; } } if (gBitTable[2] & hitmarkerFaintBits && !(gBitTable[0] & hitmarkerFaintBits)) { - gActiveBattler = 2; - if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) + battler = 2; + if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[0]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[0]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } else if (!(flags & 1)) { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } } if (gBitTable[1] & hitmarkerFaintBits) { - gActiveBattler = 1; - if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) + battler = 1; + if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[3]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[3]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } else { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); flags |= 2; } } if (gBitTable[3] & hitmarkerFaintBits && !(gBitTable[1] & hitmarkerFaintBits)) { - gActiveBattler = 3; - if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) + battler = 3; + if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[1]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[1]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } else if (!(flags & 2)) { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } } @@ -6634,12 +6550,12 @@ static void Cmd_openpartyscreen(void) if (!hasReplacement_2 && hitmarkerFaintBits != 0) { if (gAbsentBattlerFlags & gBitTable[0]) - gActiveBattler = 2; + battler = 2; else - gActiveBattler = 0; + battler = 0; - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } } @@ -6650,12 +6566,12 @@ static void Cmd_openpartyscreen(void) if (!hasReplacement_3 && hitmarkerFaintBits != 0) { if (gAbsentBattlerFlags & gBitTable[1]) - gActiveBattler = 3; + battler = 3; else - gActiveBattler = 1; + battler = 1; - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battler, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battler); } } } @@ -6670,34 +6586,34 @@ static void Cmd_openpartyscreen(void) hitmarkerFaintBits = gHitMarker >> 28; if (gBitTable[2] & hitmarkerFaintBits && gBitTable[0] & hitmarkerFaintBits) { - gActiveBattler = 2; - if (HasNoMonsToSwitch(gActiveBattler, gBattleResources->bufferB[0][1], PARTY_SIZE)) + battler = 2; + if (HasNoMonsToSwitch(battler, gBattleResources->bufferB[0][1], PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[0]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[0]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } } if (gBitTable[3] & hitmarkerFaintBits && hitmarkerFaintBits & gBitTable[1]) { - gActiveBattler = 3; - if (HasNoMonsToSwitch(gActiveBattler, gBattleResources->bufferB[1][1], PARTY_SIZE)) + battler = 3; + if (HasNoMonsToSwitch(battler, gBattleResources->bufferB[1][1], PARTY_SIZE)) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); + BtlController_EmitCantSwitch(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); } - else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) + else if (!gSpecialStatuses[battler].faintedHasReplacement) { - ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[1]); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; + ChooseMonToSendOut(battler, gBattleStruct->monToSwitchIntoId[1]); + gSpecialStatuses[battler].faintedHasReplacement = TRUE; } } gBattlescriptCurrInstr = cmd->nextInstr; @@ -6731,52 +6647,50 @@ static void Cmd_openpartyscreen(void) else hitmarkerFaintBits = PARTY_ACTION_SEND_OUT; - battlerId = GetBattlerForBattleScript(cmd->battler); - if (gSpecialStatuses[battlerId].faintedHasReplacement) + battler = GetBattlerForBattleScript(cmd->battler); + if (gSpecialStatuses[battler].faintedHasReplacement) { gBattlescriptCurrInstr = cmd->nextInstr; } - else if (HasNoMonsToSwitch(battlerId, PARTY_SIZE, PARTY_SIZE)) + else if (HasNoMonsToSwitch(battler, PARTY_SIZE, PARTY_SIZE)) { - gActiveBattler = battlerId; - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker &= ~HITMARKER_FAINTED(battler); gBattlescriptCurrInstr = failInstr; } else { - gActiveBattler = battlerId; - *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); + *(gBattleStruct->battlerPartyIndexes + battler) = gBattlerPartyIndexes[battler]; + *(gBattleStruct->monToSwitchIntoId + battler) = PARTY_SIZE; + gBattleStruct->field_93 &= ~(gBitTable[battler]); - BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitChoosePokemon(battler, BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + BATTLE_PARTNER(battler)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[battler]); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; - if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_LEFT && gBattleResults.playerSwitchesCounter < 255) + if (GetBattlerPosition(battler) == B_POSITION_PLAYER_LEFT && gBattleResults.playerSwitchesCounter < 255) gBattleResults.playerSwitchesCounter++; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (i = 0; i < gBattlersCount; i++) { - if (gActiveBattler != battlerId) + if (i != battler) { - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(i, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(i); } } } else { - gActiveBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battlerId))); - if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) - gActiveBattler ^= BIT_FLANK; + u32 battlerOpposite = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battler))); + if (gAbsentBattlerFlags & gBitTable[battlerOpposite]) + battlerOpposite ^= BIT_FLANK; - BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitLinkStandbyMsg(battlerOpposite, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battlerOpposite); } } } @@ -6786,11 +6700,11 @@ static void Cmd_switchhandleorder(void) { CMD_ARGS(u8 battler, u8 state); - s32 i; + u32 battler, i; if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + battler = GetBattlerForBattleScript(cmd->battler); switch (cmd->state) { @@ -6810,51 +6724,51 @@ static void Cmd_switchhandleorder(void) break; case 1: if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - SwitchPartyOrder(gActiveBattler); + SwitchPartyOrder(battler); break; case 2: - if (!(gBattleStruct->field_93 & gBitTable[gActiveBattler])) + if (!(gBattleStruct->field_93 & gBitTable[battler])) { - RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][1]); - gBattleStruct->field_93 |= gBitTable[gActiveBattler]; + RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][1]); + gBattleStruct->field_93 |= gBitTable[battler]; } // fall through case 3: - gBattleCommunication[0] = gBattleResources->bufferB[gActiveBattler][1]; - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][1]; + gBattleCommunication[0] = gBattleResources->bufferB[battler][1]; + *(gBattleStruct->monToSwitchIntoId + battler) = gBattleResources->bufferB[battler][1]; if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) { - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0); - *(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[gActiveBattler][3]; + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0); + *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[battler][3]; - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0) >> 4; - *((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[gActiveBattler][3]; + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0) >> 4; + *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[battler][3]; } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - SwitchPartyOrderInGameMulti(gActiveBattler, *(gBattleStruct->monToSwitchIntoId + gActiveBattler)); + SwitchPartyOrderInGameMulti(battler, *(gBattleStruct->monToSwitchIntoId + battler)); } else { - SwitchPartyOrder(gActiveBattler); + SwitchPartyOrder(battler); } PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].species) - PREPARE_MON_NICK_BUFFER(gBattleTextBuff2, gActiveBattler, gBattleResources->bufferB[gActiveBattler][1]) + PREPARE_MON_NICK_BUFFER(gBattleTextBuff2, battler, gBattleResources->bufferB[battler][1]) break; } gBattlescriptCurrInstr = cmd->nextInstr; } -static void SetDmgHazardsBattlescript(u8 battlerId, u8 multistringId) +static void SetDmgHazardsBattlescript(u8 battler, u8 multistringId) { - gBattleMons[battlerId].status2 &= ~STATUS2_DESTINY_BOND; + gBattleMons[battler].status2 &= ~STATUS2_DESTINY_BOND; gHitMarker &= ~HITMARKER_DESTINYBOND; - gBattleScripting.battler = battlerId; + gBattleScripting.battler = battler; gBattleCommunication[MULTISTRING_CHOOSER] = multistringId; BattleScriptPushCursor(); @@ -6866,20 +6780,20 @@ static void SetDmgHazardsBattlescript(u8 battlerId, u8 multistringId) gBattlescriptCurrInstr = BattleScript_DmgHazardsOnFaintedBattler; } -bool32 DoSwitchInAbilitiesItems(u32 battlerId) +bool32 DoSwitchInAbilitiesItems(u32 battler) { - return (TryPrimalReversion(battlerId) - || 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) + return (TryPrimalReversion(battler) + || AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, battler, 0, 0, 0) + || (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, battler, 0, 0, 0)) + || (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, battler, 0, 0, 0)) + || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, battler, FALSE) || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0)); } -bool32 ShouldPostponeSwitchInAbilities(u32 battlerId) +bool32 ShouldPostponeSwitchInAbilities(u32 battler) { - bool32 aliveOpposing1 = IsBattlerAlive(BATTLE_OPPOSITE(battlerId)); - bool32 aliveOpposing2 = IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(battlerId))); + bool32 aliveOpposing1 = IsBattlerAlive(BATTLE_OPPOSITE(battler)); + bool32 aliveOpposing2 = IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(battler))); // No pokemon on opposing side - postpone. if (!aliveOpposing1 && !aliveOpposing2) return TRUE; @@ -6887,9 +6801,9 @@ bool32 ShouldPostponeSwitchInAbilities(u32 battlerId) // Checks for double battle, so abilities like Intimidate wait until all battlers are switched-in before activating. if (IsDoubleBattle()) { - if (aliveOpposing1 && !aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_PARTNER(BATTLE_OPPOSITE(battlerId)), PARTY_SIZE, PARTY_SIZE)) + if (aliveOpposing1 && !aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_PARTNER(BATTLE_OPPOSITE(battler)), PARTY_SIZE, PARTY_SIZE)) return TRUE; - if (!aliveOpposing1 && aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_OPPOSITE(battlerId), PARTY_SIZE, PARTY_SIZE)) + if (!aliveOpposing1 && aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_OPPOSITE(battler), PARTY_SIZE, PARTY_SIZE)) return TRUE; } @@ -6901,119 +6815,119 @@ static void Cmd_switchineffects(void) CMD_ARGS(u8 battler); s32 i; + u32 battler = GetBattlerForBattleScript(cmd->battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - UpdateSentPokesToOpponentValue(gActiveBattler); + UpdateSentPokesToOpponentValue(battler); - gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - gSpecialStatuses[gActiveBattler].faintedHasReplacement = FALSE; + gHitMarker &= ~HITMARKER_FAINTED(battler); + gSpecialStatuses[battler].faintedHasReplacement = FALSE; - if (!BattlerHasAi(gActiveBattler)) - gBattleStruct->appearedInBattle |= gBitTable[gBattlerPartyIndexes[gActiveBattler]]; + if (!BattlerHasAi(battler)) + gBattleStruct->appearedInBattle |= gBitTable[gBattlerPartyIndexes[battler]]; // Neutralizing Gas announces itself before hazards - if (gBattleMons[gActiveBattler].ability == ABILITY_NEUTRALIZING_GAS && gSpecialStatuses[gActiveBattler].announceNeutralizingGas == 0) + if (gBattleMons[battler].ability == ABILITY_NEUTRALIZING_GAS && gSpecialStatuses[battler].announceNeutralizingGas == 0) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SWITCHIN_NEUTRALIZING_GAS; - gSpecialStatuses[gActiveBattler].announceNeutralizingGas = TRUE; - gBattlerAbility = gActiveBattler; + gSpecialStatuses[battler].announceNeutralizingGas = TRUE; + gBattlerAbility = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SwitchInAbilityMsgRet; } // Healing Wish activates before hazards. // Starting from Gen8 - it heals only pokemon which can be healed. In gens 5,6,7 the effect activates anyways. - else if (((gBattleStruct->storedHealingWish & gBitTable[gActiveBattler]) || (gBattleStruct->storedLunarDance & gBitTable[gActiveBattler])) - && (gBattleMons[gActiveBattler].hp != gBattleMons[gActiveBattler].maxHP || gBattleMons[gActiveBattler].status1 != 0 || B_HEALING_WISH_SWITCH < GEN_8)) + else if (((gBattleStruct->storedHealingWish & gBitTable[battler]) || (gBattleStruct->storedLunarDance & gBitTable[battler])) + && (gBattleMons[battler].hp != gBattleMons[battler].maxHP || gBattleMons[battler].status1 != 0 || B_HEALING_WISH_SWITCH < GEN_8)) { - if (gBattleStruct->storedHealingWish & gBitTable[gActiveBattler]) + if (gBattleStruct->storedHealingWish & gBitTable[battler]) { BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_HealingWishActivates; - gBattleStruct->storedHealingWish &= ~(gBitTable[gActiveBattler]); + gBattleStruct->storedHealingWish &= ~(gBitTable[battler]); } else // Lunar Dance { BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_LunarDanceActivates; - gBattleStruct->storedLunarDance &= ~(gBitTable[gActiveBattler]); + gBattleStruct->storedLunarDance &= ~(gBitTable[battler]); } } - else if (!(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_SPIKES_DAMAGED) - && (gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_SPIKES) - && GetBattlerAbility(gActiveBattler) != ABILITY_MAGIC_GUARD - && IsBattlerAffectedByHazards(gActiveBattler, FALSE) - && IsBattlerGrounded(gActiveBattler)) + else if (!(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SPIKES_DAMAGED) + && (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SPIKES) + && GetBattlerAbility(battler) != ABILITY_MAGIC_GUARD + && IsBattlerAffectedByHazards(battler, FALSE) + && IsBattlerGrounded(battler)) { - u8 spikesDmg = (5 - gSideTimers[GetBattlerSide(gActiveBattler)].spikesAmount) * 2; - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / (spikesDmg); + u8 spikesDmg = (5 - gSideTimers[GetBattlerSide(battler)].spikesAmount) * 2; + gBattleMoveDamage = gBattleMons[battler].maxHP / (spikesDmg); if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - gSideStatuses[GetBattlerSide(gActiveBattler)] |= SIDE_STATUS_SPIKES_DAMAGED; - SetDmgHazardsBattlescript(gActiveBattler, B_MSG_PKMNHURTBYSPIKES); + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_SPIKES_DAMAGED; + SetDmgHazardsBattlescript(battler, B_MSG_PKMNHURTBYSPIKES); } - else if (!(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_STEALTH_ROCK_DAMAGED) - && (gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_STEALTH_ROCK) - && IsBattlerAffectedByHazards(gActiveBattler, FALSE) - && GetBattlerAbility(gActiveBattler) != ABILITY_MAGIC_GUARD) + else if (!(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_STEALTH_ROCK_DAMAGED) + && (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_STEALTH_ROCK) + && IsBattlerAffectedByHazards(battler, FALSE) + && GetBattlerAbility(battler) != ABILITY_MAGIC_GUARD) { - gSideStatuses[GetBattlerSide(gActiveBattler)] |= SIDE_STATUS_STEALTH_ROCK_DAMAGED; - gBattleMoveDamage = GetStealthHazardDamage(gBattleMoves[MOVE_STEALTH_ROCK].type, gActiveBattler); + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_STEALTH_ROCK_DAMAGED; + gBattleMoveDamage = GetStealthHazardDamage(gBattleMoves[MOVE_STEALTH_ROCK].type, battler); if (gBattleMoveDamage != 0) - SetDmgHazardsBattlescript(gActiveBattler, B_MSG_STEALTHROCKDMG); + SetDmgHazardsBattlescript(battler, B_MSG_STEALTHROCKDMG); } - else if (!(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_TOXIC_SPIKES_DAMAGED) - && (gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_TOXIC_SPIKES) - && IsBattlerGrounded(gActiveBattler)) + else if (!(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_TOXIC_SPIKES_DAMAGED) + && (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_TOXIC_SPIKES) + && IsBattlerGrounded(battler)) { - gSideStatuses[GetBattlerSide(gActiveBattler)] |= SIDE_STATUS_TOXIC_SPIKES_DAMAGED; - if (IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_POISON)) // Absorb the toxic spikes. + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_TOXIC_SPIKES_DAMAGED; + if (IS_BATTLER_OF_TYPE(battler, TYPE_POISON)) // Absorb the toxic spikes. { - gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~SIDE_STATUS_TOXIC_SPIKES; - gSideTimers[GetBattlerSide(gActiveBattler)].toxicSpikesAmount = 0; - gBattleScripting.battler = gActiveBattler; + gSideStatuses[GetBattlerSide(battler)] &= ~SIDE_STATUS_TOXIC_SPIKES; + gSideTimers[GetBattlerSide(battler)].toxicSpikesAmount = 0; + gBattleScripting.battler = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_ToxicSpikesAbsorbed; } - else if (IsBattlerAffectedByHazards(gActiveBattler, TRUE)) + else if (IsBattlerAffectedByHazards(battler, TRUE)) { - if (!(gBattleMons[gActiveBattler].status1 & STATUS1_ANY) - && !IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_STEEL) - && GetBattlerAbility(gActiveBattler) != ABILITY_IMMUNITY - && !IsAbilityOnSide(gActiveBattler, ABILITY_PASTEL_VEIL) - && !(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_SAFEGUARD) + if (!(gBattleMons[battler].status1 & STATUS1_ANY) + && !IS_BATTLER_OF_TYPE(battler, TYPE_STEEL) + && GetBattlerAbility(battler) != ABILITY_IMMUNITY + && !IsAbilityOnSide(battler, ABILITY_PASTEL_VEIL) + && !(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD) && !(gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN)) { - if (gSideTimers[GetBattlerSide(gActiveBattler)].toxicSpikesAmount >= 2) - gBattleMons[gActiveBattler].status1 |= STATUS1_TOXIC_POISON; + if (gSideTimers[GetBattlerSide(battler)].toxicSpikesAmount >= 2) + gBattleMons[battler].status1 |= STATUS1_TOXIC_POISON; else - gBattleMons[gActiveBattler].status1 |= STATUS1_POISON; + gBattleMons[battler].status1 |= STATUS1_POISON; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); - gBattleScripting.battler = gActiveBattler; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); + gBattleScripting.battler = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_ToxicSpikesPoisoned; } } } - else if (!(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_STICKY_WEB_DAMAGED) - && (gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_STICKY_WEB) - && IsBattlerAffectedByHazards(gActiveBattler, FALSE) - && IsBattlerGrounded(gActiveBattler)) + else if (!(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_STICKY_WEB_DAMAGED) + && (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_STICKY_WEB) + && IsBattlerAffectedByHazards(battler, FALSE) + && IsBattlerGrounded(battler)) { - gSideStatuses[GetBattlerSide(gActiveBattler)] |= SIDE_STATUS_STICKY_WEB_DAMAGED; - gBattleScripting.battler = gActiveBattler; + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_STICKY_WEB_DAMAGED; + gBattleScripting.battler = battler; SET_STATCHANGER(STAT_SPEED, 1, TRUE); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_StickyWebOnSwitchIn; } - else if (gBattleMons[gActiveBattler].hp != gBattleMons[gActiveBattler].maxHP && gBattleStruct->zmove.healReplacement) + else if (gBattleMons[battler].hp != gBattleMons[battler].maxHP && gBattleStruct->zmove.healReplacement) { gBattleStruct->zmove.healReplacement = FALSE; - gBattleMoveDamage = -1 * (gBattleMons[gActiveBattler].maxHP); - gBattleScripting.battler = gActiveBattler; + gBattleMoveDamage = -1 * (gBattleMons[battler].maxHP); + gBattleScripting.battler = battler; BattleScriptPushCursor(); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_Z_HP_TRAP; gBattlescriptCurrInstr = BattleScript_HealReplacementZMove; @@ -7023,30 +6937,30 @@ static void Cmd_switchineffects(void) { // There is a hack here to ensure the truant counter will be 0 when the battler's next turn starts. // The truant counter is not updated in the case where a mon switches in after a lost judgment in the battle arena. - if (GetBattlerAbility(gActiveBattler) == ABILITY_TRUANT + if (GetBattlerAbility(battler) == ABILITY_TRUANT && gCurrentActionFuncId != B_ACTION_USE_MOVE - && !gDisableStructs[gActiveBattler].truantSwitchInHack) - gDisableStructs[gActiveBattler].truantCounter = 1; + && !gDisableStructs[battler].truantSwitchInHack) + gDisableStructs[battler].truantCounter = 1; - gDisableStructs[gActiveBattler].truantSwitchInHack = 0; + gDisableStructs[battler].truantSwitchInHack = 0; // Don't activate switch-in abilities if the opposing field is empty. // This could happen when a mon uses explosion and causes everyone to faint. - if (ShouldPostponeSwitchInAbilities(gActiveBattler) || gBattleStruct->switchInAbilityPostponed) + if (ShouldPostponeSwitchInAbilities(battler) || gBattleStruct->switchInAbilityPostponed) { - gBattleStruct->switchInAbilityPostponed |= gBitTable[gActiveBattler]; + gBattleStruct->switchInAbilityPostponed |= gBitTable[battler]; } else { - if (DoSwitchInAbilitiesItems(gActiveBattler)) + if (DoSwitchInAbilitiesItems(battler)) 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(battler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); for (i = 0; i < gBattlersCount; i++) { - if (gBattlerByTurnOrder[i] == gActiveBattler) + if (gBattlerByTurnOrder[i] == battler) gActionsByTurnOrder[i] = B_ACTION_CANCEL_PARTNER; gBattleStruct->hpOnSwitchout[GetBattlerSide(i)] = gBattleMons[i].hp; @@ -7066,7 +6980,7 @@ static void Cmd_switchineffects(void) gBattlerFainted++; } } - gBattleStruct->forcedSwitch &= ~(gBitTable[gActiveBattler]); + gBattleStruct->forcedSwitch &= ~(gBitTable[battler]); gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -7075,9 +6989,9 @@ static void Cmd_trainerslidein(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerAtPosition(cmd->battler); - BtlController_EmitTrainerSlide(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerAtPosition(cmd->battler); + BtlController_EmitTrainerSlide(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7086,9 +7000,8 @@ static void Cmd_playse(void) { CMD_ARGS(u16 song); - gActiveBattler = gBattlerAttacker; - BtlController_EmitPlaySE(BUFFER_A, cmd->song); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlaySE(gBattlerAttacker, BUFFER_A, cmd->song); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7097,9 +7010,8 @@ static void Cmd_fanfare(void) { CMD_ARGS(u16 song); - gActiveBattler = gBattlerAttacker; - BtlController_EmitPlayFanfareOrBGM(BUFFER_A, cmd->song, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlayFanfareOrBGM(gBattlerAttacker, BUFFER_A, cmd->song, FALSE); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7108,9 +7020,9 @@ static void Cmd_playfaintcry(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitFaintingCry(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitFaintingCry(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7119,9 +7031,9 @@ static void Cmd_endlinkbattle(void) { CMD_ARGS(); - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - BtlController_EmitEndLinkBattle(BUFFER_A, gBattleOutcome); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + BtlController_EmitEndLinkBattle(battler, BUFFER_A, gBattleOutcome); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7130,9 +7042,9 @@ static void Cmd_returntoball(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitReturnMonToBall(BUFFER_A, TRUE); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitReturnMonToBall(battler, BUFFER_A, TRUE); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7141,16 +7053,13 @@ static void Cmd_handlelearnnewmove(void) { 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); while (learnMove == MON_ALREADY_KNOWS_MOVE) learnMove = MonTryLearningNewMove(&gPlayerParty[gBattleStruct->expGetterMonId], FALSE); if (learnMove == MOVE_NONE) { - gBattlescriptCurrInstr = nothingToLearnPtr; + gBattlescriptCurrInstr = cmd->nothingToLearnPtr; } else if (learnMove == MON_HAS_MAX_MOVES) { @@ -7158,24 +7067,24 @@ static void Cmd_handlelearnnewmove(void) } else { - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + u32 battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - if (gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId - && !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) + if (gBattlerPartyIndexes[battler] == gBattleStruct->expGetterMonId + && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED)) { - GiveMoveToBattleMon(&gBattleMons[gActiveBattler], learnMove); + GiveMoveToBattleMon(&gBattleMons[battler], learnMove); } if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - if (gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId - && !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) + battler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + if (gBattlerPartyIndexes[battler] == gBattleStruct->expGetterMonId + && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED)) { - GiveMoveToBattleMon(&gBattleMons[gActiveBattler], learnMove); + GiveMoveToBattleMon(&gBattleMons[battler], learnMove); } } - gBattlescriptCurrInstr = learnedMovePtr; + gBattlescriptCurrInstr = cmd->learnedMovePtr; } } @@ -7183,8 +7092,6 @@ static void Cmd_yesnoboxlearnmove(void) { CMD_ARGS(const u8 *forgotMovePtr); - gActiveBattler = 0; - switch (gBattleScripting.learnMoveState) { case 0: @@ -7256,7 +7163,7 @@ static void Cmd_yesnoboxlearnmove(void) u16 moveId = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MOVE1 + movePosition); if (IsMoveHM(moveId)) { - PrepareStringBattle(STRINGID_HMMOVESCANTBEFORGOTTEN, gActiveBattler); + PrepareStringBattle(STRINGID_HMMOVESCANTBEFORGOTTEN, B_POSITION_PLAYER_LEFT); gBattleScripting.learnMoveState = 6; } else @@ -7350,16 +7257,15 @@ static void Cmd_hitanimation(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - + u32 battler = GetBattlerForBattleScript(cmd->battler); if (gMoveResultFlags & MOVE_RESULT_NO_EFFECT) { gBattlescriptCurrInstr = cmd->nextInstr; } - else if (!(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE) || !(DoesSubstituteBlockMove(gBattlerAttacker, gActiveBattler, gCurrentMove)) || gDisableStructs[gActiveBattler].substituteHP == 0) + else if (!(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE) || !(DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove)) || gDisableStructs[battler].substituteHP == 0) { - BtlController_EmitHitAnimation(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitHitAnimation(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -7444,24 +7350,24 @@ static void Cmd_updatebattlermoves(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + u32 battler = GetBattlerForBattleScript(cmd->battler); switch (gBattleCommunication[0]) { case 0: - BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitGetMonData(battler, BUFFER_A, REQUEST_ALL_BATTLE, 0); + MarkBattlerForControllerExec(battler); gBattleCommunication[0]++; break; case 1: if (gBattleControllerExecFlags == 0) { s32 i; - struct BattlePokemon *bufferPoke = (struct BattlePokemon *) &gBattleResources->bufferB[gActiveBattler][4]; + struct BattlePokemon *bufferPoke = (struct BattlePokemon *) &gBattleResources->bufferB[battler][4]; for (i = 0; i < MAX_MON_MOVES; i++) { - gBattleMons[gActiveBattler].moves[i] = bufferPoke->moves[i]; - gBattleMons[gActiveBattler].pp[i] = bufferPoke->pp[i]; + gBattleMons[battler].moves[i] = bufferPoke->moves[i]; + gBattleMons[battler].pp[i] = bufferPoke->pp[i]; } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7473,9 +7379,8 @@ static void Cmd_swapattackerwithtarget(void) { CMD_ARGS(); - gActiveBattler = gBattlerAttacker; - gBattlerAttacker = gBattlerTarget; - gBattlerTarget = gActiveBattler; + u8 temp; + SWAP(gBattlerAttacker, gBattlerTarget, temp); if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET; @@ -7499,16 +7404,15 @@ static void Cmd_drawpartystatussummary(void) { CMD_ARGS(u8 battler); - s32 i; + u32 battler, i; struct Pokemon *party; struct HpAndStatus hpStatuses[PARTY_SIZE]; if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - - party = GetBattlerParty(gActiveBattler); + battler = GetBattlerForBattleScript(cmd->battler); + party = GetBattlerParty(battler); for (i = 0; i < PARTY_SIZE; i++) { @@ -7525,8 +7429,8 @@ static void Cmd_drawpartystatussummary(void) } } - BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatuses, 1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitDrawPartyStatusSummary(battler, BUFFER_A, hpStatuses, 1); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7535,9 +7439,9 @@ static void Cmd_hidepartystatussummary(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitHidePartyStatusSummary(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitHidePartyStatusSummary(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7560,13 +7464,13 @@ static void Cmd_statusanimation(void) if (gBattleControllerExecFlags == 0) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (!(gStatuses3[gActiveBattler] & STATUS3_SEMI_INVULNERABLE) - && gDisableStructs[gActiveBattler].substituteHP == 0 + u32 battler = GetBattlerForBattleScript(cmd->battler); + if (!(gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) + && gDisableStructs[battler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(BUFFER_A, FALSE, gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitStatusAnimation(battler, BUFFER_A, FALSE, gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7576,18 +7480,16 @@ static void Cmd_status2animation(void) { CMD_ARGS(u8 battler, u32 status2); - u32 wantedToAnimate; - if (gBattleControllerExecFlags == 0) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - wantedToAnimate = cmd->status2; - if (!(gStatuses3[gActiveBattler] & STATUS3_SEMI_INVULNERABLE) - && gDisableStructs[gActiveBattler].substituteHP == 0 + u32 battler = GetBattlerForBattleScript(cmd->battler); + u32 status2ToAnim = cmd->status2; + if (!(gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) + && gDisableStructs[battler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(BUFFER_A, TRUE, gBattleMons[gActiveBattler].status2 & wantedToAnimate); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitStatusAnimation(battler, BUFFER_A, TRUE, gBattleMons[battler].status2 & status2ToAnim); + MarkBattlerForControllerExec(battler); } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7597,18 +7499,16 @@ static void Cmd_chosenstatusanimation(void) { CMD_ARGS(u8 battler, bool8 isStatus2, u32 status); - u32 wantedStatus; - if (gBattleControllerExecFlags == 0) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - wantedStatus = cmd->status; - if (!(gStatuses3[gActiveBattler] & STATUS3_SEMI_INVULNERABLE) - && gDisableStructs[gActiveBattler].substituteHP == 0 + u32 battler = GetBattlerForBattleScript(cmd->battler); + u32 wantedStatus = cmd->status; + if (!(gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) + && gDisableStructs[battler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(BUFFER_A, cmd->isStatus2, wantedStatus); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitStatusAnimation(battler, BUFFER_A, cmd->isStatus2, wantedStatus); + MarkBattlerForControllerExec(battler); } gBattlescriptCurrInstr = cmd->nextInstr; } @@ -7687,19 +7587,19 @@ static void Cmd_setgravity(void) } } -static bool32 TryCheekPouch(u32 battlerId, u32 itemId) +static bool32 TryCheekPouch(u32 battler, u32 itemId) { if (ItemId_GetPocket(itemId) == POCKET_BERRIES - && GetBattlerAbility(battlerId) == ABILITY_CHEEK_POUCH - && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK) - && gBattleStruct->ateBerry[GetBattlerSide(battlerId)] & gBitTable[gBattlerPartyIndexes[battlerId]] - && !BATTLER_MAX_HP(battlerId)) + && GetBattlerAbility(battler) == ABILITY_CHEEK_POUCH + && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK) + && gBattleStruct->ateBerry[GetBattlerSide(battler)] & gBitTable[gBattlerPartyIndexes[battler]] + && !BATTLER_MAX_HP(battler)) { - gBattleMoveDamage = gBattleMons[battlerId].maxHP / 3; + gBattleMoveDamage = gBattleMons[battler].maxHP / 3; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; - gBattlerAbility = battlerId; + gBattlerAbility = battler; BattleScriptPush(gBattlescriptCurrInstr + 2); gBattlescriptCurrInstr = BattleScript_CheekPouchActivates; return TRUE; @@ -7712,15 +7612,13 @@ static void BestowItem(u32 battlerAtk, u32 battlerDef) { gLastUsedItem = gBattleMons[battlerAtk].item; - gActiveBattler = battlerAtk; gBattleMons[battlerAtk].item = ITEM_NONE; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battlerAtk].item), &gBattleMons[battlerAtk].item); + BtlController_EmitSetMonData(battlerAtk, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battlerAtk].item), &gBattleMons[battlerAtk].item); MarkBattlerForControllerExec(battlerAtk); CheckSetUnburden(battlerAtk); - gActiveBattler = battlerDef; gBattleMons[battlerDef].item = gLastUsedItem; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battlerDef].item), &gBattleMons[battlerDef].item); + BtlController_EmitSetMonData(battlerDef, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battlerDef].item), &gBattleMons[battlerDef].item); MarkBattlerForControllerExec(battlerDef); gBattleResources->flags->flags[battlerDef] &= ~RESOURCE_FLAG_UNBURDEN; } @@ -7754,6 +7652,7 @@ static void Cmd_removeitem(void) { CMD_ARGS(u8 battler); + u32 battler; u16 itemId = 0; if (gBattleScripting.overrideBerryRequirements) @@ -7763,23 +7662,23 @@ static void Cmd_removeitem(void) return; } - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - itemId = gBattleMons[gActiveBattler].item; + battler = GetBattlerForBattleScript(cmd->battler); + itemId = gBattleMons[battler].item; // Popped Air Balloon cannot be restored by any means. // Corroded items cannot be restored either. - if (GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_AIR_BALLOON + if (GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_AIR_BALLOON && gBattleMoves[gCurrentMove].effect != EFFECT_CORROSIVE_GAS) - gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)] = itemId; // Remember if switched out + gBattleStruct->usedHeldItems[gBattlerPartyIndexes[battler]][GetBattlerSide(battler)] = itemId; // Remember if switched out - gBattleMons[gActiveBattler].item = ITEM_NONE; - CheckSetUnburden(gActiveBattler); + gBattleMons[battler].item = ITEM_NONE; + CheckSetUnburden(battler); - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battler].item), &gBattleMons[battler].item); + MarkBattlerForControllerExec(battler); - ClearBattlerItemEffectHistory(gActiveBattler); - if (!TryCheekPouch(gActiveBattler, itemId) && !TrySymbiosis(gActiveBattler, itemId)) + ClearBattlerItemEffectHistory(battler); + if (!TryCheekPouch(battler, itemId) && !TrySymbiosis(battler, itemId)) gBattlescriptCurrInstr = cmd->nextInstr; } @@ -8094,13 +7993,14 @@ static void Cmd_setatktoplayer0(void) static void Cmd_makevisible(void) { CMD_ARGS(u8 battler); + u32 battler; if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitSpriteInvisibility(battler, BUFFER_A, FALSE); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -8141,15 +8041,12 @@ static void Cmd_hpthresholds(void) { CMD_ARGS(u8 battler); - u8 opposingBattler; - s32 result; - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - opposingBattler = BATTLE_OPPOSITE(gActiveBattler); + u32 battler = GetBattlerForBattleScript(cmd->battler); + 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) result = 1; @@ -8170,16 +8067,12 @@ static void Cmd_hpthresholds2(void) { CMD_ARGS(u8 battler); - u8 opposingBattler; - s32 result; - u8 hpSwitchout; - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - opposingBattler = BATTLE_OPPOSITE(gActiveBattler); - hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler)); - result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout; + u32 battler = GetBattlerForBattleScript(cmd->battler); + u32 opposingBattler = BATTLE_OPPOSITE(battler); + u8 hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler)); + s32 result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout; if (gBattleMons[opposingBattler].hp >= hpSwitchout) gBattleStruct->hpScale = 0; @@ -8293,16 +8186,16 @@ bool32 CanParalyzeType(u8 battlerAttacker, u8 battlerTarget) return !(B_PARALYZE_ELECTRIC >= GEN_6 && IS_BATTLER_OF_TYPE(battlerTarget, TYPE_ELECTRIC)); } -bool32 CanUseLastResort(u8 battlerId) +bool32 CanUseLastResort(u8 battler) { u32 i; u32 knownMovesCount = 0, usedMovesCount = 0; for (i = 0; i < 4; i++) { - if (gBattleMons[battlerId].moves[i] != MOVE_NONE) + if (gBattleMons[battler].moves[i] != MOVE_NONE) knownMovesCount++; - if (i != gCurrMovePos && gDisableStructs[battlerId].usedMoves & gBitTable[i]) // Increment used move count for all moves except current Last Resort. + if (i != gCurrMovePos && gDisableStructs[battler].usedMoves & gBitTable[i]) // Increment used move count for all moves except current Last Resort. usedMovesCount++; } @@ -8414,13 +8307,13 @@ u32 IsAbilityStatusProtected(u32 battler) || IsShieldsDownProtected(battler); } -u32 GetHighestStatId(u32 battlerId) +u32 GetHighestStatId(u32 battler) { - u32 i, highestId = STAT_ATK, highestStat = gBattleMons[battlerId].attack; + u32 i, highestId = STAT_ATK, highestStat = gBattleMons[battler].attack; for (i = STAT_DEF; i < NUM_STATS; i++) { - u16 *statVal = &gBattleMons[battlerId].attack + (i - 1); + u16 *statVal = &gBattleMons[battler].attack + (i - 1); if (*statVal > highestStat) { highestStat = *statVal; @@ -8430,17 +8323,17 @@ u32 GetHighestStatId(u32 battlerId) return highestId; } -static bool32 IsRototillerAffected(u32 battlerId) +static bool32 IsRototillerAffected(u32 battler) { - if (!IsBattlerAlive(battlerId)) + if (!IsBattlerAlive(battler)) return FALSE; - if (!IsBattlerGrounded(battlerId)) + if (!IsBattlerGrounded(battler)) return FALSE; // Only grounded battlers affected - if (!IS_BATTLER_OF_TYPE(battlerId, TYPE_GRASS)) + if (!IS_BATTLER_OF_TYPE(battler, TYPE_GRASS)) return FALSE; // Only grass types affected - if (gStatuses3[battlerId] & STATUS3_SEMI_INVULNERABLE) + if (gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) return FALSE; // Rototiller doesn't affected semi-invulnerable battlers - if (BlocksPrankster(MOVE_ROTOTILLER, gBattlerAttacker, battlerId, FALSE)) + if (BlocksPrankster(MOVE_ROTOTILLER, gBattlerAttacker, battler, FALSE)) return FALSE; return TRUE; } @@ -8497,11 +8390,11 @@ static bool32 IsAbilityAbsorbAffected(void) return FALSE; } -static bool32 IsTeatimeAffected(u32 battlerId) +static bool32 IsTeatimeAffected(u32 battler) { - if (ItemId_GetPocket(gBattleMons[battlerId].item) != POCKET_BERRIES) + if (ItemId_GetPocket(gBattleMons[battler].item) != POCKET_BERRIES) return FALSE; // Only berries - if (gStatuses3[battlerId] & STATUS3_SEMI_INVULNERABLE) + if (gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) return FALSE; // Teatime doesn't affected semi-invulnerable battlers return TRUE; } @@ -8565,37 +8458,37 @@ static bool32 CourtChangeSwapSideStatuses(void) SWAP(sideTimerPlayer->stickyWebBattlerSide, sideTimerOpp->stickyWebBattlerSide, temp); } -static void HandleScriptMegaPrimalBurst(u32 caseId, u32 battlerId, u32 type) +static void HandleScriptMegaPrimalBurst(u32 caseId, u32 battler, u32 type) { - struct Pokemon *party = GetBattlerParty(battlerId); - struct Pokemon *mon = &party[gBattlerPartyIndexes[battlerId]]; - u32 position = GetBattlerPosition(battlerId); - u32 side = GET_BATTLER_SIDE(battlerId); + struct Pokemon *party = GetBattlerParty(battler); + struct Pokemon *mon = &party[gBattlerPartyIndexes[battler]]; + u32 position = GetBattlerPosition(battler); + u32 side = GET_BATTLER_SIDE(battler); // Change species. if (caseId == 0) { if (type == HANDLE_TYPE_MEGA_EVOLUTION) { - if (!TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_ITEM)) - TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE); + if (!TryBattleFormChange(battler, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_ITEM)) + TryBattleFormChange(battler, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE); } else if (type == HANDLE_TYPE_PRIMAL_REVERSION) - TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_PRIMAL_REVERSION); + TryBattleFormChange(battler, FORM_CHANGE_BATTLE_PRIMAL_REVERSION); else - TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_ULTRA_BURST); + TryBattleFormChange(battler, FORM_CHANGE_BATTLE_ULTRA_BURST); - PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[battlerId].species); + PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[battler].species); - BtlController_EmitSetMonData(BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[battlerId]], sizeof(gBattleMons[battlerId].species), &gBattleMons[battlerId].species); - MarkBattlerForControllerExec(battlerId); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[battler]], sizeof(gBattleMons[battler].species), &gBattleMons[battler].species); + MarkBattlerForControllerExec(battler); } // Update healthbox and elevation and play cry. else { - UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId], mon, HEALTHBOX_ALL); + UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], mon, HEALTHBOX_ALL); if (side == B_SIDE_OPPONENT) - SetBattlerShadowSpriteCallback(battlerId, gBattleMons[battlerId].species); + SetBattlerShadowSpriteCallback(battler, gBattleMons[battler].species); if (type == HANDLE_TYPE_MEGA_EVOLUTION) gBattleStruct->mega.alreadyEvolved[position] = TRUE; if (type == HANDLE_TYPE_ULTRA_BURST) @@ -8642,12 +8535,12 @@ static void Cmd_various(void) struct Pokemon *mon; s32 i, j; u8 data[10]; - u32 side, bits; + u32 side, battler, bits; if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(cmd->battler); + battler = GetBattlerForBattleScript(cmd->battler); switch (cmd->id) { @@ -8672,7 +8565,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_ABSENT: { VARIOUS_ARGS(const u8 *jumpInstr); - if (!IsBattlerAlive(gActiveBattler)) + if (!IsBattlerAlive(battler)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -8681,9 +8574,9 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_SHIELDS_DOWN_PROTECTED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (IsShieldsDownProtected(gActiveBattler)) + if (IsShieldsDownProtected(battler)) { - gBattlerAbility = gActiveBattler; + gBattlerAbility = battler; gBattlescriptCurrInstr = cmd->jumpInstr; } else @@ -8695,13 +8588,13 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_NO_HOLD_EFFECT: { VARIOUS_ARGS(u8 holdEffect, const u8 *jumpInstr); - if (GetBattlerHoldEffect(gActiveBattler, TRUE) != cmd->holdEffect) + if (GetBattlerHoldEffect(battler, TRUE) != cmd->holdEffect) { gBattlescriptCurrInstr = cmd->jumpInstr; } else { - gLastUsedItem = gBattleMons[gActiveBattler].item; // For B_LAST_USED_ITEM + gLastUsedItem = gBattleMons[battler].item; // For B_LAST_USED_ITEM gBattlescriptCurrInstr = cmd->nextInstr; } return; @@ -8709,7 +8602,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_NO_ALLY: { VARIOUS_ARGS(const u8 *jumpInstr); - if (!IsBattlerAlive(BATTLE_PARTNER(gActiveBattler))) + if (!IsBattlerAlive(BATTLE_PARTNER(battler))) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -8718,15 +8611,15 @@ static void Cmd_various(void) case VARIOUS_INFATUATE_WITH_BATTLER: { VARIOUS_ARGS(u8 infatuateWith); - gBattleScripting.battler = gActiveBattler; - gBattleMons[gActiveBattler].status2 |= STATUS2_INFATUATED_WITH(GetBattlerForBattleScript(cmd->infatuateWith)); + gBattleScripting.battler = battler; + gBattleMons[battler].status2 |= STATUS2_INFATUATED_WITH(GetBattlerForBattleScript(cmd->infatuateWith)); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_SET_LAST_USED_ITEM: { VARIOUS_ARGS(); - gLastUsedItem = gBattleMons[gActiveBattler].item; + gLastUsedItem = gBattleMons[battler].item; break; } case VARIOUS_TRY_FAIRY_LOCK: @@ -8748,16 +8641,16 @@ static void Cmd_various(void) { VARIOUS_ARGS(u8 stat); i = cmd->stat; - gBattleMoveDamage = *(u16 *)(&gBattleMons[gActiveBattler].attack) + (i - 1); - gBattleMoveDamage *= gStatStageRatios[gBattleMons[gActiveBattler].statStages[i]][0]; - gBattleMoveDamage /= gStatStageRatios[gBattleMons[gActiveBattler].statStages[i]][1]; + gBattleMoveDamage = *(u16 *)(&gBattleMons[battler].attack) + (i - 1); + gBattleMoveDamage *= gStatStageRatios[gBattleMons[battler].statStages[i]][0]; + gBattleMoveDamage /= gStatStageRatios[gBattleMons[battler].statStages[i]][1]; gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_JUMP_IF_FULL_HP: { VARIOUS_ARGS(const u8 *jumpInstr); - if (BATTLER_MAX_HP(gActiveBattler)) + if (BATTLER_MAX_HP(battler)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -8769,7 +8662,7 @@ static void Cmd_various(void) while (gBattleStruct->friskedBattler < gBattlersCount) { gBattlerTarget = gBattleStruct->friskedBattler++; - if (GET_BATTLER_SIDE2(gActiveBattler) != GET_BATTLER_SIDE2(gBattlerTarget) + if (GET_BATTLER_SIDE2(battler) != GET_BATTLER_SIDE2(gBattlerTarget) && IsBattlerAlive(gBattlerTarget) && gBattleMons[gBattlerTarget].item != ITEM_NONE) { @@ -8796,7 +8689,7 @@ static void Cmd_various(void) case VARIOUS_POISON_TYPE_IMMUNITY: { VARIOUS_ARGS(u8 target, const u8 *failInstr); - if (!CanPoisonType(gActiveBattler, GetBattlerForBattleScript(cmd->target))) + if (!CanPoisonType(battler, GetBattlerForBattleScript(cmd->target))) gBattlescriptCurrInstr = cmd->failInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -8805,7 +8698,7 @@ static void Cmd_various(void) case VARIOUS_PARALYZE_TYPE_IMMUNITY: { VARIOUS_ARGS(u8 target, const u8 *failInstr); - if (!CanParalyzeType(gActiveBattler, GetBattlerForBattleScript(cmd->target))) + if (!CanParalyzeType(battler, GetBattlerForBattleScript(cmd->target))) gBattlescriptCurrInstr = cmd->failInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -8814,13 +8707,13 @@ static void Cmd_various(void) case VARIOUS_TRACE_ABILITY: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].ability = gBattleStruct->overwrittenAbilities[gActiveBattler] = gBattleStruct->tracedAbility[gActiveBattler]; + gBattleMons[battler].ability = gBattleStruct->overwrittenAbilities[battler] = gBattleStruct->tracedAbility[battler]; break; } case VARIOUS_TRY_ILLUSION_OFF: { VARIOUS_ARGS(); - if (GetIllusionMonPtr(gActiveBattler) != NULL) + if (GetIllusionMonPtr(battler) != NULL) { gBattlescriptCurrInstr = cmd->nextInstr; BattleScriptPushCursor(); @@ -8839,17 +8732,17 @@ static void Cmd_various(void) case VARIOUS_UPDATE_NICK: { VARIOUS_ARGS(); - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - mon = &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]; + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; else - mon = &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]]; - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], mon, HEALTHBOX_NICK); + mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; + UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], mon, HEALTHBOX_NICK); break; } case VARIOUS_JUMP_IF_NOT_BERRY: { VARIOUS_ARGS(const u8 *jumpInstr); - if (ItemId_GetPocket(gBattleMons[gActiveBattler].item) == POCKET_BERRIES) + if (ItemId_GetPocket(gBattleMons[battler].item) == POCKET_BERRIES) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->jumpInstr; @@ -8858,16 +8751,16 @@ static void Cmd_various(void) case VARIOUS_CHECK_IF_GRASSY_TERRAIN_HEALS: { VARIOUS_ARGS(const u8 *failInstr); - if ((gStatuses3[gActiveBattler] & (STATUS3_SEMI_INVULNERABLE | STATUS3_HEAL_BLOCK)) - || BATTLER_MAX_HP(gActiveBattler) - || !gBattleMons[gActiveBattler].hp - || !(IsBattlerGrounded(gActiveBattler))) + if ((gStatuses3[battler] & (STATUS3_SEMI_INVULNERABLE | STATUS3_HEAL_BLOCK)) + || BATTLER_MAX_HP(battler) + || !gBattleMons[battler].hp + || !(IsBattlerGrounded(battler))) { gBattlescriptCurrInstr = cmd->failInstr; } else { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; @@ -8880,10 +8773,10 @@ static void Cmd_various(void) { VARIOUS_ARGS(); // Cancel all multiturn moves of IN_AIR Pokemon except those being targeted by Sky Drop. - if (gStatuses3[gActiveBattler] & STATUS3_ON_AIR && !(gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED)) - CancelMultiTurnMoves(gActiveBattler); + if (gStatuses3[battler] & STATUS3_ON_AIR && !(gStatuses3[battler] & STATUS3_SKY_DROPPED)) + CancelMultiTurnMoves(battler); - gStatuses3[gActiveBattler] &= ~(STATUS3_MAGNET_RISE | STATUS3_TELEKINESIS | STATUS3_ON_AIR | STATUS3_SKY_DROPPED); + gStatuses3[battler] &= ~(STATUS3_MAGNET_RISE | STATUS3_TELEKINESIS | STATUS3_ON_AIR | STATUS3_SKY_DROPPED); break; } case VARIOUS_SPECTRAL_THIEF: @@ -8909,7 +8802,7 @@ static void Cmd_various(void) case VARIOUS_SET_POWDER: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].status2 |= STATUS2_POWDER; + gBattleMons[battler].status2 |= STATUS2_POWDER; break; } case VARIOUS_ACUPRESSURE: @@ -8918,7 +8811,7 @@ static void Cmd_various(void) bits = 0; for (i = STAT_ATK; i < NUM_BATTLE_STATS; i++) { - if (CompareStat(gActiveBattler, i, MAX_STAT_STAGE, CMP_LESS_THAN)) + if (CompareStat(battler, i, MAX_STAT_STAGE, CMP_LESS_THAN)) bits |= gBitTable[i]; } if (bits) @@ -8941,25 +8834,25 @@ static void Cmd_various(void) case VARIOUS_CANCEL_MULTI_TURN_MOVES: { VARIOUS_ARGS(); - CancelMultiTurnMoves(gActiveBattler); + CancelMultiTurnMoves(battler); break; } case VARIOUS_SET_MAGIC_COAT_TARGET: { VARIOUS_ARGS(); - gBattleStruct->attackerBeforeBounce = gActiveBattler; + gBattleStruct->attackerBeforeBounce = battler; gBattlerAttacker = gBattlerTarget; side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker)); if (IsAffectedByFollowMe(gBattlerAttacker, side, gCurrentMove)) gBattlerTarget = gSideTimers[side].followmeTarget; else - gBattlerTarget = gActiveBattler; + gBattlerTarget = battler; break; } case VARIOUS_IS_RUNNING_IMPOSSIBLE: { VARIOUS_ARGS(); - gBattleCommunication[0] = IsRunningFromBattleImpossible(); + gBattleCommunication[0] = IsRunningFromBattleImpossible(battler); break; } case VARIOUS_GET_MOVE_TARGET: @@ -8971,7 +8864,7 @@ static void Cmd_various(void) case VARIOUS_GET_BATTLER_FAINTED: { VARIOUS_ARGS(); - if (gHitMarker & HITMARKER_FAINTED(gActiveBattler)) + if (gHitMarker & HITMARKER_FAINTED(battler)) gBattleCommunication[0] = TRUE; else gBattleCommunication[0] = FALSE; @@ -8980,8 +8873,8 @@ static void Cmd_various(void) case VARIOUS_RESET_SWITCH_IN_ABILITY_BITS: { VARIOUS_ARGS(); - gSpecialStatuses[gActiveBattler].traced = FALSE; - gSpecialStatuses[gActiveBattler].switchInAbilityDone = FALSE; + gSpecialStatuses[battler].traced = FALSE; + gSpecialStatuses[battler].switchInAbilityDone = FALSE; break; } case VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP: @@ -8990,17 +8883,17 @@ static void Cmd_various(void) if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId || gBattlerPartyIndexes[2] == gBattleStruct->expGetterMonId) { if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId) - gActiveBattler = 0; + battler = 0; else - gActiveBattler = 2; + battler = 2; for (i = 0; i < MAX_MON_MOVES; i++) { - if (gBattleMons[gActiveBattler].moves[i] == gBattleStruct->choicedMove[gActiveBattler]) + if (gBattleMons[battler].moves[i] == gBattleStruct->choicedMove[battler]) break; } if (i == MAX_MON_MOVES) - gBattleStruct->choicedMove[gActiveBattler] = MOVE_NONE; + gBattleStruct->choicedMove[battler] = MOVE_NONE; } break; } @@ -9021,15 +8914,15 @@ static void Cmd_various(void) VARIOUS_ARGS(); // Try and print end-of-turn Battle Palace flavor text (e.g. "A glint appears in mon's eyes") gBattleCommunication[0] = FALSE; // whether or not msg should be printed - gBattleScripting.battler = gActiveBattler = gBattleCommunication[1]; - if (!(gBattleStruct->palaceFlags & gBitTable[gActiveBattler]) - && gBattleMons[gActiveBattler].maxHP / 2 >= gBattleMons[gActiveBattler].hp - && gBattleMons[gActiveBattler].hp != 0 - && !(gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP)) + gBattleScripting.battler = battler = gBattleCommunication[1]; + if (!(gBattleStruct->palaceFlags & gBitTable[battler]) + && gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp + && gBattleMons[battler].hp != 0 + && !(gBattleMons[battler].status1 & STATUS1_SLEEP)) { - gBattleStruct->palaceFlags |= gBitTable[gActiveBattler]; + gBattleStruct->palaceFlags |= gBitTable[battler]; gBattleCommunication[0] = TRUE; - gBattleCommunication[MULTISTRING_CHOOSER] = sBattlePalaceNatureToFlavorTextId[GetNatureFromPersonality(gBattleMons[gActiveBattler].personality)]; + gBattleCommunication[MULTISTRING_CHOOSER] = sBattlePalaceNatureToFlavorTextId[GetNatureFromPersonality(gBattleMons[battler].personality)]; } break; } @@ -9083,8 +8976,8 @@ static void Cmd_various(void) case VARIOUS_EMIT_YESNOBOX: { VARIOUS_ARGS(); - BtlController_EmitYesNoBox(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitYesNoBox(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_DRAW_ARENA_REF_TEXT_BOX: @@ -9123,11 +9016,11 @@ static void Cmd_various(void) case VARIOUS_RETURN_OPPONENT_MON1: { VARIOUS_ARGS(); - gActiveBattler = 1; - if (gBattleMons[gActiveBattler].hp != 0) + battler = 1; + if (gBattleMons[battler].hp != 0) { - BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitReturnMonToBall(battler, BUFFER_A, FALSE); + MarkBattlerForControllerExec(battler); } break; } @@ -9136,11 +9029,11 @@ static void Cmd_various(void) VARIOUS_ARGS(); if (gBattlersCount > 3) { - gActiveBattler = 3; - if (gBattleMons[gActiveBattler].hp != 0) + battler = 3; + if (gBattleMons[battler].hp != 0) { - BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitReturnMonToBall(battler, BUFFER_A, FALSE); + MarkBattlerForControllerExec(battler); } } break; @@ -9160,13 +9053,13 @@ static void Cmd_various(void) case VARIOUS_SET_ALREADY_STATUS_MOVE_ATTEMPT: { VARIOUS_ARGS(); - gBattleStruct->alreadyStatusedMoveAttempt |= gBitTable[gActiveBattler]; + gBattleStruct->alreadyStatusedMoveAttempt |= gBitTable[battler]; break; } case VARIOUS_PALACE_TRY_ESCAPE_STATUS: { VARIOUS_ARGS(); - if (BattlePalace_TryEscapeStatus(gActiveBattler)) + if (BattlePalace_TryEscapeStatus(battler)) return; break; } @@ -9175,16 +9068,16 @@ static void Cmd_various(void) VARIOUS_ARGS(); // Don't end the battle if one of the wild mons teleported from the wild double battle // and its partner is still alive. - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT && IsBattlerAlive(BATTLE_PARTNER(gActiveBattler))) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && IsBattlerAlive(BATTLE_PARTNER(battler))) { - gAbsentBattlerFlags |= gBitTable[gActiveBattler]; - gHitMarker |= HITMARKER_FAINTED(gActiveBattler); - gBattleMons[gActiveBattler].hp = 0; - SetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_HP, &gBattleMons[gActiveBattler].hp); - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - FaintClearSetData(); + gAbsentBattlerFlags |= gBitTable[battler]; + gHitMarker |= HITMARKER_FAINTED(battler); + gBattleMons[battler].hp = 0; + SetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP, &gBattleMons[battler].hp); + SetHealthboxSpriteInvisible(gHealthboxSpriteIds[battler]); + FaintClearSetData(battler); } - else if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + else if (GetBattlerSide(battler) == B_SIDE_PLAYER) { gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; } @@ -9197,8 +9090,8 @@ static void Cmd_various(void) case VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC: { VARIOUS_ARGS(); - BtlController_EmitPlayFanfareOrBGM(BUFFER_A, MUS_VICTORY_TRAINER, TRUE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPlayFanfareOrBGM(battler, BUFFER_A, MUS_VICTORY_TRAINER, TRUE); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_STAT_TEXT_BUFFER: @@ -9211,9 +9104,9 @@ static void Cmd_various(void) { VARIOUS_ARGS(); gBattlescriptCurrInstr = cmd->nextInstr; - AbilityBattleEffects(ABILITYEFFECT_NEUTRALIZINGGAS, gActiveBattler, 0, 0, 0); - AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0); - AbilityBattleEffects(ABILITYEFFECT_TRACE2, gActiveBattler, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_NEUTRALIZINGGAS, battler, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, battler, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_TRACE2, battler, 0, 0, 0); return; } case VARIOUS_SAVE_TARGET: @@ -9231,16 +9124,16 @@ static void Cmd_various(void) case VARIOUS_INSTANT_HP_DROP: { VARIOUS_ARGS(); - BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitHealthBarUpdate(battler, BUFFER_A, INSTANT_HP_BAR_DROP); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_CLEAR_STATUS: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMons[battler].status1 = 0; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_RESTORE_PP: @@ -9248,19 +9141,19 @@ static void Cmd_various(void) VARIOUS_ARGS(); for (i = 0; i < 4; i++) { - gBattleMons[gActiveBattler].pp[i] = CalculatePPWithBonus(gBattleMons[gActiveBattler].moves[i], gBattleMons[gActiveBattler].ppBonuses, i); - data[i] = gBattleMons[gActiveBattler].pp[i]; + gBattleMons[battler].pp[i] = CalculatePPWithBonus(gBattleMons[battler].moves[i], gBattleMons[battler].ppBonuses, i); + data[i] = gBattleMons[battler].pp[i]; } - data[i] = gBattleMons[gActiveBattler].ppBonuses; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PP_DATA_BATTLE, 0, 5, data); - MarkBattlerForControllerExec(gActiveBattler); + data[i] = gBattleMons[battler].ppBonuses; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_PP_DATA_BATTLE, 0, 5, data); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_TRY_ACTIVATE_MOXIE: // and chilling neigh + as one ice rider { VARIOUS_ARGS(); - u16 battlerAbility = GetBattlerAbility(gActiveBattler); + u16 battlerAbility = GetBattlerAbility(battler); if ((battlerAbility == ABILITY_MOXIE || battlerAbility == ABILITY_CHILLING_NEIGH @@ -9284,7 +9177,7 @@ static void Cmd_various(void) { VARIOUS_ARGS(); - u16 battlerAbility = GetBattlerAbility(gActiveBattler); + u16 battlerAbility = GetBattlerAbility(battler); if ((battlerAbility == ABILITY_GRIM_NEIGH || battlerAbility == ABILITY_AS_ONE_SHADOW_RIDER) @@ -9306,13 +9199,13 @@ static void Cmd_various(void) case VARIOUS_TRY_ACTIVATE_RECEIVER: // Partner gets fainted's ally ability { VARIOUS_ARGS(); - gBattlerAbility = BATTLE_PARTNER(gActiveBattler); + gBattlerAbility = BATTLE_PARTNER(battler); i = GetBattlerAbility(gBattlerAbility); if (IsBattlerAlive(gBattlerAbility) && (i == ABILITY_RECEIVER || i == ABILITY_POWER_OF_ALCHEMY) - && GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_ABILITY_SHIELD) + && GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_ABILITY_SHIELD) { - switch (gBattleMons[gActiveBattler].ability) + switch (gBattleMons[battler].ability) { // Can't copy these abilities. case ABILITY_POWER_OF_ALCHEMY: case ABILITY_RECEIVER: case ABILITY_FORECAST: case ABILITY_MULTITYPE: @@ -9325,8 +9218,8 @@ static void Cmd_various(void) case ABILITY_RKS_SYSTEM: case ABILITY_TRACE: break; default: - gBattleStruct->tracedAbility[gBattlerAbility] = gBattleMons[gActiveBattler].ability; // re-using the variable for trace - gBattleScripting.battler = gActiveBattler; + gBattleStruct->tracedAbility[gBattlerAbility] = gBattleMons[battler].ability; // re-using the variable for trace + gBattleScripting.battler = battler; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = BattleScript_ReceiverActivates; return; @@ -9337,8 +9230,8 @@ static void Cmd_various(void) case VARIOUS_TRY_ACTIVATE_BEAST_BOOST: { VARIOUS_ARGS(); - i = GetHighestStatId(gActiveBattler); - if (GetBattlerAbility(gActiveBattler) == ABILITY_BEAST_BOOST + i = GetHighestStatId(battler); + if (GetBattlerAbility(battler) == ABILITY_BEAST_BOOST && HasAttackerFaintedTarget() && !NoAliveMonsForEitherParty() && CompareStat(gBattlerAttacker, i, MAX_STAT_STAGE, CMP_LESS_THAN)) @@ -9395,19 +9288,19 @@ static void Cmd_various(void) case VARIOUS_PLAY_MOVE_ANIMATION: { VARIOUS_ARGS(u16 move); - BtlController_EmitMoveAnimation(BUFFER_A, cmd->move, gBattleScripting.animTurn, 0, 0, gBattleMons[gActiveBattler].friendship, &gDisableStructs[gActiveBattler], gMultiHitCounter); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitMoveAnimation(battler, BUFFER_A, cmd->move, gBattleScripting.animTurn, 0, 0, gBattleMons[battler].friendship, &gDisableStructs[battler], gMultiHitCounter); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_SET_LUCKY_CHANT: { VARIOUS_ARGS(const u8 *failInstr); - if (!(gSideStatuses[GET_BATTLER_SIDE(gActiveBattler)] & SIDE_STATUS_LUCKY_CHANT)) + if (!(gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_LUCKY_CHANT)) { - gSideStatuses[GET_BATTLER_SIDE(gActiveBattler)] |= SIDE_STATUS_LUCKY_CHANT; - gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].luckyChantBattlerId = gActiveBattler; - gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].luckyChantTimer = 5; + gSideStatuses[GET_BATTLER_SIDE(battler)] |= SIDE_STATUS_LUCKY_CHANT; + gSideTimers[GET_BATTLER_SIDE(battler)].luckyChantBattlerId = battler; + gSideTimers[GET_BATTLER_SIDE(battler)].luckyChantTimer = 5; gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -9484,22 +9377,22 @@ static void Cmd_various(void) case VARIOUS_SET_LAST_USED_ABILITY: { VARIOUS_ARGS(); - gLastUsedAbility = gBattleMons[gActiveBattler].ability; + gLastUsedAbility = gBattleMons[battler].ability; break; } case VARIOUS_TRY_HEAL_PULSE: { VARIOUS_ARGS(const u8 *failInstr); - if (BATTLER_MAX_HP(gActiveBattler)) + if (BATTLER_MAX_HP(battler)) { gBattlescriptCurrInstr = cmd->failInstr; } else { if (GetBattlerAbility(gBattlerAttacker) == ABILITY_MEGA_LAUNCHER && gBattleMoves[gCurrentMove].pulseMove) - gBattleMoveDamage = -(gBattleMons[gActiveBattler].maxHP * 75 / 100); + gBattleMoveDamage = -(gBattleMons[battler].maxHP * 75 / 100); else - gBattleMoveDamage = -(gBattleMons[gActiveBattler].maxHP / 2); + gBattleMoveDamage = -(gBattleMons[battler].maxHP / 2); if (gBattleMoveDamage == 0) gBattleMoveDamage = -1; @@ -9526,10 +9419,10 @@ static void Cmd_various(void) VARIOUS_ARGS(); for (i = 0; i < NUM_BATTLE_STATS; i++) { - if (gBattleMons[gActiveBattler].statStages[i] < DEFAULT_STAT_STAGE) // Negative becomes positive. - gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE + (DEFAULT_STAT_STAGE - gBattleMons[gActiveBattler].statStages[i]); - else if (gBattleMons[gActiveBattler].statStages[i] > DEFAULT_STAT_STAGE) // Positive becomes negative. - gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE - (gBattleMons[gActiveBattler].statStages[i] - DEFAULT_STAT_STAGE); + if (gBattleMons[battler].statStages[i] < DEFAULT_STAT_STAGE) // Negative becomes positive. + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE + (DEFAULT_STAT_STAGE - gBattleMons[battler].statStages[i]); + else if (gBattleMons[battler].statStages[i] > DEFAULT_STAT_STAGE) // Positive becomes negative. + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE - (gBattleMons[battler].statStages[i] - DEFAULT_STAT_STAGE); } break; } @@ -9629,49 +9522,49 @@ static void Cmd_various(void) case VARIOUS_HANDLE_MEGA_EVO: { VARIOUS_ARGS(u8 case_); - HandleScriptMegaPrimalBurst(cmd->case_, gActiveBattler, HANDLE_TYPE_MEGA_EVOLUTION); + HandleScriptMegaPrimalBurst(cmd->case_, battler, HANDLE_TYPE_MEGA_EVOLUTION); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_HANDLE_PRIMAL_REVERSION: { VARIOUS_ARGS(u8 case_); - HandleScriptMegaPrimalBurst(cmd->case_, gActiveBattler, HANDLE_TYPE_PRIMAL_REVERSION); + HandleScriptMegaPrimalBurst(cmd->case_, battler, HANDLE_TYPE_PRIMAL_REVERSION); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_HANDLE_ULTRA_BURST: { VARIOUS_ARGS(u8 case_); - HandleScriptMegaPrimalBurst(cmd->case_, gActiveBattler, HANDLE_TYPE_ULTRA_BURST); + HandleScriptMegaPrimalBurst(cmd->case_, battler, HANDLE_TYPE_ULTRA_BURST); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_HANDLE_FORM_CHANGE: { VARIOUS_ARGS(u8 case_); - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) - mon = &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]]; + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) + mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; else - mon = &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]; + mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; // Change species. if (cmd->case_ == 0) { if (!gBattleTextBuff1) - PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); - BtlController_EmitSetMonData(BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]], sizeof(gBattleMons[gActiveBattler].species), &gBattleMons[gActiveBattler].species); - MarkBattlerForControllerExec(gActiveBattler); + PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[battler].species); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[battler]], sizeof(gBattleMons[battler].species), &gBattleMons[battler].species); + MarkBattlerForControllerExec(battler); } // Change stats. else if (cmd->case_ == 1) { - RecalcBattlerStats(gActiveBattler, mon); + RecalcBattlerStats(battler, mon); } // Update healthbox. else { - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], mon, HEALTHBOX_ALL); + UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], mon, HEALTHBOX_ALL); } gBattlescriptCurrInstr = cmd->nextInstr; return; @@ -9679,7 +9572,7 @@ static void Cmd_various(void) case VARIOUS_TRY_LAST_RESORT: { VARIOUS_ARGS(const u8 *failInstr); - if (CanUseLastResort(gActiveBattler)) + if (CanUseLastResort(battler)) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->failInstr; @@ -9744,9 +9637,9 @@ static void Cmd_various(void) case VARIOUS_TRY_AUTOTOMIZE: { VARIOUS_ARGS(const u8 *failInstr); - if (GetBattlerWeight(gActiveBattler) > 1) + if (GetBattlerWeight(battler) > 1) { - gDisableStructs[gActiveBattler].autotomizeCount++; + gDisableStructs[battler].autotomizeCount++; gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -9799,7 +9692,7 @@ static void Cmd_various(void) { gBattlerTarget = gBattleStruct->lastMoveTarget[gBattlerAttacker]; gHitMarker &= ~HITMARKER_ATTACKSTRING_PRINTED; - PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, gActiveBattler, gBattlerPartyIndexes[gActiveBattler]); + PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battler, gBattlerPartyIndexes[battler]); gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -9808,13 +9701,13 @@ static void Cmd_various(void) case VARIOUS_ABILITY_POPUP: { VARIOUS_ARGS(); - CreateAbilityPopUp(gActiveBattler, gBattleMons[gActiveBattler].ability, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0); + CreateAbilityPopUp(battler, gBattleMons[battler].ability, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0); break; } case VARIOUS_UPDATE_ABILITY_POPUP: { VARIOUS_ARGS(); - UpdateAbilityPopup(gActiveBattler); + UpdateAbilityPopup(battler); break; } case VARIOUS_DEFOG: @@ -9829,7 +9722,7 @@ static void Cmd_various(void) } else { - if (TryDefogClear(gActiveBattler, FALSE)) + if (TryDefogClear(battler, FALSE)) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->failInstr; @@ -9859,8 +9752,8 @@ static void Cmd_various(void) VARIOUS_ARGS(u8 type); for (i = 0; i < 3; i++) { - if (*(u8 *)(&gBattleMons[gActiveBattler].type1 + i) == cmd->type) - *(u8 *)(&gBattleMons[gActiveBattler].type1 + i) = TYPE_MYSTERY; + if (*(u8 *)(&gBattleMons[battler].type1 + i) == cmd->type) + *(u8 *)(&gBattleMons[battler].type1 + i) = TYPE_MYSTERY; } gBattlescriptCurrInstr = cmd->nextInstr; return; @@ -9887,25 +9780,25 @@ static void Cmd_various(void) return; } gBattleMons[gBattlerTarget].status1 = gBattleMons[gBattlerAttacker].status1 & STATUS1_ANY; - gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + battler = gBattlerTarget; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; return; } case VARIOUS_CURE_STATUS: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMons[battler].status1 = 0; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_POWER_TRICK: { VARIOUS_ARGS(); - gStatuses3[gActiveBattler] ^= STATUS3_POWER_TRICK; - SWAP(gBattleMons[gActiveBattler].attack, gBattleMons[gActiveBattler].defense, i); + gStatuses3[battler] ^= STATUS3_POWER_TRICK; + SWAP(gBattleMons[battler].attack, gBattleMons[battler].defense, i); break; } case VARIOUS_AFTER_YOU: @@ -9949,7 +9842,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_NOT_GROUNDED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (!IsBattlerGrounded(gActiveBattler)) + if (!IsBattlerGrounded(battler)) gBattlescriptCurrInstr = gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -9961,24 +9854,24 @@ static void Cmd_various(void) if (cmd->case_ == 0) { // Save sprite IDs, because trainer slide in will overwrite gBattlerSpriteIds variable. - gBattleScripting.savedDmg = (gBattlerSpriteIds[gActiveBattler] & 0xFF) | (gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)] << 8); - HideBattlerShadowSprite(gActiveBattler); + gBattleScripting.savedDmg = (gBattlerSpriteIds[battler] & 0xFF) | (gBattlerSpriteIds[BATTLE_PARTNER(battler)] << 8); + HideBattlerShadowSprite(battler); } else if (cmd->case_ == 1) { - BtlController_EmitPrintString(BUFFER_A, STRINGID_TRAINERSLIDE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPrintString(battler, BUFFER_A, STRINGID_TRAINERSLIDE); + MarkBattlerForControllerExec(battler); } else { - gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)] = gBattleScripting.savedDmg >> 8; - gBattlerSpriteIds[gActiveBattler] = gBattleScripting.savedDmg & 0xFF; - if (IsBattlerAlive(gActiveBattler)) + gBattlerSpriteIds[BATTLE_PARTNER(battler)] = gBattleScripting.savedDmg >> 8; + gBattlerSpriteIds[battler] = gBattleScripting.savedDmg & 0xFF; + if (IsBattlerAlive(battler)) { - SetBattlerShadowSpriteCallback(gActiveBattler, gBattleMons[gActiveBattler].species); - BattleLoadMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); + SetBattlerShadowSpriteCallback(battler, gBattleMons[battler].species); + BattleLoadMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battler]], battler); } - i = BATTLE_PARTNER(gActiveBattler); + i = BATTLE_PARTNER(battler); if (IsBattlerAlive(i)) { SetBattlerShadowSpriteCallback(i, gBattleMons[i].species); @@ -9991,9 +9884,9 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_FIRST_OFF: { VARIOUS_ARGS(); - if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_FIRST_DOWN))) + if ((i = ShouldDoTrainerSlide(battler, TRAINER_SLIDE_FIRST_DOWN))) { - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; @@ -10003,9 +9896,9 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_LAST_ON: { VARIOUS_ARGS(); - if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_LAST_SWITCHIN))) + if ((i = ShouldDoTrainerSlide(battler, TRAINER_SLIDE_LAST_SWITCHIN))) { - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; @@ -10015,7 +9908,7 @@ static void Cmd_various(void) case VARIOUS_SET_AURORA_VEIL: { VARIOUS_ARGS(); - if (gSideStatuses[GET_BATTLER_SIDE(gActiveBattler)] & SIDE_STATUS_AURORA_VEIL + if (gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_AURORA_VEIL || !(WEATHER_HAS_EFFECT && gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW))) { gMoveResultFlags |= MOVE_RESULT_MISSED; @@ -10023,14 +9916,14 @@ static void Cmd_various(void) } else { - gSideStatuses[GET_BATTLER_SIDE(gActiveBattler)] |= SIDE_STATUS_AURORA_VEIL; - if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_LIGHT_CLAY) - gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].auroraVeilTimer = 8; + gSideStatuses[GET_BATTLER_SIDE(battler)] |= SIDE_STATUS_AURORA_VEIL; + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_LIGHT_CLAY) + gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilTimer = 8; else - gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].auroraVeilTimer = 5; - gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].auroraVeilBattlerId = gActiveBattler; + gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilTimer = 5; + gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilBattlerId = battler; - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_ATK_SIDE) == 2) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = 5; else gBattleCommunication[MULTISTRING_CHOOSER] = 5; @@ -10040,13 +9933,13 @@ static void Cmd_various(void) case VARIOUS_TRY_THIRD_TYPE: { VARIOUS_ARGS(const u8 *failInstr); - if (IS_BATTLER_OF_TYPE(gActiveBattler, gBattleMoves[gCurrentMove].argument)) + if (IS_BATTLER_OF_TYPE(battler, gBattleMoves[gCurrentMove].argument)) { gBattlescriptCurrInstr = cmd->failInstr; } else { - gBattleMons[gActiveBattler].type3 = gBattleMoves[gCurrentMove].argument; + gBattleMons[battler].type3 = gBattleMoves[gCurrentMove].argument; PREPARE_TYPE_BUFFER(gBattleTextBuff1, gBattleMoves[gCurrentMove].argument); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -10055,14 +9948,14 @@ static void Cmd_various(void) case VARIOUS_DESTROY_ABILITY_POPUP: { VARIOUS_ARGS(); - DestroyAbilityPopUp(gActiveBattler); + DestroyAbilityPopUp(battler); break; } case VARIOUS_TOTEM_BOOST: { VARIOUS_ARGS(const u8 *jumpInstr); - gActiveBattler = gBattlerAttacker; - if (gTotemBoosts[gActiveBattler].stats == 0) + battler = gBattlerAttacker; + if (gTotemBoosts[battler].stats == 0) { gBattlescriptCurrInstr = cmd->nextInstr; // stats done, exit } @@ -10070,19 +9963,19 @@ static void Cmd_various(void) { for (i = 0; i < (NUM_BATTLE_STATS - 1); i++) { - if (gTotemBoosts[gActiveBattler].stats & (1 << i)) + if (gTotemBoosts[battler].stats & (1 << i)) { - if (gTotemBoosts[gActiveBattler].statChanges[i] <= -1) - SET_STATCHANGER(i + 1, abs(gTotemBoosts[gActiveBattler].statChanges[i]), TRUE); + if (gTotemBoosts[battler].statChanges[i] <= -1) + SET_STATCHANGER(i + 1, abs(gTotemBoosts[battler].statChanges[i]), TRUE); else - SET_STATCHANGER(i + 1, gTotemBoosts[gActiveBattler].statChanges[i], FALSE); + SET_STATCHANGER(i + 1, gTotemBoosts[battler].statChanges[i], FALSE); - gTotemBoosts[gActiveBattler].stats &= ~(1 << i); - gBattleScripting.battler = gActiveBattler; - gBattlerTarget = gActiveBattler; - if (gTotemBoosts[gActiveBattler].stats & 0x80) + gTotemBoosts[battler].stats &= ~(1 << i); + gBattleScripting.battler = battler; + gBattlerTarget = battler; + if (gTotemBoosts[battler].stats & 0x80) { - gTotemBoosts[gActiveBattler].stats &= ~0x80; // set 'aura flared to life' flag + gTotemBoosts[battler].stats &= ~0x80; // set 'aura flared to life' flag gBattlescriptCurrInstr = BattleScript_TotemFlaredToLife; } else @@ -10099,14 +9992,14 @@ static void Cmd_various(void) case VARIOUS_MOVEEND_ITEM_EFFECTS: { VARIOUS_ARGS(); - if (ItemBattleEffects(ITEMEFFECT_NORMAL, gActiveBattler, FALSE)) + if (ItemBattleEffects(ITEMEFFECT_NORMAL, battler, FALSE)) return; break; } case VARIOUS_ROOM_SERVICE: { VARIOUS_ARGS(const u8 *failInstr); - if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_ROOM_SERVICE && TryRoomService(gActiveBattler)) + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_ROOM_SERVICE && TryRoomService(battler)) { BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryStatRaiseRet; @@ -10120,23 +10013,23 @@ static void Cmd_various(void) case VARIOUS_TERRAIN_SEED: { VARIOUS_ARGS(const u8 *failInstr); - if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_SEEDS) + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_SEEDS) { u8 effect = 0; - u16 item = gBattleMons[gActiveBattler].item; - switch (GetBattlerHoldEffectParam(gActiveBattler)) + u16 item = gBattleMons[battler].item; + switch (GetBattlerHoldEffectParam(battler)) { case HOLD_EFFECT_PARAM_ELECTRIC_TERRAIN: - effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, item, FALSE); + effect = TryHandleSeed(battler, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, item, FALSE); break; case HOLD_EFFECT_PARAM_GRASSY_TERRAIN: - effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, item, FALSE); + effect = TryHandleSeed(battler, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, item, FALSE); break; case HOLD_EFFECT_PARAM_MISTY_TERRAIN: - effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, item, FALSE); + effect = TryHandleSeed(battler, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, item, FALSE); break; case HOLD_EFFECT_PARAM_PSYCHIC_TERRAIN: - effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, item, FALSE); + effect = TryHandleSeed(battler, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, item, FALSE); break; } @@ -10152,15 +10045,15 @@ static void Cmd_various(void) if (gBattleControllerExecFlags) break; - BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSpriteInvisibility(battler, BUFFER_A, TRUE); + MarkBattlerForControllerExec(battler); break; } case VARIOUS_JUMP_IF_TERRAIN_AFFECTED: { VARIOUS_ARGS(u32 flags, const u8 *jumpInstr); u32 flags = cmd->flags; - if (IsBattlerTerrainAffected(gActiveBattler, flags)) + if (IsBattlerTerrainAffected(battler, flags)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10169,36 +10062,36 @@ static void Cmd_various(void) case VARIOUS_EERIE_SPELL_PP_REDUCE: { VARIOUS_ARGS(const u8 *failInstr); - if (gLastMoves[gActiveBattler] != 0 && gLastMoves[gActiveBattler] != 0xFFFF) + if (gLastMoves[battler] != 0 && gLastMoves[battler] != 0xFFFF) { s32 i; for (i = 0; i < MAX_MON_MOVES; i++) { - if (gLastMoves[gActiveBattler] == gBattleMons[gActiveBattler].moves[i]) + if (gLastMoves[battler] == gBattleMons[battler].moves[i]) break; } - if (i != MAX_MON_MOVES && gBattleMons[gActiveBattler].pp[i] != 0) + if (i != MAX_MON_MOVES && gBattleMons[battler].pp[i] != 0) { s32 ppToDeduct = 3; - if (gBattleMons[gActiveBattler].pp[i] < ppToDeduct) - ppToDeduct = gBattleMons[gActiveBattler].pp[i]; + if (gBattleMons[battler].pp[i] < ppToDeduct) + ppToDeduct = gBattleMons[battler].pp[i]; - PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastMoves[gActiveBattler]) + PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastMoves[battler]) ConvertIntToDecimalStringN(gBattleTextBuff2, ppToDeduct, STR_CONV_MODE_LEFT_ALIGN, 1); PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff2, 1, ppToDeduct) - gBattleMons[gActiveBattler].pp[i] -= ppToDeduct; - if (!(gDisableStructs[gActiveBattler].mimickedMoves & gBitTable[i]) - && !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) + gBattleMons[battler].pp[i] -= ppToDeduct; + if (!(gDisableStructs[battler].mimickedMoves & gBitTable[i]) + && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED)) { - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[battler].pp[i]), &gBattleMons[battler].pp[i]); + MarkBattlerForControllerExec(battler); } - if (gBattleMons[gActiveBattler].pp[i] == 0 && gBattleStruct->skyDropTargets[gActiveBattler] == 0xFF) - CancelMultiTurnMoves(gActiveBattler); + if (gBattleMons[battler].pp[i] == 0 && gBattleStruct->skyDropTargets[battler] == 0xFF) + CancelMultiTurnMoves(battler); gBattlescriptCurrInstr = cmd->nextInstr; // continue } @@ -10216,10 +10109,10 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_TEAM_HEALTHY: { VARIOUS_ARGS(const u8 *jumpInstr); - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && IsBattlerAlive(BATTLE_PARTNER(gActiveBattler))) + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && IsBattlerAlive(BATTLE_PARTNER(battler))) { - u8 partner = BATTLE_PARTNER(gActiveBattler); - if ((gBattleMons[gActiveBattler].hp == gBattleMons[gActiveBattler].maxHP && !(gBattleMons[gActiveBattler].status1 & STATUS1_ANY)) + u8 partner = BATTLE_PARTNER(battler); + if ((gBattleMons[battler].hp == gBattleMons[battler].maxHP && !(gBattleMons[battler].status1 & STATUS1_ANY)) && (gBattleMons[partner].hp == gBattleMons[partner].maxHP && !(gBattleMons[partner].status1 & STATUS1_ANY))) gBattlescriptCurrInstr = cmd->jumpInstr; else @@ -10227,7 +10120,7 @@ static void Cmd_various(void) } else // single battle { - if (gBattleMons[gActiveBattler].hp == gBattleMons[gActiveBattler].maxHP && !(gBattleMons[gActiveBattler].status1 & STATUS1_ANY)) + if (gBattleMons[battler].hp == gBattleMons[battler].maxHP && !(gBattleMons[battler].status1 & STATUS1_ANY)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10237,12 +10130,12 @@ static void Cmd_various(void) case VARIOUS_TRY_HEAL_QUARTER_HP: { VARIOUS_ARGS(const u8 *failInstr); - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 4; + gBattleMoveDamage = gBattleMons[battler].maxHP / 4; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; - if (gBattleMons[gActiveBattler].hp == gBattleMons[gActiveBattler].maxHP) + if (gBattleMons[battler].hp == gBattleMons[battler].maxHP) gBattlescriptCurrInstr = cmd->failInstr; // fail else gBattlescriptCurrInstr = cmd->nextInstr; // can heal @@ -10334,7 +10227,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_PRANKSTER_BLOCKED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (BlocksPrankster(gCurrentMove, gBattlerAttacker, gActiveBattler, TRUE)) + if (BlocksPrankster(gCurrentMove, gBattlerAttacker, battler, TRUE)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10356,19 +10249,19 @@ static void Cmd_various(void) if (gBattleWeather & B_WEATHER_SUN_PRIMAL && !shouldNotClear) { gBattleWeather &= ~B_WEATHER_SUN_PRIMAL; - PrepareStringBattle(STRINGID_EXTREMESUNLIGHTFADED, gActiveBattler); + PrepareStringBattle(STRINGID_EXTREMESUNLIGHTFADED, battler); gBattleCommunication[MSG_DISPLAY] = 1; } else if (gBattleWeather & B_WEATHER_RAIN_PRIMAL && !shouldNotClear) { gBattleWeather &= ~B_WEATHER_RAIN_PRIMAL; - PrepareStringBattle(STRINGID_HEAVYRAINLIFTED, gActiveBattler); + PrepareStringBattle(STRINGID_HEAVYRAINLIFTED, battler); gBattleCommunication[MSG_DISPLAY] = 1; } else if (gBattleWeather & B_WEATHER_STRONG_WINDS && !shouldNotClear) { gBattleWeather &= ~B_WEATHER_STRONG_WINDS; - PrepareStringBattle(STRINGID_STRONGWINDSDISSIPATED, gActiveBattler); + PrepareStringBattle(STRINGID_STRONGWINDSDISSIPATED, battler); gBattleCommunication[MSG_DISPLAY] = 1; } break; @@ -10376,9 +10269,9 @@ static void Cmd_various(void) case VARIOUS_TRY_END_NEUTRALIZING_GAS: { VARIOUS_ARGS(); - if (gSpecialStatuses[gActiveBattler].neutralizingGasRemoved) + if (gSpecialStatuses[battler].neutralizingGasRemoved) { - gSpecialStatuses[gActiveBattler].neutralizingGasRemoved = FALSE; + gSpecialStatuses[battler].neutralizingGasRemoved = FALSE; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = BattleScript_NeutralizingGasExits; return; @@ -10411,9 +10304,9 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_NOT_ROTOTILLER_AFFECTED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (gSpecialStatuses[gActiveBattler].rototillerAffected) + if (gSpecialStatuses[battler].rototillerAffected) { - gSpecialStatuses[gActiveBattler].rototillerAffected = FALSE; + gSpecialStatuses[battler].rototillerAffected = FALSE; gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -10450,10 +10343,10 @@ static void Cmd_various(void) } if (cmd->fromBattler) - gLastUsedItem = gBattleMons[gActiveBattler].item; + gLastUsedItem = gBattleMons[battler].item; - gBattleScripting.battler = gEffectBattler = gBattlerTarget = gActiveBattler; // Cover all berry effect battlerId cases. e.g. ChangeStatBuffs uses target ID - if (ItemBattleEffects(ITEMEFFECT_USE_LAST_ITEM, gActiveBattler, FALSE)) + gBattleScripting.battler = gEffectBattler = gBattlerTarget = battler; // Cover all berry effect battler cases. e.g. ChangeStatBuffs uses target ID + if (ItemBattleEffects(ITEMEFFECT_USE_LAST_ITEM, battler, FALSE)) return; gBattlescriptCurrInstr = cmd->nextInstr; return; @@ -10461,7 +10354,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_CANT_REVERT_TO_PRIMAL: { VARIOUS_ARGS(const u8 *jumpInstr); - if (GetBattleFormChangeTargetSpecies(gActiveBattler, FORM_CHANGE_BATTLE_PRIMAL_REVERSION) == SPECIES_NONE) + if (GetBattleFormChangeTargetSpecies(battler, FORM_CHANGE_BATTLE_PRIMAL_REVERSION) == SPECIES_NONE) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10471,7 +10364,7 @@ static void Cmd_various(void) { VARIOUS_ARGS(u32 flags, const u8 *jumpInstr); u32 flags = cmd->flags; - if (IsBattlerWeatherAffected(gActiveBattler, flags)) + if (IsBattlerWeatherAffected(battler, flags)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10487,7 +10380,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_SPECIES: { VARIOUS_ARGS(u16 species, const u8 *jumpInstr); - if (gBattleMons[gActiveBattler].species == cmd->species) + if (gBattleMons[battler].species == cmd->species) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10496,7 +10389,7 @@ static void Cmd_various(void) case VARIOUS_PHOTON_GEYSER_CHECK: { VARIOUS_ARGS(); - gBattleStruct->swapDamageCategory = (GetSplitBasedOnStats(gActiveBattler) == SPLIT_SPECIAL); + gBattleStruct->swapDamageCategory = (GetSplitBasedOnStats(battler) == SPLIT_SPECIAL); break; } case VARIOUS_SHELL_SIDE_ARM_CHECK: // 0% chance GameFreak actually checks this way according to DaWobblefet, but this is the only functional explanation at the moment @@ -10540,9 +10433,9 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (IsLeafGuardProtected(gActiveBattler)) + if (IsLeafGuardProtected(battler)) { - gBattlerAbility = gActiveBattler; + gBattlerAbility = battler; gBattlescriptCurrInstr = cmd->jumpInstr; } else @@ -10558,8 +10451,8 @@ static void Cmd_various(void) // If Pokémon which set up Sticky Web is not on the field, no Pokémon have their Speed lowered." gBattlerAttacker = gBattlerTarget; // Initialize 'fail' condition SET_STATCHANGER(STAT_SPEED, 1, TRUE); - if (gSideTimers[GetBattlerSide(gActiveBattler)].stickyWebBattlerId != 0xFF) - gBattlerAttacker = gSideTimers[GetBattlerSide(gActiveBattler)].stickyWebBattlerId; + if (gSideTimers[GetBattlerSide(battler)].stickyWebBattlerId != 0xFF) + gBattlerAttacker = gSideTimers[GetBattlerSide(battler)].stickyWebBattlerId; break; } case VARIOUS_CUT_1_3_HP_RAISE_STATS: @@ -10591,15 +10484,15 @@ static void Cmd_various(void) case VARIOUS_SET_OCTOLOCK: { VARIOUS_ARGS(const u8 *failInstr); - if (gDisableStructs[gActiveBattler].octolock) + if (gDisableStructs[battler].octolock) { gBattlescriptCurrInstr = cmd->failInstr; } else { - gDisableStructs[gActiveBattler].octolock = TRUE; - gBattleMons[gActiveBattler].status2 |= STATUS2_ESCAPE_PREVENTION; - gDisableStructs[gActiveBattler].battlerPreventingEscape = gBattlerAttacker; + gDisableStructs[battler].octolock = TRUE; + gBattleMons[battler].status2 |= STATUS2_ESCAPE_PREVENTION; + gDisableStructs[battler].battlerPreventingEscape = gBattlerAttacker; gBattlescriptCurrInstr = cmd->nextInstr; } return; @@ -10607,16 +10500,16 @@ static void Cmd_various(void) case VARIOUS_CHECK_POLTERGEIST: { VARIOUS_ARGS(const u8 *failInstr); - if (gBattleMons[gActiveBattler].item == ITEM_NONE + if (gBattleMons[battler].item == ITEM_NONE || gFieldStatuses & STATUS_FIELD_MAGIC_ROOM - || GetBattlerAbility(gActiveBattler) == ABILITY_KLUTZ) + || GetBattlerAbility(battler) == ABILITY_KLUTZ) { gBattlescriptCurrInstr = cmd->failInstr; } else { - PREPARE_ITEM_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].item); - gLastUsedItem = gBattleMons[gActiveBattler].item; + PREPARE_ITEM_BUFFER(gBattleTextBuff1, gBattleMons[battler].item); + gLastUsedItem = gBattleMons[battler].item; gBattlescriptCurrInstr = cmd->nextInstr; } return; @@ -10624,14 +10517,14 @@ static void Cmd_various(void) case VARIOUS_TRY_NO_RETREAT: { VARIOUS_ARGS(const u8 *failInstr); - if (gDisableStructs[gActiveBattler].noRetreat) + if (gDisableStructs[battler].noRetreat) { gBattlescriptCurrInstr = cmd->failInstr; } else { - if (!(gBattleMons[gActiveBattler].status2 & STATUS2_ESCAPE_PREVENTION)) - gDisableStructs[gActiveBattler].noRetreat = TRUE; + if (!(gBattleMons[battler].status2 & STATUS2_ESCAPE_PREVENTION)) + gDisableStructs[battler].noRetreat = TRUE; gBattlescriptCurrInstr = cmd->nextInstr; } return; @@ -10639,13 +10532,13 @@ static void Cmd_various(void) case VARIOUS_TRY_TAR_SHOT: { VARIOUS_ARGS(const u8 *failInstr); - if (gDisableStructs[gActiveBattler].tarShot) + if (gDisableStructs[battler].tarShot) { gBattlescriptCurrInstr = cmd->failInstr; } else { - gDisableStructs[gActiveBattler].tarShot = TRUE; + gDisableStructs[battler].tarShot = TRUE; gBattlescriptCurrInstr = cmd->nextInstr; } return; @@ -10654,8 +10547,8 @@ static void Cmd_various(void) { VARIOUS_ARGS(const u8 *failInstr); // Tar Shot will fail if it's already been used on the target and its speed can't be lowered further - if (!gDisableStructs[gActiveBattler].tarShot - && CompareStat(gActiveBattler, STAT_SPEED, MAX_STAT_STAGE, CMP_LESS_THAN)) + if (!gDisableStructs[battler].tarShot + && CompareStat(battler, STAT_SPEED, MAX_STAT_STAGE, CMP_LESS_THAN)) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->failInstr; @@ -10664,7 +10557,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_CANT_FLING: { VARIOUS_ARGS(const u8 *jumpInstr); - if (!CanFling(gActiveBattler)) + if (!CanFling(battler)) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10674,43 +10567,43 @@ static void Cmd_various(void) { VARIOUS_ARGS(); // Check infatuation - if (gBattleMons[gActiveBattler].status2 & STATUS2_INFATUATION) + if (gBattleMons[battler].status2 & STATUS2_INFATUATION) { - gBattleMons[gActiveBattler].status2 &= ~(STATUS2_INFATUATION); + gBattleMons[battler].status2 &= ~(STATUS2_INFATUATION); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_INFATUATION; // STRINGID_TARGETGOTOVERINFATUATION StringCopy(gBattleTextBuff1, gStatusConditionString_LoveJpn); } // Check taunt - if (gDisableStructs[gActiveBattler].tauntTimer != 0) + if (gDisableStructs[battler].tauntTimer != 0) { - gDisableStructs[gActiveBattler].tauntTimer = 0; + gDisableStructs[battler].tauntTimer = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_TAUNT; PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_TAUNT); } // Check encore - if (gDisableStructs[gActiveBattler].encoreTimer != 0) + if (gDisableStructs[battler].encoreTimer != 0) { - gDisableStructs[gActiveBattler].encoredMove = 0; - gDisableStructs[gActiveBattler].encoreTimer = 0; + gDisableStructs[battler].encoredMove = 0; + gDisableStructs[battler].encoreTimer = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_ENCORE; // STRINGID_PKMNENCOREENDED } // Check torment - if (gBattleMons[gActiveBattler].status2 & STATUS2_TORMENT) + if (gBattleMons[battler].status2 & STATUS2_TORMENT) { - gBattleMons[gActiveBattler].status2 &= ~(STATUS2_TORMENT); + gBattleMons[battler].status2 &= ~(STATUS2_TORMENT); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_TORMENT; } // Check heal block - if (gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) + if (gStatuses3[battler] & STATUS3_HEAL_BLOCK) { - gStatuses3[gActiveBattler] &= ~(STATUS3_HEAL_BLOCK); + gStatuses3[battler] &= ~(STATUS3_HEAL_BLOCK); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_HEALBLOCK; } // Check disable - if (gDisableStructs[gActiveBattler].disableTimer != 0) + if (gDisableStructs[battler].disableTimer != 0) { - gDisableStructs[gActiveBattler].disableTimer = 0; - gDisableStructs[gActiveBattler].disabledMove = 0; + gDisableStructs[battler].disableTimer = 0; + gDisableStructs[battler].disabledMove = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_DISABLE; } gBattlescriptCurrInstr = cmd->nextInstr; @@ -10719,10 +10612,10 @@ static void Cmd_various(void) case VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES: { VARIOUS_ARGS(); - gActiveBattler = gBattlerTarget; + battler = gBattlerTarget; for (i = 0; i < NUM_BATTLE_STATS; i++) - if (gBattleMons[gActiveBattler].statStages[i] < DEFAULT_STAT_STAGE) - gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE; + if (gBattleMons[battler].statStages[i] < DEFAULT_STAT_STAGE) + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; gBattlescriptCurrInstr = cmd->nextInstr; return; } @@ -10747,25 +10640,25 @@ static void Cmd_various(void) case VARIOUS_SAVE_BATTLER_ITEM: { VARIOUS_ARGS(); - gBattleResources->battleHistory->heldItems[gActiveBattler] = gBattleMons[gActiveBattler].item; + gBattleResources->battleHistory->heldItems[battler] = gBattleMons[battler].item; break; } case VARIOUS_RESTORE_BATTLER_ITEM: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].item = gBattleResources->battleHistory->heldItems[gActiveBattler]; + gBattleMons[battler].item = gBattleResources->battleHistory->heldItems[battler]; break; } case VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM: { VARIOUS_ARGS(); - gBattleMons[gActiveBattler].item = gLastUsedItem; + gBattleMons[battler].item = gLastUsedItem; break; } case VARIOUS_SET_BEAK_BLAST: { VARIOUS_ARGS(); - gProtectStructs[gActiveBattler].beakBlastCharge = TRUE; + gProtectStructs[battler].beakBlastCharge = TRUE; break; } case VARIOUS_SWAP_SIDE_STATUSES: @@ -10825,7 +10718,7 @@ static void Cmd_various(void) case VARIOUS_TEATIME_INVUL: { VARIOUS_ARGS(const u8 *jumpInstr); - if (ItemId_GetPocket(gBattleMons[gActiveBattler].item) == POCKET_BERRIES && !(gStatuses3[gBattlerTarget] & (STATUS3_SEMI_INVULNERABLE))) + if (ItemId_GetPocket(gBattleMons[battler].item) == POCKET_BERRIES && !(gStatuses3[gBattlerTarget] & (STATUS3_SEMI_INVULNERABLE))) gBattlescriptCurrInstr = cmd->nextInstr; else gBattlescriptCurrInstr = cmd->jumpInstr; @@ -10861,13 +10754,13 @@ static void Cmd_various(void) case VARIOUS_TRY_WIND_RIDER_POWER: { VARIOUS_ARGS(const u8 *failInstr); - u16 ability = GetBattlerAbility(gActiveBattler); - if (GetBattlerSide(gActiveBattler) == GetBattlerSide(gBattlerAttacker) + u16 ability = GetBattlerAbility(battler); + if (GetBattlerSide(battler) == GetBattlerSide(gBattlerAttacker) && (ability == ABILITY_WIND_RIDER || ability == ABILITY_WIND_POWER)) { gLastUsedAbility = ability; - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); - gBattlerAbility = gBattleScripting.battler = gActiveBattler; + RecordAbilityBattle(battler, gLastUsedAbility); + gBattlerAbility = gBattleScripting.battler = battler; gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -10880,20 +10773,20 @@ static void Cmd_various(void) { VARIOUS_ARGS(); gBattlescriptCurrInstr = cmd->nextInstr; - AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, battler, 0, 0, 0); return; } case VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES: { VARIOUS_ARGS(); gBattlescriptCurrInstr = cmd->nextInstr; - AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, battler, 0, 0, 0); return; } case VARIOUS_JUMP_IF_EMERGENCY_EXITED: { VARIOUS_ARGS(const u8 *jumpInstr); - if (gSpecialStatuses[gActiveBattler].emergencyExited) + if (gSpecialStatuses[battler].emergencyExited) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10903,9 +10796,9 @@ static void Cmd_various(void) { VARIOUS_ARGS(); if (gCurrentMove == MOVE_LUNAR_DANCE) - gBattleStruct->storedLunarDance |= gBitTable[gActiveBattler]; + gBattleStruct->storedLunarDance |= gBitTable[battler]; else - gBattleStruct->storedHealingWish |= gBitTable[gActiveBattler]; + gBattleStruct->storedHealingWish |= gBitTable[battler]; break; } case VARIOUS_HIT_SWITCH_TARGET_FAILED: @@ -10918,7 +10811,7 @@ static void Cmd_various(void) case VARIOUS_JUMP_IF_SHELL_TRAP: { VARIOUS_ARGS(const u8 *jumpInstr); - if (gProtectStructs[gActiveBattler].shellTrap) + if (gProtectStructs[battler].shellTrap) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -10943,7 +10836,7 @@ static void Cmd_various(void) struct Pokemon *party = GetSideParty(side); u16 hp = GetMonData(&party[gSelectedMonPartyId], MON_DATA_MAX_HP) / 2; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, gBitTable[gSelectedMonPartyId], sizeof(hp), &hp); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_HP_BATTLE, gBitTable[gSelectedMonPartyId], sizeof(hp), &hp); MarkBattlerForControllerExec(gBattlerAttacker); PREPARE_SPECIES_BUFFER(gBattleTextBuff1, GetMonData(&party[gSelectedMonPartyId], MON_DATA_SPECIES)); @@ -10963,7 +10856,7 @@ static void Cmd_various(void) // Open party menu, wait to go to next instruction. else { - BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_FAINTED_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gBattlerAttacker]); + BtlController_EmitChoosePokemon(gBattlerAttacker, BUFFER_A, PARTY_ACTION_CHOOSE_FAINTED_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gBattlerAttacker]); MarkBattlerForControllerExec(gBattlerAttacker); } return; @@ -10971,9 +10864,9 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_Z_MOVE: { VARIOUS_ARGS(); - if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_Z_MOVE))) + if ((i = ShouldDoTrainerSlide(battler, TRAINER_SLIDE_Z_MOVE))) { - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; @@ -10983,9 +10876,9 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_MEGA_EVOLUTION: { VARIOUS_ARGS(); - if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_MEGA_EVOLUTION))) + if ((i = ShouldDoTrainerSlide(battler, TRAINER_SLIDE_MEGA_EVOLUTION))) { - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; BattleScriptPush(cmd->nextInstr); gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; @@ -11113,10 +11006,9 @@ static void Cmd_tryexplosion(void) return; } - gActiveBattler = gBattlerAttacker; - gBattleMoveDamage = gBattleMons[gActiveBattler].hp; - BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMoveDamage = gBattleMons[gBattlerAttacker].hp; + BtlController_EmitHealthBarUpdate(gBattlerAttacker, BUFFER_A, INSTANT_HP_BAR_DROP); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -11127,10 +11019,9 @@ static void Cmd_setatkhptozero(void) if (gBattleControllerExecFlags) return; - gActiveBattler = gBattlerAttacker; - gBattleMons[gActiveBattler].hp = 0; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMons[gBattlerAttacker].hp = 0; + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gBattlerAttacker].hp), &gBattleMons[gBattlerAttacker].hp); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -11255,7 +11146,7 @@ static void Cmd_setreflect(void) gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].reflectTimer = 5; gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].reflectBattlerId = gBattlerAttacker; - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_ATK_SIDE) == 2) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_REFLECT_DOUBLE; else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_REFLECT_SINGLE; @@ -11341,7 +11232,7 @@ static void Cmd_trysetrest(void) CMD_ARGS(const u8 *failInstr); const u8 *failInstr = cmd->failInstr; - gActiveBattler = gBattlerTarget = gBattlerAttacker; + gBattlerTarget = gBattlerAttacker; gBattleMoveDamage = gBattleMons[gBattlerTarget].maxHP * (-1); if (gBattleMons[gBattlerTarget].hp == gBattleMons[gBattlerTarget].maxHP) @@ -11364,8 +11255,8 @@ static void Cmd_trysetrest(void) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_REST; gBattleMons[gBattlerTarget].status1 = STATUS1_SLEEP_TURN(3); - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerTarget, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); + MarkBattlerForControllerExec(gBattlerTarget); gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -11397,13 +11288,13 @@ static void Cmd_setmiracleeye(void) } } -bool8 UproarWakeUpCheck(u8 battlerId) +bool8 UproarWakeUpCheck(u8 battler) { s32 i; for (i = 0; i < gBattlersCount; i++) { - if (!(gBattleMons[i].status2 & STATUS2_UPROAR) || GetBattlerAbility(battlerId) == ABILITY_SOUNDPROOF) + if (!(gBattleMons[i].status2 & STATUS2_UPROAR) || GetBattlerAbility(battler) == ABILITY_SOUNDPROOF) continue; gBattleScripting.battler = i; @@ -11614,19 +11505,19 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr { bool32 certain = FALSE; bool32 notProtectAffected = FALSE; - u32 index; - u16 activeBattlerAbility; + u32 index, battler; + u16 battlerAbility; bool32 affectsUser = (flags & MOVE_EFFECT_AFFECTS_USER); bool32 mirrorArmored = (flags & STAT_CHANGE_MIRROR_ARMOR); if (affectsUser) - gActiveBattler = gBattlerAttacker; + battler = gBattlerAttacker; 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); @@ -11638,7 +11529,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr notProtectAffected++; flags &= ~STAT_CHANGE_NOT_PROTECT_AFFECTED; - if (activeBattlerAbility == ABILITY_CONTRARY) + if (battlerAbility == ABILITY_CONTRARY) { statValue ^= STAT_BUFF_NEGATIVE; gBattleScripting.statChanger ^= STAT_BUFF_NEGATIVE; @@ -11648,7 +11539,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr 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); } @@ -11657,22 +11548,22 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr if (statValue <= -1) // Stat decrease. { - if (gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].mistTimer + if (gSideTimers[GET_BATTLER_SIDE(battler)].mistTimer && !certain && gCurrentMove != MOVE_CURSE - && !(gActiveBattler == gBattlerTarget && GetBattlerAbility(gBattlerAttacker) == ABILITY_INFILTRATOR)) + && !(battler == gBattlerTarget && GetBattlerAbility(gBattlerAttacker) == ABILITY_INFILTRATOR)) { if (flags == STAT_CHANGE_ALLOW_PTR) { - if (gSpecialStatuses[gActiveBattler].statLowered) + if (gSpecialStatuses[battler].statLowered) { gBattlescriptCurrInstr = BS_ptr; } else { BattleScriptPush(BS_ptr); - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; gBattlescriptCurrInstr = BattleScript_MistProtected; - gSpecialStatuses[gActiveBattler].statLowered = TRUE; + gSpecialStatuses[battler].statLowered = TRUE; } } return STAT_CHANGE_DIDNT_WORK; @@ -11683,108 +11574,108 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr gBattlescriptCurrInstr = BattleScript_ButItFailed; return STAT_CHANGE_DIDNT_WORK; } - else if ((GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET - || activeBattlerAbility == ABILITY_CLEAR_BODY - || activeBattlerAbility == ABILITY_FULL_METAL_BODY - || activeBattlerAbility == ABILITY_WHITE_SMOKE) + else if ((GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET + || battlerAbility == ABILITY_CLEAR_BODY + || battlerAbility == ABILITY_FULL_METAL_BODY + || battlerAbility == ABILITY_WHITE_SMOKE) && (!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 (gSpecialStatuses[gActiveBattler].statLowered) + if (gSpecialStatuses[battler].statLowered) { gBattlescriptCurrInstr = BS_ptr; } else { BattleScriptPush(BS_ptr); - gBattleScripting.battler = gActiveBattler; - if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET) + gBattleScripting.battler = battler; + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET) { gBattlescriptCurrInstr = BattleScript_ItemNoStatLoss; } else { - gBattlerAbility = gActiveBattler; + gBattlerAbility = battler; gBattlescriptCurrInstr = BattleScript_AbilityNoStatLoss; - gLastUsedAbility = activeBattlerAbility; - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); + gLastUsedAbility = battlerAbility; + RecordAbilityBattle(battler, gLastUsedAbility); } - gSpecialStatuses[gActiveBattler].statLowered = TRUE; + gSpecialStatuses[battler].statLowered = TRUE; } } return STAT_CHANGE_DIDNT_WORK; } - else if ((index = IsFlowerVeilProtected(gActiveBattler)) && !certain) + else if ((index = IsFlowerVeilProtected(battler)) && !certain) { if (flags == STAT_CHANGE_ALLOW_PTR) { - if (gSpecialStatuses[gActiveBattler].statLowered) + if (gSpecialStatuses[battler].statLowered) { gBattlescriptCurrInstr = BS_ptr; } else { BattleScriptPush(BS_ptr); - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; gBattlerAbility = index - 1; gBattlescriptCurrInstr = BattleScript_FlowerVeilProtectsRet; gLastUsedAbility = ABILITY_FLOWER_VEIL; - gSpecialStatuses[gActiveBattler].statLowered = TRUE; + gSpecialStatuses[battler].statLowered = TRUE; } } return STAT_CHANGE_DIDNT_WORK; } else if (!certain - && ((activeBattlerAbility == ABILITY_KEEN_EYE && statId == STAT_ACC) - || (activeBattlerAbility == ABILITY_HYPER_CUTTER && statId == STAT_ATK) - || (activeBattlerAbility == ABILITY_BIG_PECKS && statId == STAT_DEF))) + && ((battlerAbility == ABILITY_KEEN_EYE && statId == STAT_ACC) + || (battlerAbility == ABILITY_HYPER_CUTTER && statId == STAT_ATK) + || (battlerAbility == ABILITY_BIG_PECKS && statId == STAT_DEF))) { if (flags == STAT_CHANGE_ALLOW_PTR) { BattleScriptPush(BS_ptr); - gBattleScripting.battler = gActiveBattler; - gBattlerAbility = gActiveBattler; + gBattleScripting.battler = battler; + gBattlerAbility = battler; gBattlescriptCurrInstr = BattleScript_AbilityNoSpecificStatLoss; - gLastUsedAbility = activeBattlerAbility; - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); + gLastUsedAbility = battlerAbility; + RecordAbilityBattle(battler, gLastUsedAbility); } 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) { SET_STATCHANGER(statId, GET_STAT_BUFF_VALUE(statValue) | STAT_BUFF_NEGATIVE, TRUE); BattleScriptPush(BS_ptr); - gBattleScripting.battler = gActiveBattler; - gBattlerAbility = gActiveBattler; + gBattleScripting.battler = battler; + gBattlerAbility = battler; gBattlescriptCurrInstr = BattleScript_MirrorArmorReflect; - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); + RecordAbilityBattle(battler, gBattleMons[battler].ability); } 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; } - 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; } else // try to decrease { statValue = -GET_STAT_BUFF_VALUE(statValue); - if (gBattleMons[gActiveBattler].statStages[statId] == 1) + if (gBattleMons[battler].statStages[statId] == 1) statValue = -1; - else if (gBattleMons[gActiveBattler].statStages[statId] == 2 && statValue < -2) + else if (gBattleMons[battler].statStages[statId] == 2 && statValue < -2) statValue = -2; gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN; index = 1; @@ -11807,23 +11698,23 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr gBattleTextBuff2[index++] = STRINGID_STATFELL >> 8; 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; } else { - gProtectStructs[gActiveBattler].statFell = TRUE; // Eject pack, lash out - gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); // B_MSG_ATTACKER_STAT_FELL or B_MSG_DEFENDER_STAT_FELL + gProtectStructs[battler].statFell = TRUE; // Eject pack, lash out + gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == battler); // B_MSG_ATTACKER_STAT_FELL or B_MSG_DEFENDER_STAT_FELL } } } else // stat increase { statValue = GET_STAT_BUFF_VALUE(statValue); - if (gBattleMons[gActiveBattler].statStages[statId] == 11) + if (gBattleMons[battler].statStages[statId] == 11) statValue = 1; - else if (gBattleMons[gActiveBattler].statStages[statId] == 10 && statValue > 2) + else if (gBattleMons[battler].statStages[statId] == 10 && statValue > 2) statValue = 2; gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN; index = 1; @@ -11846,19 +11737,19 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr gBattleTextBuff2[index++] = STRINGID_STATROSE >> 8; 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; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); - gProtectStructs[gActiveBattler].statRaised = TRUE; + gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == battler); + gProtectStructs[battler].statRaised = TRUE; // check mirror herb for (index = 0; index < gBattlersCount; index++) { - if (GetBattlerSide(index) == GetBattlerSide(gActiveBattler)) + if (GetBattlerSide(index) == GetBattlerSide(battler)) continue; // Only triggers on opposing side if (GetBattlerHoldEffect(index, TRUE) == HOLD_EFFECT_MIRROR_HERB && gBattleMons[index].statStages[statId] < MAX_STAT_STAGE) @@ -11871,11 +11762,11 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr } } - gBattleMons[gActiveBattler].statStages[statId] += statValue; - if (gBattleMons[gActiveBattler].statStages[statId] < MIN_STAT_STAGE) - gBattleMons[gActiveBattler].statStages[statId] = MIN_STAT_STAGE; - if (gBattleMons[gActiveBattler].statStages[statId] > MAX_STAT_STAGE) - gBattleMons[gActiveBattler].statStages[statId] = MAX_STAT_STAGE; + gBattleMons[battler].statStages[statId] += statValue; + if (gBattleMons[battler].statStages[statId] < MIN_STAT_STAGE) + gBattleMons[battler].statStages[statId] = MIN_STAT_STAGE; + if (gBattleMons[battler].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) gMoveResultFlags |= MOVE_RESULT_MISSED; @@ -12313,7 +12204,7 @@ static void Cmd_setlightscreen(void) gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].lightscreenTimer = 5; gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].lightscreenBattlerId = gBattlerAttacker; - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_ATK_SIDE) == 2) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_LIGHTSCREEN_DOUBLE; else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_LIGHTSCREEN_SINGLE; @@ -12536,32 +12427,33 @@ static void Cmd_tryinfatuating(void) static void Cmd_updatestatusicon(void) { CMD_ARGS(u8 battler); + u32 battler; if (gBattleControllerExecFlags) return; if (cmd->battler != BS_ATTACKER_WITH_PARTNER) { - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); - MarkBattlerForControllerExec(gActiveBattler); + battler = GetBattlerForBattleScript(cmd->battler); + BtlController_EmitStatusIconUpdate(battler, BUFFER_A, gBattleMons[battler].status1, gBattleMons[battler].status2); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } else { - gActiveBattler = gBattlerAttacker; - if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler])) + battler = gBattlerAttacker; + if (!(gAbsentBattlerFlags & gBitTable[battler])) { - BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitStatusIconUpdate(battler, BUFFER_A, gBattleMons[battler].status1, gBattleMons[battler].status2); + MarkBattlerForControllerExec(battler); } if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); - if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler])) + battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); + if (!(gAbsentBattlerFlags & gBitTable[battler])) { - BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitStatusIconUpdate(battler, BUFFER_A, gBattleMons[battler].status1, gBattleMons[battler].status2); + MarkBattlerForControllerExec(battler); } } gBattlescriptCurrInstr = cmd->nextInstr; @@ -12647,9 +12539,8 @@ static void Cmd_transformdataexecution(void) gBattleMons[gBattlerAttacker].pp[i] = 5; } - gActiveBattler = gBattlerAttacker; - BtlController_EmitResetActionMoveSelection(BUFFER_A, RESET_MOVE_SELECTION); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitResetActionMoveSelection(gBattlerAttacker, BUFFER_A, RESET_MOVE_SELECTION); + MarkBattlerForControllerExec(gBattlerAttacker); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TRANSFORMED; } } @@ -13026,7 +12917,6 @@ static void Cmd_copymovepermanently(void) gBattleMons[gBattlerAttacker].moves[gCurrMovePos] = gLastPrintedMoves[gBattlerTarget]; gBattleMons[gBattlerAttacker].pp[gCurrMovePos] = gBattleMoves[gLastPrintedMoves[gBattlerTarget]].pp; - gActiveBattler = gBattlerAttacker; for (i = 0; i < MAX_MON_MOVES; i++) { @@ -13035,8 +12925,8 @@ static void Cmd_copymovepermanently(void) } movePpData.ppBonuses = gBattleMons[gBattlerAttacker].ppBonuses; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_MOVES_PP_BATTLE, 0, sizeof(movePpData), &movePpData); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_MOVES_PP_BATTLE, 0, sizeof(movePpData), &movePpData); + MarkBattlerForControllerExec(gBattlerAttacker); PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastPrintedMoves[gBattlerTarget]) @@ -13064,11 +12954,11 @@ static bool8 IsTwoTurnsMove(u16 move) } // unused -static u8 AttacksThisTurn(u8 battlerId, u16 move) // Note: returns 1 if it's a charging turn, otherwise 2 +static u8 AttacksThisTurn(u8 battler, u16 move) // Note: returns 1 if it's a charging turn, otherwise 2 { // first argument is unused if (gBattleMoves[move].effect == EFFECT_SOLAR_BEAM - && IsBattlerWeatherAffected(battlerId, B_WEATHER_SUN)) + && IsBattlerWeatherAffected(battler, B_WEATHER_SUN)) return 2; if (gBattleMoves[move].effect == EFFECT_SKULL_BASH @@ -13206,14 +13096,13 @@ static void Cmd_tryspiteppreduce(void) PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff2, 1, ppToDeduct) gBattleMons[gBattlerTarget].pp[i] -= ppToDeduct; - gActiveBattler = gBattlerTarget; - // if (MOVE_IS_PERMANENT(gActiveBattler, i)), but backwards - if (!(gDisableStructs[gActiveBattler].mimickedMoves & gBitTable[i]) - && !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) + // if (MOVE_IS_PERMANENT(gBattlerTarget, i)), but backwards + if (!(gDisableStructs[gBattlerTarget].mimickedMoves & gBitTable[i]) + && !(gBattleMons[gBattlerTarget].status2 & STATUS2_TRANSFORMED)) { - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerTarget, BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gBattlerTarget].pp[i]), &gBattleMons[gBattlerTarget].pp[i]); + MarkBattlerForControllerExec(gBattlerTarget); } gBattlescriptCurrInstr = cmd->nextInstr; @@ -13238,6 +13127,7 @@ static void Cmd_healpartystatus(void) CMD_ARGS(); u32 zero = 0; + u32 battler; u8 toHeal = 0; if (gCurrentMove == MOVE_HEAL_BELL) @@ -13258,19 +13148,19 @@ static void Cmd_healpartystatus(void) 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 - && !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) + && !(gAbsentBattlerFlags & gBitTable[battler])) { - if (GetBattlerAbility(gActiveBattler) != ABILITY_SOUNDPROOF) + if (GetBattlerAbility(battler) != ABILITY_SOUNDPROOF) { - gBattleMons[gActiveBattler].status1 = 0; - gBattleMons[gActiveBattler].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status1 = 0; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; } else { - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); + RecordAbilityBattle(battler, gBattleMons[battler].ability); gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_PARTNER; } } @@ -13289,9 +13179,9 @@ static void Cmd_healpartystatus(void) if (gBattlerPartyIndexes[gBattlerAttacker] == i) ability = GetBattlerAbility(gBattlerAttacker); else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && gBattlerPartyIndexes[gActiveBattler] == i - && !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) - ability = GetBattlerAbility(gActiveBattler); + && gBattlerPartyIndexes[battler] == i + && !(gAbsentBattlerFlags & gBitTable[battler])) + ability = GetBattlerAbility(battler); else ability = GetAbilityBySpecies(species, abilityNum); @@ -13308,21 +13198,20 @@ static void Cmd_healpartystatus(void) gBattleMons[gBattlerAttacker].status1 = 0; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; - gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); + battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) + && !(gAbsentBattlerFlags & gBitTable[battler])) { - gBattleMons[gActiveBattler].status1 = 0; - gBattleMons[gActiveBattler].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status1 = 0; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; } } if (toHeal) { - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero); + MarkBattlerForControllerExec(gBattlerAttacker); } gBattlescriptCurrInstr = cmd->nextInstr; @@ -13998,10 +13887,9 @@ static void Cmd_trymemento(void) else { // Success, drop user's HP bar to 0 - gActiveBattler = gBattlerAttacker; - gBattleMoveDamage = gBattleMons[gActiveBattler].hp; - BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMoveDamage = gBattleMons[gBattlerAttacker].hp; + BtlController_EmitHealthBarUpdate(gBattlerAttacker, BUFFER_A, INSTANT_HP_BAR_DROP); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -14064,9 +13952,8 @@ static void Cmd_cureifburnedparalysedorpoisoned(void) { gBattleMons[gBattlerAttacker].status1 = 0; gBattlescriptCurrInstr = cmd->nextInstr; - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerAttacker].status1), &gBattleMons[gBattlerAttacker].status1); + MarkBattlerForControllerExec(gBattlerAttacker); } else { @@ -14221,12 +14108,10 @@ static void Cmd_tryswapitems(void) RecordItemEffectBattle(gBattlerAttacker, 0); RecordItemEffectBattle(gBattlerTarget, ItemId_GetHoldEffect(oldItemAtk)); - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(*newItemAtk), newItemAtk); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(*newItemAtk), newItemAtk); MarkBattlerForControllerExec(gBattlerAttacker); - gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item); + BtlController_EmitSetMonData(gBattlerTarget, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item); MarkBattlerForControllerExec(gBattlerTarget); gBattleStruct->choicedMove[gBattlerTarget] = MOVE_NONE; @@ -14487,13 +14372,13 @@ static void Cmd_tryimprison(void) } else { - u8 battlerId, sideAttacker; + u8 battler, sideAttacker; sideAttacker = GetBattlerSide(gBattlerAttacker); PressurePPLoseOnUsingImprison(gBattlerAttacker); - for (battlerId = 0; battlerId < gBattlersCount; battlerId++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (sideAttacker != GetBattlerSide(battlerId)) + if (sideAttacker != GetBattlerSide(battler)) { s32 attackerMoveId; for (attackerMoveId = 0; attackerMoveId < MAX_MON_MOVES; attackerMoveId++) @@ -14501,7 +14386,7 @@ static void Cmd_tryimprison(void) s32 i; for (i = 0; i < MAX_MON_MOVES; i++) { - if (gBattleMons[gBattlerAttacker].moves[attackerMoveId] == gBattleMons[battlerId].moves[i] + if (gBattleMons[gBattlerAttacker].moves[attackerMoveId] == gBattleMons[battler].moves[i] && gBattleMons[gBattlerAttacker].moves[attackerMoveId] != MOVE_NONE) break; } @@ -14516,7 +14401,7 @@ static void Cmd_tryimprison(void) } } } - if (battlerId == gBattlersCount) // In Generation 3 games, Imprison fails if the user doesn't share any moves with any of the foes. + if (battler == gBattlersCount) // In Generation 3 games, Imprison fails if the user doesn't share any moves with any of the foes. gBattlescriptCurrInstr = cmd->failInstr; } } @@ -14652,35 +14537,35 @@ static void Cmd_switchoutabilities(void) { CMD_ARGS(u8 battler); - gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (gBattleMons[gActiveBattler].ability == ABILITY_NEUTRALIZING_GAS) + u32 battler = GetBattlerForBattleScript(cmd->battler); + if (gBattleMons[battler].ability == ABILITY_NEUTRALIZING_GAS) { - gBattleMons[gActiveBattler].ability = ABILITY_NONE; + gBattleMons[battler].ability = ABILITY_NONE; BattleScriptPush(gBattlescriptCurrInstr); gBattlescriptCurrInstr = BattleScript_NeutralizingGasExits; } else { - switch (GetBattlerAbility(gActiveBattler)) + switch (GetBattlerAbility(battler)) { case ABILITY_NATURAL_CURE: - gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, - gBitTable[*(gBattleStruct->battlerPartyIndexes + gActiveBattler)], - sizeof(gBattleMons[gActiveBattler].status1), - &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + gBattleMons[battler].status1 = 0; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, + gBitTable[*(gBattleStruct->battlerPartyIndexes + battler)], + sizeof(gBattleMons[battler].status1), + &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); break; case ABILITY_REGENERATOR: - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 3; - gBattleMoveDamage += gBattleMons[gActiveBattler].hp; - if (gBattleMoveDamage > gBattleMons[gActiveBattler].maxHP) - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, - gBitTable[*(gBattleStruct->battlerPartyIndexes + gActiveBattler)], + gBattleMoveDamage = gBattleMons[battler].maxHP / 3; + gBattleMoveDamage += gBattleMons[battler].hp; + if (gBattleMoveDamage > gBattleMons[battler].maxHP) + gBattleMoveDamage = gBattleMons[battler].maxHP; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_HP_BATTLE, + gBitTable[*(gBattleStruct->battlerPartyIndexes + battler)], sizeof(gBattleMoveDamage), &gBattleMoveDamage); - MarkBattlerForControllerExec(gActiveBattler); + MarkBattlerForControllerExec(battler); break; } @@ -14692,9 +14577,9 @@ static void Cmd_jumpifhasnohp(void) { 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; else gBattlescriptCurrInstr = cmd->nextInstr; @@ -14985,16 +14870,15 @@ static void Cmd_tryrecycleitem(void) u16 *usedHeldItem; - gActiveBattler = gBattlerAttacker; - usedHeldItem = &gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)]; - if (*usedHeldItem != ITEM_NONE && gBattleMons[gActiveBattler].item == ITEM_NONE) + usedHeldItem = &gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gBattlerAttacker]][GetBattlerSide(gBattlerAttacker)]; + if (*usedHeldItem != ITEM_NONE && gBattleMons[gBattlerAttacker].item == ITEM_NONE) { gLastUsedItem = *usedHeldItem; *usedHeldItem = ITEM_NONE; - gBattleMons[gActiveBattler].item = gLastUsedItem; + gBattleMons[gBattlerAttacker].item = gLastUsedItem; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerAttacker].item), &gBattleMons[gBattlerAttacker].item); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -15004,9 +14888,9 @@ static void Cmd_tryrecycleitem(void) } } -bool32 CanCamouflage(u8 battlerId) +bool32 CanCamouflage(u8 battler) { - if (IS_BATTLER_OF_TYPE(battlerId, sTerrainToType[gBattleTerrain])) + if (IS_BATTLER_OF_TYPE(battler, sTerrainToType[gBattleTerrain])) return FALSE; return TRUE; } @@ -15053,19 +14937,19 @@ static void Cmd_pursuitdoubles(void) { CMD_ARGS(const u8 *failInstr); - gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); + u32 battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && !(gAbsentBattlerFlags & gBitTable[gActiveBattler]) - && gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_MOVE - && gBattleMoves[gChosenMoveByBattler[gActiveBattler]].effect == EFFECT_PURSUIT) + && !(gAbsentBattlerFlags & gBitTable[battler]) + && gChosenActionByBattler[battler] == B_ACTION_USE_MOVE + && gBattleMoves[gChosenMoveByBattler[battler]].effect == EFFECT_PURSUIT) { - gActionsByTurnOrder[gActiveBattler] = B_ACTION_TRY_FINISH; - gCurrentMove = gChosenMoveByBattler[gActiveBattler]; + gActionsByTurnOrder[battler] = B_ACTION_TRY_FINISH; + gCurrentMove = gChosenMoveByBattler[battler]; gBattlescriptCurrInstr = cmd->nextInstr; gBattleScripting.animTurn = 1; gBattleScripting.savedBattler = gBattlerAttacker; - gBattlerAttacker = gActiveBattler; + gBattlerAttacker = battler; } else { @@ -15150,19 +15034,18 @@ static void Cmd_handleballthrow(void) if (gBattleControllerExecFlags) return; - gActiveBattler = gBattlerAttacker; gBattlerTarget = GetCatchingBattler(); if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - BtlController_EmitBallThrowAnim(BUFFER_A, BALL_TRAINER_BLOCK); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitBallThrowAnim(gBattlerAttacker, BUFFER_A, BALL_TRAINER_BLOCK); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = BattleScript_TrainerBallBlock; } else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) { - BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitBallThrowAnim(gBattlerAttacker, BUFFER_A, BALL_3_SHAKES_SUCCESS); + MarkBattlerForControllerExec(gBattlerAttacker); gBattlescriptCurrInstr = BattleScript_WallyBallThrow; } else @@ -15372,8 +15255,8 @@ static void Cmd_handleballthrow(void) if (odds > 254) // mon caught { - BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitBallThrowAnim(gBattlerAttacker, BUFFER_A, BALL_3_SHAKES_SUCCESS); + MarkBattlerForControllerExec(gBattlerAttacker); TryBattleFormChange(gBattlerTarget, FORM_CHANGE_END_BATTLE); gBattlescriptCurrInstr = BattleScript_SuccessBallThrow; SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem); @@ -15420,8 +15303,8 @@ static void Cmd_handleballthrow(void) for (shakes = 0; shakes < maxShakes && Random() < odds; shakes++); } - BtlController_EmitBallThrowAnim(BUFFER_A, shakes); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitBallThrowAnim(gBattlerAttacker, BUFFER_A, shakes); + MarkBattlerForControllerExec(gBattlerAttacker); if (shakes == maxShakes) // mon caught, copy of the code above { @@ -15743,9 +15626,9 @@ static void Cmd_trainerslideout(void) { CMD_ARGS(u8 position); - gActiveBattler = GetBattlerAtPosition(cmd->position); - BtlController_EmitTrainerSlideBack(BUFFER_A); - MarkBattlerForControllerExec(gActiveBattler); + u32 battler = GetBattlerAtPosition(cmd->position); + BtlController_EmitTrainerSlideBack(battler, BUFFER_A); + MarkBattlerForControllerExec(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -16011,7 +15894,7 @@ static const u16 sParentalBondBannedEffects[] = EFFECT_UPROAR, }; -bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId) +bool8 IsMoveAffectedByParentalBond(u16 move, u8 battler) { if (move != MOVE_NONE && move != MOVE_STRUGGLE && gBattleMoves[move].split != SPLIT_STATUS @@ -16026,16 +15909,16 @@ bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - switch (GetBattlerMoveTargetType(battlerId, move)) + switch (GetBattlerMoveTargetType(battler, move)) { // Both foes are alive, spread move strikes once case MOVE_TARGET_BOTH: - if (CountAliveMonsInBattle(BATTLE_ALIVE_DEF_SIDE) >= 2) + if (CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerTarget) >= 2) return FALSE; break; // Either both foes or one foe and its ally are alive; spread move strikes once case MOVE_TARGET_FOES_AND_ALLY: - if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ATTACKER) >= 2) + if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_BATTLER, gBattlerAttacker) >= 2) return FALSE; break; default: @@ -16094,13 +15977,12 @@ void BS_TrySymbiosis(void) { NATIVE_ARGS(); //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem. - gActiveBattler = gBattlerAttacker; - if (SYMBIOSIS_CHECK(gBattlerAttacker, BATTLE_PARTNER(gActiveBattler))) + u32 partner = BATTLE_PARTNER(gBattlerAttacker); + if (SYMBIOSIS_CHECK(gBattlerAttacker, partner)) { - BestowItem(BATTLE_PARTNER(gActiveBattler), gActiveBattler); - gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability; - gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler); - gBattlerAttacker = gActiveBattler; + BestowItem(partner, gBattlerAttacker); + gLastUsedAbility = gBattleMons[partner].ability; + gBattleScripting.battler = gBattlerAbility = partner; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; return; @@ -16161,19 +16043,19 @@ static void TryUpdateRoundTurnOrder(void) } } -u8 GetFirstFaintedPartyIndex(u8 battlerId) +u8 GetFirstFaintedPartyIndex(u8 battler) { u32 i; u32 start = 0; u32 end = PARTY_SIZE; - struct Pokemon *party = GetBattlerParty(battlerId); + struct Pokemon *party = GetBattlerParty(battler); // Check whether partner is separate trainer. - if ((GetBattlerSide(battlerId) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) - || (GetBattlerSide(battlerId) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)) + if ((GetBattlerSide(battler) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + || (GetBattlerSide(battler) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)) { - if (GetBattlerPosition(battlerId) == B_POSITION_OPPONENT_LEFT - || GetBattlerPosition(battlerId) == B_POSITION_PLAYER_LEFT) + if (GetBattlerPosition(battler) == B_POSITION_OPPONENT_LEFT + || GetBattlerPosition(battler) == B_POSITION_PLAYER_LEFT) { end = PARTY_SIZE / 2; } @@ -16203,7 +16085,7 @@ void BS_ItemRestoreHP(void) { NATIVE_ARGS(); u16 healAmount; - u32 battlerId = MAX_BATTLERS_COUNT; + u32 battler = MAX_BATTLERS_COUNT; u32 healParam = GetItemEffect(gLastUsedItem)[6]; u32 side = GetBattlerSide(gBattlerAttacker); struct Pokemon *party = GetSideParty(side); @@ -16217,10 +16099,10 @@ void BS_ItemRestoreHP(void) // Check if the recipient is an active battler. if (gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[gBattlerAttacker]) - battlerId = gBattlerAttacker; + battler = gBattlerAttacker; else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerAttacker)]) - battlerId = BATTLE_PARTNER(gBattlerAttacker); + battler = BATTLE_PARTNER(gBattlerAttacker); // Get amount to heal. switch (healParam) @@ -16242,7 +16124,7 @@ void BS_ItemRestoreHP(void) healAmount = maxHP - hp; // Heal is applied as move damage if battler is active. - if (battlerId != MAX_BATTLERS_COUNT && hp != 0) + if (battler != MAX_BATTLERS_COUNT && hp != 0) { gBattleMoveDamage = -healAmount; } @@ -16252,10 +16134,10 @@ void BS_ItemRestoreHP(void) SetMonData(&party[gBattleStruct->itemPartyIndex[gBattlerAttacker]], MON_DATA_HP, &hp); // Revived battlers on the field need to be brought back. - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && battlerId != MAX_BATTLERS_COUNT) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && battler != MAX_BATTLERS_COUNT) { - gAbsentBattlerFlags &= ~gBitTable[battlerId]; - gBattleScripting.battler = battlerId; + gAbsentBattlerFlags &= ~gBitTable[battler]; + gBattleScripting.battler = battler; gBattleCommunication[MULTIUSE_STATE] = TRUE; } } @@ -16306,7 +16188,7 @@ void BS_ItemRestorePP(void) NATIVE_ARGS(); const u8 *effect = GetItemEffect(gLastUsedItem); u32 i, pp, maxPP, moveId, loopEnd; - u32 battlerId = MAX_BATTLERS_COUNT; + u32 battler = MAX_BATTLERS_COUNT; struct Pokemon *mon = (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) ? &gPlayerParty[gBattleStruct->itemPartyIndex[gBattlerAttacker]] : &gEnemyParty[gBattleStruct->itemPartyIndex[gBattlerAttacker]]; // Check whether to apply to all moves. @@ -16323,10 +16205,10 @@ void BS_ItemRestorePP(void) // Check if the recipient is an active battler. if (gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[gBattlerAttacker]) - battlerId = gBattlerAttacker; + battler = gBattlerAttacker; else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerAttacker)]) - battlerId = BATTLE_PARTNER(gBattlerAttacker); + battler = BATTLE_PARTNER(gBattlerAttacker); // Heal PP! for (; i < loopEnd; i++) @@ -16342,11 +16224,11 @@ void BS_ItemRestorePP(void) SetMonData(mon, MON_DATA_PP1 + i, &pp); // Update battler PP if needed. - if (battlerId != MAX_BATTLERS_COUNT - && gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[battlerId] - && MOVE_IS_PERMANENT(battlerId, i)) + if (battler != MAX_BATTLERS_COUNT + && gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[battler] + && MOVE_IS_PERMANENT(battler, i)) { - gBattleMons[battlerId].pp[i] = pp; + gBattleMons[battler].pp[i] = pp; } } } diff --git a/src/battle_util.c b/src/battle_util.c index cd186f6d3..6f28cf3cd 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -58,13 +58,13 @@ functions instead of at the top of the file with the other declarations. */ static bool32 TryRemoveScreens(u8 battler); -static bool32 IsUnnerveAbilityOnOpposingSide(u8 battlerId); +static bool32 IsUnnerveAbilityOnOpposingSide(u8 battler); static u8 GetFlingPowerFromItemId(u16 itemId); static void SetRandomMultiHitCounter(); -static u32 GetBattlerItemHoldEffectParam(u8 battlerId, u16 item); +static u32 GetBattlerItemHoldEffectParam(u8 battler, u16 item); static uq4_12_t GetInverseTypeMultiplier(uq4_12_t multiplier); -static uq4_12_t GetSupremeOverlordModifier(u8 battlerId); -static bool8 CanBeInfinitelyConfused(u8 battlerId); +static uq4_12_t GetSupremeOverlordModifier(u8 battler); +static bool8 CanBeInfinitelyConfused(u8 battler); extern const u8 *const gBattleScriptsForMoveEffects[]; extern const u8 *const gBattlescriptsForRunningByItem[]; @@ -257,7 +257,7 @@ bool32 IsAffectedByFollowMe(u32 battlerAtk, u32 defSide, u32 move) // Functions void HandleAction_UseMove(void) { - u32 i, side, moveType, var = 4; + u32 battler, i, side, moveType, var = 4; u16 moveTarget; gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; @@ -352,18 +352,18 @@ void HandleAction_UseMove(void) || (GetBattlerAbility(*(gBattleStruct->moveTarget + gBattlerAttacker)) != ABILITY_STORM_DRAIN && moveType == TYPE_WATER))) { side = GetBattlerSide(gBattlerAttacker); - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (battler = 0; battler < gBattlersCount; battler++) { - if (side != GetBattlerSide(gActiveBattler) - && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler - && ((GetBattlerAbility(gActiveBattler) == ABILITY_LIGHTNING_ROD && moveType == TYPE_ELECTRIC) - || (GetBattlerAbility(gActiveBattler) == ABILITY_STORM_DRAIN && moveType == TYPE_WATER)) - && GetBattlerTurnOrderNum(gActiveBattler) < var + if (side != GetBattlerSide(battler) + && *(gBattleStruct->moveTarget + gBattlerAttacker) != battler + && ((GetBattlerAbility(battler) == ABILITY_LIGHTNING_ROD && moveType == TYPE_ELECTRIC) + || (GetBattlerAbility(battler) == ABILITY_STORM_DRAIN && moveType == TYPE_WATER)) + && GetBattlerTurnOrderNum(battler) < var && gBattleMoves[gCurrentMove].effect != EFFECT_SNIPE_SHOT && (GetBattlerAbility(gBattlerAttacker) != ABILITY_PROPELLER_TAIL || GetBattlerAbility(gBattlerAttacker) != ABILITY_STALWART)) { - var = GetBattlerTurnOrderNum(gActiveBattler); + var = GetBattlerTurnOrderNum(battler); } } if (var == 4) @@ -417,15 +417,15 @@ void HandleAction_UseMove(void) else { u16 battlerAbility; - gActiveBattler = gBattlerByTurnOrder[var]; - battlerAbility = GetBattlerAbility(gActiveBattler); + battler = gBattlerByTurnOrder[var]; + battlerAbility = GetBattlerAbility(battler); - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); + RecordAbilityBattle(battler, gBattleMons[battler].ability); if (battlerAbility == ABILITY_LIGHTNING_ROD && gCurrentMove != MOVE_TEATIME) - gSpecialStatuses[gActiveBattler].lightningRodRedirected = TRUE; + gSpecialStatuses[battler].lightningRodRedirected = TRUE; else if (battlerAbility == ABILITY_STORM_DRAIN) - gSpecialStatuses[gActiveBattler].stormDrainRedirected = TRUE; - gBattlerTarget = gActiveBattler; + gSpecialStatuses[battler].stormDrainRedirected = TRUE; + gBattlerTarget = battler; } } else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE @@ -547,7 +547,7 @@ void HandleAction_Switch(void) void HandleAction_UseItem(void) { - gActiveBattler = gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); @@ -646,22 +646,23 @@ bool8 TryRunFromBattle(u8 battler) void HandleAction_Run(void) { - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + s32 i; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK)) { gCurrentTurnActionNumber = gBattlersCount; - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + for (i = 0; i < gBattlersCount; i++) { - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + if (GetBattlerSide(i) == B_SIDE_PLAYER) { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + if (gChosenActionByBattler[i] == B_ACTION_RUN) gBattleOutcome |= B_OUTCOME_LOST; } else { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + if (gChosenActionByBattler[i] == B_ACTION_RUN) gBattleOutcome |= B_OUTCOME_WON; } } @@ -849,7 +850,6 @@ void HandleAction_ActionFinished(void) gLastHitByType[gBattlerAttacker] = 0; gBattleStruct->dynamicMoveType = 0; gBattleScripting.moveendState = 0; - gBattleScripting.moveendState = 0; gBattleCommunication[3] = 0; gBattleCommunication[4] = 0; gBattleScripting.multihitMoveEffect = 0; @@ -1232,9 +1232,8 @@ void PressurePPLose(u8 target, u8 attacker, u16 move) if (MOVE_IS_PERMANENT(attacker, moveIndex)) { - gActiveBattler = attacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(attacker, BUFFER_A, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[attacker].pp[moveIndex]); + MarkBattlerForControllerExec(attacker); } } @@ -1264,9 +1263,8 @@ void PressurePPLoseOnUsingImprison(u8 attacker) if (imprisonPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, imprisonPos)) { - gActiveBattler = attacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(attacker, BUFFER_A, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[attacker].pp[imprisonPos]); + MarkBattlerForControllerExec(attacker); } } @@ -1295,9 +1293,8 @@ void PressurePPLoseOnUsingPerishSong(u8 attacker) if (perishSongPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, perishSongPos)) { - gActiveBattler = attacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBattler].pp[perishSongPos]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(attacker, BUFFER_A, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[attacker].pp[perishSongPos]); + MarkBattlerForControllerExec(attacker); } } @@ -1318,30 +1315,30 @@ static void MarkAllBattlersForControllerExec(void) } } -bool32 IsBattlerMarkedForControllerExec(u8 battlerId) +bool32 IsBattlerMarkedForControllerExec(u8 battler) { if (gBattleTypeFlags & BATTLE_TYPE_LINK) - return (gBattleControllerExecFlags & (gBitTable[battlerId] << 0x1C)) != 0; + return (gBattleControllerExecFlags & (gBitTable[battler] << 0x1C)) != 0; else - return (gBattleControllerExecFlags & (gBitTable[battlerId])) != 0; + return (gBattleControllerExecFlags & (gBitTable[battler])) != 0; } -void MarkBattlerForControllerExec(u8 battlerId) +void MarkBattlerForControllerExec(u8 battler) { if (gBattleTypeFlags & BATTLE_TYPE_LINK) - gBattleControllerExecFlags |= gBitTable[battlerId] << (32 - MAX_BATTLERS_COUNT); + gBattleControllerExecFlags |= gBitTable[battler] << (32 - MAX_BATTLERS_COUNT); else - gBattleControllerExecFlags |= gBitTable[battlerId]; + gBattleControllerExecFlags |= gBitTable[battler]; } -void MarkBattlerReceivedLinkData(u8 battlerId) +void MarkBattlerReceivedLinkData(u8 battler) { s32 i; for (i = 0; i < GetLinkPlayerCount(); i++) - gBattleControllerExecFlags |= gBitTable[battlerId] << (i << 2); + gBattleControllerExecFlags |= gBitTable[battler] << (i << 2); - gBattleControllerExecFlags &= ~((1 << 28) << battlerId); + gBattleControllerExecFlags &= ~((1 << 28) << battler); } void CancelMultiTurnMoves(u8 battler) @@ -1496,9 +1493,8 @@ void PrepareStringBattle(u16 stringId, u8 battler) && gBattleStruct->trainerSlidePlayerMonUnaffectedMsgState != 2) gBattleStruct->trainerSlidePlayerMonUnaffectedMsgState = 1; - gActiveBattler = battler; - BtlController_EmitPrintString(BUFFER_A, stringId); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitPrintString(battler, BUFFER_A, stringId); + MarkBattlerForControllerExec(battler); } void ResetSentPokesToOpponentValue(void) @@ -1609,86 +1605,86 @@ static bool32 IsBelchPreventingMove(u32 battler, u32 move) return !(gBattleStruct->ateBerry[battler & BIT_SIDE] & gBitTable[gBattlerPartyIndexes[battler]]); } -u8 TrySetCantSelectMoveBattleScript(void) +u32 TrySetCantSelectMoveBattleScript(u32 battler) { u32 limitations = 0; - u8 moveId = gBattleResources->bufferB[gActiveBattler][2] & ~(RET_MEGA_EVOLUTION | RET_ULTRA_BURST); - u32 move = gBattleMons[gActiveBattler].moves[moveId]; - u32 holdEffect = GetBattlerHoldEffect(gActiveBattler, TRUE); - u16 *choicedMove = &gBattleStruct->choicedMove[gActiveBattler]; + u8 moveId = gBattleResources->bufferB[battler][2] & ~(RET_MEGA_EVOLUTION | RET_ULTRA_BURST); + u32 move = gBattleMons[battler].moves[moveId]; + u32 holdEffect = GetBattlerHoldEffect(battler, TRUE); + u16 *choicedMove = &gBattleStruct->choicedMove[battler]; - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[gActiveBattler].disabledMove == move && move != MOVE_NONE) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[battler].disabledMove == move && move != MOVE_NONE) { - gBattleScripting.battler = gActiveBattler; + gBattleScripting.battler = battler; gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingDisabledMoveInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingDisabledMoveInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingDisabledMove; + gSelectionBattleScripts[battler] = BattleScript_SelectingDisabledMove; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && move == gLastMoves[gActiveBattler] && move != MOVE_STRUGGLE && (gBattleMons[gActiveBattler].status2 & STATUS2_TORMENT)) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && move == gLastMoves[battler] && move != MOVE_STRUGGLE && (gBattleMons[battler].status2 & STATUS2_TORMENT)) { - CancelMultiTurnMoves(gActiveBattler); + CancelMultiTurnMoves(battler); if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingTormentedMoveInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingTormentedMoveInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingTormentedMove; + gSelectionBattleScripts[battler] = BattleScript_SelectingTormentedMove; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[gActiveBattler].tauntTimer != 0 && IS_MOVE_STATUS(move)) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[battler].tauntTimer != 0 && IS_MOVE_STATUS(move)) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveTauntInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveTauntInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveTaunt; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveTaunt; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[gActiveBattler].throatChopTimer != 0 && gBattleMoves[move].soundMove) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && gDisableStructs[battler].throatChopTimer != 0 && gBattleMoves[move].soundMove) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveThroatChopInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveThroatChopInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveThroatChop; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveThroatChop; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && GetImprisonedMovesCount(gActiveBattler, move)) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && GetImprisonedMovesCount(battler, move)) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisonedMoveInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingImprisonedMoveInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisonedMove; + gSelectionBattleScripts[battler] = BattleScript_SelectingImprisonedMove; limitations++; } } @@ -1698,118 +1694,118 @@ u8 TrySetCantSelectMoveBattleScript(void) gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveGravityInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveGravityInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveGravity; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveGravity; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && IsHealBlockPreventingMove(gActiveBattler, move)) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && IsHealBlockPreventingMove(battler, move)) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveHealBlockInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveHealBlockInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveHealBlock; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveHealBlock; limitations++; } } - if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && IsBelchPreventingMove(gActiveBattler, move)) + if (gBattleStruct->zmove.toBeUsed[gBattlerAttacker] == MOVE_NONE && IsBelchPreventingMove(battler, move)) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedBelchInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedBelchInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedBelch; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedBelch; limitations++; } } - if (move == MOVE_STUFF_CHEEKS && ItemId_GetPocket(gBattleMons[gActiveBattler].item) != POCKET_BERRIES) + if (move == MOVE_STUFF_CHEEKS && ItemId_GetPocket(gBattleMons[battler].item) != POCKET_BERRIES) { gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedStuffCheeksInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedStuffCheeksInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedStuffCheeks; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedStuffCheeks; limitations++; } } - gPotentialItemEffectBattler = gActiveBattler; + gPotentialItemEffectBattler = battler; if (HOLD_EFFECT_CHOICE(holdEffect) && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != move) { gCurrentMove = *choicedMove; - gLastUsedItem = gBattleMons[gActiveBattler].item; + gLastUsedItem = gBattleMons[battler].item; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveChoiceItemInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveChoiceItemInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveChoiceItem; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveChoiceItem; limitations++; } } else if (holdEffect == HOLD_EFFECT_ASSAULT_VEST && IS_MOVE_STATUS(move) && move != MOVE_ME_FIRST) { gCurrentMove = move; - gLastUsedItem = gBattleMons[gActiveBattler].item; + gLastUsedItem = gBattleMons[battler].item; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveAssaultVestInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveAssaultVestInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveAssaultVest; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveAssaultVest; limitations++; } } - if ((GetBattlerAbility(gActiveBattler) == ABILITY_GORILLA_TACTICS) && *choicedMove != MOVE_NONE + if ((GetBattlerAbility(battler) == ABILITY_GORILLA_TACTICS) && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != move) { gCurrentMove = *choicedMove; - gLastUsedItem = gBattleMons[gActiveBattler].item; + gLastUsedItem = gBattleMons[battler].item; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveGorillaTacticsInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveGorillaTacticsInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveGorillaTactics; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedMoveGorillaTactics; limitations++; } } - if (gBattleMons[gActiveBattler].pp[moveId] == 0) + if (gBattleMons[battler].pp[moveId] == 0) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingMoveWithNoPP; + gSelectionBattleScripts[battler] = BattleScript_SelectingMoveWithNoPP; limitations++; } } @@ -1818,12 +1814,12 @@ u8 TrySetCantSelectMoveBattleScript(void) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedPlaceholderInPalace; - gProtectStructs[gActiveBattler].palaceUnableToUseMove = TRUE; + gPalaceSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedPlaceholderInPalace; + gProtectStructs[battler].palaceUnableToUseMove = TRUE; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedPlaceholder; + gSelectionBattleScripts[battler] = BattleScript_SelectingNotAllowedPlaceholder; limitations++; } } @@ -1831,90 +1827,91 @@ u8 TrySetCantSelectMoveBattleScript(void) return limitations; } -u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u16 check) +u8 CheckMoveLimitations(u8 battler, u8 unusableMoves, u16 check) { - u8 holdEffect = GetBattlerHoldEffect(battlerId, TRUE); - u16 *choicedMove = &gBattleStruct->choicedMove[battlerId]; + u8 holdEffect = GetBattlerHoldEffect(battler, TRUE); + u16 *choicedMove = &gBattleStruct->choicedMove[battler]; s32 i; - gPotentialItemEffectBattler = battlerId; + gPotentialItemEffectBattler = battler; for (i = 0; i < MAX_MON_MOVES; i++) { // No move - if (check & MOVE_LIMITATION_ZEROMOVE && gBattleMons[battlerId].moves[i] == MOVE_NONE) + if (check & MOVE_LIMITATION_ZEROMOVE && gBattleMons[battler].moves[i] == MOVE_NONE) unusableMoves |= gBitTable[i]; // No PP - else if (check & MOVE_LIMITATION_PP && gBattleMons[battlerId].pp[i] == 0) + else if (check & MOVE_LIMITATION_PP && gBattleMons[battler].pp[i] == 0) unusableMoves |= gBitTable[i]; // Placeholder - else if (check & MOVE_LIMITATION_PLACEHOLDER && gBattleMoves[gBattleMons[battlerId].moves[i]].effect == EFFECT_PLACEHOLDER) + else if (check & MOVE_LIMITATION_PLACEHOLDER && gBattleMoves[gBattleMons[battler].moves[i]].effect == EFFECT_PLACEHOLDER) unusableMoves |= gBitTable[i]; // Disable - else if (check & MOVE_LIMITATION_DISABLED && gBattleMons[battlerId].moves[i] == gDisableStructs[battlerId].disabledMove) + else if (check & MOVE_LIMITATION_DISABLED && gBattleMons[battler].moves[i] == gDisableStructs[battler].disabledMove) unusableMoves |= gBitTable[i]; // Torment - else if (check & MOVE_LIMITATION_TORMENTED && gBattleMons[battlerId].moves[i] == gLastMoves[battlerId] && gBattleMons[battlerId].status2 & STATUS2_TORMENT) + else if (check & MOVE_LIMITATION_TORMENTED && gBattleMons[battler].moves[i] == gLastMoves[battler] && gBattleMons[battler].status2 & STATUS2_TORMENT) unusableMoves |= gBitTable[i]; // Taunt - else if (check & MOVE_LIMITATION_TAUNT && gDisableStructs[battlerId].tauntTimer && IS_MOVE_STATUS(gBattleMons[battlerId].moves[i])) + else if (check & MOVE_LIMITATION_TAUNT && gDisableStructs[battler].tauntTimer && IS_MOVE_STATUS(gBattleMons[battler].moves[i])) unusableMoves |= gBitTable[i]; // Imprison - else if (check & MOVE_LIMITATION_IMPRISON && GetImprisonedMovesCount(battlerId, gBattleMons[battlerId].moves[i])) + else if (check & MOVE_LIMITATION_IMPRISON && GetImprisonedMovesCount(battler, gBattleMons[battler].moves[i])) unusableMoves |= gBitTable[i]; // Encore - else if (check & MOVE_LIMITATION_ENCORE && gDisableStructs[battlerId].encoreTimer && gDisableStructs[battlerId].encoredMove != gBattleMons[battlerId].moves[i]) + else if (check & MOVE_LIMITATION_ENCORE && gDisableStructs[battler].encoreTimer && gDisableStructs[battler].encoredMove != gBattleMons[battler].moves[i]) unusableMoves |= gBitTable[i]; // Choice Items - else if (check & MOVE_LIMITATION_CHOICE_ITEM && HOLD_EFFECT_CHOICE(holdEffect) && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != gBattleMons[battlerId].moves[i]) + else if (check & MOVE_LIMITATION_CHOICE_ITEM && HOLD_EFFECT_CHOICE(holdEffect) && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != gBattleMons[battler].moves[i]) unusableMoves |= gBitTable[i]; // Assault Vest - else if (check & MOVE_LIMITATION_ASSAULT_VEST && holdEffect == HOLD_EFFECT_ASSAULT_VEST && IS_MOVE_STATUS(gBattleMons[battlerId].moves[i]) && gBattleMons[battlerId].moves[i] != MOVE_ME_FIRST) + else if (check & MOVE_LIMITATION_ASSAULT_VEST && holdEffect == HOLD_EFFECT_ASSAULT_VEST && IS_MOVE_STATUS(gBattleMons[battler].moves[i]) && gBattleMons[battler].moves[i] != MOVE_ME_FIRST) unusableMoves |= gBitTable[i]; // Gravity - else if (check & MOVE_LIMITATION_GRAVITY && IsGravityPreventingMove(gBattleMons[battlerId].moves[i])) + else if (check & MOVE_LIMITATION_GRAVITY && IsGravityPreventingMove(gBattleMons[battler].moves[i])) unusableMoves |= gBitTable[i]; // Heal Block - else if (check & MOVE_LIMITATION_HEAL_BLOCK && IsHealBlockPreventingMove(battlerId, gBattleMons[battlerId].moves[i])) + else if (check & MOVE_LIMITATION_HEAL_BLOCK && IsHealBlockPreventingMove(battler, gBattleMons[battler].moves[i])) unusableMoves |= gBitTable[i]; // Belch - else if (check & MOVE_LIMITATION_BELCH && IsBelchPreventingMove(battlerId, gBattleMons[battlerId].moves[i])) + else if (check & MOVE_LIMITATION_BELCH && IsBelchPreventingMove(battler, gBattleMons[battler].moves[i])) unusableMoves |= gBitTable[i]; // Throat Chop - else if (check & MOVE_LIMITATION_THROAT_CHOP && gDisableStructs[battlerId].throatChopTimer && gBattleMoves[gBattleMons[battlerId].moves[i]].soundMove) + else if (check & MOVE_LIMITATION_THROAT_CHOP && gDisableStructs[battler].throatChopTimer && gBattleMoves[gBattleMons[battler].moves[i]].soundMove) unusableMoves |= gBitTable[i]; // Stuff Cheeks - else if (check & MOVE_LIMITATION_STUFF_CHEEKS && gBattleMons[battlerId].moves[i] == MOVE_STUFF_CHEEKS && ItemId_GetPocket(gBattleMons[battlerId].item) != POCKET_BERRIES) + else if (check & MOVE_LIMITATION_STUFF_CHEEKS && gBattleMons[battler].moves[i] == MOVE_STUFF_CHEEKS && ItemId_GetPocket(gBattleMons[battler].item) != POCKET_BERRIES) unusableMoves |= gBitTable[i]; // Gorilla Tactics - else if (check & MOVE_LIMITATION_CHOICE_ITEM && GetBattlerAbility(battlerId) == ABILITY_GORILLA_TACTICS && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != gBattleMons[battlerId].moves[i]) + else if (check & MOVE_LIMITATION_CHOICE_ITEM && GetBattlerAbility(battler) == ABILITY_GORILLA_TACTICS && *choicedMove != MOVE_NONE && *choicedMove != MOVE_UNAVAILABLE && *choicedMove != gBattleMons[battler].moves[i]) unusableMoves |= gBitTable[i]; } return unusableMoves; } -bool8 AreAllMovesUnusable(void) +#define ALL_MOVES_MASK ((1 << MAX_MON_MOVES) - 1) +bool32 AreAllMovesUnusable(u32 battler) { - u8 unusable = CheckMoveLimitations(gActiveBattler, 0, MOVE_LIMITATIONS_ALL); + u8 unusable = CheckMoveLimitations(battler, 0, MOVE_LIMITATIONS_ALL); if (unusable == ALL_MOVES_MASK) // All moves are unusable. { - gProtectStructs[gActiveBattler].noValidMoves = TRUE; - gSelectionBattleScripts[gActiveBattler] = BattleScript_NoMovesLeft; + gProtectStructs[battler].noValidMoves = TRUE; + gSelectionBattleScripts[battler] = BattleScript_NoMovesLeft; } else { - gProtectStructs[gActiveBattler].noValidMoves = FALSE; + gProtectStructs[battler].noValidMoves = FALSE; } return (unusable == ALL_MOVES_MASK); } -u8 GetImprisonedMovesCount(u8 battlerId, u16 move) +u8 GetImprisonedMovesCount(u8 battler, u16 move) { s32 i; u8 imprisonedMoves = 0; - u8 battlerSide = GetBattlerSide(battlerId); + u8 battlerSide = GetBattlerSide(battler); for (i = 0; i < gBattlersCount; i++) { @@ -1934,11 +1931,11 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) return imprisonedMoves; } -u32 GetBattlerFriendshipScore(u8 battlerId) +u32 GetBattlerFriendshipScore(u8 battler) { - u8 side = GetBattlerSide(battlerId); + u8 side = GetBattlerSide(battler); struct Pokemon *party = GetSideParty(side); - u16 species = GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); + u16 species = GetMonData(&party[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES); if (side != B_SIDE_PLAYER) return FRIENDSHIP_NONE; @@ -1950,7 +1947,7 @@ u32 GetBattlerFriendshipScore(u8 battlerId) | BATTLE_TYPE_SECRET_BASE))) return FRIENDSHIP_NONE; - return GetMonFriendshipScore(&party[gBattlerPartyIndexes[battlerId]]); + return GetMonFriendshipScore(&party[gBattlerPartyIndexes[battler]]); } static void TryToRevertMimicry(void) @@ -2058,7 +2055,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].reflectBattlerId; + gBattlerAttacker = gSideTimers[side].reflectBattlerId; if (gSideStatuses[side] & SIDE_STATUS_REFLECT) { if (--gSideTimers[side].reflectTimer == 0) @@ -2083,7 +2080,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].lightscreenBattlerId; + gBattlerAttacker = gSideTimers[side].lightscreenBattlerId; if (gSideStatuses[side] & SIDE_STATUS_LIGHTSCREEN) { if (--gSideTimers[side].lightscreenTimer == 0) @@ -2109,7 +2106,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].auroraVeilBattlerId; + gBattlerAttacker = gSideTimers[side].auroraVeilBattlerId; if (gSideStatuses[side] & SIDE_STATUS_AURORA_VEIL) { if (--gSideTimers[side].auroraVeilTimer == 0) @@ -2135,7 +2132,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].mistBattlerId; + gBattlerAttacker = gSideTimers[side].mistBattlerId; if (gSideTimers[side].mistTimer != 0 && --gSideTimers[side].mistTimer == 0) { gSideStatuses[side] &= ~SIDE_STATUS_MIST; @@ -2158,7 +2155,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].safeguardBattlerId; + gBattlerAttacker = gSideTimers[side].safeguardBattlerId; if (gSideStatuses[side] & SIDE_STATUS_SAFEGUARD) { if (--gSideTimers[side].safeguardTimer == 0) @@ -2182,7 +2179,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].luckyChantBattlerId; + gBattlerAttacker = gSideTimers[side].luckyChantBattlerId; if (gSideStatuses[side] & SIDE_STATUS_LUCKY_CHANT) { if (--gSideTimers[side].luckyChantTimer == 0) @@ -2206,7 +2203,7 @@ u8 DoFieldEndTurnEffects(void) while (gBattleStruct->turnSideTracker < 2) { side = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[side].tailwindBattlerId; + gBattlerAttacker = gSideTimers[side].tailwindBattlerId; if (gSideStatuses[side] & SIDE_STATUS_TAILWIND) { if (--gSideTimers[side].tailwindTimer == 0) @@ -2229,12 +2226,12 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_WISH: while (gBattleStruct->turnSideTracker < gBattlersCount) { - gActiveBattler = gBattlerByTurnOrder[gBattleStruct->turnSideTracker]; - if (gWishFutureKnock.wishCounter[gActiveBattler] != 0 - && --gWishFutureKnock.wishCounter[gActiveBattler] == 0 - && gBattleMons[gActiveBattler].hp != 0) + u32 battler = gBattlerByTurnOrder[gBattleStruct->turnSideTracker]; + if (gWishFutureKnock.wishCounter[battler] != 0 + && --gWishFutureKnock.wishCounter[battler] == 0 + && gBattleMons[battler].hp != 0) { - gBattlerTarget = gActiveBattler; + gBattlerTarget = battler; BattleScriptExecute(BattleScript_WishComesTrue); effect++; } @@ -2543,7 +2540,7 @@ s32 GetDrainedBigRootHp(u32 battler, s32 hp) #define MAGIC_GUARD_CHECK \ if (ability == ABILITY_MAGIC_GUARD) \ {\ - RecordAbilityBattle(gActiveBattler, ability);\ + RecordAbilityBattle(battler, ability);\ gBattleStruct->turnEffectsTracker++;\ break;\ } @@ -2551,74 +2548,74 @@ if (ability == ABILITY_MAGIC_GUARD) \ u8 DoBattlerEndTurnEffects(void) { - u32 ability, i, effect = 0; + u32 battler, ability, i, effect = 0; gHitMarker |= (HITMARKER_GRUDGE | HITMARKER_SKIP_DMG_TRACK); while (gBattleStruct->turnEffectsBattlerId < gBattlersCount && gBattleStruct->turnEffectsTracker <= ENDTURN_BATTLER_COUNT) { - gActiveBattler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->turnEffectsBattlerId]; - if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) + battler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->turnEffectsBattlerId]; + if (gAbsentBattlerFlags & gBitTable[battler]) { gBattleStruct->turnEffectsBattlerId++; continue; } - ability = GetBattlerAbility(gActiveBattler); + ability = GetBattlerAbility(battler); switch (gBattleStruct->turnEffectsTracker) { case ENDTURN_INGRAIN: // ingrain - if ((gStatuses3[gActiveBattler] & STATUS3_ROOTED) - && !BATTLER_MAX_HP(gActiveBattler) - && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) - && gBattleMons[gActiveBattler].hp != 0) + if ((gStatuses3[battler] & STATUS3_ROOTED) + && !BATTLER_MAX_HP(battler) + && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK) + && gBattleMons[battler].hp != 0) { - gBattleMoveDamage = GetDrainedBigRootHp(gActiveBattler, gBattleMons[gActiveBattler].maxHP / 16); + gBattleMoveDamage = GetDrainedBigRootHp(battler, gBattleMons[battler].maxHP / 16); BattleScriptExecute(BattleScript_IngrainTurnHeal); effect++; } gBattleStruct->turnEffectsTracker++; break; case ENDTURN_AQUA_RING: // aqua ring - if ((gStatuses3[gActiveBattler] & STATUS3_AQUA_RING) - && !BATTLER_MAX_HP(gActiveBattler) - && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) - && gBattleMons[gActiveBattler].hp != 0) + if ((gStatuses3[battler] & STATUS3_AQUA_RING) + && !BATTLER_MAX_HP(battler) + && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK) + && gBattleMons[battler].hp != 0) { - gBattleMoveDamage = GetDrainedBigRootHp(gActiveBattler, gBattleMons[gActiveBattler].maxHP / 16); + gBattleMoveDamage = GetDrainedBigRootHp(battler, gBattleMons[battler].maxHP / 16); BattleScriptExecute(BattleScript_AquaRingHeal); effect++; } gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ABILITIES: // end turn abilities - if (AbilityBattleEffects(ABILITYEFFECT_ENDTURN, gActiveBattler, 0, 0, 0)) + if (AbilityBattleEffects(ABILITYEFFECT_ENDTURN, battler, 0, 0, 0)) effect++; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ITEMS1: // item effects - if (ItemBattleEffects(ITEMEFFECT_NORMAL, gActiveBattler, FALSE)) + if (ItemBattleEffects(ITEMEFFECT_NORMAL, battler, FALSE)) effect++; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ITEMS2: // item effects again - if (ItemBattleEffects(ITEMEFFECT_NORMAL, gActiveBattler, TRUE)) + if (ItemBattleEffects(ITEMEFFECT_NORMAL, battler, TRUE)) effect++; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ORBS: - if (IsBattlerAlive(gActiveBattler) && ItemBattleEffects(ITEMEFFECT_ORBS, gActiveBattler, FALSE)) + if (IsBattlerAlive(battler) && ItemBattleEffects(ITEMEFFECT_ORBS, battler, FALSE)) effect++; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_LEECH_SEED: // leech seed - if ((gStatuses3[gActiveBattler] & STATUS3_LEECHSEED) - && gBattleMons[gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BATTLER].hp != 0 - && gBattleMons[gActiveBattler].hp != 0) + if ((gStatuses3[battler] & STATUS3_LEECHSEED) + && gBattleMons[gStatuses3[battler] & STATUS3_LEECHSEED_BATTLER].hp != 0 + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; - gBattlerTarget = gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BATTLER; // Notice gBattlerTarget is actually the HP receiver. - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattlerTarget = gStatuses3[battler] & STATUS3_LEECHSEED_BATTLER; // Notice gBattlerTarget is actually the HP receiver. + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleScripting.animArg1 = gBattlerTarget; @@ -2629,16 +2626,16 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_POISON: // poison - if ((gBattleMons[gActiveBattler].status1 & STATUS1_POISON) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status1 & STATUS1_POISON) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; if (ability == ABILITY_POISON_HEAL) { - if (!BATTLER_MAX_HP(gActiveBattler) && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK)) + if (!BATTLER_MAX_HP(battler) && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)) { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; @@ -2648,7 +2645,7 @@ u8 DoBattlerEndTurnEffects(void) } else { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; BattleScriptExecute(BattleScript_PoisonTurnDmg); @@ -2658,16 +2655,16 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_BAD_POISON: // toxic poison - if ((gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_POISON) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status1 & STATUS1_TOXIC_POISON) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; if (ability == ABILITY_POISON_HEAL) { - if (!BATTLER_MAX_HP(gActiveBattler) && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK)) + if (!BATTLER_MAX_HP(battler) && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)) { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; @@ -2677,12 +2674,12 @@ u8 DoBattlerEndTurnEffects(void) } else { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if ((gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_COUNTER) != STATUS1_TOXIC_TURN(15)) // not 16 turns - gBattleMons[gActiveBattler].status1 += STATUS1_TOXIC_TURN(1); - gBattleMoveDamage *= (gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_COUNTER) >> 8; + if ((gBattleMons[battler].status1 & STATUS1_TOXIC_COUNTER) != STATUS1_TOXIC_TURN(15)) // not 16 turns + gBattleMons[battler].status1 += STATUS1_TOXIC_TURN(1); + gBattleMoveDamage *= (gBattleMons[battler].status1 & STATUS1_TOXIC_COUNTER) >> 8; BattleScriptExecute(BattleScript_PoisonTurnDmg); effect++; } @@ -2690,19 +2687,19 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_BURN: // burn - if ((gBattleMons[gActiveBattler].status1 & STATUS1_BURN) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status1 & STATUS1_BURN) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; #if B_BURN_DAMAGE >= GEN_7 - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; #else - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; #endif if (ability == ABILITY_HEATPROOF) { if (gBattleMoveDamage > (gBattleMoveDamage / 2) + 1) // Record ability if the burn takes less damage than it normally would. - RecordAbilityBattle(gActiveBattler, ABILITY_HEATPROOF); + RecordAbilityBattle(battler, ABILITY_HEATPROOF); gBattleMoveDamage /= 2; } if (gBattleMoveDamage == 0) @@ -2713,14 +2710,14 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_FROSTBITE: // burn - if ((gBattleMons[gActiveBattler].status1 & STATUS1_FROSTBITE) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status1 & STATUS1_FROSTBITE) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; #if B_BURN_DAMAGE >= GEN_7 - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; #else - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; #endif if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; @@ -2730,15 +2727,15 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_NIGHTMARES: // spooky nightmares - if ((gBattleMons[gActiveBattler].status2 & STATUS2_NIGHTMARE) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status2 & STATUS2_NIGHTMARE) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; // R/S does not perform this sleep check, which causes the nightmare effect to // persist even after the affected Pokemon has been awakened by Shed Skin. - if (gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 4; + gBattleMoveDamage = gBattleMons[battler].maxHP / 4; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; BattleScriptExecute(BattleScript_NightmareTurnDmg); @@ -2746,17 +2743,17 @@ u8 DoBattlerEndTurnEffects(void) } else { - gBattleMons[gActiveBattler].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; } } gBattleStruct->turnEffectsTracker++; break; case ENDTURN_CURSE: // curse - if ((gBattleMons[gActiveBattler].status2 & STATUS2_CURSED) - && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status2 & STATUS2_CURSED) + && gBattleMons[battler].hp != 0) { MAGIC_GUARD_CHECK; - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 4; + gBattleMoveDamage = gBattleMons[battler].maxHP / 4; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; BattleScriptExecute(BattleScript_CurseTurnDmg); @@ -2765,25 +2762,25 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_WRAP: // wrap - if ((gBattleMons[gActiveBattler].status2 & STATUS2_WRAPPED) && gBattleMons[gActiveBattler].hp != 0) + if ((gBattleMons[battler].status2 & STATUS2_WRAPPED) && gBattleMons[battler].hp != 0) { - if (--gDisableStructs[gActiveBattler].wrapTurns != 0) // damaged by wrap + if (--gDisableStructs[battler].wrapTurns != 0) // damaged by wrap { MAGIC_GUARD_CHECK; - gBattleScripting.animArg1 = gBattleStruct->wrappedMove[gActiveBattler]; - gBattleScripting.animArg2 = gBattleStruct->wrappedMove[gActiveBattler] >> 8; - PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[gActiveBattler]); + gBattleScripting.animArg1 = gBattleStruct->wrappedMove[battler]; + gBattleScripting.animArg2 = gBattleStruct->wrappedMove[battler] >> 8; + PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[battler]); gBattlescriptCurrInstr = BattleScript_WrapTurnDmg; - if (GetBattlerHoldEffect(gBattleStruct->wrappedBy[gActiveBattler], TRUE) == HOLD_EFFECT_BINDING_BAND) + if (GetBattlerHoldEffect(gBattleStruct->wrappedBy[battler], TRUE) == HOLD_EFFECT_BINDING_BAND) #if B_BINDING_DAMAGE >= GEN_6 - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 6; + gBattleMoveDamage = gBattleMons[battler].maxHP / 6; else - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; #else - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; else - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; #endif if (gBattleMoveDamage == 0) @@ -2791,8 +2788,8 @@ u8 DoBattlerEndTurnEffects(void) } else // broke free { - gBattleMons[gActiveBattler].status2 &= ~STATUS2_WRAPPED; - PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[gActiveBattler]); + gBattleMons[battler].status2 &= ~STATUS2_WRAPPED; + PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleStruct->wrappedMove[battler]); gBattlescriptCurrInstr = BattleScript_WrapEnds; } BattleScriptExecute(gBattlescriptCurrInstr); @@ -2802,14 +2799,14 @@ u8 DoBattlerEndTurnEffects(void) break; case ENDTURN_OCTOLOCK: { - u16 battlerAbility = GetBattlerAbility(gActiveBattler); - if (gDisableStructs[gActiveBattler].octolock - && !(GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET + u16 battlerAbility = GetBattlerAbility(battler); + if (gDisableStructs[battler].octolock + && !(GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET || battlerAbility == ABILITY_CLEAR_BODY || battlerAbility == ABILITY_FULL_METAL_BODY || battlerAbility == ABILITY_WHITE_SMOKE)) { - gBattlerTarget = gActiveBattler; + gBattlerTarget = battler; BattleScriptExecute(BattleScript_OctolockEndTurn); effect++; } @@ -2817,7 +2814,7 @@ u8 DoBattlerEndTurnEffects(void) } break; case ENDTURN_UPROAR: // uproar - if (gBattleMons[gActiveBattler].status2 & STATUS2_UPROAR) + if (gBattleMons[battler].status2 & STATUS2_UPROAR) { for (gBattlerAttacker = 0; gBattlerAttacker < gBattlersCount; gBattlerAttacker++) { @@ -2828,9 +2825,8 @@ u8 DoBattlerEndTurnEffects(void) gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; gBattleCommunication[MULTISTRING_CHOOSER] = 1; BattleScriptExecute(BattleScript_MonWokeUpInUproar); - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gBattlerAttacker].status1); + MarkBattlerForControllerExec(gBattlerAttacker); break; } } @@ -2841,22 +2837,22 @@ u8 DoBattlerEndTurnEffects(void) } else { - gBattlerAttacker = gActiveBattler; - gBattleMons[gActiveBattler].status2 -= STATUS2_UPROAR_TURN(1); // uproar timer goes down - if (WasUnableToUseMove(gActiveBattler)) + gBattlerAttacker = battler; + gBattleMons[battler].status2 -= STATUS2_UPROAR_TURN(1); // uproar timer goes down + if (WasUnableToUseMove(battler)) { - CancelMultiTurnMoves(gActiveBattler); + CancelMultiTurnMoves(battler); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_ENDS; } - else if (gBattleMons[gActiveBattler].status2 & STATUS2_UPROAR) + else if (gBattleMons[battler].status2 & STATUS2_UPROAR) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_CONTINUES; - gBattleMons[gActiveBattler].status2 |= STATUS2_MULTIPLETURNS; + gBattleMons[battler].status2 |= STATUS2_MULTIPLETURNS; } else { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_ENDS; - CancelMultiTurnMoves(gActiveBattler); + CancelMultiTurnMoves(battler); } BattleScriptExecute(BattleScript_PrintUproarOverTurns); effect = 1; @@ -2867,20 +2863,20 @@ u8 DoBattlerEndTurnEffects(void) break; case ENDTURN_THRASH: // thrash // Don't decrement STATUS2_LOCK_CONFUSE if the target is held by Sky Drop - if (gBattleMons[gActiveBattler].status2 & STATUS2_LOCK_CONFUSE && !(gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED)) + if (gBattleMons[battler].status2 & STATUS2_LOCK_CONFUSE && !(gStatuses3[battler] & STATUS3_SKY_DROPPED)) { - gBattleMons[gActiveBattler].status2 -= STATUS2_LOCK_CONFUSE_TURN(1); - if (WasUnableToUseMove(gActiveBattler)) - CancelMultiTurnMoves(gActiveBattler); - else if (!(gBattleMons[gActiveBattler].status2 & STATUS2_LOCK_CONFUSE) - && (gBattleMons[gActiveBattler].status2 & STATUS2_MULTIPLETURNS)) + gBattleMons[battler].status2 -= STATUS2_LOCK_CONFUSE_TURN(1); + if (WasUnableToUseMove(battler)) + CancelMultiTurnMoves(battler); + else if (!(gBattleMons[battler].status2 & STATUS2_LOCK_CONFUSE) + && (gBattleMons[battler].status2 & STATUS2_MULTIPLETURNS)) { - gBattleMons[gActiveBattler].status2 &= ~STATUS2_MULTIPLETURNS; - if (!(gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION)) + gBattleMons[battler].status2 &= ~STATUS2_MULTIPLETURNS; + if (!(gBattleMons[battler].status2 & STATUS2_CONFUSION)) { gBattleScripting.moveEffect = MOVE_EFFECT_CONFUSION | MOVE_EFFECT_AFFECTS_USER; SetMoveEffect(TRUE, 0); - if (gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION) BattleScriptExecute(BattleScript_ThrashConfuses); effect++; } @@ -2889,25 +2885,25 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_FLINCH: // reset flinch - gBattleMons[gActiveBattler].status2 &= ~STATUS2_FLINCHED; + gBattleMons[battler].status2 &= ~STATUS2_FLINCHED; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_DISABLE: // disable - if (gDisableStructs[gActiveBattler].disableTimer != 0) + if (gDisableStructs[battler].disableTimer != 0) { for (i = 0; i < MAX_MON_MOVES; i++) { - if (gDisableStructs[gActiveBattler].disabledMove == gBattleMons[gActiveBattler].moves[i]) + if (gDisableStructs[battler].disabledMove == gBattleMons[battler].moves[i]) break; } if (i == MAX_MON_MOVES) // pokemon does not have the disabled move anymore { - gDisableStructs[gActiveBattler].disabledMove = 0; - gDisableStructs[gActiveBattler].disableTimer = 0; + gDisableStructs[battler].disabledMove = 0; + gDisableStructs[battler].disableTimer = 0; } - else if (--gDisableStructs[gActiveBattler].disableTimer == 0) // disable ends + else if (--gDisableStructs[battler].disableTimer == 0) // disable ends { - gDisableStructs[gActiveBattler].disabledMove = 0; + gDisableStructs[battler].disabledMove = 0; BattleScriptExecute(BattleScript_DisabledNoMore); effect++; } @@ -2915,18 +2911,18 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ENCORE: // encore - if (gDisableStructs[gActiveBattler].encoreTimer != 0) + if (gDisableStructs[battler].encoreTimer != 0) { - if (gBattleMons[gActiveBattler].moves[gDisableStructs[gActiveBattler].encoredMovePos] != gDisableStructs[gActiveBattler].encoredMove) // pokemon does not have the encored move anymore + if (gBattleMons[battler].moves[gDisableStructs[battler].encoredMovePos] != gDisableStructs[battler].encoredMove) // pokemon does not have the encored move anymore { - gDisableStructs[gActiveBattler].encoredMove = 0; - gDisableStructs[gActiveBattler].encoreTimer = 0; + gDisableStructs[battler].encoredMove = 0; + gDisableStructs[battler].encoreTimer = 0; } - else if (--gDisableStructs[gActiveBattler].encoreTimer == 0 - || gBattleMons[gActiveBattler].pp[gDisableStructs[gActiveBattler].encoredMovePos] == 0) + else if (--gDisableStructs[battler].encoreTimer == 0 + || gBattleMons[battler].pp[gDisableStructs[battler].encoredMovePos] == 0) { - gDisableStructs[gActiveBattler].encoredMove = 0; - gDisableStructs[gActiveBattler].encoreTimer = 0; + gDisableStructs[battler].encoredMove = 0; + gDisableStructs[battler].encoreTimer = 0; BattleScriptExecute(BattleScript_EncoredNoMore); effect++; } @@ -2934,17 +2930,17 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_LOCK_ON: // lock-on decrement - if (gStatuses3[gActiveBattler] & STATUS3_ALWAYS_HITS) - gStatuses3[gActiveBattler] -= STATUS3_ALWAYS_HITS_TURN(1); + if (gStatuses3[battler] & STATUS3_ALWAYS_HITS) + gStatuses3[battler] -= STATUS3_ALWAYS_HITS_TURN(1); gBattleStruct->turnEffectsTracker++; break; case ENDTURN_CHARGE: // charge - if (gDisableStructs[gActiveBattler].chargeTimer && --gDisableStructs[gActiveBattler].chargeTimer == 0) - gStatuses3[gActiveBattler] &= ~STATUS3_CHARGED_UP; + if (gDisableStructs[battler].chargeTimer && --gDisableStructs[battler].chargeTimer == 0) + gStatuses3[battler] &= ~STATUS3_CHARGED_UP; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_TAUNT: // taunt - if (gDisableStructs[gActiveBattler].tauntTimer && --gDisableStructs[gActiveBattler].tauntTimer == 0) + if (gDisableStructs[battler].tauntTimer && --gDisableStructs[battler].tauntTimer == 0) { BattleScriptExecute(BattleScript_BufferEndTurn); PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_TAUNT); @@ -2953,23 +2949,23 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_YAWN: // yawn - if (gStatuses3[gActiveBattler] & STATUS3_YAWN) + if (gStatuses3[battler] & STATUS3_YAWN) { - u16 battlerAbility = GetBattlerAbility(gActiveBattler); - gStatuses3[gActiveBattler] -= STATUS3_YAWN_TURN(1); - if (!(gStatuses3[gActiveBattler] & STATUS3_YAWN) && !(gBattleMons[gActiveBattler].status1 & STATUS1_ANY) + u16 battlerAbility = GetBattlerAbility(battler); + gStatuses3[battler] -= STATUS3_YAWN_TURN(1); + if (!(gStatuses3[battler] & STATUS3_YAWN) && !(gBattleMons[battler].status1 & STATUS1_ANY) && battlerAbility != ABILITY_VITAL_SPIRIT - && battlerAbility != ABILITY_INSOMNIA && !UproarWakeUpCheck(gActiveBattler) - && !IsLeafGuardProtected(gActiveBattler)) + && battlerAbility != ABILITY_INSOMNIA && !UproarWakeUpCheck(battler) + && !IsLeafGuardProtected(battler)) { - CancelMultiTurnMoves(gActiveBattler); - gEffectBattler = gActiveBattler; - if (IsBattlerTerrainAffected(gActiveBattler, STATUS_FIELD_ELECTRIC_TERRAIN)) + CancelMultiTurnMoves(battler); + gEffectBattler = battler; + if (IsBattlerTerrainAffected(battler, STATUS_FIELD_ELECTRIC_TERRAIN)) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAINPREVENTS_ELECTRIC; BattleScriptExecute(BattleScript_TerrainPreventsEnd2); } - else if (IsBattlerTerrainAffected(gActiveBattler, STATUS_FIELD_MISTY_TERRAIN)) + else if (IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAINPREVENTS_MISTY; BattleScriptExecute(BattleScript_TerrainPreventsEnd2); @@ -2977,12 +2973,12 @@ u8 DoBattlerEndTurnEffects(void) else { #if B_SLEEP_TURNS >= GEN_5 - gBattleMons[gActiveBattler].status1 |= ((Random() % 3) + 2); + gBattleMons[battler].status1 |= ((Random() % 3) + 2); #else - gBattleMons[gActiveBattler].status1 |= ((Random() % 4) + 3); + gBattleMons[battler].status1 |= ((Random() % 4) + 3); #endif - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); BattleScriptExecute(BattleScript_YawnMakesAsleep); } effect++; @@ -2991,19 +2987,19 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_LASER_FOCUS: - if (gStatuses3[gActiveBattler] & STATUS3_LASER_FOCUS) + if (gStatuses3[battler] & STATUS3_LASER_FOCUS) { - if (gDisableStructs[gActiveBattler].laserFocusTimer == 0 || --gDisableStructs[gActiveBattler].laserFocusTimer == 0) - gStatuses3[gActiveBattler] &= ~STATUS3_LASER_FOCUS; + if (gDisableStructs[battler].laserFocusTimer == 0 || --gDisableStructs[battler].laserFocusTimer == 0) + gStatuses3[battler] &= ~STATUS3_LASER_FOCUS; } gBattleStruct->turnEffectsTracker++; break; case ENDTURN_EMBARGO: - if (gStatuses3[gActiveBattler] & STATUS3_EMBARGO) + if (gStatuses3[battler] & STATUS3_EMBARGO) { - if (gDisableStructs[gActiveBattler].embargoTimer == 0 || --gDisableStructs[gActiveBattler].embargoTimer == 0) + if (gDisableStructs[battler].embargoTimer == 0 || --gDisableStructs[battler].embargoTimer == 0) { - gStatuses3[gActiveBattler] &= ~STATUS3_EMBARGO; + gStatuses3[battler] &= ~STATUS3_EMBARGO; BattleScriptExecute(BattleScript_EmbargoEndTurn); effect++; } @@ -3011,11 +3007,11 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_MAGNET_RISE: - if (gStatuses3[gActiveBattler] & STATUS3_MAGNET_RISE) + if (gStatuses3[battler] & STATUS3_MAGNET_RISE) { - if (gDisableStructs[gActiveBattler].magnetRiseTimer == 0 || --gDisableStructs[gActiveBattler].magnetRiseTimer == 0) + if (gDisableStructs[battler].magnetRiseTimer == 0 || --gDisableStructs[battler].magnetRiseTimer == 0) { - gStatuses3[gActiveBattler] &= ~STATUS3_MAGNET_RISE; + gStatuses3[battler] &= ~STATUS3_MAGNET_RISE; BattleScriptExecute(BattleScript_BufferEndTurn); PREPARE_STRING_BUFFER(gBattleTextBuff1, STRINGID_ELECTROMAGNETISM); effect++; @@ -3024,11 +3020,11 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_TELEKINESIS: - if (gStatuses3[gActiveBattler] & STATUS3_TELEKINESIS) + if (gStatuses3[battler] & STATUS3_TELEKINESIS) { - if (gDisableStructs[gActiveBattler].telekinesisTimer == 0 || --gDisableStructs[gActiveBattler].telekinesisTimer == 0) + if (gDisableStructs[battler].telekinesisTimer == 0 || --gDisableStructs[battler].telekinesisTimer == 0) { - gStatuses3[gActiveBattler] &= ~STATUS3_TELEKINESIS; + gStatuses3[battler] &= ~STATUS3_TELEKINESIS; BattleScriptExecute(BattleScript_TelekinesisEndTurn); effect++; } @@ -3036,11 +3032,11 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_HEALBLOCK: - if (gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) + if (gStatuses3[battler] & STATUS3_HEAL_BLOCK) { - if (gDisableStructs[gActiveBattler].healBlockTimer == 0 || --gDisableStructs[gActiveBattler].healBlockTimer == 0) + if (gDisableStructs[battler].healBlockTimer == 0 || --gDisableStructs[battler].healBlockTimer == 0) { - gStatuses3[gActiveBattler] &= ~STATUS3_HEAL_BLOCK; + gStatuses3[battler] &= ~STATUS3_HEAL_BLOCK; BattleScriptExecute(BattleScript_BufferEndTurn); PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_HEAL_BLOCK); effect++; @@ -3049,22 +3045,22 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ROOST: // Return flying type. - if (gBattleResources->flags->flags[gActiveBattler] & RESOURCE_FLAG_ROOST) + if (gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST) { - gBattleResources->flags->flags[gActiveBattler] &= ~RESOURCE_FLAG_ROOST; - gBattleMons[gActiveBattler].type1 = gBattleStruct->roostTypes[gActiveBattler][0]; - gBattleMons[gActiveBattler].type2 = gBattleStruct->roostTypes[gActiveBattler][1]; + gBattleResources->flags->flags[battler] &= ~RESOURCE_FLAG_ROOST; + gBattleMons[battler].type1 = gBattleStruct->roostTypes[battler][0]; + gBattleMons[battler].type2 = gBattleStruct->roostTypes[battler][1]; } gBattleStruct->turnEffectsTracker++; break; case ENDTURN_ELECTRIFY: - gStatuses4[gActiveBattler] &= ~STATUS4_ELECTRIFIED; + gStatuses4[battler] &= ~STATUS4_ELECTRIFIED; gBattleStruct->turnEffectsTracker++; case ENDTURN_POWDER: - gBattleMons[gActiveBattler].status2 &= ~STATUS2_POWDER; + gBattleMons[battler].status2 &= ~STATUS2_POWDER; gBattleStruct->turnEffectsTracker++; case ENDTURN_THROAT_CHOP: - if (gDisableStructs[gActiveBattler].throatChopTimer && --gDisableStructs[gActiveBattler].throatChopTimer == 0) + if (gDisableStructs[battler].throatChopTimer && --gDisableStructs[battler].throatChopTimer == 0) { BattleScriptExecute(BattleScript_ThroatChopEndTurn); effect++; @@ -3072,8 +3068,8 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_SLOW_START: - if (gDisableStructs[gActiveBattler].slowStartTimer - && --gDisableStructs[gActiveBattler].slowStartTimer == 0 + if (gDisableStructs[battler].slowStartTimer + && --gDisableStructs[battler].slowStartTimer == 0 && ability == ABILITY_SLOW_START) { BattleScriptExecute(BattleScript_SlowStartEnds); @@ -3082,12 +3078,12 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->turnEffectsTracker++; break; case ENDTURN_PLASMA_FISTS: - gStatuses4[gActiveBattler] &= ~STATUS4_PLASMA_FISTS; + gStatuses4[battler] &= ~STATUS4_PLASMA_FISTS; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_CUD_CHEW: - if (GetBattlerAbility(gActiveBattler) == ABILITY_CUD_CHEW && !gDisableStructs[gActiveBattler].cudChew && ItemId_GetPocket(GetUsedHeldItem(gActiveBattler)) == POCKET_BERRIES) - gDisableStructs[gActiveBattler].cudChew = TRUE; + if (GetBattlerAbility(battler) == ABILITY_CUD_CHEW && !gDisableStructs[battler].cudChew && ItemId_GetPocket(GetUsedHeldItem(battler)) == POCKET_BERRIES) + gDisableStructs[battler].cudChew = TRUE; gBattleStruct->turnEffectsTracker++; break; case ENDTURN_BATTLER_COUNT: // done @@ -3106,41 +3102,42 @@ u8 DoBattlerEndTurnEffects(void) bool8 HandleWishPerishSongOnTurnEnd(void) { - gHitMarker |= (HITMARKER_GRUDGE | HITMARKER_SKIP_DMG_TRACK); + u32 battler; + gHitMarker |= (HITMARKER_GRUDGE | HITMARKER_SKIP_DMG_TRACK); switch (gBattleStruct->wishPerishSongState) { case 0: while (gBattleStruct->wishPerishSongBattlerId < gBattlersCount) { - gActiveBattler = gBattleStruct->wishPerishSongBattlerId; - if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) + battler = gBattleStruct->wishPerishSongBattlerId; + if (gAbsentBattlerFlags & gBitTable[battler]) { gBattleStruct->wishPerishSongBattlerId++; continue; } gBattleStruct->wishPerishSongBattlerId++; - if (gWishFutureKnock.futureSightCounter[gActiveBattler] != 0 - && --gWishFutureKnock.futureSightCounter[gActiveBattler] == 0 - && gBattleMons[gActiveBattler].hp != 0) + if (gWishFutureKnock.futureSightCounter[battler] != 0 + && --gWishFutureKnock.futureSightCounter[battler] == 0 + && gBattleMons[battler].hp != 0) { - if (gWishFutureKnock.futureSightMove[gActiveBattler] == MOVE_FUTURE_SIGHT) + if (gWishFutureKnock.futureSightMove[battler] == MOVE_FUTURE_SIGHT) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_FUTURE_SIGHT; else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOOM_DESIRE; - PREPARE_MOVE_BUFFER(gBattleTextBuff1, gWishFutureKnock.futureSightMove[gActiveBattler]); + PREPARE_MOVE_BUFFER(gBattleTextBuff1, gWishFutureKnock.futureSightMove[battler]); - gBattlerTarget = gActiveBattler; - gBattlerAttacker = gWishFutureKnock.futureSightAttacker[gActiveBattler]; + gBattlerTarget = battler; + gBattlerAttacker = gWishFutureKnock.futureSightAttacker[battler]; gSpecialStatuses[gBattlerTarget].dmg = 0xFFFF; - gCurrentMove = gWishFutureKnock.futureSightMove[gActiveBattler]; - SetTypeBeforeUsingMove(gCurrentMove, gActiveBattler); + gCurrentMove = gWishFutureKnock.futureSightMove[battler]; + SetTypeBeforeUsingMove(gCurrentMove, battler); BattleScriptExecute(BattleScript_MonTookFutureAttack); - if (gWishFutureKnock.futureSightCounter[gActiveBattler] == 0 - && gWishFutureKnock.futureSightCounter[BATTLE_PARTNER(gActiveBattler)] == 0) + if (gWishFutureKnock.futureSightCounter[battler] == 0 + && gWishFutureKnock.futureSightCounter[BATTLE_PARTNER(battler)] == 0) { gSideStatuses[GET_BATTLER_SIDE(gBattlerTarget)] &= ~SIDE_STATUS_FUTUREATTACK; } @@ -3153,37 +3150,33 @@ bool8 HandleWishPerishSongOnTurnEnd(void) case 1: while (gBattleStruct->wishPerishSongBattlerId < gBattlersCount) { - gActiveBattler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->wishPerishSongBattlerId]; - if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) + battler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->wishPerishSongBattlerId]; + if (gAbsentBattlerFlags & gBitTable[battler]) { gBattleStruct->wishPerishSongBattlerId++; continue; } gBattleStruct->wishPerishSongBattlerId++; - if (gStatuses3[gActiveBattler] & STATUS3_PERISH_SONG) + if (gStatuses3[battler] & STATUS3_PERISH_SONG) { - PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff1, 1, gDisableStructs[gActiveBattler].perishSongTimer); - if (gDisableStructs[gActiveBattler].perishSongTimer == 0) + PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff1, 1, gDisableStructs[battler].perishSongTimer); + if (gDisableStructs[battler].perishSongTimer == 0) { - gStatuses3[gActiveBattler] &= ~STATUS3_PERISH_SONG; - gBattleMoveDamage = gBattleMons[gActiveBattler].hp; + gStatuses3[battler] &= ~STATUS3_PERISH_SONG; + gBattleMoveDamage = gBattleMons[battler].hp; gBattlescriptCurrInstr = BattleScript_PerishSongTakesLife; } else { - gDisableStructs[gActiveBattler].perishSongTimer--; + gDisableStructs[battler].perishSongTimer--; gBattlescriptCurrInstr = BattleScript_PerishSongCountGoesDown; } BattleScriptExecute(gBattlescriptCurrInstr); return TRUE; } } - // Hm... - { - u8 *state = &gBattleStruct->wishPerishSongState; - *state = 2; - gBattleStruct->wishPerishSongBattlerId = 0; - } + gBattleStruct->wishPerishSongState = 2; + gBattleStruct->wishPerishSongBattlerId = 0; // fall through case 2: if ((gBattleTypeFlags & BATTLE_TYPE_ARENA) @@ -3779,9 +3772,8 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType) if (effect == 2) { - gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gBattlerAttacker].status1); + MarkBattlerForControllerExec(gBattlerAttacker); } return effect; } @@ -4042,7 +4034,7 @@ static bool32 TryChangeBattleTerrain(u32 battler, u32 statusFlag, u8 *timer) static u8 ForewarnChooseMove(u32 battler) { struct Forewarn { - u8 battlerId; + u8 battler; u8 power; u16 moveId; }; @@ -4059,7 +4051,7 @@ static u8 ForewarnChooseMove(u32 battler) if (gBattleMons[i].moves[j] == MOVE_NONE) continue; data[count].moveId = gBattleMons[i].moves[j]; - data[count].battlerId = i; + data[count].battler = i; switch (gBattleMoves[data[count].moveId].effect) { case EFFECT_OHKO: @@ -4090,14 +4082,14 @@ static u8 ForewarnChooseMove(u32 battler) bestId = i; } - gBattlerTarget = data[bestId].battlerId; + gBattlerTarget = data[bestId].battler; PREPARE_MOVE_BUFFER(gBattleTextBuff1, data[bestId].moveId) RecordKnownMove(gBattlerTarget, data[bestId].moveId); Free(data); } -bool8 ChangeTypeBasedOnTerrain(u8 battlerId) +bool8 ChangeTypeBasedOnTerrain(u8 battler) { u8 battlerType; @@ -4112,17 +4104,17 @@ bool8 ChangeTypeBasedOnTerrain(u8 battlerId) else // failsafe return FALSE; - SET_BATTLER_TYPE(battlerId, battlerType); + SET_BATTLER_TYPE(battler, battlerType); PREPARE_TYPE_BUFFER(gBattleTextBuff1, battlerType); return TRUE; } // Supreme Overlord adds a damage boost for each fainted ally. // The first ally adds a x1.2 boost, and subsequent allies add an extra x0.1 boost each. -static uq4_12_t GetSupremeOverlordModifier(u8 battlerId) +static uq4_12_t GetSupremeOverlordModifier(u8 battler) { u32 i; - struct Pokemon *party = GetBattlerParty(battlerId); + struct Pokemon *party = GetBattlerParty(battler); uq4_12_t modifier = UQ_4_12(1.0); bool8 appliedFirstBoost = FALSE; @@ -4796,10 +4788,10 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move gBattleMons[battler].status1 = 0; gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; - gBattleScripting.battler = gActiveBattler = battler; + gBattleScripting.battler = battler; BattleScriptPushCursorAndCallback(BattleScript_ShedSkinActivates); - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); effect++; } break; @@ -4901,8 +4893,8 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move && gBattleResults.catchAttempts[gLastUsedBall - ITEM_ULTRA_BALL] >= 1 && !gHasFetchedBall) { - gBattleScripting.battler = gActiveBattler = battler; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, 2, &gLastUsedBall); + gBattleScripting.battler = battler; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, 2, &gLastUsedBall); MarkBattlerForControllerExec(battler); gHasFetchedBall = TRUE; gLastUsedItem = gLastUsedBall; @@ -4918,7 +4910,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITY_CUD_CHEW: - if (ItemId_GetPocket(GetUsedHeldItem(battler)) == POCKET_BERRIES && gDisableStructs[gActiveBattler].cudChew == TRUE) + if (ItemId_GetPocket(GetUsedHeldItem(battler)) == POCKET_BERRIES && gDisableStructs[battler].cudChew == TRUE) { gLastUsedItem = gBattleStruct->usedHeldItems[battler][GetBattlerSide(battler)]; gBattleStruct->usedHeldItems[battler][GetBattlerSide(battler)] = ITEM_NONE; @@ -5559,7 +5551,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } else if (TryChangeBattleWeather(battler, ENUM_WEATHER_SANDSTORM, TRUE)) { - gBattleScripting.battler = gActiveBattler = battler; + gBattleScripting.battler = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SandSpitActivates; effect++; @@ -5852,9 +5844,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move break; } - gBattleScripting.battler = gActiveBattler = gBattlerAbility = battler; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + gBattleScripting.battler = gBattlerAbility = battler; + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); return effect; } } @@ -5909,24 +5901,25 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move { if (gBattleMons[i].ability == ABILITY_TRACE && (gBattleResources->flags->flags[i] & RESOURCE_FLAG_TRACED)) { - u8 side = (BATTLE_OPPOSITE(GetBattlerPosition(i))) & BIT_SIDE; // side of the opposing pokemon - u8 target1 = GetBattlerAtPosition(side); - u8 target2 = GetBattlerAtPosition(side + BIT_FLANK); + u32 chosenTarget; + u32 side = (BATTLE_OPPOSITE(GetBattlerPosition(i))) & BIT_SIDE; // side of the opposing pokemon + u32 target1 = GetBattlerAtPosition(side); + u32 target2 = GetBattlerAtPosition(side + BIT_FLANK); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { if (!sAbilitiesNotTraced[gBattleMons[target1].ability] && gBattleMons[target1].hp != 0 && !sAbilitiesNotTraced[gBattleMons[target2].ability] && gBattleMons[target2].hp != 0) - gActiveBattler = GetBattlerAtPosition(((Random() & 1) * 2) | side), effect++; + chosenTarget = GetBattlerAtPosition(((Random() & 1) * 2) | side), effect++; else if (!sAbilitiesNotTraced[gBattleMons[target1].ability] && gBattleMons[target1].hp != 0) - gActiveBattler = target1, effect++; + chosenTarget = target1, effect++; else if (!sAbilitiesNotTraced[gBattleMons[target2].ability] && gBattleMons[target2].hp != 0) - gActiveBattler = target2, effect++; + chosenTarget = target2, effect++; } else { if (!sAbilitiesNotTraced[gBattleMons[target1].ability] && gBattleMons[target1].hp != 0) - gActiveBattler = target1, effect++; + chosenTarget = target1, effect++; } if (effect != 0) @@ -5941,11 +5934,11 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move gBattlescriptCurrInstr = BattleScript_TraceActivates; } gBattleResources->flags->flags[i] &= ~RESOURCE_FLAG_TRACED; - gBattleStruct->tracedAbility[i] = gLastUsedAbility = gBattleMons[gActiveBattler].ability; - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); // Record the opposing battler has this ability + gBattleStruct->tracedAbility[i] = gLastUsedAbility = gBattleMons[chosenTarget].ability; + RecordAbilityBattle(chosenTarget, gLastUsedAbility); // Record the opposing battler has this ability battler = gBattlerAbility = gBattleScripting.battler = i; - PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, gActiveBattler, gBattlerPartyIndexes[gActiveBattler]) + PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, chosenTarget, gBattlerPartyIndexes[chosenTarget]) PREPARE_ABILITY_BUFFER(gBattleTextBuff2, gLastUsedAbility) break; } @@ -6072,12 +6065,12 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move return effect; } -bool32 TryPrimalReversion(u8 battlerId) +bool32 TryPrimalReversion(u8 battler) { - if (GetBattlerHoldEffect(battlerId, FALSE) == HOLD_EFFECT_PRIMAL_ORB - && GetBattleFormChangeTargetSpecies(battlerId, FORM_CHANGE_BATTLE_PRIMAL_REVERSION) != SPECIES_NONE) + if (GetBattlerHoldEffect(battler, FALSE) == HOLD_EFFECT_PRIMAL_ORB + && GetBattleFormChangeTargetSpecies(battler, FORM_CHANGE_BATTLE_PRIMAL_REVERSION) != SPECIES_NONE) { - if (gBattlerAttacker == battlerId) + if (gBattlerAttacker == battler) { BattleScriptExecute(BattleScript_PrimalReversion); } @@ -6085,7 +6078,7 @@ bool32 TryPrimalReversion(u8 battlerId) { // edge case for scenarios like a switch-in after activated eject button gBattleScripting.savedBattler = gBattlerAttacker; - gBattlerAttacker = battlerId; + gBattlerAttacker = battler; BattleScriptExecute(BattleScript_PrimalReversionRestoreAttacker); } return TRUE; @@ -6142,12 +6135,12 @@ bool32 IsMyceliumMightOnField(void) return FALSE; } -u32 GetBattlerAbility(u8 battlerId) +u32 GetBattlerAbility(u8 battler) { - if (gStatuses3[battlerId] & STATUS3_GASTRO_ACID) + if (gStatuses3[battler] & STATUS3_GASTRO_ACID) return ABILITY_NONE; - if (IsNeutralizingGasOnField() && !IsNeutralizingGasBannedAbility(gBattleMons[battlerId].ability)) + if (IsNeutralizingGasOnField() && !IsNeutralizingGasBannedAbility(gBattleMons[battler].ability)) return ABILITY_NONE; if (IsMyceliumMightOnField()) @@ -6158,28 +6151,28 @@ u32 GetBattlerAbility(u8 battlerId) || gBattleMons[gBattlerAttacker].ability == ABILITY_TURBOBLAZE) && !(gStatuses3[gBattlerAttacker] & STATUS3_GASTRO_ACID)) || gBattleMoves[gCurrentMove].ignoresTargetAbility) - && sAbilitiesAffectedByMoldBreaker[gBattleMons[battlerId].ability] + && sAbilitiesAffectedByMoldBreaker[gBattleMons[battler].ability] && gBattlerByTurnOrder[gCurrentTurnActionNumber] == gBattlerAttacker && gActionsByTurnOrder[gBattlerByTurnOrder[gBattlerAttacker]] == B_ACTION_USE_MOVE && gCurrentTurnActionNumber < gBattlersCount) return ABILITY_NONE; - return gBattleMons[battlerId].ability; + return gBattleMons[battler].ability; } -u32 IsAbilityOnSide(u32 battlerId, u32 ability) +u32 IsAbilityOnSide(u32 battler, u32 ability) { - if (IsBattlerAlive(battlerId) && GetBattlerAbility(battlerId) == ability) - return battlerId + 1; - else if (IsBattlerAlive(BATTLE_PARTNER(battlerId)) && GetBattlerAbility(BATTLE_PARTNER(battlerId)) == ability) - return BATTLE_PARTNER(battlerId) + 1; + if (IsBattlerAlive(battler) && GetBattlerAbility(battler) == ability) + return battler + 1; + else if (IsBattlerAlive(BATTLE_PARTNER(battler)) && GetBattlerAbility(BATTLE_PARTNER(battler)) == ability) + return BATTLE_PARTNER(battler) + 1; else return 0; } -u32 IsAbilityOnOpposingSide(u32 battlerId, u32 ability) +u32 IsAbilityOnOpposingSide(u32 battler, u32 ability) { - return IsAbilityOnSide(BATTLE_OPPOSITE(battlerId), ability); + return IsAbilityOnSide(BATTLE_OPPOSITE(battler), ability); } u32 IsAbilityOnField(u32 ability) @@ -6195,55 +6188,55 @@ u32 IsAbilityOnField(u32 ability) return 0; } -u32 IsAbilityOnFieldExcept(u32 battlerId, u32 ability) +u32 IsAbilityOnFieldExcept(u32 battler, u32 ability) { u32 i; for (i = 0; i < gBattlersCount; i++) { - if (i != battlerId && IsBattlerAlive(i) && GetBattlerAbility(i) == ability) + if (i != battler && IsBattlerAlive(i) && GetBattlerAbility(i) == ability) return i + 1; } return 0; } -u32 IsAbilityPreventingEscape(u32 battlerId) +u32 IsAbilityPreventingEscape(u32 battler) { u32 id; #if B_GHOSTS_ESCAPE >= GEN_6 - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_GHOST)) + if (IS_BATTLER_OF_TYPE(battler, TYPE_GHOST)) return 0; #endif #if B_SHADOW_TAG_ESCAPE >= GEN_4 - if ((id = IsAbilityOnOpposingSide(battlerId, ABILITY_SHADOW_TAG)) && GetBattlerAbility(battlerId) != ABILITY_SHADOW_TAG) + if ((id = IsAbilityOnOpposingSide(battler, ABILITY_SHADOW_TAG)) && GetBattlerAbility(battler) != ABILITY_SHADOW_TAG) #else - if ((id = IsAbilityOnOpposingSide(battlerId, ABILITY_SHADOW_TAG))) + if ((id = IsAbilityOnOpposingSide(battler, ABILITY_SHADOW_TAG))) #endif return id; - if ((id = IsAbilityOnOpposingSide(battlerId, ABILITY_ARENA_TRAP)) && IsBattlerGrounded(battlerId)) + if ((id = IsAbilityOnOpposingSide(battler, ABILITY_ARENA_TRAP)) && IsBattlerGrounded(battler)) return id; - if ((id = IsAbilityOnOpposingSide(battlerId, ABILITY_MAGNET_PULL)) && IS_BATTLER_OF_TYPE(battlerId, TYPE_STEEL)) + if ((id = IsAbilityOnOpposingSide(battler, ABILITY_MAGNET_PULL)) && IS_BATTLER_OF_TYPE(battler, TYPE_STEEL)) return id; return 0; } -bool32 CanBattlerEscape(u32 battlerId) // no ability check +bool32 CanBattlerEscape(u32 battler) // no ability check { - if (GetBattlerHoldEffect(battlerId, TRUE) == HOLD_EFFECT_SHED_SHELL) + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_SHED_SHELL) return TRUE; #if B_GHOSTS_ESCAPE >= GEN_6 - else if (IS_BATTLER_OF_TYPE(battlerId, TYPE_GHOST)) + else if (IS_BATTLER_OF_TYPE(battler, TYPE_GHOST)) return TRUE; #endif - else if (gBattleMons[battlerId].status2 & (STATUS2_ESCAPE_PREVENTION | STATUS2_WRAPPED)) + else if (gBattleMons[battler].status2 & (STATUS2_ESCAPE_PREVENTION | STATUS2_WRAPPED)) return FALSE; - else if (gStatuses3[battlerId] & STATUS3_ROOTED) + else if (gStatuses3[battler] & STATUS3_ROOTED) return FALSE; else if (gFieldStatuses & STATUS_FIELD_FAIRY_LOCK) return FALSE; - else if (gStatuses3[battlerId] & STATUS3_SKY_DROPPED) + else if (gStatuses3[battler] & STATUS3_SKY_DROPPED) return FALSE; else return TRUE; @@ -6275,27 +6268,27 @@ enum ITEM_STATS_CHANGE, }; -bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag) +bool32 IsBattlerTerrainAffected(u8 battler, u32 terrainFlag) { if (!(gFieldStatuses & terrainFlag)) return FALSE; - else if (gStatuses3[battlerId] & STATUS3_SEMI_INVULNERABLE) + else if (gStatuses3[battler] & STATUS3_SEMI_INVULNERABLE) return FALSE; - return IsBattlerGrounded(battlerId); + return IsBattlerGrounded(battler); } -bool32 CanSleep(u8 battlerId) +bool32 CanSleep(u8 battler) { - u16 ability = GetBattlerAbility(battlerId); + u16 ability = GetBattlerAbility(battler); if (ability == ABILITY_INSOMNIA || ability == ABILITY_VITAL_SPIRIT || ability == ABILITY_COMATOSE - || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD - || gBattleMons[battlerId].status1 & STATUS1_ANY - || IsAbilityOnSide(battlerId, ABILITY_SWEET_VEIL) - || IsAbilityStatusProtected(battlerId) - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_MISTY_TERRAIN)) + || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD + || gBattleMons[battler].status1 & STATUS1_ANY + || IsAbilityOnSide(battler, ABILITY_SWEET_VEIL) + || IsAbilityStatusProtected(battler) + || IsBattlerTerrainAffected(battler, STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } @@ -6316,96 +6309,96 @@ bool32 CanBePoisoned(u8 battlerAttacker, u8 battlerTarget) return TRUE; } -bool32 CanBeBurned(u8 battlerId) +bool32 CanBeBurned(u8 battler) { - u16 ability = GetBattlerAbility(battlerId); - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_FIRE) - || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD - || gBattleMons[battlerId].status1 & STATUS1_ANY + u16 ability = GetBattlerAbility(battler); + if (IS_BATTLER_OF_TYPE(battler, TYPE_FIRE) + || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD + || gBattleMons[battler].status1 & STATUS1_ANY || ability == ABILITY_WATER_VEIL || ability == ABILITY_WATER_BUBBLE || ability == ABILITY_COMATOSE || ability == ABILITY_THERMAL_EXCHANGE - || IsAbilityStatusProtected(battlerId) - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN)) + || IsAbilityStatusProtected(battler) + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } -bool32 CanBeParalyzed(u8 battlerId) +bool32 CanBeParalyzed(u8 battler) { - u16 ability = GetBattlerAbility(battlerId); + u16 ability = GetBattlerAbility(battler); if ( #if B_PARALYZE_ELECTRIC >= GEN_6 - IS_BATTLER_OF_TYPE(battlerId, TYPE_ELECTRIC) || + IS_BATTLER_OF_TYPE(battler, TYPE_ELECTRIC) || #endif - gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD + gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD || ability == ABILITY_LIMBER || ability == ABILITY_COMATOSE - || gBattleMons[battlerId].status1 & STATUS1_ANY - || IsAbilityStatusProtected(battlerId) - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN)) + || gBattleMons[battler].status1 & STATUS1_ANY + || IsAbilityStatusProtected(battler) + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } -bool32 CanBeFrozen(u8 battlerId) +bool32 CanBeFrozen(u8 battler) { - u16 ability = GetBattlerAbility(battlerId); - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_ICE) - || IsBattlerWeatherAffected(battlerId, B_WEATHER_SUN) - || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD + u16 ability = GetBattlerAbility(battler); + if (IS_BATTLER_OF_TYPE(battler, TYPE_ICE) + || IsBattlerWeatherAffected(battler, B_WEATHER_SUN) + || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD || ability == ABILITY_MAGMA_ARMOR || ability == ABILITY_COMATOSE - || gBattleMons[battlerId].status1 & STATUS1_ANY - || IsAbilityStatusProtected(battlerId) - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN)) + || gBattleMons[battler].status1 & STATUS1_ANY + || IsAbilityStatusProtected(battler) + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } -bool32 CanGetFrostbite(u8 battlerId) +bool32 CanGetFrostbite(u8 battler) { - u16 ability = GetBattlerAbility(battlerId); - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_ICE) - || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD + u16 ability = GetBattlerAbility(battler); + if (IS_BATTLER_OF_TYPE(battler, TYPE_ICE) + || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD || ability == ABILITY_MAGMA_ARMOR || ability == ABILITY_COMATOSE - || gBattleMons[battlerId].status1 & STATUS1_ANY - || IsAbilityStatusProtected(battlerId) - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN)) + || gBattleMons[battler].status1 & STATUS1_ANY + || IsAbilityStatusProtected(battler) + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } -bool32 CanBeConfused(u8 battlerId) +bool32 CanBeConfused(u8 battler) { - if (GetBattlerAbility(battlerId) == ABILITY_OWN_TEMPO - || gBattleMons[battlerId].status2 & STATUS2_CONFUSION - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN)) + if (GetBattlerAbility(battler) == ABILITY_OWN_TEMPO + || gBattleMons[battler].status2 & STATUS2_CONFUSION + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } // second argument is 1/X of current hp compared to max hp -bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId) +bool32 HasEnoughHpToEatBerry(u32 battler, u32 hpFraction, u32 itemId) { bool32 isBerry = (ItemId_GetPocket(itemId) == POCKET_BERRIES); - if (gBattleMons[battlerId].hp == 0) + if (gBattleMons[battler].hp == 0) return FALSE; if (gBattleScripting.overrideBerryRequirements) return TRUE; // Unnerve prevents consumption of opponents' berries. - if (isBerry && IsUnnerveAbilityOnOpposingSide(battlerId)) + if (isBerry && IsUnnerveAbilityOnOpposingSide(battler)) return FALSE; - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / hpFraction) + if (gBattleMons[battler].hp <= gBattleMons[battler].maxHP / hpFraction) return TRUE; - if (hpFraction <= 4 && GetBattlerAbility(battlerId) == ABILITY_GLUTTONY && isBerry - && gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / 2) + if (hpFraction <= 4 && GetBattlerAbility(battler) == ABILITY_GLUTTONY && isBerry + && gBattleMons[battler].hp <= gBattleMons[battler].maxHP / 2) { - RecordAbilityBattle(battlerId, ABILITY_GLUTTONY); + RecordAbilityBattle(battler, ABILITY_GLUTTONY); return TRUE; } @@ -6418,30 +6411,30 @@ bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId) #define CONFUSE_BERRY_HP_FRACTION 2 #endif -static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) +static u8 HealConfuseBerry(u32 battler, u32 itemId, u8 flavorId, bool32 end2) { - if (HasEnoughHpToEatBerry(battlerId, CONFUSE_BERRY_HP_FRACTION, itemId) + if (HasEnoughHpToEatBerry(battler, CONFUSE_BERRY_HP_FRACTION, itemId) #if B_HEAL_BLOCKING >= GEN_5 - && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK) + && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK) #endif ) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, flavorId); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / GetBattlerItemHoldEffectParam(battlerId, itemId); + gBattleMoveDamage = gBattleMons[battler].maxHP / GetBattlerItemHoldEffectParam(battler, itemId); if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + if (GetBattlerAbility(battler) == ABILITY_RIPEN) { gBattleMoveDamage *= 2; - gBattlerAbility = battlerId; + gBattlerAbility = battler; } - gBattleScripting.battler = battlerId; + gBattleScripting.battler = battler; if (end2) { - if (GetFlavorRelationByPersonality(gBattleMons[battlerId].personality, flavorId) < 0) + if (GetFlavorRelationByPersonality(gBattleMons[battler].personality, flavorId) < 0) BattleScriptExecute(BattleScript_BerryConfuseHealEnd2); else BattleScriptExecute(BattleScript_ItemHealHP_RemoveItemEnd2); @@ -6449,7 +6442,7 @@ static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) else { BattleScriptPushCursor(); - if (GetFlavorRelationByPersonality(gBattleMons[battlerId].personality, flavorId) < 0) + if (GetFlavorRelationByPersonality(gBattleMons[battler].personality, flavorId) < 0) gBattlescriptCurrInstr = BattleScript_BerryConfuseHealRet; else gBattlescriptCurrInstr = BattleScript_ItemHealHP_RemoveItemRet; @@ -6462,13 +6455,13 @@ static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) #undef CONFUSE_BERRY_HP_FRACTION -static u8 StatRaiseBerry(u32 battlerId, u32 itemId, u32 statId, bool32 end2) +static u8 StatRaiseBerry(u32 battler, u32 itemId, u32 statId, bool32 end2) { - if (CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN) && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, itemId), itemId)) + if (CompareStat(battler, statId, MAX_STAT_STAGE, CMP_LESS_THAN) && HasEnoughHpToEatBerry(battler, GetBattlerItemHoldEffectParam(battler, itemId), itemId)) { - BufferStatChange(battlerId, statId, STRINGID_STATROSE); - gEffectBattler = battlerId; - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + BufferStatChange(battler, statId, STRINGID_STATROSE); + gEffectBattler = battler; + if (GetBattlerAbility(battler) == ABILITY_RIPEN) SET_STATCHANGER(statId, 2, FALSE); else SET_STATCHANGER(statId, 1, FALSE); @@ -6490,23 +6483,23 @@ static u8 StatRaiseBerry(u32 battlerId, u32 itemId, u32 statId, bool32 end2) return 0; } -static u8 RandomStatRaiseBerry(u32 battlerId, u32 itemId, bool32 end2) +static u8 RandomStatRaiseBerry(u32 battler, u32 itemId, bool32 end2) { s32 i; u16 stringId; for (i = 0; i < NUM_STATS - 1; i++) { - if (CompareStat(battlerId, STAT_ATK + i, MAX_STAT_STAGE, CMP_LESS_THAN)) + if (CompareStat(battler, STAT_ATK + i, MAX_STAT_STAGE, CMP_LESS_THAN)) break; } - if (i != NUM_STATS - 1 && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, itemId), itemId)) + if (i != NUM_STATS - 1 && HasEnoughHpToEatBerry(battler, GetBattlerItemHoldEffectParam(battler, itemId), itemId)) { - u16 battlerAbility = GetBattlerAbility(battlerId); + u16 battlerAbility = GetBattlerAbility(battler); do { i = Random() % (NUM_STATS - 1); - } while (!CompareStat(battlerId, STAT_ATK + i, MAX_STAT_STAGE, CMP_LESS_THAN)); + } while (!CompareStat(battler, STAT_ATK + i, MAX_STAT_STAGE, CMP_LESS_THAN)); PREPARE_STAT_BUFFER(gBattleTextBuff1, i + 1); stringId = (battlerAbility == ABILITY_CONTRARY) ? STRINGID_STATFELL : STRINGID_STATROSE; @@ -6518,7 +6511,7 @@ static u8 RandomStatRaiseBerry(u32 battlerId, u32 itemId, bool32 end2) gBattleTextBuff2[5] = stringId; gBattleTextBuff2[6] = stringId >> 8; gBattleTextBuff2[7] = EOS; - gEffectBattler = battlerId; + gEffectBattler = battler; if (battlerAbility == ABILITY_RIPEN) SET_STATCHANGER(i + 1, 4, FALSE); else @@ -6541,11 +6534,11 @@ static u8 RandomStatRaiseBerry(u32 battlerId, u32 itemId, bool32 end2) return 0; } -static u8 TrySetMicleBerry(u32 battlerId, u32 itemId, bool32 end2) +static u8 TrySetMicleBerry(u32 battler, u32 itemId, bool32 end2) { - if (HasEnoughHpToEatBerry(battlerId, 4, itemId)) + if (HasEnoughHpToEatBerry(battler, 4, itemId)) { - gProtectStructs[battlerId].usedMicleBerry = TRUE; // battler's next attack has increased accuracy + gProtectStructs[battler].usedMicleBerry = TRUE; // battler's next attack has increased accuracy if (end2) { @@ -6561,18 +6554,18 @@ static u8 TrySetMicleBerry(u32 battlerId, u32 itemId, bool32 end2) return 0; } -static u8 DamagedStatBoostBerryEffect(u8 battlerId, u8 statId, u8 split) +static u8 DamagedStatBoostBerryEffect(u8 battler, u8 statId, u8 split) { - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED - && CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN) - && !DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove) + && CompareStat(battler, statId, MAX_STAT_STAGE, CMP_LESS_THAN) + && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && GetBattleMoveSplit(gCurrentMove) == split) { - BufferStatChange(battlerId, statId, STRINGID_STATROSE); + BufferStatChange(battler, statId, STRINGID_STATROSE); - gEffectBattler = battlerId; - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + gEffectBattler = battler; + if (GetBattlerAbility(battler) == ABILITY_RIPEN) SET_STATCHANGER(statId, 2, FALSE); else SET_STATCHANGER(statId, 1, FALSE); @@ -6610,24 +6603,24 @@ u8 TryHandleSeed(u8 battler, u32 terrainFlag, u8 statId, u16 itemId, bool32 exec return 0; } -static u8 ItemHealHp(u32 battlerId, u32 itemId, bool32 end2, bool32 percentHeal) +static u8 ItemHealHp(u32 battler, u32 itemId, bool32 end2, bool32 percentHeal) { - if (!(gBattleScripting.overrideBerryRequirements && gBattleMons[battlerId].hp == gBattleMons[battlerId].maxHP) + if (!(gBattleScripting.overrideBerryRequirements && gBattleMons[battler].hp == gBattleMons[battler].maxHP) #if B_HEAL_BLOCKING >= GEN_5 - && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK) + && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK) #endif - && HasEnoughHpToEatBerry(battlerId, 2, itemId)) + && HasEnoughHpToEatBerry(battler, 2, itemId)) { if (percentHeal) - gBattleMoveDamage = (gBattleMons[battlerId].maxHP * GetBattlerItemHoldEffectParam(battlerId, itemId) / 100) * -1; + gBattleMoveDamage = (gBattleMons[battler].maxHP * GetBattlerItemHoldEffectParam(battler, itemId) / 100) * -1; else - gBattleMoveDamage = GetBattlerItemHoldEffectParam(battlerId, itemId) * -1; + gBattleMoveDamage = GetBattlerItemHoldEffectParam(battler, itemId) * -1; // check ripen - if (ItemId_GetPocket(itemId) == POCKET_BERRIES && GetBattlerAbility(battlerId) == ABILITY_RIPEN) + if (ItemId_GetPocket(itemId) == POCKET_BERRIES && GetBattlerAbility(battler) == ABILITY_RIPEN) gBattleMoveDamage *= 2; - gBattlerAbility = battlerId; // in SWSH, berry juice shows ability pop up but has no effect. This is mimicked here + gBattlerAbility = battler; // in SWSH, berry juice shows ability pop up but has no effect. This is mimicked here if (end2) { BattleScriptExecute(BattleScript_ItemHealHP_RemoveItemEnd2); @@ -6642,61 +6635,61 @@ static u8 ItemHealHp(u32 battlerId, u32 itemId, bool32 end2, bool32 percentHeal) return 0; } -static bool32 UnnerveOn(u32 battlerId, u32 itemId) +static bool32 UnnerveOn(u32 battler, u32 itemId) { - if (ItemId_GetPocket(itemId) == POCKET_BERRIES && IsUnnerveAbilityOnOpposingSide(battlerId)) + if (ItemId_GetPocket(itemId) == POCKET_BERRIES && IsUnnerveAbilityOnOpposingSide(battler)) return TRUE; return FALSE; } -static bool32 GetMentalHerbEffect(u8 battlerId) +static bool32 GetMentalHerbEffect(u8 battler) { bool32 ret = FALSE; // Check infatuation - if (gBattleMons[battlerId].status2 & STATUS2_INFATUATION) + if (gBattleMons[battler].status2 & STATUS2_INFATUATION) { - gBattleMons[battlerId].status2 &= ~STATUS2_INFATUATION; + gBattleMons[battler].status2 &= ~STATUS2_INFATUATION; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_INFATUATION; // STRINGID_TARGETGOTOVERINFATUATION StringCopy(gBattleTextBuff1, gStatusConditionString_LoveJpn); ret = TRUE; } #if B_MENTAL_HERB >= GEN_5 // Check taunt - if (gDisableStructs[battlerId].tauntTimer != 0) + if (gDisableStructs[battler].tauntTimer != 0) { - gDisableStructs[battlerId].tauntTimer = 0; + gDisableStructs[battler].tauntTimer = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_TAUNT; PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_TAUNT); ret = TRUE; } // Check encore - if (gDisableStructs[battlerId].encoreTimer != 0) + if (gDisableStructs[battler].encoreTimer != 0) { - gDisableStructs[battlerId].encoredMove = 0; - gDisableStructs[battlerId].encoreTimer = 0; + gDisableStructs[battler].encoredMove = 0; + gDisableStructs[battler].encoreTimer = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_ENCORE; // STRINGID_PKMNENCOREENDED ret = TRUE; } // Check torment - if (gBattleMons[battlerId].status2 & STATUS2_TORMENT) + if (gBattleMons[battler].status2 & STATUS2_TORMENT) { - gBattleMons[battlerId].status2 &= ~STATUS2_TORMENT; + gBattleMons[battler].status2 &= ~STATUS2_TORMENT; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_TORMENT; ret = TRUE; } // Check heal block - if (gStatuses3[battlerId] & STATUS3_HEAL_BLOCK) + if (gStatuses3[battler] & STATUS3_HEAL_BLOCK) { - gStatuses3[battlerId] &= ~STATUS3_HEAL_BLOCK; + gStatuses3[battler] &= ~STATUS3_HEAL_BLOCK; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_HEALBLOCK; ret = TRUE; } // Check disable - if (gDisableStructs[battlerId].disableTimer != 0) + if (gDisableStructs[battler].disableTimer != 0) { - gDisableStructs[battlerId].disableTimer = 0; - gDisableStructs[battlerId].disabledMove = 0; + gDisableStructs[battler].disableTimer = 0; + gDisableStructs[battler].disabledMove = 0; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MENTALHERBCURE_DISABLE; ret = TRUE; } @@ -6704,15 +6697,15 @@ static bool32 GetMentalHerbEffect(u8 battlerId) return ret; } -static u8 TryConsumeMirrorHerb(u8 battlerId, bool32 execute) +static u8 TryConsumeMirrorHerb(u8 battler, bool32 execute) { u8 effect = 0; - if (gProtectStructs[battlerId].eatMirrorHerb) { - gLastUsedItem = gBattleMons[battlerId].item; + if (gProtectStructs[battler].eatMirrorHerb) { + gLastUsedItem = gBattleMons[battler].item; gBattleScripting.savedBattler = gBattlerAttacker; - gBattleScripting.battler = gBattlerAttacker = battlerId; - gProtectStructs[battlerId].eatMirrorHerb = 0; + gBattleScripting.battler = gBattlerAttacker = battler; + gProtectStructs[battler].eatMirrorHerb = 0; if (execute) { BattleScriptExecute(BattleScript_MirrorHerbCopyStatChangeEnd2); } else { @@ -6724,7 +6717,7 @@ static u8 TryConsumeMirrorHerb(u8 battlerId, bool32 execute) return effect; } -static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) +static u8 ItemEffectMoveEnd(u32 battler, u16 holdEffect) { u8 effect = 0; u32 i; @@ -6733,148 +6726,148 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) { #if B_HP_BERRIES >= GEN_4 case HOLD_EFFECT_MICLE_BERRY: - effect = TrySetMicleBerry(battlerId, gLastUsedItem, FALSE); + effect = TrySetMicleBerry(battler, gLastUsedItem, FALSE); break; case HOLD_EFFECT_RESTORE_HP: - effect = ItemHealHp(battlerId, gLastUsedItem, FALSE, FALSE); + effect = ItemHealHp(battler, gLastUsedItem, FALSE, FALSE); break; #endif #if B_BERRIES_INSTANT >= GEN_4 case HOLD_EFFECT_RESTORE_PCT_HP: - effect = ItemHealHp(battlerId, gLastUsedItem, FALSE, TRUE); + effect = ItemHealHp(battler, gLastUsedItem, FALSE, TRUE); break; case HOLD_EFFECT_CONFUSE_SPICY: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SPICY, FALSE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SPICY, FALSE); break; case HOLD_EFFECT_CONFUSE_DRY: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_DRY, FALSE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_DRY, FALSE); break; case HOLD_EFFECT_CONFUSE_SWEET: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SWEET, FALSE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SWEET, FALSE); break; case HOLD_EFFECT_CONFUSE_BITTER: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_BITTER, FALSE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_BITTER, FALSE); break; case HOLD_EFFECT_CONFUSE_SOUR: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SOUR, FALSE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SOUR, FALSE); break; case HOLD_EFFECT_ATTACK_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_ATK, FALSE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_ATK, FALSE); break; case HOLD_EFFECT_DEFENSE_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_DEF, FALSE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_DEF, FALSE); break; case HOLD_EFFECT_SPEED_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPEED, FALSE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPEED, FALSE); break; case HOLD_EFFECT_SP_ATTACK_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPATK, FALSE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPATK, FALSE); break; case HOLD_EFFECT_SP_DEFENSE_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPDEF, FALSE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPDEF, FALSE); break; case HOLD_EFFECT_RANDOM_STAT_UP: - effect = RandomStatRaiseBerry(battlerId, gLastUsedItem, FALSE); + effect = RandomStatRaiseBerry(battler, gLastUsedItem, FALSE); break; #endif case HOLD_EFFECT_CURE_PAR: - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_PARALYSIS; + gBattleMons[battler].status1 &= ~STATUS1_PARALYSIS; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureParRet; effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_PSN: - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); + gBattleMons[battler].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCurePsnRet; effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_BRN: - if (gBattleMons[battlerId].status1 & STATUS1_BURN && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_BURN && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_BURN; + gBattleMons[battler].status1 &= ~STATUS1_BURN; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureBrnRet; effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_FRZ: - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FREEZE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FREEZE; + gBattleMons[battler].status1 &= ~STATUS1_FREEZE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureFrzRet; effect = ITEM_STATUS_CHANGE; } - if (gBattleMons[battlerId].status1 & STATUS1_FROSTBITE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FROSTBITE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FROSTBITE; + gBattleMons[battler].status1 &= ~STATUS1_FROSTBITE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureFsbRet; effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_SLP: - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_SLEEP && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_SLEEP; - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status1 &= ~STATUS1_SLEEP; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureSlpRet; effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_CONFUSION: - if (gBattleMons[battlerId].status2 & STATUS2_CONFUSION && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION && !UnnerveOn(battler, gLastUsedItem)) { - RemoveConfusionStatus(battlerId); + RemoveConfusionStatus(battler); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureConfusionRet; effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_MENTAL_HERB: - if (GetMentalHerbEffect(battlerId)) + if (GetMentalHerbEffect(battler)) { gBattleScripting.savedBattler = gBattlerAttacker; - gBattlerAttacker = battlerId; + gBattlerAttacker = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_MentalHerbCureRet; effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_CURE_STATUS: - if ((gBattleMons[battlerId].status1 & STATUS1_ANY || gBattleMons[battlerId].status2 & STATUS2_CONFUSION) && !UnnerveOn(battlerId, gLastUsedItem)) + if ((gBattleMons[battler].status1 & STATUS1_ANY || gBattleMons[battler].status2 & STATUS2_CONFUSION) && !UnnerveOn(battler, gLastUsedItem)) { - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY) StringCopy(gBattleTextBuff1, gStatusConditionString_PoisonJpn); - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; StringCopy(gBattleTextBuff1, gStatusConditionString_SleepJpn); } - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS) StringCopy(gBattleTextBuff1, gStatusConditionString_ParalysisJpn); - if (gBattleMons[battlerId].status1 & STATUS1_BURN) + if (gBattleMons[battler].status1 & STATUS1_BURN) StringCopy(gBattleTextBuff1, gStatusConditionString_BurnJpn); - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE || gBattleMons[battlerId].status1 & STATUS1_FROSTBITE) + if (gBattleMons[battler].status1 & STATUS1_FREEZE || gBattleMons[battler].status1 & STATUS1_FROSTBITE) StringCopy(gBattleTextBuff1, gStatusConditionString_IceJpn); - if (gBattleMons[battlerId].status2 & STATUS2_CONFUSION) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION) StringCopy(gBattleTextBuff1, gStatusConditionString_ConfusionJpn); - gBattleMons[battlerId].status1 = 0; - RemoveConfusionStatus(battlerId); + gBattleMons[battler].status1 = 0; + RemoveConfusionStatus(battler); BattleScriptPushCursor(); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; gBattlescriptCurrInstr = BattleScript_BerryCureChosenStatusRet; @@ -6884,16 +6877,16 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) case HOLD_EFFECT_RESTORE_STATS: for (i = 0; i < NUM_BATTLE_STATS; i++) { - if (gBattleMons[battlerId].statStages[i] < DEFAULT_STAT_STAGE) + if (gBattleMons[battler].statStages[i] < DEFAULT_STAT_STAGE) { - gBattleMons[battlerId].statStages[i] = DEFAULT_STAT_STAGE; + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; effect = ITEM_STATS_CHANGE; } } if (effect != 0) { - gBattleScripting.battler = battlerId; - gPotentialItemEffectBattler = battlerId; + gBattleScripting.battler = battler; + gPotentialItemEffectBattler = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_WhiteHerbRet; return effect; @@ -6901,20 +6894,20 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) break; case HOLD_EFFECT_CRITICAL_UP: // lansat berry if (B_BERRIES_INSTANT >= GEN_4 - && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) - && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) + && !(gBattleMons[battler].status2 & STATUS2_FOCUS_ENERGY) + && HasEnoughHpToEatBerry(battler, GetBattlerItemHoldEffectParam(battler, gLastUsedItem), gLastUsedItem)) { - gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; - gBattleScripting.battler = battlerId; - gPotentialItemEffectBattler = battlerId; + gBattleMons[battler].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battler; + gPotentialItemEffectBattler = battler; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryFocusEnergyRet; effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_BERSERK_GENE: - BufferStatChange(battlerId, STAT_ATK, STRINGID_STATROSE); - gEffectBattler = battlerId; + BufferStatChange(battler, STAT_ATK, STRINGID_STATROSE); + gEffectBattler = battler; if (CanBeInfinitelyConfused(gEffectBattler)) { gStatuses4[gEffectBattler] |= STATUS4_INFINITE_CONFUSION; @@ -6928,14 +6921,14 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) effect = ITEM_STATS_CHANGE; break; case HOLD_EFFECT_MIRROR_HERB: - effect = TryConsumeMirrorHerb(battlerId, FALSE); + effect = TryConsumeMirrorHerb(battler, FALSE); break; } return effect; } -u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) +u8 ItemBattleEffects(u8 caseID, u8 battler, bool8 moveTurn) { int i = 0, moveType; u8 effect = ITEM_NO_EFFECT; @@ -6945,8 +6938,8 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) u16 atkItem; if (caseID != ITEMEFFECT_USE_LAST_ITEM) { - gLastUsedItem = gBattleMons[battlerId].item; - battlerHoldEffect = GetBattlerHoldEffect(battlerId, TRUE); + gLastUsedItem = gBattleMons[battler].item; + battlerHoldEffect = GetBattlerHoldEffect(battler, TRUE); } atkItem = gBattleMons[gBattlerAttacker].item; @@ -6956,12 +6949,12 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) switch (caseID) { case ITEMEFFECT_ON_SWITCH_IN: - if (!gSpecialStatuses[battlerId].switchInItemDone) + if (!gSpecialStatuses[battler].switchInItemDone) { switch (battlerHoldEffect) { case HOLD_EFFECT_DOUBLE_PRIZE: - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER && !gBattleStruct->moneyMultiplierItem) + if (GetBattlerSide(battler) == B_SIDE_PLAYER && !gBattleStruct->moneyMultiplierItem) { gBattleStruct->moneyMultiplier *= 2; gBattleStruct->moneyMultiplierItem = 1; @@ -6970,141 +6963,141 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) case HOLD_EFFECT_RESTORE_STATS: for (i = 0; i < NUM_BATTLE_STATS; i++) { - if (gBattleMons[battlerId].statStages[i] < DEFAULT_STAT_STAGE) + if (gBattleMons[battler].statStages[i] < DEFAULT_STAT_STAGE) { - gBattleMons[battlerId].statStages[i] = DEFAULT_STAT_STAGE; + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; effect = ITEM_STATS_CHANGE; } } if (effect != 0) { - gBattleScripting.battler = battlerId; - gPotentialItemEffectBattler = battlerId; - gActiveBattler = gBattlerAttacker = battlerId; + gBattleScripting.battler = battler; + gPotentialItemEffectBattler = battler; + gBattlerAttacker = battler; BattleScriptExecute(BattleScript_WhiteHerbEnd2); } break; #if B_BERRIES_INSTANT >= GEN_4 case HOLD_EFFECT_CONFUSE_SPICY: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SPICY, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SPICY, TRUE); break; case HOLD_EFFECT_CONFUSE_DRY: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_DRY, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_DRY, TRUE); break; case HOLD_EFFECT_CONFUSE_SWEET: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SWEET, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SWEET, TRUE); break; case HOLD_EFFECT_CONFUSE_BITTER: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_BITTER, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_BITTER, TRUE); break; case HOLD_EFFECT_CONFUSE_SOUR: - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SOUR, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SOUR, TRUE); break; case HOLD_EFFECT_ATTACK_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_ATK, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_ATK, TRUE); break; case HOLD_EFFECT_DEFENSE_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_DEF, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_DEF, TRUE); break; case HOLD_EFFECT_SPEED_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPEED, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPEED, TRUE); break; case HOLD_EFFECT_SP_ATTACK_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPATK, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPATK, TRUE); break; case HOLD_EFFECT_SP_DEFENSE_UP: - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPDEF, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPDEF, TRUE); break; case HOLD_EFFECT_CRITICAL_UP: - if (!(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) + if (!(gBattleMons[battler].status2 & STATUS2_FOCUS_ENERGY) && HasEnoughHpToEatBerry(battler, GetBattlerItemHoldEffectParam(battler, gLastUsedItem), gLastUsedItem)) { - gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; - gBattleScripting.battler = battlerId; + gBattleMons[battler].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battler; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_RANDOM_STAT_UP: - effect = RandomStatRaiseBerry(battlerId, gLastUsedItem, TRUE); + effect = RandomStatRaiseBerry(battler, gLastUsedItem, TRUE); break; case HOLD_EFFECT_CURE_PAR: - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_PARALYSIS; + gBattleMons[battler].status1 &= ~STATUS1_PARALYSIS; BattleScriptExecute(BattleScript_BerryCurePrlzEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_PSN: - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); + gBattleMons[battler].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); BattleScriptExecute(BattleScript_BerryCurePsnEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_BRN: - if (gBattleMons[battlerId].status1 & STATUS1_BURN && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_BURN && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_BURN; + gBattleMons[battler].status1 &= ~STATUS1_BURN; BattleScriptExecute(BattleScript_BerryCureBrnEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_FRZ: - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FREEZE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FREEZE; + gBattleMons[battler].status1 &= ~STATUS1_FREEZE; BattleScriptExecute(BattleScript_BerryCureFrzEnd2); effect = ITEM_STATUS_CHANGE; } - if (gBattleMons[battlerId].status1 & STATUS1_FROSTBITE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FROSTBITE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FROSTBITE; + gBattleMons[battler].status1 &= ~STATUS1_FROSTBITE; BattleScriptExecute(BattleScript_BerryCureFsbEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_SLP: - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_SLEEP && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_SLEEP; - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status1 &= ~STATUS1_SLEEP; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; BattleScriptExecute(BattleScript_BerryCureSlpEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_STATUS: - if ((gBattleMons[battlerId].status1 & STATUS1_ANY || gBattleMons[battlerId].status2 & STATUS2_CONFUSION) && !UnnerveOn(battlerId, gLastUsedItem)) + if ((gBattleMons[battler].status1 & STATUS1_ANY || gBattleMons[battler].status2 & STATUS2_CONFUSION) && !UnnerveOn(battler, gLastUsedItem)) { i = 0; - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY) { StringCopy(gBattleTextBuff1, gStatusConditionString_PoisonJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; StringCopy(gBattleTextBuff1, gStatusConditionString_SleepJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS) { StringCopy(gBattleTextBuff1, gStatusConditionString_ParalysisJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_BURN) + if (gBattleMons[battler].status1 & STATUS1_BURN) { StringCopy(gBattleTextBuff1, gStatusConditionString_BurnJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE || gBattleMons[battlerId].status1 & STATUS1_FROSTBITE) + if (gBattleMons[battler].status1 & STATUS1_FREEZE || gBattleMons[battler].status1 & STATUS1_FROSTBITE) { StringCopy(gBattleTextBuff1, gStatusConditionString_IceJpn); i++; } - if (gBattleMons[battlerId].status2 & STATUS2_CONFUSION) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION) { StringCopy(gBattleTextBuff1, gStatusConditionString_ConfusionJpn); i++; @@ -7113,56 +7106,56 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_NORMALIZED_STATUS; - gBattleMons[battlerId].status1 = 0; - RemoveConfusionStatus(battlerId); + gBattleMons[battler].status1 = 0; + RemoveConfusionStatus(battler); BattleScriptExecute(BattleScript_BerryCureChosenStatusEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_RESTORE_HP: - effect = ItemHealHp(battlerId, gLastUsedItem, TRUE, FALSE); + effect = ItemHealHp(battler, gLastUsedItem, TRUE, FALSE); break; case HOLD_EFFECT_RESTORE_PCT_HP: - effect = ItemHealHp(battlerId, gLastUsedItem, TRUE, TRUE); + effect = ItemHealHp(battler, gLastUsedItem, TRUE, TRUE); break; #endif case HOLD_EFFECT_AIR_BALLOON: effect = ITEM_EFFECT_OTHER; - gBattleScripting.battler = battlerId; + gBattleScripting.battler = battler; BattleScriptPushCursorAndCallback(BattleScript_AirBaloonMsgIn); - RecordItemEffectBattle(battlerId, HOLD_EFFECT_AIR_BALLOON); + RecordItemEffectBattle(battler, HOLD_EFFECT_AIR_BALLOON); break; case HOLD_EFFECT_ROOM_SERVICE: - if (TryRoomService(battlerId)) + if (TryRoomService(battler)) { BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; } break; case HOLD_EFFECT_SEEDS: - switch (GetBattlerHoldEffectParam(battlerId)) + switch (GetBattlerHoldEffectParam(battler)) { case HOLD_EFFECT_PARAM_ELECTRIC_TERRAIN: - effect = TryHandleSeed(battlerId, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); + effect = TryHandleSeed(battler, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); break; case HOLD_EFFECT_PARAM_GRASSY_TERRAIN: - effect = TryHandleSeed(battlerId, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); + effect = TryHandleSeed(battler, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); break; case HOLD_EFFECT_PARAM_MISTY_TERRAIN: - effect = TryHandleSeed(battlerId, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); + effect = TryHandleSeed(battler, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); break; case HOLD_EFFECT_PARAM_PSYCHIC_TERRAIN: - effect = TryHandleSeed(battlerId, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); + effect = TryHandleSeed(battler, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); break; } break; case HOLD_EFFECT_EJECT_PACK: - if (gProtectStructs[battlerId].statFell - && gProtectStructs[battlerId].disableEjectPack == 0 + if (gProtectStructs[battler].statFell + && gProtectStructs[battler].disableEjectPack == 0 && !(gCurrentMove == MOVE_PARTING_SHOT && CanBattlerSwitch(gBattlerAttacker))) // Does not activate if attacker used Parting Shot and can switch out { - gProtectStructs[battlerId].statFell = FALSE; - gActiveBattler = gBattleScripting.battler = battlerId; + gProtectStructs[battler].statFell = FALSE; + gBattleScripting.battler = battler; effect = ITEM_STATS_CHANGE; if (moveTurn) { @@ -7176,8 +7169,8 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_BERSERK_GENE: - BufferStatChange(battlerId, STAT_ATK, STRINGID_STATROSE); - gEffectBattler = battlerId; + BufferStatChange(battler, STAT_ATK, STRINGID_STATROSE); + gEffectBattler = battler; if (CanBeInfinitelyConfused(gEffectBattler)) { gStatuses4[gEffectBattler] |= STATUS4_INFINITE_CONFUSION; @@ -7193,40 +7186,40 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } if (effect != 0) { - gSpecialStatuses[battlerId].switchInItemDone = TRUE; - gActiveBattler = gBattlerAttacker = gPotentialItemEffectBattler = gBattleScripting.battler = battlerId; + gSpecialStatuses[battler].switchInItemDone = TRUE; + gBattlerAttacker = gPotentialItemEffectBattler = gBattleScripting.battler = battler; switch (effect) { case ITEM_STATUS_CHANGE: - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); break; case ITEM_PP_CHANGE: - if (MOVE_IS_PERMANENT(battlerId, i)) - gBattleMons[battlerId].pp[i] = changedPP; + if (MOVE_IS_PERMANENT(battler, i)) + gBattleMons[battler].pp[i] = changedPP; break; } } } break; case ITEMEFFECT_NORMAL: - if (gBattleMons[battlerId].hp) + if (gBattleMons[battler].hp) { switch (battlerHoldEffect) { case HOLD_EFFECT_RESTORE_HP: if (!moveTurn) - effect = ItemHealHp(battlerId, gLastUsedItem, TRUE, FALSE); + effect = ItemHealHp(battler, gLastUsedItem, TRUE, FALSE); break; case HOLD_EFFECT_RESTORE_PCT_HP: if (!moveTurn) - effect = ItemHealHp(battlerId, gLastUsedItem, TRUE, TRUE); + effect = ItemHealHp(battler, gLastUsedItem, TRUE, TRUE); break; case HOLD_EFFECT_RESTORE_PP: if (!moveTurn) { - struct Pokemon *party = GetBattlerParty(battlerId); - struct Pokemon *mon = &party[gBattlerPartyIndexes[battlerId]]; + struct Pokemon *party = GetBattlerParty(battler); + struct Pokemon *mon = &party[gBattlerPartyIndexes[battler]]; u8 ppBonuses; u16 move; @@ -7241,12 +7234,12 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (i != MAX_MON_MOVES) { u8 maxPP = CalculatePPWithBonus(move, ppBonuses, i); - u8 ppRestored = GetBattlerHoldEffectParam(battlerId); + u8 ppRestored = GetBattlerHoldEffectParam(battler); - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + if (GetBattlerAbility(battler) == ABILITY_RIPEN) { ppRestored *= 2; - gBattlerAbility = battlerId; + gBattlerAbility = battler; } if (changedPP + ppRestored > maxPP) changedPP = maxPP; @@ -7256,8 +7249,8 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) PREPARE_MOVE_BUFFER(gBattleTextBuff1, move); BattleScriptExecute(BattleScript_BerryPPHealEnd2); - BtlController_EmitSetMonData(BUFFER_A, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP); + MarkBattlerForControllerExec(battler); effect = ITEM_PP_CHANGE; } } @@ -7265,193 +7258,193 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) case HOLD_EFFECT_RESTORE_STATS: for (i = 0; i < NUM_BATTLE_STATS; i++) { - if (gBattleMons[battlerId].statStages[i] < DEFAULT_STAT_STAGE) + if (gBattleMons[battler].statStages[i] < DEFAULT_STAT_STAGE) { - gBattleMons[battlerId].statStages[i] = DEFAULT_STAT_STAGE; + gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; effect = ITEM_STATS_CHANGE; } } if (effect != 0) { - gBattleScripting.battler = battlerId; - gPotentialItemEffectBattler = battlerId; - gActiveBattler = gBattlerAttacker = battlerId; + gBattleScripting.battler = battler; + gPotentialItemEffectBattler = battler; + gBattlerAttacker = battler; BattleScriptExecute(BattleScript_WhiteHerbEnd2); } break; case HOLD_EFFECT_BLACK_SLUDGE: - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_POISON)) + if (IS_BATTLER_OF_TYPE(battler, TYPE_POISON)) { goto LEFTOVERS; } - else if (GetBattlerAbility(battlerId) != ABILITY_MAGIC_GUARD && !moveTurn) + else if (GetBattlerAbility(battler) != ABILITY_MAGIC_GUARD && !moveTurn) { - gBattleMoveDamage = gBattleMons[battlerId].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; BattleScriptExecute(BattleScript_ItemHurtEnd2); effect = ITEM_HP_CHANGE; - RecordItemEffectBattle(battlerId, battlerHoldEffect); + RecordItemEffectBattle(battler, battlerHoldEffect); PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); } break; case HOLD_EFFECT_LEFTOVERS: LEFTOVERS: #if B_HEAL_BLOCKING >= GEN_5 - if (gBattleMons[battlerId].hp < gBattleMons[battlerId].maxHP && !moveTurn && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK)) + if (gBattleMons[battler].hp < gBattleMons[battler].maxHP && !moveTurn && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)) #else - if (gBattleMons[battlerId].hp < gBattleMons[battlerId].maxHP && !moveTurn) + if (gBattleMons[battler].hp < gBattleMons[battler].maxHP && !moveTurn) #endif { - gBattleMoveDamage = gBattleMons[battlerId].maxHP / 16; + gBattleMoveDamage = gBattleMons[battler].maxHP / 16; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; BattleScriptExecute(BattleScript_ItemHealHP_End2); effect = ITEM_HP_CHANGE; - RecordItemEffectBattle(battlerId, battlerHoldEffect); + RecordItemEffectBattle(battler, battlerHoldEffect); } break; case HOLD_EFFECT_CONFUSE_SPICY: if (!moveTurn) - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SPICY, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SPICY, TRUE); break; case HOLD_EFFECT_CONFUSE_DRY: if (!moveTurn) - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_DRY, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_DRY, TRUE); break; case HOLD_EFFECT_CONFUSE_SWEET: if (!moveTurn) - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SWEET, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SWEET, TRUE); break; case HOLD_EFFECT_CONFUSE_BITTER: if (!moveTurn) - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_BITTER, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_BITTER, TRUE); break; case HOLD_EFFECT_CONFUSE_SOUR: if (!moveTurn) - effect = HealConfuseBerry(battlerId, gLastUsedItem, FLAVOR_SOUR, TRUE); + effect = HealConfuseBerry(battler, gLastUsedItem, FLAVOR_SOUR, TRUE); break; case HOLD_EFFECT_ATTACK_UP: if (!moveTurn) - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_ATK, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_ATK, TRUE); break; case HOLD_EFFECT_DEFENSE_UP: if (!moveTurn) - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_DEF, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_DEF, TRUE); break; case HOLD_EFFECT_SPEED_UP: if (!moveTurn) - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPEED, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPEED, TRUE); break; case HOLD_EFFECT_SP_ATTACK_UP: if (!moveTurn) - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPATK, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPATK, TRUE); break; case HOLD_EFFECT_SP_DEFENSE_UP: if (!moveTurn) - effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPDEF, TRUE); + effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPDEF, TRUE); break; case HOLD_EFFECT_CRITICAL_UP: - if (!moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) - && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) + if (!moveTurn && !(gBattleMons[battler].status2 & STATUS2_FOCUS_ENERGY) + && HasEnoughHpToEatBerry(battler, GetBattlerItemHoldEffectParam(battler, gLastUsedItem), gLastUsedItem)) { - gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; - gBattleScripting.battler = battlerId; + gBattleMons[battler].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battler; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_RANDOM_STAT_UP: if (!moveTurn) - effect = RandomStatRaiseBerry(battlerId, gLastUsedItem, TRUE); + effect = RandomStatRaiseBerry(battler, gLastUsedItem, TRUE); break; case HOLD_EFFECT_CURE_PAR: - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_PARALYSIS; + gBattleMons[battler].status1 &= ~STATUS1_PARALYSIS; BattleScriptExecute(BattleScript_BerryCurePrlzEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_PSN: - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); + gBattleMons[battler].status1 &= ~(STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER); BattleScriptExecute(BattleScript_BerryCurePsnEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_BRN: - if (gBattleMons[battlerId].status1 & STATUS1_BURN && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_BURN && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_BURN; + gBattleMons[battler].status1 &= ~STATUS1_BURN; BattleScriptExecute(BattleScript_BerryCureBrnEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_FRZ: - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FREEZE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FREEZE; + gBattleMons[battler].status1 &= ~STATUS1_FREEZE; BattleScriptExecute(BattleScript_BerryCureFrzEnd2); effect = ITEM_STATUS_CHANGE; } - if (gBattleMons[battlerId].status1 & STATUS1_FROSTBITE && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_FROSTBITE && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_FROSTBITE; + gBattleMons[battler].status1 &= ~STATUS1_FROSTBITE; BattleScriptExecute(BattleScript_BerryCureFsbEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_SLP: - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status1 & STATUS1_SLEEP && !UnnerveOn(battler, gLastUsedItem)) { - gBattleMons[battlerId].status1 &= ~STATUS1_SLEEP; - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status1 &= ~STATUS1_SLEEP; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; BattleScriptExecute(BattleScript_BerryCureSlpEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_CURE_CONFUSION: - if (gBattleMons[battlerId].status2 & STATUS2_CONFUSION && !UnnerveOn(battlerId, gLastUsedItem)) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION && !UnnerveOn(battler, gLastUsedItem)) { - RemoveConfusionStatus(battlerId); + RemoveConfusionStatus(battler); BattleScriptExecute(BattleScript_BerryCureConfusionEnd2); effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_CURE_STATUS: - if ((gBattleMons[battlerId].status1 & STATUS1_ANY || gBattleMons[battlerId].status2 & STATUS2_CONFUSION) && !UnnerveOn(battlerId, gLastUsedItem)) + if ((gBattleMons[battler].status1 & STATUS1_ANY || gBattleMons[battler].status2 & STATUS2_CONFUSION) && !UnnerveOn(battler, gLastUsedItem)) { i = 0; - if (gBattleMons[battlerId].status1 & STATUS1_PSN_ANY) + if (gBattleMons[battler].status1 & STATUS1_PSN_ANY) { StringCopy(gBattleTextBuff1, gStatusConditionString_PoisonJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { - gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; StringCopy(gBattleTextBuff1, gStatusConditionString_SleepJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS) + if (gBattleMons[battler].status1 & STATUS1_PARALYSIS) { StringCopy(gBattleTextBuff1, gStatusConditionString_ParalysisJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_BURN) + if (gBattleMons[battler].status1 & STATUS1_BURN) { StringCopy(gBattleTextBuff1, gStatusConditionString_BurnJpn); i++; } - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE || gBattleMons[battlerId].status1 & STATUS1_FROSTBITE) + if (gBattleMons[battler].status1 & STATUS1_FREEZE || gBattleMons[battler].status1 & STATUS1_FROSTBITE) { StringCopy(gBattleTextBuff1, gStatusConditionString_IceJpn); i++; } - if (gBattleMons[battlerId].status2 & STATUS2_CONFUSION) + if (gBattleMons[battler].status2 & STATUS2_CONFUSION) { StringCopy(gBattleTextBuff1, gStatusConditionString_ConfusionJpn); i++; @@ -7460,28 +7453,28 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_NORMALIZED_STATUS; - gBattleMons[battlerId].status1 = 0; - RemoveConfusionStatus(battlerId); + gBattleMons[battler].status1 = 0; + RemoveConfusionStatus(battler); BattleScriptExecute(BattleScript_BerryCureChosenStatusEnd2); effect = ITEM_STATUS_CHANGE; } break; case HOLD_EFFECT_MENTAL_HERB: - if (GetMentalHerbEffect(battlerId)) + if (GetMentalHerbEffect(battler)) { gBattleScripting.savedBattler = gBattlerAttacker; - gBattlerAttacker = battlerId; + gBattlerAttacker = battler; BattleScriptExecute(BattleScript_MentalHerbCureEnd2); effect = ITEM_EFFECT_OTHER; } break; case HOLD_EFFECT_MICLE_BERRY: if (!moveTurn) - effect = TrySetMicleBerry(battlerId, gLastUsedItem, TRUE); + effect = TrySetMicleBerry(battler, gLastUsedItem, TRUE); break; case HOLD_EFFECT_BERSERK_GENE: - BufferStatChange(battlerId, STAT_ATK, STRINGID_STATROSE); - gEffectBattler = battlerId; + BufferStatChange(battler, STAT_ATK, STRINGID_STATROSE); + gEffectBattler = battler; if (CanBeInfinitelyConfused(gEffectBattler)) { gStatuses4[gEffectBattler] |= STATUS4_INFINITE_CONFUSION; @@ -7495,53 +7488,53 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) effect = ITEM_STATS_CHANGE; break; case HOLD_EFFECT_MIRROR_HERB: - effect = TryConsumeMirrorHerb(battlerId, TRUE); + effect = TryConsumeMirrorHerb(battler, TRUE); break; } if (effect != 0) { - gActiveBattler = gBattlerAttacker = gPotentialItemEffectBattler = gBattleScripting.battler = battlerId; + gBattlerAttacker = gPotentialItemEffectBattler = gBattleScripting.battler = battler; switch (effect) { case ITEM_STATUS_CHANGE: - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); break; case ITEM_PP_CHANGE: - if (MOVE_IS_PERMANENT(battlerId, i)) - gBattleMons[battlerId].pp[i] = changedPP; + if (MOVE_IS_PERMANENT(battler, i)) + gBattleMons[battler].pp[i] = changedPP; break; } } } break; case ITEMEFFECT_USE_LAST_ITEM: - effect = ItemEffectMoveEnd(battlerId, ItemId_GetHoldEffect(gLastUsedItem)); + effect = ItemEffectMoveEnd(battler, ItemId_GetHoldEffect(gLastUsedItem)); gBattleScripting.overrideBerryRequirements = 2; // to exit VARIOUS_CONSUME_BERRIES if (effect) { - gActiveBattler = gPotentialItemEffectBattler = gBattleScripting.battler = battlerId; + gPotentialItemEffectBattler = gBattleScripting.battler = battler; if (effect == ITEM_STATUS_CHANGE) { - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } break; } break; case ITEMEFFECT_MOVE_END: - for (battlerId = 0; battlerId < gBattlersCount; battlerId++) + for (battler = 0; battler < gBattlersCount; battler++) { - gLastUsedItem = gBattleMons[battlerId].item; - effect = ItemEffectMoveEnd(battlerId, GetBattlerHoldEffect(battlerId, TRUE)); + gLastUsedItem = gBattleMons[battler].item; + effect = ItemEffectMoveEnd(battler, GetBattlerHoldEffect(battler, TRUE)); if (effect) { - gActiveBattler = gPotentialItemEffectBattler = gBattleScripting.battler = battlerId; + gPotentialItemEffectBattler = gBattleScripting.battler = battler; if (effect == ITEM_STATUS_CHANGE) { - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } break; } @@ -7597,7 +7590,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) && gBattlerAttacker != gBattlerTarget && gBattleMons[gBattlerAttacker].hp != gBattleMons[gBattlerAttacker].maxHP #if B_HEAL_BLOCKING >= GEN_5 - && gBattleMons[gBattlerAttacker].hp != 0 && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK)) + && gBattleMons[gBattlerAttacker].hp != 0 && !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)) #else && gBattleMons[gBattlerAttacker].hp != 0) #endif @@ -7673,11 +7666,11 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_RockyHelmetActivates; PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); - RecordItemEffectBattle(battlerId, HOLD_EFFECT_ROCKY_HELMET); + RecordItemEffectBattle(battler, HOLD_EFFECT_ROCKY_HELMET); } break; case HOLD_EFFECT_WEAKNESS_POLICY: - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED && gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) { @@ -7687,7 +7680,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SNOWBALL: - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED && moveType == TYPE_ICE) { @@ -7698,7 +7691,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_LUMINOUS_MOSS: - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED && moveType == TYPE_WATER) { @@ -7709,7 +7702,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_CELL_BATTERY: - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED && moveType == TYPE_ELECTRIC) { @@ -7720,7 +7713,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_ABSORB_BULB: - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED && moveType == TYPE_WATER) { @@ -7731,62 +7724,62 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_JABOCA_BERRY: // consume and damage attacker if used physical move - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED - && !DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove) + && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && IS_MOVE_PHYSICAL(gCurrentMove) && GetBattlerAbility(gBattlerAttacker) != ABILITY_MAGIC_GUARD) { gBattleMoveDamage = gBattleMons[gBattlerAttacker].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + if (GetBattlerAbility(battler) == ABILITY_RIPEN) gBattleMoveDamage *= 2; effect = ITEM_HP_CHANGE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_JabocaRowapBerryActivates; PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); - RecordItemEffectBattle(battlerId, HOLD_EFFECT_ROCKY_HELMET); + RecordItemEffectBattle(battler, HOLD_EFFECT_ROCKY_HELMET); } break; case HOLD_EFFECT_ROWAP_BERRY: // consume and damage attacker if used special move - if (IsBattlerAlive(battlerId) + if (IsBattlerAlive(battler) && TARGET_TURN_DAMAGED - && !DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove) + && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && IS_MOVE_SPECIAL(gCurrentMove) && GetBattlerAbility(gBattlerAttacker) != ABILITY_MAGIC_GUARD) { gBattleMoveDamage = gBattleMons[gBattlerAttacker].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if (GetBattlerAbility(battlerId) == ABILITY_RIPEN) + if (GetBattlerAbility(battler) == ABILITY_RIPEN) gBattleMoveDamage *= 2; effect = ITEM_HP_CHANGE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_JabocaRowapBerryActivates; PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); - RecordItemEffectBattle(battlerId, HOLD_EFFECT_ROCKY_HELMET); + RecordItemEffectBattle(battler, HOLD_EFFECT_ROCKY_HELMET); } break; case HOLD_EFFECT_KEE_BERRY: // consume and boost defense if used physical move - effect = DamagedStatBoostBerryEffect(battlerId, STAT_DEF, SPLIT_PHYSICAL); + effect = DamagedStatBoostBerryEffect(battler, STAT_DEF, SPLIT_PHYSICAL); break; case HOLD_EFFECT_MARANGA_BERRY: // consume and boost sp. defense if used special move - effect = DamagedStatBoostBerryEffect(battlerId, STAT_SPDEF, SPLIT_SPECIAL); + effect = DamagedStatBoostBerryEffect(battler, STAT_SPDEF, SPLIT_SPECIAL); break; case HOLD_EFFECT_STICKY_BARB: if (TARGET_TURN_DAMAGED && (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) && IsMoveMakingContact(gCurrentMove, gBattlerAttacker) - && !DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove) + && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && IsBattlerAlive(gBattlerAttacker) && CanStealItem(gBattlerAttacker, gBattlerTarget, gBattleMons[gBattlerTarget].item) && gBattleMons[gBattlerAttacker].item == ITEM_NONE) { // No sticky hold checks. - gEffectBattler = battlerId; // gEffectBattler = target + gEffectBattler = battler; // gEffectBattler = target StealTargetItem(gBattlerAttacker, gBattlerTarget); // Attacker takes target's barb BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_StickyBarbTransfer; @@ -7798,36 +7791,36 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) break; case ITEMEFFECT_ORBS: { - u16 battlerAbility = GetBattlerAbility(battlerId); + u16 battlerAbility = GetBattlerAbility(battler); switch (battlerHoldEffect) { case HOLD_EFFECT_TOXIC_ORB: - if (CanBePoisoned(battlerId, battlerId)) + if (CanBePoisoned(battler, battler)) { effect = ITEM_STATUS_CHANGE; - gBattleMons[battlerId].status1 = STATUS1_TOXIC_POISON; + gBattleMons[battler].status1 = STATUS1_TOXIC_POISON; BattleScriptExecute(BattleScript_ToxicOrb); - RecordItemEffectBattle(battlerId, battlerHoldEffect); + RecordItemEffectBattle(battler, battlerHoldEffect); } break; case HOLD_EFFECT_FLAME_ORB: - if (CanBeBurned(battlerId)) + if (CanBeBurned(battler)) { effect = ITEM_STATUS_CHANGE; - gBattleMons[battlerId].status1 = STATUS1_BURN; + gBattleMons[battler].status1 = STATUS1_BURN; BattleScriptExecute(BattleScript_FlameOrb); - RecordItemEffectBattle(battlerId, battlerHoldEffect); + RecordItemEffectBattle(battler, battlerHoldEffect); } break; case HOLD_EFFECT_STICKY_BARB: // Not an orb per se, but similar effect, and needs to NOT activate with pickpocket if (battlerAbility != ABILITY_MAGIC_GUARD) { - gBattleMoveDamage = gBattleMons[battlerId].maxHP / 8; + gBattleMoveDamage = gBattleMons[battler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; BattleScriptExecute(BattleScript_ItemHurtEnd2); effect = ITEM_HP_CHANGE; - RecordItemEffectBattle(battlerId, battlerHoldEffect); + RecordItemEffectBattle(battler, battlerHoldEffect); PREPARE_ITEM_BUFFER(gBattleTextBuff1, gLastUsedItem); } break; @@ -7835,9 +7828,8 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (effect == ITEM_STATUS_CHANGE) { - gActiveBattler = battlerId; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } } break; @@ -7845,16 +7837,16 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) // Berry was successfully used on a Pokemon. if (effect && (gLastUsedItem >= FIRST_BERRY_INDEX && gLastUsedItem <= LAST_BERRY_INDEX)) - gBattleStruct->ateBerry[battlerId & BIT_SIDE] |= gBitTable[gBattlerPartyIndexes[battlerId]]; + gBattleStruct->ateBerry[battler & BIT_SIDE] |= gBitTable[gBattlerPartyIndexes[battler]]; return effect; } -void ClearFuryCutterDestinyBondGrudge(u8 battlerId) +void ClearFuryCutterDestinyBondGrudge(u8 battler) { - gDisableStructs[battlerId].furyCutterCounter = 0; - gBattleMons[battlerId].status2 &= ~STATUS2_DESTINY_BOND; - gStatuses3[battlerId] &= ~STATUS3_GRUDGE; + gDisableStructs[battler].furyCutterCounter = 0; + gBattleMons[battler].status2 &= ~STATUS2_DESTINY_BOND; + gStatuses3[battler] &= ~STATUS3_GRUDGE; } void HandleAction_RunBattleScript(void) // identical to RunBattleScriptCommands @@ -7863,7 +7855,7 @@ void HandleAction_RunBattleScript(void) // identical to RunBattleScriptCommands gBattleScriptingCommandsTable[*gBattlescriptCurrInstr](); } -u32 SetRandomTarget(u32 battlerId) +u32 SetRandomTarget(u32 battler) { u32 target; static const u8 targets[2][2] = @@ -7874,13 +7866,13 @@ u32 SetRandomTarget(u32 battlerId) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - target = GetBattlerAtPosition(targets[GetBattlerSide(battlerId)][Random() % 2]); + target = GetBattlerAtPosition(targets[GetBattlerSide(battler)][Random() % 2]); if (!IsBattlerAlive(target)) target ^= BIT_FLANK; } else { - target = GetBattlerAtPosition(targets[GetBattlerSide(battlerId)][0]); + target = GetBattlerAtPosition(targets[GetBattlerSide(battler)][0]); } return target; @@ -7964,14 +7956,14 @@ u32 GetMoveTarget(u16 move, u8 setTarget) return targetBattler; } -static bool32 IsBattlerModernFatefulEncounter(u8 battlerId) +static bool32 IsBattlerModernFatefulEncounter(u8 battler) { - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) return TRUE; - if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES, NULL) != SPECIES_DEOXYS - && GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES, NULL) != SPECIES_MEW) + if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL) != SPECIES_DEOXYS + && GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL) != SPECIES_MEW) return TRUE; - return GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_MODERN_FATEFUL_ENCOUNTER, NULL); + return GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_MODERN_FATEFUL_ENCOUNTER, NULL); } u8 IsMonDisobedient(void) @@ -8101,40 +8093,40 @@ u8 IsMonDisobedient(void) } } -u32 GetBattlerHoldEffect(u8 battlerId, bool32 checkNegating) +u32 GetBattlerHoldEffect(u8 battler, bool32 checkNegating) { if (checkNegating) { - if (gStatuses3[battlerId] & STATUS3_EMBARGO) + if (gStatuses3[battler] & STATUS3_EMBARGO) return HOLD_EFFECT_NONE; if (gFieldStatuses & STATUS_FIELD_MAGIC_ROOM) return HOLD_EFFECT_NONE; - if (GetBattlerAbility(battlerId) == ABILITY_KLUTZ) + if (GetBattlerAbility(battler) == ABILITY_KLUTZ) return HOLD_EFFECT_NONE; } - gPotentialItemEffectBattler = battlerId; + gPotentialItemEffectBattler = battler; - if (gBattleMons[battlerId].item == ITEM_ENIGMA_BERRY_E_READER) - return gEnigmaBerries[battlerId].holdEffect; + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER) + return gEnigmaBerries[battler].holdEffect; else - return ItemId_GetHoldEffect(gBattleMons[battlerId].item); + return ItemId_GetHoldEffect(gBattleMons[battler].item); } -static u32 GetBattlerItemHoldEffectParam(u8 battlerId, u16 item) +static u32 GetBattlerItemHoldEffectParam(u8 battler, u16 item) { if (item == ITEM_ENIGMA_BERRY_E_READER) - return gEnigmaBerries[battlerId].holdEffectParam; + return gEnigmaBerries[battler].holdEffectParam; else return ItemId_GetHoldEffectParam(item); } -u32 GetBattlerHoldEffectParam(u8 battlerId) +u32 GetBattlerHoldEffectParam(u8 battler) { - if (gBattleMons[battlerId].item == ITEM_ENIGMA_BERRY_E_READER) - return gEnigmaBerries[battlerId].holdEffectParam; + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER) + return gEnigmaBerries[battler].holdEffectParam; else - return ItemId_GetHoldEffectParam(gBattleMons[battlerId].item); + return ItemId_GetHoldEffectParam(gBattleMons[battler].item); } bool32 IsMoveMakingContact(u16 move, u8 battlerAtk) @@ -8160,14 +8152,14 @@ bool32 IsMoveMakingContact(u16 move, u8 battlerAtk) } } -bool32 IsBattlerProtected(u8 battlerId, u16 move) +bool32 IsBattlerProtected(u8 battler, u16 move) { // Decorate bypasses protect and detect, but not crafty shield if (move == MOVE_DECORATE) { - if (gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_CRAFTY_SHIELD) + if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_CRAFTY_SHIELD) return TRUE; - else if (gProtectStructs[battlerId].protected) + else if (gProtectStructs[battler].protected) return FALSE; } @@ -8191,26 +8183,26 @@ bool32 IsBattlerProtected(u8 battlerId, u16 move) return FALSE; else if (gBattleMoves[move].effect == EFFECT_FEINT) return FALSE; - else if (gProtectStructs[battlerId].protected) + else if (gProtectStructs[battler].protected) return TRUE; - else if (gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_WIDE_GUARD + else if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_WIDE_GUARD && GetBattlerMoveTargetType(gBattlerAttacker, move) & (MOVE_TARGET_BOTH | MOVE_TARGET_FOES_AND_ALLY)) return TRUE; - else if (gProtectStructs[battlerId].banefulBunkered) + else if (gProtectStructs[battler].banefulBunkered) return TRUE; - else if ((gProtectStructs[battlerId].obstructed || gProtectStructs[battlerId].silkTrapped) && !IS_MOVE_STATUS(move)) + else if ((gProtectStructs[battler].obstructed || gProtectStructs[battler].silkTrapped) && !IS_MOVE_STATUS(move)) return TRUE; - else if (gProtectStructs[battlerId].spikyShielded) + else if (gProtectStructs[battler].spikyShielded) return TRUE; - else if (gProtectStructs[battlerId].kingsShielded && gBattleMoves[move].power != 0) + else if (gProtectStructs[battler].kingsShielded && gBattleMoves[move].power != 0) return TRUE; - else if (gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_QUICK_GUARD + else if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_QUICK_GUARD && GetChosenMovePriority(gBattlerAttacker) > 0) return TRUE; - else if (gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_CRAFTY_SHIELD + else if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_CRAFTY_SHIELD && IS_MOVE_STATUS(move)) return TRUE; - else if (gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_MAT_BLOCK + else if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_MAT_BLOCK && !IS_MOVE_STATUS(move)) return TRUE; else @@ -8218,43 +8210,43 @@ bool32 IsBattlerProtected(u8 battlerId, u16 move) } // Only called directly when calculating damage type effectiveness -static bool32 IsBattlerGrounded2(u8 battlerId, bool32 considerInverse) +static bool32 IsBattlerGrounded2(u8 battler, bool32 considerInverse) { - if (GetBattlerHoldEffect(battlerId, TRUE) == HOLD_EFFECT_IRON_BALL) + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_IRON_BALL) return TRUE; if (gFieldStatuses & STATUS_FIELD_GRAVITY) return TRUE; #if B_ROOTED_GROUNDING >= GEN_4 - if (gStatuses3[battlerId] & STATUS3_ROOTED) + if (gStatuses3[battler] & STATUS3_ROOTED) return TRUE; #endif - if (gStatuses3[battlerId] & STATUS3_SMACKED_DOWN) + if (gStatuses3[battler] & STATUS3_SMACKED_DOWN) return TRUE; - if (gStatuses3[battlerId] & STATUS3_TELEKINESIS) + if (gStatuses3[battler] & STATUS3_TELEKINESIS) return FALSE; - if (gStatuses3[battlerId] & STATUS3_MAGNET_RISE) + if (gStatuses3[battler] & STATUS3_MAGNET_RISE) return FALSE; - if (GetBattlerHoldEffect(battlerId, TRUE) == HOLD_EFFECT_AIR_BALLOON) + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_AIR_BALLOON) return FALSE; - if (GetBattlerAbility(battlerId) == ABILITY_LEVITATE) + if (GetBattlerAbility(battler) == ABILITY_LEVITATE) return FALSE; - if (IS_BATTLER_OF_TYPE(battlerId, TYPE_FLYING) && (!considerInverse || !FlagGet(B_FLAG_INVERSE_BATTLE))) + if (IS_BATTLER_OF_TYPE(battler, TYPE_FLYING) && (!considerInverse || !FlagGet(B_FLAG_INVERSE_BATTLE))) return FALSE; return TRUE; } -bool32 IsBattlerGrounded(u8 battlerId) +bool32 IsBattlerGrounded(u8 battler) { - IsBattlerGrounded2(battlerId, FALSE); + IsBattlerGrounded2(battler, FALSE); } -bool32 IsBattlerAlive(u8 battlerId) +bool32 IsBattlerAlive(u8 battler) { - if (gBattleMons[battlerId].hp == 0) + if (gBattleMons[battler].hp == 0) return FALSE; - else if (battlerId >= gBattlersCount) + else if (battler >= gBattlersCount) return FALSE; - else if (gAbsentBattlerFlags & gBitTable[battlerId]) + else if (gAbsentBattlerFlags & gBitTable[battler]) return FALSE; else return TRUE; @@ -8272,12 +8264,12 @@ u8 GetBattleMonMoveSlot(struct BattlePokemon *battleMon, u16 move) return i; } -u32 GetBattlerWeight(u8 battlerId) +u32 GetBattlerWeight(u8 battler) { u32 i; - u32 weight = GetPokedexHeightWeight(SpeciesToNationalPokedexNum(gBattleMons[battlerId].species), 1); - u32 ability = GetBattlerAbility(battlerId); - u32 holdEffect = GetBattlerHoldEffect(battlerId, TRUE); + u32 weight = GetPokedexHeightWeight(SpeciesToNationalPokedexNum(gBattleMons[battler].species), 1); + u32 ability = GetBattlerAbility(battler); + u32 holdEffect = GetBattlerHoldEffect(battler, TRUE); if (ability == ABILITY_HEAVY_METAL) weight *= 2; @@ -8287,7 +8279,7 @@ u32 GetBattlerWeight(u8 battlerId) if (holdEffect == HOLD_EFFECT_FLOAT_STONE) weight /= 2; - for (i = 0; i < gDisableStructs[battlerId].autotomizeCount; i++) + for (i = 0; i < gDisableStructs[battler].autotomizeCount; i++) { if (weight > 1000) { @@ -8306,7 +8298,7 @@ u32 GetBattlerWeight(u8 battlerId) return weight; } -u32 CountBattlerStatIncreases(u8 battlerId, bool32 countEvasionAcc) +u32 CountBattlerStatIncreases(u8 battler, bool32 countEvasionAcc) { u32 i; u32 count = 0; @@ -8315,8 +8307,8 @@ u32 CountBattlerStatIncreases(u8 battlerId, bool32 countEvasionAcc) { if ((i == STAT_ACC || i == STAT_EVASION) && !countEvasionAcc) continue; - if (gBattleMons[battlerId].statStages[i] > DEFAULT_STAT_STAGE) // Stat is increased. - count += gBattleMons[battlerId].statStages[i] - DEFAULT_STAT_STAGE; + if (gBattleMons[battler].statStages[i] > DEFAULT_STAT_STAGE) // Stat is increased. + count += gBattleMons[battler].statStages[i] - DEFAULT_STAT_STAGE; } return count; @@ -9595,7 +9587,7 @@ static inline uq4_12_t GetScreensModifier(u32 move, u32 battlerAtk, u32 battlerD return UQ_4_12(1.0); if (reflect || lightScreen || auroraVeil) return (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) ? UQ_4_12(0.667) : UQ_4_12(0.5); - return UQ_4_12(1.0); + return UQ_4_12(1.0); } static inline uq4_12_t GetCollisionCourseElectroDriftModifier(u32 move, uq4_12_t typeEffectivenessModifier) @@ -10080,20 +10072,20 @@ s32 GetStealthHazardDamageByTypesAndHP(u8 hazardType, u8 type1, u8 type2, u32 ma return dmg; } -s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId) +s32 GetStealthHazardDamage(u8 hazardType, u8 battler) { - u8 type1 = gBattleMons[battlerId].type1; - u8 type2 = gBattleMons[battlerId].type2; - u32 maxHp = gBattleMons[battlerId].maxHP; + u8 type1 = gBattleMons[battler].type1; + u8 type2 = gBattleMons[battler].type2; + u32 maxHp = gBattleMons[battler].maxHP; return GetStealthHazardDamageByTypesAndHP(hazardType, type1, type2, maxHp); } -bool32 IsPartnerMonFromSameTrainer(u8 battlerId) +bool32 IsPartnerMonFromSameTrainer(u8 battler) { - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) return FALSE; - else if (GetBattlerSide(battlerId) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + else if (GetBattlerSide(battler) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) return FALSE; else if (gBattleTypeFlags & BATTLE_TYPE_MULTI) return FALSE; @@ -10125,16 +10117,16 @@ bool32 DoesSpeciesUseHoldItemToChangeForm(u16 species, u16 heldItemId) return FALSE; } -bool32 CanMegaEvolve(u8 battlerId) +bool32 CanMegaEvolve(u8 battler) { u32 itemId, holdEffect, species; struct Pokemon *mon; - u8 battlerPosition = GetBattlerPosition(battlerId); - u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battlerId)); - struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]))->mega); + u8 battlerPosition = GetBattlerPosition(battler); + u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battler)); + struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]))->mega); // Check if Player has a Mega Ring - if ((GetBattlerPosition(battlerId) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battlerId) == B_POSITION_PLAYER_RIGHT)) + if ((GetBattlerPosition(battler) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT)) && !CheckBagHasItem(ITEM_MEGA_RING, 1)) return FALSE; @@ -10143,34 +10135,34 @@ bool32 CanMegaEvolve(u8 battlerId) return FALSE; // Cannot use z move and mega evolve on same turn - if (gBattleStruct->zmove.toBeUsed[battlerId]) + if (gBattleStruct->zmove.toBeUsed[battler]) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && IsPartnerMonFromSameTrainer(battlerId) - && (mega->alreadyEvolved[partnerPosition] || (mega->toEvolve & gBitTable[BATTLE_PARTNER(battlerId)]))) + && IsPartnerMonFromSameTrainer(battler) + && (mega->alreadyEvolved[partnerPosition] || (mega->toEvolve & gBitTable[BATTLE_PARTNER(battler)]))) return FALSE; // Check if mon is currently held by Sky Drop - if (gStatuses3[battlerId] & STATUS3_SKY_DROPPED) + if (gStatuses3[battler] & STATUS3_SKY_DROPPED) return FALSE; // Gets mon data. - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) - mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) + mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; else - mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; + mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; species = GetMonData(mon, MON_DATA_SPECIES); itemId = GetMonData(mon, MON_DATA_HELD_ITEM); if (itemId == ITEM_ENIGMA_BERRY_E_READER) - holdEffect = gEnigmaBerries[battlerId].holdEffect; + holdEffect = gEnigmaBerries[battler].holdEffect; else holdEffect = ItemId_GetHoldEffect(itemId); // Check if there is an entry in the evolution table for regular Mega Evolution. - if (GetBattleFormChangeTargetSpecies(battlerId, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_ITEM) != SPECIES_NONE) + if (GetBattleFormChangeTargetSpecies(battler, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_ITEM) != SPECIES_NONE) { // Can Mega Evolve via Mega Stone. if (holdEffect == HOLD_EFFECT_MEGA_STONE) @@ -10178,7 +10170,7 @@ bool32 CanMegaEvolve(u8 battlerId) } // Check if there is an entry in the evolution table for Wish Mega Evolution. - if (GetBattleFormChangeTargetSpecies(battlerId, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE) != SPECIES_NONE) + if (GetBattleFormChangeTargetSpecies(battler, FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE) != SPECIES_NONE) { // Can't Wish Mega Evolve if holding a Z Crystal. if (holdEffect != HOLD_EFFECT_Z_CRYSTAL) @@ -10189,15 +10181,15 @@ bool32 CanMegaEvolve(u8 battlerId) return FALSE; } -bool32 CanUltraBurst(u8 battlerId) +bool32 CanUltraBurst(u8 battler) { u32 itemId, holdEffect, species; struct Pokemon *mon; - u8 battlerPosition = GetBattlerPosition(battlerId); - u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battlerId)); + u8 battlerPosition = GetBattlerPosition(battler); + u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battler)); // Check if Player has a Z Ring - if ((GetBattlerPosition(battlerId) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battlerId) == B_POSITION_PLAYER_RIGHT)) + if ((GetBattlerPosition(battler) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT)) && !CheckBagHasItem(ITEM_Z_POWER_RING, 1)) return FALSE; @@ -10206,32 +10198,32 @@ bool32 CanUltraBurst(u8 battlerId) return FALSE; // Cannot use z move and ultra burst on same turn - if (gBattleStruct->zmove.toBeUsed[battlerId]) + if (gBattleStruct->zmove.toBeUsed[battler]) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && IsPartnerMonFromSameTrainer(battlerId) - && (gBattleStruct->burst.alreadyBursted[partnerPosition] || (gBattleStruct->burst.toBurst & gBitTable[BATTLE_PARTNER(battlerId)]))) + && IsPartnerMonFromSameTrainer(battler) + && (gBattleStruct->burst.alreadyBursted[partnerPosition] || (gBattleStruct->burst.toBurst & gBitTable[BATTLE_PARTNER(battler)]))) return FALSE; // Check if mon is currently held by Sky Drop - if (gStatuses3[battlerId] & STATUS3_SKY_DROPPED) + if (gStatuses3[battler] & STATUS3_SKY_DROPPED) return FALSE; - + // Gets mon data. - if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) - mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) + mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; else - mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; + mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; species = GetMonData(mon, MON_DATA_SPECIES); itemId = GetMonData(mon, MON_DATA_HELD_ITEM); // Check if there is an entry in the evolution table for Ultra Burst. - if (GetBattleFormChangeTargetSpecies(battlerId, FORM_CHANGE_BATTLE_ULTRA_BURST) != SPECIES_NONE) + if (GetBattleFormChangeTargetSpecies(battler, FORM_CHANGE_BATTLE_ULTRA_BURST) != SPECIES_NONE) { if (itemId == ITEM_ENIGMA_BERRY_E_READER) - holdEffect = gEnigmaBerries[battlerId].holdEffect; + holdEffect = gEnigmaBerries[battler].holdEffect; else holdEffect = ItemId_GetHoldEffect(itemId); @@ -10244,44 +10236,44 @@ bool32 CanUltraBurst(u8 battlerId) return FALSE; } -bool32 IsBattlerMegaEvolved(u8 battlerId) +bool32 IsBattlerMegaEvolved(u8 battler) { // While Transform does copy stats and visuals, it shouldn't be counted as true Mega Evolution. - if (gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED) + if (gBattleMons[battler].status2 & STATUS2_TRANSFORMED) return FALSE; - return (gSpeciesInfo[gBattleMons[battlerId].species].flags & SPECIES_FLAG_MEGA_EVOLUTION); + return (gSpeciesInfo[gBattleMons[battler].species].flags & SPECIES_FLAG_MEGA_EVOLUTION); } -bool32 IsBattlerPrimalReverted(u8 battlerId) +bool32 IsBattlerPrimalReverted(u8 battler) { // While Transform does copy stats and visuals, it shouldn't be counted as true Primal Revesion. - if (gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED) + if (gBattleMons[battler].status2 & STATUS2_TRANSFORMED) return FALSE; - return (gSpeciesInfo[gBattleMons[battlerId].species].flags & SPECIES_FLAG_PRIMAL_REVERSION); + return (gSpeciesInfo[gBattleMons[battler].species].flags & SPECIES_FLAG_PRIMAL_REVERSION); } -bool32 IsBattlerUltraBursted(u8 battlerId) +bool32 IsBattlerUltraBursted(u8 battler) { // While Transform does copy stats and visuals, it shouldn't be counted as true Ultra Burst. - if (gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED) + if (gBattleMons[battler].status2 & STATUS2_TRANSFORMED) return FALSE; - return (gSpeciesInfo[gBattleMons[battlerId].species].flags & SPECIES_FLAG_ULTRA_BURST); + return (gSpeciesInfo[gBattleMons[battler].species].flags & SPECIES_FLAG_ULTRA_BURST); } // Returns SPECIES_NONE if no form change is possible -u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method) +u16 GetBattleFormChangeTargetSpecies(u8 battler, u16 method) { u32 i, j; u16 targetSpecies = SPECIES_NONE; - u16 species = gBattleMons[battlerId].species; + u16 species = gBattleMons[battler].species; const struct FormChange *formChanges = gFormChangeTablePointers[species]; u16 heldItem; u32 ability; if (formChanges != NULL) { - heldItem = gBattleMons[battlerId].item; - ability = GetBattlerAbility(battlerId); + heldItem = gBattleMons[battler].item; + ability = GetBattlerAbility(battler); for (i = 0; formChanges[i].method != FORM_CHANGE_TERMINATOR; i++) { @@ -10296,20 +10288,20 @@ u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method) targetSpecies = formChanges[i].targetSpecies; break; case FORM_CHANGE_BATTLE_MEGA_EVOLUTION_MOVE: - if (gBattleMons[battlerId].moves[0] == formChanges[i].param1 - || gBattleMons[battlerId].moves[1] == formChanges[i].param1 - || gBattleMons[battlerId].moves[2] == formChanges[i].param1 - || gBattleMons[battlerId].moves[3] == formChanges[i].param1) + if (gBattleMons[battler].moves[0] == formChanges[i].param1 + || gBattleMons[battler].moves[1] == formChanges[i].param1 + || gBattleMons[battler].moves[2] == formChanges[i].param1 + || gBattleMons[battler].moves[3] == formChanges[i].param1) targetSpecies = formChanges[i].targetSpecies; break; case FORM_CHANGE_BATTLE_SWITCH: targetSpecies = formChanges[i].targetSpecies; break; case FORM_CHANGE_BATTLE_HP_PERCENT: - if (formChanges[i].param1 == GetBattlerAbility(battlerId)) + if (formChanges[i].param1 == GetBattlerAbility(battler)) { // We multiply by 100 to make sure that integer division doesn't mess with the health check. - u32 hpCheck = gBattleMons[battlerId].hp * 100 * 100 / gBattleMons[battlerId].maxHP; + u32 hpCheck = gBattleMons[battler].hp * 100 * 100 / gBattleMons[battler].maxHP; switch(formChanges[i].param2) { case HP_HIGHER_THAN: @@ -10327,7 +10319,7 @@ u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method) // Check if there is a required ability and if the battler's ability does not match it // or is suppressed. If so, revert to the no weather form. if (formChanges[i].param2 - && GetBattlerAbility(battlerId) != formChanges[i].param2 + && GetBattlerAbility(battler) != formChanges[i].param2 && formChanges[i].param1 == B_WEATHER_NONE) { targetSpecies = formChanges[i].targetSpecies; @@ -10345,7 +10337,7 @@ u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method) } break; case FORM_CHANGE_BATTLE_TURN_END: - if (formChanges[i].param1 == GetBattlerAbility(battlerId)) + if (formChanges[i].param1 == GetBattlerAbility(battler)) targetSpecies = formChanges[i].targetSpecies; break; } @@ -10356,43 +10348,43 @@ u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method) return targetSpecies; } -bool32 CanBattlerFormChange(u8 battlerId, u16 method) +bool32 CanBattlerFormChange(u8 battler, u16 method) { // Can't change form if transformed. - if (gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED + if (gBattleMons[battler].status2 & STATUS2_TRANSFORMED && B_TRANSFORM_FORM_CHANGES >= GEN_5) return FALSE; // Mega Evolved and Ultra Bursted Pokémon should always revert to normal upon fainting or ending the battle. - if ((IsBattlerMegaEvolved(battlerId) || IsBattlerUltraBursted(battlerId)) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_END_BATTLE)) + if ((IsBattlerMegaEvolved(battler) || IsBattlerUltraBursted(battler)) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_END_BATTLE)) return TRUE; - else if (IsBattlerPrimalReverted(battlerId) && (method == FORM_CHANGE_END_BATTLE)) + else if (IsBattlerPrimalReverted(battler) && (method == FORM_CHANGE_END_BATTLE)) return TRUE; - return DoesSpeciesHaveFormChangeMethod(gBattleMons[battlerId].species, method); + return DoesSpeciesHaveFormChangeMethod(gBattleMons[battler].species, method); } -bool32 TryBattleFormChange(u8 battlerId, u16 method) +bool32 TryBattleFormChange(u8 battler, u16 method) { - u8 monId = gBattlerPartyIndexes[battlerId]; - u8 side = GET_BATTLER_SIDE(battlerId); - struct Pokemon *party = GetBattlerParty(battlerId); + u8 monId = gBattlerPartyIndexes[battler]; + u8 side = GET_BATTLER_SIDE(battler); + struct Pokemon *party = GetBattlerParty(battler); u16 targetSpecies; - if (!CanBattlerFormChange(battlerId, method)) + if (!CanBattlerFormChange(battler, method)) return FALSE; - targetSpecies = GetBattleFormChangeTargetSpecies(battlerId, method); + targetSpecies = GetBattleFormChangeTargetSpecies(battler, method); if (targetSpecies == SPECIES_NONE) targetSpecies = GetFormChangeTargetSpecies(&party[monId], method, 0); if (targetSpecies != SPECIES_NONE) { // Saves the original species on the first form change for the player. if (gBattleStruct->changedSpecies[side][monId] == SPECIES_NONE) - gBattleStruct->changedSpecies[side][monId] = gBattleMons[battlerId].species; + gBattleStruct->changedSpecies[side][monId] = gBattleMons[battler].species; TryToSetBattleFormChangeMoves(&party[monId], method); SetMonData(&party[monId], MON_DATA_SPECIES, &targetSpecies); - gBattleMons[battlerId].species = targetSpecies; - RecalcBattlerStats(battlerId, &party[monId]); + gBattleMons[battler].species = targetSpecies; + RecalcBattlerStats(battler, &party[monId]); return TRUE; } else if (gBattleStruct->changedSpecies[side][monId] != SPECIES_NONE) @@ -10400,11 +10392,11 @@ bool32 TryBattleFormChange(u8 battlerId, u16 method) bool8 restoreSpecies = FALSE; // Mega Evolved and Ultra Bursted Pokémon should always revert to normal upon fainting or ending the battle, so no need to add it to the form change tables. - if ((IsBattlerMegaEvolved(battlerId) || IsBattlerUltraBursted(battlerId)) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_END_BATTLE)) + if ((IsBattlerMegaEvolved(battler) || IsBattlerUltraBursted(battler)) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_END_BATTLE)) restoreSpecies = TRUE; // Unlike Megas, Primal Reversion isn't canceled on fainting. - else if (IsBattlerPrimalReverted(battlerId) && (method == FORM_CHANGE_END_BATTLE)) + else if (IsBattlerPrimalReverted(battler) && (method == FORM_CHANGE_END_BATTLE)) restoreSpecies = TRUE; if (restoreSpecies) @@ -10412,7 +10404,7 @@ bool32 TryBattleFormChange(u8 battlerId, u16 method) // Reverts the original species TryToSetBattleFormChangeMoves(&party[monId], method); SetMonData(&party[monId], MON_DATA_SPECIES, &gBattleStruct->changedSpecies[side][monId]); - RecalcBattlerStats(battlerId, &party[monId]); + RecalcBattlerStats(battler, &party[monId]); return TRUE; } } @@ -10440,9 +10432,9 @@ bool32 DoBattlersShareType(u32 battler1, u32 battler2) return FALSE; } -bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId) +bool32 CanBattlerGetOrLoseItem(u8 battler, u16 itemId) { - u16 species = gBattleMons[battlerId].species; + u16 species = gBattleMons[battler].species; u16 holdEffect = ItemId_GetHoldEffect(itemId); // Mail can be stolen now @@ -10456,56 +10448,56 @@ bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId) return TRUE; } -struct Pokemon *GetIllusionMonPtr(u32 battlerId) +struct Pokemon *GetIllusionMonPtr(u32 battler) { - if (gBattleStruct->illusion[battlerId].broken) + if (gBattleStruct->illusion[battler].broken) return NULL; - if (!gBattleStruct->illusion[battlerId].set) + if (!gBattleStruct->illusion[battler].set) { - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) - SetIllusionMon(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + SetIllusionMon(&gPlayerParty[gBattlerPartyIndexes[battler]], battler); else - SetIllusionMon(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); + SetIllusionMon(&gEnemyParty[gBattlerPartyIndexes[battler]], battler); } - if (!gBattleStruct->illusion[battlerId].on) + if (!gBattleStruct->illusion[battler].on) return NULL; - return gBattleStruct->illusion[battlerId].mon; + return gBattleStruct->illusion[battler].mon; } -void ClearIllusionMon(u32 battlerId) +void ClearIllusionMon(u32 battler) { - memset(&gBattleStruct->illusion[battlerId], 0, sizeof(gBattleStruct->illusion[battlerId])); + memset(&gBattleStruct->illusion[battler], 0, sizeof(gBattleStruct->illusion[battler])); } -u32 GetIllusionMonSpecies(u32 battlerId) +u32 GetIllusionMonSpecies(u32 battler) { - struct Pokemon *illusionMon = GetIllusionMonPtr(battlerId); + struct Pokemon *illusionMon = GetIllusionMonPtr(battler); if (illusionMon != NULL) return GetMonData(illusionMon, MON_DATA_SPECIES); return SPECIES_NONE; } -bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId) +bool32 SetIllusionMon(struct Pokemon *mon, u32 battler) { struct Pokemon *party, *partnerMon; s32 i, id; u8 side, partyCount; - gBattleStruct->illusion[battlerId].set = 1; + gBattleStruct->illusion[battler].set = 1; if (GetMonAbility(mon) != ABILITY_ILLUSION) return FALSE; - party = GetBattlerParty(battlerId); - side = GetBattlerSide(battlerId); + party = GetBattlerParty(battler); + side = GetBattlerSide(battler); partyCount = side == B_SIDE_PLAYER ? gPlayerPartyCount : gEnemyPartyCount; // If this pokemon is last in the party, ignore Illusion. if (&party[partyCount - 1] == mon) return FALSE; - if (IsBattlerAlive(BATTLE_PARTNER(battlerId))) - partnerMon = &party[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]]; + if (IsBattlerAlive(BATTLE_PARTNER(battler))) + partnerMon = &party[gBattlerPartyIndexes[BATTLE_PARTNER(battler)]]; else partnerMon = mon; @@ -10519,10 +10511,10 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId) && &party[id] != mon && &party[id] != partnerMon) { - gBattleStruct->illusion[battlerId].on = 1; - gBattleStruct->illusion[battlerId].broken = 0; - gBattleStruct->illusion[battlerId].partyId = id; - gBattleStruct->illusion[battlerId].mon = &party[id]; + gBattleStruct->illusion[battler].on = 1; + gBattleStruct->illusion[battler].broken = 0; + gBattleStruct->illusion[battler].partyId = id; + gBattleStruct->illusion[battler].mon = &party[id]; return TRUE; } } @@ -10530,12 +10522,12 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId) return FALSE; } -bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) +bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battler) { #if B_BADGE_BOOST == GEN_3 if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_FRONTIER)) return FALSE; - else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) + else if (GetBattlerSide(battler) != B_SIDE_PLAYER) return FALSE; else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) return FALSE; @@ -10593,26 +10585,26 @@ static bool32 TryRemoveScreens(u8 battler) return removed; } -static bool32 IsUnnerveAbilityOnOpposingSide(u8 battlerId) +static bool32 IsUnnerveAbilityOnOpposingSide(u8 battler) { - if (IsAbilityOnOpposingSide(battlerId, ABILITY_UNNERVE) - || IsAbilityOnOpposingSide(battlerId, ABILITY_AS_ONE_ICE_RIDER) - || IsAbilityOnOpposingSide(battlerId, ABILITY_AS_ONE_SHADOW_RIDER)) + if (IsAbilityOnOpposingSide(battler, ABILITY_UNNERVE) + || IsAbilityOnOpposingSide(battler, ABILITY_AS_ONE_ICE_RIDER) + || IsAbilityOnOpposingSide(battler, ABILITY_AS_ONE_SHADOW_RIDER)) return TRUE; return FALSE; } // Photon geyser & light that burns the sky -u8 GetSplitBasedOnStats(u8 battlerId) +u8 GetSplitBasedOnStats(u8 battler) { - u32 attack = gBattleMons[battlerId].attack; - u32 spAttack = gBattleMons[battlerId].spAttack; + u32 attack = gBattleMons[battler].attack; + u32 spAttack = gBattleMons[battler].spAttack; - attack = attack * gStatStageRatios[gBattleMons[battlerId].statStages[STAT_ATK]][0]; - attack = attack / gStatStageRatios[gBattleMons[battlerId].statStages[STAT_ATK]][1]; + attack = attack * gStatStageRatios[gBattleMons[battler].statStages[STAT_ATK]][0]; + attack = attack / gStatStageRatios[gBattleMons[battler].statStages[STAT_ATK]][1]; - spAttack = spAttack * gStatStageRatios[gBattleMons[battlerId].statStages[STAT_SPATK]][0]; - spAttack = spAttack / gStatStageRatios[gBattleMons[battlerId].statStages[STAT_SPATK]][1]; + spAttack = spAttack * gStatStageRatios[gBattleMons[battler].statStages[STAT_SPATK]][0]; + spAttack = spAttack / gStatStageRatios[gBattleMons[battler].statStages[STAT_SPATK]][1]; if (spAttack >= attack) return SPLIT_SPECIAL; @@ -10634,19 +10626,19 @@ static u8 GetFlingPowerFromItemId(u16 itemId) } // Make sure the input bank is any bank on the specific mon's side -bool32 CanFling(u8 battlerId) +bool32 CanFling(u8 battler) { - u16 item = gBattleMons[battlerId].item; + u16 item = gBattleMons[battler].item; u16 itemEffect = ItemId_GetHoldEffect(item); if (item == ITEM_NONE #if B_KLUTZ_FLING_INTERACTION >= GEN_5 - || GetBattlerAbility(battlerId) == ABILITY_KLUTZ + || GetBattlerAbility(battler) == ABILITY_KLUTZ #endif || gFieldStatuses & STATUS_FIELD_MAGIC_ROOM - || gDisableStructs[battlerId].embargoTimer != 0 + || gDisableStructs[battler].embargoTimer != 0 || GetFlingPowerFromItemId(item) == 0 - || !CanBattlerGetOrLoseItem(battlerId, item)) + || !CanBattlerGetOrLoseItem(battler, item)) return FALSE; return TRUE; @@ -10828,7 +10820,7 @@ bool32 CanStealItem(u8 battlerStealing, u8 battlerItem, u16 item) return TRUE; } -void TrySaveExchangedItem(u8 battlerId, u16 stolenItem) +void TrySaveExchangedItem(u8 battler, u16 stolenItem) { // Because BtlController_EmitSetMonData does SetMonData, we need to save the stolen item only if it matches the battler's original // So, if the player steals an item during battle and has it stolen from it, it will not end the battle with it (naturally) @@ -10836,25 +10828,25 @@ void TrySaveExchangedItem(u8 battlerId, u16 stolenItem) // If regular trainer battle and mon's original item matches what is being stolen, save it to be restored at end of battle if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & BATTLE_TYPE_FRONTIER) - && GetBattlerSide(battlerId) == B_SIDE_PLAYER - && stolenItem == gBattleStruct->itemLost[gBattlerPartyIndexes[battlerId]].originalItem) - gBattleStruct->itemLost[gBattlerPartyIndexes[battlerId]].stolen = TRUE; + && GetBattlerSide(battler) == B_SIDE_PLAYER + && stolenItem == gBattleStruct->itemLost[gBattlerPartyIndexes[battler]].originalItem) + gBattleStruct->itemLost[gBattlerPartyIndexes[battler]].stolen = TRUE; #endif } -bool32 IsBattlerAffectedByHazards(u8 battlerId, bool32 toxicSpikes) +bool32 IsBattlerAffectedByHazards(u8 battler, bool32 toxicSpikes) { bool32 ret = TRUE; - u32 holdEffect = GetBattlerHoldEffect(battlerId, TRUE); - if (toxicSpikes && holdEffect == HOLD_EFFECT_HEAVY_DUTY_BOOTS && !IS_BATTLER_OF_TYPE(battlerId, TYPE_POISON)) + u32 holdEffect = GetBattlerHoldEffect(battler, TRUE); + if (toxicSpikes && holdEffect == HOLD_EFFECT_HEAVY_DUTY_BOOTS && !IS_BATTLER_OF_TYPE(battler, TYPE_POISON)) { ret = FALSE; - RecordItemEffectBattle(battlerId, holdEffect); + RecordItemEffectBattle(battler, holdEffect); } else if (holdEffect == HOLD_EFFECT_HEAVY_DUTY_BOOTS) { ret = FALSE; - RecordItemEffectBattle(battlerId, holdEffect); + RecordItemEffectBattle(battler, holdEffect); } return ret; } @@ -10868,14 +10860,14 @@ bool32 TestSheerForceFlag(u8 battler, u16 move) } // This function is the body of "jumpifstat", but can be used dynamically in a function -bool32 CompareStat(u8 battlerId, u8 statId, u8 cmpTo, u8 cmpKind) +bool32 CompareStat(u8 battler, u8 statId, u8 cmpTo, u8 cmpKind) { bool8 ret = FALSE; - u8 statValue = gBattleMons[battlerId].statStages[statId]; + u8 statValue = gBattleMons[battler].statStages[statId]; // Because this command is used as a way of checking if a stat can be lowered/raised, // we need to do some modification at run-time. - if (GetBattlerAbility(battlerId) == ABILITY_CONTRARY) + if (GetBattlerAbility(battler) == ABILITY_CONTRARY) { if (cmpKind == CMP_GREATER_THAN) cmpKind = CMP_LESS_THAN; @@ -10919,9 +10911,9 @@ bool32 CompareStat(u8 battlerId, u8 statId, u8 cmpTo, u8 cmpKind) return ret; } -void BufferStatChange(u8 battlerId, u8 statId, u8 stringId) +void BufferStatChange(u8 battler, u8 statId, u8 stringId) { - bool8 hasContrary = (GetBattlerAbility(battlerId) == ABILITY_CONTRARY); + bool8 hasContrary = (GetBattlerAbility(battler) == ABILITY_CONTRARY); PREPARE_STAT_BUFFER(gBattleTextBuff1, statId); if (stringId == STRINGID_STATFELL) @@ -10944,16 +10936,16 @@ void BufferStatChange(u8 battlerId, u8 statId, u8 stringId) } } -bool32 TryRoomService(u8 battlerId) +bool32 TryRoomService(u8 battler) { - if (gFieldStatuses & STATUS_FIELD_TRICK_ROOM && CompareStat(battlerId, STAT_SPEED, MIN_STAT_STAGE, CMP_GREATER_THAN)) + if (gFieldStatuses & STATUS_FIELD_TRICK_ROOM && CompareStat(battler, STAT_SPEED, MIN_STAT_STAGE, CMP_GREATER_THAN)) { - BufferStatChange(battlerId, STAT_SPEED, STRINGID_STATFELL); - gEffectBattler = gBattleScripting.battler = battlerId; + BufferStatChange(battler, STAT_SPEED, STRINGID_STATFELL); + gEffectBattler = gBattleScripting.battler = battler; SET_STATCHANGER(STAT_SPEED, 1, TRUE); gBattleScripting.animArg1 = 14 + STAT_SPEED; gBattleScripting.animArg2 = 0; - gLastUsedItem = gBattleMons[battlerId].item; + gLastUsedItem = gBattleMons[battler].item; return TRUE; } else @@ -10986,12 +10978,12 @@ u16 GetUsedHeldItem(u8 battler) return gBattleStruct->usedHeldItems[gBattlerPartyIndexes[battler]][GetBattlerSide(battler)]; } -bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags) +bool32 IsBattlerWeatherAffected(u8 battler, u32 weatherFlags) { if (gBattleWeather & weatherFlags && WEATHER_HAS_EFFECT) { // given weather is active -> check if its sun, rain against utility umbrella ( since only 1 weather can be active at once) - if (gBattleWeather & (B_WEATHER_SUN | B_WEATHER_RAIN) && GetBattlerHoldEffect(battlerId, TRUE) == HOLD_EFFECT_UTILITY_UMBRELLA) + if (gBattleWeather & (B_WEATHER_SUN | B_WEATHER_RAIN) && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_UTILITY_UMBRELLA) return FALSE; // utility umbrella blocks sun, rain effects return TRUE; @@ -11001,12 +10993,12 @@ bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags) // Gets move target before redirection effects etc. are applied // Possible return values are defined in battle.h following MOVE_TARGET_SELECTED -u32 GetBattlerMoveTargetType(u8 battlerId, u16 move) +u32 GetBattlerMoveTargetType(u8 battler, u16 move) { u32 target; if (gBattleMoves[move].effect == EFFECT_EXPANDING_FORCE - && IsBattlerTerrainAffected(battlerId, STATUS_FIELD_PSYCHIC_TERRAIN)) + && IsBattlerTerrainAffected(battler, STATUS_FIELD_PSYCHIC_TERRAIN)) return MOVE_TARGET_BOTH; else return gBattleMoves[move].target; @@ -11066,27 +11058,27 @@ void RecalcBattlerStats(u32 battler, struct Pokemon *mon) CopyMonAbilityAndTypesToBattleMon(battler, mon); } -void RemoveConfusionStatus(u8 battlerId) +void RemoveConfusionStatus(u8 battler) { - gBattleMons[battlerId].status2 &= ~STATUS2_CONFUSION; - gStatuses4[battlerId] &= ~STATUS4_INFINITE_CONFUSION; + gBattleMons[battler].status2 &= ~STATUS2_CONFUSION; + gStatuses4[battler] &= ~STATUS4_INFINITE_CONFUSION; } -static bool8 CanBeInfinitelyConfused(u8 battlerId) +static bool8 CanBeInfinitelyConfused(u8 battler) { - if (gBattleMons[battlerId].ability == ABILITY_OWN_TEMPO - || IsBattlerTerrainAffected(battlerId, STATUS_FIELD_MISTY_TERRAIN) - || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_SAFEGUARD) + if (gBattleMons[battler].ability == ABILITY_OWN_TEMPO + || IsBattlerTerrainAffected(battler, STATUS_FIELD_MISTY_TERRAIN) + || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD) { return FALSE; } return TRUE; } -u8 GetBattlerGender(u8 battlerId) +u8 GetBattlerGender(u8 battler) { - return GetGenderFromSpeciesAndPersonality(gBattleMons[battlerId].species, - gBattleMons[battlerId].personality); + return GetGenderFromSpeciesAndPersonality(gBattleMons[battler].species, + gBattleMons[battler].personality); } bool8 AreBattlersOfOppositeGender(u8 battler1, u8 battler2) @@ -11097,9 +11089,9 @@ bool8 AreBattlersOfOppositeGender(u8 battler1, u8 battler2) return (gender1 != MON_GENDERLESS && gender2 != MON_GENDERLESS && gender1 != gender2); } -u32 CalcSecondaryEffectChance(u8 battlerId, u8 secondaryEffectChance) +u32 CalcSecondaryEffectChance(u8 battler, u8 secondaryEffectChance) { - if (GetBattlerAbility(battlerId) == ABILITY_SERENE_GRACE) + if (GetBattlerAbility(battler) == ABILITY_SERENE_GRACE) secondaryEffectChance *= 2; return secondaryEffectChance; diff --git a/src/battle_util2.c b/src/battle_util2.c index 0f04a6eb4..8dda3004c 100644 --- a/src/battle_util2.c +++ b/src/battle_util2.c @@ -72,7 +72,7 @@ void FreeBattleResources(void) } } -void AdjustFriendshipOnBattleFaint(u8 battlerId) +void AdjustFriendshipOnBattleFaint(u8 battler) { u8 opposingBattlerId; @@ -91,28 +91,28 @@ void AdjustFriendshipOnBattleFaint(u8 battlerId) opposingBattlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); } - if (gBattleMons[opposingBattlerId].level > gBattleMons[battlerId].level) + if (gBattleMons[opposingBattlerId].level > gBattleMons[battler].level) { - if (gBattleMons[opposingBattlerId].level - gBattleMons[battlerId].level > 29) - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_LARGE); + if (gBattleMons[opposingBattlerId].level - gBattleMons[battler].level > 29) + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battler]], FRIENDSHIP_EVENT_FAINT_LARGE); else - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL); + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battler]], FRIENDSHIP_EVENT_FAINT_SMALL); } else { - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL); + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battler]], FRIENDSHIP_EVENT_FAINT_SMALL); } } -void SwitchPartyOrderInGameMulti(u8 battlerId, u8 arg1) +void SwitchPartyOrderInGameMulti(u8 battler, u8 arg1) { - if (GetBattlerSide(battlerId) != B_SIDE_OPPONENT) + if (GetBattlerSide(battler) != B_SIDE_OPPONENT) { s32 i; for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) gBattlePartyCurrentOrder[i] = *(0 * 3 + i + (u8 *)(gBattleStruct->battlerPartyOrders)); - SwitchPartyMonSlots(GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battlerId]), GetPartyIdFromBattlePartyId(arg1)); + SwitchPartyMonSlots(GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battler]), GetPartyIdFromBattlePartyId(arg1)); for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) *(0 * 3 + i + (u8 *)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i]; @@ -121,7 +121,7 @@ void SwitchPartyOrderInGameMulti(u8 battlerId, u8 arg1) // Called when a Pokémon is unable to attack during a Battle Palace battle. // Check if it was because they are frozen/asleep, and if so try to cure the status. -u32 BattlePalace_TryEscapeStatus(u8 battlerId) +u32 BattlePalace_TryEscapeStatus(u8 battler) { u32 effect = 0; @@ -130,13 +130,13 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) switch (gBattleCommunication[MULTIUSE_STATE]) { case 0: - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { - if (UproarWakeUpCheck(battlerId)) + if (UproarWakeUpCheck(battler)) { // Wake up from Uproar - gBattleMons[battlerId].status1 &= ~(STATUS1_SLEEP); - gBattleMons[battlerId].status2 &= ~(STATUS2_NIGHTMARE); + gBattleMons[battler].status1 &= ~(STATUS1_SLEEP); + gBattleMons[battler].status2 &= ~(STATUS2_NIGHTMARE); BattleScriptPushCursor(); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WOKE_UP_UPROAR; gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; @@ -146,18 +146,18 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) { u32 toSub; - if (GetBattlerAbility(battlerId) == ABILITY_EARLY_BIRD) + if (GetBattlerAbility(battler) == ABILITY_EARLY_BIRD) toSub = 2; else toSub = 1; // Reduce number of sleep turns - if ((gBattleMons[battlerId].status1 & STATUS1_SLEEP) < toSub) - gBattleMons[battlerId].status1 &= ~(STATUS1_SLEEP); + if ((gBattleMons[battler].status1 & STATUS1_SLEEP) < toSub) + gBattleMons[battler].status1 &= ~(STATUS1_SLEEP); else - gBattleMons[battlerId].status1 -= toSub; + gBattleMons[battler].status1 -= toSub; - if (gBattleMons[battlerId].status1 & STATUS1_SLEEP) + if (gBattleMons[battler].status1 & STATUS1_SLEEP) { // Still asleep gBattlescriptCurrInstr = BattleScript_MoveUsedIsAsleep; @@ -166,7 +166,7 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) else { // Wake up - gBattleMons[battlerId].status2 &= ~(STATUS2_NIGHTMARE); + gBattleMons[battler].status2 &= ~(STATUS2_NIGHTMARE); BattleScriptPushCursor(); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WOKE_UP; gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; @@ -177,7 +177,7 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) gBattleCommunication[MULTIUSE_STATE]++; break; case 1: - if (gBattleMons[battlerId].status1 & STATUS1_FREEZE) + if (gBattleMons[battler].status1 & STATUS1_FREEZE) { if (Random() % 5 != 0) { @@ -187,7 +187,7 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) else { // Unfreeze - gBattleMons[battlerId].status1 &= ~(STATUS1_FREEZE); + gBattleMons[battler].status1 &= ~(STATUS1_FREEZE); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_MoveUsedUnfroze; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DEFROSTED; @@ -204,9 +204,8 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) if (effect == 2) { - gActiveBattler = battlerId; - BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + MarkBattlerForControllerExec(battler); } return effect; diff --git a/src/battle_z_move.c b/src/battle_z_move.c index 3983f96b9..d760148b5 100644 --- a/src/battle_z_move.c +++ b/src/battle_z_move.c @@ -48,12 +48,12 @@ static void SpriteCB_ZMoveTrigger(struct Sprite *sprite); static u16 GetSignatureZMove(u16 move, u16 species, u16 item); static u16 GetTypeBasedZMove(u16 move, u8 battler); -static void ZMoveSelectionDisplayPpNumber(void); +static void ZMoveSelectionDisplayPpNumber(u32 battler); static void ZMoveSelectionDisplayPower(u16 move, u16 zMove); static void ShowZMoveTriggerSprite(u8 battleId); -static bool32 AreStatsMaxed(u8 battlerId, u8 n); +static bool32 AreStatsMaxed(u8 battler, u8 n); static u8 GetZMoveScore(u8 battlerAtk, u8 battlerDef, u16 baseMove, u16 zMove); -static void ZMoveSelectionDisplayMoveType(u16 zMove); +static void ZMoveSelectionDisplayMoveType(u16 zMove, u32 battler); // Const Data static const struct SignatureZMove sSignatureZMoves[] = @@ -146,52 +146,52 @@ bool8 IsZMove(u16 move) return move >= FIRST_Z_MOVE && move <= LAST_Z_MOVE; } -void QueueZMove(u8 battlerId, u16 baseMove) +void QueueZMove(u8 battler, u16 baseMove) { - gBattleStruct->zmove.toBeUsed[battlerId] = gBattleStruct->zmove.chosenZMove; - gBattleStruct->zmove.baseMoves[battlerId] = baseMove; + gBattleStruct->zmove.toBeUsed[battler] = gBattleStruct->zmove.chosenZMove; + gBattleStruct->zmove.baseMoves[battler] = baseMove; if (gBattleStruct->zmove.chosenZMove == MOVE_LIGHT_THAT_BURNS_THE_SKY) - gBattleStruct->zmove.splits[battlerId] = GetSplitBasedOnStats(battlerId); + gBattleStruct->zmove.splits[battler] = GetSplitBasedOnStats(battler); else - gBattleStruct->zmove.splits[battlerId] = gBattleMoves[baseMove].split; + gBattleStruct->zmove.splits[battler] = gBattleMoves[baseMove].split; } -bool32 IsViableZMove(u8 battlerId, u16 move) +bool32 IsViableZMove(u8 battler, u16 move) { struct Pokemon *mon; - u8 battlerPosition = GetBattlerPosition(battlerId); - u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battlerId)); + u8 battlerPosition = GetBattlerPosition(battler); + u8 partnerPosition = GetBattlerPosition(BATTLE_PARTNER(battler)); u32 item; u16 holdEffect; u16 species; int moveSlotIndex; - species = gBattleMons[battlerId].species; - item = gBattleMons[battlerId].item; + species = gBattleMons[battler].species; + item = gBattleMons[battler].item; for (moveSlotIndex = 0; moveSlotIndex < MAX_MON_MOVES; moveSlotIndex++) { - if (gBattleMons[battlerId].moves[moveSlotIndex] == move && gBattleMons[battlerId].pp[moveSlotIndex] == 0) + if (gBattleMons[battler].moves[moveSlotIndex] == move && gBattleMons[battler].pp[moveSlotIndex] == 0) return FALSE; } - if (gBattleStruct->zmove.used[battlerId]) + if (gBattleStruct->zmove.used[battler]) return FALSE; if (gBattleTypeFlags & (BATTLE_TYPE_SAFARI | BATTLE_TYPE_WALLY_TUTORIAL | BATTLE_TYPE_FRONTIER)) return FALSE; - if ((GetBattlerPosition(battlerId) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battlerId) == B_POSITION_PLAYER_RIGHT)) && !CheckBagHasItem(ITEM_Z_POWER_RING, 1)) + if ((GetBattlerPosition(battler) == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT)) && !CheckBagHasItem(ITEM_Z_POWER_RING, 1)) return FALSE; if (item == ITEM_ENIGMA_BERRY_E_READER) - return FALSE; // HoldEffect = gEnigmaBerries[battlerId].holdEffect; + return FALSE; // HoldEffect = gEnigmaBerries[battler].holdEffect; else holdEffect = ItemId_GetHoldEffect(item); if (holdEffect == HOLD_EFFECT_Z_CRYSTAL) { - u16 zMove = GetSignatureZMove(move, gBattleMons[battlerId].species, item); + u16 zMove = GetSignatureZMove(move, gBattleMons[battler].species, item); if (zMove != MOVE_NONE) { gBattleStruct->zmove.chosenZMove = zMove; // Signature z move exists @@ -200,7 +200,7 @@ bool32 IsViableZMove(u8 battlerId, u16 move) if (move != MOVE_NONE && zMove != MOVE_Z_STATUS && gBattleMoves[move].type == ItemId_GetSecondaryId(item)) { - gBattleStruct->zmove.chosenZMove = GetTypeBasedZMove(move, battlerId); + gBattleStruct->zmove.chosenZMove = GetTypeBasedZMove(move, battler); return TRUE; } } @@ -208,34 +208,34 @@ bool32 IsViableZMove(u8 battlerId, u16 move) return FALSE; } -void GetUsableZMoves(u8 battlerId, u16 *moves) +void GetUsableZMoves(u8 battler, u16 *moves) { u32 i; - gBattleStruct->zmove.possibleZMoves[battlerId] = 0; + gBattleStruct->zmove.possibleZMoves[battler] = 0; for (i = 0; i < MAX_MON_MOVES; i++) { - if (moves[i] != MOVE_NONE && IsViableZMove(battlerId, moves[i])) - gBattleStruct->zmove.possibleZMoves[battlerId] |= (1 << i); + if (moves[i] != MOVE_NONE && IsViableZMove(battler, moves[i])) + gBattleStruct->zmove.possibleZMoves[battler] |= (1 << i); } } -bool32 IsZMoveUsable(u8 battlerId, u16 moveIndex) +bool32 IsZMoveUsable(u8 battler, u16 moveIndex) { - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && IsPartnerMonFromSameTrainer(battlerId) && gBattleStruct->zmove.toBeUsed[BATTLE_PARTNER(battlerId)] != MOVE_NONE) + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && IsPartnerMonFromSameTrainer(battler) && gBattleStruct->zmove.toBeUsed[BATTLE_PARTNER(battler)] != MOVE_NONE) return FALSE; // Player's other mon has a z move queued up already - if (gBattleStruct->zmove.possibleZMoves[battlerId] & (1 << moveIndex)) + if (gBattleStruct->zmove.possibleZMoves[battler] & (1 << moveIndex)) return TRUE; return FALSE; } -bool32 TryChangeZIndicator(u8 battlerId, u8 moveIndex) +bool32 TryChangeZIndicator(u8 battler, u8 moveIndex) { - bool32 viableZMove = IsZMoveUsable(battlerId, moveIndex); + bool32 viableZMove = IsZMoveUsable(battler, moveIndex); if (gBattleStruct->zmove.viable && !viableZMove) HideZMoveTriggerSprite(); // Was a viable z move, now is not -> slide out else if (!gBattleStruct->zmove.viable && viableZMove) - ShowZMoveTriggerSprite(battlerId); // Was not a viable z move, now is -> slide back in + ShowZMoveTriggerSprite(battler); // Was not a viable z move, now is -> slide back in } #define SINGLES_Z_TRIGGER_POS_X_OPTIMAL (29) @@ -251,7 +251,7 @@ bool32 TryChangeZIndicator(u8 battlerId, u8 moveIndex) #define tBattler data[0] #define tHide data[1] -void CreateZMoveTriggerSprite(u8 battlerId, bool8 viable) +void CreateZMoveTriggerSprite(u8 battler, bool8 viable) { s16 x, y; @@ -261,19 +261,19 @@ void CreateZMoveTriggerSprite(u8 battlerId, bool8 viable) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - x = gSprites[gHealthboxSpriteIds[battlerId]].x - DOUBLES_Z_TRIGGER_POS_X_SLIDE; - y = gSprites[gHealthboxSpriteIds[battlerId]].y - DOUBLES_Z_TRIGGER_POS_Y_DIFF; + x = gSprites[gHealthboxSpriteIds[battler]].x - DOUBLES_Z_TRIGGER_POS_X_SLIDE; + y = gSprites[gHealthboxSpriteIds[battler]].y - DOUBLES_Z_TRIGGER_POS_Y_DIFF; } else { - x = gSprites[gHealthboxSpriteIds[battlerId]].x - SINGLES_Z_TRIGGER_POS_X_SLIDE; - y = gSprites[gHealthboxSpriteIds[battlerId]].y - SINGLES_Z_TRIGGER_POS_Y_DIFF, 0; + x = gSprites[gHealthboxSpriteIds[battler]].x - SINGLES_Z_TRIGGER_POS_X_SLIDE; + y = gSprites[gHealthboxSpriteIds[battler]].y - SINGLES_Z_TRIGGER_POS_Y_DIFF, 0; } if (gBattleStruct->zmove.triggerSpriteId == 0xFF) gBattleStruct->zmove.triggerSpriteId = CreateSprite(&sSpriteTemplate_ZMoveTrigger, x, y, 0); - gSprites[gBattleStruct->zmove.triggerSpriteId].tBattler = battlerId; + gSprites[gBattleStruct->zmove.triggerSpriteId].tBattler = battler; gSprites[gBattleStruct->zmove.triggerSpriteId].tHide = (viable == TRUE) ? FALSE : TRUE; } @@ -348,11 +348,11 @@ void HideZMoveTriggerSprite(void) sprite->tHide = TRUE; } -static void ShowZMoveTriggerSprite(u8 battlerId) +static void ShowZMoveTriggerSprite(u8 battler) { struct Sprite *sprite = &gSprites[gBattleStruct->zmove.triggerSpriteId]; gBattleStruct->zmove.viable = TRUE; - CreateZMoveTriggerSprite(battlerId, TRUE); + CreateZMoveTriggerSprite(battler, TRUE); } void DestroyZMoveTriggerSprite(void) @@ -392,11 +392,11 @@ static u16 GetTypeBasedZMove(u16 move, u8 battler) return MOVE_BREAKNECK_BLITZ + (moveType - 1); } -bool32 MoveSelectionDisplayZMove(u16 zmove) +bool32 MoveSelectionDisplayZMove(u16 zmove, u32 battler) { u32 i; - struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]); - u16 move = moveInfo->moves[gMoveSelectionCursor[gActiveBattler]]; + struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); + u16 move = moveInfo->moves[gMoveSelectionCursor[battler]]; PlaySE(SE_SELECT); gBattleStruct->zmove.viewing = TRUE; @@ -507,8 +507,8 @@ bool32 MoveSelectionDisplayZMove(u16 zmove) } BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MOVE_NAME_1); - ZMoveSelectionDisplayPpNumber(); - ZMoveSelectionDisplayMoveType(zmove); + ZMoveSelectionDisplayPpNumber(battler); + ZMoveSelectionDisplayMoveType(zmove, battler); MoveSelectionCreateCursorAt(0, 0); return TRUE; } @@ -532,26 +532,26 @@ static void ZMoveSelectionDisplayPower(u16 move, u16 zMove) } } -static void ZMoveSelectionDisplayPpNumber(void) +static void ZMoveSelectionDisplayPpNumber(u32 battler) { u8 *txtPtr; struct ChooseMoveStruct *moveInfo; - if (gBattleResources->bufferA[gActiveBattler][2] == TRUE) // Check if we didn't want to display pp number + if (gBattleResources->bufferA[battler][2] == TRUE) // Check if we didn't want to display pp number return; - SetPpNumbersPaletteInMoveSelection(); - moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]); + SetPpNumbersPaletteInMoveSelection(battler); + moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); txtPtr = ConvertIntToDecimalStringN(gDisplayedStringBattle, 1, STR_CONV_MODE_RIGHT_ALIGN, 2); *(txtPtr)++ = CHAR_SLASH; ConvertIntToDecimalStringN(txtPtr, 1, STR_CONV_MODE_RIGHT_ALIGN, 2); BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_PP_REMAINING); } -static void ZMoveSelectionDisplayMoveType(u16 zMove) +static void ZMoveSelectionDisplayMoveType(u16 zMove, u32 battler) { u8 *txtPtr; - struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]); + struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[battler][4]); u8 zMoveType; GET_MOVE_TYPE(zMove, zMoveType); @@ -683,12 +683,12 @@ void SetZEffect(void) gBattleStruct->zmove.zStatusActive = FALSE; } -static bool32 AreStatsMaxed(u8 battlerId, u8 n) +static bool32 AreStatsMaxed(u8 battler, u8 n) { u32 i; for (i = STAT_ATK; i <= n; i++) { - if (STAT_STAGE(battlerId, i) < MAX_STAT_STAGE) + if (STAT_STAGE(battler, i) < MAX_STAT_STAGE) return FALSE; } return TRUE; diff --git a/src/data/battle_anim.h b/src/data/battle_anim.h index 0a3c5d647..885038725 100644 --- a/src/data/battle_anim.h +++ b/src/data/battle_anim.h @@ -1156,11 +1156,7 @@ const struct CompressedSpriteSheet gBattleAnimPicTable[] = {gBattleAnimSpriteGfx_Shock2, 0x0600, ANIM_TAG_SHOCK_2}, {gBattleAnimSpriteGfx_ClosingEye2, 0x0200, ANIM_TAG_CLOSING_EYE_2}, {gBattleAnimSpriteGfx_MetalBall, 0x0080, ANIM_TAG_METAL_BALL}, -#if NEW_SUBSTITUTE_PARTICLE - {gBattleAnimSpriteGfx_NewSubstituteFront, 0x0200, ANIM_TAG_MONSTER_DOLL}, -#else {gBattleAnimSpriteGfx_MonsterDoll, 0x0200, ANIM_TAG_MONSTER_DOLL}, -#endif {gBattleAnimSpriteGfx_Whirlwind, 0x0800, ANIM_TAG_WHIRLWIND}, {gBattleAnimSpriteGfx_Whirlwind2, 0x0080, ANIM_TAG_WHIRLWIND_2}, {gBattleAnimSpriteGfx_Explosion4, 0x0a00, ANIM_TAG_EXPLOSION_4}, @@ -1607,11 +1603,7 @@ const struct CompressedSpritePalette gBattleAnimPaletteTable[] = {gBattleAnimSpritePal_Shock2, ANIM_TAG_SHOCK_2}, {gBattleAnimSpritePal_ClosingEye2, ANIM_TAG_CLOSING_EYE_2}, {gBattleAnimSpritePal_MetalBall, ANIM_TAG_METAL_BALL}, -#if NEW_SUBSTITUTE_PARTICLE - {gBattleAnimSpritePal_NewSubstituteFront, ANIM_TAG_MONSTER_DOLL}, -#else {gBattleAnimSpritePal_MonsterDoll, ANIM_TAG_MONSTER_DOLL}, -#endif {gBattleAnimSpritePal_Whirlwind, ANIM_TAG_WHIRLWIND}, {gBattleAnimSpritePal_Whirlwind, ANIM_TAG_WHIRLWIND_2}, {gBattleAnimSpritePal_Explosion4, ANIM_TAG_EXPLOSION_4}, diff --git a/src/graphics.c b/src/graphics.c index e7b93e9e9..40c5d131b 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -265,10 +265,6 @@ const u32 gBattleAnimSpritePal_SteelBeam[] = INCBIN_U32("graphics/battle_anims/s const u32 gBattleAnimSpriteGfx_StraightBeam[] = INCBIN_U32("graphics/battle_anims/sprites/straight_beam.4bpp.lz"); const u32 gBattleAnimSpritePal_StraightBeam[] = INCBIN_U32("graphics/battle_anims/sprites/straight_beam.gbapal.lz"); -const u32 gBattleAnimSpriteGfx_SubstituteBack[] = INCBIN_U32("graphics/battle_anims/sprites/substitute_back_new.4bpp.lz"); -const u32 gBattleAnimSpriteGfx_NewSubstituteFront[] = INCBIN_U32("graphics/battle_anims/sprites/substitute_new.4bpp.lz"); -const u32 gBattleAnimSpritePal_NewSubstituteFront[] = INCBIN_U32("graphics/battle_anims/sprites/substitute_new.gbapal.lz"); - const u32 gBattleAnimSpritePal_NewSurf[] = INCBIN_U32("graphics/battle_anims/sprites/surf_new.gbapal.lz"); const u32 gBattleAnimSpriteGfx_NewSword[] = INCBIN_U32("graphics/battle_anims/sprites/sword_new.4bpp.lz"); @@ -1174,9 +1170,9 @@ const u32 gBattleAnimSpritePal_HandsAndFeet[] = INCBIN_U32("graphics/battle_anim const u32 gBattleAnimSpriteGfx_Confetti[] = INCBIN_U32("graphics/battle_anims/sprites/confetti.4bpp.lz"); const u32 gBattleAnimSpritePal_Confetti[] = INCBIN_U32("graphics/battle_anims/sprites/confetti.gbapal.lz"); -const u32 gSubstituteDollPal[] = INCBIN_U32("graphics/battle_anims/sprites/substitute.gbapal.lz"); -const u32 gSubstituteDollFrontGfx[] = INCBIN_U32("graphics/battle_anims/sprites/substitute.4bpp.lz"); -const u32 gSubstituteDollBackGfx[] = INCBIN_U32("graphics/battle_anims/sprites/substitute_back.4bpp.lz"); +const u32 gBattleAnimSpriteGfx_Substitute[] = INCBIN_U32("graphics/battle_anims/sprites/substitute.4bpp.lz"); +const u32 gBattleAnimSpriteGfx_SubstituteBack[] = INCBIN_U32("graphics/battle_anims/sprites/substitute_back.4bpp.lz"); +const u32 gBattleAnimSpritePal_Substitute[] = INCBIN_U32("graphics/battle_anims/sprites/substitute.gbapal.lz"); const u32 gBattleAnimSpriteGfx_GreenStar[] = INCBIN_U32("graphics/battle_anims/sprites/green_star.4bpp.lz"); const u32 gBattleAnimSpritePal_GreenStar[] = INCBIN_U32("graphics/battle_anims/sprites/green_star.gbapal.lz"); diff --git a/src/pokeball.c b/src/pokeball.c index 2e556ec22..891b8fe4a 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -527,17 +527,17 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = #define tBattler data[3] #define tOpponentBattler data[4] -u8 DoPokeballSendOutAnimation(s16 pan, u8 kindOfThrow) +u8 DoPokeballSendOutAnimation(u32 battler, s16 pan, u8 kindOfThrow) { u8 taskId; gDoingBattleAnim = TRUE; - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive = TRUE; + gBattleSpritesDataPtr->healthBoxesData[battler].ballAnimActive = TRUE; taskId = CreateTask(Task_DoPokeballSendOutAnim, 5); gTasks[taskId].tPan = pan; gTasks[taskId].tThrowId = kindOfThrow; - gTasks[taskId].tBattler = gActiveBattler; + gTasks[taskId].tBattler = battler; return 0; } diff --git a/src/pokemon.c b/src/pokemon.c index 679abe1e2..474044e80 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4408,38 +4408,24 @@ void DeleteFirstMoveAndGiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move) SetBoxMonData(boxMon, MON_DATA_PP_BONUSES, &ppBonuses); } -u8 CountAliveMonsInBattle(u8 caseId) +u8 CountAliveMonsInBattle(u8 caseId, u32 battler) { s32 i; u8 retVal = 0; switch (caseId) { - case BATTLE_ALIVE_EXCEPT_ACTIVE: + case BATTLE_ALIVE_EXCEPT_BATTLER: for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - if (i != gActiveBattler && !(gAbsentBattlerFlags & gBitTable[i])) + if (i != battler && !(gAbsentBattlerFlags & gBitTable[i])) retVal++; } break; - case BATTLE_ALIVE_ATK_SIDE: + case BATTLE_ALIVE_SIDE: for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - if (GetBattlerSide(i) == GetBattlerSide(gBattlerAttacker) && !(gAbsentBattlerFlags & gBitTable[i])) - retVal++; - } - break; - case BATTLE_ALIVE_DEF_SIDE: - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerSide(i) == GetBattlerSide(gBattlerTarget) && !(gAbsentBattlerFlags & gBitTable[i])) - retVal++; - } - break; - case BATTLE_ALIVE_EXCEPT_ATTACKER: - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (i != gBattlerAttacker && !(gAbsentBattlerFlags & gBitTable[i])) + if (GetBattlerSide(i) == GetBattlerSide(battler) && !(gAbsentBattlerFlags & gBitTable[i])) retVal++; } break; @@ -4454,7 +4440,7 @@ u8 GetDefaultMoveTarget(u8 battlerId) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return GetBattlerAtPosition(opposing); - if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ACTIVE) > 1) + if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_BATTLER, battlerId) > 1) { u8 position; @@ -5518,7 +5504,7 @@ u8 CalculatePartyCount(struct Pokemon *party) { partyCount++; } - + return partyCount; } @@ -6230,7 +6216,7 @@ bool8 HealStatusConditions(struct Pokemon *mon, u32 battlePartyId, u32 healMask, } } -u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit) +u8 GetItemEffectParamOffset(u32 battler, u16 itemId, u8 effectByte, u8 effectBit) { const u8 *temp; const u8 *itemEffect; @@ -6248,7 +6234,7 @@ u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit) if (itemId == ITEM_ENIGMA_BERRY_E_READER) { - temp = gEnigmaBerries[gActiveBattler].itemEffect; + temp = gEnigmaBerries[battler].itemEffect; } itemEffect = temp; diff --git a/src/recorded_battle.c b/src/recorded_battle.c index e4b1a5544..17f12ce93 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -616,13 +616,13 @@ static void RecordedBattle_RestoreSavedParties(void) } } -u8 GetActiveBattlerLinkPlayerGender(void) +u8 GetBattlerLinkPlayerGender(u32 battler) { s32 i; for (i = 0; i < MAX_LINK_PLAYERS; i++) { - if (gLinkPlayers[i].id == gActiveBattler) + if (gLinkPlayers[i].id == battler) break; } @@ -658,11 +658,11 @@ u8 GetTextSpeedInRecordedBattle(void) return sTextSpeed; } -void RecordedBattle_CopyBattlerMoves(void) +void RecordedBattle_CopyBattlerMoves(u32 battler) { s32 i; - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) + if (GetBattlerSide(battler) == B_SIDE_OPPONENT) return; if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK)) return; @@ -670,7 +670,7 @@ void RecordedBattle_CopyBattlerMoves(void) return; for (i = 0; i < MAX_MON_MOVES; i++) - sPlayerMonMoves[gActiveBattler / 2][i] = gBattleMons[gActiveBattler].moves[i]; + sPlayerMonMoves[battler / 2][i] = gBattleMons[battler].moves[i]; } // This is a special battle action only used by this function