diff options
Diffstat (limited to 'src/battle_main.c')
-rw-r--r-- | src/battle_main.c | 453 |
1 files changed, 251 insertions, 202 deletions
diff --git a/src/battle_main.c b/src/battle_main.c index 8481a108a..6ed9f1232 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -61,13 +61,9 @@ #include "constants/trainers.h" #include "cable_club.h" -extern struct MusicPlayerInfo gMPlayInfo_SE1; -extern struct MusicPlayerInfo gMPlayInfo_SE2; - extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; -// this file's functions static void CB2_InitBattleInternal(void); static void CB2_PreInitMultiBattle(void); static void CB2_PreInitIngamePlayerPartnerBattle(void); @@ -77,19 +73,18 @@ static void CB2_HandleStartBattle(void); static void TryCorrectShedinjaLanguage(struct Pokemon *mon); static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 firstTrainer); static void BattleMainCB1(void); -static void sub_8038538(struct Sprite *sprite); static void CB2_EndLinkBattle(void); static void EndLinkBattleInSteps(void); -static void sub_80392A8(void); -static void sub_803937C(void); -static void sub_803939C(void); +static void CB2_InitAskRecordBattle(void); +static void CB2_AskRecordBattle(void); +static void AskRecordBattle(void); static void SpriteCb_MoveWildMonToRight(struct Sprite *sprite); static void SpriteCb_WildMonShowHealthbox(struct Sprite *sprite); static void SpriteCb_WildMonAnimate(struct Sprite *sprite); -static void sub_80398D0(struct Sprite *sprite); +static void SpriteCB_Flicker(struct Sprite *sprite); static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void SpriteCb_BlinkVisible(struct Sprite *sprite); -static void SpriteCallbackDummy_3(struct Sprite *sprite); +static void SpriteCB_Idle(struct Sprite *sprite); static void SpriteCB_BattleSpriteSlideLeft(struct Sprite *sprite); static void TurnValuesCleanUp(bool8 var0); static void SpriteCB_BounceEffect(struct Sprite *sprite); @@ -123,8 +118,9 @@ static void HandleEndTurn_BattleLost(void); static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); +static void SpriteCB_UnusedBattleInit(struct Sprite* sprite); +static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite); -// EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0; EWRAM_DATA u16 gBattle_BG1_X = 0; @@ -141,14 +137,19 @@ EWRAM_DATA u8 gDisplayedStringBattle[300] = {0}; EWRAM_DATA u8 gBattleTextBuff1[TEXT_BUFF_ARRAY_COUNT] = {0}; EWRAM_DATA u8 gBattleTextBuff2[TEXT_BUFF_ARRAY_COUNT] = {0}; EWRAM_DATA u8 gBattleTextBuff3[TEXT_BUFF_ARRAY_COUNT] = {0}; -EWRAM_DATA static u32 sUnusedUnknownArray[25] = {0}; +// The below array is never intentionally used. However, Juan's +// defeat text (SootopolisCity_Gym_1F_Text_JuanDefeat) is too long +// for gDisplayedStringBattle and overflows into this array. If it +// is removed (and none of the buffers above are increased in size) +// it will instead overflow into useful data. +EWRAM_DATA static u32 sFlickerArray[25] = {0}; EWRAM_DATA u32 gBattleTypeFlags = 0; EWRAM_DATA u8 gBattleTerrain = 0; EWRAM_DATA u32 gUnusedFirstBattleVar1 = 0; // Never read -EWRAM_DATA struct UnknownPokemonStruct4 gMultiPartnerParty[MULTI_PARTY_SIZE] = {0}; -EWRAM_DATA static struct UnknownPokemonStruct4* sMultiPartnerPartyBuffer = NULL; -EWRAM_DATA u8 *gUnknown_0202305C = NULL; -EWRAM_DATA u8 *gUnknown_02023060 = NULL; +EWRAM_DATA struct MultiPartnerMenuPokemon gMultiPartnerParty[MULTI_PARTY_SIZE] = {0}; +EWRAM_DATA static struct MultiPartnerMenuPokemon* sMultiPartnerPartyBuffer = NULL; +EWRAM_DATA u8 *gBattleAnimBgTileBuffer = NULL; +EWRAM_DATA u8 *gBattleAnimBgTilemapBuffer = NULL; EWRAM_DATA u8 gBattleBufferA[MAX_BATTLERS_COUNT][0x200] = {0}; EWRAM_DATA u8 gBattleBufferB[MAX_BATTLERS_COUNT][0x200] = {0}; EWRAM_DATA u8 gActiveBattler = 0; @@ -236,7 +237,6 @@ EWRAM_DATA u16 gBattleMovePower = 0; EWRAM_DATA u16 gMoveToLearn = 0; EWRAM_DATA u8 gBattleMonForms[MAX_BATTLERS_COUNT] = {0}; -// IWRAM common vars void (*gPreBattleCallback1)(void); void (*gBattleMainFunc)(void); struct BattleResults gBattleResults; @@ -247,7 +247,6 @@ u8 gMultiUsePlayerCursor; u8 gNumberOfMovesToChoose; u8 gBattleControllerData[MAX_BATTLERS_COUNT]; // Used by the battle controllers to store misc sprite/task IDs for each battler -// rom const data static const struct ScanlineEffectParams sIntroScanlineParams16Bit = { (void *)REG_ADDR_BG3HOFS, SCANLINE_EFFECT_DMACNT_16BIT, 1 @@ -259,7 +258,7 @@ static const struct ScanlineEffectParams sIntroScanlineParams32Bit = (void *)REG_ADDR_BG3HOFS, SCANLINE_EFFECT_DMACNT_32BIT, 1 }; -const struct SpriteTemplate gUnknown_0831AC88 = +const struct SpriteTemplate gUnusedBattleInitSprite = { .tileTag = 0, .paletteTag = 0, @@ -267,7 +266,7 @@ const struct SpriteTemplate gUnknown_0831AC88 = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_8038528, + .callback = SpriteCB_UnusedBattleInit, }; static const u8 sText_ShedinjaJpnName[] = _("ヌケニン"); // Nukenin @@ -512,53 +511,53 @@ const struct TrainerMoney gTrainerMoneyTable[] = {TRAINER_CLASS_HIKER, 10}, {TRAINER_CLASS_YOUNG_COUPLE, 8}, {TRAINER_CLASS_WINSTRATE, 10}, - {0xFF, 5}, + {0xFF, 5}, // Any trainer class not listed above uses this }; #include "data/text/abilities.h" static void (* const sTurnActionsFuncsTable[])(void) = { - [B_ACTION_USE_MOVE] = HandleAction_UseMove, - [B_ACTION_USE_ITEM] = HandleAction_UseItem, - [B_ACTION_SWITCH] = HandleAction_Switch, - [B_ACTION_RUN] = HandleAction_Run, + [B_ACTION_USE_MOVE] = HandleAction_UseMove, + [B_ACTION_USE_ITEM] = HandleAction_UseItem, + [B_ACTION_SWITCH] = HandleAction_Switch, + [B_ACTION_RUN] = HandleAction_Run, [B_ACTION_SAFARI_WATCH_CAREFULLY] = HandleAction_WatchesCarefully, - [B_ACTION_SAFARI_BALL] = HandleAction_SafariZoneBallThrow, - [B_ACTION_SAFARI_POKEBLOCK] = HandleAction_ThrowPokeblock, - [B_ACTION_SAFARI_GO_NEAR] = HandleAction_GoNear, - [B_ACTION_SAFARI_RUN] = HandleAction_SafariZoneRun, - [B_ACTION_WALLY_THROW] = HandleAction_WallyBallThrow, - [B_ACTION_EXEC_SCRIPT] = HandleAction_RunBattleScript, - [B_ACTION_TRY_FINISH] = HandleAction_TryFinish, - [B_ACTION_FINISHED] = HandleAction_ActionFinished, - [B_ACTION_NOTHING_FAINTED] = HandleAction_NothingIsFainted, + [B_ACTION_SAFARI_BALL] = HandleAction_SafariZoneBallThrow, + [B_ACTION_SAFARI_POKEBLOCK] = HandleAction_ThrowPokeblock, + [B_ACTION_SAFARI_GO_NEAR] = HandleAction_GoNear, + [B_ACTION_SAFARI_RUN] = HandleAction_SafariZoneRun, + [B_ACTION_WALLY_THROW] = HandleAction_WallyBallThrow, + [B_ACTION_EXEC_SCRIPT] = HandleAction_RunBattleScript, + [B_ACTION_TRY_FINISH] = HandleAction_TryFinish, + [B_ACTION_FINISHED] = HandleAction_ActionFinished, + [B_ACTION_NOTHING_FAINTED] = HandleAction_NothingIsFainted, }; static void (* const sEndTurnFuncsTable[])(void) = { - [0] = HandleEndTurn_ContinueBattle, //B_OUTCOME_NONE? - [B_OUTCOME_WON] = HandleEndTurn_BattleWon, - [B_OUTCOME_LOST] = HandleEndTurn_BattleLost, - [B_OUTCOME_DREW] = HandleEndTurn_BattleLost, - [B_OUTCOME_RAN] = HandleEndTurn_RanFromBattle, + [0] = HandleEndTurn_ContinueBattle, + [B_OUTCOME_WON] = HandleEndTurn_BattleWon, + [B_OUTCOME_LOST] = HandleEndTurn_BattleLost, + [B_OUTCOME_DREW] = HandleEndTurn_BattleLost, + [B_OUTCOME_RAN] = HandleEndTurn_RanFromBattle, [B_OUTCOME_PLAYER_TELEPORTED] = HandleEndTurn_FinishBattle, - [B_OUTCOME_MON_FLED] = HandleEndTurn_MonFled, - [B_OUTCOME_CAUGHT] = HandleEndTurn_FinishBattle, - [B_OUTCOME_NO_SAFARI_BALLS] = HandleEndTurn_FinishBattle, - [B_OUTCOME_FORFEITED] = HandleEndTurn_FinishBattle, - [B_OUTCOME_MON_TELEPORTED] = HandleEndTurn_FinishBattle, + [B_OUTCOME_MON_FLED] = HandleEndTurn_MonFled, + [B_OUTCOME_CAUGHT] = HandleEndTurn_FinishBattle, + [B_OUTCOME_NO_SAFARI_BALLS] = HandleEndTurn_FinishBattle, + [B_OUTCOME_FORFEITED] = HandleEndTurn_FinishBattle, + [B_OUTCOME_MON_TELEPORTED] = HandleEndTurn_FinishBattle, }; -const u8 gStatusConditionString_PoisonJpn[8] = _("どく$$$$$"); -const u8 gStatusConditionString_SleepJpn[8] = _("ねむり$$$$"); -const u8 gStatusConditionString_ParalysisJpn[8] = _("まひ$$$$$"); -const u8 gStatusConditionString_BurnJpn[8] = _("やけど$$$$"); -const u8 gStatusConditionString_IceJpn[8] = _("こおり$$$$"); -const u8 gStatusConditionString_ConfusionJpn[8] = _("こんらん$$$"); -const u8 gStatusConditionString_LoveJpn[8] = _("メロメロ$$$"); +const u8 gStatusConditionString_PoisonJpn[] = _("どく$$$$$"); +const u8 gStatusConditionString_SleepJpn[] = _("ねむり$$$$"); +const u8 gStatusConditionString_ParalysisJpn[] = _("まひ$$$$$"); +const u8 gStatusConditionString_BurnJpn[] = _("やけど$$$$"); +const u8 gStatusConditionString_IceJpn[] = _("こおり$$$$"); +const u8 gStatusConditionString_ConfusionJpn[] = _("こんらん$$$"); +const u8 gStatusConditionString_LoveJpn[] = _("メロメロ$$$"); -const u8 * const gStatusConditionStringsTable[7][2] = +const u8 * const gStatusConditionStringsTable[][2] = { {gStatusConditionString_PoisonJpn, gText_Poison}, {gStatusConditionString_SleepJpn, gText_Sleep}, @@ -569,7 +568,6 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; -// code void CB2_InitBattle(void) { MoveSaveBlocks_ResetHeap(); @@ -1022,8 +1020,10 @@ static void CB2_HandleStartBattle(void) } break; case 3: + // Link battle, send/receive party Pokémon 2 at a time if (IsLinkTaskFinished()) { + // Send Pokémon 1-2 SendBlock(bitmask_all_link_players_but_self(), gPlayerParty, sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } @@ -1031,6 +1031,7 @@ static void CB2_HandleStartBattle(void) case 4: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv Pokémon 1-2 ResetBlockReceivedFlags(); memcpy(gEnemyParty, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; @@ -1039,30 +1040,35 @@ static void CB2_HandleStartBattle(void) case 7: if (IsLinkTaskFinished()) { - SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 2, sizeof(struct Pokemon) * 2); + // Send Pokémon 3-4 + SendBlock(bitmask_all_link_players_but_self(), &gPlayerParty[2], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 8: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv Pokémon 3-4 ResetBlockReceivedFlags(); - memcpy(gEnemyParty + 2, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); + memcpy(&gEnemyParty[2], gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 11: if (IsLinkTaskFinished()) { - SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 4, sizeof(struct Pokemon) * 2); + // Send Pokémon 5-6 + SendBlock(bitmask_all_link_players_but_self(), &gPlayerParty[4], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 12: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv Pokémon 5-6 ResetBlockReceivedFlags(); - memcpy(gEnemyParty + 4, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); + memcpy(&gEnemyParty[4], gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); + TryCorrectShedinjaLanguage(&gEnemyParty[0]); TryCorrectShedinjaLanguage(&gEnemyParty[1]); TryCorrectShedinjaLanguage(&gEnemyParty[2]); @@ -1074,13 +1080,15 @@ static void CB2_HandleStartBattle(void) break; case 15: InitBattleControllers(); - sub_8184E58(); + RecordedBattle_SetTrainerInfo(); gBattleCommunication[SPRITES_INIT_STATE1] = 0; gBattleCommunication[SPRITES_INIT_STATE2] = 0; if (gBattleTypeFlags & BATTLE_TYPE_LINK) { + // Check if both players are using Emerald + // to determine if the recorded battle rng + // seed needs to be sent s32 i; - for (i = 0; i < 2 && (gLinkPlayers[i].version & 0xFF) == VERSION_EMERALD; i++); if (i == 2) @@ -1094,6 +1102,7 @@ static void CB2_HandleStartBattle(void) } break; case 16: + // Both players are using Emerald, send rng seed for recorded battle if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), &gRecordedBattleRngSeed, sizeof(gRecordedBattleRngSeed)); @@ -1101,6 +1110,7 @@ static void CB2_HandleStartBattle(void) } break; case 17: + // Receive rng seed for recorded battle (only read it if partner is the link master) if ((GetBlockReceivedStatus() & 3) == 3) { ResetBlockReceivedFlags(); @@ -1110,17 +1120,17 @@ static void CB2_HandleStartBattle(void) } break; case 18: + // Finish, start battle if (BattleInitAllSprites(&gBattleCommunication[SPRITES_INIT_STATE1], &gBattleCommunication[SPRITES_INIT_STATE2])) { gPreBattleCallback1 = gMain.callback1; gMain.callback1 = BattleMainCB1; SetMainCallback2(BattleMainCB2); if (gBattleTypeFlags & BATTLE_TYPE_LINK) - { gBattleTypeFlags |= BATTLE_TYPE_LINK_IN_BATTLE; - } } break; + // Introduce short delays between sending party Pokémon for link case 5: case 9: case 13: @@ -1138,7 +1148,7 @@ static void CB2_HandleStartBattle(void) static void CB2_HandleStartMultiPartnerBattle(void) { u8 playerMultiplayerId; - u8 enemyMultiplayerId; + u8 partnerMultiplayerId; RunTasks(); AnimateSprites(); @@ -1146,7 +1156,7 @@ static void CB2_HandleStartMultiPartnerBattle(void) playerMultiplayerId = GetMultiplayerId(); gBattleScripting.multiplayerId = playerMultiplayerId; - enemyMultiplayerId = playerMultiplayerId ^ BIT_SIDE; + partnerMultiplayerId = playerMultiplayerId ^ BIT_SIDE; switch (gBattleCommunication[MULTIUSE_STATE]) { @@ -1222,8 +1232,10 @@ static void CB2_HandleStartMultiPartnerBattle(void) } break; case 3: + // Link battle, send/receive party Pokémon in groups if (IsLinkTaskFinished()) { + // Send Pokémon 1-2 SendBlock(bitmask_all_link_players_but_self(), gPlayerParty, sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } @@ -1231,16 +1243,17 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 4: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv partner's Pokémon 1-2, and copy partner's and own Pokémon into party positions ResetBlockReceivedFlags(); if (gLinkPlayers[playerMultiplayerId].id != 0) { - memcpy(gPlayerParty, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); - memcpy(gPlayerParty + MULTI_PARTY_SIZE, gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon) * 2); + memcpy(gPlayerParty, gBlockRecvBuffer[partnerMultiplayerId], sizeof(struct Pokemon) * 2); + memcpy(&gPlayerParty[MULTI_PARTY_SIZE], gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon) * 2); } else { memcpy(gPlayerParty, gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon) * 2); - memcpy(gPlayerParty + MULTI_PARTY_SIZE, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon) * 2); + memcpy(&gPlayerParty[MULTI_PARTY_SIZE], gBlockRecvBuffer[partnerMultiplayerId], sizeof(struct Pokemon) * 2); } gBattleCommunication[MULTIUSE_STATE]++; } @@ -1248,23 +1261,25 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 5: if (IsLinkTaskFinished()) { - SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 2, sizeof(struct Pokemon)); + // Send Pokémon 3 + SendBlock(bitmask_all_link_players_but_self(), &gPlayerParty[2], sizeof(struct Pokemon)); gBattleCommunication[MULTIUSE_STATE]++; } break; case 6: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv partner's Pokémon 3, and copy partner's and own Pokémon into party positions ResetBlockReceivedFlags(); if (gLinkPlayers[playerMultiplayerId].id != 0) { - memcpy(gPlayerParty + 2, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon)); - memcpy(gPlayerParty + 5, gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon)); + memcpy(&gPlayerParty[2], gBlockRecvBuffer[partnerMultiplayerId], sizeof(struct Pokemon)); + memcpy(&gPlayerParty[2 + MULTI_PARTY_SIZE], gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon)); } else { - memcpy(gPlayerParty + 2, gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon)); - memcpy(gPlayerParty + 5, gBlockRecvBuffer[enemyMultiplayerId], sizeof(struct Pokemon)); + memcpy(&gPlayerParty[2], gBlockRecvBuffer[playerMultiplayerId], sizeof(struct Pokemon)); + memcpy(&gPlayerParty[2 + MULTI_PARTY_SIZE], gBlockRecvBuffer[partnerMultiplayerId], sizeof(struct Pokemon)); } gBattleCommunication[MULTIUSE_STATE]++; } @@ -1272,6 +1287,7 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 7: if (IsLinkTaskFinished()) { + // Send enemy Pokémon 1-2 to partner SendBlock(bitmask_all_link_players_but_self(), gEnemyParty, sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } @@ -1279,45 +1295,47 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 8: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv enemy Pokémon 1-2 (if not master) ResetBlockReceivedFlags(); if (GetMultiplayerId() != 0) - { memcpy(gEnemyParty, gBlockRecvBuffer[0], sizeof(struct Pokemon) * 2); - } gBattleCommunication[MULTIUSE_STATE]++; } break; case 9: if (IsLinkTaskFinished()) { - SendBlock(bitmask_all_link_players_but_self(), gEnemyParty + 2, sizeof(struct Pokemon) * 2); + // Send enemy Pokémon 3-4 to partner + SendBlock(bitmask_all_link_players_but_self(), &gEnemyParty[2], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 10: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv enemy Pokémon 3-4 (if not master) ResetBlockReceivedFlags(); if (GetMultiplayerId() != 0) - { - memcpy(gEnemyParty + 2, gBlockRecvBuffer[0], sizeof(struct Pokemon) * 2); - } + memcpy(&gEnemyParty[2], gBlockRecvBuffer[0], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 11: if (IsLinkTaskFinished()) { - SendBlock(bitmask_all_link_players_but_self(), gEnemyParty + 4, sizeof(struct Pokemon) * 2); + // Send enemy Pokémon 5-6 to partner + SendBlock(bitmask_all_link_players_but_self(), &gEnemyParty[4], sizeof(struct Pokemon) * 2); gBattleCommunication[MULTIUSE_STATE]++; } break; case 12: if ((GetBlockReceivedStatus() & 3) == 3) { + // Recv enemy Pokémon 5-6 (if not master) ResetBlockReceivedFlags(); if (GetMultiplayerId() != 0) - memcpy(gEnemyParty + 4, gBlockRecvBuffer[0], sizeof(struct Pokemon) * 2); + memcpy(&gEnemyParty[4], gBlockRecvBuffer[0], sizeof(struct Pokemon) * 2); + TryCorrectShedinjaLanguage(&gPlayerParty[0]); TryCorrectShedinjaLanguage(&gPlayerParty[1]); TryCorrectShedinjaLanguage(&gPlayerParty[2]); @@ -1335,19 +1353,16 @@ static void CB2_HandleStartMultiPartnerBattle(void) break; case 13: InitBattleControllers(); - sub_8184E58(); + RecordedBattle_SetTrainerInfo(); gBattleCommunication[SPRITES_INIT_STATE1] = 0; gBattleCommunication[SPRITES_INIT_STATE2] = 0; if (gBattleTypeFlags & BATTLE_TYPE_LINK) - { gBattleCommunication[MULTIUSE_STATE] = 14; - } else - { gBattleCommunication[MULTIUSE_STATE] = 16; - } break; case 14: + // Send rng seed for recorded battle if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), &gRecordedBattleRngSeed, sizeof(gRecordedBattleRngSeed)); @@ -1355,15 +1370,17 @@ static void CB2_HandleStartMultiPartnerBattle(void) } break; case 15: + // Receive rng seed for recorded battle (only read it if partner is the link master) if ((GetBlockReceivedStatus() & 3) == 3) { ResetBlockReceivedFlags(); if (!(gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)) - memcpy(&gRecordedBattleRngSeed, gBlockRecvBuffer[enemyMultiplayerId], sizeof(gRecordedBattleRngSeed)); + memcpy(&gRecordedBattleRngSeed, gBlockRecvBuffer[partnerMultiplayerId], sizeof(gRecordedBattleRngSeed)); gBattleCommunication[MULTIUSE_STATE]++; } break; case 16: + // Finish, start battle if (BattleInitAllSprites(&gBattleCommunication[SPRITES_INIT_STATE1], &gBattleCommunication[SPRITES_INIT_STATE2])) { TrySetLinkBattleTowerEnemyPartyLevel(); @@ -1371,31 +1388,29 @@ static void CB2_HandleStartMultiPartnerBattle(void) gMain.callback1 = BattleMainCB1; SetMainCallback2(BattleMainCB2); if (gBattleTypeFlags & BATTLE_TYPE_LINK) - { gBattleTypeFlags |= BATTLE_TYPE_LINK_IN_BATTLE; - } } break; } } -static void sub_80379F8(u8 arrayIdPlus) +static void SetMultiPartnerMenuParty(u8 offset) { s32 i; - for (i = 0; i < (int)ARRAY_COUNT(gMultiPartnerParty); i++) - { - gMultiPartnerParty[i].species = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_SPECIES); - gMultiPartnerParty[i].heldItem = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_HELD_ITEM); - GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_NICKNAME, gMultiPartnerParty[i].nickname); - gMultiPartnerParty[i].level = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_LEVEL); - gMultiPartnerParty[i].hp = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_HP); - gMultiPartnerParty[i].maxhp = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_MAX_HP); - gMultiPartnerParty[i].status = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_STATUS); - gMultiPartnerParty[i].personality = GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_PERSONALITY); - gMultiPartnerParty[i].gender = GetMonGender(&gPlayerParty[arrayIdPlus + i]); + for (i = 0; i < MULTI_PARTY_SIZE; i++) + { + gMultiPartnerParty[i].species = GetMonData(&gPlayerParty[offset + i], MON_DATA_SPECIES); + gMultiPartnerParty[i].heldItem = GetMonData(&gPlayerParty[offset + i], MON_DATA_HELD_ITEM); + GetMonData(&gPlayerParty[offset + i], MON_DATA_NICKNAME, gMultiPartnerParty[i].nickname); + gMultiPartnerParty[i].level = GetMonData(&gPlayerParty[offset + i], MON_DATA_LEVEL); + gMultiPartnerParty[i].hp = GetMonData(&gPlayerParty[offset + i], MON_DATA_HP); + gMultiPartnerParty[i].maxhp = GetMonData(&gPlayerParty[offset + i], MON_DATA_MAX_HP); + gMultiPartnerParty[i].status = GetMonData(&gPlayerParty[offset + i], MON_DATA_STATUS); + gMultiPartnerParty[i].personality = GetMonData(&gPlayerParty[offset + i], MON_DATA_PERSONALITY); + gMultiPartnerParty[i].gender = GetMonGender(&gPlayerParty[offset + i]); StripExtCtrlCodes(gMultiPartnerParty[i].nickname); - if (GetMonData(&gPlayerParty[arrayIdPlus + i], MON_DATA_LANGUAGE) != LANGUAGE_JAPANESE) + if (GetMonData(&gPlayerParty[offset + i], MON_DATA_LANGUAGE) != LANGUAGE_JAPANESE) PadNameString(gMultiPartnerParty[i].nickname, CHAR_SPACE); } memcpy(sMultiPartnerPartyBuffer, gMultiPartnerParty, sizeof(gMultiPartnerParty)); @@ -1405,15 +1420,15 @@ static void CB2_PreInitMultiBattle(void) { s32 i; u8 playerMultiplierId; - s32 numPlayers = 4; - u8 r4 = 0xF; + s32 numPlayers = MAX_BATTLERS_COUNT; + u8 blockMask = 0xF; u32 *savedBattleTypeFlags; void (**savedCallback)(void); if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) { numPlayers = 2; - r4 = 3; + blockMask = 3; } playerMultiplierId = GetMultiplayerId(); @@ -1430,14 +1445,14 @@ static void CB2_PreInitMultiBattle(void) case 0: if (gReceivedRemoteLinkPlayers != 0 && IsLinkTaskFinished()) { - sMultiPartnerPartyBuffer = Alloc(sizeof(struct UnknownPokemonStruct4) * ARRAY_COUNT(gMultiPartnerParty)); - sub_80379F8(0); - SendBlock(bitmask_all_link_players_but_self(), sMultiPartnerPartyBuffer, sizeof(struct UnknownPokemonStruct4) * ARRAY_COUNT(gMultiPartnerParty)); + sMultiPartnerPartyBuffer = Alloc(sizeof(gMultiPartnerParty)); + SetMultiPartnerMenuParty(0); + SendBlock(bitmask_all_link_players_but_self(), sMultiPartnerPartyBuffer, sizeof(gMultiPartnerParty)); gBattleCommunication[MULTIUSE_STATE]++; } break; case 1: - if ((GetBlockReceivedStatus() & r4) == r4) + if ((GetBlockReceivedStatus() & blockMask) == blockMask) { ResetBlockReceivedFlags(); for (i = 0; i < numPlayers; i++) @@ -1450,12 +1465,12 @@ static void CB2_PreInitMultiBattle(void) if ((!(gLinkPlayers[i].id & 1) && !(gLinkPlayers[playerMultiplierId].id & 1)) || (gLinkPlayers[i].id & 1 && gLinkPlayers[playerMultiplierId].id & 1)) { - memcpy(gMultiPartnerParty, gBlockRecvBuffer[i], sizeof(struct UnknownPokemonStruct4) * ARRAY_COUNT(gMultiPartnerParty)); + memcpy(gMultiPartnerParty, gBlockRecvBuffer[i], sizeof(gMultiPartnerParty)); } } else { - memcpy(gMultiPartnerParty, gBlockRecvBuffer[i], sizeof(struct UnknownPokemonStruct4) * ARRAY_COUNT(gMultiPartnerParty)); + memcpy(gMultiPartnerParty, gBlockRecvBuffer[i], sizeof(gMultiPartnerParty)); } } gBattleCommunication[MULTIUSE_STATE]++; @@ -1514,8 +1529,8 @@ static void CB2_PreInitIngamePlayerPartnerBattle(void) switch (gBattleCommunication[MULTIUSE_STATE]) { case 0: - sMultiPartnerPartyBuffer = Alloc(sizeof(struct UnknownPokemonStruct4) * ARRAY_COUNT(gMultiPartnerParty)); - sub_80379F8(3); + sMultiPartnerPartyBuffer = Alloc(sizeof(gMultiPartnerParty)); + SetMultiPartnerMenuParty(MULTI_PARTY_SIZE); gBattleCommunication[MULTIUSE_STATE]++; *savedCallback = gMain.savedCallback; *savedBattleTypeFlags = gBattleTypeFlags; @@ -1773,7 +1788,7 @@ static void CB2_HandleStartMultiBattle(void) break; case 7: InitBattleControllers(); - sub_8184E58(); + RecordedBattle_SetTrainerInfo(); gBattleCommunication[SPRITES_INIT_STATE1] = 0; gBattleCommunication[SPRITES_INIT_STATE2] = 0; if (gBattleTypeFlags & BATTLE_TYPE_LINK) @@ -1841,11 +1856,12 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && RecordedBattle_CanStopPlayback()) { + // Player pressed B during recorded battle playback, end battle gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); SetMainCallback2(CB2_QuitRecordedBattle); } } @@ -1854,7 +1870,7 @@ static void FreeRestoreBattleData(void) { gMain.callback1 = gPreBattleCallback1; gScanlineEffect.state = 3; - gMain.inBattle = 0; + gMain.inBattle = FALSE; ZeroEnemyPartyMons(); m4aSongNumStop(SE_LOW_HEALTH); FreeMonSpritesGfx(); @@ -1875,34 +1891,37 @@ void CB2_QuitRecordedBattle(void) } } -void sub_8038528(struct Sprite* sprite) +#define sState data[0] +#define sDelay data[4] + +static void SpriteCB_UnusedBattleInit(struct Sprite* sprite) { - sprite->data[0] = 0; - sprite->callback = sub_8038538; + sprite->sState = 0; + sprite->callback = SpriteCB_UnusedBattleInit_Main; } -static void sub_8038538(struct Sprite *sprite) +static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite) { - u16 *arr = (u16*)(gDecompressionBuffer); + u16 *arr = (u16*)gDecompressionBuffer; - switch (sprite->data[0]) + switch (sprite->sState) { case 0: - sprite->data[0]++; + sprite->sState++; sprite->data[1] = 0; sprite->data[2] = 0x281; sprite->data[3] = 0; - sprite->data[4] = 1; + sprite->sDelay = 1; // fall through case 1: - sprite->data[4]--; - if (sprite->data[4] == 0) + sprite->sDelay--; + if (sprite->sDelay == 0) { s32 i; s32 r2; s32 r0; - sprite->data[4] = 2; + sprite->sDelay = 2; r2 = sprite->data[1] + sprite->data[3] * 32; r0 = sprite->data[2] - sprite->data[3] * 32; for (i = 0; i < 29; i += 2) @@ -1913,7 +1932,7 @@ static void sub_8038538(struct Sprite *sprite) sprite->data[3]++; if (sprite->data[3] == 21) { - sprite->data[0]++; + sprite->sState++; sprite->data[1] = 32; } } @@ -1946,8 +1965,8 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { - if (gTrainers[trainerNum].partySize > 3) - monsCount = 3; + if (gTrainers[trainerNum].partySize > PARTY_SIZE / 2) + monsCount = PARTY_SIZE / 2; else monsCount = gTrainers[trainerNum].partySize; } @@ -2044,9 +2063,9 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir return gTrainers[trainerNum].partySize; } -void sub_8038A04(void) // unused +static void sub_8038A04(void) // unused { - if (REG_VCOUNT < 0xA0 && REG_VCOUNT >= 0x6F) + if (REG_VCOUNT < DISPLAY_HEIGHT && REG_VCOUNT >= 111) SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_SCREENBASE(24) | BGCNT_TXT256x512); } @@ -2246,33 +2265,35 @@ static void EndLinkBattleInSteps(void) case 1: if (--gBattleCommunication[1] == 0) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE]++; } break; case 2: if (!gPaletteFade.active) { - u8 monsCount; + u8 battlerCount; gMain.anyLinkBattlerHasFrontierPass = RecordedBattle_GetFrontierPassFlag(); if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - monsCount = 4; + battlerCount = 4; else - monsCount = 2; + battlerCount = 2; - for (i = 0; i < monsCount && (gLinkPlayers[i].version & 0xFF) == VERSION_EMERALD; i++); + for (i = 0; i < battlerCount && (gLinkPlayers[i].version & 0xFF) == VERSION_EMERALD; i++); - if (!gSaveBlock2Ptr->frontier.disableRecordBattle && i == monsCount) + if (!gSaveBlock2Ptr->frontier.disableRecordBattle && i == battlerCount) { if (FlagGet(FLAG_SYS_FRONTIER_PASS)) { + // Ask player if they want to record the battle FreeAllWindowBuffers(); - SetMainCallback2(sub_80392A8); + SetMainCallback2(CB2_InitAskRecordBattle); } else if (!gMain.anyLinkBattlerHasFrontierPass) { + // No players can record this battle, end SetMainCallback2(gMain.savedCallback); FreeBattleResources(); FreeBattleSpritesData(); @@ -2280,6 +2301,8 @@ static void EndLinkBattleInSteps(void) } else if (gReceivedRemoteLinkPlayers == 0) { + // Player can't record battle but + // another player can, reconnect with them CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; } @@ -2298,12 +2321,12 @@ static void EndLinkBattleInSteps(void) } break; case 3: - CpuFill32(0, (void*)(VRAM), VRAM_SIZE); + CpuFill32(0, (void*)VRAM, VRAM_SIZE); for (i = 0; i < 2; i++) LoadChosenBattleElement(i); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE]++; break; case 4: @@ -2337,7 +2360,7 @@ static void EndLinkBattleInSteps(void) case 9: if (!gMain.anyLinkBattlerHasFrontierPass || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.anyLinkBattlerHasFrontierPass = 0; + gMain.anyLinkBattlerHasFrontierPass = FALSE; SetMainCallback2(gMain.savedCallback); FreeBattleResources(); FreeBattleSpritesData(); @@ -2379,7 +2402,7 @@ u32 GetBattleBgTemplateData(u8 arrayId, u8 caseId) return ret; } -static void sub_80392A8(void) +static void CB2_InitAskRecordBattle(void) { s32 i; @@ -2407,14 +2430,14 @@ static void sub_80392A8(void) FreeAllSpritePalettes(); gReservedSpritePaletteCount = 4; SetVBlankCallback(VBlankCB_Battle); - SetMainCallback2(sub_803937C); + SetMainCallback2(CB2_AskRecordBattle); BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE] = 0; } -static void sub_803937C(void) +static void CB2_AskRecordBattle(void) { - sub_803939C(); + AskRecordBattle(); AnimateSprites(); BuildOamBuffer(); RunTextPrinters(); @@ -2422,33 +2445,50 @@ static void sub_803937C(void) RunTasks(); } -static void sub_803939C(void) + +// States for AskRecordBattle +#define STATE_INIT 0 +#define STATE_LINK 1 +#define STATE_WAIT_LINK 2 +#define STATE_ASK_RECORD 3 +#define STATE_PRINT_YES_NO 4 +#define STATE_HANDLE_YES_NO 5 +#define STATE_RECORD_NO 6 +#define STATE_END_RECORD_NO 7 +#define STATE_WAIT_END 8 +#define STATE_END 9 +#define STATE_RECORD_YES 10 +#define STATE_RECORD_WAIT 11 +#define STATE_END_RECORD_YES 12 + +static void AskRecordBattle(void) { switch (gBattleCommunication[MULTIUSE_STATE]) { - case 0: + case STATE_INIT: ShowBg(0); ShowBg(1); ShowBg(2); gBattleCommunication[MULTIUSE_STATE]++; break; - case 1: + case STATE_LINK: if (gMain.anyLinkBattlerHasFrontierPass && gReceivedRemoteLinkPlayers == 0) CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; break; - case 2: + case STATE_WAIT_LINK: if (!FuncIsActiveTask(Task_ReconnectWithLinkPlayers)) gBattleCommunication[MULTIUSE_STATE]++; break; - case 3: + case STATE_ASK_RECORD: if (!gPaletteFade.active) { + // "Would you like to record your battle on your FRONTIER PASS?" BattlePutTextOnWindow(gText_RecordBattleToPass, 0); gBattleCommunication[MULTIUSE_STATE]++; } break; - case 4: + case STATE_PRINT_YES_NO: if (!IsTextPrinterActive(0)) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); @@ -2458,11 +2498,12 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } break; - case 5: + case STATE_HANDLE_YES_NO: if (JOY_NEW(DPAD_UP)) { if (gBattleCommunication[CURSOR_POSITION] != 0) { + // Moved cursor onto Yes PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; @@ -2473,6 +2514,7 @@ static void sub_803939C(void) { if (gBattleCommunication[CURSOR_POSITION] == 0) { + // Moved cursor onto No PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; @@ -2484,12 +2526,14 @@ static void sub_803939C(void) PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) { + // Selected Yes HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); gBattleCommunication[1] = MoveRecordedBattleToSaveData(); - gBattleCommunication[MULTIUSE_STATE] = 10; + gBattleCommunication[MULTIUSE_STATE] = STATE_RECORD_YES; } else { + // Selected No gBattleCommunication[MULTIUSE_STATE]++; } } @@ -2499,19 +2543,20 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } break; - case 6: + case STATE_RECORD_NO: if (IsLinkTaskFinished() == TRUE) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); if (gMain.anyLinkBattlerHasFrontierPass) { + // Other battlers may be recording, wait for them SetLinkStandbyCallback(); BattlePutTextOnWindow(gText_LinkStandby3, 0); } - gBattleCommunication[MULTIUSE_STATE]++; + gBattleCommunication[MULTIUSE_STATE]++; // STATE_END_RECORD_NO } break; - case 8: + case STATE_WAIT_END: if (--gBattleCommunication[1] == 0) { if (gMain.anyLinkBattlerHasFrontierPass && !gWirelessCommType) @@ -2519,10 +2564,10 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } break; - case 9: + case STATE_END: if (!gMain.anyLinkBattlerHasFrontierPass || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) { - gMain.anyLinkBattlerHasFrontierPass = 0; + gMain.anyLinkBattlerHasFrontierPass = FALSE; if (!gPaletteFade.active) { SetMainCallback2(gMain.savedCallback); @@ -2532,24 +2577,24 @@ static void sub_803939C(void) } } break; - case 10: + case STATE_RECORD_YES: if (gBattleCommunication[1] == 1) { PlaySE(SE_SAVE); BattleStringExpandPlaceholdersToDisplayedString(gText_BattleRecordedOnPass); BattlePutTextOnWindow(gDisplayedStringBattle, 0); - gBattleCommunication[1] = 0x80; + gBattleCommunication[1] = 128; // Delay gBattleCommunication[MULTIUSE_STATE]++; } else { BattleStringExpandPlaceholdersToDisplayedString(BattleFrontier_BattleTowerBattleRoom_Text_RecordCouldntBeSaved); BattlePutTextOnWindow(gDisplayedStringBattle, 0); - gBattleCommunication[1] = 0x80; + gBattleCommunication[1] = 128; // Delay gBattleCommunication[MULTIUSE_STATE]++; } break; - case 11: + case STATE_RECORD_WAIT: if (IsLinkTaskFinished() == TRUE && !IsTextPrinterActive(0) && --gBattleCommunication[1] == 0) { if (gMain.anyLinkBattlerHasFrontierPass) @@ -2560,25 +2605,25 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } break; - case 12: - case 7: + case STATE_END_RECORD_YES: + case STATE_END_RECORD_NO: if (!IsTextPrinterActive(0)) { if (gMain.anyLinkBattlerHasFrontierPass) { if (IsLinkTaskFinished() == TRUE) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); - gBattleCommunication[1] = 0x20; - gBattleCommunication[MULTIUSE_STATE] = 8; + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gBattleCommunication[1] = 32; // Delay + gBattleCommunication[MULTIUSE_STATE] = STATE_WAIT_END; } } else { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); - gBattleCommunication[1] = 0x20; - gBattleCommunication[MULTIUSE_STATE] = 8; + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gBattleCommunication[1] = 32; // Delay + gBattleCommunication[MULTIUSE_STATE] = STATE_WAIT_END; } } break; @@ -2599,9 +2644,9 @@ static void TryCorrectShedinjaLanguage(struct Pokemon *mon) } } -u32 GetBattleWindowTemplatePixelWidth(u32 setId, u32 tableId) +u32 GetBattleWindowTemplatePixelWidth(u32 windowsType, u32 tableId) { - return gBattleWindowTemplates[setId][tableId].width * 8; + return gBattleWindowTemplates[windowsType][tableId].width * 8; } #define sBattler data[0] @@ -2651,31 +2696,37 @@ void SpriteCallbackDummy_2(struct Sprite *sprite) } +#define sNumFlickers data[3] +#define sDelay data[4] + // Unused -static void sub_80398BC(struct Sprite *sprite) +static void SpriteCB_InitFlicker(struct Sprite *sprite) { - sprite->data[3] = 6; - sprite->data[4] = 1; - sprite->callback = sub_80398D0; + sprite->sNumFlickers = 6; + sprite->sDelay = 1; + sprite->callback = SpriteCB_Flicker; } -static void sub_80398D0(struct Sprite *sprite) +static void SpriteCB_Flicker(struct Sprite *sprite) { - sprite->data[4]--; - if (sprite->data[4] == 0) + sprite->sDelay--; + if (sprite->sDelay == 0) { - sprite->data[4] = 8; + sprite->sDelay = 8; sprite->invisible ^= 1; - sprite->data[3]--; - if (sprite->data[3] == 0) + sprite->sNumFlickers--; + if (sprite->sNumFlickers == 0) { sprite->invisible = FALSE; sprite->callback = SpriteCallbackDummy_2; - sUnusedUnknownArray[0] = 0; + sFlickerArray[0] = 0; } } } +#undef sNumFlickers +#undef sDelay + extern const struct MonCoords gMonFrontPicCoords[]; extern const struct MonCoords gCastformFrontSpriteCoords[]; @@ -2772,7 +2823,7 @@ void SpriteCb_HideAsMoveTarget(struct Sprite *sprite) sprite->callback = SpriteCallbackDummy_2; } -void SpriteCb_OpponentMonFromBall(struct Sprite *sprite) +void SpriteCB_OpponentMonFromBall(struct Sprite *sprite) { if (sprite->affineAnimEnded) { @@ -2798,19 +2849,19 @@ static void SpriteCB_BattleSpriteSlideLeft(struct Sprite *sprite) sprite->x2 -= 2; if (sprite->x2 == 0) { - sprite->callback = SpriteCallbackDummy_3; + sprite->callback = SpriteCB_Idle; sprite->data[1] = 0; } } } // Unused -static void sub_80105DC(struct Sprite *sprite) +static void SetIdleSpriteCallback(struct Sprite *sprite) { - sprite->callback = SpriteCallbackDummy_3; + sprite->callback = SpriteCB_Idle; } -static void SpriteCallbackDummy_3(struct Sprite *sprite) +static void SpriteCB_Idle(struct Sprite *sprite) { } @@ -2923,23 +2974,25 @@ static void SpriteCB_BounceEffect(struct Sprite *sprite) #undef sBouncerSpriteId #undef sWhich -void SpriteCb_PlayerMonFromBall(struct Sprite *sprite) +void SpriteCB_PlayerMonFromBall(struct Sprite *sprite) { if (sprite->affineAnimEnded) BattleAnimateBackSprite(sprite, sprite->sSpeciesId); } -void sub_8039E60(struct Sprite *sprite) +static void SpriteCB_TrainerThrowObject_Main(struct Sprite *sprite) { sub_8039E9C(sprite); if (sprite->animEnded) - sprite->callback = SpriteCallbackDummy_3; + sprite->callback = SpriteCB_Idle; } +// Sprite callback for a trainer back pic to throw an object +// (Wally throwing a ball, throwing Pokéblocks/balls in the Safari Zone) void SpriteCB_TrainerThrowObject(struct Sprite *sprite) { StartSpriteAnim(sprite, 1); - sprite->callback = sub_8039E60; + sprite->callback = SpriteCB_TrainerThrowObject_Main; } void sub_8039E9C(struct Sprite *sprite) @@ -3235,7 +3288,7 @@ void FaintClearSetData(void) gProtectStructs[gActiveBattler].confusionSelfDmg = 0; gProtectStructs[gActiveBattler].targetNotAffected = 0; gProtectStructs[gActiveBattler].chargingTurn = 0; - gProtectStructs[gActiveBattler].fleeFlag = 0; + gProtectStructs[gActiveBattler].fleeType = 0; gProtectStructs[gActiveBattler].usedImprisonedMove = 0; gProtectStructs[gActiveBattler].loveImmobility = 0; gProtectStructs[gActiveBattler].usedDisabledMove = 0; @@ -4352,13 +4405,9 @@ static void HandleTurnActionSelectionState(void) break; case B_ACTION_SAFARI_POKEBLOCK: if ((gBattleBufferB[gActiveBattler][1] | (gBattleBufferB[gActiveBattler][2] << 8)) != 0) - { gBattleCommunication[gActiveBattler]++; - } else - { gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; - } break; case B_ACTION_SAFARI_GO_NEAR: gBattleCommunication[gActiveBattler]++; @@ -4984,15 +5033,15 @@ static void HandleEndTurn_RanFromBattle(void) } else { - switch (gProtectStructs[gBattlerAttacker].fleeFlag) + switch (gProtectStructs[gBattlerAttacker].fleeType) { default: gBattlescriptCurrInstr = BattleScript_GotAwaySafely; break; - case 1: + case FLEE_ITEM: gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; break; - case 2: + case FLEE_ABILITY: gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; break; } @@ -5055,7 +5104,7 @@ static void HandleEndTurn_FinishBattle(void) TryPutBreakingNewsOnAir(); } - sub_8186444(); + RecordedBattle_SetPlaybackFinished(); BeginFastPaletteFade(3); FadeOutMapMusic(5); gBattleMainFunc = FreeResetData_ReturnToOvOrDoEvolutions; @@ -5142,7 +5191,7 @@ static void ReturnFromBattleToOverworld(void) return; gSpecialVar_Result = gBattleOutcome; - gMain.inBattle = 0; + gMain.inBattle = FALSE; gMain.callback1 = gPreBattleCallback1; if (gBattleTypeFlags & BATTLE_TYPE_ROAMER) |