diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index c5bede3f5d..4b9e0bfdf1 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -183,7 +183,7 @@ .byte \battler .endm - .macro atk24 ptr:req + .macro checkteamslost ptr:req .byte 0x24 .4byte \ptr .endm @@ -538,7 +538,7 @@ .byte 0x5d .endm - .macro atk5E battler:req + .macro updatebattlermoves battler:req .byte 0x5e .byte \battler .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 203ea31256..5a48e0b3c2 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2825,37 +2825,40 @@ BattleScript_GiveExp:: end2 BattleScript_HandleFaintedMon:: - atk24 BattleScript_HandleFaintedMonMultiple + checkteamslost BattleScript_LinkHandleFaintedMonMultiple jumpifbyte CMP_NOT_EQUAL, gBattleOutcome, 0, BattleScript_FaintedMonEnd - jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_FaintedMonTryChooseAnother - jumpifword CMP_NO_COMMON_BITS, gHitMarker, HITMARKER_PLAYER_FAINTED, BattleScript_FaintedMonTryChooseAnother -@ Yes/No for sending out a new Pokémon, when sending out is optional + jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_FaintedMonTryChoose + jumpifword CMP_NO_COMMON_BITS, gHitMarker, HITMARKER_PLAYER_FAINTED, BattleScript_FaintedMonTryChoose +@ Yes/No for sending out a new Pokémon if one is defeated in a wild battle printstring STRINGID_USENEXTPKMN setbyte gBattleCommunication, 0 yesnobox - jumpifbyte CMP_EQUAL, gBattleCommunication + 1, 0, BattleScript_FaintedMonTryChooseAnother + jumpifbyte CMP_EQUAL, gBattleCommunication + 1, 0, BattleScript_FaintedMonTryChoose @ Player said no, try to run jumpifplayerran BattleScript_FaintedMonEnd printstring STRINGID_CANTESCAPE2 -BattleScript_FaintedMonTryChooseAnother:: +BattleScript_FaintedMonTryChoose:: openpartyscreen BS_FAINTED, BattleScript_FaintedMonEnd switchhandleorder BS_FAINTED, 2 - jumpifnotbattletype BATTLE_TYPE_TRAINER, BattleScript_FaintedMonChooseAnother - jumpifbattletype BATTLE_TYPE_LINK, BattleScript_FaintedMonChooseAnother - jumpifbattletype BATTLE_TYPE_RECORDED_LINK, BattleScript_FaintedMonChooseAnother - jumpifbattletype BATTLE_TYPE_FRONTIER, BattleScript_FaintedMonChooseAnother - jumpifbattletype BATTLE_TYPE_DOUBLE, BattleScript_FaintedMonChooseAnother - jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_PLAYER_FAINTED, BattleScript_FaintedMonChooseAnother - jumpifbyte CMP_EQUAL, sBATTLE_STYLE, OPTIONS_BATTLE_STYLE_SET, BattleScript_FaintedMonChooseAnother - jumpifcantswitch BS_PLAYER1, BattleScript_FaintedMonChooseAnother + jumpifnotbattletype BATTLE_TYPE_TRAINER, BattleScript_FaintedMonSendOutNew + jumpifbattletype BATTLE_TYPE_LINK, BattleScript_FaintedMonSendOutNew + jumpifbattletype BATTLE_TYPE_RECORDED_LINK, BattleScript_FaintedMonSendOutNew + jumpifbattletype BATTLE_TYPE_FRONTIER, BattleScript_FaintedMonSendOutNew + jumpifbattletype BATTLE_TYPE_DOUBLE, BattleScript_FaintedMonSendOutNew + jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_PLAYER_FAINTED, BattleScript_FaintedMonSendOutNew + jumpifbyte CMP_EQUAL, sBATTLE_STYLE, OPTIONS_BATTLE_STYLE_SET, BattleScript_FaintedMonSendOutNew + jumpifcantswitch BS_PLAYER1, BattleScript_FaintedMonSendOutNew +@ Yes/No for sending out a new Pokémon when the opponent is switching printstring STRINGID_ENEMYABOUTTOSWITCHPKMN setbyte gBattleCommunication, 0 yesnobox - jumpifbyte CMP_EQUAL, gBattleCommunication + 1, 1, BattleScript_FaintedMonChooseAnother + jumpifbyte CMP_EQUAL, gBattleCommunication + 1, 1, BattleScript_FaintedMonSendOutNew +@ Player said yes, go to party screen (note optional flag, player may exit the menu instead) setatktoplayer0 - openpartyscreen BS_ATTACKER | PARTY_SCREEN_OPTIONAL, BattleScript_FaintedMonChooseAnother + openpartyscreen BS_ATTACKER | PARTY_SCREEN_OPTIONAL, BattleScript_FaintedMonSendOutNew switchhandleorder BS_ATTACKER, 2 - jumpifbyte CMP_EQUAL, gBattleCommunication, PARTY_SIZE, BattleScript_FaintedMonChooseAnother + jumpifbyte CMP_EQUAL, gBattleCommunication, PARTY_SIZE, BattleScript_FaintedMonSendOutNew +@ Switch Pokémon before opponent atknameinbuff1 resetintimidatetracebits BS_ATTACKER hpthresholds2 BS_ATTACKER @@ -2874,7 +2877,7 @@ BattleScript_FaintedMonTryChooseAnother:: waitstate switchineffects BS_ATTACKER resetsentmonsvalue -BattleScript_FaintedMonChooseAnother:: +BattleScript_FaintedMonSendOutNew:: drawpartystatussummary BS_FAINTED getswitchedmondata BS_FAINTED switchindataupdate BS_FAINTED @@ -2890,13 +2893,13 @@ BattleScript_FaintedMonChooseAnother:: BattleScript_FaintedMonEnd:: end2 -BattleScript_HandleFaintedMonMultiple:: - openpartyscreen BS_UNK_5, BattleScript_HandleFaintedMonMultipleStart -BattleScript_HandleFaintedMonMultipleStart:: +BattleScript_LinkHandleFaintedMonMultiple:: + openpartyscreen BS_FAINTED_LINK_MULTIPLE_1, BattleScript_LinkHandleFaintedMonMultipleStart +BattleScript_LinkHandleFaintedMonMultipleStart:: switchhandleorder BS_FAINTED, 0 - openpartyscreen BS_UNK_6, BattleScript_HandleFaintedMonMultipleEnd + openpartyscreen BS_FAINTED_LINK_MULTIPLE_2, BattleScript_LinkHandleFaintedMonMultipleEnd switchhandleorder BS_FAINTED, 0 -BattleScript_HandleFaintedMonLoop:: +BattleScript_LinkHandleFaintedMonLoop:: switchhandleorder BS_FAINTED, 3 drawpartystatussummary BS_FAINTED getswitchedmondata BS_FAINTED @@ -2906,9 +2909,9 @@ BattleScript_HandleFaintedMonLoop:: hidepartystatussummary BS_FAINTED switchinanim BS_FAINTED, FALSE waitstate - switchineffects BS_UNK_5 - jumpifbytenotequal gBattlerFainted, gBattlersCount, BattleScript_HandleFaintedMonLoop -BattleScript_HandleFaintedMonMultipleEnd:: + switchineffects BS_FAINTED_LINK_MULTIPLE_1 + jumpifbytenotequal gBattlerFainted, gBattlersCount, BattleScript_LinkHandleFaintedMonLoop +BattleScript_LinkHandleFaintedMonMultipleEnd:: end2 BattleScript_LocalTrainerBattleWon:: @@ -3208,7 +3211,7 @@ BattleScript_DamagingWeatherLoop:: healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER tryfaintmon BS_ATTACKER, FALSE, NULL - atk24 BattleScript_DamagingWeatherLoopIncrement + checkteamslost BattleScript_DamagingWeatherLoopIncrement BattleScript_DamagingWeatherLoopIncrement:: jumpifbyte CMP_NOT_EQUAL, gBattleOutcome, 0, BattleScript_DamagingWeatherContinuesEnd addbyte gBattleCommunication, 1 @@ -3523,7 +3526,7 @@ BattleScript_DoFutureAttackHit:: resultmessage waitmessage B_WAIT_TIME_LONG tryfaintmon BS_TARGET, FALSE, NULL - atk24 BattleScript_FutureAttackEnd + checkteamslost BattleScript_FutureAttackEnd BattleScript_FutureAttackEnd:: moveendcase MOVEEND_RAGE moveendfromto MOVEEND_ITEM_EFFECTS_ALL, MOVEEND_UPDATE_LAST_MOVES @@ -3737,7 +3740,7 @@ BattleScript_DoTurnDmg:: healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER tryfaintmon BS_ATTACKER, FALSE, NULL - atk24 BattleScript_DoTurnDmgEnd + checkteamslost BattleScript_DoTurnDmgEnd BattleScript_DoTurnDmgEnd:: end2 diff --git a/include/battle.h b/include/battle.h index f793c779f7..5a30bc90c8 100644 --- a/include/battle.h +++ b/include/battle.h @@ -145,7 +145,7 @@ struct SpecialStatus u32 intimidatedMon:1; u32 traced:1; u32 ppNotAffectedByPressure:1; - u32 flag40:1; + u32 faintedHasReplacement:1; u32 focusBanded:1; s32 dmg; s32 physicalDmg; @@ -384,9 +384,9 @@ struct BattleStruct u8 field_52; u8 sentInPokes; bool8 selectionScriptFinished[MAX_BATTLERS_COUNT]; - u8 field_58[4]; + u8 battlerPartyIndexes[MAX_BATTLERS_COUNT]; u8 monToSwitchIntoId[MAX_BATTLERS_COUNT]; - u8 field_60[4][3]; + u8 battlerPartyOrders[MAX_BATTLERS_COUNT][PARTY_SIZE / 2]; u8 runTries; u8 caughtMonNick[POKEMON_NAME_LENGTH + 1]; u8 unused_2; @@ -405,7 +405,7 @@ struct BattleStruct u8 stringMoveType; u8 expGetterBattlerId; u8 unused_5; - u8 field_91; // related to gAbsentBattlerFlags, possibly absent flags turn ago? + u8 absentBattlerFlags; u8 palaceFlags; // First 4 bits are "is < 50% HP and not asleep" for each battler, last 4 bits are selected moves to pass to AI u8 field_93; // related to choosing pokemon? u8 wallyBattleState; diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 34e916b0f2..9d9fba1b40 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -1,8 +1,7 @@ #ifndef GUARD_BATTLE_CONTROLLERS_H #define GUARD_BATTLE_CONTROLLERS_H -enum -{ +enum { REQUEST_ALL_BATTLE, REQUEST_SPECIES_BATTLE, REQUEST_HELDITEM_BATTLE, @@ -67,19 +66,36 @@ enum // Special arguments for Battle Controller functions. -#define RESET_ACTION_MOVE_SELECTION 0 -#define RESET_ACTION_SELECTION 1 -#define RESET_MOVE_SELECTION 2 +enum { // Values given to the emit functions to choose gBattleBufferA or gBattleBufferB + BUFFER_A, + BUFFER_B +}; -#define BALL_NO_SHAKES 0 -#define BALL_1_SHAKE 1 -#define BALL_2_SHAKES 2 -#define BALL_3_SHAKES_FAIL 3 -#define BALL_3_SHAKES_SUCCESS 4 -#define BALL_TRAINER_BLOCK 5 +enum { + RESET_ACTION_MOVE_SELECTION, + RESET_ACTION_SELECTION, + RESET_MOVE_SELECTION, +}; + +enum { + BALL_NO_SHAKES, + BALL_1_SHAKE, + BALL_2_SHAKES, + BALL_3_SHAKES_FAIL, + BALL_3_SHAKES_SUCCESS, + BALL_TRAINER_BLOCK, +}; + +enum { + LINK_STANDBY_MSG_STOP_BOUNCE, + LINK_STANDBY_STOP_BOUNCE_ONLY, + LINK_STANDBY_MSG_ONLY, +}; #define INSTANT_HP_BAR_DROP 32767 +#define PARTY_SUMM_SKIP_DRAW_DELAY (1 << 7) + // Special return values in gBattleBufferB from Battle Controller functions. #define RET_VALUE_LEVELED_UP 11 @@ -191,7 +207,7 @@ void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 b void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data); // unused void BtlController_EmitLoadMonSprite(u8 bufferId); void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit); -void BtlController_EmitReturnMonToBall(u8 bufferId, u8 arg1); +void BtlController_EmitReturnMonToBall(u8 bufferId, bool8 skipAnim); void BtlController_EmitDrawTrainerPic(u8 bufferId); void BtlController_EmitTrainerSlide(u8 bufferId); void BtlController_EmitTrainerSlideBack(u8 bufferId); @@ -203,11 +219,11 @@ void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data); // unused 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 arg1, u16 arg2); +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* arg1); -void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 abilityId, u8* arg4); +void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abilityId, u8* data); void BtlController_EmitCmd23(u8 bufferId); // unused void BtlController_EmitHealthBarUpdate(u8 bufferId, u16 hpValue); void BtlController_EmitExpUpdate(u8 bufferId, u8 partyId, u16 expPoints); @@ -216,7 +232,7 @@ void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status); void BtlController_EmitStatusXor(u8 bufferId, u8 b); // unused void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data); void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data); // unused -void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *unusedDumbDataParameter); // unused +void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data); // unused void BtlController_EmitCmd32(u8 bufferId, u16 size, void *c); // unused void BtlController_EmitTwoReturnValues(u8 bufferId, u8 arg1, u16 arg2); void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 b, u8 *c); @@ -233,7 +249,7 @@ 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 arg2); +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); diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index d5e3eb7bbf..f3e11b4be3 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -40,8 +40,8 @@ #define BS_EFFECT_BATTLER 2 #define BS_FAINTED 3 #define BS_ATTACKER_WITH_PARTNER 4 // for Cmd_updatestatusicon -#define BS_UNK_5 5 -#define BS_UNK_6 6 +#define BS_FAINTED_LINK_MULTIPLE_1 5 +#define BS_FAINTED_LINK_MULTIPLE_2 6 #define BS_BATTLER_0 7 #define BS_ATTACKER_SIDE 8 // for Cmd_jumpifability #define BS_NOT_ATTACKER_SIDE 9 // for Cmd_jumpifability diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 537005d309..6ded484679 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -22,7 +22,7 @@ static bool8 ShouldSwitchIfPerishSong(void) && gDisableStructs[gActiveBattler].perishSongTimer == 0) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } else @@ -106,7 +106,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) { // We found a mon. *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } } @@ -206,7 +206,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) { // we found a mon. *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } } @@ -226,13 +226,13 @@ static bool8 ShouldSwitchIfNaturalCure(void) if ((gLastLandedMoves[gActiveBattler] == 0 || gLastLandedMoves[gActiveBattler] == 0xFFFF) && Random() & 1) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0 && Random() & 1) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } @@ -244,7 +244,7 @@ static bool8 ShouldSwitchIfNaturalCure(void) if (Random() & 1) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } @@ -412,7 +412,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % moduloPercent == 0) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); return TRUE; } } @@ -597,7 +597,7 @@ void AI_TrySwitchOrUseItem(void) } } - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_MOVE, (gActiveBattler ^ BIT_SIDE) << 8); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, (gActiveBattler ^ BIT_SIDE) << 8); } static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var) @@ -923,7 +923,7 @@ static bool8 ShouldUseItem(void) if (shouldUse) { - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_ITEM, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2) = item; gBattleResources->battleHistory->trainerItems[i] = 0; return shouldUse; diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 11b8f3af78..55fffa705b 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -555,7 +555,7 @@ static void LinkOpponentHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); LinkOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 9c184b9c26..a9240b0ac7 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -442,7 +442,7 @@ static void LinkPartnerHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); LinkPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 3f62ba08d4..fe339ddfc8 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -555,7 +555,7 @@ static void OpponentHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); OpponentBufferExecCompleted(); } @@ -875,7 +875,7 @@ static void OpponentHandleGetRawMonData(void) for (i = 0; i < gBattleBufferA[gActiveBattler][2]; i++) dst[i] = src[i]; - BtlController_EmitDataTransfer(1, gBattleBufferA[gActiveBattler][2], dst); + BtlController_EmitDataTransfer(BUFFER_B, gBattleBufferA[gActiveBattler][2], dst); OpponentBufferExecCompleted(); } @@ -1546,7 +1546,7 @@ static void OpponentHandleChooseMove(void) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(1, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); OpponentBufferExecCompleted(); } else @@ -1563,13 +1563,13 @@ static void OpponentHandleChooseMove(void) switch (chosenMoveId) { case AI_CHOICE_WATCH: - BtlController_EmitTwoReturnValues(1, B_ACTION_SAFARI_WATCH_CAREFULLY, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0); break; case AI_CHOICE_FLEE: - BtlController_EmitTwoReturnValues(1, B_ACTION_RUN, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0); break; case 6: - BtlController_EmitTwoReturnValues(1, 15, gBattlerTarget); + BtlController_EmitTwoReturnValues(BUFFER_B, 15, gBattlerTarget); break; default: if (gBattleMoves[moveInfo->moves[chosenMoveId]].target & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER)) @@ -1580,7 +1580,7 @@ static void OpponentHandleChooseMove(void) if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); } - BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); break; } OpponentBufferExecCompleted(); @@ -1595,11 +1595,11 @@ static void OpponentHandleChooseMove(void) } while (move == MOVE_NONE); if (gBattleMoves[move].target & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER)) - BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (gActiveBattler << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8)); else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); else - BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); OpponentBufferExecCompleted(); } @@ -1608,7 +1608,7 @@ static void OpponentHandleChooseMove(void) static void OpponentHandleChooseItem(void) { - BtlController_EmitOneReturnValue(1, *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2)); + BtlController_EmitOneReturnValue(BUFFER_B, *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2)); OpponentBufferExecCompleted(); } @@ -1665,7 +1665,7 @@ static void OpponentHandleChoosePokemon(void) *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = chosenMonId; - BtlController_EmitChosenMonReturnValue(1, chosenMonId, NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL); OpponentBufferExecCompleted(); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index bc8db16991..600e4a16a7 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -248,17 +248,17 @@ static void HandleInputChooseAction(void) switch (gActionSelectionCursor[gActiveBattler]) { - case B_ACTION_USE_MOVE: - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_MOVE, 0); + case 0: // Top left + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); break; - case B_ACTION_USE_ITEM: - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_ITEM, 0); + case 1: // Top right + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); break; - case B_ACTION_SWITCH: - BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); + case 2: // Bottom left + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0); break; - case B_ACTION_RUN: - BtlController_EmitTwoReturnValues(1, B_ACTION_RUN, 0); + case 3: // Bottom right + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0); break; } PlayerBufferExecCompleted(); @@ -319,7 +319,7 @@ static void HandleInputChooseAction(void) return; } PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, B_ACTION_CANCEL_PARTNER, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_CANCEL_PARTNER, 0); PlayerBufferExecCompleted(); } } @@ -365,7 +365,7 @@ static void HandleInputChooseTarget(void) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; - BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); PlayerBufferExecCompleted(); } @@ -523,7 +523,7 @@ static void HandleInputChooseMove(void) if (!canSelectTarget) { - BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); PlayerBufferExecCompleted(); } else @@ -543,7 +543,7 @@ static void HandleInputChooseMove(void) else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, 10, 0xFFFF); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF); PlayerBufferExecCompleted(); } else if (JOY_NEW(DPAD_LEFT)) @@ -1174,7 +1174,7 @@ static void Task_GiveExpToMon(u8 taskId) gainedExp -= nextLvlExp - currExp; savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); + BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBattler; if (IsDoubleBattle() == TRUE @@ -1253,7 +1253,7 @@ static void Task_GiveExpWithExpBar(u8 taskId) gainedExp -= expOnNextLvl - currExp; savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); + BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBattler; gTasks[taskId].func = Task_LaunchLvlUpAnim; } @@ -1361,9 +1361,9 @@ static void WaitForMonSelection(void) if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { if (gPartyMenuUseExitCallback == TRUE) - BtlController_EmitChosenMonReturnValue(1, gSelectedMonPartyId, gBattlePartyCurrentOrder); + BtlController_EmitChosenMonReturnValue(BUFFER_B, gSelectedMonPartyId, gBattlePartyCurrentOrder); else - BtlController_EmitChosenMonReturnValue(1, PARTY_SIZE, NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, PARTY_SIZE, NULL); if ((gBattleBufferA[gActiveBattler][1] & 0xF) == 1) PrintLinkStandbyMsg(); @@ -1387,7 +1387,7 @@ static void CompleteWhenChoseItem(void) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(1, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); PlayerBufferExecCompleted(); } } @@ -1439,9 +1439,9 @@ static void PlayerHandleYesNoInput(void) PlaySE(SE_SELECT); if (gMultiUsePlayerCursor != 0) - BtlController_EmitTwoReturnValues(1, 0xE, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, 0xE, 0); else - BtlController_EmitTwoReturnValues(1, 0xD, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, 0xD, 0); PlayerBufferExecCompleted(); } @@ -1600,7 +1600,7 @@ static void PlayerHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); PlayerBufferExecCompleted(); } @@ -1920,7 +1920,7 @@ void PlayerHandleGetRawMonData(void) for (i = 0; i < gBattleBufferA[gActiveBattler][2]; i++) dst[i] = src[i]; - BtlController_EmitDataTransfer(1, gBattleBufferA[gActiveBattler][2], dst); + BtlController_EmitDataTransfer(BUFFER_B, gBattleBufferA[gActiveBattler][2], dst); PlayerBufferExecCompleted(); } @@ -2226,13 +2226,14 @@ static void StartSendOutAnim(u8 battlerId, bool8 dontClearSubstituteBit) static void PlayerHandleReturnMonToBall(void) { - if (gBattleBufferA[gActiveBattler][1] == 0) + if (!gBattleBufferA[gActiveBattler][1]) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; gBattlerControllerFuncs[gActiveBattler] = DoSwitchOutAnimation; } else { + // Skip animation, just remove battler FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); @@ -2620,7 +2621,7 @@ static void PlayerChooseMoveInBattlePalace(void) if (--*(gBattleStruct->arenaMindPoints + gActiveBattler) == 0) { gBattlePalaceMoveSelectionRngValue = gRngValue; - BtlController_EmitTwoReturnValues(1, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); PlayerBufferExecCompleted(); } } @@ -2670,7 +2671,7 @@ static void PlayerHandleChoosePokemon(void) if (gBattleTypeFlags & BATTLE_TYPE_ARENA && (gBattleBufferA[gActiveBattler][1] & 0xF) != PARTY_ACTION_CANT_SWITCH) { - BtlController_EmitChosenMonReturnValue(1, gBattlerPartyIndexes[gActiveBattler] + 1, gBattlePartyCurrentOrder); + BtlController_EmitChosenMonReturnValue(BUFFER_B, gBattlerPartyIndexes[gActiveBattler] + 1, gBattlePartyCurrentOrder); PlayerBufferExecCompleted(); } else @@ -2827,25 +2828,25 @@ static void PlayerHandleCmd32(void) static void PlayerHandleTwoReturnValues(void) { - BtlController_EmitTwoReturnValues(1, 0, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, 0, 0); PlayerBufferExecCompleted(); } static void PlayerHandleChosenMonReturnValue(void) { - BtlController_EmitChosenMonReturnValue(1, 0, NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, 0, NULL); PlayerBufferExecCompleted(); } static void PlayerHandleOneReturnValue(void) { - BtlController_EmitOneReturnValue(1, 0); + BtlController_EmitOneReturnValue(BUFFER_B, 0); PlayerBufferExecCompleted(); } static void PlayerHandleOneReturnValue_Duplicate(void) { - BtlController_EmitOneReturnValue_Duplicate(1, 0); + BtlController_EmitOneReturnValue_Duplicate(BUFFER_B, 0); PlayerBufferExecCompleted(); } @@ -3098,14 +3099,14 @@ static void PlayerHandleLinkStandbyMsg(void) RecordedBattle_RecordAllBattlerData(&gBattleBufferA[gActiveBattler][2]); switch (gBattleBufferA[gActiveBattler][1]) { - case 0: + case LINK_STANDBY_MSG_STOP_BOUNCE: PrintLinkStandbyMsg(); // fall through - case 1: + case LINK_STANDBY_STOP_BOUNCE_ONLY: EndBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX); EndBounceEffect(gActiveBattler, BOUNCE_MON); break; - case 2: + case LINK_STANDBY_MSG_ONLY: PrintLinkStandbyMsg(); break; } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index d07f2763ad..91fea6cde2 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -332,7 +332,7 @@ static void Task_GiveExpToMon(u8 taskId) gainedExp -= nextLvlExp - currExp; savedActiveBank = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); + BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBank; if (IsDoubleBattle() == TRUE @@ -411,7 +411,7 @@ static void Task_GiveExpWithExpBar(u8 taskId) gainedExp -= expOnNextLvl - currExp; savedActiveBank = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); + BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBank; gTasks[taskId].func = Task_LaunchLvlUpAnim; } @@ -626,7 +626,7 @@ static void PlayerPartnerHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); PlayerPartnerBufferExecCompleted(); } @@ -1527,7 +1527,7 @@ static void PlayerPartnerHandleChooseMove(void) gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); } - BtlController_EmitTwoReturnValues(1, 10, chosenMoveId | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, chosenMoveId | (gBattlerTarget << 8)); PlayerPartnerBufferExecCompleted(); } @@ -1557,7 +1557,7 @@ static void PlayerPartnerHandleChoosePokemon(void) } *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = chosenMonId; - BtlController_EmitChosenMonReturnValue(1, chosenMonId, NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL); PlayerPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index bb99c7bf94..ac92fb22df 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -538,7 +538,7 @@ static void RecordedOpponentHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); RecordedOpponentBufferExecCompleted(); } @@ -1406,7 +1406,7 @@ static void RecordedOpponentHandlePrintSelectionString(void) static void RecordedOpponentHandleChooseAction(void) { - BtlController_EmitTwoReturnValues(1, RecordedBattle_GetBattlerAction(gActiveBattler), 0); + BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0); RecordedOpponentBufferExecCompleted(); } @@ -1419,13 +1419,13 @@ static void RecordedOpponentHandleChooseMove(void) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(1, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); } else { u8 moveId = RecordedBattle_GetBattlerAction(gActiveBattler); u8 target = RecordedBattle_GetBattlerAction(gActiveBattler); - BtlController_EmitTwoReturnValues(1, 10, moveId | (target << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8)); } RecordedOpponentBufferExecCompleted(); @@ -1439,7 +1439,7 @@ static void RecordedOpponentHandleChooseItem(void) static void RecordedOpponentHandleChoosePokemon(void) { *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = RecordedBattle_GetBattlerAction(gActiveBattler); - BtlController_EmitChosenMonReturnValue(1, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL); RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 26231060a4..3e73c1dd19 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -517,7 +517,7 @@ static void RecordedPlayerHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); RecordedPlayerBufferExecCompleted(); } @@ -1414,7 +1414,7 @@ static void ChooseActionInBattlePalace(void) { if (gBattleCommunication[4] >= gBattlersCount / 2) { - BtlController_EmitTwoReturnValues(1, RecordedBattle_GetBattlerAction(gActiveBattler), 0); + BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0); RecordedPlayerBufferExecCompleted(); } } @@ -1427,7 +1427,7 @@ static void RecordedPlayerHandleChooseAction(void) } else { - BtlController_EmitTwoReturnValues(1, RecordedBattle_GetBattlerAction(gActiveBattler), 0); + BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0); RecordedPlayerBufferExecCompleted(); } } @@ -1441,13 +1441,13 @@ static void RecordedPlayerHandleChooseMove(void) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - BtlController_EmitTwoReturnValues(1, 10, ChooseMoveAndTargetInBattlePalace()); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace()); } else { u8 moveId = RecordedBattle_GetBattlerAction(gActiveBattler); u8 target = RecordedBattle_GetBattlerAction(gActiveBattler); - BtlController_EmitTwoReturnValues(1, 10, moveId | (target << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8)); } RecordedPlayerBufferExecCompleted(); @@ -1461,7 +1461,7 @@ static void RecordedPlayerHandleChooseItem(void) static void RecordedPlayerHandleChoosePokemon(void) { *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = RecordedBattle_GetBattlerAction(gActiveBattler); - BtlController_EmitChosenMonReturnValue(1, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL); + BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL); RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 6dc7aa2e52..a26f31b929 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -176,16 +176,16 @@ static void HandleInputChooseAction(void) switch (gActionSelectionCursor[gActiveBattler]) { case 0: - BtlController_EmitTwoReturnValues(1, B_ACTION_SAFARI_BALL, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_BALL, 0); break; case 1: - BtlController_EmitTwoReturnValues(1, B_ACTION_SAFARI_POKEBLOCK, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_POKEBLOCK, 0); break; case 2: - BtlController_EmitTwoReturnValues(1, B_ACTION_SAFARI_GO_NEAR, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_GO_NEAR, 0); break; case 3: - BtlController_EmitTwoReturnValues(1, B_ACTION_SAFARI_RUN, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_RUN, 0); break; } SafariBufferExecCompleted(); @@ -280,7 +280,7 @@ static void CompleteWhenChosePokeblock(void) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(1, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); SafariBufferExecCompleted(); } } diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 466b3f3151..d018fe1c01 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -196,7 +196,7 @@ static void WallyHandleActions(void) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_MOVE, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); WallyBufferExecCompleted(); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -207,7 +207,7 @@ static void WallyHandleActions(void) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_MOVE, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0); WallyBufferExecCompleted(); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -217,7 +217,7 @@ static void WallyHandleActions(void) case 3: if (--gBattleStruct->wallyWaitFrames == 0) { - BtlController_EmitTwoReturnValues(1, B_ACTION_WALLY_THROW, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_WALLY_THROW, 0); WallyBufferExecCompleted(); gBattleStruct->wallyBattleState++; gBattleStruct->wallyMovesState = 0; @@ -238,7 +238,7 @@ static void WallyHandleActions(void) if (--gBattleStruct->wallyWaitFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, B_ACTION_USE_ITEM, 0); + BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0); WallyBufferExecCompleted(); } break; @@ -278,7 +278,7 @@ static void CompleteOnChosenItem(void) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - BtlController_EmitOneReturnValue(1, gSpecialVar_ItemId); + BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId); WallyBufferExecCompleted(); } } @@ -444,7 +444,7 @@ static void WallyHandleGetMonData(void) monToCheck >>= 1; } } - BtlController_EmitDataTransfer(1, size, monData); + BtlController_EmitDataTransfer(BUFFER_B, size, monData); WallyBufferExecCompleted(); } @@ -1241,7 +1241,7 @@ static void WallyHandleChooseMove(void) if (--gBattleStruct->wallyMoveFrames == 0) { PlaySE(SE_SELECT); - BtlController_EmitTwoReturnValues(1, 10, 0x100); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0x100); WallyBufferExecCompleted(); } break; diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 0f32345791..ef5f1daa29 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -660,14 +660,14 @@ static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size) { switch (bufferId) { - case 0: + case BUFFER_A: for (i = 0; i < size; i++) { gBattleBufferA[gActiveBattler][i] = *data; data++; } break; - case 1: + case BUFFER_B: for (i = 0; i < size; i++) { gBattleBufferB[gActiveBattler][i] = *data; @@ -737,7 +737,7 @@ void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data) static void Task_HandleSendLinkBuffersData(u8 taskId) { - u16 var; + u16 numPlayers; u16 blockSize; switch (gTasks[taskId].data[11]) @@ -759,11 +759,11 @@ static void Task_HandleSendLinkBuffersData(u8 taskId) else { if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) - var = 2; + numPlayers = 2; else - var = (gBattleTypeFlags & BATTLE_TYPE_MULTI) ? 4 : 2; + numPlayers = (gBattleTypeFlags & BATTLE_TYPE_MULTI) ? 4 : 2; - if (GetLinkPlayerCount_2() >= var) + if (GetLinkPlayerCount_2() >= numPlayers) { if (IsLinkMaster()) { @@ -964,10 +964,10 @@ void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubs PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitReturnMonToBall(u8 bufferId, u8 arg1) +void BtlController_EmitReturnMonToBall(u8 bufferId, bool8 skipAnim) { sBattleBuffersTransferData[0] = CONTROLLER_RETURNMONTOBALL; - sBattleBuffersTransferData[1] = arg1; + sBattleBuffersTransferData[1] = skipAnim; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); } @@ -1134,12 +1134,13 @@ void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4); } -void BtlController_EmitChooseAction(u8 bufferId, u8 arg1, u16 arg2) +// itemId only relevant for B_ACTION_USE_ITEM +void BtlController_EmitChooseAction(u8 bufferId, u8 action, u16 itemId) { sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEACTION; - sBattleBuffersTransferData[1] = arg1; - sBattleBuffersTransferData[2] = arg2; - sBattleBuffersTransferData[3] = (arg2 & 0xFF00) >> 8; + sBattleBuffersTransferData[1] = action; + sBattleBuffersTransferData[2] = itemId; + sBattleBuffersTransferData[3] = (itemId & 0xFF00) >> 8; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } @@ -1177,7 +1178,7 @@ void BtlController_EmitChooseItem(u8 bufferId, u8 *arg1) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abilityId, u8 *arg4) +void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abilityId, u8 *data) { s32 i; @@ -1186,7 +1187,7 @@ void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 slotId, u8 abili sBattleBuffersTransferData[2] = slotId; sBattleBuffersTransferData[3] = abilityId; for (i = 0; i < 3; i++) - sBattleBuffersTransferData[4 + i] = arg4[i]; + sBattleBuffersTransferData[4 + i] = data[i]; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // Only 7 bytes were written. } @@ -1280,15 +1281,19 @@ void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 7); } -void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *unusedDumbDataParameter) +// Unused +void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *data) { s32 i; sBattleBuffersTransferData[0] = CONTROLLER_PLAYBGM; sBattleBuffersTransferData[1] = songId; sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8; - for (i = 0; i < songId; i++) // ???? - sBattleBuffersTransferData[3 + i] = *(u8*)(unusedDumbDataParameter++); + + // 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); } @@ -1442,8 +1447,8 @@ void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* h s32 i; sBattleBuffersTransferData[0] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; - sBattleBuffersTransferData[1] = flags & 0x7F; - sBattleBuffersTransferData[2] = (flags & 0x80) >> 7; // If true, skip delay after drawing. True during intro + 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; for (i = 0; i < (s32)(sizeof(struct HpAndStatus) * PARTY_SIZE); i++) sBattleBuffersTransferData[4 + i] = *(i + (u8*)(hpAndStatus)); @@ -1486,11 +1491,12 @@ void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 arg1, bool32 record) +// mode is a LINK_STANDBY_* constant +void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 mode, bool32 record) { bool8 record_ = record; sBattleBuffersTransferData[0] = CONTROLLER_LINKSTANDBYMSG; - sBattleBuffersTransferData[1] = arg1; + sBattleBuffersTransferData[1] = mode; if (record_) sBattleBuffersTransferData[3] = sBattleBuffersTransferData[2] = RecordedBattle_BufferNewBattlerData(&sBattleBuffersTransferData[4]); diff --git a/src/battle_main.c b/src/battle_main.c index 1d0f3454b8..da95402c8d 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -105,7 +105,7 @@ static void TryDoEventsBeforeFirstTurn(void); static void HandleTurnActionSelectionState(void); static void RunTurnActionsFunctions(void); static void SetActionsAndBattlersTurnOrder(void); -static void sub_803CDF8(void); +static void UpdateBattlerPartyOrdersOnSwitch(void); static bool8 AllAtActionConfirmed(void); static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void); static void FreeResetData_ReturnToOvOrDoEvolutions(void); @@ -2063,7 +2063,8 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir return gTrainers[trainerNum].partySize; } -static void sub_8038A04(void) // unused +// Unused +static void HBlankCB_Battle(void) { if (REG_VCOUNT < DISPLAY_HEIGHT && REG_VCOUNT >= 111) SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_SCREENBASE(24) | BGCNT_TXT256x512); @@ -3348,7 +3349,7 @@ static void BattleIntroGetMonsData(void) { case 0: gActiveBattler = gBattleCommunication[1]; - BtlController_EmitGetMonData(0, REQUEST_ALL_BATTLE, 0); + BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0); MarkBattlerForControllerExec(gActiveBattler); gBattleCommunication[MULTIUSE_STATE]++; break; @@ -3370,7 +3371,7 @@ static void BattleIntroPrepareBackgroundSlide(void) if (gBattleControllerExecFlags == 0) { gActiveBattler = GetBattlerAtPosition(0); - BtlController_EmitIntroSlide(0, gBattleTerrain); + BtlController_EmitIntroSlide(BUFFER_A, gBattleTerrain); MarkBattlerForControllerExec(gActiveBattler); gBattleMainFunc = BattleIntroDrawTrainersOrMonsSprites; gBattleCommunication[0] = 0; @@ -3415,7 +3416,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_LEFT) { - BtlController_EmitDrawTrainerPic(0); + BtlController_EmitDrawTrainerPic(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } @@ -3423,7 +3424,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) { if (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_LEFT) { - BtlController_EmitDrawTrainerPic(0); + BtlController_EmitDrawTrainerPic(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT @@ -3448,7 +3449,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) { HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality); } - BtlController_EmitLoadMonSprite(0); + BtlController_EmitLoadMonSprite(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); } @@ -3459,14 +3460,14 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) { - BtlController_EmitDrawTrainerPic(0); + BtlController_EmitDrawTrainerPic(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } } if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) { - BtlController_EmitDrawTrainerPic(0); + BtlController_EmitDrawTrainerPic(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } @@ -3501,7 +3502,7 @@ static void BattleIntroDrawPartySummaryScreens(void) } } gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - BtlController_EmitDrawPartyStatusSummary(0, hpStatus, 0x80); + BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); MarkBattlerForControllerExec(gActiveBattler); for (i = 0; i < PARTY_SIZE; i++) @@ -3519,7 +3520,7 @@ static void BattleIntroDrawPartySummaryScreens(void) } } gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - BtlController_EmitDrawPartyStatusSummary(0, hpStatus, 0x80); + BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY); MarkBattlerForControllerExec(gActiveBattler); gBattleMainFunc = BattleIntroPrintTrainerWantsToBattle; @@ -3612,7 +3613,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) { if (GetBattlerPosition(gActiveBattler) == position) { - BtlController_EmitIntroTrainerBallThrow(0); + BtlController_EmitIntroTrainerBallThrow(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } } @@ -3646,7 +3647,7 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) { if (GetBattlerPosition(gActiveBattler) == position) { - BtlController_EmitIntroTrainerBallThrow(0); + BtlController_EmitIntroTrainerBallThrow(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS)) { @@ -3679,7 +3680,8 @@ static void BattleIntroRecordMonsToDex(void) } } -void sub_803B3AC(void) // unused +// Unused +static void BattleIntroSkipRecordMonsToDex(void) { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3730,7 +3732,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) { if (GetBattlerPosition(gActiveBattler) == position) { - BtlController_EmitIntroTrainerBallThrow(0); + BtlController_EmitIntroTrainerBallThrow(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } } @@ -3765,7 +3767,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) { if (GetBattlerPosition(gActiveBattler) == position) { - BtlController_EmitIntroTrainerBallThrow(0); + BtlController_EmitIntroTrainerBallThrow(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); if (gBattleTypeFlags & (BATTLE_TYPE_MULTI)) { @@ -3782,7 +3784,8 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -void sub_803B598(void) // unused +// Unused +static void BattleIntroSwitchInPlayerMons(void) { if (gBattleControllerExecFlags == 0) { @@ -3790,7 +3793,7 @@ void sub_803B598(void) // unused { if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) { - BtlController_EmitSwitchInAnim(0, gBattlerPartyIndexes[gActiveBattler], FALSE); + BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], FALSE); MarkBattlerForControllerExec(gActiveBattler); } } @@ -3865,7 +3868,7 @@ static void TryDoEventsBeforeFirstTurn(void) } TurnValuesCleanUp(FALSE); SpecialStatusesClear(); - *(&gBattleStruct->field_91) = gAbsentBattlerFlags; + *(&gBattleStruct->absentBattlerFlags) = gAbsentBattlerFlags; BattlePutTextOnWindow(gText_EmptyString3, B_WIN_MSG); gBattleMainFunc = HandleTurnActionSelectionState; ResetSentPokesToOpponentValue(); @@ -3972,7 +3975,7 @@ void BattleTurnPassed(void) for (i = 0; i < MAX_BATTLERS_COUNT; i++) *(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE; - *(&gBattleStruct->field_91) = gAbsentBattlerFlags; + *(&gBattleStruct->absentBattlerFlags) = gAbsentBattlerFlags; BattlePutTextOnWindow(gText_EmptyString3, B_WIN_MSG); gBattleMainFunc = HandleTurnActionSelectionState; gRandomTurnNumber = Random(); @@ -4054,10 +4057,8 @@ void SwitchPartyOrder(u8 battler) u8 partyId1; u8 partyId2; - // gBattleStruct->field_60[battler][i] - for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) - gBattlePartyCurrentOrder[i] = *(battler * 3 + i + (u8*)(gBattleStruct->field_60)); + gBattlePartyCurrentOrder[i] = *(battler * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)); partyId1 = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battler]); partyId2 = GetPartyIdFromBattlePartyId(*(gBattleStruct->monToSwitchIntoId + battler)); @@ -4067,15 +4068,15 @@ void SwitchPartyOrder(u8 battler) { for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) { - *(battler * 3 + i + (u8*)(gBattleStruct->field_60)) = gBattlePartyCurrentOrder[i]; - *(BATTLE_PARTNER(battler) * 3 + i + (u8*)(gBattleStruct->field_60)) = gBattlePartyCurrentOrder[i]; + *(battler * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i]; + *(BATTLE_PARTNER(battler) * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i]; } } else { for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) { - *(battler * 3 + i + (u8*)(gBattleStruct->field_60)) = gBattlePartyCurrentOrder[i]; + *(battler * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i]; } } } @@ -4111,10 +4112,10 @@ static void HandleTurnActionSelectionState(void) *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; if (gBattleTypeFlags & BATTLE_TYPE_MULTI || (position & BIT_FLANK) == B_FLANK_LEFT - || gBattleStruct->field_91 & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))] + || gBattleStruct->absentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))] || gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == STATE_WAIT_ACTION_CONFIRMED) { - if (gBattleStruct->field_91 & gBitTable[gActiveBattler]) + if (gBattleStruct->absentBattlerFlags & gBitTable[gActiveBattler]) { gChosenActionByBattler[gActiveBattler] = B_ACTION_NOTHING_FAINTED; if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) @@ -4132,7 +4133,7 @@ static void HandleTurnActionSelectionState(void) } else { - BtlController_EmitChooseAction(0, gChosenActionByBattler[0], gBattleBufferB[0][1] | (gBattleBufferB[0][2] << 8)); + BtlController_EmitChooseAction(BUFFER_A, gChosenActionByBattler[0], gBattleBufferB[0][1] | (gBattleBufferB[0][2] << 8)); MarkBattlerForControllerExec(gActiveBattler); gBattleCommunication[gActiveBattler]++; } @@ -4181,7 +4182,7 @@ static void HandleTurnActionSelectionState(void) i); } - BtlController_EmitChooseMove(0, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo); + BtlController_EmitChooseMove(BUFFER_A, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo); MarkBattlerForControllerExec(gActiveBattler); } break; @@ -4200,17 +4201,17 @@ static void HandleTurnActionSelectionState(void) } else { - BtlController_EmitChooseItem(0, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); } break; case B_ACTION_SWITCH: - *(gBattleStruct->field_58 + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION) || gBattleTypeFlags & BATTLE_TYPE_ARENA || gStatuses3[gActiveBattler] & STATUS3_ROOTED) { - BtlController_EmitChoosePokemon(0, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); } else if ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_SHADOW_TAG)) || ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_ARENA_TRAP)) @@ -4219,16 +4220,16 @@ static void HandleTurnActionSelectionState(void) || ((i = AbilityBattleEffects(ABILITYEFFECT_CHECK_FIELD_EXCEPT_BATTLER, gActiveBattler, ABILITY_MAGNET_PULL, 0, 0)) && IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_STEEL))) { - BtlController_EmitChoosePokemon(0, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gLastUsedAbility, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gLastUsedAbility, gBattleStruct->battlerPartyOrders[gActiveBattler]); } else { if (gActiveBattler == 2 && gChosenActionByBattler[0] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(0, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + 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(0, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); else - BtlController_EmitChoosePokemon(0, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); } MarkBattlerForControllerExec(gActiveBattler); break; @@ -4243,7 +4244,7 @@ static void HandleTurnActionSelectionState(void) } break; case B_ACTION_SAFARI_POKEBLOCK: - BtlController_EmitChooseItem(0, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); break; case B_ACTION_CANCEL_PARTNER: @@ -4253,7 +4254,7 @@ static void HandleTurnActionSelectionState(void) if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_MULTIPLETURNS || gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_RECHARGE) { - BtlController_EmitEndBounceEffect(0); + BtlController_EmitEndBounceEffect(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); return; } @@ -4281,7 +4282,7 @@ static void HandleTurnActionSelectionState(void) { RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 3); } - BtlController_EmitEndBounceEffect(0); + BtlController_EmitEndBounceEffect(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); return; } @@ -4337,7 +4338,7 @@ static void HandleTurnActionSelectionState(void) return; case 15: gChosenActionByBattler[gActiveBattler] = B_ACTION_SWITCH; - sub_803CDF8(); + UpdateBattlerPartyOrdersOnSwitch(); return; default: RecordedBattle_CheckMovesetChanges(B_RECORD_MODE_PLAYBACK); @@ -4389,7 +4390,7 @@ static void HandleTurnActionSelectionState(void) } else { - sub_803CDF8(); + UpdateBattlerPartyOrdersOnSwitch(); gBattleCommunication[gActiveBattler]++; } break; @@ -4434,15 +4435,15 @@ static void HandleTurnActionSelectionState(void) else i = FALSE; - if (((gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_DOUBLE)) != BATTLE_TYPE_DOUBLE) + if (((gBattleTypeFlags & BATTLE_TYPE_MULTI) || !(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) || (position & BIT_FLANK) != B_FLANK_LEFT - || (*(&gBattleStruct->field_91) & gBitTable[GetBattlerAtPosition(position ^ BIT_FLANK)])) + || (*(&gBattleStruct->absentBattlerFlags) & gBitTable[GetBattlerAtPosition(position ^ BIT_FLANK)])) { - BtlController_EmitLinkStandbyMsg(0, 0, i); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_STOP_BOUNCE, i); } else { - BtlController_EmitLinkStandbyMsg(0, 1, i); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_STOP_BOUNCE_ONLY, i); } MarkBattlerForControllerExec(gActiveBattler); gBattleCommunication[gActiveBattler]++; @@ -4538,20 +4539,20 @@ static bool8 AllAtActionConfirmed(void) return FALSE; } -static void sub_803CDF8(void) +static void UpdateBattlerPartyOrdersOnSwitch(void) { *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = gBattleBufferB[gActiveBattler][1]; RecordedBattle_SetBattlerAction(gActiveBattler, gBattleBufferB[gActiveBattler][1]); if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) { - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 0) &= 0xF; - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 1) = gBattleBufferB[gActiveBattler][3]; + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 1) = gBattleBufferB[gActiveBattler][3]; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 0) &= (0xF0); - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 2) = gBattleBufferB[gActiveBattler][3]; + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 3e91b64b12..9056aa58da 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -113,7 +113,7 @@ static void Cmd_jumpifstat(void); static void Cmd_jumpifstatus3condition(void); static void Cmd_jumpiftype(void); static void Cmd_getexp(void); -static void Cmd_unknown_24(void); +static void Cmd_checkteamslost(void); static void Cmd_movevaluescleanup(void); static void Cmd_setmultihit(void); static void Cmd_decrementmultihit(void); @@ -171,7 +171,7 @@ static void Cmd_yesnoboxlearnmove(void); static void Cmd_yesnoboxstoplearningmove(void); static void Cmd_hitanimation(void); static void Cmd_getmoneyreward(void); -static void Cmd_unknown_5E(void); +static void Cmd_updatebattlermoves(void); static void Cmd_swapattackerwithtarget(void); static void Cmd_incrementgamestat(void); static void Cmd_drawpartystatussummary(void); @@ -365,7 +365,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_jumpifstatus3condition, //0x21 Cmd_jumpiftype, //0x22 Cmd_getexp, //0x23 - Cmd_unknown_24, //0x24 + Cmd_checkteamslost, //0x24 Cmd_movevaluescleanup, //0x25 Cmd_setmultihit, //0x26 Cmd_decrementmultihit, //0x27 @@ -423,7 +423,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_yesnoboxstoplearningmove, //0x5B Cmd_hitanimation, //0x5C Cmd_getmoneyreward, //0x5D - Cmd_unknown_5E, //0x5E + Cmd_updatebattlermoves, //0x5E Cmd_swapattackerwithtarget, //0x5F Cmd_incrementgamestat, //0x60 Cmd_drawpartystatussummary, //0x61 @@ -1238,7 +1238,9 @@ static void Cmd_ppreduce(void) if (MOVE_IS_PERMANENT(gBattlerAttacker, gCurrMovePos)) { gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0, 1, &gBattleMons[gBattlerAttacker].pp[gCurrMovePos]); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0, + sizeof(gBattleMons[gBattlerAttacker].pp[gCurrMovePos]), + &gBattleMons[gBattlerAttacker].pp[gCurrMovePos]); MarkBattlerForControllerExec(gBattlerAttacker); } } @@ -1775,7 +1777,7 @@ static void Cmd_attackanimation(void) else multihit = gMultiHitCounter; - BtlController_EmitMoveAnimation(0, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit); + BtlController_EmitMoveAnimation(BUFFER_A, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit); gBattleScripting.animTurn += 1; gBattleScripting.animTargetsHit += 1; MarkBattlerForControllerExec(gBattlerAttacker); @@ -1820,7 +1822,7 @@ static void Cmd_healthbarupdate(void) else healthValue = maxPossibleDmgValue; - BtlController_EmitHealthBarUpdate(0, healthValue); + BtlController_EmitHealthBarUpdate(BUFFER_A, healthValue); MarkBattlerForControllerExec(gActiveBattler); if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleMoveDamage > 0) @@ -1944,7 +1946,7 @@ static void Cmd_datahpupdate(void) } } gHitMarker &= ~HITMARKER_PASSIVE_DAMAGE; - BtlController_EmitSetMonData(0, REQUEST_HP_BATTLE, 0, 2, &gBattleMons[gActiveBattler].hp); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp); MarkBattlerForControllerExec(gActiveBattler); } } @@ -1981,11 +1983,11 @@ static void Cmd_effectivenesssound(void) switch (gMoveResultFlags & (u8)(~MOVE_RESULT_MISSED)) { case MOVE_RESULT_SUPER_EFFECTIVE: - BtlController_EmitPlaySE(0, SE_SUPER_EFFECTIVE); + BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE); MarkBattlerForControllerExec(gActiveBattler); break; case MOVE_RESULT_NOT_VERY_EFFECTIVE: - BtlController_EmitPlaySE(0, SE_NOT_EFFECTIVE); + BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE); MarkBattlerForControllerExec(gActiveBattler); break; case MOVE_RESULT_DOESNT_AFFECT_FOE: @@ -1998,17 +2000,17 @@ static void Cmd_effectivenesssound(void) default: if (gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) { - BtlController_EmitPlaySE(0, SE_SUPER_EFFECTIVE); + BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE); MarkBattlerForControllerExec(gActiveBattler); } else if (gMoveResultFlags & MOVE_RESULT_NOT_VERY_EFFECTIVE) { - BtlController_EmitPlaySE(0, SE_NOT_EFFECTIVE); + BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE); MarkBattlerForControllerExec(gActiveBattler); } else if (!(gMoveResultFlags & (MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED))) { - BtlController_EmitPlaySE(0, SE_EFFECTIVE); + BtlController_EmitPlaySE(BUFFER_A, SE_EFFECTIVE); MarkBattlerForControllerExec(gActiveBattler); } break; @@ -2121,7 +2123,7 @@ static void Cmd_printselectionstring(void) { gActiveBattler = gBattlerAttacker; - BtlController_EmitPrintSelectionString(0, T2_READ_16(gBattlescriptCurrInstr + 1)); + BtlController_EmitPrintSelectionString(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1)); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 3; @@ -2171,7 +2173,7 @@ static void Cmd_printselectionstringfromtable(void) ptr += gBattleCommunication[MULTISTRING_CHOOSER]; gActiveBattler = gBattlerAttacker; - BtlController_EmitPrintSelectionString(0, *ptr); + BtlController_EmitPrintSelectionString(BUFFER_A, *ptr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 5; @@ -2453,7 +2455,7 @@ void SetMoveEffect(bool8 primary, u8 certain) gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleCommunication[MOVE_EFFECT_BYTE]]; gActiveBattler = gEffectBattler; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gEffectBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].status1), &gBattleMons[gEffectBattler].status1); MarkBattlerForControllerExec(gActiveBattler); if (gHitMarker & HITMARKER_IGNORE_SAFEGUARD) @@ -2756,11 +2758,11 @@ void SetMoveEffect(bool8 primary, u8 certain) gBattleMons[gBattlerTarget].item = 0; gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gLastUsedItem); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gLastUsedItem), &gLastUsedItem); MarkBattlerForControllerExec(gBattlerAttacker); gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gBattlerTarget].item); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item); MarkBattlerForControllerExec(gBattlerTarget); BattleScriptPush(gBattlescriptCurrInstr + 1); @@ -2799,7 +2801,7 @@ void SetMoveEffect(bool8 primary, u8 certain) gBattleMons[gBattlerTarget].status1 &= ~STATUS1_PARALYSIS; gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); BattleScriptPush(gBattlescriptCurrInstr + 1); @@ -3006,7 +3008,7 @@ static void Cmd_tryfaintmon(void) BattleScriptPush(gBattlescriptCurrInstr); gBattlescriptCurrInstr = BattleScript_GrudgeTakesPp; gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]); + BtlController_EmitSetMonData(BUFFER_A, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].pp[moveIndex]), &gBattleMons[gActiveBattler].pp[moveIndex]); MarkBattlerForControllerExec(gActiveBattler); PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].moves[moveIndex]) @@ -3024,7 +3026,7 @@ static void Cmd_dofaintanimation(void) if (gBattleControllerExecFlags == 0) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitFaintAnimation(0); + BtlController_EmitFaintAnimation(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; } @@ -3039,7 +3041,7 @@ static void Cmd_cleareffectsonfaint(void) if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[gActiveBattler].hp == 0) { gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); } @@ -3405,7 +3407,7 @@ static void Cmd_getexp(void) gBattleResources->beforeLvlUp->stats[STAT_SPDEF] = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF); gActiveBattler = gBattleStruct->expGetterBattlerId; - BtlController_EmitExpUpdate(0, gBattleStruct->expGetterMonId, gBattleMoveDamage); + BtlController_EmitExpUpdate(BUFFER_A, gBattleStruct->expGetterMonId, gBattleMoveDamage); MarkBattlerForControllerExec(gActiveBattler); } gBattleScripting.getexpState++; @@ -3496,8 +3498,9 @@ static void Cmd_getexp(void) } // For battles that aren't BATTLE_TYPE_LINK or BATTLE_TYPE_RECORDED_LINK, the only thing this -// command does is check whether the player has won/lost by totaling each team's HP -static void Cmd_unknown_24(void) +// command does is check whether the player has won/lost by totaling each team's HP. It then +// sets gBattleOutcome accordingly, if necessary. +static void Cmd_checkteamslost(void) { u16 HP_count = 0; s32 i; @@ -3547,35 +3550,37 @@ static void Cmd_unknown_24(void) if (HP_count == 0) gBattleOutcome |= B_OUTCOME_WON; + // For link battles that haven't ended, count number of empty battler spots + // In link multi battles, jump to pointer if more than 1 spot empty + // In non-multi battles, jump to pointer if 1 spot is missing on both sides if (gBattleOutcome == 0 && (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK))) { - s32 foundPlayer = 0; - s32 foundOpponent; + s32 emptyPlayerSpots = 0; + s32 emptyOpponentSpots; for (i = 0; i < gBattlersCount; i += 2) { - if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) - foundPlayer++; + if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].faintedHasReplacement)) + emptyPlayerSpots++; } - foundOpponent = 0; - + emptyOpponentSpots = 0; for (i = 1; i < gBattlersCount; i += 2) { - if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) - foundOpponent++; + if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].faintedHasReplacement)) + emptyOpponentSpots++; } if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - if (foundOpponent + foundPlayer > 1) + if (emptyOpponentSpots + emptyPlayerSpots > 1) gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; } else { - if (foundOpponent != 0 && foundPlayer != 0) + if (emptyOpponentSpots != 0 && emptyPlayerSpots != 0) gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; @@ -3906,7 +3911,7 @@ static void Cmd_healthbar_update(void) else gActiveBattler = gBattlerAttacker; - BtlController_EmitHealthBarUpdate(0, gBattleMoveDamage); + BtlController_EmitHealthBarUpdate(BUFFER_A, gBattleMoveDamage); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; } @@ -3980,7 +3985,7 @@ static void Cmd_playanimation(void) || gBattlescriptCurrInstr[2] == B_ANIM_SNATCH_MOVE || gBattlescriptCurrInstr[2] == B_ANIM_SUBSTITUTE_FADE) { - BtlController_EmitBattleAnimation(0, gBattlescriptCurrInstr[2], *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 7; } @@ -3994,7 +3999,7 @@ static void Cmd_playanimation(void) || gBattlescriptCurrInstr[2] == B_ANIM_SANDSTORM_CONTINUES || gBattlescriptCurrInstr[2] == B_ANIM_HAIL_CONTINUES) { - BtlController_EmitBattleAnimation(0, gBattlescriptCurrInstr[2], *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 7; } @@ -4004,7 +4009,7 @@ static void Cmd_playanimation(void) } else { - BtlController_EmitBattleAnimation(0, gBattlescriptCurrInstr[2], *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 7; } @@ -4023,7 +4028,7 @@ static void Cmd_playanimation2(void) // animation Id is stored in the first poin || *animationIdPtr == B_ANIM_SNATCH_MOVE || *animationIdPtr == B_ANIM_SUBSTITUTE_FADE) { - BtlController_EmitBattleAnimation(0, *animationIdPtr, *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 10; } @@ -4036,7 +4041,7 @@ static void Cmd_playanimation2(void) // animation Id is stored in the first poin || *animationIdPtr == B_ANIM_SANDSTORM_CONTINUES || *animationIdPtr == B_ANIM_HAIL_CONTINUES) { - BtlController_EmitBattleAnimation(0, *animationIdPtr, *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 10; } @@ -4046,7 +4051,7 @@ static void Cmd_playanimation2(void) // animation Id is stored in the first poin } else { - BtlController_EmitBattleAnimation(0, *animationIdPtr, *argumentPtr); + BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 10; } @@ -4162,7 +4167,7 @@ static void Cmd_playstatchangeanimation(void) } else if (changeableStatsCount != 0 && !gBattleScripting.statAnimPlayed) { - BtlController_EmitBattleAnimation(0, B_ANIM_STATS_CHANGE, statAnimId); + BtlController_EmitBattleAnimation(BUFFER_A, B_ANIM_STATS_CHANGE, statAnimId); MarkBattlerForControllerExec(gActiveBattler); if (gBattlescriptCurrInstr[3] & STAT_CHANGE_MULTIPLE_STATS && changeableStatsCount > 1) gBattleScripting.statAnimPlayed = TRUE; @@ -4226,7 +4231,7 @@ static void Cmd_moveend(void) { gBattleMons[gBattlerTarget].status1 &= ~STATUS1_FREEZE; gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gBattlerTarget].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1); MarkBattlerForControllerExec(gActiveBattler); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_DefrostedViaFireMove; @@ -4305,7 +4310,7 @@ static void Cmd_moveend(void) && gHitMarker & HITMARKER_NO_ANIMATIONS) { gActiveBattler = gBattlerAttacker; - BtlController_EmitSpriteInvisibility(0, TRUE); + BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE); MarkBattlerForControllerExec(gActiveBattler); gBattleScripting.moveendState++; return; @@ -4318,7 +4323,7 @@ static void Cmd_moveend(void) || WasUnableToUseMove(gBattlerAttacker)) { gActiveBattler = gBattlerAttacker; - BtlController_EmitSpriteInvisibility(0, FALSE); + BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); gStatuses3[gBattlerAttacker] &= ~STATUS3_SEMI_INVULNERABLE; gSpecialStatuses[gBattlerAttacker].restoredBattlerSprite = 1; @@ -4332,7 +4337,7 @@ static void Cmd_moveend(void) && !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE)) { gActiveBattler = gBattlerTarget; - BtlController_EmitSpriteInvisibility(0, FALSE); + BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); gStatuses3[gBattlerTarget] &= ~STATUS3_SEMI_INVULNERABLE; gBattleScripting.moveendState++; @@ -4361,7 +4366,7 @@ static void Cmd_moveend(void) gLastPrintedMoves[gBattlerAttacker] = gChosenMove; } if (!(gAbsentBattlerFlags & gBitTable[gBattlerAttacker]) - && !(gBattleStruct->field_91 & gBitTable[gBattlerAttacker]) + && !(gBattleStruct->absentBattlerFlags & gBitTable[gBattlerAttacker]) && gBattleMoves[originallyUsedMove].effect != EFFECT_BATON_PASS) { if (gHitMarker & HITMARKER_OBEYS) @@ -4398,7 +4403,7 @@ static void Cmd_moveend(void) gBattleScripting.moveendState++; break; case MOVEEND_MIRROR_MOVE: // mirror move - if (!(gAbsentBattlerFlags & gBitTable[gBattlerAttacker]) && !(gBattleStruct->field_91 & gBitTable[gBattlerAttacker]) + if (!(gAbsentBattlerFlags & gBitTable[gBattlerAttacker]) && !(gBattleStruct->absentBattlerFlags & gBitTable[gBattlerAttacker]) && gBattleMoves[originallyUsedMove].flags & FLAG_MIRROR_MOVE_AFFECTED && gHitMarker & HITMARKER_OBEYS && gBattlerAttacker != gBattlerTarget && !(gHitMarker & HITMARKER_FAINTED(gBattlerTarget)) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) @@ -4556,7 +4561,7 @@ static void Cmd_returnatktoball(void) gActiveBattler = gBattlerAttacker; if (!(gHitMarker & HITMARKER_FAINTED(gActiveBattler))) { - BtlController_EmitReturnMonToBall(0, 0); + BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); } gBattlescriptCurrInstr++; @@ -4571,7 +4576,7 @@ static void Cmd_getswitchedmondata(void) gBattlerPartyIndexes[gActiveBattler] = *(gBattleStruct->monToSwitchIntoId + gActiveBattler); - BtlController_EmitGetMonData(0, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]]); + BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]]); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -4647,7 +4652,7 @@ static void Cmd_switchinanim(void) gAbsentBattlerFlags &= ~(gBitTable[gActiveBattler]); - BtlController_EmitSwitchInAnim(0, gBattlerPartyIndexes[gActiveBattler], gBattlescriptCurrInstr[2]); + BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], gBattlescriptCurrInstr[2]); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 3; @@ -4808,15 +4813,16 @@ 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 +// 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) { - *(gBattleStruct->field_58 + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); - BtlController_EmitChoosePokemon(0, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); } @@ -4831,9 +4837,9 @@ static void Cmd_openpartyscreen(void) flags = 0; jumpPtr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - if (gBattlescriptCurrInstr[1] == BS_UNK_5) + if (gBattlescriptCurrInstr[1] == BS_FAINTED_LINK_MULTIPLE_1) { - if ((gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_MULTI)) != BATTLE_TYPE_DOUBLE) + if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) || !(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { @@ -4843,46 +4849,46 @@ static void Cmd_openpartyscreen(void) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(PARTY_SIZE); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } } else { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } } else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - u8 flag40_0, flag40_1, flag40_2, flag40_3; + bool8 hasReplacement_0, hasReplacement_1, hasReplacement_2, hasReplacement_3; hitmarkerFaintBits = gHitMarker >> 28; if (gBitTable[0] & hitmarkerFaintBits) { gActiveBattler = 0; - if (HasNoMonsToSwitch(0, PARTY_SIZE, PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[2]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } else { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); flags |= 1; } @@ -4890,42 +4896,42 @@ static void Cmd_openpartyscreen(void) if (gBitTable[2] & hitmarkerFaintBits && !(gBitTable[0] & hitmarkerFaintBits)) { gActiveBattler = 2; - if (HasNoMonsToSwitch(2, PARTY_SIZE, PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[0]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } else if (!(flags & 1)) { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } if (gBitTable[1] & hitmarkerFaintBits) { gActiveBattler = 1; - if (HasNoMonsToSwitch(1, PARTY_SIZE, PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[3]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } else { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); flags |= 2; } @@ -4933,60 +4939,60 @@ static void Cmd_openpartyscreen(void) if (gBitTable[3] & hitmarkerFaintBits && !(gBitTable[1] & hitmarkerFaintBits)) { gActiveBattler = 3; - if (HasNoMonsToSwitch(3, PARTY_SIZE, PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, PARTY_SIZE, PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[1]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } else if (!(flags & 2)) { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } - flag40_0 = gSpecialStatuses[0].flag40; - if (!flag40_0) + hasReplacement_0 = gSpecialStatuses[0].faintedHasReplacement; + if (!hasReplacement_0) { - flag40_2 = gSpecialStatuses[2].flag40; - if (!flag40_2 && hitmarkerFaintBits != 0) + hasReplacement_2 = gSpecialStatuses[2].faintedHasReplacement; + if (!hasReplacement_2 && hitmarkerFaintBits != 0) { if (gAbsentBattlerFlags & gBitTable[0]) gActiveBattler = 2; else gActiveBattler = 0; - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } - flag40_1 = gSpecialStatuses[1].flag40; - if (!flag40_1) + hasReplacement_1 = gSpecialStatuses[1].faintedHasReplacement; + if (!hasReplacement_1) { - flag40_3 = gSpecialStatuses[3].flag40; - if (!flag40_3 && hitmarkerFaintBits != 0) + hasReplacement_3 = gSpecialStatuses[3].faintedHasReplacement; + if (!hasReplacement_3 && hitmarkerFaintBits != 0) { if (gAbsentBattlerFlags & gBitTable[1]) gActiveBattler = 3; else gActiveBattler = 1; - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } } gBattlescriptCurrInstr += 6; } - else if (gBattlescriptCurrInstr[1] == BS_UNK_6) + else if (gBattlescriptCurrInstr[1] == BS_FAINTED_LINK_MULTIPLE_2) { if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { @@ -4996,44 +5002,46 @@ static void Cmd_openpartyscreen(void) if (gBitTable[2] & hitmarkerFaintBits && gBitTable[0] & hitmarkerFaintBits) { gActiveBattler = 2; - if (HasNoMonsToSwitch(2, gBattleBufferB[0][1], PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, gBattleBufferB[0][1], PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[0]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } } if (gBitTable[3] & hitmarkerFaintBits && hitmarkerFaintBits & gBitTable[1]) { gActiveBattler = 3; - if (HasNoMonsToSwitch(3, gBattleBufferB[1][1], PARTY_SIZE)) + if (HasNoMonsToSwitch(gActiveBattler, gBattleBufferB[1][1], PARTY_SIZE)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - BtlController_EmitCantSwitch(0); + BtlController_EmitCantSwitch(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); } - else if (!gSpecialStatuses[gActiveBattler].flag40) + else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement) { ChooseMonToSendOut(gBattleStruct->monToSwitchIntoId[1]); - gSpecialStatuses[gActiveBattler].flag40 = TRUE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = TRUE; } } gBattlescriptCurrInstr += 6; } else { + // Not multi or double battle gBattlescriptCurrInstr += 6; } } else { + // Multi battle gBattlescriptCurrInstr += 6; } @@ -5055,7 +5063,7 @@ static void Cmd_openpartyscreen(void) hitmarkerFaintBits = PARTY_ACTION_SEND_OUT; battlerId = GetBattlerForBattleScript(gBattlescriptCurrInstr[1] & ~PARTY_SCREEN_OPTIONAL); - if (gSpecialStatuses[battlerId].flag40) + if (gSpecialStatuses[battlerId].faintedHasReplacement) { gBattlescriptCurrInstr += 6; } @@ -5069,16 +5077,16 @@ static void Cmd_openpartyscreen(void) else { gActiveBattler = battlerId; - *(gBattleStruct->field_58 + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = 6; + *(gBattleStruct->battlerPartyIndexes + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; + *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); - BtlController_EmitChoosePokemon(0, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (gActiveBattler ^ 2)), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + (gActiveBattler ^ 2)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 6; - if (GetBattlerPosition(gActiveBattler) == 0 && gBattleResults.playerSwitchesCounter < 255) + if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_LEFT && gBattleResults.playerSwitchesCounter < 255) gBattleResults.playerSwitchesCounter++; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) @@ -5087,7 +5095,7 @@ static void Cmd_openpartyscreen(void) { if (gActiveBattler != battlerId) { - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } @@ -5098,7 +5106,7 @@ static void Cmd_openpartyscreen(void) if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) gActiveBattler ^= BIT_FLANK; - BtlController_EmitLinkStandbyMsg(0, 2, FALSE); + BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } @@ -5146,13 +5154,13 @@ static void Cmd_switchhandleorder(void) if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) { - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 0) &= 0xF; - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); - *(gActiveBattler * 3 + (u8*)(gBattleStruct->field_60) + 1) = gBattleBufferB[gActiveBattler][3]; + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0); + *(gActiveBattler * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 1) = gBattleBufferB[gActiveBattler][3]; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 0) &= (0xF0); - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; - *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->field_60) + 2) = gBattleBufferB[gActiveBattler][3]; + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleBufferB[gActiveBattler][2] & 0xF0) >> 4; + *((gActiveBattler ^ BIT_FLANK) * 3 + (u8*)(gBattleStruct->battlerPartyOrders) + 2) = gBattleBufferB[gActiveBattler][3]; } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { @@ -5180,7 +5188,7 @@ static void Cmd_switchineffects(void) UpdateSentPokesToOpponentValue(gActiveBattler); gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler); - gSpecialStatuses[gActiveBattler].flag40 = FALSE; + gSpecialStatuses[gActiveBattler].faintedHasReplacement = FALSE; if (!(gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_SPIKES_DAMAGED) && (gSideStatuses[GetBattlerSide(gActiveBattler)] & SIDE_STATUS_SPIKES) @@ -5235,7 +5243,7 @@ static void Cmd_switchineffects(void) *hpOnSwitchout = gBattleMons[i].hp; } - if (gBattlescriptCurrInstr[1] == BS_UNK_5) + if (gBattlescriptCurrInstr[1] == BS_FAINTED_LINK_MULTIPLE_1) { u32 hitmarkerFaintBits = gHitMarker >> 28; @@ -5257,7 +5265,7 @@ static void Cmd_switchineffects(void) static void Cmd_trainerslidein(void) { gActiveBattler = GetBattlerAtPosition(gBattlescriptCurrInstr[1]); - BtlController_EmitTrainerSlide(0); + BtlController_EmitTrainerSlide(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -5266,7 +5274,7 @@ static void Cmd_trainerslidein(void) static void Cmd_playse(void) { gActiveBattler = gBattlerAttacker; - BtlController_EmitPlaySE(0, T2_READ_16(gBattlescriptCurrInstr + 1)); + BtlController_EmitPlaySE(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1)); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 3; @@ -5275,7 +5283,7 @@ static void Cmd_playse(void) static void Cmd_fanfare(void) { gActiveBattler = gBattlerAttacker; - BtlController_EmitPlayFanfareOrBGM(0, T2_READ_16(gBattlescriptCurrInstr + 1), FALSE); + BtlController_EmitPlayFanfareOrBGM(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1), FALSE); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 3; @@ -5284,7 +5292,7 @@ static void Cmd_fanfare(void) static void Cmd_playfaintcry(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitFaintingCry(0); + BtlController_EmitFaintingCry(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -5293,7 +5301,7 @@ static void Cmd_playfaintcry(void) static void Cmd_endlinkbattle(void) { gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - BtlController_EmitEndLinkBattle(0, gBattleOutcome); + BtlController_EmitEndLinkBattle(BUFFER_A, gBattleOutcome); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 1; @@ -5302,7 +5310,7 @@ static void Cmd_endlinkbattle(void) static void Cmd_returntoball(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitReturnMonToBall(0, 1); + BtlController_EmitReturnMonToBall(BUFFER_A, TRUE); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -5521,7 +5529,7 @@ static void Cmd_hitanimation(void) } else if (!(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE) || !(gBattleMons[gActiveBattler].status2 & STATUS2_SUBSTITUTE) || gDisableStructs[gActiveBattler].substituteHP == 0) { - BtlController_EmitHitAnimation(0); + BtlController_EmitHitAnimation(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; } @@ -5600,14 +5608,15 @@ static void Cmd_getmoneyreward(void) gBattlescriptCurrInstr++; } -static void Cmd_unknown_5E(void) +// Command is never used +static void Cmd_updatebattlermoves(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); switch (gBattleCommunication[0]) { case 0: - BtlController_EmitGetMonData(0, REQUEST_ALL_BATTLE, 0); + BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0); MarkBattlerForControllerExec(gActiveBattler); gBattleCommunication[0]++; break; @@ -5680,7 +5689,7 @@ static void Cmd_drawpartystatussummary(void) } } - BtlController_EmitDrawPartyStatusSummary(0, hpStatuses, 1); + BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatuses, 1); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -5689,7 +5698,7 @@ static void Cmd_drawpartystatussummary(void) static void Cmd_hidepartystatussummary(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitHidePartyStatusSummary(0); + BtlController_EmitHidePartyStatusSummary(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -5714,7 +5723,7 @@ static void Cmd_statusanimation(void) && gDisableStructs[gActiveBattler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(0, FALSE, gBattleMons[gActiveBattler].status1); + BtlController_EmitStatusAnimation(BUFFER_A, FALSE, gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); } gBattlescriptCurrInstr += 2; @@ -5733,7 +5742,7 @@ static void Cmd_status2animation(void) && gDisableStructs[gActiveBattler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(0, TRUE, gBattleMons[gActiveBattler].status2 & wantedToAnimate); + BtlController_EmitStatusAnimation(BUFFER_A, TRUE, gBattleMons[gActiveBattler].status2 & wantedToAnimate); MarkBattlerForControllerExec(gActiveBattler); } gBattlescriptCurrInstr += 6; @@ -5752,7 +5761,7 @@ static void Cmd_chosenstatusanimation(void) && gDisableStructs[gActiveBattler].substituteHP == 0 && !(gHitMarker & HITMARKER_NO_ANIMATIONS)) { - BtlController_EmitStatusAnimation(0, gBattlescriptCurrInstr[2], wantedStatus); + BtlController_EmitStatusAnimation(BUFFER_A, gBattlescriptCurrInstr[2], wantedStatus); MarkBattlerForControllerExec(gActiveBattler); } gBattlescriptCurrInstr += 7; @@ -5862,7 +5871,7 @@ static void Cmd_removeitem(void) *usedHeldItem = gBattleMons[gActiveBattler].item; gBattleMons[gActiveBattler].item = 0; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -6171,7 +6180,7 @@ static void Cmd_setatktoplayer0(void) static void Cmd_makevisible(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitSpriteInvisibility(0, FALSE); + BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -6382,7 +6391,7 @@ static void Cmd_various(void) gDisableStructs[1].truantSwitchInHack = 1; break; case VARIOUS_EMIT_YESNOBOX: - BtlController_EmitYesNoBox(0); + BtlController_EmitYesNoBox(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); break; case VARIOUS_DRAW_ARENA_REF_TEXT_BOX: @@ -6407,7 +6416,7 @@ static void Cmd_various(void) gActiveBattler = 1; if (gBattleMons[gActiveBattler].hp != 0) { - BtlController_EmitReturnMonToBall(0, 0); + BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); } break; @@ -6417,7 +6426,7 @@ static void Cmd_various(void) gActiveBattler = 3; if (gBattleMons[gActiveBattler].hp != 0) { - BtlController_EmitReturnMonToBall(0, 0); + BtlController_EmitReturnMonToBall(BUFFER_A, FALSE); MarkBattlerForControllerExec(gActiveBattler); } } @@ -6442,7 +6451,7 @@ static void Cmd_various(void) gBattleOutcome = B_OUTCOME_MON_TELEPORTED; break; case VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC: - BtlController_EmitPlayFanfareOrBGM(0, MUS_VICTORY_TRAINER, TRUE); + BtlController_EmitPlayFanfareOrBGM(BUFFER_A, MUS_VICTORY_TRAINER, TRUE); MarkBattlerForControllerExec(gActiveBattler); break; } @@ -6500,7 +6509,7 @@ static void Cmd_faintifabilitynotdamp(void) { gActiveBattler = gBattlerAttacker; gBattleMoveDamage = gBattleMons[gActiveBattler].hp; - BtlController_EmitHealthBarUpdate(0, INSTANT_HP_BAR_DROP); + BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr++; @@ -6527,7 +6536,7 @@ static void Cmd_setatkhptozero(void) gActiveBattler = gBattlerAttacker; gBattleMons[gActiveBattler].hp = 0; - BtlController_EmitSetMonData(0, REQUEST_HP_BATTLE, 0, 2, &gBattleMons[gActiveBattler].hp); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr++; @@ -6725,7 +6734,7 @@ static void Cmd_trysetrest(void) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_REST; gBattleMons[gBattlerTarget].status1 = STATUS1_SLEEP_TURN(3); - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 5; } @@ -7119,7 +7128,7 @@ static bool8 TryDoForceSwitchOut(void) { if (gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level) { - *(gBattleStruct->field_58 + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; + *(gBattleStruct->battlerPartyIndexes + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; } else { @@ -7129,7 +7138,7 @@ static bool8 TryDoForceSwitchOut(void) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); return FALSE; } - *(gBattleStruct->field_58 + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; + *(gBattleStruct->battlerPartyIndexes + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget]; } gBattlescriptCurrInstr = BattleScript_SuccessForceOut; @@ -7611,7 +7620,7 @@ static void Cmd_updatestatusicon(void) if (gBattlescriptCurrInstr[1] != BS_ATTACKER_WITH_PARTNER) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitStatusIconUpdate(0, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); + BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; } @@ -7620,7 +7629,7 @@ static void Cmd_updatestatusicon(void) gActiveBattler = gBattlerAttacker; if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler])) { - BtlController_EmitStatusIconUpdate(0, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); + BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); MarkBattlerForControllerExec(gActiveBattler); } if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) @@ -7628,7 +7637,7 @@ static void Cmd_updatestatusicon(void) gActiveBattler = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_FLANK); if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler])) { - BtlController_EmitStatusIconUpdate(0, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); + BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2); MarkBattlerForControllerExec(gActiveBattler); } } @@ -7706,7 +7715,7 @@ static void Cmd_transformdataexecution(void) } gActiveBattler = gBattlerAttacker; - BtlController_EmitResetActionMoveSelection(0, RESET_MOVE_SELECTION); + BtlController_EmitResetActionMoveSelection(BUFFER_A, RESET_MOVE_SELECTION); MarkBattlerForControllerExec(gActiveBattler); gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TRANSFORMED; } @@ -8075,7 +8084,7 @@ static void Cmd_copymovepermanently(void) // sketch } movePpData.ppBonuses = gBattleMons[gBattlerAttacker].ppBonuses; - BtlController_EmitSetMonData(0, REQUEST_MOVES_PP_BATTLE, 0, sizeof(struct MovePpInfo), &movePpData); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_MOVES_PP_BATTLE, 0, sizeof(movePpData), &movePpData); MarkBattlerForControllerExec(gActiveBattler); PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastPrintedMoves[gBattlerTarget]) @@ -8241,7 +8250,7 @@ static void Cmd_tryspiteppreduce(void) if (!(gDisableStructs[gActiveBattler].mimickedMoves & gBitTable[i]) && !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) { - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + i, 0, 1, &gBattleMons[gActiveBattler].pp[i]); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]); MarkBattlerForControllerExec(gActiveBattler); } @@ -8352,7 +8361,7 @@ static void Cmd_healpartystatus(void) if (toHeal) { gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, toHeal, 4, &zero); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero); MarkBattlerForControllerExec(gActiveBattler); } @@ -8958,7 +8967,7 @@ static void Cmd_jumpifattackandspecialattackcannotfall(void) // memento { gActiveBattler = gBattlerAttacker; gBattleMoveDamage = gBattleMons[gActiveBattler].hp; - BtlController_EmitHealthBarUpdate(0, INSTANT_HP_BAR_DROP); + BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 5; } @@ -8995,7 +9004,7 @@ static void Cmd_cureifburnedparalysedorpoisoned(void) // refresh gBattleMons[gBattlerAttacker].status1 = 0; gBattlescriptCurrInstr += 5; gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); } else @@ -9112,15 +9121,15 @@ static void Cmd_tryswapitems(void) // trick oldItemAtk = gBattleMons[gBattlerAttacker].item; *newItemAtk = gBattleMons[gBattlerTarget].item; - gBattleMons[gBattlerAttacker].item = 0; + gBattleMons[gBattlerAttacker].item = ITEM_NONE; gBattleMons[gBattlerTarget].item = oldItemAtk; gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, newItemAtk); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(*newItemAtk), newItemAtk); MarkBattlerForControllerExec(gBattlerAttacker); gActiveBattler = gBattlerTarget; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gBattlerTarget].item); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item); MarkBattlerForControllerExec(gBattlerTarget); *(u8*)((u8*)(&gBattleStruct->choicedMove[gBattlerTarget]) + 0) = 0; @@ -9134,9 +9143,9 @@ static void Cmd_tryswapitems(void) // trick PREPARE_ITEM_BUFFER(gBattleTextBuff1, *newItemAtk) PREPARE_ITEM_BUFFER(gBattleTextBuff2, oldItemAtk) - if (oldItemAtk != 0 && *newItemAtk != 0) + if (oldItemAtk != ITEM_NONE && *newItemAtk != ITEM_NONE) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ITEM_SWAP_BOTH; // attacker's item -> <- target's item - else if (oldItemAtk == 0 && *newItemAtk != 0) + else if (oldItemAtk == ITEM_NONE && *newItemAtk != ITEM_NONE) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ITEM_SWAP_TAKEN; // nothing -> <- target's item else gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ITEM_SWAP_GIVEN; // attacker's item -> <- nothing @@ -9462,7 +9471,10 @@ static void Cmd_switchoutabilities(void) { case ABILITY_NATURAL_CURE: gBattleMons[gActiveBattler].status1 = 0; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, gBitTable[*(gBattleStruct->field_58 + gActiveBattler)], 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, + gBitTable[*(gBattleStruct->battlerPartyIndexes + gActiveBattler)], + sizeof(gBattleMons[gActiveBattler].status1), + &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); break; } @@ -9599,7 +9611,7 @@ static void Cmd_docastformchangeanimation(void) if (gBattleMons[gActiveBattler].status2 & STATUS2_SUBSTITUTE) *(&gBattleStruct->formToChangeInto) |= CASTFORM_SUBSTITUTE; - BtlController_EmitBattleAnimation(0, B_ANIM_CASTFORM_CHANGE, gBattleStruct->formToChangeInto); + BtlController_EmitBattleAnimation(BUFFER_A, B_ANIM_CASTFORM_CHANGE, gBattleStruct->formToChangeInto); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr++; @@ -9680,7 +9692,7 @@ static void Cmd_tryrecycleitem(void) *usedHeldItem = ITEM_NONE; gBattleMons[gActiveBattler].item = gLastUsedItem; - BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 5; @@ -9775,13 +9787,13 @@ static void Cmd_handleballthrow(void) if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - BtlController_EmitBallThrowAnim(0, BALL_TRAINER_BLOCK); + BtlController_EmitBallThrowAnim(BUFFER_A, BALL_TRAINER_BLOCK); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr = BattleScript_TrainerBallBlock; } else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) { - BtlController_EmitBallThrowAnim(0, BALL_3_SHAKES_SUCCESS); + BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr = BattleScript_WallyBallThrow; } @@ -9867,7 +9879,7 @@ static void Cmd_handleballthrow(void) if (odds > 254) // mon caught { - BtlController_EmitBallThrowAnim(0, BALL_3_SHAKES_SUCCESS); + BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr = BattleScript_SuccessBallThrow; SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem); @@ -9889,7 +9901,7 @@ static void Cmd_handleballthrow(void) if (gLastUsedItem == ITEM_MASTER_BALL) shakes = BALL_3_SHAKES_SUCCESS; // why calculate the shakes before that check? - BtlController_EmitBallThrowAnim(0, shakes); + BtlController_EmitBallThrowAnim(BUFFER_A, shakes); MarkBattlerForControllerExec(gActiveBattler); if (shakes == BALL_3_SHAKES_SUCCESS) // mon caught, copy of the code above @@ -10178,7 +10190,7 @@ static void Cmd_finishturn(void) static void Cmd_trainerslideout(void) { gActiveBattler = GetBattlerAtPosition(gBattlescriptCurrInstr[1]); - BtlController_EmitTrainerSlideBack(0); + BtlController_EmitTrainerSlideBack(BUFFER_A); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; diff --git a/src/battle_util.c b/src/battle_util.c index ac2fbd34fe..6bb6d9ae4a 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -82,7 +82,7 @@ void HandleAction_UseMove(void) gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) + if (*(&gBattleStruct->absentBattlerFlags) & gBitTable[gBattlerAttacker]) { gCurrentActionFuncId = B_ACTION_FINISHED; return; @@ -299,7 +299,7 @@ void HandleAction_Switch(void) gActionSelectionCursor[gBattlerAttacker] = 0; gMoveSelectionCursor[gBattlerAttacker] = 0; - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->battlerPartyIndexes + gBattlerAttacker)) gBattleScripting.battler = gBattlerAttacker; gBattlescriptCurrInstr = BattleScript_ActionSwitch; @@ -708,11 +708,11 @@ u8 GetBattlerForBattleScript(u8 caseId) case BS_FAINTED: ret = gBattlerFainted; break; - case BS_UNK_5: + case BS_FAINTED_LINK_MULTIPLE_1: ret = gBattlerFainted; break; case BS_ATTACKER_WITH_PARTNER: - case BS_UNK_6: + case BS_FAINTED_LINK_MULTIPLE_2: case BS_ATTACKER_SIDE: case BS_NOT_ATTACKER_SIDE: case BS_PLAYER1: @@ -753,7 +753,7 @@ void PressurePPLose(u8 target, u8 attacker, u16 move) if (MOVE_IS_PERMANENT(attacker, moveIndex)) { gActiveBattler = attacker; - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]); MarkBattlerForControllerExec(gActiveBattler); } } @@ -785,7 +785,7 @@ void PressurePPLoseOnUsingImprison(u8 attacker) if (imprisonPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, imprisonPos)) { gActiveBattler = attacker; - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]); MarkBattlerForControllerExec(gActiveBattler); } } @@ -816,7 +816,7 @@ void PressurePPLoseOnUsingPerishSong(u8 attacker) if (perishSongPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, perishSongPos)) { gActiveBattler = attacker; - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBattler].pp[perishSongPos]); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBattler].pp[perishSongPos]); MarkBattlerForControllerExec(gActiveBattler); } } @@ -887,7 +887,7 @@ bool8 WasUnableToUseMove(u8 battler) void PrepareStringBattle(u16 stringId, u8 battler) { gActiveBattler = battler; - BtlController_EmitPrintString(0, stringId); + BtlController_EmitPrintString(BUFFER_A, stringId); MarkBattlerForControllerExec(gActiveBattler); } @@ -1616,7 +1616,7 @@ u8 DoBattlerEndTurnEffects(void) gBattleCommunication[MULTISTRING_CHOOSER] = 1; BattleScriptExecute(BattleScript_MonWokeUpInUproar); gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); break; } @@ -1741,7 +1741,7 @@ u8 DoBattlerEndTurnEffects(void) { CancelMultiTurnMoves(gActiveBattler); gBattleMons[gActiveBattler].status1 |= STATUS1_SLEEP_TURN((Random() & 3) + 2); // 2-5 turns of sleep - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); gEffectBattler = gActiveBattler; BattleScriptExecute(BattleScript_YawnMakesAsleep); @@ -2251,7 +2251,7 @@ u8 AtkCanceller_UnableToUseMove(void) if (effect == 2) { gActiveBattler = gBattlerAttacker; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); } return effect; @@ -2615,7 +2615,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; // fix nightmare glitch gBattleScripting.battler = gActiveBattler = battler; BattleScriptPushCursorAndCallback(BattleScript_ShedSkinActivates); - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1); MarkBattlerForControllerExec(gActiveBattler); effect++; } @@ -2926,7 +2926,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA gBattlescriptCurrInstr = BattleScript_AbilityCuredStatus; gBattleScripting.battler = battler; gActiveBattler = battler; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); return effect; } @@ -3354,7 +3354,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) PREPARE_MOVE_BUFFER(gBattleTextBuff1, move); BattleScriptExecute(BattleScript_BerryPPHealEnd2); - BtlController_EmitSetMonData(0, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP); + BtlController_EmitSetMonData(BUFFER_A, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP); MarkBattlerForControllerExec(gActiveBattler); effect = ITEM_PP_CHANGE; } @@ -3589,7 +3589,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) switch (effect) { case ITEM_STATUS_CHANGE: - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1); MarkBattlerForControllerExec(gActiveBattler); break; case ITEM_PP_CHANGE: @@ -3740,7 +3740,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleScripting.battler = battlerId; gPotentialItemEffectBattler = battlerId; gActiveBattler = battlerId; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); break; } diff --git a/src/battle_util2.c b/src/battle_util2.c index 794b4f36af..767e314927 100644 --- a/src/battle_util2.c +++ b/src/battle_util2.c @@ -108,16 +108,13 @@ void SwitchPartyOrderInGameMulti(u8 battlerId, u8 arg1) if (GetBattlerSide(battlerId) != B_SIDE_OPPONENT) { s32 i; - - // gBattleStruct->field_60[0][i] - for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) - gBattlePartyCurrentOrder[i] = *(0 * 3 + i + (u8*)(gBattleStruct->field_60)); + gBattlePartyCurrentOrder[i] = *(0 * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)); SwitchPartyMonSlots(GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battlerId]), GetPartyIdFromBattlePartyId(arg1)); for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) - *(0 * 3 + i + (u8*)(gBattleStruct->field_60)) = gBattlePartyCurrentOrder[i]; + *(0 * 3 + i + (u8*)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i]; } } @@ -207,7 +204,7 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId) if (effect == 2) { gActiveBattler = battlerId; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); MarkBattlerForControllerExec(gActiveBattler); } diff --git a/src/party_menu.c b/src/party_menu.c index a55d397d2e..b4ff08313f 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -5840,7 +5840,7 @@ static void BufferBattlePartyOrder(u8 *partyBattleOrder, u8 flankId) void BufferBattlePartyCurrentOrderBySide(u8 battlerId, u8 flankId) { - BufferBattlePartyOrderBySide(gBattleStruct->field_60[battlerId], flankId, battlerId); + BufferBattlePartyOrderBySide(gBattleStruct->battlerPartyOrders[battlerId], flankId, battlerId); } // when GetBattlerSide(battlerId) == B_SIDE_PLAYER, this function is identical the one above @@ -5920,8 +5920,8 @@ void SwitchPartyOrderLinkMulti(u8 battlerId, u8 slot, u8 slot2) if (IsMultiBattle()) { - partyBattleOrder = gBattleStruct->field_60[battlerId]; - for (i = j = 0; i < 3; j++, i++) + partyBattleOrder = gBattleStruct->battlerPartyOrders[battlerId]; + for (i = j = 0; i < PARTY_SIZE / 2; j++, i++) { partyIds[j] = partyBattleOrder[i] >> 4; j++; diff --git a/src/pokemon.c b/src/pokemon.c index f4ca3f4c10..6e3d37ae39 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5042,7 +5042,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov temp2 = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitGetMonData(0, REQUEST_ALL_BATTLE, 0); + BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0); MarkBattlerForControllerExec(gActiveBattler); gActiveBattler = temp2; }