diff --git a/ld_script.txt b/ld_script.txt index 2ea2d0cfd..d6a10b16a 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -292,7 +292,6 @@ SECTIONS { src/text_window.o(.text); src/quest_log_player.o(.text); src/dodrio_berry_picking.o(.text); - src/dodrio_berry_picking_2.o(.text); src/battle_controller_pokedude.o(.text); src/quest_log_objects.o(.text); src/dodrio_berry_picking_3.o(.text); @@ -590,7 +589,6 @@ SECTIONS { src/text_window_graphics.o(.rodata); src/quest_log_player.o(.rodata); src/dodrio_berry_picking.o(.rodata); - src/dodrio_berry_picking_2.o(.rodata); src/battle_controller_pokedude.o(.rodata); src/teachy_tv.o(.rodata); src/digit_obj_util.o(.rodata); diff --git a/src/data/dodrio_berry_picking.h b/src/data/dodrio_berry_picking.h index e71ce13cf..9128495b1 100644 --- a/src/data/dodrio_berry_picking.h +++ b/src/data/dodrio_berry_picking.h @@ -1,6 +1,3 @@ -#ifndef GUARD_DATA_DODRIO_BERRY_PICKING_H -#define GUARD_DATA_DODRIO_BERRY_PICKING_H - static const struct BgTemplate sUnknown_847565C[] = { { @@ -243,5 +240,3 @@ static const u32 sDodrioBerryPkmnGfx[] = INCBIN_U32("graphics/link_games/dodriob static const u32 sDodrioBerryBgTilemap1[] = INCBIN_U32("graphics/link_games/dodrioberry_bg1.bin.lz"); static const u32 sDodrioBerryBgTilemap2Right[] = INCBIN_U32("graphics/link_games/dodrioberry_bg2right.bin.lz"); static const u32 sDodrioBerryBgTilemap2Left[] = INCBIN_U32("graphics/link_games/dodrioberry_bg2left.bin.lz"); - -#endif //GUARD_DATA_DODRIO_BERRY_PICKING_H diff --git a/src/dodrio_berry_picking.c b/src/dodrio_berry_picking.c index 15bc18c2b..86db5b58b 100644 --- a/src/dodrio_berry_picking.c +++ b/src/dodrio_berry_picking.c @@ -1,17 +1,22 @@ #include "global.h" #include "gflib.h" #include "dodrio_berry_picking.h" +#include "dynamic_placeholder_text_util.h" #include "event_data.h" #include "item.h" #include "link.h" #include "link_rfu.h" #include "m4a.h" +#include "menu.h" #include "minigame_countdown.h" +#include "new_menu_helpers.h" #include "random.h" +#include "save.h" #include "script.h" #include "strings.h" #include "task.h" #include "text_window.h" +#include "text_window_graphics.h" #include "constants/songs.h" #include "constants/sound.h" #include "constants/items.h" @@ -69,76 +74,383 @@ struct DodrioStruct /*0x3308*/ struct DodrioSubstruct_3308 unk3308[5]; }; // size = 0x3330 -static EWRAM_DATA struct DodrioStruct * gUnknown_203F3E0 = NULL; +struct DodrioStruct_2022CF4 +{ + u8 filler_00[0xc]; + u8 unkC[10]; + s16 unk16[10]; + u16 unk2A[10]; + u16 unk3E; +}; // size = 0x40 -static bool32 gUnknown_3002044; +static EWRAM_DATA struct DodrioStruct * sGame = NULL; +static EWRAM_DATA u16 *sDodrioSpriteIds[5] = {NULL}; +static EWRAM_DATA u16 *sCloudSpriteIds[2] = {NULL}; +static EWRAM_DATA u16 *sBerrySpriteIds[11] = {NULL}; +static EWRAM_DATA u16 *sBerryIconSpriteIds[4] = {NULL}; +static EWRAM_DATA struct DodrioStruct_2022CF4 * sStatusBar = NULL; +static EWRAM_DATA struct DodrioSubstruct_0160 * sGfx = NULL; -static void sub_81508D8(void); -static void sub_81508EC(struct DodrioStruct * dodrio); -static void sub_8150A84(u8 taskId); -static void sub_8150C78(void); -static void sub_8150CBC(void); -static void sub_8150CF4(void); -static void sub_8150D7C(void); -static void sub_8150DA4(void); -static void sub_8150E68(void); -static void sub_8150F40(void); -static void sub_8150FC4(void); -static void sub_8150FDC(void); -static void sub_815109C(void); -static void sub_8151198(void); -static void sub_81512B4(void); -static void sub_8151488(void); -static void sub_81514F0(void); -static void sub_815159C(void); -static void sub_81516DC(u8 taskId); -static void sub_8151750(u8 taskId); -static void sub_8151B54(void); -static void sub_8151BA0(void); -static void sub_8151C5C(void); -static void sub_8151D28(void); -static void sub_8151D98(void); -static void sub_8151E94(void); -static void sub_815201C(void); -static void sub_8152034(void); -static void sub_8152048(struct DodrioSubstruct_318C * dodrioMon, struct Pokemon * partyMon); -static void sub_815205C(TaskFunc func, u8 priority); -static void sub_815206C(TaskFunc func); -static void sub_8152090(u8 a0); -static bool32 sub_81520B4(void); -static void sub_8152110(void); -static bool32 sub_8152484(u8 a0, u8 a1, u8 a2); -static void sub_815256C(void); -static void sub_815293C(void); -static void sub_8152970(void); -static bool32 sub_8152A00(void); -static void sub_8152A70(void); -static void sub_81529A4(u8 a0, u8 *a1, u8 *a2); -static bool32 sub_8152A98(void); -static bool32 sub_8152AD8(void); -static void sub_8152B64(u8 a0); -static u8 sub_8152BD4(u8 a0); -static u8 sub_8152BF8(u8 a0, u8 a1); -static u8 sub_8152CB8(u8 arg0, u8 arg1); -static void sub_8152D34(u8 a0, u8 a1, u8 a2); -static void sub_8152F94(bool32 a0); -static void sub_8153004(void); -static void sub_8153048(void); -static void sub_8153150(void); -static void sub_81531FC(void); -static u8 sub_815327C(u8); -static void sub_81532B8(void); -static void sub_815336C(void); -static u32 sub_8153424(u8 mpId); +static bool32 sExitingGame; + +static void ResetTasksAndSprites(void); +static void InitDodrioGame(struct DodrioStruct * dodrio); +static void Task_StartDodrioGame(u8 taskId); +static void DoGameIntro(void); +static void InitCountdown(void); +static void DoCountdown(void); +static void WaitGameStart(void); +static void PlayGame_Leader(void); +static void PlayGame_Member(void); +static void WaitEndGame_Leader(void); +static void WaitEndGame_Member(void); +static void InitResults_Leader(void); +static void InitResults_Member(void); +static void DoResults(void); +static void AskPlayAgain(void); +static void EndLink(void); +static void ExitGame(void); +static void ResetGame(void); +static void Task_NewGameIntro(u8 taskId); +static void Task_CommunicateMonInfo(u8 taskId); +static void RecvLinkData_Leader(void); +static void SendLinkData_Leader(void); +static void RecvLinkData_Member(void); +static void SendLinkData_Member(void); +static void HandleSound_Leader(void); +static void HandleSound_Member(void); +static void CB2_DodrioGame(void); +static void VBlankCB_DodrioGame(void); +static void InitMonInfo(struct DodrioSubstruct_318C * dodrioMon, struct Pokemon * partyMon); +static void CreateTask_(TaskFunc func, u8 priority); +static void CreateDodrioGameTask(TaskFunc func); +static void SetGameFunc(u8 a0); +static bool32 SlideTreeBordersOut(void); +static void InitFirstWaveOfBerries(void); +static bool32 TryPickBerry(u8 a0, u8 a1, u8 a2); +static void UpdateFallingBerries(void); +static void UpdateGame_Leader(void); +static void UpdateGame_Member(void); +static bool32 AllPlayersReadyToStart(void); +static void ResetReadyToStart(void); +static void GetActiveBerryColumns(u8 a0, u8 *a1, u8 *a2); +static bool32 ReadyToEndGame_Leader(void); +static bool32 ReadyToEndGame_Member(void); +static void TryIncrementDifficulty(u8 a0); +static u8 GetPlayerIdAtColumn(u8 a0); +static u8 GetNewBerryId(u8 a0, u8 a1); +static u8 GetNewBerryIdByDifficulty(u8 arg0, u8 arg1); +static void IncrementBerryResult(u8 a0, u8 a1, u8 a2); +static void UpdateBerriesPickedInRow(bool32 a0); +static void SetMaxBerriesPickedInRow(void); +static void ResetForPlayAgainPrompt(void); +static void SetRandomPrize(void); +static void TryUpdateRecords(void); +static u8 UpdatePickStateQueue(u8); +static void HandleWaitPlayAgainInput(void); +static void ResetPickState(void); +static u32 GetScore(u8 mpId); static void Task_ShowDodrioBerryPickingRecords(u8 taskId); -static void sub_81538D0(u8 windowId); +static void PrintRecordsText(u8 windowId); +static void SpriteCB_Dodrio(struct Sprite *sprite); +static u32 DoDodrioMissedAnim(struct Sprite *sprite); +static u32 DoDodrioIntroAnim(struct Sprite *sprite); +static void SetDodrioInvisibility(bool8 a0, u8 a1); +static void SpriteCB_Status(struct Sprite *sprite); +static void SetBerryIconsInvisibility(bool8 a0); +static void SpriteCB_Cloud(struct Sprite *sprite); +static s16 GetDodrioXPos(u8 a0, u8 a1); +static void Task_TryRunGfxFunc(u8 taskId); +static void LoadGfx(void); +static void ShowNames(void); +static void ShowResults(void); +static void Msg_WantToPlayAgain(void); +static void Msg_SavingDontTurnOff(void); +static void Msg_CommunicationStandby(void); +static void EraseMessage(void); +static void Msg_SomeoneDroppedOut(void); +static void StopGfxFuncs(void); +static void GfxIdle(void); +static void SetGfxFunc(MainCallback cb); +MainCallback GetGfxFunc(void); +static void InitBgs(void); +static bool32 LoadBgGfx(void); +static void InitGameGfx(struct DodrioSubstruct_0160 * ptr); +void LoadDodrioGfx(void); +void CreateDodrioSprite(struct DodrioSubstruct_318C * arg0, u8 arg1, u8 id, u8 arg3); +void SetAllDodrioInvisibility(bool8 invisible, u8 count); +void LoadBerryGfx(void); +void CreateBerrySprites(void); +void CreateCloudSprites(void); +void CreateStatusBarSprites(void); +void StartDodrioIntroAnim(u8 unused); +void SetGfxFuncById(u8 arg0); +void SetStatusBarInvisibility(bool8 invisible); +void ResetCloudPos(void); +void SetCloudInvisibility(bool8 invisible); +u8 GetPlayAgainState(void); +u32 GetHighestScore(void); +void ResetBerryAndStatusBarSprites(void); +void FreeBerrySprites(void); +void FreeStatusBar(void); +void FreeDodrioSprites(u8 count); +void FreeCloudSprites(void); +void StartCloudMovement(void); +void ResetGfxState(void); +void InitStatusBarPos(void); +bool32 DoStatusBarIntro(void); +void StartDodrioMissedAnim(u8 unused); +void SetBerryInvisibility(u8 id, bool8 invisible); +void SetBerryAnim(u16 id, u8 frameNum); +void SetBerryYPos(u8 id, u8 y); +void SetDodrioAnim(u8 id, u8 frameNum); +void UpdateStatusBarAnim(u8 arg0); +bool32 IsGfxFuncActive(void); -// const rom data +static const struct BgTemplate sBgTemplates_Duplicate[] = +{ + { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0 + }, + { + .bg = 1, + .charBaseIndex = 2, + .mapBaseIndex = 12, + .screenSize = 1, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + }, + { + .bg = 2, + .charBaseIndex = 2, + .mapBaseIndex = 14, + .screenSize = 1, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + }, + { + .bg = 3, + .charBaseIndex = 3, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0 + }, +}; -// Assets in this header are duplicated -#include "data/dodrio_berry_picking.h" +static const struct WindowTemplate sWindowTemplate_Dummy_Duplicate = DUMMY_WIN_TEMPLATE; -static const u8 sUnknown_847553C[][3] = +static const struct WindowTemplate sWindowTemplates_Results_Duplicate[] = +{ + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 28, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, + }, + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 6, + .width = 28, + .height = 13, + .paletteNum = 13, + .baseBlock = 0x67, + } +}; + +static const struct WindowTemplate sWindowTemplate_Prize_Duplicate = +{ + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 6, + .width = 28, + .height = 7, + .paletteNum = 13, + .baseBlock = 0x67, +}; + +static const struct WindowTemplate sWindowTemplates_PlayAgain_Duplicate[] = +{ + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 8, + .width = 19, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, + }, + { + .bg = 0, + .tilemapLeft = 22, + .tilemapTop = 7, + .width = 6, + .height = 4, + .paletteNum = 13, + .baseBlock = 0x4C, + } +}; + +static const struct WindowTemplate sWindowTemplate_DroppedOut_Duplicate = +{ + .bg = 0, + .tilemapLeft = 4, + .tilemapTop = 6, + .width = 22, + .height = 5, + .paletteNum = 13, + .baseBlock = 0x13, +}; + +static const struct WindowTemplate sWindowTemplate_CommStandby_Duplicate = +{ + .bg = 0, + .tilemapLeft = 5, + .tilemapTop = 8, + .width = 19, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, +}; + +static const u8 sActiveColumnMap[5][5][11] = +{ + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 3, 8, 9, 0}, + {0, 1, 2, 5, 6, 3, 4, 5, 8, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 2, 9, 0}, + {0, 1, 4, 5, 6, 7, 2, 3, 4, 9, 0}, + {0, 1, 6, 7, 2, 3, 4, 5, 6, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 0}, + {0, 3, 4, 5, 6, 7, 8, 1, 2, 3, 0}, + {0, 5, 6, 7, 8, 1, 2, 3, 4, 5, 0}, + {0, 7, 8, 1, 2, 3, 4, 5, 6, 7, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + {2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}, + {4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4}, + {6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, + {8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8}, + }, +}; + +static const u8 sDodrioHeadToColumnMap[5][5][3] = +{ + { + {4, 5, 6}, + }, + { + {3, 4, 5}, + {5, 6, 3}, + }, + { + {4, 5, 6}, + {6, 7, 2}, + {2, 3, 4}, + }, + { + {3, 4, 5}, + {5, 6, 7}, + {7, 8, 1}, + {1, 2, 3}, + }, + { + {4, 5, 6}, + {6, 7, 8}, + {8, 9, 0}, + {0, 1, 2}, + {2, 3, 4}, + }, +}; + +static const u8 sDodrioNeighborMap[5][5][3] = +{ + { + {1, 0, 1}, + }, + { + {1, 0, 1}, + {0, 1, 0}, + }, + { + {2, 0, 1}, + {0, 1, 2}, + {1, 2, 0}, + }, + { + {3, 0, 1}, + {0, 1, 2}, + {1, 2, 3}, + {2, 3, 0}, + }, + { + {4, 0, 1}, + {0, 1, 2}, + {1, 2, 3}, + {2, 3, 4}, + {3, 4, 0}, + }, +}; + +ALIGNED(4) +static const u8 sPlayerIdAtColumn[5][11] = +{ + {9, 9, 9, 9, 1, 1, 1, 9, 9, 9, 9}, + {9, 9, 9, 0, 0, 1, 1, 0, 9, 9, 9}, + {9, 9, 2, 2, 0, 0, 1, 1, 1, 9, 9}, + {9, 3, 3, 0, 0, 1, 1, 2, 2, 3, 9}, + {3, 3, 4, 4, 0, 0, 1, 1, 2, 2, 3}, +}; + +static const u8 sUnsharedColumns[5][5] = +{ + {5}, + {4, 6}, + {3, 5, 7}, + {2, 4, 6, 8}, + {1, 3, 5, 6, 9}, +}; + +// Duplicate and unused gfx. +static const u32 sDuplicateGfx[] = INCBIN_U32("graphics/link_games/dodrioberry_bg1.gbapal", + "graphics/link_games/dodrioberry_bg2.gbapal", + "graphics/link_games/dodrioberry_pkmn.gbapal", + "graphics/link_games/dodrioberry_shiny.gbapal", + "graphics/link_games/dodrioberry_status.gbapal", + "graphics/link_games/dodrioberry_berrysprites.gbapal", + "graphics/link_games/dodrioberry_berrysprites.4bpp.lz", + "graphics/link_games/dodrioberry_platform.gbapal", + "graphics/link_games/dodrioberry_bg1.4bpp.lz", + "graphics/link_games/dodrioberry_bg2.4bpp.lz", + "graphics/link_games/dodrioberry_status.4bpp.lz", + "graphics/link_games/dodrioberry_platform.4bpp.lz", + "graphics/link_games/dodrioberry_pkmn.4bpp.lz", + "graphics/link_games/dodrioberry_bg1.bin.lz", + "graphics/link_games/dodrioberry_bg2right.bin.lz", + "graphics/link_games/dodrioberry_bg2left.bin.lz"); + +static const u8 sBerryFallDelays[][3] = { {40, 24, 13}, {32, 19, 10}, @@ -146,67 +458,67 @@ static const u8 sUnknown_847553C[][3] = }; ALIGNED(4) -static const u8 sUnknown_8475548[] = {8, 5, 8, 11, 15}; +static const u8 sTreeBorderXPos[] = {8, 5, 8, 11, 15}; ALIGNED(4) -static const u8 sUnknown_8475550[] = {5, 10, 20, 30, 50, 70, 100}; +static const u8 sDifficultyThresholds[] = {5, 10, 20, 30, 50, 70, 100}; ALIGNED(4) -static const u8 sUnknown_8475558[][10] = +static const u8 sPrizeBerryIds[][10] = { {15, 16, 17, 18, 19, 19, 18, 17, 16, 15}, {20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, {30, 31, 32, 33, 34, 34, 33, 32, 31, 30}, }; -static void (*const sUnknown_8475578[])(void) = +static void (*const sLeaderFuncs[])(void) = { - sub_8150C78, - sub_8150CBC, - sub_8150CF4, - sub_8150D7C, - sub_8150DA4, - sub_8150FDC, - sub_8151198, - sub_81512B4, - sub_8151488, - sub_81514F0, - sub_815159C, - sub_8150F40 + DoGameIntro, + InitCountdown, + DoCountdown, + WaitGameStart, + PlayGame_Leader, + InitResults_Leader, + DoResults, + AskPlayAgain, + EndLink, + ExitGame, + ResetGame, + WaitEndGame_Leader }; -static void (*const sUnknown_84755A8[])(void) = +static void (*const sMemberFuncs[])(void) = { - sub_8150C78, - sub_8150CBC, - sub_8150CF4, - sub_8150D7C, - sub_8150E68, - sub_815109C, - sub_8151198, - sub_81512B4, - sub_8151488, - sub_81514F0, - sub_815159C, - sub_8150FC4 + DoGameIntro, + InitCountdown, + DoCountdown, + WaitGameStart, + PlayGame_Member, + InitResults_Member, + DoResults, + AskPlayAgain, + EndLink, + ExitGame, + ResetGame, + WaitEndGame_Member }; void StartDodrioBerryPicking(u16 a0, MainCallback callback) { - gUnknown_3002044 = FALSE; + sExitingGame = FALSE; - if (gReceivedRemoteLinkPlayers && (gUnknown_203F3E0 = AllocZeroed(sizeof(*gUnknown_203F3E0))) != NULL) + if (gReceivedRemoteLinkPlayers && (sGame = AllocZeroed(sizeof(*sGame))) != NULL) { - sub_81508D8(); - sub_81508EC(gUnknown_203F3E0); - gUnknown_203F3E0->savedCallback = callback; - gUnknown_203F3E0->multiplayerId = GetMultiplayerId(); - gUnknown_203F3E0->unk32CC = gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId]; - sub_8152048(&gUnknown_203F3E0->unk318C[gUnknown_203F3E0->multiplayerId], &gPlayerParty[a0]); - CreateTask(sub_8150A84, 1); - SetMainCallback2(sub_815201C); - sub_8153150(); - sub_81529A4(gUnknown_203F3E0->unk24, &gUnknown_203F3E0->unk44, &gUnknown_203F3E0->unk48); + ResetTasksAndSprites(); + InitDodrioGame(sGame); + sGame->savedCallback = callback; + sGame->multiplayerId = GetMultiplayerId(); + sGame->unk32CC = sGame->unk31A0[sGame->multiplayerId]; + InitMonInfo(&sGame->unk318C[sGame->multiplayerId], &gPlayerParty[a0]); + CreateTask(Task_StartDodrioGame, 1); + SetMainCallback2(CB2_DodrioGame); + SetRandomPrize(); + GetActiveBerryColumns(sGame->unk24, &sGame->unk44, &sGame->unk48); StopMapMusic(); PlayNewMapMusic(MUS_BERRY_PICK); } @@ -217,14 +529,14 @@ void StartDodrioBerryPicking(u16 a0, MainCallback callback) } } -static void sub_81508D8(void) +static void ResetTasksAndSprites(void) { ResetTasks(); ResetSpriteData(); FreeAllSpritePalettes(); } -static void sub_81508EC(struct DodrioStruct * data) +static void InitDodrioGame(struct DodrioStruct * data) { u8 i; @@ -278,29 +590,29 @@ static void sub_81508EC(struct DodrioStruct * data) } } -static void sub_8150A84(u8 taskId) +static void Task_StartDodrioGame(u8 taskId) { u8 r4, r5; - switch (gUnknown_203F3E0->unk0C) + switch (sGame->unk0C) { case 0: SetVBlankCallback(NULL); - sub_815205C(sub_8151750, 4); - gUnknown_203F3E0->unk0C++; + CreateTask_(Task_CommunicateMonInfo, 4); + sGame->unk0C++; break; case 1: - if (!FuncIsActiveTask(sub_8151750)) + if (!FuncIsActiveTask(Task_CommunicateMonInfo)) { - sub_8154968(&gUnknown_203F3E0->unk160); - gUnknown_203F3E0->unk0C++; + InitGameGfx(&sGame->unk160); + sGame->unk0C++; } break; case 2: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { Rfu_SetLinkStandbyCallback(); - gUnknown_203F3E0->unk0C++; + sGame->unk0C++; } break; case 3: @@ -311,574 +623,574 @@ static void sub_8150A84(u8 taskId) LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); } - gUnknown_203F3E0->unk0C++; + sGame->unk0C++; } break; case 4: - r5 = gUnknown_203F3E0->unk24; - sub_8153A9C(); + r5 = sGame->unk24; + LoadDodrioGfx(); for (r4 = 0; r4 < r5; r4++) { - sub_8153AFC(&gUnknown_203F3E0->unk318C[gUnknown_203F3E0->unk34[r4]], r4, gUnknown_203F3E0->unk34[r4], gUnknown_203F3E0->unk24); + CreateDodrioSprite(&sGame->unk318C[sGame->unk34[r4]], r4, sGame->unk34[r4], sGame->unk24); } - sub_8153D80(FALSE, gUnknown_203F3E0->unk24); - gUnknown_203F3E0->unk0C++; + SetAllDodrioInvisibility(FALSE, sGame->unk24); + sGame->unk0C++; break; case 5: - sub_8154128(); - sub_815417C(); - sub_8154438(); - sub_8153E28(); - gUnknown_203F3E0->unk0C++; + LoadBerryGfx(); + CreateBerrySprites(); + CreateCloudSprites(); + CreateStatusBarSprites(); + sGame->unk0C++; break; case 6: BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - SetVBlankCallback(sub_8152034); - gUnknown_203F3E0->unk0C++; + SetVBlankCallback(VBlankCB_DodrioGame); + sGame->unk0C++; break; case 7: UpdatePaletteFade(); if (!gPaletteFade.active) { - gUnknown_203F3E0->unk0C++; + sGame->unk0C++; } break; default: DestroyTask(taskId); - sub_815206C(sub_81516DC); + CreateDodrioGameTask(Task_NewGameIntro); break; } } -static void sub_8150C08(u8 taskId) +static void Task_DodrioGame_Leader(u8 taskId) { - sub_8151B54(); - sUnknown_8475578[gUnknown_203F3E0->unk18](); - if (!gUnknown_3002044) + RecvLinkData_Leader(); + sLeaderFuncs[sGame->unk18](); + if (!sExitingGame) { - sub_815293C(); + UpdateGame_Leader(); } - sub_8151BA0(); + SendLinkData_Leader(); } -static void sub_8150C40(u8 taskId) +static void Task_DodrioGame_Member(u8 taskId) { - sub_8151C5C(); - sUnknown_84755A8[gUnknown_203F3E0->unk18](); - if (!gUnknown_3002044) + RecvLinkData_Member(); + sMemberFuncs[sGame->unk18](); + if (!sExitingGame) { - sub_8152970(); + UpdateGame_Member(); } - sub_8151D28(); + SendLinkData_Member(); } -static void sub_8150C78(void) +static void DoGameIntro(void) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - sub_8153BF8(1); - sub_81549D4(1); - gUnknown_203F3E0->unk10++; + StartDodrioIntroAnim(1); + SetGfxFuncById(1); + sGame->unk10++; break; case 1: - if (!sub_8155E68()) - sub_8152090(1); + if (!IsGfxFuncActive()) + SetGameFunc(1); break; } } -static void sub_8150CBC(void) +static void InitCountdown(void) { - if (gUnknown_203F3E0->unk10 == 0) + if (sGame->unk10 == 0) { - sub_8152110(); - gUnknown_203F3E0->unk10++; + InitFirstWaveOfBerries(); + sGame->unk10++; } else { - gUnknown_203F3E0->unk118 = 1; - sub_8152090(2); + sGame->unk118 = 1; + SetGameFunc(2); } } -static void sub_8150CF4(void) +static void DoCountdown(void) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: StartMinigameCountdown(7, 8, 120, 80, 0); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 1: Rfu_SetLinkStandbyCallback(); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 2: if (IsLinkTaskFinished()) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 3: if (!IsMinigameCountdownRunning()) { Rfu_SetLinkStandbyCallback(); - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 4: if (IsLinkTaskFinished()) { - sub_8152090(3); + SetGameFunc(3); } break; } } -static void sub_8150D7C(void) +static void WaitGameStart(void) { - if (gUnknown_203F3E0->unk10 == 0) + if (sGame->unk10 == 0) { - if (gUnknown_203F3E0->unk11C != 0) + if (sGame->unk11C != 0) { - sub_8152090(4); + SetGameFunc(4); } } } -static void sub_8150DA4(void) +static void PlayGame_Leader(void) { - if (gUnknown_203F3E0->unk10 == 0) + if (sGame->unk10 == 0) { - if (gUnknown_203F3E0->unk40 < 10) + if (sGame->unk40 < 10) { - if (gUnknown_203F3E0->unkA8[0] == 0) + if (sGame->unkA8[0] == 0) { if (JOY_NEW(DPAD_UP)) { - if (gUnknown_203F3E0->unk31A0[0].unk2C.unk0 == 0) + if (sGame->unk31A0[0].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk31A0[0].unk2C.unk4 = 0; - gUnknown_203F3E0->unk31A0[0].unk2C.unk0 = sub_815327C(2); + sGame->unk31A0[0].unk2C.unk4 = 0; + sGame->unk31A0[0].unk2C.unk0 = UpdatePickStateQueue(2); } } else if (JOY_NEW(DPAD_RIGHT)) { - if (gUnknown_203F3E0->unk31A0[0].unk2C.unk0 == 0) + if (sGame->unk31A0[0].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk31A0[0].unk2C.unk4 = 0; - gUnknown_203F3E0->unk31A0[0].unk2C.unk0 = sub_815327C(1); + sGame->unk31A0[0].unk2C.unk4 = 0; + sGame->unk31A0[0].unk2C.unk0 = UpdatePickStateQueue(1); } } else if (JOY_NEW(DPAD_LEFT)) { - if (gUnknown_203F3E0->unk31A0[0].unk2C.unk0 == 0) + if (sGame->unk31A0[0].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk31A0[0].unk2C.unk4 = 0; - gUnknown_203F3E0->unk31A0[0].unk2C.unk0 = sub_815327C(3); + sGame->unk31A0[0].unk2C.unk4 = 0; + sGame->unk31A0[0].unk2C.unk0 = UpdatePickStateQueue(3); } } else { - gUnknown_203F3E0->unk31A0[0].unk2C.unk0 = sub_815327C(0); + sGame->unk31A0[0].unk2C.unk0 = UpdatePickStateQueue(0); } } } else { - sub_8152090(11); + SetGameFunc(11); } - sub_815256C(); - sub_8151D98(); + UpdateFallingBerries(); + HandleSound_Leader(); } } -static void sub_8150E68(void) +static void PlayGame_Member(void) { - if (gUnknown_203F3E0->unk40 < 10) + if (sGame->unk40 < 10) { if (JOY_NEW(DPAD_UP)) { - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 == 0) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk32CC.unk2C.unk0 = 2; + sGame->unk32CC.unk2C.unk0 = 2; } } else if (JOY_NEW(DPAD_RIGHT)) { - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 == 0) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk32CC.unk2C.unk0 = 1; + sGame->unk32CC.unk2C.unk0 = 1; } } else if (JOY_NEW(DPAD_LEFT)) { - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 == 0) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 == 0) { - gUnknown_203F3E0->unk32CC.unk2C.unk0 = 3; + sGame->unk32CC.unk2C.unk0 = 3; } } else { - gUnknown_203F3E0->unk32CC.unk2C.unk0 = 0; + sGame->unk32CC.unk2C.unk0 = 0; } } else { - sub_8152090(11); + SetGameFunc(11); } - sub_8151E94(); + HandleSound_Member(); } -static void sub_8150F40(void) +static void WaitEndGame_Leader(void) { u8 i; - sub_815256C(); - sub_8151D98(); - if (sub_8152A98() == 1) + UpdateFallingBerries(); + HandleSound_Leader(); + if (ReadyToEndGame_Leader() == 1) { - sub_8153004(); - sub_8152090(5); + SetMaxBerriesPickedInRow(); + SetGameFunc(5); } else { - gUnknown_203F3E0->unk12C = 1; - for (i = 1; i < gUnknown_203F3E0->unk24; i++) + sGame->unk12C = 1; + for (i = 1; i < sGame->unk24; i++) { - if (gUnknown_203F3E0->unk130[i] != 1) + if (sGame->unk130[i] != 1) { - gUnknown_203F3E0->unk12C = 0; + sGame->unk12C = 0; break; } } } } -static void sub_8150FC4(void) +static void WaitEndGame_Member(void) { - sub_8151E94(); - if (sub_8152AD8() == 1) - sub_8152090(5); + HandleSound_Member(); + if (ReadyToEndGame_Member() == 1) + SetGameFunc(5); } -static void sub_8150FDC(void) +static void InitResults_Leader(void) { u8 blockReceivedStatus; u8 i; - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - SendBlock(0, gUnknown_203F3E0->unk4A, sizeof(gUnknown_203F3E0->unk4A)); - gUnknown_203F3E0->unk08 = 0; - gUnknown_203F3E0->unk10++; + SendBlock(0, sGame->unk4A, sizeof(sGame->unk4A)); + sGame->unk08 = 0; + sGame->unk10++; break; case 1: if (IsLinkTaskFinished()) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: blockReceivedStatus = GetBlockReceivedStatus(); - for (i = 0; i < gUnknown_203F3E0->unk24; blockReceivedStatus >>= 1, i++) + for (i = 0; i < sGame->unk24; blockReceivedStatus >>= 1, i++) { if (blockReceivedStatus & 1) { ResetBlockReceivedFlag(i); - gUnknown_203F3E0->unk08++; + sGame->unk08++; } } - if (gUnknown_203F3E0->unk08 >= gUnknown_203F3E0->unk24) + if (sGame->unk08 >= sGame->unk24) { - gUnknown_203F3E0->unk14++; - gUnknown_203F3E0->unk10++; + sGame->unk14++; + sGame->unk10++; } break; default: if (WaitFanfare(TRUE)) { - sub_8152090(6); + SetGameFunc(6); FadeOutAndPlayNewMapMusic(MUS_VICTORY_WILD, 4); } break; } } -static void sub_815109C(void) +static void InitResults_Member(void) { u8 i; u8 blockReceivedStatus; - switch (gUnknown_203F3E0->unk10) { + switch (sGame->unk10) { case 0: - SendBlock(0, gUnknown_203F3E0->unk4A[gUnknown_203F3E0->unk14], sizeof(gUnknown_203F3E0->unk4A)); - gUnknown_203F3E0->unk08 = 0; - gUnknown_203F3E0->unk10++; + SendBlock(0, sGame->unk4A[sGame->unk14], sizeof(sGame->unk4A)); + sGame->unk08 = 0; + sGame->unk10++; break; case 1: if (IsLinkTaskFinished()) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: blockReceivedStatus = GetBlockReceivedStatus(); - for (i = 0; i < gUnknown_203F3E0->unk24; blockReceivedStatus >>= 1, i++) + for (i = 0; i < sGame->unk24; blockReceivedStatus >>= 1, i++) { if (blockReceivedStatus & 1) { - memcpy(gUnknown_203F3E0->unk4A, gBlockRecvBuffer, sizeof(gUnknown_203F3E0->unk4A)); + memcpy(sGame->unk4A, gBlockRecvBuffer, sizeof(sGame->unk4A)); ResetBlockReceivedFlag(i); - gUnknown_203F3E0->unk08++; + sGame->unk08++; } } - if (gUnknown_203F3E0->unk08 >= gUnknown_203F3E0->unk24) { - gUnknown_203F3E0->unk14++; - gUnknown_203F3E0->unk10++; + if (sGame->unk08 >= sGame->unk24) { + sGame->unk14++; + sGame->unk10++; } break; default: if (WaitFanfare(TRUE)) { - gUnknown_203F3E0->unk114 = gUnknown_203F3E0->unk4A[gUnknown_203F3E0->multiplayerId][5]; - sub_8152090(6); + sGame->unk114 = sGame->unk4A[sGame->multiplayerId][5]; + SetGameFunc(6); FadeOutAndPlayNewMapMusic(MUS_VICTORY_WILD, 4); } break; } } -static void sub_8151198(void) +static void DoResults(void) { u8 sp00; u8 i; u8 blockReceivedStatus; - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - sub_81531FC(); - sub_81540DC(TRUE); - sub_81544F0(); - sub_81545BC(TRUE); - sub_81549D4(2); - gUnknown_203F3E0->unk10++; + TryUpdateRecords(); + SetStatusBarInvisibility(TRUE); + ResetCloudPos(); + SetCloudInvisibility(TRUE); + SetGfxFuncById(2); + sGame->unk10++; break; case 1: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { sp00 = 1; - sub_81549D4(5); - sp00 = sub_8155E8C(); + SetGfxFuncById(5); + sp00 = GetPlayAgainState(); SendBlock(0, &sp00, sizeof(sp00)); - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: if (IsLinkTaskFinished()) { - gUnknown_203F3E0->unk10++; - gUnknown_203F3E0->unk08 = 0; + sGame->unk10++; + sGame->unk08 = 0; } break; case 3: blockReceivedStatus = GetBlockReceivedStatus(); - for (i = 0; i < gUnknown_203F3E0->unk24; blockReceivedStatus >>= 1, i++) + for (i = 0; i < sGame->unk24; blockReceivedStatus >>= 1, i++) { if (blockReceivedStatus & 1) { - *(gUnknown_203F3E0->unk10C + i) = *(u8 *)gBlockRecvBuffer[i]; + *(sGame->unk10C + i) = *(u8 *)gBlockRecvBuffer[i]; ResetBlockReceivedFlag(i); - gUnknown_203F3E0->unk08++; + sGame->unk08++; } } - if (gUnknown_203F3E0->unk08 >= gUnknown_203F3E0->unk24) { - if (++gUnknown_203F3E0->unk14 >= 120) + if (sGame->unk08 >= sGame->unk24) { + if (++sGame->unk14 >= 120) { - sub_81549D4(6); - gUnknown_203F3E0->unk10++; + SetGfxFuncById(6); + sGame->unk10++; } } break; default: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - sub_8152090(7); + SetGameFunc(7); } break; } } -static void sub_81512B4(void) +static void AskPlayAgain(void) { u8 sp0; u8 i; u8 blockReceivedStatus; - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - if (sub_81534AC() >= 3000) + if (GetHighestScore() >= 3000) { - sub_81549D4(4); + SetGfxFuncById(4); } - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 1: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - sub_81549D4(3); - gUnknown_203F3E0->unk10++; + SetGfxFuncById(3); + sGame->unk10++; } break; case 2: - sub_81546C0(); - sub_8153048(); - gUnknown_203F3E0->unk10++; + ResetBerryAndStatusBarSprites(); + ResetForPlayAgainPrompt(); + sGame->unk10++; break; case 3: - if ((sp0 = sub_8155E8C()) != 0) + if ((sp0 = GetPlayAgainState()) != 0) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 4: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - sub_81549D4(5); - sp0 = sub_8155E8C(); + SetGfxFuncById(5); + sp0 = GetPlayAgainState(); SendBlock(0, &sp0, sizeof(sp0)); - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 5: if (IsLinkTaskFinished()) { - gUnknown_203F3E0->unk10++; - gUnknown_203F3E0->unk08 = 0; + sGame->unk10++; + sGame->unk08 = 0; } break; case 6: blockReceivedStatus = GetBlockReceivedStatus(); - for (i = 0; i < gUnknown_203F3E0->unk24; blockReceivedStatus >>= 1, i++) + for (i = 0; i < sGame->unk24; blockReceivedStatus >>= 1, i++) { if (blockReceivedStatus & 1) { - *(gUnknown_203F3E0->unk10C + i) = *(u8 *)gBlockRecvBuffer[i]; + *(sGame->unk10C + i) = *(u8 *)gBlockRecvBuffer[i]; ResetBlockReceivedFlag(i); - gUnknown_203F3E0->unk08++; + sGame->unk08++; } } - if (gUnknown_203F3E0->unk08 >= gUnknown_203F3E0->unk24) { - if (++gUnknown_203F3E0->unk14 >= 120) + if (sGame->unk08 >= sGame->unk24) { + if (++sGame->unk14 >= 120) { - sub_815336C(); - sub_81549D4(6); - gUnknown_203F3E0->unk10++; + ResetPickState(); + SetGfxFuncById(6); + sGame->unk10++; } } else { - sub_81532B8(); + HandleWaitPlayAgainInput(); } break; default: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - for (i = 0; i < gUnknown_203F3E0->unk24; i++) + for (i = 0; i < sGame->unk24; i++) { - if (gUnknown_203F3E0->unk10C[i] == 2) + if (sGame->unk10C[i] == 2) { - sub_8152090(8); + SetGameFunc(8); return; } } - sub_8152090(10); + SetGameFunc(10); } break; } } -static void sub_8151488(void) +static void EndLink(void) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: SetCloseLinkCallback(); - sub_81549D4(7); - gUnknown_203F3E0->unk10++; + SetGfxFuncById(7); + sGame->unk10++; break; case 1: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: - if (sub_8155E8C() == 5) + if (GetPlayAgainState() == 5) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; default: if (!gReceivedRemoteLinkPlayers) { - sub_8152090(9); + SetGameFunc(9); } break; } } -static void sub_81514F0(void) +static void ExitGame(void) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 1: UpdatePaletteFade(); if (!gPaletteFade.active) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: - sub_8154274(); - sub_8153ED8(); - sub_8153D08(gUnknown_203F3E0->unk24); - sub_8154578(); - gUnknown_3002044 = TRUE; - sub_81549D4(8); - gUnknown_203F3E0->unk10++; + FreeBerrySprites(); + FreeStatusBar(); + FreeDodrioSprites(sGame->unk24); + FreeCloudSprites(); + sExitingGame = TRUE; + SetGfxFuncById(8); + sGame->unk10++; break; default: - if (!sub_8155E68()) + if (!IsGfxFuncActive()) { - SetMainCallback2(gUnknown_203F3E0->savedCallback); - DestroyTask(gUnknown_203F3E0->unk04); - Free(gUnknown_203F3E0); + SetMainCallback2(sGame->savedCallback); + DestroyTask(sGame->unk04); + Free(sGame); FreeAllWindowBuffers(); } break; } } -static void sub_815159C(void) +static void ResetGame(void) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - sub_81549D4(9); + SetGfxFuncById(9); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 1: UpdatePaletteFade(); if (!gPaletteFade.active) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 2: @@ -890,79 +1202,79 @@ static void sub_815159C(void) ChangeBgY(2, 0, 0); ChangeBgX(3, 0, 0); ChangeBgY(3, 0, 0); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 3: StopMapMusic(); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 4: PlayNewMapMusic(MUS_BERRY_PICK); - sub_8154540(); - gUnknown_203F3E0->unk10++; + StartCloudMovement(); + sGame->unk10++; break; case 5: BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); - gUnknown_203F3E0->unk10++; + sGame->unk10++; break; case 6: UpdatePaletteFade(); if (!gPaletteFade.active) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; default: - DestroyTask(gUnknown_203F3E0->unk04); - sub_815206C(sub_81516DC); - sub_8154730(); - sub_81508EC(gUnknown_203F3E0); + DestroyTask(sGame->unk04); + CreateDodrioGameTask(Task_NewGameIntro); + ResetGfxState(); + InitDodrioGame(sGame); if (!gReceivedRemoteLinkPlayers) { - gUnknown_203F3E0->unk24 = 1; + sGame->unk24 = 1; } - sub_8153150(); - sub_81545BC(FALSE); + SetRandomPrize(); + SetCloudInvisibility(FALSE); break; } } -static void sub_81516DC(u8 taskId) +static void Task_NewGameIntro(u8 taskId) { - switch (gUnknown_203F3E0->unk10) + switch (sGame->unk10) { case 0: - if (sub_81520B4() == 1) + if (SlideTreeBordersOut() == 1) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; case 1: - sub_8153DD8(); - gUnknown_203F3E0->unk10++; + InitStatusBarPos(); + sGame->unk10++; break; case 2: - if (sub_8153F1C() == TRUE) + if (DoStatusBarIntro() == TRUE) { - gUnknown_203F3E0->unk10++; + sGame->unk10++; } break; default: - if (gUnknown_203F3E0->unk20 != 0) + if (sGame->unk20 != 0) { - sub_815206C(sub_8150C08); + CreateDodrioGameTask(Task_DodrioGame_Leader); } else { - sub_815206C(sub_8150C40); + CreateDodrioGameTask(Task_DodrioGame_Member); } DestroyTask(taskId); break; } } -static void sub_8151750(u8 taskId) +static void Task_CommunicateMonInfo(u8 taskId) { s16 * data = gTasks[taskId].data; u8 i; @@ -971,8 +1283,8 @@ static void sub_8151750(u8 taskId) switch (data[0]) { case 0: - SendBlock(0, &gUnknown_203F3E0->unk318C[gUnknown_203F3E0->multiplayerId].isShiny, sizeof(gUnknown_203F3E0->unk318C[gUnknown_203F3E0->multiplayerId].isShiny)); - gUnknown_203F3E0->unk08 = 0; + SendBlock(0, &sGame->unk318C[sGame->multiplayerId].isShiny, sizeof(sGame->unk318C[sGame->multiplayerId].isShiny)); + sGame->unk08 = 0; data[0]++; break; case 1: @@ -983,185 +1295,185 @@ static void sub_8151750(u8 taskId) break; case 2: blockReceivedStatus = GetBlockReceivedStatus(); - for (i = 0; i < gUnknown_203F3E0->unk24; blockReceivedStatus >>= 1, i++) + for (i = 0; i < sGame->unk24; blockReceivedStatus >>= 1, i++) { if (blockReceivedStatus & 1) { - *(u8 *)&gUnknown_203F3E0->unk318C[i] = *(u8 *)gBlockRecvBuffer[i]; + *(u8 *)&sGame->unk318C[i] = *(u8 *)gBlockRecvBuffer[i]; ResetBlockReceivedFlag(i); - gUnknown_203F3E0->unk08++; + sGame->unk08++; } } - if (gUnknown_203F3E0->unk08 >= gUnknown_203F3E0->unk24) + if (sGame->unk08 >= sGame->unk24) { DestroyTask(taskId); - sub_81549D4(6); - gUnknown_203F3E0->unk10++; + SetGfxFuncById(6); + sGame->unk10++; } break; } } -static void sub_815184C(void) +static void RecvLinkData_Gameplay(void) { u8 i; - u8 r7 = gUnknown_203F3E0->unk24; + u8 r7 = sGame->unk24; - gUnknown_203F3E0->unk31A0[0].unk10 = sub_815A950(0, &gUnknown_203F3E0->unk31A0[0], &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, &gUnknown_203F3E0->unk40, &gUnknown_203F3E0->unk120, &gUnknown_203F3E0->unk12C); - gUnknown_203F3E0->unk128 = 1; + sGame->unk31A0[0].unk10 = sub_815A950(0, &sGame->unk31A0[0], &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, &sGame->unk40, &sGame->unk120, &sGame->unk12C); + sGame->unk128 = 1; for (i = 1; i < r7; i++) { - if ( gUnknown_203F3E0->unkA8[i] == 0 - && sub_815AB04(i, &gUnknown_203F3E0->unk31A0[i].unk2C.unk0) == 0) + if ( sGame->unkA8[i] == 0 + && sub_815AB04(i, &sGame->unk31A0[i].unk2C.unk0) == 0) { - gUnknown_203F3E0->unk31A0[i].unk2C.unk0 = 0; - gUnknown_203F3E0->unk128 = 0; + sGame->unk31A0[i].unk2C.unk0 = 0; + sGame->unk128 = 0; } } - if (++gUnknown_203F3E0->unk124 >= 60) + if (++sGame->unk124 >= 60) { - if (gUnknown_203F3E0->unk128 != 0) + if (sGame->unk128 != 0) { ClearRecvCommands(); - gUnknown_203F3E0->unk124 = 0; + sGame->unk124 = 0; } - else if (gUnknown_203F3E0->unk124 > 70) + else if (sGame->unk124 > 70) { ClearRecvCommands(); - gUnknown_203F3E0->unk124 = 0; + sGame->unk124 = 0; } } for (i = 0; i < r7; i++) { - if ( gUnknown_203F3E0->unk31A0[i].unk2C.unk0 != 0 - && gUnknown_203F3E0->unkA8[i] == 0) + if ( sGame->unk31A0[i].unk2C.unk0 != 0 + && sGame->unkA8[i] == 0) { - gUnknown_203F3E0->unkA8[i] = 1; + sGame->unkA8[i] = 1; } - switch (gUnknown_203F3E0->unkA8[i]) + switch (sGame->unkA8[i]) { case 0: default: break; case 1 ... 3: - if (++gUnknown_203F3E0->unkB0[i] >= 6) + if (++sGame->unkB0[i] >= 6) { - gUnknown_203F3E0->unkB0[i] = 0; - gUnknown_203F3E0->unkA8[i] = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk0 = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk4 = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk8 = 0; + sGame->unkB0[i] = 0; + sGame->unkA8[i] = 0; + sGame->unk31A0[i].unk2C.unk0 = 0; + sGame->unk31A0[i].unk2C.unk4 = 0; + sGame->unk31A0[i].unk2C.unk8 = 0; } break; case 4: - if (++gUnknown_203F3E0->unkB0[i] >= 40) + if (++sGame->unkB0[i] >= 40) { - gUnknown_203F3E0->unkB0[i] = 0; - gUnknown_203F3E0->unkA8[i] = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk0 = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk4 = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk8 = 0; + sGame->unkB0[i] = 0; + sGame->unkA8[i] = 0; + sGame->unk31A0[i].unk2C.unk0 = 0; + sGame->unk31A0[i].unk2C.unk4 = 0; + sGame->unk31A0[i].unk2C.unk8 = 0; } break; } } } -static void sub_8151A5C(void) +static void RecvLinkData_ReadyToEnd(void) { u8 i; - u8 r6 = gUnknown_203F3E0->unk24; + u8 r6 = sGame->unk24; - gUnknown_203F3E0->unk31A0[0].unk10 = sub_815A950(0, &gUnknown_203F3E0->unk31A0[0], &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, &gUnknown_203F3E0->unk40, &gUnknown_203F3E0->unk120, &gUnknown_203F3E0->unk12C); - gUnknown_203F3E0->unk128 = 1; + sGame->unk31A0[0].unk10 = sub_815A950(0, &sGame->unk31A0[0], &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, &sGame->unk40, &sGame->unk120, &sGame->unk12C); + sGame->unk128 = 1; for (i = 1; i < r6; i++) { if (sub_815AB60(i) != 0) { - gUnknown_203F3E0->unk130[i] = 1; - gUnknown_203F3E0->unk128 = 0; + sGame->unk130[i] = 1; + sGame->unk128 = 0; } } - if (++gUnknown_203F3E0->unk124 >= 60) + if (++sGame->unk124 >= 60) { - if (gUnknown_203F3E0->unk128 != 0) + if (sGame->unk128 != 0) { ClearRecvCommands(); - gUnknown_203F3E0->unk124 = 0; + sGame->unk124 = 0; } - else if (gUnknown_203F3E0->unk124 > 70) + else if (sGame->unk124 > 70) { ClearRecvCommands(); - gUnknown_203F3E0->unk124 = 0; + sGame->unk124 = 0; } } } -static void sub_8151B54(void) +static void RecvLinkData_Leader(void) { - switch (gUnknown_203F3E0->unk18) + switch (sGame->unk18) { case 3: - if (sub_8152A00() == TRUE) + if (AllPlayersReadyToStart() == TRUE) { - sub_8152A70(); - gUnknown_203F3E0->unk11C = 1; + ResetReadyToStart(); + sGame->unk11C = 1; } break; case 4: - sub_815184C(); + RecvLinkData_Gameplay(); break; case 11: - sub_8151A5C(); + RecvLinkData_ReadyToEnd(); break; } } -static void sub_8151BA0(void) +static void SendLinkData_Leader(void) { - switch (gUnknown_203F3E0->unk18) + switch (sGame->unk18) { case 4: - sub_815A61C(&gUnknown_203F3E0->unk32CC, &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, gUnknown_203F3E0->unk40, gUnknown_203F3E0->unk120, gUnknown_203F3E0->unk12C); + sub_815A61C(&sGame->unk32CC, &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, sGame->unk40, sGame->unk120, sGame->unk12C); break; case 11: - sub_815A61C(&gUnknown_203F3E0->unk32CC, &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, gUnknown_203F3E0->unk40, gUnknown_203F3E0->unk120, gUnknown_203F3E0->unk12C); + sub_815A61C(&sGame->unk32CC, &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, sGame->unk40, sGame->unk120, sGame->unk12C); break; } } -static void sub_8151C5C(void) +static void RecvLinkData_Member(void) { - switch (gUnknown_203F3E0->unk18) + switch (sGame->unk18) { case 4: - sub_815A950(gUnknown_203F3E0->multiplayerId, &gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId], &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, &gUnknown_203F3E0->unk40, &gUnknown_203F3E0->unk120, &gUnknown_203F3E0->unk12C); + sub_815A950(sGame->multiplayerId, &sGame->unk31A0[sGame->multiplayerId], &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, &sGame->unk40, &sGame->unk120, &sGame->unk12C); break; case 11: - sub_815A950(gUnknown_203F3E0->multiplayerId, &gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId], &gUnknown_203F3E0->unk31A0[0].unk2C, &gUnknown_203F3E0->unk31A0[1].unk2C, &gUnknown_203F3E0->unk31A0[2].unk2C, &gUnknown_203F3E0->unk31A0[3].unk2C, &gUnknown_203F3E0->unk31A0[4].unk2C, &gUnknown_203F3E0->unk40, &gUnknown_203F3E0->unk120, &gUnknown_203F3E0->unk12C); + sub_815A950(sGame->multiplayerId, &sGame->unk31A0[sGame->multiplayerId], &sGame->unk31A0[0].unk2C, &sGame->unk31A0[1].unk2C, &sGame->unk31A0[2].unk2C, &sGame->unk31A0[3].unk2C, &sGame->unk31A0[4].unk2C, &sGame->unk40, &sGame->unk120, &sGame->unk12C); break; } } -static void sub_8151D28(void) +static void SendLinkData_Member(void) { - switch (gUnknown_203F3E0->unk18) + switch (sGame->unk18) { case 3: sub_815A5BC(1); - gUnknown_203F3E0->unk11C = 1; + sGame->unk11C = 1; break; case 4: - if (gUnknown_203F3E0->unk32CC.unk2C.unk0 != 0) + if (sGame->unk32CC.unk2C.unk0 != 0) { - sub_815AAD8(gUnknown_203F3E0->unk32CC.unk2C.unk0); + sub_815AAD8(sGame->unk32CC.unk2C.unk0); } break; case 11: - if (gUnknown_203F3E0->unk120 == 0 && gUnknown_203F3E0->unk12C == 0) + if (sGame->unk120 == 0 && sGame->unk12C == 0) { sub_815AB3C(1); } @@ -1169,105 +1481,105 @@ static void sub_8151D28(void) } } -static void sub_8151D98(void) +static void HandleSound_Leader(void) { - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 == 0) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 == 0) { if (!IsSEPlaying()) { - gUnknown_203F3E0->unk144 = 0; + sGame->unk144 = 0; } } - else if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk4 == 1) + else if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk4 == 1) { - if (gUnknown_203F3E0->unk144 == 0) + if (sGame->unk144 == 0) { m4aSongNumStop(SE_SUCCESS); PlaySE(SE_SUCCESS); - gUnknown_203F3E0->unk144 = 1; + sGame->unk144 = 1; } } - else if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk8 == 1) + else if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk8 == 1) { - if (gUnknown_203F3E0->unk144 == 0 && !IsSEPlaying()) + if (sGame->unk144 == 0 && !IsSEPlaying()) { PlaySE(SE_BOO); - sub_8153BC0(1); - gUnknown_203F3E0->unk144 = 1; + StartDodrioMissedAnim(1); + sGame->unk144 = 1; } } - if (gUnknown_203F3E0->unk154 == 0 && gUnknown_203F3E0->unk40 >= 10) + if (sGame->unk154 == 0 && sGame->unk40 >= 10) { StopMapMusic(); - gUnknown_203F3E0->unk154 = 1; + sGame->unk154 = 1; } - else if (gUnknown_203F3E0->unk154 == 1) + else if (sGame->unk154 == 1) { PlayFanfareByFanfareNum(FANFARE_TOO_BAD); - gUnknown_203F3E0->unk154 = 2; + sGame->unk154 = 2; } } -static void sub_8151E94(void) +static void HandleSound_Member(void) { - u8 r8 = gUnknown_203F3E0->unk44; - u8 r7 = gUnknown_203F3E0->unk48; + u8 r8 = sGame->unk44; + u8 r7 = sGame->unk48; u8 r4; - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 == 0) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 == 0) { - if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk4 != 1 && gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk8 != 1) + if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk4 != 1 && sGame->unk31A0[sGame->multiplayerId].unk2C.unk8 != 1) { - gUnknown_203F3E0->unk144 = 0; + sGame->unk144 = 0; } } - else if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk4 == 1) + else if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk4 == 1) { - if (gUnknown_203F3E0->unk144 == 0) + if (sGame->unk144 == 0) { m4aSongNumStop(SE_SUCCESS); PlaySE(SE_SUCCESS); - gUnknown_203F3E0->unk144 = 1; + sGame->unk144 = 1; } } - else if (gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk8 == 1) + else if (sGame->unk31A0[sGame->multiplayerId].unk2C.unk8 == 1) { - if (gUnknown_203F3E0->unk144 == 0 && !IsSEPlaying()) + if (sGame->unk144 == 0 && !IsSEPlaying()) { PlaySE(SE_BOO); - sub_8153BC0(1); - gUnknown_203F3E0->unk144 = 1; + StartDodrioMissedAnim(1); + sGame->unk144 = 1; } } for (r4 = r8; r4 < r7; r4++) { - struct DodrioSubstruct_31A0_14 * ptr = &gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk14; + struct DodrioSubstruct_31A0_14 * ptr = &sGame->unk31A0[sGame->multiplayerId].unk14; if (ptr->unkB[r4] >= 10) { - if (gUnknown_203F3E0->unk148[r4] == 0) + if (sGame->unk148[r4] == 0) { PlaySE(SE_BALLOON_RED + ptr->unk0[r4]); - gUnknown_203F3E0->unk148[r4] = 1; + sGame->unk148[r4] = 1; } } else { - gUnknown_203F3E0->unk148[r4] = 0; + sGame->unk148[r4] = 0; } } - if (gUnknown_203F3E0->unk154 == 0 && gUnknown_203F3E0->unk40 >= 10) + if (sGame->unk154 == 0 && sGame->unk40 >= 10) { StopMapMusic(); - gUnknown_203F3E0->unk154 = 1; + sGame->unk154 = 1; } - else if (gUnknown_203F3E0->unk154 == 1) + else if (sGame->unk154 == 1) { PlayFanfareByFanfareNum(FANFARE_TOO_BAD); - gUnknown_203F3E0->unk154 = 2; + sGame->unk154 = 2; } } -static void sub_815201C(void) +static void CB2_DodrioGame(void) { RunTasks(); AnimateSprites(); @@ -1275,46 +1587,46 @@ static void sub_815201C(void) UpdatePaletteFade(); } -static void sub_8152034(void) +static void VBlankCB_DodrioGame(void) { TransferPlttBuffer(); LoadOam(); ProcessSpriteCopyRequests(); } -static void sub_8152048(struct DodrioSubstruct_318C * a0, struct Pokemon * a1) +static void InitMonInfo(struct DodrioSubstruct_318C * a0, struct Pokemon * a1) { a0->isShiny = IsMonShiny(a1); } -static void sub_815205C(TaskFunc func, u8 priority) +static void CreateTask_(TaskFunc func, u8 priority) { CreateTask(func, priority); } -static void sub_815206C(TaskFunc func) +static void CreateDodrioGameTask(TaskFunc func) { - gUnknown_203F3E0->unk04 = CreateTask(func, 1); - gUnknown_203F3E0->unk10 = 0; - gUnknown_203F3E0->unk0C = 0; - gUnknown_203F3E0->unk14 = 0; + sGame->unk04 = CreateTask(func, 1); + sGame->unk10 = 0; + sGame->unk0C = 0; + sGame->unk14 = 0; } -static void sub_8152090(u8 a0) +static void SetGameFunc(u8 a0) { - gUnknown_203F3E0->unk1C = gUnknown_203F3E0->unk18; - gUnknown_203F3E0->unk18 = a0; - gUnknown_203F3E0->unk10 = 0; - gUnknown_203F3E0->unk14 = 0; + sGame->unk1C = sGame->unk18; + sGame->unk18 = a0; + sGame->unk10 = 0; + sGame->unk14 = 0; } -static bool32 sub_81520B4(void) +static bool32 SlideTreeBordersOut(void) { - u8 r2 = gUnknown_203F3E0->unk14 / 4; - gUnknown_203F3E0->unk14++; - if (r2 != 0 && gUnknown_203F3E0->unk14 % 4 == 0) + u8 r2 = sGame->unk14 / 4; + sGame->unk14++; + if (r2 != 0 && sGame->unk14 % 4 == 0) { - if (r2 < sUnknown_8475548[gUnknown_203F3E0->unk24 - 1]) + if (r2 < sTreeBorderXPos[sGame->unk24 - 1]) { SetGpuReg(REG_OFFSET_BG1HOFS, (r2 * 8)); SetGpuReg(REG_OFFSET_BG2HOFS, -(r2 * 8)); @@ -1331,55 +1643,55 @@ static bool32 sub_81520B4(void) } } -static void sub_8152110(void) +static void InitFirstWaveOfBerries(void) { u8 i; - u8 start = gUnknown_203F3E0->unk44; - u8 finish = gUnknown_203F3E0->unk48; + u8 start = sGame->unk44; + u8 finish = sGame->unk48; for (i = start; i < finish; i++) { - struct DodrioSubstruct_31A0_14 * ptr = &gUnknown_203F3E0->unk32CC.unk14; + struct DodrioSubstruct_31A0_14 * ptr = &sGame->unk32CC.unk14; ptr->unkB[i] = (i % 2 == 0) ? 1 : 0; ptr->unk0[i] = 0; } } -static void sub_8152174(void) +static void HandlePickBerries(void) { - u8 sp0 = gUnknown_203F3E0->unk44; - u8 sp4 = gUnknown_203F3E0->unk48; - u8 sp8 = gUnknown_203F3E0->unk24; + u8 sp0 = sGame->unk44; + u8 sp4 = sGame->unk48; + u8 sp8 = sGame->unk24; u8 i, j, k, r5; - if (gUnknown_203F3E0->unk40 >= 10) + if (sGame->unk40 >= 10) return; for (i = 0; i < sp8; i++) { - u8 *ptr = &gUnknown_203F3E0->unk31A0[i].unk2C.unk0; - if (*ptr != 0 && gUnknown_203F3E0->unkA8[i] == 1) + u8 *ptr = &sGame->unk31A0[i].unk2C.unk0; + if (*ptr != 0 && sGame->unkA8[i] == 1) { for (j = sp0; j < sp4; j++) { - r5 = sUnknown_8471F50[0][0][j]; - if (gUnknown_203F3E0->unkF4[r5][0] == i || gUnknown_203F3E0->unkF4[r5][1] == i) + r5 = sActiveColumnMap[0][0][j]; + if (sGame->unkF4[r5][0] == i || sGame->unkF4[r5][1] == i) break; - if (sub_8152484(i, *ptr, r5) == TRUE) + if (TryPickBerry(i, *ptr, r5) == TRUE) { for (k = 0; k < 2; k++) { - if (gUnknown_203F3E0->unkF4[r5][k] == 0xFF) + if (sGame->unkF4[r5][k] == 0xFF) { - gUnknown_203F3E0->unkF4[r5][k] = i; - gUnknown_203F3E0->unkA8[i] = 2; - gUnknown_203F3E0->unkC4[r5] = 1; + sGame->unkF4[r5][k] = i; + sGame->unkA8[i] = 2; + sGame->unkC4[r5] = 1; break; } } break; } - if (gUnknown_203F3E0->unk31A0[i].unk2C.unk8 == 1) + if (sGame->unk31A0[i].unk2C.unk8 == 1) break; } } @@ -1388,33 +1700,33 @@ static void sub_8152174(void) for (j = sp0; j < sp4; j++) { u8 id = 0xFF; - r5 = sUnknown_8471F50[0][0][j]; - if (gUnknown_203F3E0->unkC4[r5] == 1) + r5 = sActiveColumnMap[0][0][j]; + if (sGame->unkC4[r5] == 1) { s32 r2; - u8 r4, r3 = gUnknown_203F3E0->unk90[sub_8152BD4(r5)] / 7; - if (r3 >= NELEMS(sUnknown_847553C) - 1) - r3 = NELEMS(sUnknown_847553C) - 1; + u8 r4, r3 = sGame->unk90[GetPlayerIdAtColumn(r5)] / 7; + if (r3 >= NELEMS(sBerryFallDelays) - 1) + r3 = NELEMS(sBerryFallDelays) - 1; - r2 = sUnknown_847553C[r3][gUnknown_203F3E0->unk31A0[0].unk14.unk0[r5]] - gUnknown_203F3E0->unkD0[r5]; + r2 = sBerryFallDelays[r3][sGame->unk31A0[0].unk14.unk0[r5]] - sGame->unkD0[r5]; if (r2 < 6) - gUnknown_203F3E0->unk9C[r5] += r2; + sGame->unk9C[r5] += r2; - if (++gUnknown_203F3E0->unk9C[r5] >= 6) + if (++sGame->unk9C[r5] >= 6) { - gUnknown_203F3E0->unk9C[r5] = 0; - if (gUnknown_203F3E0->unkF4[r5][0] == 0xFF && gUnknown_203F3E0->unkF4[r5][1] == 0xFF) + sGame->unk9C[r5] = 0; + if (sGame->unkF4[r5][0] == 0xFF && sGame->unkF4[r5][1] == 0xFF) { continue; } - else if (gUnknown_203F3E0->unkF4[r5][0] != 0xFF && gUnknown_203F3E0->unkF4[r5][1] == 0xFF) + else if (sGame->unkF4[r5][0] != 0xFF && sGame->unkF4[r5][1] == 0xFF) { - r4 = gUnknown_203F3E0->unkF4[r5][0]; + r4 = sGame->unkF4[r5][0]; } else { - u8 unk0 = gUnknown_203F3E0->unkF4[r5][0]; - i = gUnknown_203F3E0->unkF4[r5][1]; // Have to re-use the variable to match. + u8 unk0 = sGame->unkF4[r5][0]; + i = sGame->unkF4[r5][1]; // Have to re-use the variable to match. if (!(Random() & 1)) { r4 = unk0; @@ -1426,30 +1738,30 @@ static void sub_8152174(void) id = unk0; } } - gUnknown_203F3E0->unk32CC.unk14.unkB[r5] = 7; - gUnknown_203F3E0->unkC4[r5] = 2; - gUnknown_203F3E0->unkA8[r4] = 3; - gUnknown_203F3E0->unkB8[r5] = r4; - gUnknown_203F3E0->unk31A0[r4].unk2C.unk4 = 1; - gUnknown_203F3E0->unk31A0[id].unk2C.unk8 = 1; - gUnknown_203F3E0->unk86[r4]++; - sub_8152D34(0, r5, r4); - sub_8152F94(TRUE); - sub_8152B64(r4); - gUnknown_203F3E0->unkE8[r5] = gUnknown_203F3E0->unk32CC.unk14.unk0[r5]; - gUnknown_203F3E0->unk32CC.unk14.unk0[r5] = 3; - gUnknown_203F3E0->unkF4[r5][0] = 0xFF; - gUnknown_203F3E0->unkF4[r5][1] = 0xFF; + sGame->unk32CC.unk14.unkB[r5] = 7; + sGame->unkC4[r5] = 2; + sGame->unkA8[r4] = 3; + sGame->unkB8[r5] = r4; + sGame->unk31A0[r4].unk2C.unk4 = 1; + sGame->unk31A0[id].unk2C.unk8 = 1; + sGame->unk86[r4]++; + IncrementBerryResult(0, r5, r4); + UpdateBerriesPickedInRow(TRUE); + TryIncrementDifficulty(r4); + sGame->unkE8[r5] = sGame->unk32CC.unk14.unk0[r5]; + sGame->unk32CC.unk14.unk0[r5] = 3; + sGame->unkF4[r5][0] = 0xFF; + sGame->unkF4[r5][1] = 0xFF; } } } } -static bool32 sub_8152484(u8 a0, u8 a1, u8 a2) +static bool32 TryPickBerry(u8 a0, u8 a1, u8 a2) { s32 r7 = 0; - u8 r5 = gUnknown_203F3E0->unk24 - 1; - struct DodrioSubstruct_31A0_14 * ptr = &gUnknown_203F3E0->unk32CC.unk14; + u8 r5 = sGame->unk24 - 1; + struct DodrioSubstruct_31A0_14 * ptr = &sGame->unk32CC.unk14; switch (a1) { @@ -1466,11 +1778,11 @@ static bool32 sub_8152484(u8 a0, u8 a1, u8 a2) } if (ptr->unkB[a2] == 6 || ptr->unkB[a2] == 7) { - if (a2 == sUnknown_8472063[r5][a0][r7]) + if (a2 == sDodrioHeadToColumnMap[r5][a0][r7]) { - if (gUnknown_203F3E0->unkC4[a2] == 1 || gUnknown_203F3E0->unkC4[a2] == 2) + if (sGame->unkC4[a2] == 1 || sGame->unkC4[a2] == 2) { - gUnknown_203F3E0->unk31A0[a0].unk2C.unk8 = 1; + sGame->unk31A0[a0].unk2C.unk8 = 1; return FALSE; } else @@ -1481,182 +1793,182 @@ static bool32 sub_8152484(u8 a0, u8 a1, u8 a2) } else { - if (a2 == sUnknown_8472063[r5][a0][r7]) + if (a2 == sDodrioHeadToColumnMap[r5][a0][r7]) { - gUnknown_203F3E0->unkA8[a0] = 4; - gUnknown_203F3E0->unk31A0[a0].unk2C.unk8 = 1; + sGame->unkA8[a0] = 4; + sGame->unk31A0[a0].unk2C.unk8 = 1; } } return FALSE; } -static void sub_815256C(void) +static void UpdateFallingBerries(void) { - u8 r1 = gUnknown_203F3E0->unk44; - u8 r9 = gUnknown_203F3E0->unk48; + u8 r1 = sGame->unk44; + u8 r9 = sGame->unk48; u8 r3 = 0; u8 r10 = 0; u8 i; u8 r2; struct DodrioStruct * ptr; - gUnknown_203F3E0->unk120 = 0; + sGame->unk120 = 0; for (i = r1; i < r9 - 1; i++) { - ptr = gUnknown_203F3E0; + ptr = sGame; - if (gUnknown_203F3E0->unkC4[i] == 0 || gUnknown_203F3E0->unkC4[i] == 1) + if (sGame->unkC4[i] == 0 || sGame->unkC4[i] == 1) { - gUnknown_203F3E0->unk120 = 1; + sGame->unk120 = 1; if (ptr->unk32CC.unk14.unkB[i] >= 10) { ptr->unk32CC.unk14.unkB[i] = 10; - gUnknown_203F3E0->unkC4[i] = 3; - if (gUnknown_203F3E0->unk148[i] == 0) + sGame->unkC4[i] = 3; + if (sGame->unk148[i] == 0) { - gUnknown_203F3E0->unk148[i] = 1; + sGame->unk148[i] = 1; PlaySE(SE_BALLOON_RED + ptr->unk32CC.unk14.unk0[i]); } - if (gUnknown_203F3E0->unk40 < 10 || r10 == 1) + if (sGame->unk40 < 10 || r10 == 1) { r10 = 1; - gUnknown_203F3E0->unk148[i] = 0; - if (gUnknown_203F3E0->unk40 < 10) + sGame->unk148[i] = 0; + if (sGame->unk40 < 10) { - gUnknown_203F3E0->unk40++; + sGame->unk40++; } - sub_8152D34(3, i, 0); - sub_8152F94(FALSE); + IncrementBerryResult(3, i, 0); + UpdateBerriesPickedInRow(FALSE); } } else { - r3 = gUnknown_203F3E0->unk90[sub_8152BD4(i)] / 7; - if (r3 >= NELEMS(sUnknown_847553C) - 1) + r3 = sGame->unk90[GetPlayerIdAtColumn(i)] / 7; + if (r3 >= NELEMS(sBerryFallDelays) - 1) { - r3 = NELEMS(sUnknown_847553C) - 1; + r3 = NELEMS(sBerryFallDelays) - 1; } - r2 = sUnknown_847553C[r3][ptr->unk32CC.unk14.unk0[i]]; - if (++gUnknown_203F3E0->unkD0[i] >= r2) + r2 = sBerryFallDelays[r3][ptr->unk32CC.unk14.unk0[i]]; + if (++sGame->unkD0[i] >= r2) { ptr->unk32CC.unk14.unkB[i]++; - gUnknown_203F3E0->unkD0[i] = 0; + sGame->unkD0[i] = 0; } - sub_8152174(); + HandlePickBerries(); } } - else if (gUnknown_203F3E0->unkC4[i] == 2) + else if (sGame->unkC4[i] == 2) { - // gUnknown_203F3E0->unk120 = 1; - if (++gUnknown_203F3E0->unkDC[i] >= 20) + // sGame->unk120 = 1; + if (++sGame->unkDC[i] >= 20) { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->unkB8[i]].unk2C.unk4 = 0; - gUnknown_203F3E0->unkDC[i] = 0; - gUnknown_203F3E0->unkD0[i] = 0; - gUnknown_203F3E0->unkC4[i] = 0; + sGame->unk31A0[sGame->unkB8[i]].unk2C.unk4 = 0; + sGame->unkDC[i] = 0; + sGame->unkD0[i] = 0; + sGame->unkC4[i] = 0; ptr->unk32CC.unk14.unkB[i] = 1; - ptr->unk32CC.unk14.unk0[i] = sub_8152BF8(sub_8152BD4(i), i); + ptr->unk32CC.unk14.unk0[i] = GetNewBerryId(GetPlayerIdAtColumn(i), i); } } - else if (gUnknown_203F3E0->unkC4[i] == 3) + else if (sGame->unkC4[i] == 3) { - if (++gUnknown_203F3E0->unkDC[i] >= 20) + if (++sGame->unkDC[i] >= 20) { - if (gUnknown_203F3E0->unk40 < 10) + if (sGame->unk40 < 10) { - gUnknown_203F3E0->unkDC[i] = 0; - gUnknown_203F3E0->unkD0[i] = 0; - gUnknown_203F3E0->unkC4[i] = 0; + sGame->unkDC[i] = 0; + sGame->unkD0[i] = 0; + sGame->unkC4[i] = 0; ptr->unk32CC.unk14.unkB[i] = 1; - gUnknown_203F3E0->unkE8[i] = ptr->unk32CC.unk14.unk0[i]; - ptr->unk32CC.unk14.unk0[i] = sub_8152BF8(sub_8152BD4(i), i); + sGame->unkE8[i] = ptr->unk32CC.unk14.unk0[i]; + ptr->unk32CC.unk14.unk0[i] = GetNewBerryId(GetPlayerIdAtColumn(i), i); } } } } } -static void sub_81527D0(void) +static void UpdateBerrySprites(void) { u8 i, first, count; - first = gUnknown_203F3E0->unk44; - count = gUnknown_203F3E0->unk48; + first = sGame->unk44; + count = sGame->unk48; for (i = first; i < count; i++) { - struct DodrioSubstruct_31A0 * ptr = &gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId]; - u8 var = sUnknown_8471F50[gUnknown_203F3E0->unk24 - 1][gUnknown_203F3E0->multiplayerId][i]; + struct DodrioSubstruct_31A0 * ptr = &sGame->unk31A0[sGame->multiplayerId]; + u8 var = sActiveColumnMap[sGame->unk24 - 1][sGame->multiplayerId][i]; if (ptr->unk14.unkB[var] != 0) - sub_81542EC(i, FALSE); + SetBerryInvisibility(i, FALSE); else - sub_81542EC(i, TRUE); + SetBerryInvisibility(i, TRUE); if (ptr->unk14.unkB[var] > 9) { - sub_8154398(i, ptr->unk14.unk0[var] + 3); - sub_8154370(i, ptr->unk14.unkB[var] * 2 - 1); + SetBerryAnim(i, ptr->unk14.unk0[var] + 3); + SetBerryYPos(i, ptr->unk14.unkB[var] * 2 - 1); } else if (ptr->unk14.unk0[var] == 3) { ptr->unk14.unkB[var] = 7; - sub_8154398(i, 6); - sub_8154370(i, ptr->unk14.unkB[var] * 2 - 1); + SetBerryAnim(i, 6); + SetBerryYPos(i, ptr->unk14.unkB[var] * 2 - 1); } else { - sub_8154398(i, ptr->unk14.unk0[var]); - sub_8154370(i, ptr->unk14.unkB[var] * 2); + SetBerryAnim(i, ptr->unk14.unk0[var]); + SetBerryYPos(i, ptr->unk14.unkB[var] * 2); } } } -static void sub_81528D0(void) +static void UpdateAllDodrioAnims(void) { u8 i, count; - count = gUnknown_203F3E0->unk24; + count = sGame->unk24; for (i = 0; i < count; i++) { - struct DodrioSubstruct_31A0 * ptr = &gUnknown_203F3E0->unk31A0[i]; - sub_8153DA8(i, ptr->unk2C.unk0); + struct DodrioSubstruct_31A0 * ptr = &sGame->unk31A0[i]; + SetDodrioAnim(i, ptr->unk2C.unk0); } } -static void sub_8152910(void) +static void SetAllDodrioDisabled(void) { u8 i, count; - count = gUnknown_203F3E0->unk24; + count = sGame->unk24; for (i = 0; i < count; i++) - sub_8153DA8(i, 4); + SetDodrioAnim(i, 4); } -static void sub_815293C(void) +static void UpdateGame_Leader(void) { - sub_81527D0(); - if (gUnknown_203F3E0->unk40 > 9) - sub_8152910(); + UpdateBerrySprites(); + if (sGame->unk40 > 9) + SetAllDodrioDisabled(); else - sub_81528D0(); + UpdateAllDodrioAnims(); - sub_8153FC8(gUnknown_203F3E0->unk40); + UpdateStatusBarAnim(sGame->unk40); } -// This function is literally the same as the one above...Why? -static void sub_8152970(void) +// Identical to UpdateGame_Leader +static void UpdateGame_Member(void) { - sub_81527D0(); - if (gUnknown_203F3E0->unk40 > 9) - sub_8152910(); + UpdateBerrySprites(); + if (sGame->unk40 > 9) + SetAllDodrioDisabled(); else - sub_81528D0(); + UpdateAllDodrioAnims(); - sub_8153FC8(gUnknown_203F3E0->unk40); + UpdateStatusBarAnim(sGame->unk40); } -static void sub_81529A4(u8 arg0, u8 *arg1, u8 *arg2) +static void GetActiveBerryColumns(u8 arg0, u8 *arg1, u8 *arg2) { switch (arg0) { @@ -1678,15 +1990,15 @@ static void sub_81529A4(u8 arg0, u8 *arg1, u8 *arg2) } } -static bool32 sub_8152A00(void) +static bool32 AllPlayersReadyToStart(void) { u8 i, count; - count = gUnknown_203F3E0->unk24; + count = sGame->unk24; for (i = 1; i < count; i++) { - if (gUnknown_203F3E0->unk158[i] == 0) - gUnknown_203F3E0->unk158[i] = sub_815A5E8(i); + if (sGame->unk158[i] == 0) + sGame->unk158[i] = sub_815A5E8(i); } // This loop won't ever run, the seemingly pointless assingment below is to make the compiler @@ -1694,48 +2006,48 @@ static bool32 sub_8152A00(void) count = count; for (; i < count; i++) { - if (gUnknown_203F3E0->unk158[i] == 0) + if (sGame->unk158[i] == 0) return FALSE; } return TRUE; } -static void sub_8152A70(void) +static void ResetReadyToStart(void) { u8 i; for (i = 0; i < 5; i++) - gUnknown_203F3E0->unk158[i] = 0; + sGame->unk158[i] = 0; } -static bool32 sub_8152A98(void) +static bool32 ReadyToEndGame_Leader(void) { - if (gUnknown_203F3E0->unk40 > 9 && gUnknown_203F3E0->unk120 == 0) + if (sGame->unk40 > 9 && sGame->unk120 == 0) { - gUnknown_203F3E0->unk40 = 10; - if (gUnknown_203F3E0->unk12C != 0) + sGame->unk40 = 10; + if (sGame->unk12C != 0) return TRUE; } return FALSE; } -static bool32 sub_8152AD8(void) +static bool32 ReadyToEndGame_Member(void) { u8 i, first, count; - if (gUnknown_203F3E0->unk40 > 9) + if (sGame->unk40 > 9) { - first = gUnknown_203F3E0->unk44; - count = gUnknown_203F3E0->unk48; - gUnknown_203F3E0->unk40 = 10; - if (gUnknown_203F3E0->unk12C != 0) + first = sGame->unk44; + count = sGame->unk48; + sGame->unk40 = 10; + if (sGame->unk12C != 0) { for (i = first; i < count; i++) { - struct DodrioSubstruct_31A0 * ptr = &gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId]; - u8 var = sUnknown_8471F50[gUnknown_203F3E0->unk24 - 1][gUnknown_203F3E0->multiplayerId][i]; + struct DodrioSubstruct_31A0 * ptr = &sGame->unk31A0[sGame->multiplayerId]; + u8 var = sActiveColumnMap[sGame->unk24 - 1][sGame->multiplayerId][i]; if (ptr->unk14.unkB[var] != 10) return FALSE; @@ -1747,47 +2059,47 @@ static bool32 sub_8152AD8(void) return FALSE; } -static void sub_8152B64(u8 arg0) +static void TryIncrementDifficulty(u8 arg0) { - u8 var = sUnknown_8475550[gUnknown_203F3E0->unk90[arg0] % 7] + (gUnknown_203F3E0->unk90[arg0] / 7) * 100; - if (gUnknown_203F3E0->unk86[arg0] >= var) - gUnknown_203F3E0->unk90[arg0]++; + u8 var = sDifficultyThresholds[sGame->unk90[arg0] % 7] + (sGame->unk90[arg0] / 7) * 100; + if (sGame->unk86[arg0] >= var) + sGame->unk90[arg0]++; } -static u8 sub_8152BD4(u8 arg0) +static u8 GetPlayerIdAtColumn(u8 arg0) { - return sUnknown_84720FC[gUnknown_203F3E0->unk24 - 1][arg0]; + return sPlayerIdAtColumn[sGame->unk24 - 1][arg0]; } -static u8 sub_8152BF8(u8 arg0, u8 arg1) +static u8 GetNewBerryId(u8 arg0, u8 arg1) { u8 i, var3; - u8 count = gUnknown_203F3E0->unk24 - 1; - u8 var0 = sUnknown_84720AE[count][arg0][0]; - u8 var1 = sUnknown_84720AE[count][arg0][1]; - u8 var2 = sUnknown_84720AE[count][arg0][2]; + u8 count = sGame->unk24 - 1; + u8 var0 = sDodrioNeighborMap[count][arg0][0]; + u8 var1 = sDodrioNeighborMap[count][arg0][1]; + u8 var2 = sDodrioNeighborMap[count][arg0][2]; - for (i = 0; sUnknown_8472133[count][i] != 0; i++) + for (i = 0; sUnsharedColumns[count][i] != 0; i++) { - if (arg1 == sUnknown_8472133[count][i]) - return sub_8152CB8(gUnknown_203F3E0->unk90[var1], arg1); + if (arg1 == sUnsharedColumns[count][i]) + return GetNewBerryIdByDifficulty(sGame->unk90[var1], arg1); } // Gets the highest of the three. - if (gUnknown_203F3E0->unk90[var0] > gUnknown_203F3E0->unk90[var1]) - var3 = gUnknown_203F3E0->unk90[var0]; + if (sGame->unk90[var0] > sGame->unk90[var1]) + var3 = sGame->unk90[var0]; else - var3 = gUnknown_203F3E0->unk90[var1]; + var3 = sGame->unk90[var1]; - if (gUnknown_203F3E0->unk90[var2] > var3) - var3 = gUnknown_203F3E0->unk90[var2]; + if (sGame->unk90[var2] > var3) + var3 = sGame->unk90[var2]; - return sub_8152CB8(var3, arg1); + return GetNewBerryIdByDifficulty(var3, arg1); } -static u8 sub_8152CB8(u8 arg0, u8 arg1) +static u8 GetNewBerryIdByDifficulty(u8 arg0, u8 arg1) { - u8 var = gUnknown_203F3E0->unkE8[arg1]; + u8 var = sGame->unkE8[arg1]; switch (arg0 % 7) { default: return 0; @@ -1819,17 +2131,17 @@ static u8 sub_8152CB8(u8 arg0, u8 arg1) } } -static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) +static void IncrementBerryResult(u8 arg0, u8 arg1, u8 arg2) { u8 var; - u8 count = gUnknown_203F3E0->unk24; + u8 count = sGame->unk24; switch (arg0) { case 0: case 1: case 2: - var = gUnknown_203F3E0->unk31A0[0].unk14.unk0[arg1]; - gUnknown_203F3E0->unk4A[arg2][var] = IncrementWithLimit(gUnknown_203F3E0->unk4A[arg2][var], 20000); + var = sGame->unk31A0[0].unk14.unk0[arg1]; + sGame->unk4A[arg2][var] = IncrementWithLimit(sGame->unk4A[arg2][var], 20000); break; case 3: switch (count) @@ -1838,39 +2150,39 @@ static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) switch (arg1) { case 0: - gUnknown_203F3E0->unk4A[2][3]++; - gUnknown_203F3E0->unk4A[3][3]++; + sGame->unk4A[2][3]++; + sGame->unk4A[3][3]++; break; case 1: - gUnknown_203F3E0->unk4A[3][3]++; + sGame->unk4A[3][3]++; break; case 2: - gUnknown_203F3E0->unk4A[3][3]++; - gUnknown_203F3E0->unk4A[4][3]++; + sGame->unk4A[3][3]++; + sGame->unk4A[4][3]++; break; case 3: - gUnknown_203F3E0->unk4A[4][3]++; + sGame->unk4A[4][3]++; break; case 4: - gUnknown_203F3E0->unk4A[4][3]++; - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[4][3]++; + sGame->unk4A[0][3]++; break; case 5: - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[0][3]++; break; case 6: - gUnknown_203F3E0->unk4A[0][3]++; - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[0][3]++; + sGame->unk4A[1][3]++; break; case 7: - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[1][3]++; break; case 8: - gUnknown_203F3E0->unk4A[1][3]++; - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[1][3]++; + sGame->unk4A[2][3]++; break; case 9: - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[2][3]++; break; } break; @@ -1878,32 +2190,32 @@ static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) switch (arg1) { case 1: - gUnknown_203F3E0->unk4A[2][3]++; - gUnknown_203F3E0->unk4A[3][3]++; + sGame->unk4A[2][3]++; + sGame->unk4A[3][3]++; break; case 2: - gUnknown_203F3E0->unk4A[3][3]++; + sGame->unk4A[3][3]++; break; case 3: - gUnknown_203F3E0->unk4A[3][3]++; - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[3][3]++; + sGame->unk4A[0][3]++; break; case 4: - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[0][3]++; break; case 5: - gUnknown_203F3E0->unk4A[0][3]++; - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[0][3]++; + sGame->unk4A[1][3]++; break; case 6: - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[1][3]++; break; case 7: - gUnknown_203F3E0->unk4A[1][3]++; - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[1][3]++; + sGame->unk4A[2][3]++; break; case 8: - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[2][3]++; break; } break; @@ -1911,25 +2223,25 @@ static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) switch (arg1) { case 2: - gUnknown_203F3E0->unk4A[1][3]++; - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[1][3]++; + sGame->unk4A[2][3]++; break; case 3: - gUnknown_203F3E0->unk4A[2][3]++; + sGame->unk4A[2][3]++; break; case 4: - gUnknown_203F3E0->unk4A[2][3]++; - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[2][3]++; + sGame->unk4A[0][3]++; break; case 5: - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[0][3]++; break; case 6: - gUnknown_203F3E0->unk4A[0][3]++; - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[0][3]++; + sGame->unk4A[1][3]++; break; case 7: - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[1][3]++; break; } break; @@ -1937,18 +2249,18 @@ static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) switch (arg1) { case 3: - gUnknown_203F3E0->unk4A[0][3]++; - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[0][3]++; + sGame->unk4A[1][3]++; break; case 4: - gUnknown_203F3E0->unk4A[0][3]++; + sGame->unk4A[0][3]++; break; case 5: - gUnknown_203F3E0->unk4A[0][3]++; - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[0][3]++; + sGame->unk4A[1][3]++; break; case 6: - gUnknown_203F3E0->unk4A[1][3]++; + sGame->unk4A[1][3]++; break; } break; @@ -1957,68 +2269,68 @@ static void sub_8152D34(u8 arg0, u8 arg1, u8 arg2) } } -static void sub_8152F94(bool32 arg0) +static void UpdateBerriesPickedInRow(bool32 arg0) { - if (gUnknown_203F3E0->unk24 != 5) + if (sGame->unk24 != 5) return; if (arg0 == TRUE) { - if (++gUnknown_203F3E0->unk112 > gUnknown_203F3E0->unk114) - gUnknown_203F3E0->unk114 = gUnknown_203F3E0->unk112; - if (gUnknown_203F3E0->unk112 > 9999) - gUnknown_203F3E0->unk112 = 9999; + if (++sGame->unk112 > sGame->unk114) + sGame->unk114 = sGame->unk112; + if (sGame->unk112 > 9999) + sGame->unk112 = 9999; } else { - if (gUnknown_203F3E0->unk112 > gUnknown_203F3E0->unk114) - gUnknown_203F3E0->unk114 = gUnknown_203F3E0->unk112; - gUnknown_203F3E0->unk112 = 0; + if (sGame->unk112 > sGame->unk114) + sGame->unk114 = sGame->unk112; + sGame->unk112 = 0; } } -static void sub_8153004(void) +static void SetMaxBerriesPickedInRow(void) { u8 i; - for (i = 0; i < gUnknown_203F3E0->unk24; i++) - gUnknown_203F3E0->unk4A[i][5] = gUnknown_203F3E0->unk114; + for (i = 0; i < sGame->unk24; i++) + sGame->unk4A[i][5] = sGame->unk114; } -static void sub_8153048(void) +static void ResetForPlayAgainPrompt(void) { u8 i, j; for (i = 0; i < 5; i++) { for (j = 0; j < 11; j++) - gUnknown_203F3E0->unk31A0[i].unk14.unkB[j] = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk0 = 0; - gUnknown_203F3E0->unk31A0[i].unk2C.unk4 = 0; - gUnknown_203F3E0->unk90[i] = 0; - gUnknown_203F3E0->unk86[i] = 0; - gUnknown_203F3E0->unk3308[i].unk0 = 0; - gUnknown_203F3E0->unk3308[i].unk4 = 0; - gUnknown_203F3E0->unk4A[i][0] = 0; - gUnknown_203F3E0->unk4A[i][1] = 0; - gUnknown_203F3E0->unk4A[i][2] = 0; - gUnknown_203F3E0->unk4A[i][3] = 0; - gUnknown_203F3E0->unk4A[i][4] = 0; - gUnknown_203F3E0->unk4A[i][5] = 0; + sGame->unk31A0[i].unk14.unkB[j] = 0; + sGame->unk31A0[i].unk2C.unk0 = 0; + sGame->unk31A0[i].unk2C.unk4 = 0; + sGame->unk90[i] = 0; + sGame->unk86[i] = 0; + sGame->unk3308[i].unk0 = 0; + sGame->unk3308[i].unk4 = 0; + sGame->unk4A[i][0] = 0; + sGame->unk4A[i][1] = 0; + sGame->unk4A[i][2] = 0; + sGame->unk4A[i][3] = 0; + sGame->unk4A[i][4] = 0; + sGame->unk4A[i][5] = 0; } - gUnknown_203F3E0->unk154 = 0; - gUnknown_203F3E0->unk112 = 0; - gUnknown_203F3E0->unk40 = 0; - sub_81528D0(); - sub_81527D0(); + sGame->unk154 = 0; + sGame->unk112 = 0; + sGame->unk40 = 0; + UpdateAllDodrioAnims(); + UpdateBerrySprites(); } -static const s16 sUnknown_84755D8[] = {10, 30, 50, 50}; +static const s16 sBerryScoreMultipliers[] = {10, 30, 50, 50}; -static void sub_8153150(void) +static void SetRandomPrize(void) { u8 i, var = 0, var2 = 0; - switch (gUnknown_203F3E0->unk24) + switch (sGame->unk24) { case 4: var = 1; break; case 5: var = 2; break; @@ -2026,153 +2338,153 @@ static void sub_8153150(void) var2 = Random() % 10; for (i = 0; i < 5; i++) - gUnknown_203F3E0->unk4A[i][4] = sUnknown_8475558[var][var2]; + sGame->unk4A[i][4] = sPrizeBerryIds[var][var2]; } -static u32 sub_81531BC(u8 arg0) +static u32 GetBerriesPicked(u8 arg0) { - u32 sum = gUnknown_203F3E0->unk4A[arg0][0] - + gUnknown_203F3E0->unk4A[arg0][1] - + gUnknown_203F3E0->unk4A[arg0][2]; + u32 sum = sGame->unk4A[arg0][0] + + sGame->unk4A[arg0][1] + + sGame->unk4A[arg0][2]; return min(sum, 9999); } -static void sub_81531FC(void) +static void TryUpdateRecords(void) { - u32 berriesPicked = Min(sub_81531BC(gUnknown_203F3E0->multiplayerId), 9999); - u32 score = Min(sub_8153424(gUnknown_203F3E0->multiplayerId), 999990); + u32 berriesPicked = Min(GetBerriesPicked(sGame->multiplayerId), 9999); + u32 score = Min(GetScore(sGame->multiplayerId), 999990); if (gSaveBlock2Ptr->berryPick.bestScore < score) gSaveBlock2Ptr->berryPick.bestScore = score; if (gSaveBlock2Ptr->berryPick.berriesPicked < berriesPicked) gSaveBlock2Ptr->berryPick.berriesPicked = berriesPicked; - if (gSaveBlock2Ptr->berryPick.berriesPickedInRow < gUnknown_203F3E0->unk114) - gSaveBlock2Ptr->berryPick.berriesPickedInRow = gUnknown_203F3E0->unk114; + if (gSaveBlock2Ptr->berryPick.berriesPickedInRow < sGame->unk114) + gSaveBlock2Ptr->berryPick.berriesPickedInRow = sGame->unk114; } -static u8 sub_815327C(u8 arg0) +static u8 UpdatePickStateQueue(u8 arg0) { u8 i, saved; - saved = gUnknown_203F3E0->unk98[3]; + saved = sGame->unk98[3]; for (i = 3; i != 0; i--) - gUnknown_203F3E0->unk98[i] = gUnknown_203F3E0->unk98[i - 1]; - gUnknown_203F3E0->unk98[0] = arg0; + sGame->unk98[i] = sGame->unk98[i - 1]; + sGame->unk98[0] = arg0; return saved; } -static void sub_81532B8(void) +static void HandleWaitPlayAgainInput(void) { - if (gUnknown_203F3E0->unkB0[gUnknown_203F3E0->multiplayerId] == 0) + if (sGame->unkB0[sGame->multiplayerId] == 0) { if (JOY_NEW(DPAD_UP)) { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 = 2; - gUnknown_203F3E0->unkB0[gUnknown_203F3E0->multiplayerId] = 6; + sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 = 2; + sGame->unkB0[sGame->multiplayerId] = 6; PlaySE(SE_M_CHARM); } else if (JOY_NEW(DPAD_LEFT)) { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 = 3; - gUnknown_203F3E0->unkB0[gUnknown_203F3E0->multiplayerId] = 6; + sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 = 3; + sGame->unkB0[sGame->multiplayerId] = 6; PlaySE(SE_M_CHARM); } else if (JOY_NEW(DPAD_RIGHT)) { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 = 1; - gUnknown_203F3E0->unkB0[gUnknown_203F3E0->multiplayerId] = 6; + sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 = 1; + sGame->unkB0[sGame->multiplayerId] = 6; PlaySE(SE_M_CHARM); } else { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 = 0; + sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 = 0; } } else { - gUnknown_203F3E0->unkB0[gUnknown_203F3E0->multiplayerId]--; + sGame->unkB0[sGame->multiplayerId]--; } } -static void sub_815336C(void) +static void ResetPickState(void) { - gUnknown_203F3E0->unk31A0[gUnknown_203F3E0->multiplayerId].unk2C.unk0 = 0; + sGame->unk31A0[sGame->multiplayerId].unk2C.unk0 = 0; } -u16 sub_8153390(void) +u16 GetPrizeItemId(void) { - return gUnknown_203F3E0->unk4A[gUnknown_203F3E0->multiplayerId][4] + FIRST_BERRY_INDEX; + return sGame->unk4A[sGame->multiplayerId][4] + FIRST_BERRY_INDEX; } -u8 sub_81533B4(void) +u8 GetNumPlayers(void) { - return gUnknown_203F3E0->unk24; + return sGame->unk24; } -u8 *sub_81533C4(u8 id) +u8 *GetPlayerName(u8 id) { if (gReceivedRemoteLinkPlayers) return gLinkPlayers[id].name; else - return gUnknown_203F3E0->unk31A0[id].name; + return sGame->unk31A0[id].name; } -u16 sub_8153404(u8 arg0, u8 arg1) +u16 GetBerryResult(u8 arg0, u8 arg1) { - return gUnknown_203F3E0->unk4A[arg0][arg1]; + return sGame->unk4A[arg0][arg1]; } -static u32 sub_8153424(u8 arg0) +static u32 GetScore(u8 arg0) { u8 i; u32 var, sum = 0; for (i = 0; i < 3; i++) - sum += gUnknown_203F3E0->unk4A[arg0][i] * sUnknown_84755D8[i]; + sum += sGame->unk4A[arg0][i] * sBerryScoreMultipliers[i]; - var = gUnknown_203F3E0->unk4A[arg0][3] * sUnknown_84755D8[3]; + var = sGame->unk4A[arg0][3] * sBerryScoreMultipliers[3]; if (sum <= var) return 0; else return sum - var; } -u32 sub_81534AC(void) +u32 GetHighestScore(void) { - u8 i, count = gUnknown_203F3E0->unk24; - u32 maxVar = sub_8153424(0); + u8 i, count = sGame->unk24; + u32 maxVar = GetScore(0); for (i = 1; i < count; i++) { - u32 var = sub_8153424(i); + u32 var = GetScore(i); if (var > maxVar) maxVar = var; } return Min(maxVar, 999990); } -u32 sub_81534F0(u8 arg0) +u32 GetHighestBerryResult(u8 arg0) { - u8 i, count = gUnknown_203F3E0->unk24; - u16 maxVar = gUnknown_203F3E0->unk4A[0][arg0]; + u8 i, count = sGame->unk24; + u16 maxVar = sGame->unk4A[0][arg0]; for (i = 0; i < count; i++) { - u16 var = gUnknown_203F3E0->unk4A[i][arg0]; + u16 var = sGame->unk4A[i][arg0]; if (var > maxVar) maxVar = var; } return maxVar; } -static u32 sub_8153534(u8 arg0) +static u32 GetScoreByRanking(u8 arg0) { u32 vals[5], temp; s16 r6 = TRUE; - u8 i, count = gUnknown_203F3E0->unk24; + u8 i, count = sGame->unk24; for (i = 0; i < count; i++) - vals[i] = temp = sub_8153424(i); + vals[i] = temp = GetScore(i); while (r6) { @@ -2190,33 +2502,33 @@ static u32 sub_8153534(u8 arg0) return vals[arg0]; } -u32 sub_81535B0(void) +u32 SetScoreResults(void) { - u8 i, r10 = 0, r8 = 0, r9 = 0, count = gUnknown_203F3E0->unk24; + u8 i, r10 = 0, r8 = 0, r9 = 0, count = sGame->unk24; // Function called two times for some reason. - sub_81534AC(); - if (sub_81534AC() == 0) + GetHighestScore(); + if (GetHighestScore() == 0) { for (i = 0; i < count; i++) { - gUnknown_203F3E0->unk3308[i].unk0 = 4; - gUnknown_203F3E0->unk3308[i].unk4 = 0; + sGame->unk3308[i].unk0 = 4; + sGame->unk3308[i].unk4 = 0; } } for (i = 0; i < count; i++) - gUnknown_203F3E0->unk3308[i].unk4 = Min(sub_8153424(i), 999990); + sGame->unk3308[i].unk4 = Min(GetScore(i), 999990); do { - u32 r6 = sub_8153534(r10); + u32 r6 = GetScoreByRanking(r10); u8 r3 = r8; for (i = 0; i < count; i++) { - if (r6 == gUnknown_203F3E0->unk3308[i].unk4) + if (r6 == sGame->unk3308[i].unk4) { - gUnknown_203F3E0->unk3308[i].unk0 = r3; + sGame->unk3308[i].unk0 = r3; r8++; r9++; } @@ -2227,18 +2539,18 @@ u32 sub_81535B0(void) return 0; } -void sub_81536A0(struct DodrioSubstruct_3308 * dst, u8 id) +void GetScoreResults(struct DodrioSubstruct_3308 * dst, u8 id) { - *dst = gUnknown_203F3E0->unk3308[id]; + *dst = sGame->unk3308[id]; } -static u8 sub_81536C0(u8 arg0) +static u8 GetScoreRanking(u8 arg0) { - u8 i, ret = 0, count = gUnknown_203F3E0->unk24; + u8 i, ret = 0, count = sGame->unk24; u32 var, vars[5] = {0}; for (i = 0; i < count; i++) - vars[i] = sub_8153424(i); + vars[i] = GetScore(i); var = vars[arg0]; for (i = 0; i < 5; i++) @@ -2250,12 +2562,12 @@ static u8 sub_81536C0(u8 arg0) return ret; } -u8 sub_815372C(void) +u8 TryGivePrize(void) { - u8 multiplayerId = gUnknown_203F3E0->multiplayerId; - u16 itemId = sub_8153390(); + u8 multiplayerId = sGame->multiplayerId; + u16 itemId = GetPrizeItemId(); - if (sub_8153424(multiplayerId) != sub_81534AC()) + if (GetScore(multiplayerId) != GetHighestScore()) return 3; if (!CheckBagHasSpace(itemId, 1)) return 2; @@ -2266,7 +2578,6 @@ u8 sub_815372C(void) return 0; } -// Really? What next, u32 Add(u32 a)return a+1;? u32 IncrementWithLimit(u32 a, u32 max) { if (a < max) @@ -2275,7 +2586,6 @@ u32 IncrementWithLimit(u32 a, u32 max) return max; } -// Gamefreak pls, min(a, b) ((a) < (b) ? (a) : (b)) is a well-known macro u32 Min(u32 a, u32 b) { if (a < b) @@ -2284,9 +2594,9 @@ u32 Min(u32 a, u32 b) return b; } -u8 sub_81537AC(u8 id) +u8 GetPlayerIdByPos(u8 id) { - return gUnknown_203F3E0->unk34[id]; + return sGame->unk34[id]; } void IsDodrioInParty(void) @@ -2312,7 +2622,7 @@ void ShowDodrioBerryPickingRecords(void) } // Data related to printing saved results. -static const struct WindowTemplate sUnknown_84755E0 = +static const struct WindowTemplate sWindowTemplates_Records = { .bg = 0, .tilemapLeft = 1, @@ -2323,12 +2633,12 @@ static const struct WindowTemplate sUnknown_84755E0 = .baseBlock = 1, }; -static const u8 *const sUnknown_84755E8[] = {gText_BerryPickingRecords, gText_BerriesPicked, gText_BestScore, gText_BerriesInRowFivePlayers}; -static const u8 sUnknown_84755F8[] = {4, 7, 4}; +static const u8 *const sRecordsTexts[] = {gText_BerryPickingRecords, gText_BerriesPicked, gText_BestScore, gText_BerriesInRowFivePlayers}; +static const u8 sRecordNumMaxDigits[] = {4, 7, 4}; ALIGNED(4) -static const u8 sUnknown_84755FC[][2] = {{24}, {40}, {56}}; -static const u8 sUnknown_8475602[][2] = {{24}, {40}, {70}}; +static const u8 sRecordTextYCoords[][2] = {{24}, {40}, {56}}; +static const u8 sRecordNumYCoords[][2] = {{24}, {40}, {70}}; static void Task_ShowDodrioBerryPickingRecords(u8 taskId) { @@ -2339,8 +2649,8 @@ static void Task_ShowDodrioBerryPickingRecords(u8 taskId) switch (data[0]) { case 0: - data[1] = AddWindow(&sUnknown_84755E0); - sub_81538D0(data[1]); + data[1] = AddWindow(&sWindowTemplates_Records); + PrintRecordsText(data[1]); CopyWindowToVram(data[1], COPYWIN_FULL); data[0]++; break; @@ -2367,7 +2677,7 @@ static void Task_ShowDodrioBerryPickingRecords(u8 taskId) } } -static void sub_81538D0(u8 windowId) +static void PrintRecordsText(u8 windowId) { s32 i, x, numWidth; s32 results[3]; @@ -2379,20 +2689,20 @@ static void sub_81538D0(u8 windowId) TextWindow_SetStdFrame0_WithPal(windowId, 0x21D, 0xD0); DrawTextBorderOuter(windowId, 0x21D, 0xD); FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); - AddTextPrinterParameterized(windowId, FONT_2, sUnknown_84755E8[0], 1, 1, TEXT_SKIP_DRAW, NULL); + AddTextPrinterParameterized(windowId, FONT_2, sRecordsTexts[0], 1, 1, TEXT_SKIP_DRAW, NULL); for (i = 0; i < 3; i++) { - ConvertIntToDecimalStringN(strbuf, results[i], STR_CONV_MODE_LEFT_ALIGN, sUnknown_84755F8[i]); + ConvertIntToDecimalStringN(strbuf, results[i], STR_CONV_MODE_LEFT_ALIGN, sRecordNumMaxDigits[i]); numWidth = GetStringWidth(FONT_2, strbuf, -1); - AddTextPrinterParameterized(windowId, FONT_2, sUnknown_84755E8[i + 1], 1, sUnknown_84755FC[i][0], TEXT_SKIP_DRAW, NULL); + AddTextPrinterParameterized(windowId, FONT_2, sRecordsTexts[i + 1], 1, sRecordTextYCoords[i][0], TEXT_SKIP_DRAW, NULL); x = 224 - numWidth; - AddTextPrinterParameterized(windowId, FONT_2, strbuf, x, sUnknown_8475602[i][0], TEXT_SKIP_DRAW, NULL); + AddTextPrinterParameterized(windowId, FONT_2, strbuf, x, sRecordNumYCoords[i][0], TEXT_SKIP_DRAW, NULL); } PutWindowTilemap(windowId); } // Debug functions? -static const u16 sUnknown_8475608[][4] = +static const u16 sDebug_BerryResults[][4] = { {9999, 0, 90, 9999}, {9999, 9999, 70, 9999}, @@ -2401,35 +2711,1837 @@ static const u16 sUnknown_8475608[][4] = {9999, 9999, 9999, 0}, }; -static const u8 sUnknown_8475630[] = _("あいうえおかき"); -static const u8 sUnknown_8475638[] = _("ABCDEFG"); -static const u8 sUnknown_8475640[] = _("0123456"); +static const u8 sJPText_Vowels[] = _("あいうえおかき"); +static const u8 sText_Letters[] = _("ABCDEFG"); +static const u8 sText_Digits[] = _("0123456"); static const u8 *const sPlaceholderPlayerNames[] = { - sUnknown_8475630, - sUnknown_8475630, - sUnknown_8475630, - sUnknown_8475638, - sUnknown_8475640 + sJPText_Vowels, + sJPText_Vowels, + sJPText_Vowels, + sText_Letters, + sText_Digits }; -static void sub_81539EC(void) +static void Debug_UpdateNumPlayers(void) { - gUnknown_203F3E0->unk24 = GetLinkPlayerCount(); + sGame->unk24 = GetLinkPlayerCount(); } -static void sub_8153A04(void) +static void Debug_SetPlayerNamesAndResults(void) { u8 i, playerId; - for (playerId = gUnknown_203F3E0->unk24; playerId < NELEMS(sPlaceholderPlayerNames); playerId++) + for (playerId = sGame->unk24; playerId < NELEMS(sPlaceholderPlayerNames); playerId++) StringCopy(gLinkPlayers[playerId].name, sPlaceholderPlayerNames[playerId]); - gUnknown_203F3E0->unk24 = 5; + sGame->unk24 = 5; for (i = 0; i < 4; i++) { - for (playerId = 0; playerId < gUnknown_203F3E0->unk24; playerId++) - gUnknown_203F3E0->unk4A[playerId][i] = sUnknown_8475608[playerId][i]; + for (playerId = 0; playerId < sGame->unk24; playerId++) + sGame->unk4A[playerId][i] = sDebug_BerryResults[playerId][i]; } } + +static const struct BgTemplate sBgTemplates[] = +{ + { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0 + }, + { + .bg = 1, + .charBaseIndex = 2, + .mapBaseIndex = 12, + .screenSize = 1, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + }, + { + .bg = 2, + .charBaseIndex = 2, + .mapBaseIndex = 14, + .screenSize = 1, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + }, + { + .bg = 3, + .charBaseIndex = 3, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0 + }, +}; + +static const struct WindowTemplate sWindowTemplate_Dummy = DUMMY_WIN_TEMPLATE; + +static const struct WindowTemplate sWindowTemplates_Results[] = +{ + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 28, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, + }, + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 6, + .width = 28, + .height = 13, + .paletteNum = 13, + .baseBlock = 0x67, + } +}; + +static const struct WindowTemplate sWindowTemplate_Prize = +{ + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 6, + .width = 28, + .height = 7, + .paletteNum = 13, + .baseBlock = 0x67, +}; + +static const struct WindowTemplate sWindowTemplates_PlayAgain[] = +{ + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 8, + .width = 19, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, + }, + { + .bg = 0, + .tilemapLeft = 22, + .tilemapTop = 7, + .width = 6, + .height = 4, + .paletteNum = 13, + .baseBlock = 0x4C, + } +}; + +static const struct WindowTemplate sWindowTemplate_DroppedOut = +{ + .bg = 0, + .tilemapLeft = 4, + .tilemapTop = 6, + .width = 22, + .height = 5, + .paletteNum = 13, + .baseBlock = 0x13, +}; + +static const struct WindowTemplate sWindowTemplate_CommStandby = +{ + .bg = 0, + .tilemapLeft = 5, + .tilemapTop = 8, + .width = 19, + .height = 3, + .paletteNum = 13, + .baseBlock = 0x13, +}; + +static const u8 sActiveColumnMap_Duplicate[5][5][11] = +{ + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 3, 8, 9, 0}, + {0, 1, 2, 5, 6, 3, 4, 5, 8, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 2, 9, 0}, + {0, 1, 4, 5, 6, 7, 2, 3, 4, 9, 0}, + {0, 1, 6, 7, 2, 3, 4, 5, 6, 9, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 0}, + {0, 3, 4, 5, 6, 7, 8, 1, 2, 3, 0}, + {0, 5, 6, 7, 8, 1, 2, 3, 4, 5, 0}, + {0, 7, 8, 1, 2, 3, 4, 5, 6, 7, 0}, + }, + { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + {2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}, + {4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4}, + {6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, + {8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8}, + }, +}; + +static const u8 sDodrioHeadToColumnMap_Duplicate[5][5][3] = +{ + { + {4, 5, 6}, + }, + { + {3, 4, 5}, + {5, 6, 3}, + }, + { + {4, 5, 6}, + {6, 7, 2}, + {2, 3, 4}, + }, + { + {3, 4, 5}, + {5, 6, 7}, + {7, 8, 1}, + {1, 2, 3}, + }, + { + {4, 5, 6}, + {6, 7, 8}, + {8, 9, 0}, + {0, 1, 2}, + {2, 3, 4}, + }, +}; + +static const u8 sDodrioNeighborMap_Duplicate[5][5][3] = +{ + { + {1, 0, 1}, + }, + { + {1, 0, 1}, + {0, 1, 0}, + }, + { + {2, 0, 1}, + {0, 1, 2}, + {1, 2, 0}, + }, + { + {3, 0, 1}, + {0, 1, 2}, + {1, 2, 3}, + {2, 3, 0}, + }, + { + {4, 0, 1}, + {0, 1, 2}, + {1, 2, 3}, + {2, 3, 4}, + {3, 4, 0}, + }, +}; + +ALIGNED(4) +static const u8 sPlayerIdAtColumn_Duplicate[5][11] = +{ + {9, 9, 9, 9, 1, 1, 1, 9, 9, 9, 9}, + {9, 9, 9, 0, 0, 1, 1, 0, 9, 9, 9}, + {9, 9, 2, 2, 0, 0, 1, 1, 1, 9, 9}, + {9, 3, 3, 0, 0, 1, 1, 2, 2, 3, 9}, + {3, 3, 4, 4, 0, 0, 1, 1, 2, 2, 3}, +}; + +static const u8 sUnsharedColumns_Duplicate[5][5] = +{ + {5}, + {4, 6}, + {3, 5, 7}, + {2, 4, 6, 8}, + {1, 3, 5, 6, 9}, +}; + +static const u16 sDodrioBerryBgPal1[] = INCBIN_U16("graphics/link_games/dodrioberry_bg1.gbapal", + "graphics/link_games/dodrioberry_bg2.gbapal"); +static const u16 sDodrioBerryPkmnPal[] = INCBIN_U16("graphics/link_games/dodrioberry_pkmn.gbapal"); +static const u16 sDodrioBerryShinyPal[] = INCBIN_U16("graphics/link_games/dodrioberry_shiny.gbapal"); +static const u16 sDodrioBerryStatusPal[] = INCBIN_U16("graphics/link_games/dodrioberry_status.gbapal"); +static const u16 sDodrioBerrySpritesPal[] = INCBIN_U16("graphics/link_games/dodrioberry_berrysprites.gbapal"); +static const u32 sDodrioBerrySpritesGfx[] = INCBIN_U32("graphics/link_games/dodrioberry_berrysprites.4bpp.lz"); +static const u16 sDodrioBerryPlatformPal[] = INCBIN_U16("graphics/link_games/dodrioberry_platform.gbapal"); +static const u32 sDodrioBerryBgGfx1[] = INCBIN_U32("graphics/link_games/dodrioberry_bg1.4bpp.lz"); +static const u32 sDodrioBerryBgGfx2[] = INCBIN_U32("graphics/link_games/dodrioberry_bg2.4bpp.lz"); +static const u32 sDodrioBerryStatusGfx[] = INCBIN_U32("graphics/link_games/dodrioberry_status.4bpp.lz"); +static const u32 sDodrioBerryPlatformGfx[] = INCBIN_U32("graphics/link_games/dodrioberry_platform.4bpp.lz"); +static const u32 sDodrioBerryPkmnGfx[] = INCBIN_U32("graphics/link_games/dodrioberry_pkmn.4bpp.lz"); +static const u32 sDodrioBerryBgTilemap1[] = INCBIN_U32("graphics/link_games/dodrioberry_bg1.bin.lz"); +static const u32 sDodrioBerryBgTilemap2Right[] = INCBIN_U32("graphics/link_games/dodrioberry_bg2right.bin.lz"); +static const u32 sDodrioBerryBgTilemap2Left[] = INCBIN_U32("graphics/link_games/dodrioberry_bg2left.bin.lz"); + +static const struct OamData sOamData_Dodrio = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(64x64), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(64x64), + .tileNum = 0, + .priority = 2, + .paletteNum = 0, + .affineParam = 0 +}; + +static const struct OamData sOamData_16x16_Priority0 = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(16x16), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(16x16), + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0 +}; + +static const struct OamData sOamData_Berry = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(16x16), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(16x16), + .tileNum = 0, + .priority = 2, + .paletteNum = 0, + .affineParam = 0 +}; + +static const struct OamData sOamData_Cloud = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(64x32), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(64x32), + .tileNum = 0, + .priority = 3, + .paletteNum = 0, + .affineParam = 0 +}; + +static const union AnimCmd sAnim_Dodrio_Normal[] = +{ + ANIMCMD_FRAME(0, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Dodrio_PickRight[] = +{ + ANIMCMD_FRAME(64, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Dodrio_PickMiddle[] = +{ + ANIMCMD_FRAME(128, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Dodrio_PickLeft[] = +{ + ANIMCMD_FRAME(192, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Dodrio_Down[] = +{ + ANIMCMD_FRAME(256, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sAnims_Dodrio[] = +{ + sAnim_Dodrio_Normal, + sAnim_Dodrio_PickRight, + sAnim_Dodrio_PickMiddle, + sAnim_Dodrio_PickLeft, + sAnim_Dodrio_Down +}; + +static const union AnimCmd sAnims_StatusBar_Yellow[] = +{ + ANIMCMD_FRAME(0, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnims_StatusBar_Gray[] = +{ + ANIMCMD_FRAME(4, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnims_StatusBar_Red[] = +{ + ANIMCMD_FRAME(8, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sAnims_StatusBar[] = +{ + sAnims_StatusBar_Yellow, + sAnims_StatusBar_Gray, + sAnims_StatusBar_Red +}; + +static const union AnimCmd sAnim_Berry_Blue[] = +{ + ANIMCMD_FRAME(0, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_Green[] = +{ + ANIMCMD_FRAME(4, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_Gold[] = +{ + ANIMCMD_FRAME(8, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_BlueSquished[] = +{ + ANIMCMD_FRAME(12, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_GreenSquished[] = +{ + ANIMCMD_FRAME(16, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_GoldSquished[] = +{ + ANIMCMD_FRAME(20, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_Eaten[] = +{ + ANIMCMD_FRAME(24, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_Empty1[] = +{ + ANIMCMD_FRAME(28, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Berry_Empty2[] = +{ + ANIMCMD_FRAME(32, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sAnims_Berry[] = +{ + sAnim_Berry_Blue, + sAnim_Berry_Green, + sAnim_Berry_Gold, + sAnim_Berry_BlueSquished, + sAnim_Berry_GreenSquished, + sAnim_Berry_GoldSquished, + sAnim_Berry_Eaten, + sAnim_Berry_Empty1, + sAnim_Berry_Empty2 +}; + +static const union AnimCmd sAnim_Cloud[] = +{ + ANIMCMD_FRAME(0, 20), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sAnims_Cloud[] = +{ + sAnim_Cloud +}; + +// Code + +void LoadDodrioGfx(void) +{ + void *ptr = AllocZeroed(0x3000); + struct SpritePalette pal1 = {sDodrioBerryPkmnPal, 0}; + struct SpritePalette pal2 = {sDodrioBerryShinyPal, 1}; + + LZ77UnCompWram(sDodrioBerryPkmnGfx, ptr); + // This check should be one line up. + if (ptr != NULL) + { + struct SpriteSheet sheet = {ptr, 0x3000, 0}; + LoadSpriteSheet(&sheet); + Free(ptr); + } + LoadSpritePalette(&pal1); + LoadSpritePalette(&pal2); +} + +void CreateDodrioSprite(struct DodrioSubstruct_318C * arg0, u8 arg1, u8 id, u8 arg3) +{ + struct SpriteTemplate sprTemplate = + { + .tileTag = 0, + .paletteTag = arg0->isShiny, + .oam = &sOamData_Dodrio, + .anims = sAnims_Dodrio, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_Dodrio, + }; + + sDodrioSpriteIds[id] = AllocZeroed(4); + *sDodrioSpriteIds[id] = CreateSprite(&sprTemplate, GetDodrioXPos(arg1, arg3), 136, 3); + SetDodrioInvisibility(TRUE, id); +} + +static void SpriteCB_Dodrio(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + break; + case 1: + DoDodrioMissedAnim(sprite); + break; + case 2: + DoDodrioIntroAnim(sprite); + break; + } +} + +void StartDodrioMissedAnim(u8 unused) +{ + struct Sprite *sprite = &gSprites[*sDodrioSpriteIds[GetMultiplayerId()]]; + sprite->data[0] = 1; + sprite->data[1] = 0; + sprite->data[2] = 0; + sprite->data[3] = 0; + sprite->data[4] = 0; +} + +void StartDodrioIntroAnim(u8 unused) +{ + struct Sprite *sprite = &gSprites[*sDodrioSpriteIds[GetMultiplayerId()]]; + sprite->data[0] = 2; + sprite->data[1] = 0; + sprite->data[2] = 0; + sprite->data[3] = 0; + sprite->data[4] = 0; +} + +static u32 DoDodrioMissedAnim(struct Sprite *sprite) +{ + s8 var; + u8 mod = (++sprite->data[1] / 2) % 4; + + if (sprite->data[1] >= 3) + { + switch (mod) + { + default: + var = 1; + break; + case 1: + case 2: + var = -1; + break; + } + + sprite->x += var; + if (++sprite->data[1] >= 40) + { + sprite->data[0] = 0; + sprite->x = GetDodrioXPos(0, GetNumPlayers()); + } + } + + return 0; +} + +static u32 DoDodrioIntroAnim(struct Sprite *sprite) +{ + u8 mod = (++sprite->data[1] / 13) % 4; + + if (sprite->data[1] % 13 == 0 && mod != 0) + PlaySE(SE_M_CHARM); + if (sprite->data[1] >= 104) + { + sprite->data[0] = 0; + mod = 0; + } + SetDodrioAnim(GetMultiplayerId(), mod); + return 0; +} + +void FreeDodrioSprites(u8 count) +{ + u8 i; + for (i = 0; i < count; i++) + { + struct Sprite *sprite = &gSprites[*sDodrioSpriteIds[i]]; + if (sprite != NULL) + DestroySpriteAndFreeResources(sprite); + // Memory should be freed here but is not. + } +} + +static void SetDodrioInvisibility(bool8 invisible, u8 id) +{ + gSprites[*sDodrioSpriteIds[id]].invisible = invisible; +} + +void SetAllDodrioInvisibility(bool8 invisible, u8 count) +{ + u8 i; + for (i = 0; i < count; i++) + SetDodrioInvisibility(invisible, i); +} + +void SetDodrioAnim(u8 id, u8 frameNum) +{ + StartSpriteAnim(&gSprites[*sDodrioSpriteIds[id]], frameNum); +} + +static void SpriteCB_Status(struct Sprite *sprite) +{ + +} + +void InitStatusBarPos(void) +{ + u8 i; + for (i = 0; i < 10; i++) + { + struct Sprite *sprite = &gSprites[sStatusBar->unk2A[i]]; + sprite->x = (i * 16) + 48; + sprite->y = -8 - (i * 8); + sStatusBar->unkC[i] = 0; + } +} + +void CreateStatusBarSprites(void) +{ + u8 i; + void *ptr = AllocZeroed(0x180); + struct SpritePalette spPal = {sDodrioBerryStatusPal, 2}; + + LZ77UnCompWram(sDodrioBerryStatusGfx, ptr); + // This check should be one line up. + if (ptr != NULL) + { + struct SpriteSheet spSheet = {ptr, 0x180, 1}; + struct SpriteTemplate spTemplate = + { + .tileTag = 1, + .paletteTag = 2, + .oam = &sOamData_16x16_Priority0, + .anims = sAnims_StatusBar, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_Status, + }; + + sStatusBar = AllocZeroed(sizeof(*sStatusBar)); + LoadSpriteSheet(&spSheet); + LoadSpritePalette(&spPal); + for (i = 0; i < 10; i++) + sStatusBar->unk2A[i] = CreateSprite(&spTemplate, (i * 16) + 48, -8 - (i * 8), 0); + } + + Free(ptr); +} + +void FreeStatusBar(void) +{ + u8 i; + for (i = 0; i < 10; i++) + { + struct Sprite *sprite = &gSprites[sStatusBar->unk2A[i]]; + if (sprite != NULL) + DestroySpriteAndFreeResources(sprite); + } + FREE_AND_SET_NULL(sStatusBar); +} + +bool32 DoStatusBarIntro(void) +{ + u8 i; + bool32 r3 = FALSE; + for (i = 0; i < 10; i++) + { + struct Sprite *sprite = &gSprites[sStatusBar->unk2A[i]]; + sStatusBar->unk16[i] = 2; + if (sStatusBar->unkC[i] != 0 && sprite->y == 8) + continue; + r3 = TRUE; + if (sprite->y == 8) + { + if (sStatusBar->unkC[i] != 0) + continue; + sStatusBar->unkC[i] = 1; + sStatusBar->unk16[i] = -16; + PlaySE(SE_CLICK); + } + sprite->y += sStatusBar->unk16[i]; + } + + if (r3) + return FALSE; + else + return TRUE; +} + +void UpdateStatusBarAnim(u8 arg0) +{ + u8 i; + + if (arg0 > 10) + { + for (i = 0; i < 10; i++) + StartSpriteAnim(&gSprites[sStatusBar->unk2A[i]], 1); + } + else + { + for (i = 0; i < 10 - arg0; i++) + { + if (arg0 > 6) + { + sStatusBar->unk3E += arg0 - 6; + if (sStatusBar->unk3E > 30) + sStatusBar->unk3E = 0; + else if (sStatusBar->unk3E > 10) + StartSpriteAnim(&gSprites[sStatusBar->unk2A[i]], 2); + else + StartSpriteAnim(&gSprites[sStatusBar->unk2A[i]], 0); + } + else + { + StartSpriteAnim(&gSprites[sStatusBar->unk2A[i]], 0); + } + } + for (; i < 10; i++) + StartSpriteAnim(&gSprites[sStatusBar->unk2A[i]], 1); + } +} + +void SetStatusBarInvisibility(bool8 invisible) +{ + u8 i; + for (i = 0; i < 10; i++) + gSprites[sStatusBar->unk2A[i]].invisible = invisible; +} + +// Unknown unused data, feel free to remove. +static const u8 sUnusedSounds[] = { + SE_M_CHARM, + SE_NOTE_C, + SE_NOTE_D, + SE_NOTE_E, + SE_NOTE_F, + SE_NOTE_G, + SE_NOTE_A, + SE_NOTE_B, + SE_NOTE_C_HIGH, + SE_CARD_OPEN +}; + +void LoadBerryGfx(void) +{ + void *ptr = AllocZeroed(0x480); + struct SpritePalette sprPal = {sDodrioBerrySpritesPal, 3}; + + LZ77UnCompWram(sDodrioBerrySpritesGfx, ptr); + if (ptr != NULL) // This should be one line up + { + struct SpriteSheet sprSheet = {ptr, 0x480, 2}; + LoadSpriteSheet(&sprSheet); + } + + LoadSpritePalette(&sprPal); + Free(ptr); +} + +static const s16 sBerryIconXCoords[] = {88, 128, 168, 208}; + +void CreateBerrySprites(void) +{ + u8 i; + s16 x; + + struct SpriteTemplate sprTemplate1 = + { + .tileTag = 2, + .paletteTag = 3, + .oam = &sOamData_Berry, + .anims = sAnims_Berry, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy, + }; + struct SpriteTemplate sprTemplate2 = + { + .tileTag = 2, + .paletteTag = 3, + .oam = &sOamData_16x16_Priority0, + .anims = sAnims_Berry, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy, + }; + + for (i = 0; i < 11; i++) + { + sBerrySpriteIds[i] = AllocZeroed(4); + x = i * 16; + *sBerrySpriteIds[i] = CreateSprite(&sprTemplate1, x + (i * 8), 8, 1); + SetBerryInvisibility(i, TRUE); + } + for (i = 0; i < 4; i++) + { + sBerryIconSpriteIds[i] = AllocZeroed(4); + if (i == 3) + *sBerryIconSpriteIds[i] = CreateSprite(&sprTemplate2, sBerryIconXCoords[i], 57, 0); + else + *sBerryIconSpriteIds[i] = CreateSprite(&sprTemplate2, sBerryIconXCoords[i], 60, 0); + StartSpriteAnim(&gSprites[*sBerryIconSpriteIds[i]], i); + } + + SetBerryIconsInvisibility(TRUE); +} + +void FreeBerrySprites(void) +{ + struct Sprite *sprite; + u8 i; + + for (i = 0; i < 11; i++) + { + sprite = &gSprites[*sBerrySpriteIds[i]]; + if (sprite != NULL) + DestroySprite(sprite); + FREE_AND_SET_NULL(sBerrySpriteIds[i]); + } + for (i = 0; i < 4; i++) + { + sprite = &gSprites[*sBerryIconSpriteIds[i]]; + if (sprite != NULL) + DestroySprite(sprite); + FREE_AND_SET_NULL(sBerryIconSpriteIds[i]); + } +} + +void SetBerryInvisibility(u8 id, bool8 invisible) +{ + gSprites[*sBerrySpriteIds[id]].invisible = invisible; +} + +static void SetBerryIconsInvisibility(bool8 invisible) +{ + u8 i; + for (i = 0; i < 4; i++) + gSprites[*sBerryIconSpriteIds[i]].invisible = invisible; +} + +void SetBerryYPos(u8 id, u8 y) +{ + gSprites[*sBerrySpriteIds[id]].y = y * 8; +} + +void SetBerryAnim(u16 id, u8 frameNum) +{ + StartSpriteAnim(&gSprites[*sBerrySpriteIds[id]], frameNum); +} + +// Unused +static void UnusedSetSpritePos(u8 spriteId) +{ + gSprites[spriteId].x = 20 * spriteId + 50; + gSprites[spriteId].y = 50; +} + +// Gamefreak made a mistake there and goes out of bounds for the data array as it holds 8 elements +// in turn overwriting sprite's subpriority and subsprites fields. +#if defined(BUGFIX) +#define sKeepPosX data[1] +#else +#define sKeepPosX data[10] +#endif // BUGFIX + +static void SpriteCB_Cloud(struct Sprite *sprite) +{ + u8 i; + static const u8 array[] = {30, 20}; + + if (sprite->sKeepPosX != TRUE) + { + for (i = 0; i < 2; i++) + { + if (++sCloudSpriteIds[i][1] > array[i]) + { + sprite->x--; + sCloudSpriteIds[i][1] = 0; + } + } + } +} + +static const s16 sCloudStartCoords[][2] = {{230, 55}, {30, 74}}; + +void CreateCloudSprites(void) +{ + u8 i; + void *ptr = AllocZeroed(0x400); + struct SpritePalette sprPal = {sDodrioBerryPlatformPal, 6}; + + LZ77UnCompWram(sDodrioBerryPlatformGfx, ptr); + if (ptr != NULL) // This should be one line up + { + struct SpriteSheet sprSheet = {ptr, 0x400, 5}; + struct SpriteTemplate sprTemplate = + { + .tileTag = 5, + .paletteTag = 6, + .oam = &sOamData_Cloud, + .anims = sAnims_Cloud, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_Cloud, + }; + + LoadSpriteSheet(&sprSheet); + LoadSpritePalette(&sprPal); + for (i = 0; i < 2; i++) + { + sCloudSpriteIds[i] = AllocZeroed(4); + *sCloudSpriteIds[i] = CreateSprite(&sprTemplate, sCloudStartCoords[i][0], sCloudStartCoords[i][1], 4); + } + } + + Free(ptr); +} + +void ResetCloudPos(void) +{ + u8 i; + for (i = 0; i < 2; i++) + { + struct Sprite *sprite = &gSprites[*sCloudSpriteIds[i]]; + sprite->sKeepPosX = TRUE; + sprite->x = sCloudStartCoords[i][0]; + sprite->y = sCloudStartCoords[i][1]; + } +} + +void StartCloudMovement(void) +{ + u8 i; + for (i = 0; i < 2; i++) + { + struct Sprite *sprite = &gSprites[*sCloudSpriteIds[i]]; + sprite->sKeepPosX = FALSE; + } +} + +void FreeCloudSprites(void) +{ + u8 i; + for (i = 0; i < 2; i++) + { + struct Sprite *sprite = &gSprites[*sCloudSpriteIds[i]]; + if (sprite) + DestroySprite(sprite); + FREE_AND_SET_NULL(sCloudSpriteIds[i]); + } +} + +void SetCloudInvisibility(bool8 invisible) +{ + u8 i; + for (i = 0; i < 2; i++) + gSprites[*sCloudSpriteIds[i]].invisible = invisible; +} + +#undef sKeepPosX + +static s16 GetDodrioXPos(u8 arg0, u8 arg1) +{ + s16 x = 0; + switch (arg1) + { + case 1: + x = 15; + break; + case 2: + switch (arg0) + { + case 0: x = 12; break; + case 1: x = 18; break; + } + break; + case 3: + switch (arg0) + { + case 0: x = 15; break; + case 1: x = 21; break; + case 2: x = 9; break; + } + break; + case 4: + switch (arg0) + { + case 0: x = 12; break; + case 1: x = 18; break; + case 2: x = 24; break; + case 3: x = 6; break; + } + break; + case 5: + switch (arg0) + { + case 0: x = 15; break; + case 1: x = 21; break; + case 2: x = 27; break; + case 3: x = 3; break; + case 4: x = 9; break; + } + break; + } + + return x * 8; +} + +void ResetBerryAndStatusBarSprites(void) +{ + u8 i; + for (i = 0; i < 11; i++) + { + SetBerryInvisibility(i, TRUE); + SetBerryYPos(i, 1); + } + SetStatusBarInvisibility(FALSE); +} + +static void LoadWindowFrameGfx(u8 frameId) +{ + LoadBgTiles(0, GetWindowFrameTilesPal(frameId)->tiles, 0x120, 1); + LoadPalette(GetWindowFrameTilesPal(frameId)->palette, 0xA0, 0x20); +} + +static void LoadUserWindowFrameGfx(void) +{ + TextWindow_SetStdFrame0_WithPal(0, 0xA, 0xB0); +} + +void ResetGfxState(void) +{ + sGfx->finished = FALSE; + sGfx->state = 0; + sGfx->unk3018 = 0; + sGfx->unk3020 = 0; + sGfx->unk3024 = 0; +} + +static void DrawYesNoMessageWindow(const struct WindowTemplate * winTempl) +{ + u8 pal = 0xA; + + FillBgTilemapBufferRect(0, 1, winTempl->tilemapLeft - 1, winTempl->tilemapTop - 1, 1, 1, pal); + FillBgTilemapBufferRect(0, 2, winTempl->tilemapLeft, winTempl->tilemapTop - 1, winTempl->width, 1, pal); + FillBgTilemapBufferRect(0, 3, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop - 1, 1, 1, pal); + FillBgTilemapBufferRect(0, 4, winTempl->tilemapLeft - 1, winTempl->tilemapTop, 1, winTempl->height, pal); + FillBgTilemapBufferRect(0, 6, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop, 1, winTempl->height, pal); + FillBgTilemapBufferRect(0, 7, winTempl->tilemapLeft - 1, winTempl->tilemapTop + winTempl->height, 1, 1, pal); + FillBgTilemapBufferRect(0, 8, winTempl->tilemapLeft, winTempl->tilemapTop + winTempl->height, winTempl->width, 1, pal); + FillBgTilemapBufferRect(0, 9, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop + winTempl->height, 1, 1, pal); +} + +static void DrawMessageWindow(const struct WindowTemplate * winTempl) +{ + u8 pal = 0xB; + + FillBgTilemapBufferRect(0, 10, winTempl->tilemapLeft - 1, winTempl->tilemapTop - 1, 1, 1, pal); + FillBgTilemapBufferRect(0, 11, winTempl->tilemapLeft, winTempl->tilemapTop - 1, winTempl->width, 1, pal); + FillBgTilemapBufferRect(0, 12, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop - 1, 1, 1, pal); + FillBgTilemapBufferRect(0, 13, winTempl->tilemapLeft - 1, winTempl->tilemapTop, 1, winTempl->height, pal); + FillBgTilemapBufferRect(0, 15, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop, 1, winTempl->height, pal); + FillBgTilemapBufferRect(0, 16, winTempl->tilemapLeft - 1, winTempl->tilemapTop + winTempl->height, 1, 1, pal); + FillBgTilemapBufferRect(0, 17, winTempl->tilemapLeft, winTempl->tilemapTop + winTempl->height, winTempl->width, 1, pal); + FillBgTilemapBufferRect(0, 18, winTempl->tilemapLeft + winTempl->width, winTempl->tilemapTop + winTempl->height, 1, 1, pal); +} + +void InitGameGfx(struct DodrioSubstruct_0160 * ptr) +{ + sGfx = ptr; + sGfx->finished = FALSE; + sGfx->state = 0; + sGfx->unk3018 = 0; + sGfx->unk3020 = 0; + sGfx->unk3024 = 0; + sGfx->unk3004 = CreateTask(Task_TryRunGfxFunc, 3); + SetGfxFunc(LoadGfx); +} + +static void FreeAllWindowBuffers_(void) +{ + FreeAllWindowBuffers(); +} + +struct WinCoords +{ + u8 left; + u8 top; +}; + +static const u8 sTextColorTable[][3] = +{ + { + TEXT_COLOR_WHITE, + TEXT_COLOR_DARK_GRAY, + TEXT_COLOR_LIGHT_GRAY + }, { + TEXT_COLOR_WHITE, + TEXT_COLOR_RED, + TEXT_COLOR_LIGHT_RED + }, { + TEXT_COLOR_WHITE, + TEXT_COLOR_BLUE, + TEXT_COLOR_LIGHT_BLUE + }, { + TEXT_COLOR_WHITE, + TEXT_COLOR_GREEN, + TEXT_COLOR_LIGHT_GREEN + } +}; + +static const struct WinCoords sNameWindowCoords_1Player[] = {{12, 6}}; +static const struct WinCoords sNameWindowCoords_2Players[] = {{9, 10}, {15, 6}}; +static const struct WinCoords sNameWindowCoords_3Players[] = {{12, 6}, {18, 10}, {6, 10}}; +static const struct WinCoords sNameWindowCoords_4Players[] = {{9, 10}, {15, 6}, {21, 10}, {3, 6}}; +static const struct WinCoords sNameWindowCoords_5Players[] = {{12, 6}, {18, 10}, {23, 6}, {1, 6}, {6, 10}}; + +static const struct WinCoords * const sNameWindowCoords[] = +{ + sNameWindowCoords_1Player, + sNameWindowCoords_2Players, + sNameWindowCoords_3Players, + sNameWindowCoords_4Players, + sNameWindowCoords_5Players, +}; + +static const u8 *const sRankingTexts[] = +{ + gText_1Colon, + gText_2Colon, + gText_3Colon, + gText_4Colon, + gText_5Colon, +}; + +static const u16 sResultsXCoords[] = {92, 132, 172, 212}; +static const u16 sResultsYCoords[] = {30, 45, 60, 75, 90}; +static const u16 sRankingYCoords[] = {12, 28, 44, 60, 76}; + +struct +{ + u8 id; + void (*func)(void); +} const sGfxFuncs[] = +{ + {0, LoadGfx}, + {1, ShowNames}, + {2, ShowResults}, + {3, Msg_WantToPlayAgain}, + {4, Msg_SavingDontTurnOff}, + {5, Msg_CommunicationStandby}, + {6, EraseMessage}, + {7, Msg_SomeoneDroppedOut}, + {8, StopGfxFuncs}, + {9, GfxIdle}, +}; + +void SetGfxFuncById(u8 arg0) +{ + u8 i; + for (i = 0; i < 10; i++) + { + if (sGfxFuncs[i].id == arg0) + SetGfxFunc(sGfxFuncs[i].func); + } +} + +static void Task_TryRunGfxFunc(u8 taskId) +{ + if (!sGfx->finished) + GetGfxFunc()(); +} + +static void LoadGfx(void) +{ + switch (sGfx->state) + { + case 0: + InitBgs(); + sGfx->state++; + break; + case 1: + if (LoadBgGfx() == TRUE) + sGfx->state++; + break; + case 2: + CopyToBgTilemapBuffer(3, sDodrioBerryBgTilemap1, 0, 0); + CopyToBgTilemapBuffer(1, sDodrioBerryBgTilemap2Left, 0, 0); + CopyToBgTilemapBuffer(2, sDodrioBerryBgTilemap2Right, 0, 0); + CopyBgTilemapBufferToVram(3); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + sGfx->state++; + break; + case 3: + ShowBg(0); + ShowBg(3); + ShowBg(1); + ShowBg(2); + sGfx->state++; + break; + case 4: + LoadWindowFrameGfx(gSaveBlock2Ptr->optionsWindowFrameType); + LoadUserWindowFrameGfx(); + sGfx->state++; + break; + default: + sGfx->finished = TRUE; + break; + } +} + +static void ShowNames(void) +{ + u8 i, playersCount, id, colorsId, *name; + u32 left; + struct WindowTemplate window; + const struct WinCoords * ptr; + + switch (sGfx->state) + { + case 0: + playersCount = GetNumPlayers(); + ptr = sNameWindowCoords[playersCount - 1]; + window.bg = 0; + window.width = 7; + window.height = 2; + window.paletteNum = 0xD; + window.baseBlock = 0x13; + for (i = 0; i < playersCount; ptr++, i++) + { + colorsId = 0; + id = GetPlayerIdByPos(i); + left = (56 - GetStringWidth(FONT_0, GetPlayerName(id), -1)) / 2u; + window.tilemapLeft = ptr->left; + window.tilemapTop = ptr->top; + sGfx->unk3008[i] = AddWindow(&window); + ClearWindowTilemap(sGfx->unk3008[i]); + FillWindowPixelBuffer(sGfx->unk3008[i], PIXEL_FILL(1)); + if (id == GetMultiplayerId()) + colorsId = 2; + name = GetPlayerName(id); + AddTextPrinterParameterized3(sGfx->unk3008[i], FONT_0, left, 1, sTextColorTable[colorsId], -1, name); + CopyWindowToVram(sGfx->unk3008[i], COPYWIN_GFX); + window.baseBlock += 0xE; + DrawMessageWindow(&window); + } + sGfx->state++; + break; + case 1: + if (!IsDma3ManagerBusyWithBgCopy()) + { + playersCount = GetNumPlayers(); + for (i = 0; i < playersCount; i++) + PutWindowTilemap(sGfx->unk3008[i]); + CopyBgTilemapBufferToVram(0); + sGfx->state++; + } + break; + default: + if (++sGfx->state > 180) + { + playersCount = GetNumPlayers(); + for (i = 0; i < playersCount; i++) + { + ClearWindowTilemap(sGfx->unk3008[i]); + RemoveWindow(sGfx->unk3008[i]); + } + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; + } + break; + } +} + +static void PrintRankedScores(u8 playersCount_) +{ + u8 i, r8 = 0, r6 = 0; + u8 playersCount = playersCount_; // Pointless variable, I know, but it's needed to match. + u8 *name; + u32 x, numWidth; + u8 numString[32]; + u8 array[5] = {0, 1, 2, 3, 4}; + struct DodrioSubstruct_3308 temp, structArray[5]; + + for (i = 0; i < playersCount; i++) + { + array[i] = i; + GetScoreResults(&temp, i); + structArray[i] = temp; + } + + if (GetHighestScore() != 0) + { + do + { + for (i = 0; i < playersCount; i++) + { + if (structArray[i].unk0 == r8) + { + array[r6] = i; + r6++; + } + } + r8 = r6; + } while (r6 < playersCount); + } + + for (i = 0; i < playersCount; i++) + { + if (structArray[i].unk4 == 0) + structArray[i].unk0 = playersCount - 1; + } + + x = 216 - GetStringWidth(FONT_0, gText_SpacePoints, 0); + for (i = 0; i < playersCount; i++) + { + u8 colorsId = 0; + u8 id = array[i]; + u32 points = structArray[id].unk4; + + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, sRankingTexts[structArray[id].unk0], 8, sRankingYCoords[i], -1, NULL); + if (id == GetMultiplayerId()) + colorsId = 2; + name = GetPlayerName(id); + AddTextPrinterParameterized3(sGfx->unk3008[1], FONT_0, 28, sRankingYCoords[i], sTextColorTable[colorsId], -1, name); + ConvertIntToDecimalStringN(numString, points, STR_CONV_MODE_RIGHT_ALIGN, 7); + numWidth = GetStringWidth(FONT_0, numString, -1); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, numString, x - 35, sRankingYCoords[i], -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, gText_SpacePoints, x, sRankingYCoords[i], -1, NULL); + } +} + +static void ShowResults(void) +{ + u8 i, j, itemGiveRet, playersCount = GetNumPlayers(); + u8 *name; + u32 strWidth, x; + u8 sp0C[100]; + u8 sp70[20]; + + switch (sGfx->state) + { + case 0: + SetScoreResults(); + sGfx->unk301C = 0; + sGfx->state++; + break; + case 1: + sGfx->unk3008[0] = AddWindow(&sWindowTemplates_Results[0]); + sGfx->unk3008[1] = AddWindow(&sWindowTemplates_Results[1]); + ClearWindowTilemap(sGfx->unk3008[0]); + ClearWindowTilemap(sGfx->unk3008[1]); + DrawMessageWindow(&sWindowTemplates_Results[0]); + DrawMessageWindow(&sWindowTemplates_Results[1]); + sGfx->state++; + break; + case 2: + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + FillWindowPixelBuffer(sGfx->unk3008[1], PIXEL_FILL(1)); + strWidth = GetStringWidth(FONT_0, gText_BerryPickingResults, -1); + x = (224 - strWidth) / 2; + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_0, gText_BerryPickingResults, x, 2, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, gText_10P30P50P50P, 68, 16, -1, NULL); + for (i = 0; i < playersCount; i++) + { + u8 colorsId = 0; + if (i == GetMultiplayerId()) + colorsId = 2; + + name = GetPlayerName(i); + AddTextPrinterParameterized3(sGfx->unk3008[1], FONT_0, 2, sResultsYCoords[i], sTextColorTable[colorsId], -1, name); + for (j = 0; j < 4; j++) + { + u32 width; + u16 result1 = Min(GetBerryResult(i, j), 9999); + u16 result2 = Min(GetHighestBerryResult(j), 9999); + + ConvertIntToDecimalStringN(sp0C, result1, STR_CONV_MODE_LEFT_ALIGN, 4); + width = GetStringWidth(FONT_0, sp0C, -1); + if (result2 == result1 && result2 != 0) + AddTextPrinterParameterized3(sGfx->unk3008[1], FONT_0, sResultsXCoords[j] - width, sResultsYCoords[i], sTextColorTable[1], -1, sp0C); + else + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, sp0C, sResultsXCoords[j] - width, sResultsYCoords[i], -1, NULL); + } + } + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + CopyWindowToVram(sGfx->unk3008[1], COPYWIN_GFX); + sGfx->state++; + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + { + PutWindowTilemap(sGfx->unk3008[0]); + PutWindowTilemap(sGfx->unk3008[1]); + } + CopyBgTilemapBufferToVram(0); + SetBerryIconsInvisibility(FALSE); + sGfx->state++; + break; + case 4: + if (++sGfx->unk301C >= 30 && JOY_NEW(A_BUTTON)) + { + sGfx->unk301C = 0; + PlaySE(SE_SELECT); + SetBerryIconsInvisibility(TRUE); + sGfx->state++; + } + break; + case 5: + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + FillWindowPixelBuffer(sGfx->unk3008[1], PIXEL_FILL(1)); + strWidth = GetStringWidth(FONT_0, gText_AnnouncingRankings, -1); + x = (224 - strWidth) / 2; + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_0, gText_AnnouncingRankings, x, 2, -1, NULL); + sGfx->state++; + break; + case 6: + PrintRankedScores(playersCount); + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + CopyWindowToVram(sGfx->unk3008[1], COPYWIN_GFX); + sGfx->state++; + break; + case 7: + if (!IsDma3ManagerBusyWithBgCopy()) + { + PutWindowTilemap(sGfx->unk3008[0]); + PutWindowTilemap(sGfx->unk3008[1]); + } + CopyBgTilemapBufferToVram(0); + sGfx->state++; + break; + case 8: + if (++sGfx->unk301C >= 30 && JOY_NEW(A_BUTTON)) + { + sGfx->unk301C = 0; + PlaySE(SE_SELECT); + if (GetHighestScore() < 3000) + { + sGfx->state = 127; + } + else + { + StopMapMusic(); + sGfx->state++; + } + + FillBgTilemapBufferRect_Palette0(0, 0, 0, 5, 30, 15); + RemoveWindow(sGfx->unk3008[1]); + sGfx->unk3008[1] = AddWindow(&sWindowTemplate_Prize); + ClearWindowTilemap(sGfx->unk3008[1]); + DrawMessageWindow(&sWindowTemplate_Prize); + } + break; + case 9: + PlayNewMapMusic(MUS_LEVEL_UP); + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + FillWindowPixelBuffer(sGfx->unk3008[1], PIXEL_FILL(1)); + strWidth = GetStringWidth(FONT_0, gText_AnnouncingPrizes, -1); + x = (224 - strWidth) / 2; + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_0, gText_AnnouncingPrizes, x, 2, -1, NULL); + DynamicPlaceholderTextUtil_Reset(); + CopyItemName(GetPrizeItemId(), sp70); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sp70); + DynamicPlaceholderTextUtil_ExpandPlaceholders(sp0C, gText_FirstPlacePrize); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, sp0C, 8, 2, -1, NULL); + itemGiveRet = TryGivePrize(); + if (itemGiveRet != 0 && itemGiveRet != 3) + { + DynamicPlaceholderTextUtil_Reset(); + CopyItemName(GetPrizeItemId(), sp70); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sp70); + if (itemGiveRet == 2) + DynamicPlaceholderTextUtil_ExpandPlaceholders(sp0C, gText_CantHoldAnyMore); + else if (itemGiveRet == 1) + DynamicPlaceholderTextUtil_ExpandPlaceholders(sp0C, gText_FilledStorageSpace); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_0, sp0C, 8, 40, -1, NULL); + } + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + CopyWindowToVram(sGfx->unk3008[1], COPYWIN_GFX); + sGfx->state++; + break; + case 10: + if (!IsDma3ManagerBusyWithBgCopy()) + { + PutWindowTilemap(sGfx->unk3008[0]); + PutWindowTilemap(sGfx->unk3008[1]); + } + CopyBgTilemapBufferToVram(0); + FadeOutAndFadeInNewMapMusic(MUS_VICTORY_WILD, 20, 10); + sGfx->state++; + break; + case 11: + if (++sGfx->unk301C >= 30 && JOY_NEW(A_BUTTON)) + { + sGfx->unk301C = 0; + PlaySE(SE_SELECT); + sGfx->state++; + } + break; + default: + ClearWindowTilemap(sGfx->unk3008[0]); + ClearWindowTilemap(sGfx->unk3008[1]); + RemoveWindow(sGfx->unk3008[0]); + RemoveWindow(sGfx->unk3008[1]); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; + break; + } +} + +static void Msg_WantToPlayAgain(void) +{ + u8 y; + + switch (sGfx->state) + { + case 0: + sGfx->unk3008[0] = AddWindow(&sWindowTemplates_PlayAgain[0]); + sGfx->unk3008[1] = AddWindow(&sWindowTemplates_PlayAgain[1]); + ClearWindowTilemap(sGfx->unk3008[0]); + ClearWindowTilemap(sGfx->unk3008[1]); + DrawMessageWindow(&sWindowTemplates_PlayAgain[0]); + DrawYesNoMessageWindow(&sWindowTemplates_PlayAgain[1]); + sGfx->state++; + sGfx->unk3020 = 0; + sGfx->unk3024 = 0; + break; + case 1: + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + FillWindowPixelBuffer(sGfx->unk3008[1], PIXEL_FILL(1)); + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_2, gText_WantToPlayAgain, 0, 6, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_Yes, 8, 2, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_No, 8, 16, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_SelectorArrow2, 0, 2, -1, NULL); + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + CopyWindowToVram(sGfx->unk3008[1], COPYWIN_GFX); + sGfx->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + { + PutWindowTilemap(sGfx->unk3008[0]); + PutWindowTilemap(sGfx->unk3008[1]); + } + CopyBgTilemapBufferToVram(0); + sGfx->state++; + break; + case 3: + y = sGfx->unk3020; + if (y == 0) + y = 1; + FillWindowPixelBuffer(sGfx->unk3008[1], PIXEL_FILL(1)); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_Yes, 8, 2, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_No, 8, 16, -1, NULL); + AddTextPrinterParameterized(sGfx->unk3008[1], FONT_2, gText_SelectorArrow2, 0, y == 1 ? 2 : 16, -1, NULL); + CopyWindowToVram(sGfx->unk3008[1], COPYWIN_FULL); + // Increment state only if A or B button have been pressed. + if (JOY_NEW(A_BUTTON)) + { + PlaySE(SE_SELECT); + if (sGfx->unk3020 == 0) + sGfx->unk3020 = 1; + sGfx->state++; + } + else if (JOY_NEW(DPAD_UP | DPAD_DOWN)) + { + PlaySE(SE_SELECT); + switch (sGfx->unk3020) + { + case 0: + sGfx->unk3020 = 2; + break; + case 1: + sGfx->unk3020 = 2; + break; + case 2: + sGfx->unk3020 = 1; + break; + } + } + else if (JOY_NEW(B_BUTTON)) + { + PlaySE(SE_SELECT); + sGfx->unk3020 = 2; + sGfx->state++; + } + break; + default: + sGfx->unk3024 = sGfx->unk3020; + ClearWindowTilemap(sGfx->unk3008[0]); + ClearWindowTilemap(sGfx->unk3008[1]); + RemoveWindow(sGfx->unk3008[0]); + RemoveWindow(sGfx->unk3008[1]); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; + break; + } +} + +static void Msg_SavingDontTurnOff(void) +{ + switch (sGfx->state) + { + case 0: + DrawDialogueFrame(0, FALSE); + AddTextPrinterParameterized2(0, FONT_2, gText_SavingDontTurnOffThePower2, 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); + sGfx->state++; + break; + case 1: + CopyWindowToVram(0, COPYWIN_FULL); + sGfx->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + { + CreateTask(Task_LinkFullSave, 0); + sGfx->state++; + } + break; + case 3: + if (!FuncIsActiveTask(Task_LinkFullSave)) + sGfx->state++; + break; + default: + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; + break; + } +} + +static void Msg_CommunicationStandby(void) +{ + switch (sGfx->state) + { + case 0: + sGfx->unk3008[0] = AddWindow(&sWindowTemplate_CommStandby); + ClearWindowTilemap(sGfx->unk3008[0]); + DrawMessageWindow(&sWindowTemplate_CommStandby); + sGfx->state++; + break; + case 1: + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_2, gText_CommunicationStandby3, 0, 6, -1, NULL); + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + sGfx->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + PutWindowTilemap(sGfx->unk3008[0]); + CopyBgTilemapBufferToVram(0); + sGfx->state++; + break; + default: + sGfx->finished = TRUE; + break; + } +} + +static void EraseMessage(void) +{ + ClearWindowTilemap(sGfx->unk3008[0]); + RemoveWindow(sGfx->unk3008[0]); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; +} + +static void Msg_SomeoneDroppedOut(void) +{ + switch (sGfx->state) + { + case 0: + sGfx->unk3008[0] = AddWindow(&sWindowTemplate_DroppedOut); + ClearWindowTilemap(sGfx->unk3008[0]); + DrawMessageWindow(&sWindowTemplate_DroppedOut); + sGfx->state++; + sGfx->unk301C = 0; + sGfx->unk3020 = 0; + sGfx->unk3024 = 0; + break; + case 1: + FillWindowPixelBuffer(sGfx->unk3008[0], PIXEL_FILL(1)); + AddTextPrinterParameterized(sGfx->unk3008[0], FONT_2, gText_SomeoneDroppedOut, 0, 6, TEXT_SKIP_DRAW, NULL); + CopyWindowToVram(sGfx->unk3008[0], COPYWIN_GFX); + sGfx->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + PutWindowTilemap(sGfx->unk3008[0]); + CopyBgTilemapBufferToVram(0); + sGfx->state++; + break; + case 3: + if (++sGfx->unk301C >= 120) + sGfx->state++; + break; + default: + sGfx->unk3024 = 5; + ClearWindowTilemap(sGfx->unk3008[0]); + RemoveWindow(sGfx->unk3008[0]); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + CopyBgTilemapBufferToVram(0); + sGfx->finished = TRUE; + break; + } +} + +static void StopGfxFuncs(void) +{ + DestroyTask(sGfx->unk3004); + sGfx->finished = TRUE; +} + +static void GfxIdle(void) +{ + +} + +static void SetGfxFunc(void (*func)(void)) +{ + sGfx->state = 0; + sGfx->finished = FALSE; + sGfx->unk3028 = func; +} + +void (*GetGfxFunc(void))(void) +{ + return sGfx->unk3028; +} + +bool32 IsGfxFuncActive(void) +{ + if (sGfx->finished == TRUE) + return FALSE; + else + return TRUE; +} + +u8 GetPlayAgainState(void) +{ + return sGfx->unk3024; +} + +static void InitBgs(void) +{ + DmaClearLarge16(3, (void *)VRAM, VRAM_SIZE, 0x1000); + DmaClear32(3,(void *)OAM, OAM_SIZE); + DmaClear16(3, (void *)PLTT, PLTT_SIZE); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + ResetBgsAndClearDma3BusyFlags(FALSE); + InitBgsFromTemplates(0, sBgTemplates, NELEMS(sBgTemplates)); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); + InitStandardTextBoxWindows(); + InitTextBoxGfxAndPrinters(); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + SetBgTilemapBuffer(3, sGfx->tilemapBuffers[0]); + SetBgTilemapBuffer(1, sGfx->tilemapBuffers[1]); + SetBgTilemapBuffer(2, sGfx->tilemapBuffers[2]); +} + +static bool32 LoadBgGfx(void) +{ + switch (sGfx->unk3018) + { + case 0: + LoadPalette(sDodrioBerryBgPal1, 0, sizeof(sDodrioBerryBgPal1)); + break; + case 1: + ResetTempTileDataBuffers(); + break; + case 2: + DecompressAndCopyTileDataToVram(3, sDodrioBerryBgGfx1, 0, 0, 0); + break; + case 3: + DecompressAndCopyTileDataToVram(1, sDodrioBerryBgGfx2, 0, 0, 0); + break; + case 4: + if (FreeTempTileDataBuffersIfPossible() == TRUE) + return FALSE; + break; + case 5: + LoadPalette(stdpal_get(3), 0xD0, 0x20); + break; + default: + sGfx->unk3018 = 0; + return TRUE; + } + + sGfx->unk3018++; + return FALSE; +} diff --git a/src/dodrio_berry_picking_2.c b/src/dodrio_berry_picking_2.c index 74d5fcacd..3888b1895 100644 --- a/src/dodrio_berry_picking_2.c +++ b/src/dodrio_berry_picking_2.c @@ -12,7 +12,7 @@ #include "text_window.h" #include "text_window_graphics.h" #include "constants/songs.h" - +/* struct DodrioStruct_2022CF4 { u8 filler_00[0xc]; @@ -1614,4 +1614,4 @@ static bool32 sub_8155FE0(void) gUnknown_203F440->unk3018++; return FALSE; -} +}*/ diff --git a/sym_ewram.txt b/sym_ewram.txt index 9fe766a2b..719497748 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -132,7 +132,6 @@ .include "src/pokemon_jump.o" .include "src/berry_crush.o" .include "src/dodrio_berry_picking.o" - .include "src/dodrio_berry_picking_2.o" .include "src/teachy_tv.o" .include "src/digit_obj_util.o" .include "src/trainer_tower.o"