From bafbf9240d0f91ee3c38ca4652e3c54b9c503c9b Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Sat, 26 Dec 2020 17:47:36 -0800 Subject: Add UBFIX for null deref in sub_80D08CC --- src/pokemon_storage_system.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index db8f3d2bb..4be1cf729 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8408,8 +8408,13 @@ static void sub_80D08CC(void) for (j = sMoveMonsPtr->minRow; j < rowCount; j++) { struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); - + // UB: possible null dereference +#ifdef UBFIX + if (boxMon != NULL) + sMoveMonsPtr->boxMons[monArrayId] = *boxMon; +#else sMoveMonsPtr->boxMons[monArrayId] = *boxMon; +#endif monArrayId++; boxPosition++; } -- cgit v1.2.3 From b65980cd4ea7e1a8052a0d2c5cb6edd73d35b89c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 19 Jan 2021 17:50:52 -0500 Subject: Remove unused local variables and functions --- src/pokemon_storage_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 4be1cf729..50fc04372 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8389,7 +8389,7 @@ static u8 sub_80D0894(void) static void sub_80D08CC(void) { - s32 i, j, r8, r9; + s32 i, j; s32 rowCount, columnCount; u8 boxId; u8 monArrayId; -- cgit v1.2.3 From 2e51a69400e6d2943903508f2ca09812ed4c0fb1 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 5 Feb 2021 04:59:26 -0300 Subject: newCurosrArea -> newCursorArea --- src/pokemon_storage_system.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 50fc04372..eaa9416cf 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -5898,12 +5898,12 @@ static bool8 sub_80CD554(void) return TRUE; } -static void sub_80CD6AC(u8 newCurosrArea, u8 newCursorPosition) +static void sub_80CD6AC(u8 newCursorArea, u8 newCursorPosition) { u16 x, y; - sub_80CD444(newCurosrArea, newCursorPosition, &x, &y); - sPSSData->field_CD4 = newCurosrArea; + sub_80CD444(newCursorArea, newCursorPosition, &x, &y); + sPSSData->field_CD4 = newCursorArea; sPSSData->field_CD5 = newCursorPosition; sPSSData->field_CCC = x; sPSSData->field_CCE = y; @@ -5955,9 +5955,9 @@ static void sub_80CD70C(void) sPSSData->field_CC0 = sPSSData->field_CB4->pos1.y << 8; } -static void sub_80CD894(u8 newCurosrArea, u8 newCursorPosition) +static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) { - sub_80CD6AC(newCurosrArea, newCursorPosition); + sub_80CD6AC(newCursorArea, newCursorPosition); sub_80CD70C(); if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) { @@ -5977,19 +5977,19 @@ static void sub_80CD894(u8 newCurosrArea, u8 newCursorPosition) else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) sub_80D0E50(CURSOR_AREA_IN_PARTY, sBoxCursorPosition); - if (newCurosrArea == CURSOR_AREA_IN_BOX) - sub_80D0D8C(newCurosrArea, newCursorPosition); - else if (newCurosrArea == CURSOR_AREA_IN_PARTY) - sub_80D0D8C(newCurosrArea, newCursorPosition); + if (newCursorArea == CURSOR_AREA_IN_BOX) + sub_80D0D8C(newCursorArea, newCursorPosition); + else if (newCursorArea == CURSOR_AREA_IN_PARTY) + sub_80D0D8C(newCursorArea, newCursorPosition); } - if (newCurosrArea == CURSOR_AREA_IN_PARTY && sBoxCursorArea != CURSOR_AREA_IN_PARTY) + if (newCursorArea == CURSOR_AREA_IN_PARTY && sBoxCursorArea != CURSOR_AREA_IN_PARTY) { - sPSSData->field_CD6 = newCurosrArea; + sPSSData->field_CD6 = newCursorArea; sPSSData->field_CB8->invisible = TRUE; } - switch (newCurosrArea) + switch (newCursorArea) { case CURSOR_AREA_IN_PARTY: case CURSOR_AREA_BOX: -- cgit v1.2.3 From b71b10623b31065a9a29b43938cf602087bcfc73 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 24 Feb 2021 11:01:02 -0500 Subject: Add palette selection constants --- src/pokemon_storage_system.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index eaa9416cf..a542d222c 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -2336,12 +2336,12 @@ static void Cb_InitPSS(u8 taskId) SetMonIconTransparency(); if (!sPSSData->isReshowingPSS) { - BlendPalettes(0xFFFFFFFF, 0x10, RGB_BLACK); + BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); SetPSSCallback(Cb_ShowPSS); } else { - BlendPalettes(0xFFFFFFFF, 0x10, RGB_BLACK); + BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); SetPSSCallback(Cb_ReshowPSS); } SetVBlankCallback(VblankCb_PSS); @@ -2374,7 +2374,7 @@ static void Cb_ReshowPSS(u8 taskId) switch (sPSSData->state) { case 0: - BeginNormalPaletteFade(0xFFFFFFFF, -1, 0x10, 0, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, -1, 0x10, 0, RGB_BLACK); sPSSData->state++; break; case 1: @@ -3681,7 +3681,7 @@ static void Cb_NameBox(u8 taskId) { case 0: sub_80CE760(); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sPSSData->state++; break; case 1: @@ -3701,7 +3701,7 @@ static void Cb_ShowMonSummary(u8 taskId) { case 0: sub_80CE7E8(); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sPSSData->state++; break; case 1: @@ -3720,7 +3720,7 @@ static void Cb_GiveItemFromBag(u8 taskId) switch (sPSSData->state) { case 0: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sPSSData->state++; break; case 1: -- cgit v1.2.3 From 031da44cab0d99210aff87533333d59a71a0b85f Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 28 Feb 2021 17:22:26 -0500 Subject: Document mon markings --- src/pokemon_storage_system.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index a542d222c..c004c8cce 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -2323,8 +2323,8 @@ static void Cb_InitPSS(u8 taskId) { sPSSData->markMenu.baseTileTag = TAG_TILE_D; sPSSData->markMenu.basePaletteTag = TAG_PAL_DACE; - sub_811F90C(&sPSSData->markMenu); - sub_811FA90(); + InitMonMarkingsMenu(&sPSSData->markMenu); + BufferMonMarkingsMenuTiles(); } else { @@ -3179,13 +3179,13 @@ static void Cb_ShowMarkMenu(u8 taskId) case 0: PrintStorageActionText(PC_TEXT_MARK_POKE); sPSSData->markMenu.markings = sPSSData->cursorMonMarkings; - sub_811FAA4(sPSSData->cursorMonMarkings, 0xb0, 0x10); + OpenMonMarkingsMenu(sPSSData->cursorMonMarkings, 0xb0, 0x10); sPSSData->state++; break; case 1: - if (!MonMarkingsMenuHandleInput()) + if (!HandleMonMarkingsMenuInput()) { - sub_811FAF8(); + FreeMonMarkingsMenu(); ClearBottomWindow(); SetMonMarkings(sPSSData->markMenu.markings); RefreshCursorMonData(); @@ -3983,7 +3983,7 @@ static void sub_80CA0D8(void) static void sub_80CA154(void) { - sPSSData->field_D94 = sub_811FFB4(TAG_TILE_10, TAG_PAL_DAC8, NULL); + sPSSData->field_D94 = CreateMonMarkingComboSprite(TAG_TILE_10, TAG_PAL_DAC8, NULL); sPSSData->field_D94->oam.priority = 1; sPSSData->field_D94->subpriority = 1; sPSSData->field_D94->pos1.x = 40; @@ -4126,7 +4126,7 @@ static void PrintCursorMonInfo(void) CopyWindowToVram(0, 2); if (sPSSData->cursorMonSpecies != SPECIES_NONE) { - sub_8120084(sPSSData->cursorMonMarkings, sPSSData->field_DA0); + UpdateMonMarkingTiles(sPSSData->cursorMonMarkings, sPSSData->field_DA0); sPSSData->field_D94->invisible = FALSE; } else -- cgit v1.2.3 From 91ab30fa71dfe800215e9e7b3309f366ccc6173e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 28 Feb 2021 17:42:11 -0500 Subject: Rename mon markings struct --- src/pokemon_storage_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index c004c8cce..3d6dc331c 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -231,7 +231,7 @@ struct PokemonStorageSystemData struct Sprite *field_D94; struct Sprite *field_D98[2]; u16 *field_DA0; - struct PokemonMarkMenu markMenu; + struct MonMarkingsMenu markMenu; struct UnkPSSStruct_2002370 field_1E5C; struct Pokemon movingMon; struct Pokemon field_2108; -- cgit v1.2.3 From 62968895ca220cf5b6f7c066e9061cf45fe7913e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 29 Mar 2021 09:38:19 -0400 Subject: Add MON_PIC_SIZE constant --- src/pokemon_storage_system.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 3d6dc331c..d249381d8 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -4049,11 +4049,11 @@ static void LoadCursorMonSprite(void) u16 tileStart; u8 palSlot; u8 spriteId; - struct SpriteSheet sheet = {sPSSData->field_22C4, 0x800, TAG_TILE_2}; + struct SpriteSheet sheet = {sPSSData->field_22C4, MON_PIC_SIZE, TAG_TILE_2}; struct SpritePalette palette = {sPSSData->field_2244, TAG_PAL_DAC6}; struct SpriteTemplate template = sSpriteTemplate_CursorMon; - for (i = 0; i < 0x800; i++) + for (i = 0; i < MON_PIC_SIZE; i++) sPSSData->field_22C4[i] = 0; for (i = 0; i < 0x10; i++) sPSSData->field_2244[i] = 0; @@ -4095,7 +4095,7 @@ static void LoadCursorMonGfx(u16 species, u32 pid) { LoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->field_22C4, species, pid, TRUE); LZ77UnCompWram(sPSSData->cursorMonPalette, sPSSData->field_2244); - CpuCopy32(sPSSData->field_22C4, sPSSData->field_223C, 0x800); + CpuCopy32(sPSSData->field_22C4, sPSSData->field_223C, MON_PIC_SIZE); LoadPalette(sPSSData->field_2244, sPSSData->field_223A, 0x20); sPSSData->cursorMonSprite->invisible = FALSE; } -- cgit v1.2.3 From 3e725272fc8b8f2ea825783771d54104d1f25e82 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Fri, 9 Apr 2021 22:39:34 -0400 Subject: standardize "grey" to "gray" --- src/pokemon_storage_system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index d249381d8..0a35aa323 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -6884,18 +6884,18 @@ static void SetCursorMonData(void *pokemon, u8 mode) *(txtPtr)++ = CHAR_FEMALE; break; default: - *(txtPtr)++ = TEXT_COLOR_DARK_GREY; + *(txtPtr)++ = TEXT_COLOR_DARK_GRAY; *(txtPtr)++ = TEXT_COLOR_WHITE; - *(txtPtr)++ = TEXT_COLOR_LIGHT_GREY; + *(txtPtr)++ = TEXT_COLOR_LIGHT_GRAY; *(txtPtr)++ = CHAR_UNK_SPACER; break; } *(txtPtr++) = EXT_CTRL_CODE_BEGIN; *(txtPtr++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - *(txtPtr++) = TEXT_COLOR_DARK_GREY; + *(txtPtr++) = TEXT_COLOR_DARK_GRAY; *(txtPtr++) = TEXT_COLOR_WHITE; - *(txtPtr++) = TEXT_COLOR_LIGHT_GREY; + *(txtPtr++) = TEXT_COLOR_LIGHT_GRAY; *(txtPtr++) = CHAR_SPACE; *(txtPtr++) = CHAR_EXTRA_SYMBOL; *(txtPtr++) = CHAR_LV_2; -- cgit v1.2.3 From 62abcecc54ac810dc082e5e822be4796a5064ece Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 02:04:01 -0400 Subject: More usage of DISPLAY constants --- src/pokemon_storage_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 0a35aa323..d3ec36c9e 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -4836,7 +4836,7 @@ static void CreatePartyMonsSprites(bool8 arg0) { for (i = 0; i < count; i++) { - sPSSData->partySprites[i]->pos1.y -= 160; + sPSSData->partySprites[i]->pos1.y -= DISPLAY_HEIGHT; sPSSData->partySprites[i]->invisible = TRUE; } } -- cgit v1.2.3 From 30fecca109e77cd3f7b85600ee6ba984878b2d03 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 13:31:18 -0400 Subject: Doc storage - menu texts --- src/pokemon_storage_system.c | 816 +++++++++++++++++++++++-------------------- 1 file changed, 428 insertions(+), 388 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 0a35aa323..99f16e43b 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -42,6 +42,186 @@ #include "constants/rgb.h" #include "constants/songs.h" +enum { + BOX_OPTION_WITHDRAW, + BOX_OPTION_DEPOSIT, + BOX_OPTION_MOVE_MONS, + BOX_OPTION_MOVE_ITEMS, + BOX_OPTION_EXIT, +}; + +// IDs for messages to print with PrintMessage +enum { + MSG_EXIT_BOX, + MSG_WHAT_YOU_DO, + MSG_PICK_A_THEME, + MSG_PICK_A_WALLPAPER, + MSG_IS_SELECTED, + MSG_JUMP_TO_WHICH_BOX, + MSG_DEPOSIT_IN_WHICH_BOX, + MSG_WAS_DEPOSITED, + MSG_BOX_IS_FULL, + MSG_RELEASE_POKE, + MSG_WAS_RELEASED, + MSG_BYE_BYE, + MSG_MARK_POKE, + MSG_LAST_POKE, + MSG_PARTY_FULL, + MSG_HOLDING_POKE, + MSG_WHICH_ONE_WILL_TAKE, + MSG_CANT_RELEASE_EGG, + MSG_CONTINUE_BOX, + MSG_CAME_BACK, + MSG_WORRIED, + MSG_SURPRISE, + MSG_PLEASE_REMOVE_MAIL, + MSG_IS_SELECTED2, + MSG_GIVE_TO_MON, + MSG_PLACED_IN_BAG, + MSG_BAG_FULL, + MSG_PUT_IN_BAG, + MSG_ITEM_IS_HELD, + MSG_CHANGED_TO_ITEM, + MSG_CANT_STORE_MAIL, +}; + +enum { + MSG_FORMAT_NORMAL, + MSG_FORMAT_MON_NAME_1, + MSG_FORMAT_MON_NAME_2, // Unused + MSG_FORMAT_MON_NAME_3, // Unused + MSG_FORMAT_MON_NAME_4, + MSG_FORMAT_MON_NAME_5, // Unused + MSG_FORMAT_MON_NAME_6, + MSG_FORMAT_ITEM_NAME, +}; + +// IDs for menu selection items. See SetMenuText, HandleMenuInput, etc +enum { + MENU_CANCEL, + MENU_STORE, + MENU_WITHDRAW, + MENU_MOVE, + MENU_SHIFT, + MENU_PLACE, + MENU_SUMMARY, + MENU_RELEASE, + MENU_MARK, + MENU_JUMP, + MENU_WALLPAPER, + MENU_NAME, + MENU_TAKE, + MENU_GIVE, + MENU_GIVE_2, + MENU_SWITCH, + MENU_BAG, + MENU_INFO, + MENU_SCENERY_1, + MENU_SCENERY_2, + MENU_SCENERY_3, + MENU_ETCETERA, + MENU_FRIENDS, + MENU_FOREST, + MENU_CITY, + MENU_DESERT, + MENU_SAVANNA, + MENU_CRAG, + MENU_VOLCANO, + MENU_SNOW, + MENU_CAVE, + MENU_BEACH, + MENU_SEAFLOOR, + MENU_RIVER, + MENU_SKY, + MENU_POLKADOT, + MENU_POKECENTER, + MENU_MACHINE, + MENU_SIMPLE, +}; +#define MENU_WALLPAPERS_START MENU_FOREST + +enum { + SCREEN_CHANGE_EXIT_BOX, + SCREEN_CHANGE_SUMMARY_SCREEN, + SCREEN_CHANGE_NAME_BOX, + SCREEN_CHANGE_ITEM_FROM_BAG, +}; + +enum { + MODE_PARTY, + MODE_BOX, + MODE_MOVE, +}; + +enum { + WALLPAPER_FOREST, + WALLPAPER_CITY, + WALLPAPER_DESERT, + WALLPAPER_SAVANNA, + WALLPAPER_CRAG, + WALLPAPER_VOLCANO, + WALLPAPER_SNOW, + WALLPAPER_CAVE, + WALLPAPER_BEACH, + WALLPAPER_SEAFLOOR, + WALLPAPER_RIVER, + WALLPAPER_SKY, + WALLPAPER_POLKADOT, + WALLPAPER_POKECENTER, + WALLPAPER_MACHINE, + WALLPAPER_PLAIN, + WALLPAPER_FRIENDS, // The one received as a gift from Walda's parents. + WALLPAPER_COUNT +}; + +enum { + FRIENDS_ZIGZAGOON, + FRIENDS_SCREEN, + FRIENDS_HORIZONTAL, + FRIENDS_DIAGONAL, + FRIENDS_BLOCK, + FRIENDS_RIBBON, + FRIENDS_POKECENTER2, + FRIENDS_FRAME, + FRIENDS_BLANK, + FRIENDS_CIRCLES, + FRIENDS_AZUMARILL, + FRIENDS_PIKACHU, + FRIENDS_LEGENDARY, + FRIENDS_DUSCLOPS, + FRIENDS_LUDICOLO, + FRIENDS_WHISCASH, + FRIENDS_WALLPAPERS_COUNT +}; + +enum { + CURSOR_AREA_IN_BOX, + CURSOR_AREA_IN_PARTY, + CURSOR_AREA_BOX, + CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box +}; + +#define TAG_PAL_WAVEFORM 0xDACA +#define TAG_PAL_DAC8 0xDAC8 +#define TAG_PAL_DAC6 0xDAC6 +#define TAG_PAL_DACE 0xDACE +#define TAG_PAL_DAC7 0xDAC7 +#define TAG_PAL_DAC9 0xDAC9 +#define TAG_PAL_DAC0 0xDAC0 +#define TAG_PAL_DACB 0xDACB + +#define TAG_TILE_WAVEFORM 0x5 +#define TAG_TILE_10 0x10 +#define TAG_TILE_2 0x2 +#define TAG_TILE_D 0xD +#define TAG_TILE_A 0xA +#define TAG_TILE_3 0x3 +#define TAG_TILE_4 0x4 +#define TAG_TILE_12 0x12 +#define TAG_TILE_7 0x7 +#define TAG_TILE_0 0x0 +#define TAG_TILE_1 0x1 + struct WallpaperTable { const u32 *tiles; @@ -55,7 +235,7 @@ struct PokemonStorageSystemFunc s8 unk4; }; -struct StorageAction +struct StorageMessage { const u8 *text; u8 format; @@ -194,7 +374,7 @@ struct PokemonStorageSystemData u8 menuItemsCount; u8 menuWidth; u8 field_CAE; // Written to, but never read. - u16 field_CB0; + u16 menuWindowId; struct Sprite *field_CB4; struct Sprite *field_CB8; s32 field_CBC; @@ -299,149 +479,6 @@ struct UnkStruct_2039D84 u8 field_2D; }; -enum -{ - BOX_OPTION_WITHDRAW, - BOX_OPTION_DEPOSIT, - BOX_OPTION_MOVE_MONS, - BOX_OPTION_MOVE_ITEMS, - BOX_OPTION_EXIT, -}; - -enum -{ - PC_TEXT_EXIT_BOX, - PC_TEXT_WHAT_YOU_DO, - PC_TEXT_PICK_A_THEME, - PC_TEXT_PICK_A_WALLPAPER, - PC_TEXT_IS_SELECTED, - PC_TEXT_JUMP_TO_WHICH_BOX, - PC_TEXT_DEPOSIT_IN_WHICH_BOX, - PC_TEXT_WAS_DEPOSITED, - PC_TEXT_BOX_IS_FULL, - PC_TEXT_RELEASE_POKE, - PC_TEXT_WAS_RELEASED, - PC_TEXT_BYE_BYE, - PC_TEXT_MARK_POKE, - PC_TEXT_LAST_POKE, - PC_TEXT_PARTY_FULL, - PC_TEXT_HOLDING_POKE, - PC_TEXT_WHICH_ONE_WILL_TAKE, - PC_TEXT_CANT_RELEASE_EGG, - PC_TEXT_CONTINUE_BOX, - PC_TEXT_CAME_BACK, - PC_TEXT_WORRIED, - PC_TEXT_SURPRISE, - PC_TEXT_PLEASE_REMOVE_MAIL, - PC_TEXT_IS_SELECTED2, - PC_TEXT_GIVE_TO_MON, - PC_TEXT_PLACED_IN_BAG, - PC_TEXT_BAG_FULL, - PC_TEXT_PUT_IN_BAG, - PC_TEXT_ITEM_IS_HELD, - PC_TEXT_CHANGED_TO_ITEM, - PC_TEXT_CANT_STORE_MAIL, -}; - -enum -{ - PC_TEXT_FMT_NORMAL, - PC_TEXT_FMT_MON_NAME_1, - PC_TEXT_FMT_MON_NAME_2, - PC_TEXT_FMT_MON_NAME_3, - PC_TEXT_FMT_MON_NAME_4, - PC_TEXT_FMT_MON_NAME_5, - PC_TEXT_FMT_MON_NAME_6, - PC_TEXT_FMT_ITEM_NAME, -}; - -enum -{ - SCREEN_CHANGE_EXIT_BOX, - SCREEN_CHANGE_SUMMARY_SCREEN, - SCREEN_CHANGE_NAME_BOX, - SCREEN_CHANGE_ITEM_FROM_BAG, -}; - -enum -{ - MODE_PARTY, - MODE_BOX, - MODE_MOVE, -}; - -enum -{ - WALLPAPER_FOREST, - WALLPAPER_CITY, - WALLPAPER_DESERT, - WALLPAPER_SAVANNA, - WALLPAPER_CRAG, - WALLPAPER_VOLCANO, - WALLPAPER_SNOW, - WALLPAPER_CAVE, - WALLPAPER_BEACH, - WALLPAPER_SEAFLOOR, - WALLPAPER_RIVER, - WALLPAPER_SKY, - WALLPAPER_POLKADOT, - WALLPAPER_POKECENTER, - WALLPAPER_MACHINE, - WALLPAPER_PLAIN, - WALLPAPER_FRIENDS, // The one received as a gift from Walda's parents. - WALLPAPER_COUNT -}; - -enum -{ - FRIENDS_ZIGZAGOON, - FRIENDS_SCREEN, - FRIENDS_HORIZONTAL, - FRIENDS_DIAGONAL, - FRIENDS_BLOCK, - FRIENDS_RIBBON, - FRIENDS_POKECENTER2, - FRIENDS_FRAME, - FRIENDS_BLANK, - FRIENDS_CIRCLES, - FRIENDS_AZUMARILL, - FRIENDS_PIKACHU, - FRIENDS_LEGENDARY, - FRIENDS_DUSCLOPS, - FRIENDS_LUDICOLO, - FRIENDS_WHISCASH, - FRIENDS_WALLPAPERS_COUNT -}; - -enum -{ - CURSOR_AREA_IN_BOX, - CURSOR_AREA_IN_PARTY, - CURSOR_AREA_BOX, - CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box -}; - -#define TAG_PAL_WAVEFORM 0xDACA -#define TAG_PAL_DAC8 0xDAC8 -#define TAG_PAL_DAC6 0xDAC6 -#define TAG_PAL_DACE 0xDACE -#define TAG_PAL_DAC7 0xDAC7 -#define TAG_PAL_DAC9 0xDAC9 -#define TAG_PAL_DAC0 0xDAC0 -#define TAG_PAL_DACB 0xDACB - -#define TAG_TILE_WAVEFORM 0x5 -#define TAG_TILE_10 0x10 -#define TAG_TILE_2 0x2 -#define TAG_TILE_D 0xD -#define TAG_TILE_A 0xA -#define TAG_TILE_3 0x3 -#define TAG_TILE_4 0x4 -#define TAG_TILE_12 0x12 -#define TAG_TILE_7 0x7 -#define TAG_TILE_0 0x0 -#define TAG_TILE_1 0x1 - // IWRAM bss static u32 gUnknown_03000F78[98]; @@ -518,7 +555,7 @@ static void sub_80CC064(void); static void sub_80CE324(void); static void ClearBottomWindow(void); static void sub_80CA704(void); -static void sub_80D013C(void); +static void RemoveMenu(void); static void sub_80CE00C(void); static void sub_80D1194(void); static void PrintCursorMonInfo(void); @@ -627,8 +664,8 @@ static void sub_80D01D0(u8 arg0); static void sub_80CD1A8(bool8 arg0); static void sub_80CA984(bool8 arg0); static void CreatePartyMonsSprites(bool8 arg0); -static void PrintStorageActionText(u8 id); -static s16 sub_80D00AC(void); +static void PrintMessage(u8 id); +static s16 HandleMenuInput(void); static s8 RunCanReleaseMon(void); static u8 GetBoxCursorPosition(void); static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos); @@ -675,7 +712,7 @@ static bool32 AtLeastThreeUsableMons(void); static u8 InBoxInput_Normal(void); static u8 InBoxInput_MovingMultiple(void); static u8 InBoxInput_GrabbingMultiple(void); -static s8 sub_80CFF98(u8 arg0); +static s8 GetMenuItemTextId(u8); static u8 sub_80CFA5C(void); static u8 sub_80D0BA4(void); static bool8 sub_80CFA84(void); @@ -914,39 +951,39 @@ static const struct SpriteTemplate sSpriteTemplate_CursorMon = .callback = SpriteCallbackDummy, }; -static const struct StorageAction gPCStorageActionTexts[] = -{ - [PC_TEXT_EXIT_BOX] = {gText_ExitFromBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PICK_A_THEME] = {gText_PleasePickATheme, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_IS_SELECTED] = {gText_PkmnIsSelected, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WAS_DEPOSITED] = {gText_PkmnWasDeposited, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_BOX_IS_FULL] = {gText_BoxIsFull2, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_RELEASE_POKE] = {gText_ReleaseThisPokemon, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WAS_RELEASED] = {gText_PkmnWasReleased, PC_TEXT_FMT_MON_NAME_4}, - [PC_TEXT_BYE_BYE] = {gText_ByeByePkmn, PC_TEXT_FMT_MON_NAME_6}, - [PC_TEXT_MARK_POKE] = {gText_MarkYourPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_LAST_POKE] = {gText_ThatsYourLastPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PARTY_FULL] = {gText_YourPartysFull, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_HOLDING_POKE] = {gText_YoureHoldingAPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CONTINUE_BOX] = {gText_ContinueBoxOperations, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CAME_BACK] = {gText_PkmnCameBack, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_WORRIED] = {gText_WasItWorriedAboutYou, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_SURPRISE] = {gText_FourEllipsesExclamation, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_IS_SELECTED2] = {gText_PkmnIsSelected, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_GIVE_TO_MON] = {gText_GiveToAPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PLACED_IN_BAG] = {gText_PlacedItemInBag, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_BAG_FULL] = {gText_BagIsFull2, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PUT_IN_BAG] = {gText_PutItemInBag, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_ITEM_IS_HELD] = {gText_ItemIsNowHeld, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_CANT_STORE_MAIL] = {gText_MailCantBeStored, PC_TEXT_FMT_NORMAL}, +static const struct StorageMessage sMessages[] = +{ + [MSG_EXIT_BOX] = {gText_ExitFromBox, MSG_FORMAT_NORMAL}, + [MSG_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, MSG_FORMAT_NORMAL}, + [MSG_PICK_A_THEME] = {gText_PleasePickATheme, MSG_FORMAT_NORMAL}, + [MSG_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, MSG_FORMAT_NORMAL}, + [MSG_IS_SELECTED] = {gText_PkmnIsSelected, MSG_FORMAT_MON_NAME_1}, + [MSG_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, MSG_FORMAT_NORMAL}, + [MSG_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, MSG_FORMAT_NORMAL}, + [MSG_WAS_DEPOSITED] = {gText_PkmnWasDeposited, MSG_FORMAT_MON_NAME_1}, + [MSG_BOX_IS_FULL] = {gText_BoxIsFull2, MSG_FORMAT_NORMAL}, + [MSG_RELEASE_POKE] = {gText_ReleaseThisPokemon, MSG_FORMAT_NORMAL}, + [MSG_WAS_RELEASED] = {gText_PkmnWasReleased, MSG_FORMAT_MON_NAME_4}, + [MSG_BYE_BYE] = {gText_ByeByePkmn, MSG_FORMAT_MON_NAME_6}, + [MSG_MARK_POKE] = {gText_MarkYourPkmn, MSG_FORMAT_NORMAL}, + [MSG_LAST_POKE] = {gText_ThatsYourLastPkmn, MSG_FORMAT_NORMAL}, + [MSG_PARTY_FULL] = {gText_YourPartysFull, MSG_FORMAT_NORMAL}, + [MSG_HOLDING_POKE] = {gText_YoureHoldingAPkmn, MSG_FORMAT_NORMAL}, + [MSG_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, MSG_FORMAT_NORMAL}, + [MSG_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, MSG_FORMAT_NORMAL}, + [MSG_CONTINUE_BOX] = {gText_ContinueBoxOperations, MSG_FORMAT_NORMAL}, + [MSG_CAME_BACK] = {gText_PkmnCameBack, MSG_FORMAT_MON_NAME_1}, + [MSG_WORRIED] = {gText_WasItWorriedAboutYou, MSG_FORMAT_NORMAL}, + [MSG_SURPRISE] = {gText_FourEllipsesExclamation, MSG_FORMAT_NORMAL}, + [MSG_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, MSG_FORMAT_NORMAL}, + [MSG_IS_SELECTED2] = {gText_PkmnIsSelected, MSG_FORMAT_ITEM_NAME}, + [MSG_GIVE_TO_MON] = {gText_GiveToAPkmn, MSG_FORMAT_NORMAL}, + [MSG_PLACED_IN_BAG] = {gText_PlacedItemInBag, MSG_FORMAT_ITEM_NAME}, + [MSG_BAG_FULL] = {gText_BagIsFull2, MSG_FORMAT_NORMAL}, + [MSG_PUT_IN_BAG] = {gText_PutItemInBag, MSG_FORMAT_NORMAL}, + [MSG_ITEM_IS_HELD] = {gText_ItemIsNowHeld, MSG_FORMAT_ITEM_NAME}, + [MSG_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, MSG_FORMAT_ITEM_NAME}, + [MSG_CANT_STORE_MAIL] = {gText_MailCantBeStored, MSG_FORMAT_NORMAL}, }; static const struct WindowTemplate sYesNoWindowTemplate = @@ -2382,7 +2419,7 @@ static void Cb_ReshowPSS(u8 taskId) { if (sWhichToReshow == 2 && gSpecialVar_ItemId != 0) { - PrintStorageActionText(PC_TEXT_ITEM_IS_HELD); + PrintMessage(MSG_ITEM_IS_HELD); sPSSData->state++; } else @@ -2419,7 +2456,7 @@ static void Cb_MainPSS(u8 taskId) case 5: if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS && sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) { - PrintStorageActionText(PC_TEXT_WHICH_ONE_WILL_TAKE); + PrintMessage(MSG_WHICH_ONE_WILL_TAKE); sPSSData->state = 3; } else @@ -2622,12 +2659,12 @@ static void Cb_MainPSS(u8 taskId) break; case 4: PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_LAST_POKE); + PrintMessage(MSG_LAST_POKE); sPSSData->state = 6; break; case 5: PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); + PrintMessage(MSG_PLEASE_REMOVE_MAIL); sPSSData->state = 6; break; case 6: @@ -2718,11 +2755,11 @@ static void Cb_OnSelectedMon(u8 taskId) { PlaySE(SE_SELECT); if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) - PrintStorageActionText(PC_TEXT_IS_SELECTED); + PrintMessage(MSG_IS_SELECTED); else if (IsActiveItemMoving() || sPSSData->cursorMonItem != 0) - PrintStorageActionText(PC_TEXT_IS_SELECTED2); + PrintMessage(MSG_IS_SELECTED2); else - PrintStorageActionText(PC_TEXT_GIVE_TO_MON); + PrintMessage(MSG_GIVE_TO_MON); AddMenu(); sPSSData->state = 1; @@ -2733,14 +2770,14 @@ static void Cb_OnSelectedMon(u8 taskId) sPSSData->state = 2; break; case 2: - switch (sub_80D00AC()) + switch (HandleMenuInput()) { - case -1: - case 0: + case MENU_B_PRESSED: + case MENU_CANCEL: ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; - case 3: + case MENU_MOVE: if (CanMovePartyMon()) { sPSSData->state = 3; @@ -2752,12 +2789,12 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_MoveMon); } break; - case 5: + case MENU_PLACE: PlaySE(SE_SELECT); ClearBottomWindow(); SetPSSCallback(Cb_PlaceMon); break; - case 4: + case MENU_SHIFT: if (!CanShiftMon()) { sPSSData->state = 3; @@ -2769,12 +2806,12 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_ShiftMon); } break; - case 2: + case MENU_WITHDRAW: PlaySE(SE_SELECT); ClearBottomWindow(); SetPSSCallback(Cb_WithdrawMon); break; - case 1: + case MENU_STORE: if (CanMovePartyMon()) { sPSSData->state = 3; @@ -2790,7 +2827,7 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_DepositMenu); } break; - case 7: + case MENU_RELEASE: if (CanMovePartyMon()) { sPSSData->state = 3; @@ -2809,51 +2846,51 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_ReleaseMon); } break; - case 6: + case MENU_SUMMARY: PlaySE(SE_SELECT); SetPSSCallback(Cb_ShowMonSummary); break; - case 8: + case MENU_MARK: PlaySE(SE_SELECT); SetPSSCallback(Cb_ShowMarkMenu); break; - case 12: + case MENU_TAKE: PlaySE(SE_SELECT); SetPSSCallback(Cb_TakeItemForMoving); break; - case 13: + case MENU_GIVE: PlaySE(SE_SELECT); SetPSSCallback(Cb_GiveMovingItemToMon); break; - case 16: + case MENU_BAG: SetPSSCallback(Cb_ItemToBag); break; - case 15: + case MENU_SWITCH: PlaySE(SE_SELECT); SetPSSCallback(Cb_SwitchSelectedItem); break; - case 14: + case MENU_GIVE_2: PlaySE(SE_SELECT); SetPSSCallback(Cb_GiveItemFromBag); break; - case 17: + case MENU_INFO: SetPSSCallback(Cb_ShowItemInfo); break; } break; case 3: PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_LAST_POKE); + PrintMessage(MSG_LAST_POKE); sPSSData->state = 6; break; case 5: PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_CANT_RELEASE_EGG); + PrintMessage(MSG_CANT_RELEASE_EGG); sPSSData->state = 6; break; case 4: PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); + PrintMessage(MSG_PLEASE_REMOVE_MAIL); sPSSData->state = 6; break; case 6: @@ -2931,7 +2968,7 @@ static void Cb_WithdrawMon(u8 taskId) case 0: if (CalculatePlayerPartyCount() == PARTY_SIZE) { - PrintStorageActionText(PC_TEXT_PARTY_FULL); + PrintMessage(MSG_PARTY_FULL); sPSSData->state = 1; } else @@ -2983,7 +3020,7 @@ static void Cb_DepositMenu(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); + PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); sub_80C77E8(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); sub_80C78D4(gUnknown_02039D0E); sPSSData->state++; @@ -3013,7 +3050,7 @@ static void Cb_DepositMenu(u8 taskId) } else { - PrintStorageActionText(PC_TEXT_BOX_IS_FULL); + PrintMessage(MSG_BOX_IS_FULL); sPSSData->state = 4; } } @@ -3035,7 +3072,7 @@ static void Cb_DepositMenu(u8 taskId) case 4: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { - PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); + PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); sPSSData->state = 1; } break; @@ -3047,7 +3084,7 @@ static void Cb_ReleaseMon(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_RELEASE_POKE); + PrintMessage(MSG_RELEASE_POKE); ShowYesNoWindow(1); sPSSData->state++; // fallthrough @@ -3090,13 +3127,13 @@ static void Cb_ReleaseMon(u8 taskId) case 3: ReleaseMon(); RefreshCursorMonData(); - PrintStorageActionText(PC_TEXT_WAS_RELEASED); + PrintMessage(MSG_WAS_RELEASED); sPSSData->state++; break; case 4: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { - PrintStorageActionText(PC_TEXT_BYE_BYE); + PrintMessage(MSG_BYE_BYE); sPSSData->state++; } break; @@ -3129,13 +3166,13 @@ static void Cb_ReleaseMon(u8 taskId) SetPSSCallback(Cb_MainPSS); break; case 8: - PrintStorageActionText(PC_TEXT_WAS_RELEASED); + PrintMessage(MSG_WAS_RELEASED); sPSSData->state++; break; case 9: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { - PrintStorageActionText(PC_TEXT_SURPRISE); + PrintMessage(MSG_SURPRISE); sPSSData->state++; } break; @@ -3151,14 +3188,14 @@ static void Cb_ReleaseMon(u8 taskId) if (!sub_80CC0A0()) { sub_80CE324(); - PrintStorageActionText(PC_TEXT_CAME_BACK); + PrintMessage(MSG_CAME_BACK); sPSSData->state++; } break; case 12: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { - PrintStorageActionText(PC_TEXT_WORRIED); + PrintMessage(MSG_WORRIED); sPSSData->state++; } break; @@ -3177,7 +3214,7 @@ static void Cb_ShowMarkMenu(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_MARK_POKE); + PrintMessage(MSG_MARK_POKE); sPSSData->markMenu.markings = sPSSData->cursorMonMarkings; OpenMonMarkingsMenu(sPSSData->cursorMonMarkings, 0xb0, 0x10); sPSSData->state++; @@ -3251,7 +3288,7 @@ static void Cb_GiveMovingItemToMon(u8 taskId) sub_80CFE54(0); sub_80CE00C(); PrintCursorMonInfo(); - PrintStorageActionText(PC_TEXT_ITEM_IS_HELD); + PrintMessage(MSG_ITEM_IS_HELD); sPSSData->state++; } break; @@ -3277,7 +3314,7 @@ static void Cb_ItemToBag(u8 taskId) if (!AddBagItem(sPSSData->cursorMonItem, 1)) { PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_BAG_FULL); + PrintMessage(MSG_BAG_FULL); sPSSData->state = 3; } else @@ -3290,7 +3327,7 @@ static void Cb_ItemToBag(u8 taskId) case 1: if (!sub_80D1218()) { - PrintStorageActionText(PC_TEXT_PLACED_IN_BAG); + PrintMessage(MSG_PLACED_IN_BAG); sPSSData->state = 2; } break; @@ -3343,7 +3380,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) sub_80CFE54(3); sub_80CE00C(); PrintCursorMonInfo(); - PrintStorageActionText(PC_TEXT_CHANGED_TO_ITEM); + PrintMessage(MSG_CHANGED_TO_ITEM); sPSSData->state++; } break; @@ -3410,7 +3447,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) { case 0: PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_PUT_IN_BAG); + PrintMessage(MSG_PUT_IN_BAG); ShowYesNoWindow(0); sPSSData->state = 1; break; @@ -3430,7 +3467,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) } else { - PrintStorageActionText(PC_TEXT_BAG_FULL); + PrintMessage(MSG_BAG_FULL); sPSSData->state = 2; } break; @@ -3485,7 +3522,7 @@ static void Cb_PrintCantStoreMail(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_CANT_STORE_MAIL); + PrintMessage(MSG_CANT_STORE_MAIL); sPSSData->state++; break; case 1: @@ -3511,7 +3548,7 @@ static void Cb_HandleBoxOptions(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_WHAT_YOU_DO); + PrintMessage(MSG_WHAT_YOU_DO); AddMenu(); sPSSData->state++; break; @@ -3520,24 +3557,24 @@ static void Cb_HandleBoxOptions(u8 taskId) return; sPSSData->state++; case 2: - switch (sub_80D00AC()) + switch (HandleMenuInput()) { - case -1: - case 0: + case MENU_B_PRESSED: + case MENU_CANCEL: sub_80CD1A8(TRUE); ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; - case 11: + case MENU_NAME: PlaySE(SE_SELECT); SetPSSCallback(Cb_NameBox); break; - case 10: + case MENU_WALLPAPER: PlaySE(SE_SELECT); ClearBottomWindow(); SetPSSCallback(Cb_HandleWallpapers); break; - case 9: + case MENU_JUMP: PlaySE(SE_SELECT); ClearBottomWindow(); SetPSSCallback(Cb_JumpBox); @@ -3553,7 +3590,7 @@ static void Cb_HandleWallpapers(u8 taskId) { case 0: AddWallpaperSetsMenu(); - PrintStorageActionText(PC_TEXT_PICK_A_THEME); + PrintMessage(MSG_PICK_A_THEME); sPSSData->state++; break; case 1: @@ -3561,25 +3598,28 @@ static void Cb_HandleWallpapers(u8 taskId) sPSSData->state++; break; case 2: - sPSSData->wallpaperSetId = sub_80D00AC(); + sPSSData->wallpaperSetId = HandleMenuInput(); switch (sPSSData->wallpaperSetId) { - case -1: + case MENU_B_PRESSED: sub_80CD1A8(TRUE); ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; - case 18 ... 21: + case MENU_SCENERY_1: + case MENU_SCENERY_2: + case MENU_SCENERY_3: + case MENU_ETCETERA: PlaySE(SE_SELECT); - sub_80D013C(); + RemoveMenu(); sPSSData->wallpaperSetId -= 18; sPSSData->state++; break; - // New wallpaper from Walda. - case 22: + case MENU_FRIENDS: + // New wallpaper from Walda. PlaySE(SE_SELECT); sPSSData->wallpaperId = 16; - sub_80D013C(); + RemoveMenu(); ClearBottomWindow(); sPSSData->state = 6; break; @@ -3589,24 +3629,24 @@ static void Cb_HandleWallpapers(u8 taskId) if (!IsDma3ManagerBusyWithBgCopy()) { AddWallpapersMenu(sPSSData->wallpaperSetId); - PrintStorageActionText(PC_TEXT_PICK_A_WALLPAPER); + PrintMessage(MSG_PICK_A_WALLPAPER); sPSSData->state++; } break; case 4: - sPSSData->wallpaperId = sub_80D00AC(); + sPSSData->wallpaperId = HandleMenuInput(); switch (sPSSData->wallpaperId) { - case -2: + case MENU_NOTHING_CHOSEN: break; - case -1: + case MENU_B_PRESSED: ClearBottomWindow(); sPSSData->state = 0; break; default: PlaySE(SE_SELECT); ClearBottomWindow(); - sPSSData->wallpaperId -= 23; + sPSSData->wallpaperId -= MENU_WALLPAPERS_START; SetWallpaperForCurrentBox(sPSSData->wallpaperId); sPSSData->state++; break; @@ -3634,7 +3674,7 @@ static void Cb_JumpBox(u8 taskId) switch (sPSSData->state) { case 0: - PrintStorageActionText(PC_TEXT_JUMP_TO_WHICH_BOX); + PrintMessage(MSG_JUMP_TO_WHICH_BOX); sub_80C77E8(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); sub_80C78D4(StorageGetCurrentBox()); sPSSData->state++; @@ -3742,7 +3782,7 @@ static void Cb_OnCloseBoxPressed(u8 taskId) if (IsMonBeingMoved()) { PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_HOLDING_POKE); + PrintMessage(MSG_HOLDING_POKE); sPSSData->state = 1; } else if (IsActiveItemMoving()) @@ -3752,7 +3792,7 @@ static void Cb_OnCloseBoxPressed(u8 taskId) else { PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_EXIT_BOX); + PrintMessage(MSG_EXIT_BOX); ShowYesNoWindow(0); sPSSData->state = 2; } @@ -3803,7 +3843,7 @@ static void Cb_OnBPressed(u8 taskId) if (IsMonBeingMoved()) { PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_HOLDING_POKE); + PrintMessage(MSG_HOLDING_POKE); sPSSData->state = 1; } else if (IsActiveItemMoving()) @@ -3813,7 +3853,7 @@ static void Cb_OnBPressed(u8 taskId) else { PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_CONTINUE_BOX); + PrintMessage(MSG_CONTINUE_BOX); ShowYesNoWindow(0); sPSSData->state = 2; } @@ -4382,26 +4422,26 @@ static void sub_80CAC1C(void) CopyBgTilemapBufferToVram(0); } -static void PrintStorageActionText(u8 id) +static void PrintMessage(u8 id) { u8 *txtPtr; DynamicPlaceholderTextUtil_Reset(); - switch (gPCStorageActionTexts[id].format) + switch (sMessages[id].format) { - case PC_TEXT_FMT_NORMAL: + case MSG_FORMAT_NORMAL: break; - case PC_TEXT_FMT_MON_NAME_1: - case PC_TEXT_FMT_MON_NAME_2: - case PC_TEXT_FMT_MON_NAME_3: + case MSG_FORMAT_MON_NAME_1: + case MSG_FORMAT_MON_NAME_2: + case MSG_FORMAT_MON_NAME_3: DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->cursorMonNick); break; - case PC_TEXT_FMT_MON_NAME_4: - case PC_TEXT_FMT_MON_NAME_5: - case PC_TEXT_FMT_MON_NAME_6: + case MSG_FORMAT_MON_NAME_4: + case MSG_FORMAT_MON_NAME_5: + case MSG_FORMAT_MON_NAME_6: DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->field_21E0); break; - case PC_TEXT_FMT_ITEM_NAME: + case MSG_FORMAT_ITEM_NAME: if (IsActiveItemMoving()) txtPtr = StringCopy(sPSSData->itemName, GetMovingItemName()); else @@ -4415,7 +4455,7 @@ static void PrintStorageActionText(u8 id) break; } - DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->field_2190, gPCStorageActionTexts[id].text); + DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->field_2190, sMessages[id].text); FillWindowPixelBuffer(1, PIXEL_FILL(1)); AddTextPrinterParameterized(1, 1, sPSSData->field_2190, 0, 1, TEXT_SPEED_FF, NULL); DrawTextBorderOuter(1, 2, 14); @@ -4439,12 +4479,12 @@ static void ClearBottomWindow(void) static void AddWallpaperSetsMenu(void) { InitMenu(); - SetMenuText(18); - SetMenuText(19); - SetMenuText(20); - SetMenuText(21); + SetMenuText(MENU_SCENERY_1); + SetMenuText(MENU_SCENERY_2); + SetMenuText(MENU_SCENERY_3); + SetMenuText(MENU_ETCETERA); if (IsWaldaWallpaperUnlocked()) - SetMenuText(22); + SetMenuText(MENU_FRIENDS); AddMenu(); } @@ -4454,28 +4494,28 @@ static void AddWallpapersMenu(u8 wallpaperSet) switch (wallpaperSet) { case 0: - SetMenuText(23); - SetMenuText(24); - SetMenuText(25); - SetMenuText(26); + SetMenuText(MENU_FOREST); + SetMenuText(MENU_CITY); + SetMenuText(MENU_DESERT); + SetMenuText(MENU_SAVANNA); break; case 1: - SetMenuText(27); - SetMenuText(28); - SetMenuText(29); - SetMenuText(30); + SetMenuText(MENU_CRAG); + SetMenuText(MENU_VOLCANO); + SetMenuText(MENU_SNOW); + SetMenuText(MENU_CAVE); break; case 2: - SetMenuText(31); - SetMenuText(32); - SetMenuText(33); - SetMenuText(34); + SetMenuText(MENU_BEACH); + SetMenuText(MENU_SEAFLOOR); + SetMenuText(MENU_RIVER); + SetMenuText(MENU_SKY); break; case 3: - SetMenuText(35); - SetMenuText(36); - SetMenuText(37); - SetMenuText(38); + SetMenuText(MENU_POLKADOT); + SetMenuText(MENU_POKECENTER); + SetMenuText(MENU_MACHINE); + SetMenuText(MENU_SIMPLE); break; } AddMenu(); @@ -7010,23 +7050,23 @@ static u8 InBoxInput_Normal(void) if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) { - switch (sub_80CFF98(0)) + switch (GetMenuItemTextId(0)) { - case 1: + case MENU_STORE: return 11; - case 2: + case MENU_WITHDRAW: return 12; - case 3: + case MENU_MOVE: return 13; - case 4: + case MENU_SHIFT: return 14; - case 5: + case MENU_PLACE: return 15; - case 12: + case MENU_TAKE: return 16; - case 13: + case MENU_GIVE: return 17; - case 15: + case MENU_SWITCH: return 18; } } @@ -7290,23 +7330,23 @@ static u8 HandleInput_InParty(void) if (!sCanOnlyMove) return 8; - switch (sub_80CFF98(0)) + switch (GetMenuItemTextId(0)) { - case 1: + case MENU_STORE: return 11; - case 2: + case MENU_WITHDRAW: return 12; - case 3: + case MENU_MOVE: return 13; - case 4: + case MENU_SHIFT: return 14; - case 5: + case MENU_PLACE: return 15; - case 12: + case MENU_TAKE: return 16; - case 13: + case MENU_GIVE: return 17; - case 15: + case MENU_SWITCH: return 18; } } @@ -7515,10 +7555,10 @@ static u8 HandleInput(void) static void AddBoxMenu(void) { InitMenu(); - SetMenuText(9); - SetMenuText(10); - SetMenuText(11); - SetMenuText(0); + SetMenuText(MENU_JUMP); + SetMenuText(MENU_WALLPAPER); + SetMenuText(MENU_NAME); + SetMenuText(MENU_CANCEL); } static u8 sub_80CFA5C(void) @@ -7538,13 +7578,13 @@ static bool8 sub_80CFA84(void) { case BOX_OPTION_DEPOSIT: if (var0) - SetMenuText(1); + SetMenuText(MENU_STORE); else return FALSE; break; case BOX_OPTION_WITHDRAW: if (var0) - SetMenuText(2); + SetMenuText(MENU_WITHDRAW); else return FALSE; break; @@ -7552,14 +7592,14 @@ static bool8 sub_80CFA84(void) if (sIsMonBeingMoved) { if (var0) - SetMenuText(4); + SetMenuText(MENU_SHIFT); else - SetMenuText(5); + SetMenuText(MENU_PLACE); } else { if (var0) - SetMenuText(3); + SetMenuText(MENU_MOVE); else return FALSE; } @@ -7569,18 +7609,18 @@ static bool8 sub_80CFA84(void) return FALSE; } - SetMenuText(6); + SetMenuText(MENU_SUMMARY); if (sPSSData->boxOption == BOX_OPTION_MOVE_MONS) { if (!sBoxCursorArea) - SetMenuText(2); + SetMenuText(MENU_WITHDRAW); else - SetMenuText(1); + SetMenuText(MENU_STORE); } - SetMenuText(8); - SetMenuText(7); - SetMenuText(0); + SetMenuText(MENU_MARK); + SetMenuText(MENU_RELEASE); + SetMenuText(MENU_CANCEL); return TRUE; } @@ -7596,16 +7636,16 @@ static bool8 sub_80CFB44(void) if (sPSSData->cursorMonSpecies == SPECIES_NONE) return FALSE; - SetMenuText(14); + SetMenuText(MENU_GIVE_2); } else { if (!ItemIsMail(sPSSData->cursorMonItem)) { - SetMenuText(12); - SetMenuText(16); + SetMenuText(MENU_TAKE); + SetMenuText(MENU_BAG); } - SetMenuText(17); + SetMenuText(MENU_INFO); } } else @@ -7615,18 +7655,18 @@ static bool8 sub_80CFB44(void) if (sPSSData->cursorMonSpecies == SPECIES_NONE) return FALSE; - SetMenuText(13); + SetMenuText(MENU_GIVE); } else { if (ItemIsMail(sPSSData->cursorMonItem) == TRUE) return FALSE; - SetMenuText(15); + SetMenuText(MENU_SWITCH); } } - SetMenuText(0); + SetMenuText(MENU_CANCEL); return TRUE; } @@ -7825,57 +7865,57 @@ static void InitMenu(void) sPSSData->menuWindow.baseBlock = 92; } -static const u8 *const gUnknown_0857BA80[] = -{ - gPCText_Cancel, - gPCText_Store, - gPCText_Withdraw, - gPCText_Move, - gPCText_Shift, - gPCText_Place, - gPCText_Summary, - gPCText_Release, - gPCText_Mark, - gPCText_Jump, - gPCText_Wallpaper, - gPCText_Name, - gPCText_Take, - gPCText_Give, - gPCText_Give, - gPCText_Switch, - gPCText_Bag, - gPCText_Info, - gPCText_Scenery1, - gPCText_Scenery2, - gPCText_Scenery3, - gPCText_Etcetera, - gPCText_Friends, - gPCText_Forest, - gPCText_City, - gPCText_Desert, - gPCText_Savanna, - gPCText_Crag, - gPCText_Volcano, - gPCText_Snow, - gPCText_Cave, - gPCText_Beach, - gPCText_Seafloor, - gPCText_River, - gPCText_Sky, - gPCText_PolkaDot, - gPCText_Pokecenter, - gPCText_Machine, - gPCText_Simple, +static const u8 *const sMenuTexts[] = +{ + [MENU_CANCEL] = gPCText_Cancel, + [MENU_STORE] = gPCText_Store, + [MENU_WITHDRAW] = gPCText_Withdraw, + [MENU_MOVE] = gPCText_Move, + [MENU_SHIFT] = gPCText_Shift, + [MENU_PLACE] = gPCText_Place, + [MENU_SUMMARY] = gPCText_Summary, + [MENU_RELEASE] = gPCText_Release, + [MENU_MARK] = gPCText_Mark, + [MENU_JUMP] = gPCText_Jump, + [MENU_WALLPAPER] = gPCText_Wallpaper, + [MENU_NAME] = gPCText_Name, + [MENU_TAKE] = gPCText_Take, + [MENU_GIVE] = gPCText_Give, + [MENU_GIVE_2] = gPCText_Give, + [MENU_SWITCH] = gPCText_Switch, + [MENU_BAG] = gPCText_Bag, + [MENU_INFO] = gPCText_Info, + [MENU_SCENERY_1] = gPCText_Scenery1, + [MENU_SCENERY_2] = gPCText_Scenery2, + [MENU_SCENERY_3] = gPCText_Scenery3, + [MENU_ETCETERA] = gPCText_Etcetera, + [MENU_FRIENDS] = gPCText_Friends, + [MENU_FOREST] = gPCText_Forest, + [MENU_CITY] = gPCText_City, + [MENU_DESERT] = gPCText_Desert, + [MENU_SAVANNA] = gPCText_Savanna, + [MENU_CRAG] = gPCText_Crag, + [MENU_VOLCANO] = gPCText_Volcano, + [MENU_SNOW] = gPCText_Snow, + [MENU_CAVE] = gPCText_Cave, + [MENU_BEACH] = gPCText_Beach, + [MENU_SEAFLOOR] = gPCText_Seafloor, + [MENU_RIVER] = gPCText_River, + [MENU_SKY] = gPCText_Sky, + [MENU_POLKADOT] = gPCText_PolkaDot, + [MENU_POKECENTER] = gPCText_Pokecenter, + [MENU_MACHINE] = gPCText_Machine, + [MENU_SIMPLE] = gPCText_Simple, }; static void SetMenuText(u8 textId) { - if (sPSSData->menuItemsCount < 7) + if (sPSSData->menuItemsCount < ARRAY_COUNT(sPSSData->menuItems)) { u8 len; struct StorageMenu *menu = &sPSSData->menuItems[sPSSData->menuItemsCount]; - menu->text = gUnknown_0857BA80[textId]; + menu->text = sMenuTexts[textId]; menu->textId = textId; len = StringLength(menu->text); if (len > sPSSData->menuWidth) @@ -7885,12 +7925,12 @@ static void SetMenuText(u8 textId) } } -static s8 sub_80CFF98(u8 arg0) +static s8 GetMenuItemTextId(u8 menuIdx) { - if (arg0 >= sPSSData->menuItemsCount) + if (menuIdx >= sPSSData->menuItemsCount) return -1; else - return sPSSData->menuItems[arg0].textId; + return sPSSData->menuItems[menuIdx].textId; } static void AddMenu(void) @@ -7899,11 +7939,11 @@ static void AddMenu(void) sPSSData->menuWindow.height = 2 * sPSSData->menuItemsCount; sPSSData->menuWindow.tilemapLeft = 29 - sPSSData->menuWindow.width; sPSSData->menuWindow.tilemapTop = 15 - sPSSData->menuWindow.height; - sPSSData->field_CB0 = AddWindow(&sPSSData->menuWindow); - ClearWindowTilemap(sPSSData->field_CB0); - DrawStdFrameWithCustomTileAndPalette(sPSSData->field_CB0, FALSE, 11, 14); - PrintMenuTable(sPSSData->field_CB0, sPSSData->menuItemsCount, (void*)sPSSData->menuItems); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sPSSData->field_CB0, sPSSData->menuItemsCount, 0); + sPSSData->menuWindowId = AddWindow(&sPSSData->menuWindow); + ClearWindowTilemap(sPSSData->menuWindowId); + DrawStdFrameWithCustomTileAndPalette(sPSSData->menuWindowId, FALSE, 11, 14); + PrintMenuTable(sPSSData->menuWindowId, sPSSData->menuItemsCount, (void*)sPSSData->menuItems); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sPSSData->menuWindowId, sPSSData->menuItemsCount, 0); ScheduleBgCopyTilemapToVram(0); sPSSData->field_CAE = 0; } @@ -7913,21 +7953,21 @@ static bool8 sub_80D00A8(void) return FALSE; } -static s16 sub_80D00AC(void) +static s16 HandleMenuInput(void) { - s32 textId = -2; + s32 input = MENU_NOTHING_CHOSEN; do { if (JOY_NEW(A_BUTTON)) { - textId = Menu_GetCursorPos(); + input = Menu_GetCursorPos(); break; } else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - textId = -1; + input = MENU_B_PRESSED; } if (JOY_NEW(DPAD_UP)) @@ -7942,19 +7982,19 @@ static s16 sub_80D00AC(void) } } while (0); - if (textId != -2) - sub_80D013C(); + if (input != MENU_NOTHING_CHOSEN) + RemoveMenu(); - if (textId >= 0) - textId = sPSSData->menuItems[textId].textId; + if (input >= 0) + input = sPSSData->menuItems[input].textId; - return textId; + return input; } -static void sub_80D013C(void) +static void RemoveMenu(void) { - ClearStdWindowAndFrameToTransparent(sPSSData->field_CB0, TRUE); - RemoveWindow(sPSSData->field_CB0); + ClearStdWindowAndFrameToTransparent(sPSSData->menuWindowId, TRUE); + RemoveWindow(sPSSData->menuWindowId); } // The functions below handle moving and grabbing multiple mons at once. -- cgit v1.2.3 From a1ed59450e133a9dd84c59869418d449e48fc1ce Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 14:06:25 -0400 Subject: Doc storage - wallpaper and titles --- src/pokemon_storage_system.c | 1133 +++++++++++++++--------------------------- 1 file changed, 398 insertions(+), 735 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 99f16e43b..6bcc10afc 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -138,6 +138,7 @@ enum { MENU_MACHINE, MENU_SIMPLE, }; +#define MENU_WALLPAPER_SETS_START MENU_SCENERY_1 #define MENU_WALLPAPERS_START MENU_FOREST enum { @@ -153,27 +154,6 @@ enum { MODE_MOVE, }; -enum { - WALLPAPER_FOREST, - WALLPAPER_CITY, - WALLPAPER_DESERT, - WALLPAPER_SAVANNA, - WALLPAPER_CRAG, - WALLPAPER_VOLCANO, - WALLPAPER_SNOW, - WALLPAPER_CAVE, - WALLPAPER_BEACH, - WALLPAPER_SEAFLOOR, - WALLPAPER_RIVER, - WALLPAPER_SKY, - WALLPAPER_POLKADOT, - WALLPAPER_POKECENTER, - WALLPAPER_MACHINE, - WALLPAPER_PLAIN, - WALLPAPER_FRIENDS, // The one received as a gift from Walda's parents. - WALLPAPER_COUNT -}; - enum { FRIENDS_ZIGZAGOON, FRIENDS_SCREEN, @@ -206,26 +186,28 @@ enum { #define TAG_PAL_DAC6 0xDAC6 #define TAG_PAL_DACE 0xDACE #define TAG_PAL_DAC7 0xDAC7 -#define TAG_PAL_DAC9 0xDAC9 +#define PALTAG_BOX_TITLE 0xDAC9 #define TAG_PAL_DAC0 0xDAC0 #define TAG_PAL_DACB 0xDACB -#define TAG_TILE_WAVEFORM 0x5 -#define TAG_TILE_10 0x10 -#define TAG_TILE_2 0x2 -#define TAG_TILE_D 0xD -#define TAG_TILE_A 0xA -#define TAG_TILE_3 0x3 -#define TAG_TILE_4 0x4 -#define TAG_TILE_12 0x12 -#define TAG_TILE_7 0x7 -#define TAG_TILE_0 0x0 -#define TAG_TILE_1 0x1 +#define TAG_TILE_0 0 +#define TAG_TILE_1 1 +#define TAG_TILE_2 2 +#define GFXTAG_BOX_TITLE 3 +#define GFXTAG_BOX_TITLE_ALT 4 +#define TAG_TILE_WAVEFORM 5 +#define GFXTAG_ARROW 6 +#define TAG_TILE_7 7 +#define TAG_TILE_A 10 +#define TAG_TILE_D 13 +#define TAG_TILE_10 16 +#define TAG_TILE_12 18 -struct WallpaperTable + +struct Wallpaper { const u32 *tiles; - const u32 *tileMap; + const u32 *tilemap; const u16 *palettes; }; @@ -275,7 +257,7 @@ struct UnkPSSStruct_2002370 struct Sprite *unk_0000; struct Sprite *unk_0004[4]; u32 unk_0014[3]; - struct Sprite *unk_0020[2]; + struct Sprite *arrowSprites[2]; u8 filler_0028[0x214]; u32 unk_023c; u16 unk_0240; @@ -317,37 +299,37 @@ struct PokemonStorageSystemData u16 bg2_X; s16 wallpaperScrollSpeed; u16 field_2D0; - u8 field_2D2; + u8 wallpaperOffset; u8 field_2D3; // Written to, but never read. - u8 field_2D4; // Written to, but never read. + u8 scrollToBoxIdUnused; // Written to, but never read. u16 field_2D6; // Written to, but never read. - s16 field_2D8; // Written to, but never read. + s16 scrollDirectionUnused; // Written to, but never read. u16 field_2DA; // Written to, but never read. u16 field_2DC; // Written to, but never read. u16 field_2DE; // Written to, but never read. u16 field_2E0; // Written to, but never read. u8 filler[22]; - u8 field_2F8[1024]; - u8 field_6F8; - u8 field_6F9; // Written to, but never read. - u8 field_6FA; - s8 field_6FB; - u16 field_6FC[16]; - u16 field_71C; - u16 field_71E; - struct Sprite *field_720[2]; - struct Sprite *field_728[2]; - struct Sprite *field_730[2]; - u32 field_738; + u8 boxTitleTiles[1024]; + u8 boxTitleCycleId; + u8 wallpaperLoadState; // Written to, but never read. + u8 wallpaperLoadBoxId; + s8 wallpaperLoadDir; + u16 boxTitlePal[16]; + u16 boxTitlePalOffset; + u16 boxTitleAltPalOffset; + struct Sprite *curBoxTitleSprites[2]; + struct Sprite *nextBoxTitleSprites[2]; + struct Sprite *arrowSprites[2]; + u32 boxTitlePalBits; u8 field_73C[80]; // Unused u16 field_78C; // Written to, but never read. s16 wallpaperSetId; s16 wallpaperId; - u16 field_792[360]; + u16 wallpaperTilemap[360]; u8 wallpaperChangeState; - u8 field_A63; - u8 boxScrollDestination; - s8 field_A65; + u8 scrollState; + u8 scrollToBoxId; + s8 scrollDirection; u8 *wallpaperTiles; struct Sprite *movingMonSprite; struct Sprite *partySprites[PARTY_SIZE]; @@ -433,7 +415,7 @@ struct PokemonStorageSystemData struct BoxPokemon *box; } field_218C; u8 field_2190[40]; - u8 field_21B8[40]; + u8 boxTitleText[40]; u8 field_21E0[POKEMON_NAME_LENGTH + 1]; u8 itemName[20]; u8 inBoxMovingMode; @@ -449,7 +431,7 @@ struct PokemonStorageSystemData u8 field_22C4[0x800]; u8 field_2AC4[0x1800]; // Unused u8 field_42C4[0x800]; - u8 field_4AC4[0x1000]; + u8 wallpaperBgTilemapBuffer[0x1000]; u8 field_5AC4[0x800]; }; @@ -501,19 +483,19 @@ EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0; EWRAM_DATA static bool8 sCanOnlyMove = 0; // This file's functions. -static void CreatePCMenu(u8 whichMenu, s16 *windowIdPtr); -static void Cb2_EnterPSS(u8 boxOption); +static void CreatePCMenu(u8, s16 *); +static void Cb2_EnterPSS(u8); static u8 GetCurrentBoxOption(void); static u8 HandleInput(void); static u8 sub_80CDC2C(void); static u8 sub_80CB9BC(void); -static void LoadWallpaperGfx(u8 boxId, s8 direction); -static void sub_80CCCFC(u8 boxId, s8 direction); -static void sub_80CD0B8(s8 direction); -static void SetCurrentBox(u8 boxId); -static void sub_80CC32C(u8 boxId); -static void sub_80C7958(u8 curBox); -static void sub_80CCAE0(void *arg0); +static void LoadWallpaperGfx(u8, s8); +static void CreateIncomingBoxTitle(u8, s8); +static void StartBoxScrollArrowsSlide(s8); +static void SetCurrentBox(u8); +static void CreateInitBoxTask(u8); +static void sub_80C7958(u8); +static void TrimOldWallpaper(void *); static void sub_80C7B14(void); static void sub_80C7BB4(void); static void ScrollBackground(void); @@ -561,14 +543,14 @@ static void sub_80D1194(void); static void PrintCursorMonInfo(void); static void sub_80CA65C(void); static void AddWallpaperSetsMenu(void); -static void sub_80CD02C(void); +static void CreateBoxScrollArrows(void); static void InitMenu(void); -static void sub_80CD158(void); +static void StopBoxScrollArrowsSlide(void); static void sub_80CFC14(void); static void sub_80CEB40(void); -static void sub_80CCEE0(void); +static void CycleBoxTitleSprites(void); static void sub_80D1818(void); -static void sub_80D19B4(u32 arg0); +static void sub_80D19B4(u32); static void sub_80CAA74(void); static void PrintItemDescription(void); static void sub_80CE760(void); @@ -578,7 +560,7 @@ static void sub_80CFECC(void); static void sub_80CA9EC(void); static void FreePSSData(void); static void AddBoxMenu(void); -static void sub_80CCF9C(void); +static void CycleBoxTitleColor(void); static void MoveMon(void); static void PlaceMon(void); static void sub_80CAB20(void); @@ -588,16 +570,16 @@ static void sub_80CB950(void); static void sub_80CA9C0(void); static void SetUpDoShowPartyMenu(void); static void BoxSetMosaic(void); -static void sub_80C7CF4(struct Sprite *sprite); -static void sub_80CC100(struct Sprite *sprite); -static void sub_80CB278(struct Sprite *sprite); -static void sub_80CD210(struct Sprite *sprite); +static void SpriteCB_JumpBoxArrow(struct Sprite *); +static void sub_80CC100(struct Sprite *); +static void sub_80CB278(struct Sprite *); +static void SpriteCB_Arrow(struct Sprite *); static bool32 WaitForWallpaperGfxLoad(void); static bool8 InitPSSWindows(void); static bool8 sub_80CC0A0(void); static bool8 sub_80CE2A8(void); static bool8 sub_80D0164(void); -static bool8 sub_80CC35C(void); +static bool8 IsInitBoxActive(void); static bool8 sub_80D01E4(void); static bool8 sub_80CDED4(void); static bool8 sub_80CDF08(void); @@ -614,14 +596,14 @@ static bool8 sub_80D0BC0(void); static bool8 sub_80CA2B8(void); static bool8 DoWallpaperGfxChange(void); static bool8 DoMonPlaceChange(void); -static bool8 sub_80D00A8(void); +static bool8 IsMenuLoading(void); static bool8 CanMovePartyMon(void); static bool8 CanShiftMon(void); static bool8 IsCursorOnCloseBox(void); static bool8 IsCursorOnBox(void); static bool8 IsCursorInBox(void); static bool8 IsMonBeingMoved(void); -static bool8 TryStorePartyMonInBox(u8 boxId); +static bool8 TryStorePartyMonInBox(u8); static void Cb_InitPSS(u8 taskId); static void Cb_PlaceMon(u8 taskId); static void Cb_ChangeScreen(u8 taskId); @@ -653,34 +635,34 @@ static void Cb_HandleWallpapers(u8 taskId); static void Cb_NameBox(u8 taskId); static void Cb_PrintCantStoreMail(u8 taskId); static void Cb_HandleMovingMonFromParty(u8 taskId); -static void SetUpScrollToBox(u8 boxId); -static void sub_80CFE54(u8 animNum); -static void SetMovingMonPriority(u8 priority); -static void InitMonPlaceChange(u8 arg0); -static void SetMonMarkings(u8 markings); -static void ShowYesNoWindow(s8 cursorPos); -static void sub_80CDBF8(u8 cursorBoxPosition); -static void sub_80D01D0(u8 arg0); -static void sub_80CD1A8(bool8 arg0); -static void sub_80CA984(bool8 arg0); -static void CreatePartyMonsSprites(bool8 arg0); +static void SetUpScrollToBox(u8); +static void sub_80CFE54(u8); +static void SetMovingMonPriority(u8); +static void InitMonPlaceChange(u8); +static void SetMonMarkings(u8); +static void ShowYesNoWindow(s8); +static void sub_80CDBF8(u8); +static void sub_80D01D0(u8); +static void AnimateBoxScrollArrows(bool8); +static void sub_80CA984(bool8); +static void CreatePartyMonsSprites(bool8); static void PrintMessage(u8 id); static s16 HandleMenuInput(void); static s8 RunCanReleaseMon(void); static u8 GetBoxCursorPosition(void); -static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos); -static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos); -static void Item_TakeMons(u8 cursorArea, u8 cursorPos); -static void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos); -static struct Sprite *sub_80CD2E8(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority); -static void SetWallpaperForCurrentBox(u8 wallpaperId); -static void AddWallpapersMenu(u8 wallpaperSet); +static void Item_FromMonToMoving(u8, u8); +static void Item_GiveMovingToMon(u8, u8); +static void Item_TakeMons(u8, u8); +static void Item_SwitchMonsWithMoving(u8, u8); +static struct Sprite *CreateJumpBoxArrows(u16, u16, u8, u8, u8); +static void SetWallpaperForCurrentBox(u8); +static void AddWallpapersMenu(u8); static u16 GetMovingItem(void); static void LoadCursorMonGfx(u16 species, u32 pid); static void sub_80CA2D0(struct Sprite *sprite); -static void sub_80CCF64(struct Sprite *sprite); +static void SpriteCB_OutgoingBoxTitle(struct Sprite *); static void sub_80CBA3C(struct Sprite *sprite); -static void sub_80CCF30(struct Sprite *sprite); +static void SpriteCB_IncomingBoxTitle(struct Sprite *); static void sub_80CBAF0(s16 yDelta); static void sub_80CAAA8(u8 arg0, bool8 isPartyMon); static const u8 *GetMovingItemName(void); @@ -690,13 +672,13 @@ static void sub_80D0E50(u8 cursorArea, u8 cursorPos); static void sub_80D0F38(u16 item); static struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 oamPriority, u8 subpriority); static void DestroyBoxMonIcon(struct Sprite *sprite); -static void SetBoxSpeciesAndPersonalities(u8 boxId); -static void sub_80CB9D0(struct Sprite *sprite, u16 partyId); -static void sub_80CC370(u8 taskId); -static void sub_80CCB50(u8 boxId); +static void SetBoxSpeciesAndPersonalities(u8); +static void sub_80CB9D0(struct Sprite *, u16); +static void Task_InitBox(u8 taskId); +static void InitBoxTitle(u8 boxId); static s8 DetermineBoxScrollDirection(u8 boxId); -static void sub_80CCA3C(const void *tilemap, s8 direction, u8 arg2); -static s16 sub_80CD00C(const u8 *string); +static void DrawWallpaper(const void *, s8, u8); +static s16 GetBoxTitleBaseX(const u8 *); static bool8 MonPlaceChange_Shift(void); static bool8 MonPlaceChange_Move(void); static bool8 MonPlaceChange_Place(void); @@ -750,6 +732,8 @@ static void sub_80D2A90(struct UnkStruct_2000020 *arg0, struct UnkStruct_2000028 static void sub_80D2AA4(void); static void sub_80D2B88(struct UnkStruct_2000028 *unkStruct); static void sub_80D2C1C(struct UnkStruct_2000028 *unkStruct); +static u8 GetBoxWallpaper(u8); +static void SetBoxWallpaper(u8, u8); // static const rom data static const struct PSS_MenuStringPtrs gUnknown_085716C0[] = @@ -1126,450 +1110,83 @@ static const union AffineAnimCmd *const gSpriteAffineAnimTable_857291C[] = gSpriteAffineAnim_8572904 }; -static const u16 gWallpaperPalettes_Forest[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/forest_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/forest_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Forest[] = INCBIN_U32("graphics/pokemon_storage/forest.4bpp.lz"); -static const u32 gWallpaperTilemap_Forest[] = INCBIN_U32("graphics/pokemon_storage/forest.bin.lz"); - -static const u16 gWallpaperPalettes_City[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/city_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/city_bg.gbapal"), -}; -static const u32 gWallpaperTiles_City[] = INCBIN_U32("graphics/pokemon_storage/city.4bpp.lz"); -static const u32 gWallpaperTilemap_City[] = INCBIN_U32("graphics/pokemon_storage/city.bin.lz"); - -static const u16 gWallpaperPalettes_Desert[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/desert_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/desert_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Desert[] = INCBIN_U32("graphics/pokemon_storage/desert.4bpp.lz"); -static const u32 gWallpaperTilemap_Desert[] = INCBIN_U32("graphics/pokemon_storage/desert.bin.lz"); - -static const u16 gWallpaperPalettes_Savanna[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/savanna_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/savanna_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Savanna[] = INCBIN_U32("graphics/pokemon_storage/savanna.4bpp.lz"); -static const u32 gWallpaperTilemap_Savanna[] = INCBIN_U32("graphics/pokemon_storage/savanna.bin.lz"); - -static const u16 gWallpaperPalettes_Crag[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/crag_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/crag_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Crag[] = INCBIN_U32("graphics/pokemon_storage/crag.4bpp.lz"); -static const u32 gWallpaperTilemap_Crag[] = INCBIN_U32("graphics/pokemon_storage/crag.bin.lz"); - -static const u16 gWallpaperPalettes_Volcano[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/volcano_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/volcano_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Volcano[] = INCBIN_U32("graphics/pokemon_storage/volcano.4bpp.lz"); -static const u32 gWallpaperTilemap_Volcano[] = INCBIN_U32("graphics/pokemon_storage/volcano.bin.lz"); - -static const u16 gWallpaperPalettes_Snow[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/snow_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/snow_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Snow[] = INCBIN_U32("graphics/pokemon_storage/snow.4bpp.lz"); -static const u32 gWallpaperTilemap_Snow[] = INCBIN_U32("graphics/pokemon_storage/snow.bin.lz"); - -static const u16 gWallpaperPalettes_Cave[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/cave_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/cave_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Cave[] = INCBIN_U32("graphics/pokemon_storage/cave.4bpp.lz"); -static const u32 gWallpaperTilemap_Cave[] = INCBIN_U32("graphics/pokemon_storage/cave.bin.lz"); - -static const u16 gWallpaperPalettes_Beach[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/beach_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/beach_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Beach[] = INCBIN_U32("graphics/pokemon_storage/beach.4bpp.lz"); -static const u32 gWallpaperTilemap_Beach[] = INCBIN_U32("graphics/pokemon_storage/beach.bin.lz"); - -static const u16 gWallpaperPalettes_Seafloor[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/seafloor_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/seafloor_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Seafloor[] = INCBIN_U32("graphics/pokemon_storage/seafloor.4bpp.lz"); -static const u32 gWallpaperTilemap_Seafloor[] = INCBIN_U32("graphics/pokemon_storage/seafloor.bin.lz"); - -static const u16 gWallpaperPalettes_River[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/river_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/river_bg.gbapal"), -}; -static const u32 gWallpaperTiles_River[] = INCBIN_U32("graphics/pokemon_storage/river.4bpp.lz"); -static const u32 gWallpaperTilemap_River[] = INCBIN_U32("graphics/pokemon_storage/river.bin.lz"); -static const u16 gWallpaperPalettes_Sky[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/sky_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/sky_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Sky[] = INCBIN_U32("graphics/pokemon_storage/sky.4bpp.lz"); -static const u32 gWallpaperTilemap_Sky[] = INCBIN_U32("graphics/pokemon_storage/sky.bin.lz"); - -static const u16 gWallpaperPalettes_PolkaDot[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/polkadot_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/polkadot_bg.gbapal"), -}; -static const u32 gWallpaperTiles_PolkaDot[] = INCBIN_U32("graphics/pokemon_storage/polkadot.4bpp.lz"); -static const u32 gWallpaperTilemap_PolkaDot[] = INCBIN_U32("graphics/pokemon_storage/polkadot.bin.lz"); - -static const u16 gWallpaperPalettes_Pokecenter[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/pokecenter_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/pokecenter_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Pokecenter[] = INCBIN_U32("graphics/pokemon_storage/pokecenter.4bpp.lz"); -static const u32 gWallpaperTilemap_Pokecenter[] = INCBIN_U32("graphics/pokemon_storage/pokecenter.bin.lz"); - -static const u16 gWallpaperPalettes_Machine[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/machine_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/machine_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Machine[] = INCBIN_U32("graphics/pokemon_storage/machine.4bpp.lz"); -static const u32 gWallpaperTilemap_Machine[] = INCBIN_U32("graphics/pokemon_storage/machine.bin.lz"); - -static const u16 gWallpaperPalettes_Plain[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/plain_frame.gbapal"), - INCBIN_U16("graphics/pokemon_storage/plain_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Plain[] = INCBIN_U32("graphics/pokemon_storage/plain.4bpp.lz"); -static const u32 gWallpaperTilemap_Plain[] = INCBIN_U32("graphics/pokemon_storage/plain.bin.lz"); - -// 12x18 tilemap -static const u32 gUnknown_085773C4[] = INCBIN_U32("graphics/unused/tilemap_5773C4.bin"); - -static const u16 gUnknown_08577574[][2] = -{ - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF}, - {0x1CE7, 0x7FFF} -}; - -#define WALLPAPER_ENTRY(name) {gWallpaperTiles_##name, gWallpaperTilemap_##name, gWallpaperPalettes_##name[0]} - -static const struct WallpaperTable gWallpaperTable[] = -{ - [WALLPAPER_FOREST] = WALLPAPER_ENTRY(Forest), - [WALLPAPER_CITY] = WALLPAPER_ENTRY(City), - [WALLPAPER_DESERT] = WALLPAPER_ENTRY(Desert), - [WALLPAPER_SAVANNA] = WALLPAPER_ENTRY(Savanna), - [WALLPAPER_CRAG] = WALLPAPER_ENTRY(Crag), - [WALLPAPER_VOLCANO] = WALLPAPER_ENTRY(Volcano), - [WALLPAPER_SNOW] = WALLPAPER_ENTRY(Snow), - [WALLPAPER_CAVE] = WALLPAPER_ENTRY(Cave), - [WALLPAPER_BEACH] = WALLPAPER_ENTRY(Beach), - [WALLPAPER_SEAFLOOR] = WALLPAPER_ENTRY(Seafloor), - [WALLPAPER_RIVER] = WALLPAPER_ENTRY(River), - [WALLPAPER_SKY] = WALLPAPER_ENTRY(Sky), - [WALLPAPER_POLKADOT] = WALLPAPER_ENTRY(PolkaDot), - [WALLPAPER_POKECENTER] = WALLPAPER_ENTRY(Pokecenter), - [WALLPAPER_MACHINE] = WALLPAPER_ENTRY(Machine), - [WALLPAPER_PLAIN] = WALLPAPER_ENTRY(Plain), -}; - -static const u8 gPCGfx_Arrow[] = INCBIN_U8("graphics/pokemon_storage/arrow.4bpp"); - -static const u16 gWallpaperPalettes_Zigzagoon[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame1.gbapal"), - INCBIN_U16("graphics/pokemon_storage/zigzagoon_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Zigzagoon[] = INCBIN_U32("graphics/pokemon_storage/zigzagoon.4bpp.lz"); -static const u32 gWallpaperTilemap_Zigzagoon[] = INCBIN_U32("graphics/pokemon_storage/zigzagoon.bin.lz"); - -static const u16 gWallpaperPalettes_Screen[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame1.gbapal"), - INCBIN_U16("graphics/pokemon_storage/screen_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Screen[] = INCBIN_U32("graphics/pokemon_storage/screen.4bpp.lz"); -static const u32 gWallpaperTilemap_Screen[] = INCBIN_U32("graphics/pokemon_storage/screen.bin.lz"); - -static const u16 gWallpaperPalettes_Diagonal[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame1.gbapal"), - INCBIN_U16("graphics/pokemon_storage/diagonal_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Diagonal[] = INCBIN_U32("graphics/pokemon_storage/diagonal.4bpp.lz"); -static const u32 gWallpaperTilemap_Diagonal[] = INCBIN_U32("graphics/pokemon_storage/diagonal.bin.lz"); - -static const u16 gWallpaperPalettes_Block[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/block_bg.gbapal"), - INCBIN_U16("graphics/pokemon_storage/block_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Block[] = INCBIN_U32("graphics/pokemon_storage/block.4bpp.lz"); -static const u32 gWallpaperTilemap_Block[] = INCBIN_U32("graphics/pokemon_storage/block.bin.lz"); - -static const u16 gWallpaperPalettes_Pokecenter2[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/pokecenter2_bg.gbapal"), - INCBIN_U16("graphics/pokemon_storage/pokecenter2_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Pokecenter2[] = INCBIN_U32("graphics/pokemon_storage/pokecenter2.4bpp.lz"); -static const u32 gWallpaperTilemap_Pokecenter2[] = INCBIN_U32("graphics/pokemon_storage/pokecenter2.bin.lz"); - -static const u16 gWallpaperPalettes_Frame[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/frame_bg.gbapal"), - INCBIN_U16("graphics/pokemon_storage/frame_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Frame[] = INCBIN_U32("graphics/pokemon_storage/frame.4bpp.lz"); -static const u32 gWallpaperTilemap_Frame[] = INCBIN_U32("graphics/pokemon_storage/frame.bin.lz"); - -static const u16 gWallpaperPalettes_Blank[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame1.gbapal"), - INCBIN_U16("graphics/pokemon_storage/zigzagoon_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Blank[] = INCBIN_U32("graphics/pokemon_storage/blank.4bpp.lz"); -static const u32 gWallpaperTilemap_Blank[] = INCBIN_U32("graphics/pokemon_storage/blank.bin.lz"); - -static const u16 gWallpaperPalettes_Circles[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/circles_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Circles[] = INCBIN_U32("graphics/pokemon_storage/circles.4bpp.lz"); -static const u32 gWallpaperTilemap_Circles[] = INCBIN_U32("graphics/pokemon_storage/circles.bin.lz"); - -static const u16 gWallpaperPalettes_Azumarill[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/azumarill_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Azumarill[] = INCBIN_U32("graphics/pokemon_storage/azumarill.4bpp.lz"); -static const u32 gWallpaperTilemap_Azumarill[] = INCBIN_U32("graphics/pokemon_storage/azumarill.bin.lz"); - -static const u16 gWallpaperPalettes_Pikachu[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/pikachu_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Pikachu[] = INCBIN_U32("graphics/pokemon_storage/pikachu.4bpp.lz"); -static const u32 gWallpaperTilemap_Pikachu[] = INCBIN_U32("graphics/pokemon_storage/pikachu.bin.lz"); - -static const u16 gWallpaperPalettes_Legendary[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/legendary_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Legendary[] = INCBIN_U32("graphics/pokemon_storage/legendary.4bpp.lz"); -static const u32 gWallpaperTilemap_Legendary[] = INCBIN_U32("graphics/pokemon_storage/legendary.bin.lz"); - -static const u16 gWallpaperPalettes_Dusclops[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/dusclops_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Dusclops[] = INCBIN_U32("graphics/pokemon_storage/dusclops.4bpp.lz"); -static const u32 gWallpaperTilemap_Dusclops[] = INCBIN_U32("graphics/pokemon_storage/dusclops.bin.lz"); - -static const u16 gWallpaperPalettes_Ludicolo[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/ludicolo_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Ludicolo[] = INCBIN_U32("graphics/pokemon_storage/ludicolo.4bpp.lz"); -static const u32 gWallpaperTilemap_Ludicolo[] = INCBIN_U32("graphics/pokemon_storage/ludicolo.bin.lz"); - -static const u16 gWallpaperPalettes_Whiscash[][16] = -{ - INCBIN_U16("graphics/pokemon_storage/friends_frame2.gbapal"), - INCBIN_U16("graphics/pokemon_storage/whiscash_bg.gbapal"), -}; -static const u32 gWallpaperTiles_Whiscash[] = INCBIN_U32("graphics/pokemon_storage/whiscash.4bpp.lz"); -static const u32 gWallpaperTilemap_Whiscash[] = INCBIN_U32("graphics/pokemon_storage/whiscash.bin.lz"); - -static const u32 gWallpaperIcon_Aqua[] = INCBIN_U32("graphics/pokemon_storage/aqua_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Heart[] = INCBIN_U32("graphics/pokemon_storage/heart_icon.4bpp.lz"); -static const u32 gWallpaperIcon_FiveStar[] = INCBIN_U32("graphics/pokemon_storage/five_star_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Brick[] = INCBIN_U32("graphics/pokemon_storage/brick_icon.4bpp.lz"); -static const u32 gWallpaperIcon_FourStar[] = INCBIN_U32("graphics/pokemon_storage/four_star_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Asterisk[] = INCBIN_U32("graphics/pokemon_storage/asterisk_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Dot[] = INCBIN_U32("graphics/pokemon_storage/dot_icon.4bpp.lz"); -static const u32 gWallpaperIcon_LineCircle[] = INCBIN_U32("graphics/pokemon_storage/line_circle_icon.4bpp.lz"); -static const u32 gWallpaperIcon_PokeBall[] = INCBIN_U32("graphics/pokemon_storage/pokeball_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Maze[] = INCBIN_U32("graphics/pokemon_storage/maze_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Footprint[] = INCBIN_U32("graphics/pokemon_storage/footprint_icon.4bpp.lz"); -static const u32 gWallpaperIcon_BigAsterisk[] = INCBIN_U32("graphics/pokemon_storage/big_asterisk_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Circle[] = INCBIN_U32("graphics/pokemon_storage/circle_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Koffing[] = INCBIN_U32("graphics/pokemon_storage/koffing_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Ribbon[] = INCBIN_U32("graphics/pokemon_storage/ribbon_icon.4bpp.lz"); -static const u32 gWallpaperIcon_FourCircles[] = INCBIN_U32("graphics/pokemon_storage/four_circles_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Lotad[] = INCBIN_U32("graphics/pokemon_storage/lotad_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Crystal[] = INCBIN_U32("graphics/pokemon_storage/crystal_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Pichu[] = INCBIN_U32("graphics/pokemon_storage/pichu_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Diglett[] = INCBIN_U32("graphics/pokemon_storage/diglett_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Luvdisc[] = INCBIN_U32("graphics/pokemon_storage/luvdisc_icon.4bpp.lz"); -static const u32 gWallpaperIcon_StarInCircle[] = INCBIN_U32("graphics/pokemon_storage/star_in_circle_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Spinda[] = INCBIN_U32("graphics/pokemon_storage/spinda_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Latis[] = INCBIN_U32("graphics/pokemon_storage/latis_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Minun[] = INCBIN_U32("graphics/pokemon_storage/minun_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Togepi[] = INCBIN_U32("graphics/pokemon_storage/togepi_icon.4bpp.lz"); -static const u32 gWallpaperIcon_Magma[] = INCBIN_U32("graphics/pokemon_storage/magma_icon.4bpp.lz"); - -static const struct WallpaperTable gFriendsWallpaperTable[] = -{ - WALLPAPER_ENTRY(Zigzagoon), - WALLPAPER_ENTRY(Screen), - WALLPAPER_ENTRY(Horizontal), - WALLPAPER_ENTRY(Diagonal), - WALLPAPER_ENTRY(Block), - WALLPAPER_ENTRY(Ribbon), - WALLPAPER_ENTRY(Pokecenter2), - WALLPAPER_ENTRY(Frame), - WALLPAPER_ENTRY(Blank), - WALLPAPER_ENTRY(Circles), - WALLPAPER_ENTRY(Azumarill), - WALLPAPER_ENTRY(Pikachu), - WALLPAPER_ENTRY(Legendary), - WALLPAPER_ENTRY(Dusclops), - WALLPAPER_ENTRY(Ludicolo), - WALLPAPER_ENTRY(Whiscash), -}; - -static const u32 *const gFriendsIcons[] = -{ - gWallpaperIcon_Aqua, - gWallpaperIcon_Heart, - gWallpaperIcon_FiveStar, - gWallpaperIcon_Brick, - gWallpaperIcon_FourStar, - gWallpaperIcon_Asterisk, - gWallpaperIcon_Dot, - gWallpaperIcon_Cross, - gWallpaperIcon_LineCircle, - gWallpaperIcon_PokeBall, - gWallpaperIcon_Maze, - gWallpaperIcon_Footprint, - gWallpaperIcon_BigAsterisk, - gWallpaperIcon_Circle, - gWallpaperIcon_Koffing, - gWallpaperIcon_Ribbon, - gWallpaperIcon_Bolt, - gWallpaperIcon_FourCircles, - gWallpaperIcon_Lotad, - gWallpaperIcon_Crystal, - gWallpaperIcon_Pichu, - gWallpaperIcon_Diglett, - gWallpaperIcon_Luvdisc, - gWallpaperIcon_StarInCircle, - gWallpaperIcon_Spinda, - gWallpaperIcon_Latis, - gWallpaperIcon_Plusle, - gWallpaperIcon_Minun, - gWallpaperIcon_Togepi, - gWallpaperIcon_Magma, -}; +#include "data/wallpapers.h" // Unknown Unused data. static const u16 gUnknown_0857B07C = 0x23BA; -static const struct SpriteSheet gUnknown_0857B080 = {gPCGfx_Arrow, 0x80, 6}; +static const struct SpriteSheet sSpriteSheet_Arrow = {sArrow_Gfx, 0x80, GFXTAG_ARROW}; -static const struct OamData gOamData_83BB298 = +static const struct OamData sOamData_BoxTitle = { .shape = SPRITE_SHAPE(32x16), .size = SPRITE_SIZE(32x16), .priority = 2 }; -static const union AnimCmd gSpriteAnim_83BB2A0[] = +static const union AnimCmd sAnim_BoxTitle_Left[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_83BB2A8[] = +static const union AnimCmd sAnim_BoxTitle_Right[] = { ANIMCMD_FRAME(8, 5), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_83BB2B0[] = +static const union AnimCmd *const sAnims_BoxTitle[] = { - gSpriteAnim_83BB2A0, - gSpriteAnim_83BB2A8 + sAnim_BoxTitle_Left, + sAnim_BoxTitle_Right }; -static const struct SpriteTemplate gSpriteTemplate_857B0A8 = +static const struct SpriteTemplate sSpriteTemplate_BoxTitle = { - TAG_TILE_3, - TAG_PAL_DAC9, - &gOamData_83BB298, - gSpriteAnimTable_83BB2B0, - NULL, - gDummySpriteAffineAnimTable, - SpriteCallbackDummy + .tileTag = GFXTAG_BOX_TITLE, + .paletteTag = PALTAG_BOX_TITLE, + .oam = &sOamData_BoxTitle, + .anims = sAnims_BoxTitle, + .images NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy }; -static const struct OamData gOamData_83BB2D0 = +static const struct OamData sOamData_Arrow = { .shape = SPRITE_SHAPE(8x16), .size = SPRITE_SIZE(8x16), .priority = 2 }; -static const union AnimCmd gSpriteAnim_83BB2D8[] = +static const union AnimCmd sAnim_Arrow_Left[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_83BB2E0[] = +static const union AnimCmd sAnim_Arrow_Right[] = { ANIMCMD_FRAME(2, 5), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_83BB2E8[] = +static const union AnimCmd *const sAnims_Arrow[] = { - gSpriteAnim_83BB2D8, - gSpriteAnim_83BB2E0 + sAnim_Arrow_Left, + sAnim_Arrow_Right }; -static const struct SpriteTemplate gUnknown_0857B0E0 = +static const struct SpriteTemplate sSpriteTemplate_Arrow = { - 6, - TAG_PAL_WAVEFORM, - &gOamData_83BB2D0, - gSpriteAnimTable_83BB2E8, - NULL, - gDummySpriteAffineAnimTable, - sub_80CD210 + .tileTag = GFXTAG_ARROW, + .paletteTag = TAG_PAL_WAVEFORM, + .oam = &sOamData_Arrow, + .anims = sAnims_Arrow, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_Arrow }; static const u16 gHandCursorPalette[] = INCBIN_U16("graphics/pokemon_storage/hand_cursor.gbapal"); @@ -1961,10 +1578,10 @@ void ResetPokemonStorageSystem(void) u8 *dest = StringCopy(GetBoxNamePtr(boxId), gText_Box); ConvertIntToDecimalStringN(dest, boxId + 1, STR_CONV_MODE_LEFT_ALIGN, 2); } + for (boxId = 0; boxId < TOTAL_BOXES_COUNT; boxId++) - { - SetBoxWallpaper(boxId, boxId % 4); - } + SetBoxWallpaper(boxId, boxId % (MAX_DEFAULT_WALLPAPER + 1)); + ResetWaldaWallpaper(); } @@ -2079,11 +1696,11 @@ static void sub_80C7958(u8 curBox) } for (i = 0; i < 2; i++) { - gUnknown_02039D04->unk_0020[i] = sub_80CD2E8(72 * i + 0x7c, 0x58, i, 0, gUnknown_02039D04->unk_0246); - if (gUnknown_02039D04->unk_0020[i]) + gUnknown_02039D04->arrowSprites[i] = CreateJumpBoxArrows(72 * i + 124, 88, i, 0, gUnknown_02039D04->unk_0246); + if (gUnknown_02039D04->arrowSprites[i]) { - gUnknown_02039D04->unk_0020[i]->data[0] = (i == 0 ? -1 : 1); - gUnknown_02039D04->unk_0020[i]->callback = sub_80C7CF4; + gUnknown_02039D04->arrowSprites[i]->data[0] = (i == 0 ? -1 : 1); + gUnknown_02039D04->arrowSprites[i]->callback = SpriteCB_JumpBoxArrow; } } sub_80C7BE4(); @@ -2107,8 +1724,8 @@ static void sub_80C7B14(void) } for (i = 0; i < 2; i++) { - if (gUnknown_02039D04->unk_0020[i]) - DestroySprite(gUnknown_02039D04->unk_0020[i]); + if (gUnknown_02039D04->arrowSprites[i]) + DestroySprite(gUnknown_02039D04->arrowSprites[i]); } } @@ -2156,7 +1773,7 @@ static void sub_80C7BE4(void) RemoveWindow(windowId); } -static void sub_80C7CF4(struct Sprite *sprite) +static void SpriteCB_JumpBoxArrow(struct Sprite *sprite) { if (++sprite->data[1] > 3) { @@ -2350,10 +1967,10 @@ static void Cb_InitPSS(u8 taskId) sub_80CA704(); break; case 8: - sub_80CC32C(StorageGetCurrentBox()); + CreateInitBoxTask(StorageGetCurrentBox()); break; case 9: - if (sub_80CC35C()) + if (IsInitBoxActive()) return; if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) @@ -2765,8 +2382,8 @@ static void Cb_OnSelectedMon(u8 taskId) sPSSData->state = 1; } break; - case 1: // debug? - if (!sub_80D00A8()) + case 1: + if (!IsMenuLoading()) sPSSData->state = 2; break; case 2: @@ -3553,7 +3170,7 @@ static void Cb_HandleBoxOptions(u8 taskId) sPSSData->state++; break; case 1: - if (sub_80D00A8()) + if (IsMenuLoading()) return; sPSSData->state++; case 2: @@ -3561,7 +3178,7 @@ static void Cb_HandleBoxOptions(u8 taskId) { case MENU_B_PRESSED: case MENU_CANCEL: - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; @@ -3594,7 +3211,7 @@ static void Cb_HandleWallpapers(u8 taskId) sPSSData->state++; break; case 1: - if (!sub_80D00A8()) + if (!IsMenuLoading()) sPSSData->state++; break; case 2: @@ -3602,7 +3219,7 @@ static void Cb_HandleWallpapers(u8 taskId) switch (sPSSData->wallpaperSetId) { case MENU_B_PRESSED: - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; @@ -3612,13 +3229,13 @@ static void Cb_HandleWallpapers(u8 taskId) case MENU_ETCETERA: PlaySE(SE_SELECT); RemoveMenu(); - sPSSData->wallpaperSetId -= 18; + sPSSData->wallpaperSetId -= MENU_WALLPAPER_SETS_START; sPSSData->state++; break; case MENU_FRIENDS: // New wallpaper from Walda. PlaySE(SE_SELECT); - sPSSData->wallpaperId = 16; + sPSSData->wallpaperId = WALLPAPER_FRIENDS; RemoveMenu(); ClearBottomWindow(); sPSSData->state = 6; @@ -3655,7 +3272,7 @@ static void Cb_HandleWallpapers(u8 taskId) case 5: if (!DoWallpaperGfxChange()) { - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); SetPSSCallback(Cb_MainPSS); } break; @@ -3691,7 +3308,7 @@ static void Cb_JumpBox(u8 taskId) sub_80C7890(); if (sPSSData->newCurrBoxId == 201 || sPSSData->newCurrBoxId == StorageGetCurrentBox()) { - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); SetPSSCallback(Cb_MainPSS); } else @@ -4493,25 +4110,25 @@ static void AddWallpapersMenu(u8 wallpaperSet) InitMenu(); switch (wallpaperSet) { - case 0: + case MENU_SCENERY_1 - MENU_WALLPAPER_SETS_START: SetMenuText(MENU_FOREST); SetMenuText(MENU_CITY); SetMenuText(MENU_DESERT); SetMenuText(MENU_SAVANNA); break; - case 1: + case MENU_SCENERY_2 - MENU_WALLPAPER_SETS_START: SetMenuText(MENU_CRAG); SetMenuText(MENU_VOLCANO); SetMenuText(MENU_SNOW); SetMenuText(MENU_CAVE); break; - case 2: + case MENU_SCENERY_3 - MENU_WALLPAPER_SETS_START: SetMenuText(MENU_BEACH); SetMenuText(MENU_SEAFLOOR); SetMenuText(MENU_RIVER); SetMenuText(MENU_SKY); break; - case 3: + case MENU_ETCETERA - MENU_WALLPAPER_SETS_START: SetMenuText(MENU_POLKADOT); SetMenuText(MENU_POKECENTER); SetMenuText(MENU_MACHINE); @@ -4576,7 +4193,7 @@ static void CreateMovingMonIcon(void) sPSSData->movingMonSprite->callback = sub_80CC100; } -static void sub_80CB028(u8 boxId) +static void InitBoxMonSprites(u8 boxId) { u8 boxPosition; u16 i, j, count; @@ -4585,6 +4202,8 @@ static void sub_80CB028(u8 boxId) count = 0; boxPosition = 0; + + // For each box slot, create a Pokémon icon if a species is present for (i = 0; i < IN_BOX_COLUMNS; i++) { for (j = 0; j < IN_BOX_ROWS; j++) @@ -4604,11 +4223,12 @@ static void sub_80CB028(u8 boxId) } } + // If in item mode, set all Pokémon icons with no item to be transparent if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) { for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++) { - if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == 0) + if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; } } @@ -5260,59 +4880,67 @@ static void DestroyBoxMonIcon(struct Sprite *sprite) DestroySprite(sprite); } -static void sub_80CC32C(u8 boxId) +#define tState data[0] +#define tDmaIdx data[1] +#define tBoxId data[2] + +static void CreateInitBoxTask(u8 boxId) { - u8 taskId = CreateTask(sub_80CC370, 2); + u8 taskId = CreateTask(Task_InitBox, 2); - gTasks[taskId].data[2] = boxId; + gTasks[taskId].tBoxId = boxId; } -static bool8 sub_80CC35C(void) +static bool8 IsInitBoxActive(void) { - return FuncIsActiveTask(sub_80CC370); + return FuncIsActiveTask(Task_InitBox); } -static void sub_80CC370(u8 taskId) +static void Task_InitBox(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: - sPSSData->field_2D2 = 0; + sPSSData->wallpaperOffset = 0; sPSSData->bg2_X = 0; - task->data[1] = RequestDma3Fill(0, sPSSData->field_4AC4, 0x1000, 1); + task->tDmaIdx = RequestDma3Fill(0, sPSSData->wallpaperBgTilemapBuffer, sizeof(sPSSData->wallpaperBgTilemapBuffer), 1); break; case 1: - if (CheckForSpaceForDma3Request(task->data[1]) == -1) + if (CheckForSpaceForDma3Request(task->tDmaIdx) == -1) return; - SetBgTilemapBuffer(2, sPSSData->field_4AC4); + SetBgTilemapBuffer(2, sPSSData->wallpaperBgTilemapBuffer); ShowBg(2); break; case 2: - LoadWallpaperGfx(task->data[2], 0); + LoadWallpaperGfx(task->tBoxId, 0); break; case 3: if (!WaitForWallpaperGfxLoad()) return; - sub_80CCB50(task->data[2]); - sub_80CD02C(); - sub_80CB028(task->data[2]); + InitBoxTitle(task->tBoxId); + CreateBoxScrollArrows(); + InitBoxMonSprites(task->tBoxId); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(27) | BGCNT_TXT512x256); break; case 4: DestroyTask(taskId); break; default: - task->data[0] = 0; + task->tState = 0; return; } - task->data[0]++; + task->tState++; } +#undef tState +#undef tDmaIdx +#undef tBoxId + static void SetUpScrollToBox(u8 boxId) { s8 direction = DetermineBoxScrollDirection(boxId); @@ -5320,34 +4948,35 @@ static void SetUpScrollToBox(u8 boxId) sPSSData->wallpaperScrollSpeed = (direction > 0) ? 6 : -6; sPSSData->field_2D3 = (direction > 0) ? 1 : 2; sPSSData->field_2D0 = 32; - sPSSData->field_2D4 = boxId; + sPSSData->scrollToBoxIdUnused = boxId; sPSSData->field_2D6 = (direction <= 0) ? 5 : 0; - sPSSData->field_2D8 = direction; + sPSSData->scrollDirectionUnused = direction; + sPSSData->field_2DA = (direction > 0) ? 264 : 56; sPSSData->field_2DC = (direction <= 0) ? 5 : 0; sPSSData->field_2DE = 0; sPSSData->field_2E0 = 2; - sPSSData->boxScrollDestination = boxId; - sPSSData->field_A65 = direction; - sPSSData->field_A63 = 0; + sPSSData->scrollToBoxId = boxId; + sPSSData->scrollDirection = direction; + sPSSData->scrollState = 0; } static bool8 ScrollToBox(void) { bool8 var; - switch (sPSSData->field_A63) + switch (sPSSData->scrollState) { case 0: - LoadWallpaperGfx(sPSSData->boxScrollDestination, sPSSData->field_A65); - sPSSData->field_A63++; + LoadWallpaperGfx(sPSSData->scrollToBoxId, sPSSData->scrollDirection); + sPSSData->scrollState++; case 1: if (!WaitForWallpaperGfxLoad()) return TRUE; - sub_80CB4CC(sPSSData->boxScrollDestination, sPSSData->field_A65); - sub_80CCCFC(sPSSData->boxScrollDestination, sPSSData->field_A65); - sub_80CD0B8(sPSSData->field_A65); + sub_80CB4CC(sPSSData->scrollToBoxId, sPSSData->scrollDirection); + CreateIncomingBoxTitle(sPSSData->scrollToBoxId, sPSSData->scrollDirection); + StartBoxScrollArrowsSlide(sPSSData->scrollDirection); break; case 2: var = sub_80CB584(); @@ -5356,13 +4985,13 @@ static bool8 ScrollToBox(void) sPSSData->bg2_X += sPSSData->wallpaperScrollSpeed; if (--sPSSData->field_2D0 != 0) return TRUE; - sub_80CCEE0(); - sub_80CD158(); + CycleBoxTitleSprites(); + StopBoxScrollArrowsSlide(); } return var; } - sPSSData->field_A63++; + sPSSData->scrollState++; return TRUE; } @@ -5393,7 +5022,7 @@ static bool8 DoWallpaperGfxChange(void) switch (sPSSData->wallpaperChangeState) { case 0: - BeginNormalPaletteFade(sPSSData->field_738, 1, 0, 16, RGB_WHITEALPHA); + BeginNormalPaletteFade(sPSSData->boxTitlePalBits, 1, 0, 16, RGB_WHITEALPHA); sPSSData->wallpaperChangeState++; break; case 1: @@ -5407,8 +5036,8 @@ static bool8 DoWallpaperGfxChange(void) case 2: if (WaitForWallpaperGfxLoad() == TRUE) { - sub_80CCF9C(); - BeginNormalPaletteFade(sPSSData->field_738, 1, 16, 0, RGB_WHITEALPHA); + CycleBoxTitleColor(); + BeginNormalPaletteFade(sPSSData->boxTitlePalBits, 1, 16, 0, RGB_WHITEALPHA); sPSSData->wallpaperChangeState++; } break; @@ -5426,54 +5055,54 @@ static bool8 DoWallpaperGfxChange(void) static void LoadWallpaperGfx(u8 boxId, s8 direction) { u8 wallpaperId; - const struct WallpaperTable *wallpaperGfx; + const struct Wallpaper *wallpaper; void *iconGfx; - u32 size1, size2; + u32 tilesSize, iconSize; - sPSSData->field_6F9 = 0; - sPSSData->field_6FA = boxId; - sPSSData->field_6FB = direction; - if (sPSSData->field_6FB != 0) + sPSSData->wallpaperLoadState = 0; + sPSSData->wallpaperLoadBoxId = boxId; + sPSSData->wallpaperLoadDir = direction; + if (sPSSData->wallpaperLoadDir != 0) { - sPSSData->field_2D2 = (sPSSData->field_2D2 == 0); - sub_80CCAE0(sPSSData->field_4AC4); + sPSSData->wallpaperOffset = (sPSSData->wallpaperOffset == 0); + TrimOldWallpaper(sPSSData->wallpaperBgTilemapBuffer); } - wallpaperId = GetBoxWallpaper(sPSSData->field_6FA); + wallpaperId = GetBoxWallpaper(sPSSData->wallpaperLoadBoxId); if (wallpaperId != WALLPAPER_FRIENDS) { - wallpaperGfx = &gWallpaperTable[wallpaperId]; - LZ77UnCompWram(wallpaperGfx->tileMap, sPSSData->field_792); - sub_80CCA3C(sPSSData->field_792, sPSSData->field_6FB, sPSSData->field_2D2); + wallpaper = &sWallpapers[wallpaperId]; + LZ77UnCompWram(wallpaper->tilemap, sPSSData->wallpaperTilemap); + DrawWallpaper(sPSSData->wallpaperTilemap, sPSSData->wallpaperLoadDir, sPSSData->wallpaperOffset); - if (sPSSData->field_6FB != 0) - LoadPalette(wallpaperGfx->palettes, (sPSSData->field_2D2 * 32) + 0x40, 0x40); + if (sPSSData->wallpaperLoadDir != 0) + LoadPalette(wallpaper->palettes, (sPSSData->wallpaperOffset * 32) + 0x40, 0x40); else - CpuCopy16(wallpaperGfx->palettes, &gPlttBufferUnfaded[(sPSSData->field_2D2 * 32) + 0x40], 0x40); + CpuCopy16(wallpaper->palettes, &gPlttBufferUnfaded[(sPSSData->wallpaperOffset * 32) + 0x40], 0x40); - sPSSData->wallpaperTiles = malloc_and_decompress(wallpaperGfx->tiles, &size1); - LoadBgTiles(2, sPSSData->wallpaperTiles, size1, sPSSData->field_2D2 << 8); + sPSSData->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); + LoadBgTiles(2, sPSSData->wallpaperTiles, tilesSize, sPSSData->wallpaperOffset << 8); } else { - wallpaperGfx = &gFriendsWallpaperTable[GetWaldaWallpaperPatternId()]; - LZ77UnCompWram(wallpaperGfx->tileMap, sPSSData->field_792); - sub_80CCA3C(sPSSData->field_792, sPSSData->field_6FB, sPSSData->field_2D2); + wallpaper = &sWaldaWallpapers[GetWaldaWallpaperPatternId()]; + LZ77UnCompWram(wallpaper->tilemap, sPSSData->wallpaperTilemap); + DrawWallpaper(sPSSData->wallpaperTilemap, sPSSData->wallpaperLoadDir, sPSSData->wallpaperOffset); - CpuCopy16(wallpaperGfx->palettes, sPSSData->field_792, 0x40); - CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->field_792[1], 4); - CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->field_792[17], 4); + CpuCopy16(wallpaper->palettes, sPSSData->wallpaperTilemap, 0x40); + CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->wallpaperTilemap[1], 4); + CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->wallpaperTilemap[17], 4); - if (sPSSData->field_6FB != 0) - LoadPalette(sPSSData->field_792, (sPSSData->field_2D2 * 32) + 0x40, 0x40); + if (sPSSData->wallpaperLoadDir != 0) + LoadPalette(sPSSData->wallpaperTilemap, (sPSSData->wallpaperOffset * 32) + 0x40, 0x40); else - CpuCopy16(sPSSData->field_792, &gPlttBufferUnfaded[(sPSSData->field_2D2 * 32) + 0x40], 0x40); + CpuCopy16(sPSSData->wallpaperTilemap, &gPlttBufferUnfaded[(sPSSData->wallpaperOffset * 32) + 0x40], 0x40); - sPSSData->wallpaperTiles = malloc_and_decompress(wallpaperGfx->tiles, &size1); - iconGfx = malloc_and_decompress(gFriendsIcons[GetWaldaWallpaperIconId()], &size2); - CpuCopy32(iconGfx, sPSSData->wallpaperTiles + 0x800, size2); + sPSSData->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); + iconGfx = malloc_and_decompress(sWaldaWallpaperIcons[GetWaldaWallpaperIconId()], &iconSize); + CpuCopy32(iconGfx, sPSSData->wallpaperTiles + 0x800, iconSize); Free(iconGfx); - LoadBgTiles(2, sPSSData->wallpaperTiles, size1, sPSSData->field_2D2 << 8); + LoadBgTiles(2, sPSSData->wallpaperTiles, tilesSize, sPSSData->wallpaperOffset << 8); } CopyBgTilemapBufferToVram(2); @@ -5492,12 +5121,12 @@ static bool32 WaitForWallpaperGfxLoad(void) return TRUE; } -static void sub_80CCA3C(const void *tilemap, s8 direction, u8 arg2) +static void DrawWallpaper(const void *tilemap, s8 direction, u8 offset) { - s16 var = (arg2 * 2) + 3; + s16 var = (offset * 2) + 3; s16 x = ((sPSSData->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; - CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, arg2 << 8, var); + CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, offset << 8, var); if (direction == 0) return; @@ -5509,10 +5138,10 @@ static void sub_80CCA3C(const void *tilemap, s8 direction, u8 arg2) FillBgTilemapBufferRect(2, 0, x, 2, 4, 0x12, 0x11); } -static void sub_80CCAE0(void *arg0) +static void TrimOldWallpaper(void *tilemap) { u16 i; - u16 *dest = arg0; + u16 *dest = tilemap; s16 r3 = ((sPSSData->bg2_X / 8) + 30) & 0x3F; if (r3 <= 31) @@ -5531,238 +5160,266 @@ static void sub_80CCAE0(void *arg0) } } -static void sub_80CCB50(u8 boxId) +static void InitBoxTitle(u8 boxId) { u8 tagIndex; - s16 r6; + s16 x; u16 i; - struct SpriteSheet spriteSheet = {sPSSData->field_2F8, 0x200, TAG_TILE_3}; + struct SpriteSheet spriteSheet = {sPSSData->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; struct SpritePalette palettes[] = { - {sPSSData->field_6FC, TAG_PAL_DAC9}, + {sPSSData->boxTitlePal, PALTAG_BOX_TITLE}, {} }; u16 wallpaperId = GetBoxWallpaper(boxId); - sPSSData->field_6FC[14] = gUnknown_08577574[wallpaperId][0]; - sPSSData->field_6FC[15] = gUnknown_08577574[wallpaperId][1]; + sPSSData->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; // Shadow color + sPSSData->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; // Text Color LoadSpritePalettes(palettes); - sPSSData->field_738 = 0x3f0; - - tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9); - sPSSData->field_71C = 0x10e + 16 * tagIndex; - sPSSData->field_738 |= 0x10000 << tagIndex; - - tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9); - sPSSData->field_71E = 0x10e + 16 * tagIndex; - sPSSData->field_738 |= 0x10000 << tagIndex; - - StringCopyPadded(sPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(sPSSData->field_21B8, sPSSData->field_2F8, 0, 0, 2); + sPSSData->boxTitlePalBits = 0x3f0; + + tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); + sPSSData->boxTitlePalOffset = 0x10e + 16 * tagIndex; + sPSSData->boxTitlePalBits |= 0x10000 << tagIndex; + + // The below seems intended to have separately tracked + // the incoming wallpaper title's palette, but as they now + // share a palette tag, all colors (and fields in some cases) + // this is redundant along with the use of boxTitleAltPalOffset + tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); + sPSSData->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; + sPSSData->boxTitlePalBits |= 0x10000 << tagIndex; + + StringCopyPadded(sPSSData->boxTitleText, GetBoxNamePtr(boxId), 0, 8); + DrawTextWindowAndBufferTiles(sPSSData->boxTitleText, sPSSData->boxTitleTiles, 0, 0, 2); LoadSpriteSheet(&spriteSheet); - r6 = sub_80CD00C(GetBoxNamePtr(boxId)); + x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); + // Title is split across two sprites for (i = 0; i < 2; i++) { - u8 spriteId = CreateSprite(&gSpriteTemplate_857B0A8, r6 + i * 32, 28, 24); - sPSSData->field_720[i] = &gSprites[spriteId]; - StartSpriteAnim(sPSSData->field_720[i], i); + u8 spriteId = CreateSprite(&sSpriteTemplate_BoxTitle, x + i * 32, 28, 24); + sPSSData->curBoxTitleSprites[i] = &gSprites[spriteId]; + StartSpriteAnim(sPSSData->curBoxTitleSprites[i], i); } - sPSSData->field_6F8 = 0; + sPSSData->boxTitleCycleId = 0; } -static void sub_80CCCFC(u8 boxId, s8 direction) +// Sprite data for moving title text +#define sSpeed data[0] +// Flipped between incoming/outgoing for some reason +#define sIncomingX data[1] +#define sIncomingDelay data[2] +#define sOutgoingDelay data[1] +#define sOutgoingX data[2] + +static void CreateIncomingBoxTitle(u8 boxId, s8 direction) { - u16 r8; - s16 x, x2; + u16 palOffset; + s16 x, adjustedX; u16 i; - struct SpriteSheet spriteSheet = {sPSSData->field_2F8, 0x200, TAG_TILE_3}; - struct SpriteTemplate template = gSpriteTemplate_857B0A8; + struct SpriteSheet spriteSheet = {sPSSData->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; + struct SpriteTemplate template = sSpriteTemplate_BoxTitle; - sPSSData->field_6F8 = (sPSSData->field_6F8 == 0); - if (sPSSData->field_6F8 == 0) + sPSSData->boxTitleCycleId = (sPSSData->boxTitleCycleId == 0); + if (sPSSData->boxTitleCycleId == 0) { - spriteSheet.tag = TAG_TILE_3; - r8 = sPSSData->field_71C; + spriteSheet.tag = GFXTAG_BOX_TITLE; + palOffset = sPSSData->boxTitlePalOffset; } else { - spriteSheet.tag = TAG_TILE_4; - r8 = sPSSData->field_71C; - template.tileTag = TAG_TILE_4; - template.paletteTag = TAG_PAL_DAC9; + spriteSheet.tag = GFXTAG_BOX_TITLE_ALT; + palOffset = sPSSData->boxTitlePalOffset; + template.tileTag = GFXTAG_BOX_TITLE_ALT; + template.paletteTag = PALTAG_BOX_TITLE; } - StringCopyPadded(sPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(sPSSData->field_21B8, sPSSData->field_2F8, 0, 0, 2); + StringCopyPadded(sPSSData->boxTitleText, GetBoxNamePtr(boxId), 0, 8); + DrawTextWindowAndBufferTiles(sPSSData->boxTitleText, sPSSData->boxTitleTiles, 0, 0, 2); LoadSpriteSheet(&spriteSheet); - LoadPalette(gUnknown_08577574[GetBoxWallpaper(boxId)], r8, 4); - x = sub_80CD00C(GetBoxNamePtr(boxId)); - x2 = x; - x2 += direction * 192; + LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], palOffset, 4); + x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); + adjustedX = x; + adjustedX += direction * 192; + // Title is split across two sprites for (i = 0; i < 2; i++) { - u8 spriteId = CreateSprite(&template, i * 32 + x2, 28, 24); + u8 spriteId = CreateSprite(&template, i * 32 + adjustedX, 28, 24); - sPSSData->field_728[i] = &gSprites[spriteId]; - sPSSData->field_728[i]->data[0] = (-direction) * 6; - sPSSData->field_728[i]->data[1] = i * 32 + x; - sPSSData->field_728[i]->data[2] = 0; - sPSSData->field_728[i]->callback = sub_80CCF30; - StartSpriteAnim(sPSSData->field_728[i], i); + sPSSData->nextBoxTitleSprites[i] = &gSprites[spriteId]; + sPSSData->nextBoxTitleSprites[i]->sSpeed = (-direction) * 6; + sPSSData->nextBoxTitleSprites[i]->sIncomingX = i * 32 + x; + sPSSData->nextBoxTitleSprites[i]->sIncomingDelay = 0; + sPSSData->nextBoxTitleSprites[i]->callback = SpriteCB_IncomingBoxTitle; + StartSpriteAnim(sPSSData->nextBoxTitleSprites[i], i); - sPSSData->field_720[i]->data[0] = (-direction) * 6; - sPSSData->field_720[i]->data[1] = 1; - sPSSData->field_720[i]->callback = sub_80CCF64; + sPSSData->curBoxTitleSprites[i]->sSpeed = (-direction) * 6; + sPSSData->curBoxTitleSprites[i]->sOutgoingDelay = 1; + sPSSData->curBoxTitleSprites[i]->callback = SpriteCB_OutgoingBoxTitle; } } -static void sub_80CCEE0(void) +static void CycleBoxTitleSprites(void) { - if (sPSSData->field_6F8 == 0) - FreeSpriteTilesByTag(TAG_TILE_4); + if (sPSSData->boxTitleCycleId == 0) + FreeSpriteTilesByTag(GFXTAG_BOX_TITLE_ALT); else - FreeSpriteTilesByTag(TAG_TILE_3); + FreeSpriteTilesByTag(GFXTAG_BOX_TITLE); - sPSSData->field_720[0] = sPSSData->field_728[0]; - sPSSData->field_720[1] = sPSSData->field_728[1]; + sPSSData->curBoxTitleSprites[0] = sPSSData->nextBoxTitleSprites[0]; + sPSSData->curBoxTitleSprites[1] = sPSSData->nextBoxTitleSprites[1]; } -static void sub_80CCF30(struct Sprite *sprite) +static void SpriteCB_IncomingBoxTitle(struct Sprite *sprite) { - if (sprite->data[2] != 0) - sprite->data[2]--; - else if ((sprite->pos1.x += sprite->data[0]) == sprite->data[1]) + if (sprite->sIncomingDelay != 0) + sprite->sIncomingDelay--; + else if ((sprite->pos1.x += sprite->sSpeed) == sprite->sIncomingX) sprite->callback = SpriteCallbackDummy; } -static void sub_80CCF64(struct Sprite *sprite) +static void SpriteCB_OutgoingBoxTitle(struct Sprite *sprite) { - if (sprite->data[1] != 0) + if (sprite->sOutgoingDelay != 0) { - sprite->data[1]--; + sprite->sOutgoingDelay--; } else { - sprite->pos1.x += sprite->data[0]; - sprite->data[2] = sprite->pos1.x + sprite->pos2.x; - if (sprite->data[2] < 0x40 || sprite->data[2] > 0x100) + sprite->pos1.x += sprite->sSpeed; + sprite->sOutgoingX = sprite->pos1.x + sprite->pos2.x; + if (sprite->sOutgoingX < 64 || sprite->sOutgoingX > DISPLAY_WIDTH + 16) DestroySprite(sprite); } } -static void sub_80CCF9C(void) +#undef sSpeed +#undef sIncomingX +#undef sIncomingDelay +#undef sOutgoingDelay +#undef sOutgoingX + +static void CycleBoxTitleColor(void) { u8 boxId = StorageGetCurrentBox(); u8 wallpaperId = GetBoxWallpaper(boxId); - if (sPSSData->field_6F8 == 0) - CpuCopy16(gUnknown_08577574[wallpaperId], gPlttBufferUnfaded + sPSSData->field_71C, 4); + if (sPSSData->boxTitleCycleId == 0) + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sPSSData->boxTitlePalOffset, 4); else - CpuCopy16(gUnknown_08577574[wallpaperId], gPlttBufferUnfaded + sPSSData->field_71E, 4); + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sPSSData->boxTitleAltPalOffset, 4); } -static s16 sub_80CD00C(const u8 *string) +static s16 GetBoxTitleBaseX(const u8 *string) { - return 0xB0 - GetStringWidth(1, string, 0) / 2; + return DISPLAY_WIDTH - 64 - GetStringWidth(1, string, 0) / 2; } -static void sub_80CD02C(void) +// Sprite data for box scroll arrows +#define sState data[0] +#define sTimer data[1] +#define sSpeed data[3] + +static void CreateBoxScrollArrows(void) { u16 i; - LoadSpriteSheet(&gUnknown_0857B080); + LoadSpriteSheet(&sSpriteSheet_Arrow); for (i = 0; i < 2; i++) { - u8 spriteId = CreateSprite(&gUnknown_0857B0E0, 0x5c + i * 0x88, 28, 22); + u8 spriteId = CreateSprite(&sSpriteTemplate_Arrow, 92 + i * 136, 28, 22); if (spriteId != MAX_SPRITES) { struct Sprite *sprite = &gSprites[spriteId]; StartSpriteAnim(sprite, i); - sprite->data[3] = (i == 0) ? -1 : 1; - sPSSData->field_730[i] = sprite; + sprite->sSpeed = (i == 0) ? -1 : 1; + sPSSData->arrowSprites[i] = sprite; } } if (IsCursorOnBox()) - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); } -static void sub_80CD0B8(s8 direction) +// Slide box scroll arrows horizontally for box change +static void StartBoxScrollArrowsSlide(s8 direction) { u16 i; for (i = 0; i < 2; i++) { - sPSSData->field_730[i]->pos2.x = 0; - sPSSData->field_730[i]->data[0] = 2; + sPSSData->arrowSprites[i]->pos2.x = 0; + sPSSData->arrowSprites[i]->sState = 2; } if (direction < 0) { - sPSSData->field_730[0]->data[1] = 29; - sPSSData->field_730[1]->data[1] = 5; - sPSSData->field_730[0]->data[2] = 0x48; - sPSSData->field_730[1]->data[2] = 0x48; + sPSSData->arrowSprites[0]->sTimer = 29; + sPSSData->arrowSprites[1]->sTimer = 5; + sPSSData->arrowSprites[0]->data[2] = 72; + sPSSData->arrowSprites[1]->data[2] = 72; } else { - sPSSData->field_730[0]->data[1] = 5; - sPSSData->field_730[1]->data[1] = 29; - sPSSData->field_730[0]->data[2] = 0xF8; - sPSSData->field_730[1]->data[2] = 0xF8; + sPSSData->arrowSprites[0]->sTimer = 5; + sPSSData->arrowSprites[1]->sTimer = 29; + sPSSData->arrowSprites[0]->data[2] = DISPLAY_WIDTH + 8; + sPSSData->arrowSprites[1]->data[2] = DISPLAY_WIDTH + 8; } - sPSSData->field_730[0]->data[7] = 0; - sPSSData->field_730[1]->data[7] = 1; + sPSSData->arrowSprites[0]->data[7] = 0; + sPSSData->arrowSprites[1]->data[7] = 1; } -static void sub_80CD158(void) +// New box's scroll arrows have entered, stop sliding and set their position +static void StopBoxScrollArrowsSlide(void) { u16 i; for (i = 0; i < 2; i++) { - sPSSData->field_730[i]->pos1.x = 0x88 * i + 0x5c; - sPSSData->field_730[i]->pos2.x = 0; - sPSSData->field_730[i]->invisible = FALSE; + sPSSData->arrowSprites[i]->pos1.x = 136 * i + 92; + sPSSData->arrowSprites[i]->pos2.x = 0; + sPSSData->arrowSprites[i]->invisible = FALSE; } - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); } -static void sub_80CD1A8(bool8 a0) +// Bounce scroll arrows while title is selected +static void AnimateBoxScrollArrows(bool8 animate) { u16 i; - if (a0) + if (animate) { + // Start arrows moving for (i = 0; i < 2; i++) { - sPSSData->field_730[i]->data[0] = 1; - sPSSData->field_730[i]->data[1] = 0; - sPSSData->field_730[i]->data[2] = 0; - sPSSData->field_730[i]->data[4] = 0; + sPSSData->arrowSprites[i]->sState = 1; + sPSSData->arrowSprites[i]->sTimer = 0; + sPSSData->arrowSprites[i]->data[2] = 0; + sPSSData->arrowSprites[i]->data[4] = 0; } } else { + // Stop arrows moving for (i = 0; i < 2; i++) - { - sPSSData->field_730[i]->data[0] = 0; - } + sPSSData->arrowSprites[i]->sState = 0; } } -static void sub_80CD210(struct Sprite *sprite) +static void SpriteCB_Arrow(struct Sprite *sprite) { - switch (sprite->data[0]) + switch (sprite->sState) { case 0: sprite->pos2.x = 0; break; case 1: - if (++sprite->data[1] > 3) + if (++sprite->sTimer > 3) { - sprite->data[1] = 0; - sprite->pos2.x += sprite->data[3]; + sprite->sTimer = 0; + sprite->pos2.x += sprite->sSpeed; if (++sprite->data[2] > 5) { sprite->data[2] = 0; @@ -5771,17 +5428,17 @@ static void sub_80CD210(struct Sprite *sprite) } break; case 2: - sprite->data[0] = 3; + sprite->sState = 3; break; case 3: sprite->pos1.x -= sPSSData->wallpaperScrollSpeed; - if (sprite->pos1.x < 73 || sprite->pos1.x > 247) + if (sprite->pos1.x <= 72 || sprite->pos1.x >= DISPLAY_WIDTH + 8) sprite->invisible = TRUE; - if (--sprite->data[1] == 0) + if (--sprite->sTimer == 0) { sprite->pos1.x = sprite->data[2]; sprite->invisible = FALSE; - sprite->data[0] = 4; + sprite->sState = 4; } break; case 4: @@ -5790,9 +5447,12 @@ static void sub_80CD210(struct Sprite *sprite) } } -static struct Sprite *sub_80CD2E8(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) +#undef sState +#undef sSpeed + +static struct Sprite *CreateJumpBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) { - u8 spriteId = CreateSprite(&gUnknown_0857B0E0, x, y, subpriority); + u8 spriteId = CreateSprite(&sSpriteTemplate_Arrow, x, y, subpriority); if (spriteId == MAX_SPRITES) return NULL; @@ -5905,25 +5565,25 @@ static bool8 sub_80CD554(void) sPSSData->field_CC0 += sPSSData->field_CC8; sPSSData->field_CB4->pos1.x = sPSSData->field_CBC >> 8; sPSSData->field_CB4->pos1.y = sPSSData->field_CC0 >> 8; - if (sPSSData->field_CB4->pos1.x > 0x100) + if (sPSSData->field_CB4->pos1.x > DISPLAY_WIDTH + 16) { - tmp = sPSSData->field_CB4->pos1.x - 0x100; - sPSSData->field_CB4->pos1.x = tmp + 0x40; + tmp = sPSSData->field_CB4->pos1.x - (DISPLAY_WIDTH + 16); + sPSSData->field_CB4->pos1.x = tmp + 64; } - if (sPSSData->field_CB4->pos1.x < 0x40) + if (sPSSData->field_CB4->pos1.x < 64) { - tmp = 0x40 - sPSSData->field_CB4->pos1.x; - sPSSData->field_CB4->pos1.x = 0x100 - tmp; + tmp = 64 - sPSSData->field_CB4->pos1.x; + sPSSData->field_CB4->pos1.x = DISPLAY_WIDTH + 16 - tmp; } - if (sPSSData->field_CB4->pos1.y > 0xb0) + if (sPSSData->field_CB4->pos1.y > DISPLAY_HEIGHT + 16) { - tmp = sPSSData->field_CB4->pos1.y - 0xb0; - sPSSData->field_CB4->pos1.y = tmp - 0x10; + tmp = sPSSData->field_CB4->pos1.y - (DISPLAY_HEIGHT + 16); + sPSSData->field_CB4->pos1.y = tmp - 16; } - if (sPSSData->field_CB4->pos1.y < -0x10) + if (sPSSData->field_CB4->pos1.y < -16) { - tmp = -0x10 - sPSSData->field_CB4->pos1.y; - sPSSData->field_CB4->pos1.y = 0xb0 - tmp; + tmp = -16 - sPSSData->field_CB4->pos1.y; + sPSSData->field_CB4->pos1.y = DISPLAY_HEIGHT + 16 - tmp; } if (sPSSData->field_CD7 && --sPSSData->field_CD7 == 0) sPSSData->field_CB4->vFlip = (sPSSData->field_CB4->vFlip == FALSE); @@ -6076,7 +5736,7 @@ static void sub_80CDA68(void) SetMovingMonPriority(1); break; case CURSOR_AREA_BOX: - sub_80CD1A8(TRUE); + AnimateBoxScrollArrows(TRUE); break; case CURSOR_AREA_IN_PARTY: sPSSData->field_CB8->subpriority = 13; @@ -7426,7 +7086,7 @@ static u8 HandleInput_OnBox(void) if (JOY_NEW(A_BUTTON)) { - sub_80CD1A8(FALSE); + AnimateBoxScrollArrows(FALSE); AddBoxMenu(); return 7; } @@ -7447,7 +7107,7 @@ static u8 HandleInput_OnBox(void) if (retVal) { if (cursorArea != CURSOR_AREA_BOX) - sub_80CD1A8(FALSE); + AnimateBoxScrollArrows(FALSE); sub_80CD894(cursorArea, cursorPosition); } @@ -7948,7 +7608,10 @@ static void AddMenu(void) sPSSData->field_CAE = 0; } -static bool8 sub_80D00A8(void) +// Called after AddMenu to determine whether or not the handler callback should +// wait to move on to the next state. Evidently there was no need to wait, and +// now it always returns FALSE +static bool8 IsMenuLoading(void) { return FALSE; } @@ -9451,7 +9114,7 @@ u8 *GetBoxNamePtr(u8 boxId) return NULL; } -u8 GetBoxWallpaper(u8 boxId) +static u8 GetBoxWallpaper(u8 boxId) { if (boxId < TOTAL_BOXES_COUNT) return gPokemonStoragePtr->boxWallpapers[boxId]; @@ -9459,7 +9122,7 @@ u8 GetBoxWallpaper(u8 boxId) return 0; } -void SetBoxWallpaper(u8 boxId, u8 wallpaperId) +static void SetBoxWallpaper(u8 boxId, u8 wallpaperId) { if (boxId < TOTAL_BOXES_COUNT && wallpaperId < WALLPAPER_COUNT) gPokemonStoragePtr->boxWallpapers[boxId] = wallpaperId; @@ -9615,7 +9278,7 @@ u32 GetWaldaWallpaperIconId(void) void SetWaldaWallpaperIconId(u8 id) { - if (id < 30) + if (id < ARRAY_COUNT(sWaldaWallpaperIcons)) gSaveBlock1Ptr->waldaPhrase.iconId = id; } -- cgit v1.2.3 From 838a452363c1296e3c9a0d92ce41f59a75e9c844 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 17:31:50 -0400 Subject: Doc storage - choose box menu, move wallpaper gfx --- src/pokemon_storage_system.c | 1039 ++++++++++++++++++++++-------------------- 1 file changed, 538 insertions(+), 501 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 6bcc10afc..07e0931ed 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -42,12 +42,14 @@ #include "constants/rgb.h" #include "constants/songs.h" +// PC main menu options enum { - BOX_OPTION_WITHDRAW, - BOX_OPTION_DEPOSIT, - BOX_OPTION_MOVE_MONS, - BOX_OPTION_MOVE_ITEMS, - BOX_OPTION_EXIT, + OPTION_WITHDRAW, + OPTION_DEPOSIT, + OPTION_MOVE_MONS, + OPTION_MOVE_ITEMS, + OPTION_EXIT, + OPTIONS_COUNT }; // IDs for messages to print with PrintMessage @@ -85,6 +87,7 @@ enum { MSG_CANT_STORE_MAIL, }; +// Formatting for the above messages enum { MSG_FORMAT_NORMAL, MSG_FORMAT_MON_NAME_1, @@ -141,6 +144,37 @@ enum { #define MENU_WALLPAPER_SETS_START MENU_SCENERY_1 #define MENU_WALLPAPERS_START MENU_FOREST +// Return IDs for input handlers +enum { + INPUT_NONE, + INPUT_1, + INPUT_2, // Unused + INPUT_3, // Unused + INPUT_4, + INPUT_5, + INPUT_6, + INPUT_7, + INPUT_8, + INPUT_9, + INPUT_10, + INPUT_11, + INPUT_12, + INPUT_13, + INPUT_14, + INPUT_15, + INPUT_16, + INPUT_17, + INPUT_18, + INPUT_19, + INPUT_20, + INPUT_21, + INPUT_22, + INPUT_23, + INPUT_24, + INPUT_25, + INPUT_26, +}; + enum { SCREEN_CHANGE_EXIT_BOX, SCREEN_CHANGE_SUMMARY_SCREEN, @@ -154,26 +188,6 @@ enum { MODE_MOVE, }; -enum { - FRIENDS_ZIGZAGOON, - FRIENDS_SCREEN, - FRIENDS_HORIZONTAL, - FRIENDS_DIAGONAL, - FRIENDS_BLOCK, - FRIENDS_RIBBON, - FRIENDS_POKECENTER2, - FRIENDS_FRAME, - FRIENDS_BLANK, - FRIENDS_CIRCLES, - FRIENDS_AZUMARILL, - FRIENDS_PIKACHU, - FRIENDS_LEGENDARY, - FRIENDS_DUSCLOPS, - FRIENDS_LUDICOLO, - FRIENDS_WHISCASH, - FRIENDS_WALLPAPERS_COUNT -}; - enum { CURSOR_AREA_IN_BOX, CURSOR_AREA_IN_PARTY, @@ -181,27 +195,32 @@ enum { CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box }; +// Special box ids for the choose box menu +#define BOXID_NONE_CHOSEN 200 +#define BOXID_CANCELED 201 + #define TAG_PAL_WAVEFORM 0xDACA #define TAG_PAL_DAC8 0xDAC8 #define TAG_PAL_DAC6 0xDAC6 #define TAG_PAL_DACE 0xDACE #define TAG_PAL_DAC7 0xDAC7 -#define PALTAG_BOX_TITLE 0xDAC9 +#define PALTAG_BOX_TITLE 0xDAC9 #define TAG_PAL_DAC0 0xDAC0 #define TAG_PAL_DACB 0xDACB -#define TAG_TILE_0 0 -#define TAG_TILE_1 1 -#define TAG_TILE_2 2 -#define GFXTAG_BOX_TITLE 3 -#define GFXTAG_BOX_TITLE_ALT 4 -#define TAG_TILE_WAVEFORM 5 -#define GFXTAG_ARROW 6 -#define TAG_TILE_7 7 -#define TAG_TILE_A 10 -#define TAG_TILE_D 13 -#define TAG_TILE_10 16 -#define TAG_TILE_12 18 +#define TAG_TILE_0 0 +#define TAG_TILE_1 1 +#define TAG_TILE_2 2 +#define GFXTAG_BOX_TITLE 3 +#define GFXTAG_BOX_TITLE_ALT 4 +#define TAG_TILE_WAVEFORM 5 +#define GFXTAG_ARROW 6 +#define TAG_TILE_7 7 +#define GFXTAG_CHOOSE_BOX_MENU 10 +#define GFXTAG_CHOOSE_BOX_MENU_SIDES 11 // Used implicitly in LoadChooseBoxMenuGfx +#define TAG_TILE_D 13 +#define TAG_TILE_10 16 +#define TAG_TILE_12 18 struct Wallpaper @@ -229,12 +248,6 @@ struct StorageMenu int textId; }; -struct PSS_MenuStringPtrs -{ - const u8 *text; - const u8 *desc; -}; - struct UnkStruct_2000028 { const u8 *unk_00; @@ -252,19 +265,19 @@ struct UnkStruct_2000020 u8 unk_05; }; -struct UnkPSSStruct_2002370 +struct ChooseBoxMenu { - struct Sprite *unk_0000; - struct Sprite *unk_0004[4]; + struct Sprite *menuSprite; + struct Sprite *menuSideSprites[4]; u32 unk_0014[3]; struct Sprite *arrowSprites[2]; u8 filler_0028[0x214]; - u32 unk_023c; - u16 unk_0240; - u16 unk_0242; + bool32 loadedPalette; + u16 tileTag; + u16 paletteTag; u8 curBox; u8 unk_0245; - u8 unk_0246; + u8 subpriority; }; struct UnkStorageStruct @@ -297,7 +310,7 @@ struct PokemonStorageSystemData bool8 unk_02C9; s16 newCurrBoxId; u16 bg2_X; - s16 wallpaperScrollSpeed; + s16 scrollSpeed; u16 field_2D0; u8 wallpaperOffset; u8 field_2D3; // Written to, but never read. @@ -394,7 +407,7 @@ struct PokemonStorageSystemData struct Sprite *field_D98[2]; u16 *field_DA0; struct MonMarkingsMenu markMenu; - struct UnkPSSStruct_2002370 field_1E5C; + struct ChooseBoxMenu chooseBoxMenu; struct Pokemon movingMon; struct Pokemon field_2108; s8 field_216C; @@ -408,7 +421,7 @@ struct PokemonStorageSystemData u16 field_2176[8]; u8 field_2186; u8 field_2187; - u8 pokemonSummaryScreenMode; + u8 summaryScreenMode; union { struct Pokemon *mon; @@ -461,16 +474,14 @@ struct UnkStruct_2039D84 u8 field_2D; }; -// IWRAM bss static u32 gUnknown_03000F78[98]; -// EWRAM DATA EWRAM_DATA static u8 sPreviousBoxOption = 0; -EWRAM_DATA static struct UnkPSSStruct_2002370 *gUnknown_02039D04 = NULL; +EWRAM_DATA static struct ChooseBoxMenu *sChooseBoxMenu = NULL; EWRAM_DATA static struct PokemonStorageSystemData *sPSSData = NULL; EWRAM_DATA static bool8 sInPartyMenu = 0; EWRAM_DATA static u8 sCurrentBoxOption = 0; -EWRAM_DATA static u8 gUnknown_02039D0E = 0; +EWRAM_DATA static u8 sDepositBoxId = 0; EWRAM_DATA static u8 sWhichToReshow = 0; EWRAM_DATA static u8 sLastUsedBox = 0; EWRAM_DATA static u16 sMovingItemId = 0; @@ -482,8 +493,7 @@ EWRAM_DATA static u8 sMovingMonOrigBoxId = 0; EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0; EWRAM_DATA static bool8 sCanOnlyMove = 0; -// This file's functions. -static void CreatePCMenu(u8, s16 *); +static void CreateMainMenu(u8, s16 *); static void Cb2_EnterPSS(u8); static u8 GetCurrentBoxOption(void); static u8 HandleInput(void); @@ -494,13 +504,13 @@ static void CreateIncomingBoxTitle(u8, s8); static void StartBoxScrollArrowsSlide(s8); static void SetCurrentBox(u8); static void CreateInitBoxTask(u8); -static void sub_80C7958(u8); +static void ChooseBoxMenu_CreateSprites(u8); static void TrimOldWallpaper(void *); -static void sub_80C7B14(void); -static void sub_80C7BB4(void); +static void ChooseBoxMenu_DestroySprites(void); +static void ChooseBoxMenu_MoveLeft(void); static void ScrollBackground(void); -static void sub_80C7B80(void); -static void sub_80C7BE4(void); +static void ChooseBoxMenu_MoveRight(void); +static void ChooseBoxMenu_PrintInfo(void); static void sub_80CAA14(void); static void sub_80CFDC4(void); static void sub_80CE790(void); @@ -570,7 +580,7 @@ static void sub_80CB950(void); static void sub_80CA9C0(void); static void SetUpDoShowPartyMenu(void); static void BoxSetMosaic(void); -static void SpriteCB_JumpBoxArrow(struct Sprite *); +static void SpriteCB_ChooseBoxArrow(struct Sprite *); static void sub_80CC100(struct Sprite *); static void sub_80CB278(struct Sprite *); static void SpriteCB_Arrow(struct Sprite *); @@ -591,7 +601,7 @@ static bool8 ScrollToBox(void); static bool8 sub_80CD554(void); static bool8 HidePartyMenu(void); static bool8 IsActiveItemMoving(void); -static bool8 sub_80D0580(u8 arg0); +static bool8 sub_80D0580(u8); static bool8 sub_80D0BC0(void); static bool8 sub_80CA2B8(void); static bool8 DoWallpaperGfxChange(void); @@ -604,37 +614,37 @@ static bool8 IsCursorOnBox(void); static bool8 IsCursorInBox(void); static bool8 IsMonBeingMoved(void); static bool8 TryStorePartyMonInBox(u8); -static void Cb_InitPSS(u8 taskId); -static void Cb_PlaceMon(u8 taskId); -static void Cb_ChangeScreen(u8 taskId); -static void Cb_ShowPSS(u8 taskId); -static void Cb_OnBPressed(u8 taskId); -static void Cb_HandleBoxOptions(u8 taskId); -static void Cb_OnSelectedMon(u8 taskId); -static void Cb_OnCloseBoxPressed(u8 taskId); -static void Cb_HidePartyPokemon(u8 taskId); -static void Cb_DepositMenu(u8 taskId); -static void Cb_MoveMon(u8 taskId); -static void Cb_GiveMovingItemToMon(u8 taskId); -static void Cb_SwitchSelectedItem(u8 taskId); -static void Cb_TakeItemForMoving(u8 taskId); -static void Cb_WithdrawMon(u8 taskId); -static void Cb_ShiftMon(u8 taskId); -static void Cb_ShowPartyPokemon(u8 taskId); -static void Cb_ShowItemInfo(u8 taskId); -static void Cb_GiveItemFromBag(u8 taskId); -static void Cb_ItemToBag(u8 taskId); -static void Cb_TakeItemForMoving(u8 taskId); -static void Cb_ShowMarkMenu(u8 taskId); -static void Cb_ShowMonSummary(u8 taskId); -static void Cb_ReleaseMon(u8 taskId); -static void Cb_ReshowPSS(u8 taskId); -static void Cb_MainPSS(u8 taskId); -static void Cb_JumpBox(u8 taskId); -static void Cb_HandleWallpapers(u8 taskId); -static void Cb_NameBox(u8 taskId); -static void Cb_PrintCantStoreMail(u8 taskId); -static void Cb_HandleMovingMonFromParty(u8 taskId); +static void Cb_InitPSS(u8); +static void Cb_PlaceMon(u8); +static void Cb_ChangeScreen(u8); +static void Cb_ShowPSS(u8); +static void Cb_OnBPressed(u8); +static void Cb_HandleBoxOptions(u8); +static void Cb_OnSelectedMon(u8); +static void Cb_OnCloseBoxPressed(u8); +static void Cb_HidePartyPokemon(u8); +static void Cb_DepositMenu(u8); +static void Cb_MoveMon(u8); +static void Cb_GiveMovingItemToMon(u8); +static void Cb_SwitchSelectedItem(u8); +static void Cb_TakeItemForMoving(u8); +static void Cb_WithdrawMon(u8); +static void Cb_ShiftMon(u8); +static void Cb_ShowPartyPokemon(u8); +static void Cb_ShowItemInfo(u8); +static void Cb_GiveItemFromBag(u8); +static void Cb_ItemToBag(u8); +static void Cb_TakeItemForMoving(u8); +static void Cb_ShowMarkMenu(u8); +static void Cb_ShowMonSummary(u8); +static void Cb_ReleaseMon(u8); +static void Cb_ReshowPSS(u8); +static void Cb_MainPSS(u8); +static void Cb_JumpBox(u8); +static void Cb_HandleWallpapers(u8); +static void Cb_NameBox(u8); +static void Cb_PrintCantStoreMail(u8); +static void Cb_HandleMovingMonFromParty(u8); static void SetUpScrollToBox(u8); static void sub_80CFE54(u8); static void SetMovingMonPriority(u8); @@ -654,29 +664,29 @@ static void Item_FromMonToMoving(u8, u8); static void Item_GiveMovingToMon(u8, u8); static void Item_TakeMons(u8, u8); static void Item_SwitchMonsWithMoving(u8, u8); -static struct Sprite *CreateJumpBoxArrows(u16, u16, u8, u8, u8); +static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); static void SetWallpaperForCurrentBox(u8); static void AddWallpapersMenu(u8); static u16 GetMovingItem(void); -static void LoadCursorMonGfx(u16 species, u32 pid); -static void sub_80CA2D0(struct Sprite *sprite); +static void LoadCursorMonGfx(u16, u32); +static void sub_80CA2D0(struct Sprite *); static void SpriteCB_OutgoingBoxTitle(struct Sprite *); -static void sub_80CBA3C(struct Sprite *sprite); +static void sub_80CBA3C(struct Sprite *); static void SpriteCB_IncomingBoxTitle(struct Sprite *); -static void sub_80CBAF0(s16 yDelta); -static void sub_80CAAA8(u8 arg0, bool8 isPartyMon); +static void sub_80CBAF0(s16); +static void sub_80CAAA8(u8, bool8); static const u8 *GetMovingItemName(void); -static void SetMenuText(u8 textId); -static void sub_80D0D8C(u8 cursorArea, u8 cursorPos); -static void sub_80D0E50(u8 cursorArea, u8 cursorPos); -static void sub_80D0F38(u16 item); -static struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 oamPriority, u8 subpriority); -static void DestroyBoxMonIcon(struct Sprite *sprite); +static void SetMenuText(u8); +static void sub_80D0D8C(u8, u8); +static void sub_80D0E50(u8, u8); +static void sub_80D0F38(u16); +static struct Sprite *CreateMonIconSprite(u16, u32, s16, s16, u8, u8); +static void DestroyBoxMonIcon(struct Sprite *); static void SetBoxSpeciesAndPersonalities(u8); static void sub_80CB9D0(struct Sprite *, u16); -static void Task_InitBox(u8 taskId); -static void InitBoxTitle(u8 boxId); -static s8 DetermineBoxScrollDirection(u8 boxId); +static void Task_InitBox(u8); +static void InitBoxTitle(u8); +static s8 DetermineBoxScrollDirection(u8); static void DrawWallpaper(const void *, s8, u8); static s16 GetBoxTitleBaseX(const u8 *); static bool8 MonPlaceChange_Shift(void); @@ -684,12 +694,12 @@ static bool8 MonPlaceChange_Move(void); static bool8 MonPlaceChange_Place(void); static bool8 sub_80CDEC4(void); static bool8 sub_80CDEB4(void); -static void sub_80CD444(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y); -static void SetShiftedMonData(u8 boxId, u8 position); -static void SetMovedMonData(u8 boxId, u8 position); -static void SetPlacedMonData(u8 boxId, u8 position); -static void PurgeMonOrBoxMon(u8 boxId, u8 position); -static void SetCursorMonData(void *pokemon, u8 mode); +static void sub_80CD444(u8, u8, u16 *, u16 *); +static void SetShiftedMonData(u8, u8); +static void SetMovedMonData(u8, u8); +static void SetPlacedMonData(u8, u8); +static void PurgeMonOrBoxMon(u8, u8); +static void SetCursorMonData(void *, u8); static bool32 AtLeastThreeUsableMons(void); static u8 InBoxInput_Normal(void); static u8 InBoxInput_MovingMultiple(void); @@ -705,47 +715,49 @@ static bool8 sub_80D03B0(void); static bool8 sub_80D0420(void); static bool8 sub_80D04A0(void); static bool8 sub_80D04C8(void); -static void sub_80D07B0(u8 arg0, u8 arg1); -static void sub_80D0834(u8 arg0, u8 arg1); +static void sub_80D07B0(u8, u8); +static void sub_80D0834(u8, u8); static void sub_80D0B5C(void); static void sub_80D062C(void); -static void sub_80D0884(u16 arg0, u16 arg1, u16 arg2); +static void sub_80D0884(u16, u16, u16); static void sub_80D08CC(void); static void sub_80D09A4(void); static void sub_80D0A1C(void); static void sub_80D0AAC(void); static u8 sub_80D0894(void); -static void sub_80D0778(u8 arg0, u8 arg1, u8 arg2); -static void sub_80D0708(u8 arg0, u8 arg1, u8 arg2); -static void sub_80D06D0(u8 arg0, u8 arg1, u8 arg2); -static void sub_80D0740(u8 arg0, u8 arg1, u8 arg2); -static void sub_80D27AC(u8 id, u16 arg1, u16 arg2, u16 arg3, u16 arg4); -static void sub_80D27F4(u8 id, u8 arg1, s8 arg2); -static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4); -static void sub_80D2770(u8 id, u16 arg1, u16 arg2); -static void sub_80D259C(u8 count); +static void sub_80D0778(u8, u8, u8); +static void sub_80D0708(u8, u8, u8); +static void sub_80D06D0(u8, u8, u8); +static void sub_80D0740(u8, u8, u8); +static void sub_80D27AC(u8, u16, u16, u16, u16); +static void sub_80D27F4(u8, u8, s8); +static void sub_80D2644(u8, u8, const void *, u16, u16); +static void sub_80D2770(u8, u16, u16); +static void sub_80D259C(u8); static void sub_80D25F0(void); -static void sub_80D2918(u8 id); -static void sub_80D2960(u8 id); -static void sub_80D29F8(u8 id); -static void sub_80D2A90(struct UnkStruct_2000020 *arg0, struct UnkStruct_2000028 *arg1, u32 arg2); +static void sub_80D2918(u8); +static void sub_80D2960(u8); +static void sub_80D29F8(u8); +static void sub_80D2A90(struct UnkStruct_2000020 *, struct UnkStruct_2000028 *, u32); static void sub_80D2AA4(void); -static void sub_80D2B88(struct UnkStruct_2000028 *unkStruct); -static void sub_80D2C1C(struct UnkStruct_2000028 *unkStruct); +static void sub_80D2B88(struct UnkStruct_2000028 *); +static void sub_80D2C1C(struct UnkStruct_2000028 *); static u8 GetBoxWallpaper(u8); static void SetBoxWallpaper(u8, u8); -// static const rom data -static const struct PSS_MenuStringPtrs gUnknown_085716C0[] = +struct { + const u8 *text; + const u8 *desc; +} static const sMainMenuTexts[OPTIONS_COUNT] = { - {gText_WithdrawPokemon, gText_WithdrawMonDescription}, - {gText_DepositPokemon, gText_DepositMonDescription}, - {gText_MovePokemon, gText_MoveMonDescription}, - {gText_MoveItems, gText_MoveItemsDescription}, - {gText_SeeYa, gText_SeeYaDescription} + [OPTION_WITHDRAW] = {gText_WithdrawPokemon, gText_WithdrawMonDescription}, + [OPTION_DEPOSIT] = {gText_DepositPokemon, gText_DepositMonDescription}, + [OPTION_MOVE_MONS] = {gText_MovePokemon, gText_MoveMonDescription}, + [OPTION_MOVE_ITEMS] = {gText_MoveItems, gText_MoveItemsDescription}, + [OPTION_EXIT] = {gText_SeeYa, gText_SeeYaDescription} }; -static const struct WindowTemplate gUnknown_085716E8 = +static const struct WindowTemplate sWindowTemplate_MainMenu = { .bg = 0, .tilemapLeft = 1, @@ -756,55 +768,56 @@ static const struct WindowTemplate gUnknown_085716E8 = .baseBlock = 0x1, }; -static const union AnimCmd sSpriteAnim_85716F0[] = +static const union AnimCmd sAnim_ChooseBoxMenu_TopLeft[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85716F8[] = +static const union AnimCmd sAnim_ChooseBoxMenu_BottomLeft[] = { ANIMCMD_FRAME(4, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571700[] = +static const union AnimCmd sAnim_ChooseBoxMenu_TopRight[] = { ANIMCMD_FRAME(6, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571708[] = +static const union AnimCmd sAnim_ChooseBoxMenu_BottomRight[] = { ANIMCMD_FRAME(10, 5), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_8571710[] = +static const union AnimCmd *const sAnims_ChooseBoxMenu[] = { - sSpriteAnim_85716F0, - sSpriteAnim_85716F8, - sSpriteAnim_8571700, - sSpriteAnim_8571708 + sAnim_ChooseBoxMenu_TopLeft, + sAnim_ChooseBoxMenu_BottomLeft, + sAnim_ChooseBoxMenu_TopRight, + sAnim_ChooseBoxMenu_BottomRight }; -static const union AffineAnimCmd sSpriteAffineAnim_8571720[] = +static const union AffineAnimCmd sAffineAnim_ChooseBoxMenu[] = { AFFINEANIMCMD_FRAME(0xE0, 0xE0, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const sSpriteAffineAnimTable_8571730[] = +// Unused +static const union AffineAnimCmd *const sAffineAnims_ChooseBoxMenu[] = { - sSpriteAffineAnim_8571720 + sAffineAnim_ChooseBoxMenu }; -static const u8 sBoxInfoTextColors[] = {TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5}; +static const u8 sChooseBoxMenu_TextColors[] = {TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5}; static const u8 sText_OutOf30[] = _("/30"); -static const u16 gBoxSelectionPopupPalette[] = INCBIN_U16("graphics/unknown/unknown_57173C.gbapal"); -static const u8 gBoxSelectionPopupCenterTiles[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp"); -static const u8 gBoxSelectionPopupSidesTiles[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); +static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal"); +static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp"); +static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); static const u32 gPokemonStorageScrollingBGTileset[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); static const u32 gPokemonStorageScrollingBGTilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); static const u32 gUnknown_08572280[] = INCBIN_U32("graphics/unknown/unknown_572280.gbapal"); @@ -1381,109 +1394,126 @@ static void sub_80C71A4(u16 *dest, u16 dest_left, u16 dest_top, u16 width, u16 h Dma3FillLarge16_(0, dest, width); } -static void Task_PokemonStorageSystemPC(u8 taskId) +enum { + STATE_LOAD, + STATE_FADE_IN, + STATE_HANDLE_INPUT, + STATE_ERROR_MSG, + STATE_ENTER_PC, +}; + +#define tState data[0] +#define tSelectedOption data[1] +#define tInput data[2] +#define tNextOption data[3] +#define tWindowId data[15] + +static void Task_PCMainMenu(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { - case 0: - CreatePCMenu(task->data[1], &task->data[15]); + case STATE_LOAD: + CreateMainMenu(task->tSelectedOption, &task->tWindowId); LoadMessageBoxAndBorderGfx(); DrawDialogueFrame(0, 0); FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, TEXT_SPEED_FF, NULL, 2, 1, 3); + AddTextPrinterParameterized2(0, 1, sMainMenuTexts[task->tSelectedOption].desc, TEXT_SPEED_FF, NULL, 2, 1, 3); CopyWindowToVram(0, 3); - CopyWindowToVram(task->data[15], 3); - task->data[0]++; + CopyWindowToVram(task->tWindowId, 3); + task->tState++; break; - case 1: + case STATE_FADE_IN: if (IsWeatherNotFadingIn()) - { - task->data[0]++; - } + task->tState++; break; - case 2: - task->data[2] = Menu_ProcessInput(); - switch(task->data[2]) + case STATE_HANDLE_INPUT: + task->tInput = Menu_ProcessInput(); + switch(task->tInput) { case MENU_NOTHING_CHOSEN: - task->data[3] = task->data[1]; - if (JOY_NEW(DPAD_UP) && --task->data[3] < 0) - task->data[3] = 4; + task->tNextOption = task->tSelectedOption; + if (JOY_NEW(DPAD_UP) && --task->tNextOption < 0) + task->tNextOption = OPTIONS_COUNT - 1; + if (JOY_NEW(DPAD_DOWN) && ++task->tNextOption > OPTIONS_COUNT - 1) + task->tNextOption = 0; - if (JOY_NEW(DPAD_DOWN) && ++task->data[3] > 4) - task->data[3] = 0; - if (task->data[1] != task->data[3]) + if (task->tSelectedOption != task->tNextOption) { - task->data[1] = task->data[3]; + task->tSelectedOption = task->tNextOption; FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); + AddTextPrinterParameterized2(0, 1, sMainMenuTexts[task->tSelectedOption].desc, 0, NULL, 2, 1, 3); } break; case MENU_B_PRESSED: - case 4: - ClearStdWindowAndFrame(task->data[15], TRUE); + case OPTION_EXIT: + ClearStdWindowAndFrame(task->tWindowId, TRUE); ScriptContext2_Disable(); EnableBothScriptContexts(); - RemoveWindow(task->data[15]); + RemoveWindow(task->tWindowId); DestroyTask(taskId); break; default: - if (task->data[2] == 0 && CountPartyMons() == PARTY_SIZE) + if (task->tInput == OPTION_WITHDRAW && CountPartyMons() == PARTY_SIZE) { + // Can't withdraw FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_PartyFull, 0, NULL, 2, 1, 3); - task->data[0] = 3; + task->tState = STATE_ERROR_MSG; } - else if (task->data[2] == 1 && CountPartyMons() == 1) + else if (task->tInput == OPTION_DEPOSIT && CountPartyMons() == 1) { + // Can't deposit FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_JustOnePkmn, 0, NULL, 2, 1, 3); - task->data[0] = 3; + task->tState = STATE_ERROR_MSG; } else { + // Enter PC FadeScreen(FADE_TO_BLACK, 0); - task->data[0] = 4; + task->tState = STATE_ENTER_PC; } break; } break; - case 3: + case STATE_ERROR_MSG: + // Printed "can't do PC option message" + // Wait for new input after message if (JOY_NEW(A_BUTTON | B_BUTTON)) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); - task->data[0] = 2; + AddTextPrinterParameterized2(0, 1, sMainMenuTexts[task->tSelectedOption].desc, 0, NULL, 2, 1, 3); + task->tState = STATE_HANDLE_INPUT; } else if (JOY_NEW(DPAD_UP)) { - if (--task->data[1] < 0) - task->data[1] = 4; + if (--task->tSelectedOption < 0) + task->tSelectedOption = OPTIONS_COUNT - 1; Menu_MoveCursor(-1); - task->data[1] = Menu_GetCursorPos(); + task->tSelectedOption = Menu_GetCursorPos(); FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); - task->data[0] = 2; + AddTextPrinterParameterized2(0, 1, sMainMenuTexts[task->tSelectedOption].desc, 0, NULL, 2, 1, 3); + task->tState = STATE_HANDLE_INPUT; } else if (JOY_NEW(DPAD_DOWN)) { - if (++task->data[1] > 3) - task->data[1] = 0; + if (++task->tSelectedOption >= OPTIONS_COUNT - 1) + task->tSelectedOption = 0; Menu_MoveCursor(1); - task->data[1] = Menu_GetCursorPos(); + task->tSelectedOption = Menu_GetCursorPos(); FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); - task->data[0] = 2; + AddTextPrinterParameterized2(0, 1, sMainMenuTexts[task->tSelectedOption].desc, 0, NULL, 2, 1, 3); + task->tState = STATE_HANDLE_INPUT; } break; - case 4: + case STATE_ENTER_PC: if (!gPaletteFade.active) { CleanupOverworldWindowsAndTilemaps(); - Cb2_EnterPSS(task->data[2]); - RemoveWindow(task->data[15]); + Cb2_EnterPSS(task->tInput); + RemoveWindow(task->tWindowId); DestroyTask(taskId); } break; @@ -1492,9 +1522,9 @@ static void Task_PokemonStorageSystemPC(u8 taskId) void ShowPokemonStorageSystemPC(void) { - u8 taskId = CreateTask(Task_PokemonStorageSystemPC, 80); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = 0; + u8 taskId = CreateTask(Task_PCMainMenu, 80); + gTasks[taskId].tState = 0; + gTasks[taskId].tSelectedOption = 0; ScriptContext2_Enable(); } @@ -1504,24 +1534,30 @@ static void FieldCb_ReturnToPcMenu(void) MainCallback vblankCb = gMain.vblankCallback; SetVBlankCallback(NULL); - taskId = CreateTask(Task_PokemonStorageSystemPC, 80); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = sPreviousBoxOption; - Task_PokemonStorageSystemPC(taskId); + taskId = CreateTask(Task_PCMainMenu, 80); + gTasks[taskId].tState = 0; + gTasks[taskId].tSelectedOption = sPreviousBoxOption; + Task_PCMainMenu(taskId); SetVBlankCallback(vblankCb); FadeInFromBlack(); } -static void CreatePCMenu(u8 whichMenu, s16 *windowIdPtr) +#undef tState +#undef tSelectedOption +#undef tInput +#undef tNextOption +#undef tWindowId + +static void CreateMainMenu(u8 whichMenu, s16 *windowIdPtr) { s16 windowId; - struct WindowTemplate winTemplate = gUnknown_085716E8; - winTemplate.width = GetMaxWidthInMenuTable((void *)gUnknown_085716C0, ARRAY_COUNT(gUnknown_085716C0)); - windowId = AddWindow(&winTemplate); + struct WindowTemplate template = sWindowTemplate_MainMenu; + template.width = GetMaxWidthInMenuTable((void *)sMainMenuTexts, OPTIONS_COUNT); + windowId = AddWindow(&template); DrawStdWindowFrame(windowId, FALSE); - PrintMenuTable(windowId, ARRAY_COUNT(gUnknown_085716C0), (void *)gUnknown_085716C0); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, ARRAY_COUNT(gUnknown_085716C0), whichMenu); + PrintMenuTable(windowId, OPTIONS_COUNT, (void *)sMainMenuTexts); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, OPTIONS_COUNT, whichMenu); *windowIdPtr = windowId; } @@ -1532,6 +1568,7 @@ static void Cb2_ExitPSS(void) SetMainCallback2(CB2_ReturnToField); } +// Unused static s16 StorageSystemGetNextMonIndex(struct BoxPokemon *box, s8 startIdx, u8 stopIdx, u8 mode) { s16 i; @@ -1585,74 +1622,75 @@ void ResetPokemonStorageSystem(void) ResetWaldaWallpaper(); } -static void sub_80C77E8(struct UnkPSSStruct_2002370 *a0, u16 tileTag, u16 palTag, u8 a3, bool32 loadPal) +static void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *menu, u16 tileTag, u16 palTag, u8 subpriority, bool32 loadPal) { struct SpritePalette palette = { - gBoxSelectionPopupPalette, palTag + sChooseBoxMenu_Pal, palTag }; struct SpriteSheet sheets[] = { - {gBoxSelectionPopupCenterTiles, 0x800, tileTag}, - {gBoxSelectionPopupSidesTiles, 0x180, tileTag + 1}, + {sChooseBoxMenuCenter_Gfx, 0x800, tileTag}, + {sChooseBoxMenuSides_Gfx, 0x180, tileTag + 1}, {} }; - if (loadPal) + if (loadPal) // Always false LoadSpritePalette(&palette); LoadSpriteSheets(sheets); - gUnknown_02039D04 = a0; - a0->unk_0240 = tileTag; - a0->unk_0242 = palTag; - a0->unk_0246 = a3; - a0->unk_023c = loadPal; + sChooseBoxMenu = menu; + menu->tileTag = tileTag; + menu->paletteTag = palTag; + menu->subpriority = subpriority; + menu->loadedPalette = loadPal; } -static void sub_80C7890(void) +static void FreeChooseBoxMenu(void) { - if (gUnknown_02039D04->unk_023c) - FreeSpritePaletteByTag(gUnknown_02039D04->unk_0242); - FreeSpriteTilesByTag(gUnknown_02039D04->unk_0240); - FreeSpriteTilesByTag(gUnknown_02039D04->unk_0240 + 1); + if (sChooseBoxMenu->loadedPalette) + FreeSpritePaletteByTag(sChooseBoxMenu->paletteTag); + FreeSpriteTilesByTag(sChooseBoxMenu->tileTag); + FreeSpriteTilesByTag(sChooseBoxMenu->tileTag + 1); } -static void sub_80C78D4(u8 curBox) +static void CreateChooseBoxMenuSprites(u8 curBox) { - sub_80C7958(curBox); + ChooseBoxMenu_CreateSprites(curBox); } -static void sub_80C78E4(void) +static void DestroyChooseBoxMenuSprites(void) { - sub_80C7B14(); + ChooseBoxMenu_DestroySprites(); } -static u8 HandleBoxChooseSelectionInput(void) +// For the popout window when choosing a box to deposit in or jump to +static u8 HandleChooseBoxMenuInput(void) { if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - return 201; + return BOXID_CANCELED; } if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - return gUnknown_02039D04->curBox; + return sChooseBoxMenu->curBox; } if (JOY_NEW(DPAD_LEFT)) { PlaySE(SE_SELECT); - sub_80C7BB4(); + ChooseBoxMenu_MoveLeft(); } else if (JOY_NEW(DPAD_RIGHT)) { PlaySE(SE_SELECT); - sub_80C7B80(); + ChooseBoxMenu_MoveRight(); } - return 200; + return BOXID_NONE_CHOSEN; } -static void sub_80C7958(u8 curBox) +static void ChooseBoxMenu_CreateSprites(u8 curBox) { u16 i; u8 spriteId; @@ -1664,116 +1702,118 @@ static void sub_80C7958(u8 curBox) 0, 0, &oamData, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy }; - gUnknown_02039D04->curBox = curBox; - template.tileTag = gUnknown_02039D04->unk_0240; - template.paletteTag = gUnknown_02039D04->unk_0242; + sChooseBoxMenu->curBox = curBox; + template.tileTag = sChooseBoxMenu->tileTag; + template.paletteTag = sChooseBoxMenu->paletteTag; spriteId = CreateSprite(&template, 160, 96, 0); - gUnknown_02039D04->unk_0000 = gSprites + spriteId; + sChooseBoxMenu->menuSprite = &gSprites[spriteId]; oamData.shape = SPRITE_SHAPE(8x32); oamData.size = SPRITE_SIZE(8x32); - template.tileTag = gUnknown_02039D04->unk_0240 + 1; - template.anims = sSpriteAnimTable_8571710; - for (i = 0; i < 4; i++) - { - u16 r5; - spriteId = CreateSprite(&template, 124, 80, gUnknown_02039D04->unk_0246); - gUnknown_02039D04->unk_0004[i] = gSprites + spriteId; - r5 = 0; + template.tileTag = sChooseBoxMenu->tileTag + 1; + template.anims = sAnims_ChooseBoxMenu; + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->menuSideSprites); i++) + { + u16 anim; + spriteId = CreateSprite(&template, 124, 80, sChooseBoxMenu->subpriority); + sChooseBoxMenu->menuSideSprites[i] = &gSprites[spriteId]; + anim = 0; if (i & 2) { - gUnknown_02039D04->unk_0004[i]->pos1.x = 196; - r5 = 2; + sChooseBoxMenu->menuSideSprites[i]->pos1.x = 196; + anim = 2; } if (i & 1) { - gUnknown_02039D04->unk_0004[i]->pos1.y = 112; - gUnknown_02039D04->unk_0004[i]->oam.size = 0; - r5++; + sChooseBoxMenu->menuSideSprites[i]->pos1.y = 112; + sChooseBoxMenu->menuSideSprites[i]->oam.size = 0; + anim++; } - StartSpriteAnim(gUnknown_02039D04->unk_0004[i], r5); + StartSpriteAnim(sChooseBoxMenu->menuSideSprites[i], anim); } - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->arrowSprites); i++) { - gUnknown_02039D04->arrowSprites[i] = CreateJumpBoxArrows(72 * i + 124, 88, i, 0, gUnknown_02039D04->unk_0246); - if (gUnknown_02039D04->arrowSprites[i]) + sChooseBoxMenu->arrowSprites[i] = CreateChooseBoxArrows(72 * i + 124, 88, i, 0, sChooseBoxMenu->subpriority); + if (sChooseBoxMenu->arrowSprites[i]) { - gUnknown_02039D04->arrowSprites[i]->data[0] = (i == 0 ? -1 : 1); - gUnknown_02039D04->arrowSprites[i]->callback = SpriteCB_JumpBoxArrow; + sChooseBoxMenu->arrowSprites[i]->data[0] = (i == 0 ? -1 : 1); + sChooseBoxMenu->arrowSprites[i]->callback = SpriteCB_ChooseBoxArrow; } } - sub_80C7BE4(); + ChooseBoxMenu_PrintInfo(); } -static void sub_80C7B14(void) +static void ChooseBoxMenu_DestroySprites(void) { u16 i; - if (gUnknown_02039D04->unk_0000) + if (sChooseBoxMenu->menuSprite) { - DestroySprite(gUnknown_02039D04->unk_0000); - gUnknown_02039D04->unk_0000 = NULL; + DestroySprite(sChooseBoxMenu->menuSprite); + sChooseBoxMenu->menuSprite = NULL; } - for (i = 0; i < 4; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->menuSideSprites); i++) { - if (gUnknown_02039D04->unk_0004[i]) + if (sChooseBoxMenu->menuSideSprites[i]) { - DestroySprite(gUnknown_02039D04->unk_0004[i]); - gUnknown_02039D04->unk_0004[i] = NULL; + DestroySprite(sChooseBoxMenu->menuSideSprites[i]); + sChooseBoxMenu->menuSideSprites[i] = NULL; } } - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->arrowSprites); i++) { - if (gUnknown_02039D04->arrowSprites[i]) - DestroySprite(gUnknown_02039D04->arrowSprites[i]); + if (sChooseBoxMenu->arrowSprites[i]) + DestroySprite(sChooseBoxMenu->arrowSprites[i]); } } -static void sub_80C7B80(void) +static void ChooseBoxMenu_MoveRight(void) { - if (++gUnknown_02039D04->curBox >= TOTAL_BOXES_COUNT) - gUnknown_02039D04->curBox = 0; - sub_80C7BE4(); + if (++sChooseBoxMenu->curBox >= TOTAL_BOXES_COUNT) + sChooseBoxMenu->curBox = 0; + ChooseBoxMenu_PrintInfo(); } -static void sub_80C7BB4(void) +static void ChooseBoxMenu_MoveLeft(void) { - gUnknown_02039D04->curBox = (gUnknown_02039D04->curBox == 0 ? TOTAL_BOXES_COUNT - 1 : gUnknown_02039D04->curBox - 1); - sub_80C7BE4(); + sChooseBoxMenu->curBox = (sChooseBoxMenu->curBox == 0 ? TOTAL_BOXES_COUNT - 1 : sChooseBoxMenu->curBox - 1); + ChooseBoxMenu_PrintInfo(); } -static void sub_80C7BE4(void) +static void ChooseBoxMenu_PrintInfo(void) { u8 numBoxMonsText[16]; - struct WindowTemplate winTemplate; + struct WindowTemplate template; u8 windowId; - u8 *boxName = GetBoxNamePtr(gUnknown_02039D04->curBox); - u8 nPokemonInBox = CountMonsInBox(gUnknown_02039D04->curBox); + u8 *boxName = GetBoxNamePtr(sChooseBoxMenu->curBox); + u8 numInBox = CountMonsInBox(sChooseBoxMenu->curBox); u32 winTileData; s32 center; - memset(&winTemplate, 0, sizeof(winTemplate)); - winTemplate.width = 8; - winTemplate.height = 4; + memset(&template, 0, sizeof(template)); + template.width = 8; + template.height = 4; - windowId = AddWindow(&winTemplate); + windowId = AddWindow(&template); FillWindowPixelBuffer(windowId, PIXEL_FILL(4)); + // Print box name center = GetStringCenterAlignXOffset(1, boxName, 64); - AddTextPrinterParameterized3(windowId, 1, center, 1, sBoxInfoTextColors, TEXT_SPEED_FF, boxName); + AddTextPrinterParameterized3(windowId, 1, center, 1, sChooseBoxMenu_TextColors, TEXT_SPEED_FF, boxName); - ConvertIntToDecimalStringN(numBoxMonsText, nPokemonInBox, STR_CONV_MODE_RIGHT_ALIGN, 2); + // Print #/30 for number of Pokémon in the box + ConvertIntToDecimalStringN(numBoxMonsText, numInBox, STR_CONV_MODE_RIGHT_ALIGN, 2); StringAppend(numBoxMonsText, sText_OutOf30); center = GetStringCenterAlignXOffset(1, numBoxMonsText, 64); - AddTextPrinterParameterized3(windowId, 1, center, 17, sBoxInfoTextColors, TEXT_SPEED_FF, numBoxMonsText); + AddTextPrinterParameterized3(windowId, 1, center, 17, sChooseBoxMenu_TextColors, TEXT_SPEED_FF, numBoxMonsText); winTileData = GetWindowAttribute(windowId, WINDOW_TILE_DATA); - CpuCopy32((void *)winTileData, (void *)OBJ_VRAM0 + 0x100 + (GetSpriteTileStartByTag(gUnknown_02039D04->unk_0240) * 32), 0x400); + CpuCopy32((void *)winTileData, (void *)OBJ_VRAM0 + 0x100 + (GetSpriteTileStartByTag(sChooseBoxMenu->tileTag) * 32), 0x400); RemoveWindow(windowId); } -static void SpriteCB_JumpBoxArrow(struct Sprite *sprite) +static void SpriteCB_ChooseBoxArrow(struct Sprite *sprite) { if (++sprite->data[1] > 3) { @@ -1877,13 +1917,13 @@ static void sub_80C7E98(void) static void sub_80C7F1C(void) { sub_80CDC0C(); - sInPartyMenu = (sPSSData->boxOption == BOX_OPTION_DEPOSIT); - gUnknown_02039D0E = 0; + sInPartyMenu = (sPSSData->boxOption == OPTION_DEPOSIT); + sDepositBoxId = 0; } static void SetMonIconTransparency(void) { - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(7, 11)); @@ -1973,7 +2013,7 @@ static void Cb_InitPSS(u8 taskId) if (IsInitBoxActive()) return; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { sPSSData->markMenu.baseTileTag = TAG_TILE_D; sPSSData->markMenu.basePaletteTag = TAG_PAL_DACE; @@ -1990,12 +2030,12 @@ static void Cb_InitPSS(u8 taskId) SetMonIconTransparency(); if (!sPSSData->isReshowingPSS) { - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); SetPSSCallback(Cb_ShowPSS); } else { - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); SetPSSCallback(Cb_ReshowPSS); } SetVBlankCallback(VblankCb_PSS); @@ -2066,12 +2106,12 @@ static void Cb_MainPSS(u8 taskId) case 0: switch (HandleInput()) { - case 1: + case INPUT_1: PlaySE(SE_SELECT); sPSSData->state = 1; break; - case 5: - if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS && sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + case INPUT_5: + if (sPSSData->boxOption != OPTION_MOVE_MONS && sPSSData->boxOption != OPTION_MOVE_ITEMS) { PrintMessage(MSG_WHICH_ONE_WILL_TAKE); sPSSData->state = 3; @@ -2082,38 +2122,38 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_ShowPartyPokemon); } break; - case 6: - if (sPSSData->boxOption == BOX_OPTION_MOVE_MONS) + case INPUT_6: + if (sPSSData->boxOption == OPTION_MOVE_MONS) { if (IsMonBeingMoved() && ItemIsMail(sPSSData->cursorMonItem)) sPSSData->state = 5; else SetPSSCallback(Cb_HidePartyPokemon); } - else if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + else if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { SetPSSCallback(Cb_HidePartyPokemon); } break; - case 4: + case INPUT_4: SetPSSCallback(Cb_OnCloseBoxPressed); break; - case 19: + case INPUT_19: SetPSSCallback(Cb_OnBPressed); break; - case 7: + case INPUT_7: PlaySE(SE_SELECT); SetPSSCallback(Cb_HandleBoxOptions); break; - case 8: + case INPUT_8: SetPSSCallback(Cb_OnSelectedMon); break; - case 9: + case INPUT_9: PlaySE(SE_SELECT); sPSSData->newCurrBoxId = StorageGetCurrentBox() + 1; if (sPSSData->newCurrBoxId >= TOTAL_BOXES_COUNT) sPSSData->newCurrBoxId = 0; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { SetUpScrollToBox(sPSSData->newCurrBoxId); sPSSData->state = 2; @@ -2124,12 +2164,12 @@ static void Cb_MainPSS(u8 taskId) sPSSData->state = 10; } break; - case 10: + case INPUT_10: PlaySE(SE_SELECT); sPSSData->newCurrBoxId = StorageGetCurrentBox() - 1; if (sPSSData->newCurrBoxId < 0) sPSSData->newCurrBoxId = TOTAL_BOXES_COUNT - 1; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { SetUpScrollToBox(sPSSData->newCurrBoxId); sPSSData->state = 2; @@ -2140,7 +2180,7 @@ static void Cb_MainPSS(u8 taskId) sPSSData->state = 10; } break; - case 11: + case INPUT_11: if (!CanMovePartyMon()) { if (ItemIsMail(sPSSData->cursorMonItem)) @@ -2158,7 +2198,7 @@ static void Cb_MainPSS(u8 taskId) sPSSData->state = 4; } break; - case 13: + case INPUT_13: if (CanMovePartyMon()) { sPSSData->state = 4; @@ -2169,7 +2209,7 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_MoveMon); } break; - case 14: + case INPUT_14: if (!CanShiftMon()) { sPSSData->state = 4; @@ -2180,55 +2220,55 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_ShiftMon); } break; - case 12: + case INPUT_12: PlaySE(SE_SELECT); SetPSSCallback(Cb_WithdrawMon); break; - case 15: + case INPUT_15: PlaySE(SE_SELECT); SetPSSCallback(Cb_PlaceMon); break; - case 16: + case INPUT_16: PlaySE(SE_SELECT); SetPSSCallback(Cb_TakeItemForMoving); break; - case 17: + case INPUT_17: PlaySE(SE_SELECT); SetPSSCallback(Cb_GiveMovingItemToMon); break; - case 18: + case INPUT_18: PlaySE(SE_SELECT); SetPSSCallback(Cb_SwitchSelectedItem); break; - case 20: + case INPUT_20: PlaySE(SE_SELECT); sub_80D01D0(0); sPSSData->state = 7; break; - case 22: + case INPUT_22: sub_80D01D0(1); sPSSData->state = 8; break; - case 21: + case INPUT_21: PlaySE(SE_SELECT); sub_80D01D0(2); sPSSData->state = 9; break; - case 23: + case INPUT_23: sub_80D01D0(3); sPSSData->state = 7; break; - case 25: + case INPUT_25: PlaySE(SE_SELECT); sub_80D01D0(4); sPSSData->state = 9; break; - case 26: + case INPUT_26: PlaySE(SE_SELECT); sub_80D01D0(5); sPSSData->state = 7; break; - case 24: + case INPUT_24: PlaySE(SE_FAILURE); break; } @@ -2256,7 +2296,7 @@ static void Cb_MainPSS(u8 taskId) BoxSetMosaic(); } - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { sub_80CFECC(); sPSSData->state = 11; @@ -2371,7 +2411,7 @@ static void Cb_OnSelectedMon(u8 taskId) if (!sub_80CA2B8()) { PlaySE(SE_SELECT); - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) PrintMessage(MSG_IS_SELECTED); else if (IsActiveItemMoving() || sPSSData->cursorMonItem != 0) PrintMessage(MSG_IS_SELECTED2); @@ -2638,31 +2678,29 @@ static void Cb_DepositMenu(u8 taskId) { case 0: PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); - sub_80C77E8(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); - sub_80C78D4(gUnknown_02039D0E); + LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, TAG_PAL_DAC7, 3, FALSE); + CreateChooseBoxMenuSprites(sDepositBoxId); sPSSData->state++; break; case 1: - boxId = HandleBoxChooseSelectionInput(); - if (boxId == 200) - { - // no box chosen yet - } - else if (boxId == 201) + boxId = HandleChooseBoxMenuInput(); + switch (boxId) { + case BOXID_NONE_CHOSEN: + break; + case BOXID_CANCELED: ClearBottomWindow(); - sub_80C78E4(); - sub_80C7890(); + DestroyChooseBoxMenuSprites(); + FreeChooseBoxMenu(); SetPSSCallback(Cb_MainPSS); - } - else - { + break; + default: if (TryStorePartyMonInBox(boxId)) { - gUnknown_02039D0E = boxId; + sDepositBoxId = boxId; ClearBottomWindow(); - sub_80C78E4(); - sub_80C7890(); + DestroyChooseBoxMenuSprites(); + FreeChooseBoxMenu(); sPSSData->state = 2; } else @@ -2670,6 +2708,7 @@ static void Cb_DepositMenu(u8 taskId) PrintMessage(MSG_BOX_IS_FULL); sPSSData->state = 4; } + break; } break; case 2: @@ -3292,21 +3331,21 @@ static void Cb_JumpBox(u8 taskId) { case 0: PrintMessage(MSG_JUMP_TO_WHICH_BOX); - sub_80C77E8(&sPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); - sub_80C78D4(StorageGetCurrentBox()); + LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, TAG_PAL_DAC7, 3, FALSE); + CreateChooseBoxMenuSprites(StorageGetCurrentBox()); sPSSData->state++; break; case 1: - sPSSData->newCurrBoxId = HandleBoxChooseSelectionInput(); + sPSSData->newCurrBoxId = HandleChooseBoxMenuInput(); switch (sPSSData->newCurrBoxId) { - case 200: + case BOXID_NONE_CHOSEN: break; default: ClearBottomWindow(); - sub_80C78E4(); - sub_80C7890(); - if (sPSSData->newCurrBoxId == 201 || sPSSData->newCurrBoxId == StorageGetCurrentBox()) + DestroyChooseBoxMenuSprites(); + FreeChooseBoxMenu(); + if (sPSSData->newCurrBoxId == BOXID_CANCELED || sPSSData->newCurrBoxId == StorageGetCurrentBox()) { AnimateBoxScrollArrows(TRUE); SetPSSCallback(Cb_MainPSS); @@ -3519,7 +3558,7 @@ static void Cb_ChangeScreen(u8 taskId) u8 mode, monIndex, maxMonIndex; u8 screenChangeType = sPSSData->screenChangeType; - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE) sMovingItemId = GetMovingItem(); else sMovingItemId = ITEM_NONE; @@ -3535,9 +3574,9 @@ static void Cb_ChangeScreen(u8 taskId) boxMons = sPSSData->field_218C.box; monIndex = sPSSData->field_2187; maxMonIndex = sPSSData->field_2186; - mode = sPSSData->pokemonSummaryScreenMode; + mode = sPSSData->summaryScreenMode; FreePSSData(); - if (mode == PSS_MODE_NORMAL && boxMons == &gUnknown_02039D14.box) + if (mode == SUMMARY_MODE_NORMAL && boxMons == &gUnknown_02039D14.box) ShowPokemonSummaryScreenSet40EF(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); else ShowPokemonSummaryScreen(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); @@ -3626,7 +3665,7 @@ static void sub_80CA0D8(void) LoadPalette(gUnknown_085723DC, 0, 0x20); LoadPalette(gUnknown_085723FC, 0x20, 0x20); LoadPalette(gUnknown_085726F4, 0xF0, 0x20); - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) LoadPalette(gUnknown_0857241C, 0x30, 0x20); else LoadPalette(gUnknown_0857243C, 0x30, 0x20); @@ -3765,7 +3804,7 @@ static void LoadCursorMonGfx(u16 species, u32 pid) static void PrintCursorMonInfo(void) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { AddTextPrinterParameterized(0, 1, sPSSData->cursorMonNickText, 6, 0, TEXT_SPEED_FF, NULL); AddTextPrinterParameterized(0, 2, sPSSData->cursorMonSpeciesName, 6, 15, TEXT_SPEED_FF, NULL); @@ -3876,7 +3915,7 @@ static void SetUpHidePartyMenu(void) sPSSData->field_2C0 = 0; sPSSData->field_2C2 = 22; sPSSData->field_2C5 = 0; - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) sub_80D11CC(); } @@ -4224,7 +4263,7 @@ static void InitBoxMonSprites(u8 boxId) } // If in item mode, set all Pokémon icons with no item to be transparent - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++) { @@ -4245,7 +4284,7 @@ static void sub_80CB140(u8 boxPosition) u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY); sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_ROWS)); - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; } } @@ -4321,7 +4360,7 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) u8 count = 0; u8 boxPosition = row; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { for (i = 0; i < IN_BOX_COLUMNS; i++) { @@ -4501,7 +4540,7 @@ static void CreatePartyMonsSprites(bool8 arg0) } } - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { for (i = 0; i < PARTY_SIZE; i++) { @@ -4945,7 +4984,7 @@ static void SetUpScrollToBox(u8 boxId) { s8 direction = DetermineBoxScrollDirection(boxId); - sPSSData->wallpaperScrollSpeed = (direction > 0) ? 6 : -6; + sPSSData->scrollSpeed = (direction > 0) ? 6 : -6; sPSSData->field_2D3 = (direction > 0) ? 1 : 2; sPSSData->field_2D0 = 32; sPSSData->scrollToBoxIdUnused = boxId; @@ -4982,7 +5021,7 @@ static bool8 ScrollToBox(void) var = sub_80CB584(); if (sPSSData->field_2D0 != 0) { - sPSSData->bg2_X += sPSSData->wallpaperScrollSpeed; + sPSSData->bg2_X += sPSSData->scrollSpeed; if (--sPSSData->field_2D0 != 0) return TRUE; CycleBoxTitleSprites(); @@ -5114,10 +5153,8 @@ static bool32 WaitForWallpaperGfxLoad(void) return FALSE; if (sPSSData->wallpaperTiles != NULL) - { - Free(sPSSData->wallpaperTiles); - sPSSData->wallpaperTiles = NULL; - } + FREE_AND_SET_NULL(sPSSData->wallpaperTiles); + return TRUE; } @@ -5431,7 +5468,7 @@ static void SpriteCB_Arrow(struct Sprite *sprite) sprite->sState = 3; break; case 3: - sprite->pos1.x -= sPSSData->wallpaperScrollSpeed; + sprite->pos1.x -= sPSSData->scrollSpeed; if (sprite->pos1.x <= 72 || sprite->pos1.x >= DISPLAY_WIDTH + 8) sprite->invisible = TRUE; if (--sprite->sTimer == 0) @@ -5442,7 +5479,7 @@ static void SpriteCB_Arrow(struct Sprite *sprite) } break; case 4: - sprite->pos1.x -= sPSSData->wallpaperScrollSpeed; + sprite->pos1.x -= sPSSData->scrollSpeed; break; } } @@ -5450,7 +5487,8 @@ static void SpriteCB_Arrow(struct Sprite *sprite) #undef sState #undef sSpeed -static struct Sprite *CreateJumpBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) +// Arrows for Deposit/Jump Box selection +static struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) { u8 spriteId = CreateSprite(&sSpriteTemplate_Arrow, x, y, subpriority); if (spriteId == MAX_SPRITES) @@ -5465,7 +5503,7 @@ static struct Sprite *CreateJumpBoxArrows(u16 x, u16 y, u8 animId, u8 priority, static void sub_80CD36C(void) { - if (sPSSData->boxOption != BOX_OPTION_DEPOSIT) + if (sPSSData->boxOption != OPTION_DEPOSIT) sBoxCursorArea = CURSOR_AREA_IN_BOX; else sBoxCursorArea = CURSOR_AREA_IN_PARTY; @@ -5554,7 +5592,7 @@ static bool8 sub_80CD554(void) if (sPSSData->field_CD0 == 0) { - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return FALSE; else return sub_80D1218(); @@ -5659,7 +5697,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) { sub_80CD6AC(newCursorArea, newCursorPosition); sub_80CD70C(); - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) StartSpriteAnim(sPSSData->field_CB4, 1); @@ -5670,7 +5708,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) StartSpriteAnim(sPSSData->field_CB4, 1); } - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { if (sBoxCursorArea == CURSOR_AREA_IN_BOX) sub_80D0E50(CURSOR_AREA_IN_BOX, sBoxCursorPosition); @@ -5718,7 +5756,7 @@ static void sub_80CDA68(void) { sBoxCursorArea = sPSSData->field_CD4; sBoxCursorPosition = sPSSData->field_CD5; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) StartSpriteAnim(sPSSData->field_CB4, 0); @@ -6331,21 +6369,21 @@ static void sub_80CE7E8(void) sPSSData->field_218C.mon = &gUnknown_02039D14; sPSSData->field_2187 = 0; sPSSData->field_2186 = 0; - sPSSData->pokemonSummaryScreenMode = PSS_MODE_NORMAL; + sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) { sPSSData->field_218C.mon = gPlayerParty; sPSSData->field_2187 = sBoxCursorPosition; sPSSData->field_2186 = CountPartyMons() - 1; - sPSSData->pokemonSummaryScreenMode = PSS_MODE_NORMAL; + sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } else { sPSSData->field_218C.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); sPSSData->field_2187 = sBoxCursorPosition; sPSSData->field_2186 = IN_BOX_COUNT - 1; - sPSSData->pokemonSummaryScreenMode = PSS_MODE_BOX; + sPSSData->summaryScreenMode = SUMMARY_MODE_BOX; } } @@ -6641,7 +6679,7 @@ static u8 InBoxInput_Normal(void) if (JOY_REPEAT(DPAD_UP)) { - retVal = TRUE; + retVal = INPUT_1; if (sBoxCursorPosition >= IN_BOX_ROWS) { cursorPosition -= IN_BOX_ROWS; @@ -6655,7 +6693,7 @@ static u8 InBoxInput_Normal(void) } else if (JOY_REPEAT(DPAD_DOWN)) { - retVal = TRUE; + retVal = INPUT_1; cursorPosition += IN_BOX_ROWS; if (cursorPosition >= IN_BOX_COUNT) { @@ -6669,7 +6707,7 @@ static u8 InBoxInput_Normal(void) } else if (JOY_REPEAT(DPAD_LEFT)) { - retVal = TRUE; + retVal = INPUT_1; if (sBoxCursorPosition % IN_BOX_ROWS != 0) { cursorPosition--; @@ -6683,7 +6721,7 @@ static u8 InBoxInput_Normal(void) } else if (JOY_REPEAT(DPAD_RIGHT)) { - retVal = TRUE; + retVal = INPUT_1; if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) { cursorPosition++; @@ -6697,7 +6735,7 @@ static u8 InBoxInput_Normal(void) } else if (JOY_NEW(START_BUTTON)) { - retVal = TRUE; + retVal = INPUT_1; cursorArea = CURSOR_AREA_BOX; cursorPosition = 0; break; @@ -6706,55 +6744,55 @@ static u8 InBoxInput_Normal(void) if ((JOY_NEW(A_BUTTON)) && sub_80CFA5C()) { if (!sCanOnlyMove) - return 8; + return INPUT_8; - if (sPSSData->boxOption != BOX_OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) + if (sPSSData->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) { switch (GetMenuItemTextId(0)) { case MENU_STORE: - return 11; + return INPUT_11; case MENU_WITHDRAW: - return 12; + return INPUT_12; case MENU_MOVE: - return 13; + return INPUT_13; case MENU_SHIFT: - return 14; + return INPUT_14; case MENU_PLACE: - return 15; + return INPUT_15; case MENU_TAKE: - return 16; + return INPUT_16; case MENU_GIVE: - return 17; + return INPUT_17; case MENU_SWITCH: - return 18; + return INPUT_18; } } else { sPSSData->inBoxMovingMode = 1; - return 20; + return INPUT_20; } } if (JOY_NEW(B_BUTTON)) - return 19; + return INPUT_19; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return 10; + return INPUT_10; if (JOY_HELD(R_BUTTON)) - return 9; + return INPUT_9; } if (JOY_NEW(SELECT_BUTTON)) { sub_80CFDC4(); - return 0; + return INPUT_NONE; } - retVal = 0; + retVal = INPUT_NONE; } while (0); @@ -6773,11 +6811,11 @@ static u8 InBoxInput_GrabbingMultiple(void) if (sBoxCursorPosition / IN_BOX_ROWS != 0) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); - return 21; + return INPUT_21; } else { - return 24; + return INPUT_24; } } else if (JOY_REPEAT(DPAD_DOWN)) @@ -6785,11 +6823,11 @@ static u8 InBoxInput_GrabbingMultiple(void) if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); - return 21; + return INPUT_21; } else { - return 24; + return INPUT_24; } } else if (JOY_REPEAT(DPAD_LEFT)) @@ -6797,11 +6835,11 @@ static u8 InBoxInput_GrabbingMultiple(void) if (sBoxCursorPosition % IN_BOX_ROWS != 0) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return 21; + return INPUT_21; } else { - return 24; + return INPUT_24; } } else if (JOY_REPEAT(DPAD_RIGHT)) @@ -6809,16 +6847,16 @@ static u8 InBoxInput_GrabbingMultiple(void) if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return 21; + return INPUT_21; } else { - return 24; + return INPUT_24; } } else { - return 0; + return INPUT_NONE; } } else @@ -6827,14 +6865,14 @@ static u8 InBoxInput_GrabbingMultiple(void) { sPSSData->inBoxMovingMode = 0; sPSSData->field_CB8->invisible = FALSE; - return 22; + return INPUT_22; } else { sIsMonBeingMoved = (sPSSData->cursorMonSpecies != SPECIES_NONE); sPSSData->inBoxMovingMode = 2; sMovingMonOrigBoxId = StorageGetCurrentBox(); - return 23; + return INPUT_23; } } } @@ -6846,11 +6884,11 @@ static u8 InBoxInput_MovingMultiple(void) if (sub_80D0580(0)) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); - return 25; + return INPUT_25; } else { - return 24; + return INPUT_24; } } else if (JOY_REPEAT(DPAD_DOWN)) @@ -6858,11 +6896,11 @@ static u8 InBoxInput_MovingMultiple(void) if (sub_80D0580(1)) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); - return 25; + return INPUT_25; } else { - return 24; + return INPUT_24; } } else if (JOY_REPEAT(DPAD_LEFT)) @@ -6870,11 +6908,11 @@ static u8 InBoxInput_MovingMultiple(void) if (sub_80D0580(2)) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return 25; + return INPUT_25; } else { - return 10; + return INPUT_10; } } else if (JOY_REPEAT(DPAD_RIGHT)) @@ -6882,11 +6920,11 @@ static u8 InBoxInput_MovingMultiple(void) if (sub_80D0580(3)) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return 25; + return INPUT_25; } else { - return 9; + return INPUT_9; } } else if (JOY_NEW(A_BUTTON)) @@ -6895,28 +6933,28 @@ static u8 InBoxInput_MovingMultiple(void) { sIsMonBeingMoved = FALSE; sPSSData->inBoxMovingMode = 0; - return 26; + return INPUT_26; } else { - return 24; + return INPUT_24; } } else if (JOY_NEW(B_BUTTON)) { - return 24; + return INPUT_24; } else { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return 10; + return INPUT_10; if (JOY_HELD(R_BUTTON)) - return 9; + return INPUT_9; } - return 0; + return INPUT_NONE; } } @@ -6935,14 +6973,14 @@ static u8 HandleInput_InParty(void) sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; gotoBox = FALSE; - retVal = 0; + retVal = INPUT_NONE; if (JOY_REPEAT(DPAD_UP)) { if (--cursorPosition < 0) cursorPosition = PARTY_SIZE; if (cursorPosition != sBoxCursorPosition) - retVal = 1; + retVal = INPUT_1; break; } else if (JOY_REPEAT(DPAD_DOWN)) @@ -6950,12 +6988,12 @@ static u8 HandleInput_InParty(void) if (++cursorPosition > PARTY_SIZE) cursorPosition = 0; if (cursorPosition != sBoxCursorPosition) - retVal = 1; + retVal = INPUT_1; break; } else if (JOY_REPEAT(DPAD_LEFT) && sBoxCursorPosition != 0) { - retVal = 1; + retVal = INPUT_1; sPSSData->field_CD6 = sBoxCursorPosition; cursorPosition = 0; break; @@ -6964,12 +7002,12 @@ static u8 HandleInput_InParty(void) { if (sBoxCursorPosition == 0) { - retVal = 1; + retVal = INPUT_1; cursorPosition = sPSSData->field_CD6; } else { - retVal = 6; + retVal = INPUT_6; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } @@ -6980,63 +7018,63 @@ static u8 HandleInput_InParty(void) { if (sBoxCursorPosition == PARTY_SIZE) { - if (sPSSData->boxOption == BOX_OPTION_DEPOSIT) - return 4; + if (sPSSData->boxOption == OPTION_DEPOSIT) + return INPUT_4; gotoBox = TRUE; } else if (sub_80CFA5C()) { if (!sCanOnlyMove) - return 8; + return INPUT_8; switch (GetMenuItemTextId(0)) { case MENU_STORE: - return 11; + return INPUT_11; case MENU_WITHDRAW: - return 12; + return INPUT_12; case MENU_MOVE: - return 13; + return INPUT_13; case MENU_SHIFT: - return 14; + return INPUT_14; case MENU_PLACE: - return 15; + return INPUT_15; case MENU_TAKE: - return 16; + return INPUT_16; case MENU_GIVE: - return 17; + return INPUT_17; case MENU_SWITCH: - return 18; + return INPUT_18; } } } if (JOY_NEW(B_BUTTON)) { - if (sPSSData->boxOption == BOX_OPTION_DEPOSIT) - return 19; + if (sPSSData->boxOption == OPTION_DEPOSIT) + return INPUT_19; gotoBox = TRUE; } if (gotoBox) { - retVal = 6; + retVal = INPUT_6; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } else if (JOY_NEW(SELECT_BUTTON)) { sub_80CFDC4(); - return 0; + return INPUT_NONE; } } while (0); - if (retVal != 0) + if (retVal != INPUT_NONE) { - if (retVal != 6) + if (retVal != INPUT_6) sub_80CD894(cursorArea, cursorPosition); } @@ -7057,7 +7095,7 @@ static u8 HandleInput_OnBox(void) if (JOY_REPEAT(DPAD_UP)) { - retVal = 1; + retVal = INPUT_1; cursorArea = CURSOR_AREA_BUTTONS; cursorPosition = 0; sPSSData->field_CD7 = 1; @@ -7065,46 +7103,46 @@ static u8 HandleInput_OnBox(void) } else if (JOY_REPEAT(DPAD_DOWN)) { - retVal = 1; + retVal = INPUT_1; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 2; break; } if (JOY_HELD(DPAD_LEFT)) - return 10; + return INPUT_10; if (JOY_HELD(DPAD_RIGHT)) - return 9; + return INPUT_9; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return 10; + return INPUT_10; if (JOY_HELD(R_BUTTON)) - return 9; + return INPUT_9; } if (JOY_NEW(A_BUTTON)) { AnimateBoxScrollArrows(FALSE); AddBoxMenu(); - return 7; + return INPUT_7; } if (JOY_NEW(B_BUTTON)) - return 19; + return INPUT_19; if (JOY_NEW(SELECT_BUTTON)) { sub_80CFDC4(); - return 0; + return INPUT_NONE; } - retVal = 0; + retVal = INPUT_NONE; } while (0); - if (retVal) + if (retVal != INPUT_NONE) { if (cursorArea != CURSOR_AREA_BOX) AnimateBoxScrollArrows(FALSE); @@ -7130,7 +7168,7 @@ static u8 HandleInput_OnButtons(void) if (JOY_REPEAT(DPAD_UP)) { - retVal = 1; + retVal = INPUT_1; cursorArea = CURSOR_AREA_IN_BOX; sPSSData->field_CD2 = -1; if (sBoxCursorPosition == 0) @@ -7143,7 +7181,7 @@ static u8 HandleInput_OnButtons(void) if (JOY_REPEAT(DPAD_DOWN | START_BUTTON)) { - retVal = 1; + retVal = INPUT_1; cursorArea = CURSOR_AREA_BOX; cursorPosition = 0; sPSSData->field_CD7 = 1; @@ -7152,34 +7190,34 @@ static u8 HandleInput_OnButtons(void) if (JOY_REPEAT(DPAD_LEFT)) { - retVal = 1; + retVal = INPUT_1; if (--cursorPosition < 0) cursorPosition = 1; break; } else if (JOY_REPEAT(DPAD_RIGHT)) { - retVal = 1; + retVal = INPUT_1; if (++cursorPosition > 1) cursorPosition = 0; break; } if (JOY_NEW(A_BUTTON)) - return (cursorPosition == 0) ? 5 : 4; + return (cursorPosition == 0) ? INPUT_5 : INPUT_4; if (JOY_NEW(B_BUTTON)) - return 19; + return INPUT_19; if (JOY_NEW(SELECT_BUTTON)) { sub_80CFDC4(); - return 0; + return INPUT_NONE; } - retVal = 0; + retVal = INPUT_NONE; } while (0); - if (retVal != 0) + if (retVal != INPUT_NONE) sub_80CD894(cursorArea, cursorPosition); return retVal; @@ -7191,14 +7229,13 @@ static u8 HandleInput(void) { u8 (*func)(void); s8 area; - } - static const inputFuncs[] = + } static const inputFuncs[] = { - {HandleInput_InBox, CURSOR_AREA_IN_BOX}, - {HandleInput_InParty, CURSOR_AREA_IN_PARTY}, - {HandleInput_OnBox, CURSOR_AREA_BOX}, + {HandleInput_InBox, CURSOR_AREA_IN_BOX}, + {HandleInput_InParty, CURSOR_AREA_IN_PARTY}, + {HandleInput_OnBox, CURSOR_AREA_BOX}, {HandleInput_OnButtons, CURSOR_AREA_BUTTONS}, - {NULL, 0}, + {}, }; u16 i = 0; @@ -7209,7 +7246,7 @@ static u8 HandleInput(void) i++; } - return 0; + return INPUT_NONE; } static void AddBoxMenu(void) @@ -7224,7 +7261,7 @@ static void AddBoxMenu(void) static u8 sub_80CFA5C(void) { InitMenu(); - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return sub_80CFA84(); else return sub_80CFB44(); @@ -7236,19 +7273,19 @@ static bool8 sub_80CFA84(void) switch (sPSSData->boxOption) { - case BOX_OPTION_DEPOSIT: + case OPTION_DEPOSIT: if (var0) SetMenuText(MENU_STORE); else return FALSE; break; - case BOX_OPTION_WITHDRAW: + case OPTION_WITHDRAW: if (var0) SetMenuText(MENU_WITHDRAW); else return FALSE; break; - case BOX_OPTION_MOVE_MONS: + case OPTION_MOVE_MONS: if (sIsMonBeingMoved) { if (var0) @@ -7264,13 +7301,13 @@ static bool8 sub_80CFA84(void) return FALSE; } break; - case BOX_OPTION_MOVE_ITEMS: + case OPTION_MOVE_ITEMS: default: return FALSE; } SetMenuText(MENU_SUMMARY); - if (sPSSData->boxOption == BOX_OPTION_MOVE_MONS) + if (sPSSData->boxOption == OPTION_MOVE_MONS) { if (!sBoxCursorArea) SetMenuText(MENU_WITHDRAW); @@ -8320,7 +8357,7 @@ static void sub_80D0C60(void) struct CompressedSpriteSheet spriteSheet; struct SpriteTemplate spriteTemplate; - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { spriteSheet.data = gUnknown_03000F78; spriteSheet.size = 0x200; @@ -8368,7 +8405,7 @@ static void sub_80D0D8C(u8 cursorArea, u8 cursorPos) { u16 heldItem; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; if (sub_80D1324(cursorArea, cursorPos)) return; @@ -8406,7 +8443,7 @@ static void sub_80D0E50(u8 cursorArea, u8 cursorPos) { u8 id; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; id = sub_80D1370(cursorArea, cursorPos); @@ -8419,7 +8456,7 @@ static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) u8 id; u16 item; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; id = sub_80D1370(cursorArea, cursorPos); @@ -8460,7 +8497,7 @@ static void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) u8 id; u16 item; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; id = sub_80D1370(cursorArea, cursorPos); @@ -8488,7 +8525,7 @@ static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) { u8 id; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; id = sub_80D1370(2, 0); @@ -8511,7 +8548,7 @@ static void Item_TakeMons(u8 cursorArea, u8 cursorPos) u8 id; u16 item; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; item = 0; @@ -8532,7 +8569,7 @@ static void Item_TakeMons(u8 cursorArea, u8 cursorPos) static void sub_80D1194(void) { - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { u8 id = sub_80D1370(2, 0); sub_80D15D4(id, 5); @@ -8544,7 +8581,7 @@ static void sub_80D11CC(void) { s32 i; - if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; for (i = 0; i < 3; i++) @@ -8576,7 +8613,7 @@ static bool8 IsActiveItemMoving(void) { s32 i; - if (sPSSData->boxOption == BOX_OPTION_MOVE_ITEMS) + if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { for (i = 0; i < 3; i++) { @@ -9267,7 +9304,7 @@ u32 GetWaldaWallpaperPatternId(void) void SetWaldaWallpaperPatternId(u8 id) { - if (id < FRIENDS_WALLPAPERS_COUNT) + if (id < ARRAY_COUNT(sWaldaWallpapers)) gSaveBlock1Ptr->waldaPhrase.patternId = id; } -- cgit v1.2.3 From 84e1cbaaa651a937712ac95ae97cc1fb7675b735 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 19:17:53 -0400 Subject: Doc storage - misc gfx, item icons --- src/pokemon_storage_system.c | 929 +++++++++++++++++++++++-------------------- 1 file changed, 493 insertions(+), 436 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 07e0931ed..bcf2d4075 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -195,33 +195,79 @@ enum { CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box }; +#define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX // Alt name for cursor area used by Move Items + // Special box ids for the choose box menu #define BOXID_NONE_CHOSEN 200 #define BOXID_CANCELED 201 -#define TAG_PAL_WAVEFORM 0xDACA -#define TAG_PAL_DAC8 0xDAC8 -#define TAG_PAL_DAC6 0xDAC6 -#define TAG_PAL_DACE 0xDACE -#define TAG_PAL_DAC7 0xDAC7 -#define PALTAG_BOX_TITLE 0xDAC9 -#define TAG_PAL_DAC0 0xDAC0 -#define TAG_PAL_DACB 0xDACB - -#define TAG_TILE_0 0 -#define TAG_TILE_1 1 -#define TAG_TILE_2 2 -#define GFXTAG_BOX_TITLE 3 -#define GFXTAG_BOX_TITLE_ALT 4 -#define TAG_TILE_WAVEFORM 5 -#define GFXTAG_ARROW 6 -#define TAG_TILE_7 7 -#define GFXTAG_CHOOSE_BOX_MENU 10 -#define GFXTAG_CHOOSE_BOX_MENU_SIDES 11 // Used implicitly in LoadChooseBoxMenuGfx -#define TAG_TILE_D 13 -#define TAG_TILE_10 16 -#define TAG_TILE_12 18 +enum { + PALTAG_MON_ICON_0 = 56000, + PALTAG_MON_ICON_1, // Used implicitly in CreateMonIconSprite + PALTAG_MON_ICON_2, // Used implicitly in CreateMonIconSprite + PALTAG_3, + PALTAG_4, + PALTAG_5, + PALTAG_CURSOR_MON, + PALTAG_7, + PALTAG_MON_MARKING, + PALTAG_BOX_TITLE, + PALTAG_10, + PALTAG_ITEM_ICON_0, + PALTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites + PALTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites + PALTAG_14, +}; + +enum { + TAG_TILE_0, + TAG_TILE_1, + GFXTAG_CURSOR_MON, + GFXTAG_BOX_TITLE, + GFXTAG_BOX_TITLE_ALT, + GFXTAG_WAVEFORM, + GFXTAG_ARROW, + GFXTAG_ITEM_ICON_0, + GFXTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites + GFXTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites + GFXTAG_CHOOSE_BOX_MENU, + GFXTAG_CHOOSE_BOX_MENU_SIDES, // Used implicitly in LoadChooseBoxMenuGfx + GFXTAG_12, + GFXTAG_13, + GFXTAG_14, + GFXTAG_15, + GFXTAG_MON_MARKING, + GFXTAG_17, + GFXTAG_18, +}; +// The maximum number of item icons that can appear on-screen while +// moving held items. 1 in the cursor, and 2 more while switching +// between 2 Pokémon with held items +#define MAX_ITEM_ICONS 3 + +// IDs for the item icons affine anims +enum { + ITEM_ANIM_NONE, + ITEM_ANIM_APPEAR, + ITEM_ANIM_DISAPPEAR, + ITEM_ANIM_PICK_UP, + ITEM_ANIM_PUT_DOWN, + ITEM_ANIM_PUT_AWAY, + ITEM_ANIM_LARGE, +}; + +// IDs for the item icon sprite callbacks +enum { + ITEM_CB_WAIT_ANIM, + ITEM_CB_TO_HAND, + ITEM_CB_TO_MON, + ITEM_CB_SWAP_TO_HAND, + ITEM_CB_SWAP_TO_MON, + ITEM_CB_UNUSED_1, + ITEM_CB_UNUSED_2, + ITEM_CB_HIDE_PARTY, +}; struct Wallpaper { @@ -280,14 +326,14 @@ struct ChooseBoxMenu u8 subpriority; }; -struct UnkStorageStruct +struct ItemIcon { struct Sprite *sprite; u8 *tiles; u16 palIndex; - u8 unk8; - u8 unk9; - u8 unk10; + u8 cursorArea; + u8 cursorPos; + bool8 active; }; struct PokemonStorageSystemData @@ -389,7 +435,7 @@ struct PokemonStorageSystemData const u32 *cursorMonPalette; u32 cursorMonPersonality; u16 cursorMonSpecies; - u16 cursorMonItem; + u16 cursorMonItemId; u16 field_CE8; bool8 setMosaic; u8 cursorMonMarkings; @@ -403,9 +449,9 @@ struct PokemonStorageSystemData bool8 (*monPlaceChangeFunc)(void); u8 monPlaceChangeState; u8 field_D91; - struct Sprite *field_D94; - struct Sprite *field_D98[2]; - u16 *field_DA0; + struct Sprite *markingComboSprite; + struct Sprite *waveformSprites[2]; + u16 *markingComboTilesPtr; struct MonMarkingsMenu markMenu; struct ChooseBoxMenu chooseBoxMenu; struct Pokemon movingMon; @@ -433,15 +479,15 @@ struct PokemonStorageSystemData u8 itemName[20]; u8 inBoxMovingMode; u16 field_2200; - struct UnkStorageStruct field_2204[3]; - u16 movingItem; - u16 field_2236; + struct ItemIcon itemIcons[MAX_ITEM_ICONS]; + u16 movingItemId; + u16 itemInfoWindowOffset; u8 field_2238; // Unused - u16 field_223A; - u16 *field_223C; + u16 cursorMonPalOffset; + u16 *cursorMonTilePtr; struct Sprite *cursorMonSprite; - u16 field_2244[0x40]; - u8 field_22C4[0x800]; + u16 cursorMonPalBuffer[0x40]; + u8 tileBuffer[0x800]; u8 field_2AC4[0x1800]; // Unused u8 field_42C4[0x800]; u8 wallpaperBgTilemapBuffer[0x1000]; @@ -474,7 +520,7 @@ struct UnkStruct_2039D84 u8 field_2D; }; -static u32 gUnknown_03000F78[98]; +static u32 sItemIconGfxBuffer[98]; EWRAM_DATA static u8 sPreviousBoxOption = 0; EWRAM_DATA static struct ChooseBoxMenu *sChooseBoxMenu = NULL; @@ -529,7 +575,7 @@ static void sub_80CEBDC(void); static void SetScrollingBackground(void); static void sub_80CABE0(void); static void sub_80CAEAC(void); -static void sub_80D0C60(void); +static void CreateItemIconSprites(void); static void sub_80CFEA8(void); static void sub_80CDC0C(void); static void sub_80CAF04(void); @@ -540,9 +586,9 @@ static void InitCanRelaseMonVars(void); static void sub_80D01B8(void); static void ReleaseMon(void); static void RefreshCursorMonData(void); -static void LoadCursorMonSprite(void); -static void sub_80CA154(void); -static void sub_80CA1C4(void); +static void CreateCursorMonSprite(void); +static void CreateMarkingComboSprite(void); +static void CreateWaveformSprites(void); static void sub_80CC064(void); static void sub_80CE324(void); static void ClearBottomWindow(void); @@ -551,7 +597,7 @@ static void RemoveMenu(void); static void sub_80CE00C(void); static void sub_80D1194(void); static void PrintCursorMonInfo(void); -static void sub_80CA65C(void); +static void UpdateWaveformAnimation(void); static void AddWallpaperSetsMenu(void); static void CreateBoxScrollArrows(void); static void InitMenu(void); @@ -559,8 +605,8 @@ static void StopBoxScrollArrowsSlide(void); static void sub_80CFC14(void); static void sub_80CEB40(void); static void CycleBoxTitleSprites(void); -static void sub_80D1818(void); -static void sub_80D19B4(u32); +static void InitItemInfoWindow(void); +static void DrawItemInfoWindow(u32); static void sub_80CAA74(void); static void PrintItemDescription(void); static void sub_80CE760(void); @@ -593,17 +639,17 @@ static bool8 IsInitBoxActive(void); static bool8 sub_80D01E4(void); static bool8 sub_80CDED4(void); static bool8 sub_80CDF08(void); -static bool8 sub_80D184C(void); -static bool8 sub_80D18E4(void); +static bool8 UpdateItemInfoWindowSlideIn(void); +static bool8 UpdateItemInfoWindowSlideOut(void); static bool8 DoShowPartyMenu(void); -static bool8 sub_80D1218(void); +static bool8 IsItemIconAnimActive(void); static bool8 ScrollToBox(void); static bool8 sub_80CD554(void); static bool8 HidePartyMenu(void); -static bool8 IsActiveItemMoving(void); +static bool8 IsMovingItem(void); static bool8 sub_80D0580(u8); static bool8 sub_80D0BC0(void); -static bool8 sub_80CA2B8(void); +static bool8 GetCursorMonMosaic(void); static bool8 DoWallpaperGfxChange(void); static bool8 DoMonPlaceChange(void); static bool8 IsMenuLoading(void); @@ -667,7 +713,7 @@ static void Item_SwitchMonsWithMoving(u8, u8); static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); static void SetWallpaperForCurrentBox(u8); static void AddWallpapersMenu(u8); -static u16 GetMovingItem(void); +static u16 GetMovingItemId(void); static void LoadCursorMonGfx(u16, u32); static void sub_80CA2D0(struct Sprite *); static void SpriteCB_OutgoingBoxTitle(struct Sprite *); @@ -928,20 +974,20 @@ static const struct BgTemplate gUnknown_08572734[] = static const struct SpritePalette gWaveformSpritePalette = { - gWaveformPalette, TAG_PAL_WAVEFORM + gWaveformPalette, PALTAG_10 }; -static const struct SpriteSheet gWaveformSpriteSheet = +static const struct SpriteSheet sSpriteSheet_Waveform = { - gWaveformTiles, sizeof(gWaveformTiles), TAG_TILE_WAVEFORM + gWaveformTiles, sizeof(gWaveformTiles), GFXTAG_WAVEFORM }; -static const struct OamData sOamData_857286C; +static const struct OamData sOamData_CursorMon; static const struct SpriteTemplate sSpriteTemplate_CursorMon = { - .tileTag = TAG_TILE_2, - .paletteTag = TAG_PAL_DAC6, - .oam = &sOamData_857286C, + .tileTag = GFXTAG_CURSOR_MON, + .paletteTag = PALTAG_CURSOR_MON, + .oam = &sOamData_CursorMon, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, @@ -994,7 +1040,7 @@ static const struct WindowTemplate sYesNoWindowTemplate = .baseBlock = 0x5C, }; -static const struct OamData sOamData_857286C = +static const struct OamData sOamData_CursorMon = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1011,7 +1057,7 @@ static const struct OamData sOamData_857286C = .affineParam = 0 }; -static const struct OamData sOamData_8572874 = +static const struct OamData sOamData_Waveform = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1028,13 +1074,13 @@ static const struct OamData sOamData_8572874 = .affineParam = 0 }; -static const union AnimCmd sSpriteAnim_857287C[] = +static const union AnimCmd sAnim_Waveform_LeftOff[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8572884[] = +static const union AnimCmd sAnim_Waveform_LeftOn[] = { ANIMCMD_FRAME(2, 8), ANIMCMD_FRAME(4, 8), @@ -1042,13 +1088,13 @@ static const union AnimCmd sSpriteAnim_8572884[] = ANIMCMD_JUMP(0) }; -static const union AnimCmd sSpriteAnim_8572894[] = +static const union AnimCmd sAnim_Waveform_RightOff[] = { ANIMCMD_FRAME(8, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857289C[] = +static const union AnimCmd sAnim_Waveform_RightOn[] = { ANIMCMD_FRAME(10, 8), ANIMCMD_FRAME(4, 8), @@ -1056,20 +1102,20 @@ static const union AnimCmd sSpriteAnim_857289C[] = ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sSpriteAnimTable_85728AC[] = +static const union AnimCmd *const sAnims_Waveform[] = { - sSpriteAnim_857287C, - sSpriteAnim_8572884, - sSpriteAnim_8572894, - sSpriteAnim_857289C + sAnim_Waveform_LeftOff, + sAnim_Waveform_LeftOn, + sAnim_Waveform_RightOff, + sAnim_Waveform_RightOn }; static const struct SpriteTemplate sSpriteTemplate_Waveform = { - .tileTag = TAG_TILE_WAVEFORM, - .paletteTag = TAG_PAL_WAVEFORM, - .oam = &sOamData_8572874, - .anims = sSpriteAnimTable_85728AC, + .tileTag = GFXTAG_WAVEFORM, + .paletteTag = PALTAG_10, + .oam = &sOamData_Waveform, + .anims = sAnims_Waveform, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -1078,8 +1124,8 @@ static const struct SpriteTemplate sSpriteTemplate_Waveform = static const struct OamData sOamData_85728EC; static const struct SpriteTemplate gUnknown_085728D4 = { - .tileTag = TAG_TILE_12, - .paletteTag = TAG_PAL_DAC0, + .tileTag = GFXTAG_18, + .paletteTag = PALTAG_MON_ICON_0, .oam = &sOamData_85728EC, .anims = gDummySpriteAnimTable, .images = NULL, @@ -1125,8 +1171,7 @@ static const union AffineAnimCmd *const gSpriteAffineAnimTable_857291C[] = #include "data/wallpapers.h" -// Unknown Unused data. -static const u16 gUnknown_0857B07C = 0x23BA; +static const u16 sUnusedColor = RGB(26, 29, 8); static const struct SpriteSheet sSpriteSheet_Arrow = {sArrow_Gfx, 0x80, GFXTAG_ARROW}; @@ -1194,7 +1239,7 @@ static const union AnimCmd *const sAnims_Arrow[] = static const struct SpriteTemplate sSpriteTemplate_Arrow = { .tileTag = GFXTAG_ARROW, - .paletteTag = TAG_PAL_WAVEFORM, + .paletteTag = PALTAG_10, .oam = &sOamData_Arrow, .anims = sAnims_Arrow, .images = NULL, @@ -1206,7 +1251,6 @@ static const u16 gHandCursorPalette[] = INCBIN_U16("graphics/pokemon_storage/han static const u8 gHandCursorTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor.4bpp"); static const u8 gHandCursorShadowTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor_shadow.4bpp"); -// code void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, s32 bytesToBuffer) { s32 i, tileBytesToBuffer, remainingBytes; @@ -2015,14 +2059,14 @@ static void Cb_InitPSS(u8 taskId) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - sPSSData->markMenu.baseTileTag = TAG_TILE_D; - sPSSData->markMenu.basePaletteTag = TAG_PAL_DACE; + sPSSData->markMenu.baseTileTag = GFXTAG_13; + sPSSData->markMenu.basePaletteTag = PALTAG_14; InitMonMarkingsMenu(&sPSSData->markMenu); BufferMonMarkingsMenuTiles(); } else { - sub_80D0C60(); + CreateItemIconSprites(); sub_80CAEAC(); } break; @@ -2125,7 +2169,7 @@ static void Cb_MainPSS(u8 taskId) case INPUT_6: if (sPSSData->boxOption == OPTION_MOVE_MONS) { - if (IsMonBeingMoved() && ItemIsMail(sPSSData->cursorMonItem)) + if (IsMonBeingMoved() && ItemIsMail(sPSSData->cursorMonItemId)) sPSSData->state = 5; else SetPSSCallback(Cb_HidePartyPokemon); @@ -2183,7 +2227,7 @@ static void Cb_MainPSS(u8 taskId) case INPUT_11: if (!CanMovePartyMon()) { - if (ItemIsMail(sPSSData->cursorMonItem)) + if (ItemIsMail(sPSSData->cursorMonItemId)) { sPSSData->state = 5; } @@ -2348,14 +2392,14 @@ static void Cb_MainPSS(u8 taskId) } break; case 10: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { SetUpScrollToBox(sPSSData->newCurrBoxId); sPSSData->state = 2; } break; case 11: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) sPSSData->state = 0; break; } @@ -2408,12 +2452,12 @@ static void Cb_OnSelectedMon(u8 taskId) switch (sPSSData->state) { case 0: - if (!sub_80CA2B8()) + if (!GetCursorMonMosaic()) { PlaySE(SE_SELECT); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) PrintMessage(MSG_IS_SELECTED); - else if (IsActiveItemMoving() || sPSSData->cursorMonItem != 0) + else if (IsMovingItem() || sPSSData->cursorMonItemId != ITEM_NONE) PrintMessage(MSG_IS_SELECTED2); else PrintMessage(MSG_GIVE_TO_MON); @@ -2473,7 +2517,7 @@ static void Cb_OnSelectedMon(u8 taskId) { sPSSData->state = 3; } - else if (ItemIsMail(sPSSData->cursorMonItem)) + else if (ItemIsMail(sPSSData->cursorMonItemId)) { sPSSData->state = 4; } @@ -2493,7 +2537,7 @@ static void Cb_OnSelectedMon(u8 taskId) { sPSSData->state = 5; // Cannot release an Egg. } - else if (ItemIsMail(sPSSData->cursorMonItem)) + else if (ItemIsMail(sPSSData->cursorMonItemId)) { sPSSData->state = 4; } @@ -2678,7 +2722,7 @@ static void Cb_DepositMenu(u8 taskId) { case 0: PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); - LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, TAG_PAL_DAC7, 3, FALSE); + LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); CreateChooseBoxMenuSprites(sDepositBoxId); sPSSData->state++; break; @@ -2893,7 +2937,7 @@ static void Cb_TakeItemForMoving(u8 taskId) switch (sPSSData->state) { case 0: - if (!ItemIsMail(sPSSData->cursorMonItem)) + if (!ItemIsMail(sPSSData->cursorMonItemId)) { ClearBottomWindow(); sPSSData->state++; @@ -2909,7 +2953,7 @@ static void Cb_TakeItemForMoving(u8 taskId) sPSSData->state++; break; case 2: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { sub_80CFE54(3); ClearBottomWindow(); @@ -2939,7 +2983,7 @@ static void Cb_GiveMovingItemToMon(u8 taskId) sPSSData->state++; break; case 2: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { sub_80CFE54(0); sub_80CE00C(); @@ -2967,7 +3011,7 @@ static void Cb_ItemToBag(u8 taskId) switch (sPSSData->state) { case 0: - if (!AddBagItem(sPSSData->cursorMonItem, 1)) + if (!AddBagItem(sPSSData->cursorMonItemId, 1)) { PlaySE(SE_FAILURE); PrintMessage(MSG_BAG_FULL); @@ -2981,7 +3025,7 @@ static void Cb_ItemToBag(u8 taskId) } break; case 1: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { PrintMessage(MSG_PLACED_IN_BAG); sPSSData->state = 2; @@ -3015,7 +3059,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) switch (sPSSData->state) { case 0: - if (!ItemIsMail(sPSSData->cursorMonItem)) + if (!ItemIsMail(sPSSData->cursorMonItemId)) { ClearBottomWindow(); sPSSData->state++; @@ -3031,7 +3075,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) sPSSData->state++; break; case 2: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { sub_80CFE54(3); sub_80CE00C(); @@ -3067,12 +3111,12 @@ static void Cb_ShowItemInfo(u8 taskId) { PlaySE(SE_WIN_OPEN); PrintItemDescription(); - sub_80D1818(); + InitItemInfoWindow(); sPSSData->state++; } break; case 2: - if (!sub_80D184C()) + if (!UpdateItemInfoWindowSlideIn()) sPSSData->state++; break; case 3: @@ -3087,7 +3131,7 @@ static void Cb_ShowItemInfo(u8 taskId) } break; case 5: - if (!sub_80D18E4()) + if (!UpdateItemInfoWindowSlideOut()) sPSSData->state++; break; case 6: @@ -3111,12 +3155,12 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case MENU_B_PRESSED: - case 1: + case 1: // No ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; - case 0: - if (AddBagItem(sPSSData->movingItem, 1) == TRUE) + case 0:// Yes + if (AddBagItem(sPSSData->movingItemId, 1) == TRUE) { ClearBottomWindow(); sPSSData->state = 3; @@ -3141,7 +3185,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) sPSSData->state = 4; break; case 4: - if (!sub_80D1218()) + if (!IsItemIconAnimActive()) { sub_80CFE54(0); SetPSSCallback(Cb_MainPSS); @@ -3331,7 +3375,7 @@ static void Cb_JumpBox(u8 taskId) { case 0: PrintMessage(MSG_JUMP_TO_WHICH_BOX); - LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, TAG_PAL_DAC7, 3, FALSE); + LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); CreateChooseBoxMenuSprites(StorageGetCurrentBox()); sPSSData->state++; break; @@ -3441,7 +3485,7 @@ static void Cb_OnCloseBoxPressed(u8 taskId) PrintMessage(MSG_HOLDING_POKE); sPSSData->state = 1; } - else if (IsActiveItemMoving()) + else if (IsMovingItem()) { SetPSSCallback(Cb_CloseBoxWhileHoldingItem); } @@ -3502,7 +3546,7 @@ static void Cb_OnBPressed(u8 taskId) PrintMessage(MSG_HOLDING_POKE); sPSSData->state = 1; } - else if (IsActiveItemMoving()) + else if (IsMovingItem()) { SetPSSCallback(Cb_CloseBoxWhileHoldingItem); } @@ -3558,8 +3602,8 @@ static void Cb_ChangeScreen(u8 taskId) u8 mode, monIndex, maxMonIndex; u8 screenChangeType = sPSSData->screenChangeType; - if (sPSSData->boxOption == OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE) - sMovingItemId = GetMovingItem(); + if (sPSSData->boxOption == OPTION_MOVE_ITEMS && IsMovingItem() == TRUE) + sMovingItemId = GetMovingItemId(); else sMovingItemId = ITEM_NONE; @@ -3671,32 +3715,32 @@ static void sub_80CA0D8(void) LoadPalette(gUnknown_0857243C, 0x30, 0x20); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30)); - LoadCursorMonSprite(); - sub_80CA154(); - sub_80CA1C4(); + CreateCursorMonSprite(); + CreateMarkingComboSprite(); + CreateWaveformSprites(); RefreshCursorMonData(); } -static void sub_80CA154(void) +static void CreateMarkingComboSprite(void) { - sPSSData->field_D94 = CreateMonMarkingComboSprite(TAG_TILE_10, TAG_PAL_DAC8, NULL); - sPSSData->field_D94->oam.priority = 1; - sPSSData->field_D94->subpriority = 1; - sPSSData->field_D94->pos1.x = 40; - sPSSData->field_D94->pos1.y = 150; - sPSSData->field_DA0 = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(TAG_TILE_10); + sPSSData->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MON_MARKING, PALTAG_MON_MARKING, NULL); + sPSSData->markingComboSprite->oam.priority = 1; + sPSSData->markingComboSprite->subpriority = 1; + sPSSData->markingComboSprite->pos1.x = 40; + sPSSData->markingComboSprite->pos1.y = 150; + sPSSData->markingComboTilesPtr = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MON_MARKING); } -static void sub_80CA1C4(void) +static void CreateWaveformSprites(void) { u16 i; - struct SpriteSheet sheet = gWaveformSpriteSheet; + struct SpriteSheet sheet = sSpriteSheet_Waveform; LoadSpriteSheet(&sheet); - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) { u8 spriteId = CreateSprite(&sSpriteTemplate_Waveform, i * 63 + 8, 9, 2); - sPSSData->field_D98[i] = &gSprites[spriteId]; + sPSSData->waveformSprites[i] = &gSprites[spriteId]; } } @@ -3704,7 +3748,7 @@ static void RefreshCursorMonData(void) { LoadCursorMonGfx(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality); PrintCursorMonInfo(); - sub_80CA65C(); + UpdateWaveformAnimation(); ScheduleBgCopyTilemapToVram(0); } @@ -3721,7 +3765,7 @@ static void BoxSetMosaic(void) } } -static u8 sub_80CA2B8(void) +static u8 GetCursorMonMosaic(void) { return sPSSData->cursorMonSprite->oam.mosaic; } @@ -3739,20 +3783,20 @@ static void sub_80CA2D0(struct Sprite *sprite) } } -static void LoadCursorMonSprite(void) +static void CreateCursorMonSprite(void) { u16 i; u16 tileStart; u8 palSlot; u8 spriteId; - struct SpriteSheet sheet = {sPSSData->field_22C4, MON_PIC_SIZE, TAG_TILE_2}; - struct SpritePalette palette = {sPSSData->field_2244, TAG_PAL_DAC6}; + struct SpriteSheet sheet = {sPSSData->tileBuffer, MON_PIC_SIZE, GFXTAG_CURSOR_MON}; + struct SpritePalette palette = {sPSSData->cursorMonPalBuffer, PALTAG_CURSOR_MON}; struct SpriteTemplate template = sSpriteTemplate_CursorMon; for (i = 0; i < MON_PIC_SIZE; i++) - sPSSData->field_22C4[i] = 0; - for (i = 0; i < 0x10; i++) - sPSSData->field_2244[i] = 0; + sPSSData->tileBuffer[i] = 0; + for (i = 0; i < 16; i++) + sPSSData->cursorMonPalBuffer[i] = 0; sPSSData->cursorMonSprite = NULL; @@ -3771,14 +3815,14 @@ static void LoadCursorMonSprite(void) break; sPSSData->cursorMonSprite = &gSprites[spriteId]; - sPSSData->field_223A = palSlot * 16 + 0x100; - sPSSData->field_223C = (void*) OBJ_VRAM0 + tileStart * 32; + sPSSData->cursorMonPalOffset = palSlot * 16 + 0x100; + sPSSData->cursorMonTilePtr = (void*) OBJ_VRAM0 + tileStart * 32; } while (0); if (sPSSData->cursorMonSprite == NULL) { - FreeSpriteTilesByTag(TAG_TILE_2); - FreeSpritePaletteByTag(TAG_PAL_DAC6); + FreeSpriteTilesByTag(GFXTAG_CURSOR_MON); + FreeSpritePaletteByTag(PALTAG_CURSOR_MON); } } @@ -3789,10 +3833,10 @@ static void LoadCursorMonGfx(u16 species, u32 pid) if (species != SPECIES_NONE) { - LoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->field_22C4, species, pid, TRUE); - LZ77UnCompWram(sPSSData->cursorMonPalette, sPSSData->field_2244); - CpuCopy32(sPSSData->field_22C4, sPSSData->field_223C, MON_PIC_SIZE); - LoadPalette(sPSSData->field_2244, sPSSData->field_223A, 0x20); + LoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->tileBuffer, species, pid, TRUE); + LZ77UnCompWram(sPSSData->cursorMonPalette, sPSSData->cursorMonPalBuffer); + CpuCopy32(sPSSData->tileBuffer, sPSSData->cursorMonTilePtr, MON_PIC_SIZE); + LoadPalette(sPSSData->cursorMonPalBuffer, sPSSData->cursorMonPalOffset, 0x20); sPSSData->cursorMonSprite->invisible = FALSE; } else @@ -3822,30 +3866,33 @@ static void PrintCursorMonInfo(void) CopyWindowToVram(0, 2); if (sPSSData->cursorMonSpecies != SPECIES_NONE) { - UpdateMonMarkingTiles(sPSSData->cursorMonMarkings, sPSSData->field_DA0); - sPSSData->field_D94->invisible = FALSE; + UpdateMonMarkingTiles(sPSSData->cursorMonMarkings, sPSSData->markingComboTilesPtr); + sPSSData->markingComboSprite->invisible = FALSE; } else { - sPSSData->field_D94->invisible = TRUE; + sPSSData->markingComboSprite->invisible = TRUE; } } -static void sub_80CA65C(void) +// Turn the wave animation on the sides of "Pkmn Data" on/off +static void UpdateWaveformAnimation(void) { u16 i; if (sPSSData->cursorMonSpecies != SPECIES_NONE) { + // Start animation sub_80D27AC(0, 0, 0, 8, 2); - for (i = 0; i < 2; i++) - StartSpriteAnimIfDifferent(sPSSData->field_D98[i], i * 2 + 1); + for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) + StartSpriteAnimIfDifferent(sPSSData->waveformSprites[i], i * 2 + 1); } else { + // Stop animation sub_80D27AC(0, 0, 2, 8, 2); - for (i = 0; i < 2; i++) - StartSpriteAnim(sPSSData->field_D98[i], i * 2); + for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) + StartSpriteAnim(sPSSData->waveformSprites[i], i * 2); } sub_80D2918(0); @@ -4098,7 +4145,7 @@ static void PrintMessage(u8 id) DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->field_21E0); break; case MSG_FORMAT_ITEM_NAME: - if (IsActiveItemMoving()) + if (IsMovingItem()) txtPtr = StringCopy(sPSSData->itemName, GetMovingItemName()); else txtPtr = StringCopy(sPSSData->itemName, sPSSData->cursorMonItemName); @@ -4892,15 +4939,15 @@ static struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s { u16 tileNum; u8 spriteId; - struct SpriteTemplate tempalte = gUnknown_085728D4; + struct SpriteTemplate template = gUnknown_085728D4; species = GetIconSpecies(species, personality); - tempalte.paletteTag = 0xDAC0 + gMonIconPaletteIndices[species]; + template.paletteTag = PALTAG_MON_ICON_0 + gMonIconPaletteIndices[species]; tileNum = sub_80CC124(species); if (tileNum == 0xFFFF) return NULL; - spriteId = CreateSprite(&tempalte, x, y, subpriority); + spriteId = CreateSprite(&template, x, y, subpriority); if (spriteId == MAX_SPRITES) { sub_80CC1E0(species); @@ -5595,7 +5642,7 @@ static bool8 sub_80CD554(void) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return FALSE; else - return sub_80D1218(); + return IsItemIconAnimActive(); } else if (--sPSSData->field_CD0 != 0) { @@ -5704,7 +5751,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) } else { - if (!IsActiveItemMoving()) + if (!IsMovingItem()) StartSpriteAnim(sPSSData->field_CB4, 1); } @@ -5763,7 +5810,7 @@ static void sub_80CDA68(void) } else { - if (!IsActiveItemMoving()) + if (!IsMovingItem()) StartSpriteAnim(sPSSData->field_CB4, 0); } @@ -6517,7 +6564,7 @@ static void SetCursorMonData(void *pokemon, u8 mode) u16 gender; bool8 sanityIsBadEgg; - sPSSData->cursorMonItem = 0; + sPSSData->cursorMonItemId = ITEM_NONE; gender = MON_MALE; sanityIsBadEgg = FALSE; if (mode == MODE_PARTY) @@ -6540,7 +6587,7 @@ static void SetCursorMonData(void *pokemon, u8 mode) sPSSData->cursorMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); sPSSData->cursorMonPalette = GetMonFrontSpritePal(mon); gender = GetMonGender(mon); - sPSSData->cursorMonItem = GetMonData(mon, MON_DATA_HELD_ITEM); + sPSSData->cursorMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); } } else if (mode == MODE_BOX) @@ -6565,13 +6612,13 @@ static void SetCursorMonData(void *pokemon, u8 mode) sPSSData->cursorMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); sPSSData->cursorMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, otId, sPSSData->cursorMonPersonality); gender = GetGenderFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality); - sPSSData->cursorMonItem = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); + sPSSData->cursorMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); } } else { sPSSData->cursorMonSpecies = SPECIES_NONE; - sPSSData->cursorMonItem = 0; + sPSSData->cursorMonItemId = ITEM_NONE; } if (sPSSData->cursorMonSpecies == SPECIES_NONE) @@ -6642,8 +6689,8 @@ static void SetCursorMonData(void *pokemon, u8 mode) txtPtr[0] = CHAR_SPACE; txtPtr[1] = EOS; - if (sPSSData->cursorMonItem != 0) - StringCopyPadded(sPSSData->cursorMonItemName, ItemId_GetName(sPSSData->cursorMonItem), CHAR_SPACE, 8); + if (sPSSData->cursorMonItemId != ITEM_NONE) + StringCopyPadded(sPSSData->cursorMonItemName, ItemId_GetName(sPSSData->cursorMonItemId), CHAR_SPACE, 8); else StringFill(sPSSData->cursorMonItemName, CHAR_SPACE, 8); } @@ -7326,9 +7373,9 @@ static bool8 sub_80CFB44(void) if (sPSSData->cursorMonSpecies == SPECIES_EGG) return FALSE; - if (!IsActiveItemMoving()) + if (!IsMovingItem()) { - if (sPSSData->cursorMonItem == 0) + if (sPSSData->cursorMonItemId == ITEM_NONE) { if (sPSSData->cursorMonSpecies == SPECIES_NONE) return FALSE; @@ -7337,7 +7384,7 @@ static bool8 sub_80CFB44(void) } else { - if (!ItemIsMail(sPSSData->cursorMonItem)) + if (!ItemIsMail(sPSSData->cursorMonItemId)) { SetMenuText(MENU_TAKE); SetMenuText(MENU_BAG); @@ -7347,7 +7394,7 @@ static bool8 sub_80CFB44(void) } else { - if (sPSSData->cursorMonItem == 0) + if (sPSSData->cursorMonItemId == ITEM_NONE) { if (sPSSData->cursorMonSpecies == SPECIES_NONE) return FALSE; @@ -7356,7 +7403,7 @@ static bool8 sub_80CFB44(void) } else { - if (ItemIsMail(sPSSData->cursorMonItem) == TRUE) + if (ItemIsMail(sPSSData->cursorMonItemId) == TRUE) return FALSE; SetMenuText(MENU_SWITCH); @@ -7387,7 +7434,7 @@ static void sub_80CFC14(void) struct SpritePalette spritePalettes[] = { - {gHandCursorPalette, TAG_PAL_DAC7}, + {gHandCursorPalette, PALTAG_7}, {} }; @@ -7437,7 +7484,7 @@ static void sub_80CFC14(void) static const struct SpriteTemplate gSpriteTemplate_857BA50 = { .tileTag = TAG_TILE_0, - .paletteTag = TAG_PAL_WAVEFORM, + .paletteTag = PALTAG_10, .oam = &sOamData_857BA0C, .anims = sSpriteAnimTable_857BA40, .images = NULL, @@ -7448,7 +7495,7 @@ static void sub_80CFC14(void) static const struct SpriteTemplate gSpriteTemplate_857BA68 = { .tileTag = TAG_TILE_1, - .paletteTag = TAG_PAL_WAVEFORM, + .paletteTag = PALTAG_10, .oam = &sOamData_857BA14, .anims = gDummySpriteAnimTable, .images = NULL, @@ -7458,8 +7505,8 @@ static void sub_80CFC14(void) LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePalettes); - sPSSData->field_CD8[0] = IndexOfSpritePaletteTag(TAG_PAL_WAVEFORM); - sPSSData->field_CD8[1] = IndexOfSpritePaletteTag(TAG_PAL_DAC7); + sPSSData->field_CD8[0] = IndexOfSpritePaletteTag(PALTAG_10); + sPSSData->field_CD8[1] = IndexOfSpritePaletteTag(PALTAG_7); sub_80CD444(sBoxCursorArea, sBoxCursorPosition, &x, &y); spriteId = CreateSprite(&gSpriteTemplate_857BA50, x, y, 6); @@ -8260,9 +8307,28 @@ static bool8 sub_80D0BC0(void) return TRUE; } -static const u32 gUnknown_0857BB24[] = INCBIN_U32("graphics/pokemon_storage/unknown_frame.4bpp"); - -static const struct OamData sOamData_857BBA4 = +// The functions below handle new features of MOVE_ITEMS box option. +static bool32 IsItemIconAtPosition(u8, u8); +static const u32 *GetItemIconPic(u16); +static const u32 *GetItemIconPalette(u16); +static u8 GetNewItemIconIdx(void); +static void SetItemIconPosition(u8, u8, u8); +static void LoadItemIconGfx(u8, const u32 *, const u32 *); +static void SetItemIconAffineAnim(u8, u8); +static void SetItemIconActive(u8, bool8); +static u8 GetItemIconIdxByPosition(u8, u8); +static void SetItemIconCallback(u8, u8, u8, u8); +static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *); +static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *); +static void SpriteCB_ItemIcon_ToHand(struct Sprite *); +static void SpriteCB_ItemIcon_ToMon(struct Sprite *); +static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *); +static void SpriteCB_ItemIcon_HideParty(struct Sprite *); +static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *); + +static const u32 sItemInfoFrame_Gfx[] = INCBIN_U32("graphics/pokemon_storage/item_info_frame.4bpp"); + +static const struct OamData sOamData_ItemIcon = { .y = 0, .affineMode = ST_OAM_AFFINE_NORMAL, @@ -8279,27 +8345,27 @@ static const struct OamData sOamData_857BBA4 = .affineParam = 0 }; -static const union AffineAnimCmd sSpriteAffineAnim_857BBAC[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_Small[] = { AFFINEANIMCMD_FRAME(128, 128, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BBBC[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_Appear[] = { AFFINEANIMCMD_FRAME(88, 88, 0, 0), AFFINEANIMCMD_FRAME(5, 5, 0, 8), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BBD4[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_Disappear[] = { AFFINEANIMCMD_FRAME(128, 128, 0, 0), AFFINEANIMCMD_FRAME(-5, -5, 0, 8), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BBEC[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_PickUp[] = { AFFINEANIMCMD_FRAME(128, 128, 0, 0), AFFINEANIMCMD_FRAME(10, 10, 0, 12), @@ -8307,7 +8373,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_857BBEC[] = AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BC0C[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_PutDown[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_FRAME(-10, -10, 0, 12), @@ -8315,42 +8381,42 @@ static const union AffineAnimCmd sSpriteAffineAnim_857BC0C[] = AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BC2C[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_PutAway[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_FRAME(-5, -5, 0, 16), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_857BC44[] = +static const union AffineAnimCmd sAffineAnim_ItemIcon_Large[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const sSpriteAffineAnimTable_857BC44[] = +static const union AffineAnimCmd *const sAffineAnims_ItemIcon[] = { - sSpriteAffineAnim_857BBAC, - sSpriteAffineAnim_857BBBC, - sSpriteAffineAnim_857BBD4, - sSpriteAffineAnim_857BBEC, - sSpriteAffineAnim_857BC0C, - sSpriteAffineAnim_857BC2C, - sSpriteAffineAnim_857BC44 + [ITEM_ANIM_NONE] = sAffineAnim_ItemIcon_Small, + [ITEM_ANIM_APPEAR] = sAffineAnim_ItemIcon_Appear, + [ITEM_ANIM_DISAPPEAR] = sAffineAnim_ItemIcon_Disappear, + [ITEM_ANIM_PICK_UP] = sAffineAnim_ItemIcon_PickUp, + [ITEM_ANIM_PUT_DOWN] = sAffineAnim_ItemIcon_PutDown, + [ITEM_ANIM_PUT_AWAY] = sAffineAnim_ItemIcon_PutAway, + [ITEM_ANIM_LARGE] = sAffineAnim_ItemIcon_Large }; -static const struct SpriteTemplate gSpriteTemplate_857BC70 = +static const struct SpriteTemplate sSpriteTemplate_ItemIcon = { - .tileTag = TAG_TILE_7, - .paletteTag = TAG_PAL_DACB, - .oam = &sOamData_857BBA4, + .tileTag = GFXTAG_ITEM_ICON_0, + .paletteTag = PALTAG_ITEM_ICON_0, + .oam = &sOamData_ItemIcon, .anims = gDummySpriteAnimTable, .images = NULL, - .affineAnims = sSpriteAffineAnimTable_857BC44, + .affineAnims = sAffineAnims_ItemIcon, .callback = SpriteCallbackDummy, }; -static void sub_80D0C60(void) +static void CreateItemIconSprites(void) { s32 i; u8 spriteId; @@ -8359,55 +8425,38 @@ static void sub_80D0C60(void) if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { - spriteSheet.data = gUnknown_03000F78; + spriteSheet.data = sItemIconGfxBuffer; spriteSheet.size = 0x200; - spriteTemplate = gSpriteTemplate_857BC70; + spriteTemplate = sSpriteTemplate_ItemIcon; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - spriteSheet.tag = TAG_TILE_7 + i; + spriteSheet.tag = GFXTAG_ITEM_ICON_0 + i; LoadCompressedSpriteSheet(&spriteSheet); - sPSSData->field_2204[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * 32 + (void*)(OBJ_VRAM0); - sPSSData->field_2204[i].palIndex = AllocSpritePalette(TAG_PAL_DACB + i); - sPSSData->field_2204[i].palIndex *= 16; - sPSSData->field_2204[i].palIndex += 0x100; - spriteTemplate.tileTag = TAG_TILE_7 + i; - spriteTemplate.paletteTag = TAG_PAL_DACB + i; + sPSSData->itemIcons[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * 32 + (void*)(OBJ_VRAM0); + sPSSData->itemIcons[i].palIndex = AllocSpritePalette(PALTAG_ITEM_ICON_0 + i); + sPSSData->itemIcons[i].palIndex *= 16; + sPSSData->itemIcons[i].palIndex += 0x100; + spriteTemplate.tileTag = GFXTAG_ITEM_ICON_0 + i; + spriteTemplate.paletteTag = PALTAG_ITEM_ICON_0 + i; spriteId = CreateSprite(&spriteTemplate, 0, 0, 11); - sPSSData->field_2204[i].sprite = &gSprites[spriteId]; - sPSSData->field_2204[i].sprite->invisible = TRUE; - sPSSData->field_2204[i].unk10 = 0; + sPSSData->itemIcons[i].sprite = &gSprites[spriteId]; + sPSSData->itemIcons[i].sprite->invisible = TRUE; + sPSSData->itemIcons[i].active = FALSE; } } - sPSSData->movingItem = 0; + sPSSData->movingItemId = ITEM_NONE; } -// The functions below handle new features of MOVE_ITEMS box option. -static bool32 sub_80D1324(u8 cursorArea, u8 cursorPos); -static const u32 *GetItemIconPic(u16 itemId); -static const u32 *GetItemIconPalette(u16 itemId); -static u8 sub_80D12E8(void); -static void sub_80D140C(u8 id, u8 cursorArea, u8 cursorPos); -static void sub_80D1524(u8 id, const u32 *itemTiles, const u32 *itemPal); -static void sub_80D15D4(u8 id, u8 animNum); -static void sub_80D1740(u8 id, bool8 arg1); -static u8 sub_80D1370(u8 cursorArea, u8 cursorPos); -static void sub_80D1604(u8 id, u8 arg1, u8 arg2, u8 arg3); -static void sub_80D1AD8(struct Sprite *sprite); -static void sub_80D1A48(struct Sprite *sprite); -static void sub_80D1A74(struct Sprite *sprite); -static void sub_80D1B14(struct Sprite *sprite); -static void sub_80D1B94(struct Sprite *sprite); -static void sub_80D1CCC(struct Sprite *sprite); -static void sub_80D1C30(struct Sprite *sprite); - static void sub_80D0D8C(u8 cursorArea, u8 cursorPos) { u16 heldItem; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - if (sub_80D1324(cursorArea, cursorPos)) + + // If we've already loaded the item here, stop + if (IsItemIconAtPosition(cursorArea, cursorPos)) return; switch (cursorArea) @@ -8426,16 +8475,16 @@ static void sub_80D0D8C(u8 cursorArea, u8 cursorPos) return; } - if (heldItem != 0) + if (heldItem != ITEM_NONE) { const u32 *tiles = GetItemIconPic(heldItem); const u32 *pal = GetItemIconPalette(heldItem); - u8 id = sub_80D12E8(); + u8 id = GetNewItemIconIdx(); - sub_80D140C(id, cursorArea, cursorPos); - sub_80D1524(id, tiles, pal); - sub_80D15D4(id, 1); - sub_80D1740(id, TRUE); + SetItemIconPosition(id, cursorArea, cursorPos); + LoadItemIconGfx(id, tiles, pal); + SetItemIconAffineAnim(id, ITEM_ANIM_APPEAR); + SetItemIconActive(id, TRUE); } } @@ -8446,79 +8495,78 @@ static void sub_80D0E50(u8 cursorArea, u8 cursorPos) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - id = sub_80D1370(cursorArea, cursorPos); - sub_80D15D4(id, 2); - sub_80D1604(id, 0, cursorArea, cursorPos); + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_DISAPPEAR); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); } static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) { u8 id; - u16 item; + u16 itemId; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - id = sub_80D1370(cursorArea, cursorPos); - item = 0; - sub_80D15D4(id, 3); - sub_80D1604(id, 1, cursorArea, cursorPos); - sub_80D140C(id, 2, 0); - if (cursorArea == CURSOR_AREA_IN_BOX) + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + itemId = ITEM_NONE; + SetItemIconAffineAnim(id, ITEM_ANIM_PICK_UP); + SetItemIconCallback(id, ITEM_CB_TO_HAND, cursorArea, cursorPos); + SetItemIconPosition(id, CURSOR_AREA_IN_HAND, 0); + if (cursorArea == CURSOR_AREA_IN_BOX) { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &itemId); SetBoxMonIconObjMode(cursorPos, 1); } else { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &itemId); SetPartyMonIconObjMode(cursorPos, 1); } - sPSSData->movingItem = sPSSData->cursorMonItem; + sPSSData->movingItemId = sPSSData->cursorMonItemId; } -static void sub_80D0F38(u16 item) +static void sub_80D0F38(u16 itemId) { - const u32 *tiles = GetItemIconPic(item); - const u32 *pal = GetItemIconPalette(item); - u8 id = sub_80D12E8(); - - sub_80D1524(id, tiles, pal); - sub_80D15D4(id, 6); - sub_80D1604(id, 1, 0, 0); - sub_80D140C(id, 2, 0); - sub_80D1740(id, TRUE); - sPSSData->movingItem = item; + const u32 *tiles = GetItemIconPic(itemId); + const u32 *pal = GetItemIconPalette(itemId); + u8 id = GetNewItemIconIdx(); + LoadItemIconGfx(id, tiles, pal); + SetItemIconAffineAnim(id, ITEM_ANIM_LARGE); + SetItemIconCallback(id, ITEM_CB_TO_HAND, CURSOR_AREA_IN_BOX, 0); + SetItemIconPosition(id, CURSOR_AREA_IN_HAND, 0); + SetItemIconActive(id, TRUE); + sPSSData->movingItemId = itemId; } static void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) { u8 id; - u16 item; + u16 itemId; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - id = sub_80D1370(cursorArea, cursorPos); - sub_80D15D4(id, 3); - sub_80D1604(id, 3, 2, 0); + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_PICK_UP); + SetItemIconCallback(id, ITEM_CB_SWAP_TO_HAND, CURSOR_AREA_IN_HAND, 0); if (cursorArea == CURSOR_AREA_IN_BOX) { - item = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItem); - sPSSData->movingItem = item; + itemId = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItemId); + sPSSData->movingItemId = itemId; } else { - item = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItem); - sPSSData->movingItem = item; + itemId = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItemId); + sPSSData->movingItemId = itemId; } - id = sub_80D1370(2, 0); - sub_80D15D4(id, 4); - sub_80D1604(id, 4, cursorArea, cursorPos); + id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_DOWN); + SetItemIconCallback(id, ITEM_CB_SWAP_TO_MON, cursorArea, cursorPos); } static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) @@ -8528,17 +8576,17 @@ static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - id = sub_80D1370(2, 0); - sub_80D15D4(id, 4); - sub_80D1604(id, 2, cursorArea, cursorPos); + id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_DOWN); + SetItemIconCallback(id, ITEM_CB_TO_MON, cursorArea, cursorPos); if (cursorArea == CURSOR_AREA_IN_BOX) { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItem); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItemId); SetBoxMonIconObjMode(cursorPos, 0); } else { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItem); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItemId); SetPartyMonIconObjMode(cursorPos, 0); } } @@ -8552,10 +8600,10 @@ static void Item_TakeMons(u8 cursorArea, u8 cursorPos) return; item = 0; - id = sub_80D1370(cursorArea, cursorPos); - sub_80D15D4(id, 2); - sub_80D1604(id, 0, cursorArea, cursorPos); - if (cursorArea == CURSOR_AREA_IN_BOX) + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_DISAPPEAR); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); + if (cursorArea == CURSOR_AREA_IN_BOX) { SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); SetBoxMonIconObjMode(cursorPos, 1); @@ -8571,9 +8619,9 @@ static void sub_80D1194(void) { if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { - u8 id = sub_80D1370(2, 0); - sub_80D15D4(id, 5); - sub_80D1604(id, 0, 2, 0); + u8 id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_AWAY); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, CURSOR_AREA_IN_HAND, 0); } } @@ -8584,122 +8632,120 @@ static void sub_80D11CC(void) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 && sPSSData->field_2204[i].unk8 == 1) - sub_80D1604(i, 7, 2, 0); + if (sPSSData->itemIcons[i].active + && sPSSData->itemIcons[i].cursorArea == CURSOR_AREA_IN_PARTY) + SetItemIconCallback(i, ITEM_CB_HIDE_PARTY, CURSOR_AREA_IN_HAND, 0); } } -static bool8 sub_80D1218(void) +static bool8 IsItemIconAnimActive(void) { s32 i; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10) + if (sPSSData->itemIcons[i].active) { - if (!sPSSData->field_2204[i].sprite->affineAnimEnded && sPSSData->field_2204[i].sprite->affineAnimBeginning) + if (!sPSSData->itemIcons[i].sprite->affineAnimEnded + && sPSSData->itemIcons[i].sprite->affineAnimBeginning) return TRUE; - if (sPSSData->field_2204[i].sprite->callback != SpriteCallbackDummy && sPSSData->field_2204[i].sprite->callback != sub_80D1AD8) + if (sPSSData->itemIcons[i].sprite->callback != SpriteCallbackDummy + && sPSSData->itemIcons[i].sprite->callback != SpriteCB_ItemIcon_SetPosToCursor) return TRUE; } } - return FALSE; } -static bool8 IsActiveItemMoving(void) +static bool8 IsMovingItem(void) { s32 i; if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 && sPSSData->field_2204[i].unk8 == 2) + if (sPSSData->itemIcons[i].active + && sPSSData->itemIcons[i].cursorArea == CURSOR_AREA_IN_HAND) return TRUE; } } - return FALSE; } static const u8 *GetMovingItemName(void) { - return ItemId_GetName(sPSSData->movingItem); + return ItemId_GetName(sPSSData->movingItemId); } -static u16 GetMovingItem(void) +static u16 GetMovingItemId(void) { - return sPSSData->movingItem; + return sPSSData->movingItemId; } -static u8 sub_80D12E8(void) +static u8 GetNewItemIconIdx(void) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 == 0) + if (!sPSSData->itemIcons[i].active) { - sPSSData->field_2204[i].unk10 = 1; + sPSSData->itemIcons[i].active = TRUE; return i; } } - - return 3; + return MAX_ITEM_ICONS; } -static bool32 sub_80D1324(u8 cursorArea, u8 cursorPos) +static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos) { s32 i; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 - && sPSSData->field_2204[i].unk8 == cursorArea - && sPSSData->field_2204[i].unk9 == cursorPos) + if (sPSSData->itemIcons[i].active + && sPSSData->itemIcons[i].cursorArea == cursorArea + && sPSSData->itemIcons[i].cursorPos == cursorPos) return TRUE; } - return FALSE; } -static u8 sub_80D1370(u8 cursorArea, u8 cursorPos) +static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 - && sPSSData->field_2204[i].unk8 == cursorArea - && sPSSData->field_2204[i].unk9 == cursorPos) + if (sPSSData->itemIcons[i].active + && sPSSData->itemIcons[i].cursorArea == cursorArea + && sPSSData->itemIcons[i].cursorPos == cursorPos) return i; } - - return 3; + return MAX_ITEM_ICONS; } -static u8 sub_80D13C4(struct Sprite *sprite) +static u8 GetItemIconIdxBySprite(struct Sprite *sprite) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->field_2204[i].unk10 - && sPSSData->field_2204[i].sprite == sprite) + if (sPSSData->itemIcons[i].active + && sPSSData->itemIcons[i].sprite == sprite) return i; } - - return 3; + return MAX_ITEM_ICONS; } -static void sub_80D140C(u8 id, u8 cursorArea, u8 cursorPos) +static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) { u8 row, column; - if (id >= 3) + if (id >= MAX_ITEM_ICONS) return; switch (cursorArea) @@ -8707,100 +8753,108 @@ static void sub_80D140C(u8 id, u8 cursorArea, u8 cursorPos) case CURSOR_AREA_IN_BOX: row = cursorPos % IN_BOX_ROWS; column = cursorPos / IN_BOX_ROWS; - sPSSData->field_2204[id].sprite->pos1.x = (24 * row) + 112; - sPSSData->field_2204[id].sprite->pos1.y = (24 * column) + 56; - sPSSData->field_2204[id].sprite->oam.priority = 2; + sPSSData->itemIcons[id].sprite->pos1.x = (24 * row) + 112; + sPSSData->itemIcons[id].sprite->pos1.y = (24 * column) + 56; + sPSSData->itemIcons[id].sprite->oam.priority = 2; break; case CURSOR_AREA_IN_PARTY: if (cursorPos == 0) { - sPSSData->field_2204[id].sprite->pos1.x = 116; - sPSSData->field_2204[id].sprite->pos1.y = 76; + sPSSData->itemIcons[id].sprite->pos1.x = 116; + sPSSData->itemIcons[id].sprite->pos1.y = 76; } else { - sPSSData->field_2204[id].sprite->pos1.x = 164; - sPSSData->field_2204[id].sprite->pos1.y = 24 * (cursorPos - 1) + 28; + sPSSData->itemIcons[id].sprite->pos1.x = 164; + sPSSData->itemIcons[id].sprite->pos1.y = 24 * (cursorPos - 1) + 28; } - sPSSData->field_2204[id].sprite->oam.priority = 1; + sPSSData->itemIcons[id].sprite->oam.priority = 1; break; } - sPSSData->field_2204[id].unk8 = cursorArea; - sPSSData->field_2204[id].unk9 = cursorPos; + sPSSData->itemIcons[id].cursorArea = cursorArea; + sPSSData->itemIcons[id].cursorPos = cursorPos; } -static void sub_80D1524(u8 id, const u32 *itemTiles, const u32 *itemPal) +static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) { s32 i; - if (id >= 3) + if (id >= MAX_ITEM_ICONS) return; CpuFastFill(0, sPSSData->field_42C4, 0x200); - LZ77UnCompWram(itemTiles, sPSSData->field_22C4); + LZ77UnCompWram(itemTiles, sPSSData->tileBuffer); for (i = 0; i < 3; i++) - CpuFastCopy(sPSSData->field_22C4 + (i * 0x60), sPSSData->field_42C4 + (i * 0x80), 0x60); + CpuFastCopy(&sPSSData->tileBuffer[i * 0x60], &sPSSData->field_42C4[i * 0x80], 0x60); - CpuFastCopy(sPSSData->field_42C4, sPSSData->field_2204[id].tiles, 0x200); + CpuFastCopy(sPSSData->field_42C4, sPSSData->itemIcons[id].tiles, 0x200); LZ77UnCompWram(itemPal, sPSSData->field_42C4); - LoadPalette(sPSSData->field_42C4, sPSSData->field_2204[id].palIndex, 0x20); + LoadPalette(sPSSData->field_42C4, sPSSData->itemIcons[id].palIndex, 0x20); } -static void sub_80D15D4(u8 id, u8 animNum) +static void SetItemIconAffineAnim(u8 id, u8 animNum) { - if (id >= 3) + if (id >= MAX_ITEM_ICONS) return; - StartSpriteAffineAnim(sPSSData->field_2204[id].sprite, animNum); + StartSpriteAffineAnim(sPSSData->itemIcons[id].sprite, animNum); } -static void sub_80D1604(u8 id, u8 arg1, u8 arg2, u8 arg3) +#define sItemIconId data[0] +#define sState data[0] +#define sCursorArea data[6] +#define sCursorPos data[7] + +static void SetItemIconCallback(u8 id, u8 callbackId, u8 cursorArea, u8 cursorPos) { - if (id >= 3) + if (id >= MAX_ITEM_ICONS) return; - switch (arg1) + switch (callbackId) { - case 0: - sPSSData->field_2204[id].sprite->data[0] = id; - sPSSData->field_2204[id].sprite->callback = sub_80D1A48; + case ITEM_CB_WAIT_ANIM: + sPSSData->itemIcons[id].sprite->sItemIconId = id; + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_WaitAnim; break; - case 1: - sPSSData->field_2204[id].sprite->data[0] = 0; - sPSSData->field_2204[id].sprite->callback = sub_80D1A74; + case ITEM_CB_TO_HAND: + sPSSData->itemIcons[id].sprite->sState = 0; + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToHand; break; - case 2: - sPSSData->field_2204[id].sprite->data[0] = 0; - sPSSData->field_2204[id].sprite->data[6] = arg2; - sPSSData->field_2204[id].sprite->data[7] = arg3; - sPSSData->field_2204[id].sprite->callback = sub_80D1B14; + case ITEM_CB_TO_MON: + sPSSData->itemIcons[id].sprite->sState = 0; + sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; + sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToMon; break; - case 3: - sPSSData->field_2204[id].sprite->data[0] = 0; - sPSSData->field_2204[id].sprite->callback = sub_80D1B94; - sPSSData->field_2204[id].sprite->data[6] = arg2; - sPSSData->field_2204[id].sprite->data[7] = arg3; + case ITEM_CB_SWAP_TO_HAND: + sPSSData->itemIcons[id].sprite->sState = 0; + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToHand; + sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; + sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; break; - case 4: - sPSSData->field_2204[id].sprite->data[0] = 0; - sPSSData->field_2204[id].sprite->data[6] = arg2; - sPSSData->field_2204[id].sprite->data[7] = arg3; - sPSSData->field_2204[id].sprite->callback = sub_80D1C30; + case ITEM_CB_SWAP_TO_MON: + sPSSData->itemIcons[id].sprite->sState = 0; + sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; + sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToMon; break; - case 7: - sPSSData->field_2204[id].sprite->callback = sub_80D1CCC; + case ITEM_CB_HIDE_PARTY: + // If cursor is on a Pokémon with a held item and + // the player closes the party menu, have the held + // item follow the Pokémon as the menu slides out + sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_HideParty; break; } } -static void sub_80D1740(u8 id, bool8 arg1) +static void SetItemIconActive(u8 id, bool8 active) { - if (id >= 3) + if (id >= MAX_ITEM_ICONS) return; - sPSSData->field_2204[id].unk10 = arg1; - sPSSData->field_2204[id].sprite->invisible = (arg1 == FALSE); + sPSSData->itemIcons[id].active = active; + sPSSData->itemIcons[id].sprite->invisible = (active == FALSE); } static const u32 *GetItemIconPic(u16 itemId) @@ -8817,90 +8871,88 @@ static void PrintItemDescription(void) { const u8 *description; - if (IsActiveItemMoving()) - description = ItemId_GetDescription(sPSSData->movingItem); + if (IsMovingItem()) + description = ItemId_GetDescription(sPSSData->movingItemId); else - description = ItemId_GetDescription(sPSSData->cursorMonItem); + description = ItemId_GetDescription(sPSSData->cursorMonItemId); FillWindowPixelBuffer(2, PIXEL_FILL(1)); AddTextPrinterParameterized5(2, 1, description, 4, 0, 0, NULL, 0, 1); } -static void sub_80D1818(void) +static void InitItemInfoWindow(void) { - sPSSData->field_2236 = 0x15; - LoadBgTiles(0, gUnknown_0857BB24, 0x80, 0x13A); - sub_80D19B4(0); + sPSSData->itemInfoWindowOffset = 21; + LoadBgTiles(0, sItemInfoFrame_Gfx, 0x80, 0x13A); + DrawItemInfoWindow(0); } -static bool8 sub_80D184C(void) +static bool8 UpdateItemInfoWindowSlideIn(void) { - s32 i, var; + s32 i, pos; - if (sPSSData->field_2236 == 0) + if (sPSSData->itemInfoWindowOffset == 0) return FALSE; - sPSSData->field_2236--; - var = 0x15 - sPSSData->field_2236; - for (i = 0; i < var; i++) - { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); - } + sPSSData->itemInfoWindowOffset--; + pos = 21 - sPSSData->itemInfoWindowOffset; + for (i = 0; i < pos; i++) + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); - sub_80D19B4(var); - return (sPSSData->field_2236 != 0); + DrawItemInfoWindow(pos); + return (sPSSData->itemInfoWindowOffset != 0); } -static bool8 sub_80D18E4(void) +static bool8 UpdateItemInfoWindowSlideOut(void) { - s32 i, var; + s32 i, pos; - if (sPSSData->field_2236 == 0x16) + if (sPSSData->itemInfoWindowOffset == 22) return FALSE; - if (sPSSData->field_2236 == 0) + if (sPSSData->itemInfoWindowOffset == 0) FillBgTilemapBufferRect(0, 0, 21, 12, 1, 9, 17); - sPSSData->field_2236++; - var = 0x15 - sPSSData->field_2236; - for (i = 0; i < var; i++) + sPSSData->itemInfoWindowOffset++; + pos = 21 - sPSSData->itemInfoWindowOffset; + for (i = 0; i < pos; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); } - if (var >= 0) - sub_80D19B4(var); + if (pos >= 0) + DrawItemInfoWindow(pos); - FillBgTilemapBufferRect(0, 0, var + 1, 12, 1, 9, 0x11); + FillBgTilemapBufferRect(0, 0, pos + 1, 12, 1, 9, 0x11); ScheduleBgCopyTilemapToVram(0); return TRUE; } -static void sub_80D19B4(u32 arg0) +static void DrawItemInfoWindow(u32 pos) { - if (arg0 != 0) + if (pos != 0) { - FillBgTilemapBufferRect(0, 0x13A, 0, 0xC, arg0, 1, 0xFu); - FillBgTilemapBufferRect(0, 0x93A, 0, 0x14, arg0, 1, 0xFu); + FillBgTilemapBufferRect(0, 0x13A, 0, 0xC, pos, 1, 0xFu); + FillBgTilemapBufferRect(0, 0x93A, 0, 0x14, pos, 1, 0xFu); } - FillBgTilemapBufferRect(0, 0x13B, arg0, 0xD, 1, 7, 0xFu); - FillBgTilemapBufferRect(0, 0x13C, arg0, 0xC, 1, 1, 0xFu); - FillBgTilemapBufferRect(0, 0x13D, arg0, 0x14, 1, 1, 0xFu); + FillBgTilemapBufferRect(0, 0x13B, pos, 0xD, 1, 7, 0xFu); + FillBgTilemapBufferRect(0, 0x13C, pos, 0xC, 1, 1, 0xFu); + FillBgTilemapBufferRect(0, 0x13D, pos, 0x14, 1, 1, 0xFu); ScheduleBgCopyTilemapToVram(0); } -static void sub_80D1A48(struct Sprite *sprite) +static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *sprite) { if (sprite->affineAnimEnded) { - sub_80D1740(sprite->data[0], FALSE); + SetItemIconActive(sprite->sItemIconId, FALSE); sprite->callback = SpriteCallbackDummy; } } -static void sub_80D1A74(struct Sprite *sprite) +static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite) { - switch (sprite->data[0]) + switch (sprite->sState) { case 0: sprite->data[1] = sprite->pos1.x << 4; @@ -8908,28 +8960,28 @@ static void sub_80D1A74(struct Sprite *sprite) sprite->data[3] = 10; sprite->data[4] = 21; sprite->data[5] = 0; - sprite->data[0]++; + sprite->sState++; case 1: sprite->data[1] -= sprite->data[3]; sprite->data[2] -= sprite->data[4]; sprite->pos1.x = sprite->data[1] >> 4; sprite->pos1.y = sprite->data[2] >> 4; if (++sprite->data[5] > 11) - sprite->callback = sub_80D1AD8; + sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; break; } } -static void sub_80D1AD8(struct Sprite *sprite) +static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite) { sprite->pos1.x = sPSSData->field_CB4->pos1.x + 4; sprite->pos1.y = sPSSData->field_CB4->pos1.y + sPSSData->field_CB4->pos2.y + 8; sprite->oam.priority = sPSSData->field_CB4->oam.priority; } -static void sub_80D1B14(struct Sprite *sprite) +static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite) { - switch (sprite->data[0]) + switch (sprite->sState) { case 0: sprite->data[1] = sprite->pos1.x << 4; @@ -8937,7 +8989,7 @@ static void sub_80D1B14(struct Sprite *sprite) sprite->data[3] = 10; sprite->data[4] = 21; sprite->data[5] = 0; - sprite->data[0]++; + sprite->sState++; case 1: sprite->data[1] += sprite->data[3]; sprite->data[2] += sprite->data[4]; @@ -8945,16 +8997,16 @@ static void sub_80D1B14(struct Sprite *sprite) sprite->pos1.y = sprite->data[2] >> 4; if (++sprite->data[5] > 11) { - sub_80D140C(sub_80D13C4(sprite), sprite->data[6], sprite->data[7]); + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); sprite->callback = SpriteCallbackDummy; } break; } } -static void sub_80D1B94(struct Sprite *sprite) +static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *sprite) { - switch (sprite->data[0]) + switch (sprite->sState) { case 0: sprite->data[1] = sprite->pos1.x << 4; @@ -8962,7 +9014,7 @@ static void sub_80D1B94(struct Sprite *sprite) sprite->data[3] = 10; sprite->data[4] = 21; sprite->data[5] = 0; - sprite->data[0]++; + sprite->sState++; case 1: sprite->data[1] -= sprite->data[3]; sprite->data[2] -= sprite->data[4]; @@ -8971,17 +9023,17 @@ static void sub_80D1B94(struct Sprite *sprite) sprite->pos2.x = gSineTable[sprite->data[5] * 8] >> 4; if (++sprite->data[5] > 11) { - sub_80D140C(sub_80D13C4(sprite), sprite->data[6], sprite->data[7]); + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); sprite->pos2.x = 0; - sprite->callback = sub_80D1AD8; + sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; } break; } } -static void sub_80D1C30(struct Sprite *sprite) +static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *sprite) { - switch (sprite->data[0]) + switch (sprite->sState) { case 0: sprite->data[1] = sprite->pos1.x << 4; @@ -8989,7 +9041,7 @@ static void sub_80D1C30(struct Sprite *sprite) sprite->data[3] = 10; sprite->data[4] = 21; sprite->data[5] = 0; - sprite->data[0]++; + sprite->sState++; case 1: sprite->data[1] += sprite->data[3]; sprite->data[2] += sprite->data[4]; @@ -8998,7 +9050,7 @@ static void sub_80D1C30(struct Sprite *sprite) sprite->pos2.x = -(gSineTable[sprite->data[5] * 8] >> 4); if (++sprite->data[5] > 11) { - sub_80D140C(sub_80D13C4(sprite), sprite->data[6], sprite->data[7]); + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); sprite->callback = SpriteCallbackDummy; sprite->pos2.x = 0; } @@ -9006,22 +9058,27 @@ static void sub_80D1C30(struct Sprite *sprite) } } -static void sub_80D1CCC(struct Sprite *sprite) +static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite) { sprite->pos1.y -= 8; if (sprite->pos1.y + sprite->pos2.y < -16) { sprite->callback = SpriteCallbackDummy; - sub_80D1740(sub_80D13C4(sprite), FALSE); + SetItemIconActive(GetItemIconIdxBySprite(sprite), FALSE); } } -void nullsub_pss(void) +#undef sState +#undef sItemIconId +#undef sCursorArea +#undef sCursorPos + +static void ItemIconDummy_1(void) { } -void nullsub_98(void) +static void ItemIconDummy_2(void) { } -- cgit v1.2.3 From e5f0d2f736ef4f1331430734e3c894cdbe4750b2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 15 Apr 2021 23:27:05 -0400 Subject: Doc storage - releasing, some cursor --- src/pokemon_storage_system.c | 1198 ++++++++++++++++++++++-------------------- 1 file changed, 623 insertions(+), 575 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index bcf2d4075..f86a4bbbf 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -87,16 +87,16 @@ enum { MSG_CANT_STORE_MAIL, }; -// Formatting for the above messages +// IDs for how to resolve variables in the above messages enum { - MSG_FORMAT_NORMAL, - MSG_FORMAT_MON_NAME_1, - MSG_FORMAT_MON_NAME_2, // Unused - MSG_FORMAT_MON_NAME_3, // Unused - MSG_FORMAT_MON_NAME_4, - MSG_FORMAT_MON_NAME_5, // Unused - MSG_FORMAT_MON_NAME_6, - MSG_FORMAT_ITEM_NAME, + MSG_VAR_NONE, + MSG_VAR_MON_NAME_1, + MSG_VAR_MON_NAME_2, // Unused + MSG_VAR_MON_NAME_3, // Unused + MSG_VAR_RELEASE_MON_1, + MSG_VAR_RELEASE_MON_2, // Unused + MSG_VAR_RELEASE_MON_3, + MSG_VAR_ITEM_NAME, }; // IDs for menu selection items. See SetMenuText, HandleMenuInput, etc @@ -194,9 +194,15 @@ enum { CURSOR_AREA_BOX, CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box }; - #define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX // Alt name for cursor area used by Move Items +enum { + CURSOR_ANIM_BOUNCE, + CURSOR_ANIM_STILL, + CURSOR_ANIM_OPEN, + CURSOR_ANIM_FIST, +}; + // Special box ids for the choose box menu #define BOXID_NONE_CHOSEN 200 #define BOXID_CANCELED 201 @@ -205,24 +211,24 @@ enum { PALTAG_MON_ICON_0 = 56000, PALTAG_MON_ICON_1, // Used implicitly in CreateMonIconSprite PALTAG_MON_ICON_2, // Used implicitly in CreateMonIconSprite - PALTAG_3, - PALTAG_4, - PALTAG_5, - PALTAG_CURSOR_MON, + PALTAG_3, // Unused + PALTAG_4, // Unused + PALTAG_5, // Unused + PALTAG_DISPLAY_MON, PALTAG_7, - PALTAG_MON_MARKING, + PALTAG_MARKING_COMBO, PALTAG_BOX_TITLE, PALTAG_10, PALTAG_ITEM_ICON_0, PALTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites PALTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites - PALTAG_14, + PALTAG_MARKING_MENU, }; enum { - TAG_TILE_0, - TAG_TILE_1, - GFXTAG_CURSOR_MON, + GFXTAG_CURSOR, + GFXTAG_CURSOR_SHADOW, + GFXTAG_DISPLAY_MON, GFXTAG_BOX_TITLE, GFXTAG_BOX_TITLE_ALT, GFXTAG_WAVEFORM, @@ -232,15 +238,19 @@ enum { GFXTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites GFXTAG_CHOOSE_BOX_MENU, GFXTAG_CHOOSE_BOX_MENU_SIDES, // Used implicitly in LoadChooseBoxMenuGfx - GFXTAG_12, - GFXTAG_13, - GFXTAG_14, - GFXTAG_15, - GFXTAG_MON_MARKING, - GFXTAG_17, + GFXTAG_12, // Unused + GFXTAG_MARKING_MENU, + GFXTAG_14, // Unused + GFXTAG_15, // Unused + GFXTAG_MARKING_COMBO, + GFXTAG_17, // Unused GFXTAG_18, }; +// The maximum number of Pokémon icons that can appear on-screen. +// By default the limit is 40 (though in practice only 37 can be). +#define MAX_MON_ICONS (IN_BOX_COUNT + PARTY_SIZE + 1 >= 40 ? IN_BOX_COUNT + PARTY_SIZE + 1 : 40) + // The maximum number of item icons that can appear on-screen while // moving held items. 1 in the cursor, and 2 more while switching // between 2 Pokémon with held items @@ -269,6 +279,11 @@ enum { ITEM_CB_HIDE_PARTY, }; +enum { + RELEASE_ANIM_RELEASE, + RELEASE_ANIM_CAME_BACK, +}; + struct Wallpaper { const u32 *tiles; @@ -315,14 +330,14 @@ struct ChooseBoxMenu { struct Sprite *menuSprite; struct Sprite *menuSideSprites[4]; - u32 unk_0014[3]; + u32 unused1[3]; struct Sprite *arrowSprites[2]; - u8 filler_0028[0x214]; + u8 unused2[0x214]; bool32 loadedPalette; u16 tileTag; u16 paletteTag; u8 curBox; - u8 unk_0245; + u8 unused3; u8 subpriority; }; @@ -331,8 +346,8 @@ struct ItemIcon struct Sprite *sprite; u8 *tiles; u16 palIndex; - u8 cursorArea; - u8 cursorPos; + u8 area; + u8 pos; bool8 active; }; @@ -394,9 +409,9 @@ struct PokemonStorageSystemData struct Sprite *partySprites[PARTY_SIZE]; struct Sprite *boxMonsSprites[IN_BOX_COUNT]; struct Sprite **field_B00; - struct Sprite **field_B04; - u16 field_B08[40]; - u16 field_B58[40]; + struct Sprite **releaseMonSpritePtr; + u16 numIconsPerSpecies[MAX_MON_ICONS]; + u16 iconSpeciesList[MAX_MON_ICONS]; u16 boxSpecies[IN_BOX_COUNT]; u32 boxPersonalities[IN_BOX_COUNT]; u8 field_C5C; @@ -416,7 +431,7 @@ struct PokemonStorageSystemData u8 menuWidth; u8 field_CAE; // Written to, but never read. u16 menuWindowId; - struct Sprite *field_CB4; + struct Sprite *cursorSprite; struct Sprite *field_CB8; s32 field_CBC; s32 field_CC0; @@ -431,21 +446,21 @@ struct PokemonStorageSystemData u8 field_CD5; u8 field_CD6; u8 field_CD7; - u8 field_CD8[2]; - const u32 *cursorMonPalette; - u32 cursorMonPersonality; - u16 cursorMonSpecies; - u16 cursorMonItemId; + u8 cursorPalNums[2]; + const u32 *displayMonPalette; + u32 displayMonPersonality; + u16 displayMonSpecies; + u16 displayMonItemId; u16 field_CE8; bool8 setMosaic; - u8 cursorMonMarkings; - u8 cursorMonLevel; - bool8 cursorMonIsEgg; - u8 cursorMonNick[POKEMON_NAME_LENGTH + 1]; - u8 cursorMonNickText[36]; - u8 cursorMonSpeciesName[36]; - u8 cursorMonGenderLvlText[36]; - u8 cursorMonItemName[36]; + u8 displayMonMarkings; + u8 displayMonLevel; + bool8 displayMonIsEgg; + u8 displayMonName[POKEMON_NAME_LENGTH + 1]; + u8 displayMonNameText[36]; + u8 displayMonSpeciesName[36]; + u8 displayMonGenderLvlText[36]; + u8 displayMonItemName[36]; bool8 (*monPlaceChangeFunc)(void); u8 monPlaceChangeState; u8 field_D91; @@ -455,16 +470,16 @@ struct PokemonStorageSystemData struct MonMarkingsMenu markMenu; struct ChooseBoxMenu chooseBoxMenu; struct Pokemon movingMon; - struct Pokemon field_2108; - s8 field_216C; - u8 field_216D; - s8 field_216E; - s8 field_216F; - s8 field_2170; - s8 field_2171; - u16 field_2172; - u16 field_2174; - u16 field_2176[8]; + struct Pokemon tempMon; + s8 canReleaseMon; + bool8 releaseStatusResolved; + s8 releaseCheckBoxId; + s8 releaseCheckBoxPos; + s8 releaseBoxId; + s8 releaseBoxPos; + u16 releaseCheckState; + u16 restrictedReleaseMonMoves; + u16 restrictedMoveList[8]; u8 field_2186; u8 field_2187; u8 summaryScreenMode; @@ -475,7 +490,7 @@ struct PokemonStorageSystemData } field_218C; u8 field_2190[40]; u8 boxTitleText[40]; - u8 field_21E0[POKEMON_NAME_LENGTH + 1]; + u8 releaseMonName[POKEMON_NAME_LENGTH + 1]; u8 itemName[20]; u8 inBoxMovingMode; u16 field_2200; @@ -483,10 +498,10 @@ struct PokemonStorageSystemData u16 movingItemId; u16 itemInfoWindowOffset; u8 field_2238; // Unused - u16 cursorMonPalOffset; - u16 *cursorMonTilePtr; - struct Sprite *cursorMonSprite; - u16 cursorMonPalBuffer[0x40]; + u16 displayMonPalOffset; + u16 *displayMonTilePtr; + struct Sprite *displayMonSprite; + u16 displayMonPalBuffer[0x40]; u8 tileBuffer[0x800]; u8 field_2AC4[0x1800]; // Unused u8 field_42C4[0x800]; @@ -578,25 +593,25 @@ static void sub_80CAEAC(void); static void CreateItemIconSprites(void); static void sub_80CFEA8(void); static void sub_80CDC0C(void); -static void sub_80CAF04(void); +static void InitMonIconFields(void); static void sub_80CA0D8(void); static void AddMenu(void); -static void sub_80CE250(void); -static void InitCanRelaseMonVars(void); +static void InitReleaseMon(void); +static void InitCanReleaseMonVars(void); static void sub_80D01B8(void); static void ReleaseMon(void); -static void RefreshCursorMonData(void); -static void CreateCursorMonSprite(void); +static void RefreshDisplayMonData(void); +static void CreateDisplayMonSprite(void); static void CreateMarkingComboSprite(void); static void CreateWaveformSprites(void); -static void sub_80CC064(void); -static void sub_80CE324(void); +static void ReshowReleaseMon(void); +static void TrySetCursorFistAnim(void); static void ClearBottomWindow(void); static void sub_80CA704(void); static void RemoveMenu(void); static void sub_80CE00C(void); static void sub_80D1194(void); -static void PrintCursorMonInfo(void); +static void PrintDisplayMonInfo(void); static void UpdateWaveformAnimation(void); static void AddWallpaperSetsMenu(void); static void CreateBoxScrollArrows(void); @@ -625,15 +640,15 @@ static void sub_80CDA68(void); static void sub_80CB950(void); static void sub_80CA9C0(void); static void SetUpDoShowPartyMenu(void); -static void BoxSetMosaic(void); +static void StartDisplayMonMosaicEffect(void); static void SpriteCB_ChooseBoxArrow(struct Sprite *); -static void sub_80CC100(struct Sprite *); +static void SpriteCB_HeldMon(struct Sprite *); static void sub_80CB278(struct Sprite *); static void SpriteCB_Arrow(struct Sprite *); static bool32 WaitForWallpaperGfxLoad(void); static bool8 InitPSSWindows(void); -static bool8 sub_80CC0A0(void); -static bool8 sub_80CE2A8(void); +static bool8 ResetReleaseMonSpritePtr(void); +static bool8 TryHideReleaseMon(void); static bool8 sub_80D0164(void); static bool8 IsInitBoxActive(void); static bool8 sub_80D01E4(void); @@ -649,7 +664,7 @@ static bool8 HidePartyMenu(void); static bool8 IsMovingItem(void); static bool8 sub_80D0580(u8); static bool8 sub_80D0BC0(void); -static bool8 GetCursorMonMosaic(void); +static bool8 IsDisplayMosaicActive(void); static bool8 DoWallpaperGfxChange(void); static bool8 DoMonPlaceChange(void); static bool8 IsMenuLoading(void); @@ -692,7 +707,7 @@ static void Cb_NameBox(u8); static void Cb_PrintCantStoreMail(u8); static void Cb_HandleMovingMonFromParty(u8); static void SetUpScrollToBox(u8); -static void sub_80CFE54(u8); +static void StartCursorAnim(u8); static void SetMovingMonPriority(u8); static void InitMonPlaceChange(u8); static void SetMonMarkings(u8); @@ -714,8 +729,8 @@ static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); static void SetWallpaperForCurrentBox(u8); static void AddWallpapersMenu(u8); static u16 GetMovingItemId(void); -static void LoadCursorMonGfx(u16, u32); -static void sub_80CA2D0(struct Sprite *); +static void LoadDisplayMonGfx(u16, u32); +static void SpriteCB_DisplayMonMosaic(struct Sprite *); static void SpriteCB_OutgoingBoxTitle(struct Sprite *); static void sub_80CBA3C(struct Sprite *); static void SpriteCB_IncomingBoxTitle(struct Sprite *); @@ -740,12 +755,12 @@ static bool8 MonPlaceChange_Move(void); static bool8 MonPlaceChange_Place(void); static bool8 sub_80CDEC4(void); static bool8 sub_80CDEB4(void); -static void sub_80CD444(u8, u8, u16 *, u16 *); +static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *); static void SetShiftedMonData(u8, u8); static void SetMovedMonData(u8, u8); static void SetPlacedMonData(u8, u8); static void PurgeMonOrBoxMon(u8, u8); -static void SetCursorMonData(void *, u8); +static void SetDisplayMonData(void *, u8); static bool32 AtLeastThreeUsableMons(void); static u8 InBoxInput_Normal(void); static u8 InBoxInput_MovingMultiple(void); @@ -864,8 +879,8 @@ static const u8 sText_OutOf30[] = _("/30"); static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal"); static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp"); static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); -static const u32 gPokemonStorageScrollingBGTileset[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); -static const u32 gPokemonStorageScrollingBGTilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); +static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); +static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); static const u32 gUnknown_08572280[] = INCBIN_U32("graphics/unknown/unknown_572280.gbapal"); static const u32 gUnknown_085722A0[] = INCBIN_U32("graphics/unknown/unknown_5722A0.bin.lz"); @@ -895,14 +910,14 @@ static const u16 gUnknown_085724BC[] = 0x1143, 0x1144, 0x1144, 0x1145, 0x1153, 0x1154, 0x1154, 0x1155, 0x1163, 0x1164, 0x1164, 0x1165, }; -static const u16 gWaveformPalette[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal"); -static const u32 gWaveformTiles[] = INCBIN_U32("graphics/pokemon_storage/waveform.4bpp"); +static const u16 sWaveform_Pal[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal"); +static const u32 sWaveform_Gfx[] = INCBIN_U32("graphics/pokemon_storage/waveform.4bpp"); static const u32 gUnknown_085726B4[] = INCBIN_U32("graphics/unused/unknown_5726B4.gbapal"); static const u32 gUnknown_085726F4[] = INCBIN_U32("graphics/unknown/unknown_5726F4.gbapal"); -static const struct WindowTemplate gUnknown_08572714[] = +static const struct WindowTemplate sWindowTemplates[] = { - { // 0 + { .bg = 1, .tilemapLeft = 0, .tilemapTop = 11, @@ -911,7 +926,7 @@ static const struct WindowTemplate gUnknown_08572714[] = .paletteNum = 3, .baseBlock = 0xC0, }, - { // 1 + { .bg = 0, .tilemapLeft = 11, .tilemapTop = 17, @@ -920,7 +935,7 @@ static const struct WindowTemplate gUnknown_08572714[] = .paletteNum = 15, .baseBlock = 0x14, }, - { // 2 + { .bg = 0, .tilemapLeft = 0, .tilemapTop = 13, @@ -974,20 +989,20 @@ static const struct BgTemplate gUnknown_08572734[] = static const struct SpritePalette gWaveformSpritePalette = { - gWaveformPalette, PALTAG_10 + sWaveform_Pal, PALTAG_10 }; static const struct SpriteSheet sSpriteSheet_Waveform = { - gWaveformTiles, sizeof(gWaveformTiles), GFXTAG_WAVEFORM + sWaveform_Gfx, sizeof(sWaveform_Gfx), GFXTAG_WAVEFORM }; -static const struct OamData sOamData_CursorMon; -static const struct SpriteTemplate sSpriteTemplate_CursorMon = +static const struct OamData sOamData_DisplayMon; +static const struct SpriteTemplate sSpriteTemplate_DisplayMon = { - .tileTag = GFXTAG_CURSOR_MON, - .paletteTag = PALTAG_CURSOR_MON, - .oam = &sOamData_CursorMon, + .tileTag = GFXTAG_DISPLAY_MON, + .paletteTag = PALTAG_DISPLAY_MON, + .oam = &sOamData_DisplayMon, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, @@ -996,37 +1011,37 @@ static const struct SpriteTemplate sSpriteTemplate_CursorMon = static const struct StorageMessage sMessages[] = { - [MSG_EXIT_BOX] = {gText_ExitFromBox, MSG_FORMAT_NORMAL}, - [MSG_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, MSG_FORMAT_NORMAL}, - [MSG_PICK_A_THEME] = {gText_PleasePickATheme, MSG_FORMAT_NORMAL}, - [MSG_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, MSG_FORMAT_NORMAL}, - [MSG_IS_SELECTED] = {gText_PkmnIsSelected, MSG_FORMAT_MON_NAME_1}, - [MSG_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, MSG_FORMAT_NORMAL}, - [MSG_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, MSG_FORMAT_NORMAL}, - [MSG_WAS_DEPOSITED] = {gText_PkmnWasDeposited, MSG_FORMAT_MON_NAME_1}, - [MSG_BOX_IS_FULL] = {gText_BoxIsFull2, MSG_FORMAT_NORMAL}, - [MSG_RELEASE_POKE] = {gText_ReleaseThisPokemon, MSG_FORMAT_NORMAL}, - [MSG_WAS_RELEASED] = {gText_PkmnWasReleased, MSG_FORMAT_MON_NAME_4}, - [MSG_BYE_BYE] = {gText_ByeByePkmn, MSG_FORMAT_MON_NAME_6}, - [MSG_MARK_POKE] = {gText_MarkYourPkmn, MSG_FORMAT_NORMAL}, - [MSG_LAST_POKE] = {gText_ThatsYourLastPkmn, MSG_FORMAT_NORMAL}, - [MSG_PARTY_FULL] = {gText_YourPartysFull, MSG_FORMAT_NORMAL}, - [MSG_HOLDING_POKE] = {gText_YoureHoldingAPkmn, MSG_FORMAT_NORMAL}, - [MSG_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, MSG_FORMAT_NORMAL}, - [MSG_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, MSG_FORMAT_NORMAL}, - [MSG_CONTINUE_BOX] = {gText_ContinueBoxOperations, MSG_FORMAT_NORMAL}, - [MSG_CAME_BACK] = {gText_PkmnCameBack, MSG_FORMAT_MON_NAME_1}, - [MSG_WORRIED] = {gText_WasItWorriedAboutYou, MSG_FORMAT_NORMAL}, - [MSG_SURPRISE] = {gText_FourEllipsesExclamation, MSG_FORMAT_NORMAL}, - [MSG_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, MSG_FORMAT_NORMAL}, - [MSG_IS_SELECTED2] = {gText_PkmnIsSelected, MSG_FORMAT_ITEM_NAME}, - [MSG_GIVE_TO_MON] = {gText_GiveToAPkmn, MSG_FORMAT_NORMAL}, - [MSG_PLACED_IN_BAG] = {gText_PlacedItemInBag, MSG_FORMAT_ITEM_NAME}, - [MSG_BAG_FULL] = {gText_BagIsFull2, MSG_FORMAT_NORMAL}, - [MSG_PUT_IN_BAG] = {gText_PutItemInBag, MSG_FORMAT_NORMAL}, - [MSG_ITEM_IS_HELD] = {gText_ItemIsNowHeld, MSG_FORMAT_ITEM_NAME}, - [MSG_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, MSG_FORMAT_ITEM_NAME}, - [MSG_CANT_STORE_MAIL] = {gText_MailCantBeStored, MSG_FORMAT_NORMAL}, + [MSG_EXIT_BOX] = {gText_ExitFromBox, MSG_VAR_NONE}, + [MSG_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, MSG_VAR_NONE}, + [MSG_PICK_A_THEME] = {gText_PleasePickATheme, MSG_VAR_NONE}, + [MSG_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, MSG_VAR_NONE}, + [MSG_IS_SELECTED] = {gText_PkmnIsSelected, MSG_VAR_MON_NAME_1}, + [MSG_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, MSG_VAR_NONE}, + [MSG_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, MSG_VAR_NONE}, + [MSG_WAS_DEPOSITED] = {gText_PkmnWasDeposited, MSG_VAR_MON_NAME_1}, + [MSG_BOX_IS_FULL] = {gText_BoxIsFull2, MSG_VAR_NONE}, + [MSG_RELEASE_POKE] = {gText_ReleaseThisPokemon, MSG_VAR_NONE}, + [MSG_WAS_RELEASED] = {gText_PkmnWasReleased, MSG_VAR_RELEASE_MON_1}, + [MSG_BYE_BYE] = {gText_ByeByePkmn, MSG_VAR_RELEASE_MON_3}, + [MSG_MARK_POKE] = {gText_MarkYourPkmn, MSG_VAR_NONE}, + [MSG_LAST_POKE] = {gText_ThatsYourLastPkmn, MSG_VAR_NONE}, + [MSG_PARTY_FULL] = {gText_YourPartysFull, MSG_VAR_NONE}, + [MSG_HOLDING_POKE] = {gText_YoureHoldingAPkmn, MSG_VAR_NONE}, + [MSG_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, MSG_VAR_NONE}, + [MSG_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, MSG_VAR_NONE}, + [MSG_CONTINUE_BOX] = {gText_ContinueBoxOperations, MSG_VAR_NONE}, + [MSG_CAME_BACK] = {gText_PkmnCameBack, MSG_VAR_MON_NAME_1}, + [MSG_WORRIED] = {gText_WasItWorriedAboutYou, MSG_VAR_NONE}, + [MSG_SURPRISE] = {gText_FourEllipsesExclamation, MSG_VAR_NONE}, + [MSG_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, MSG_VAR_NONE}, + [MSG_IS_SELECTED2] = {gText_PkmnIsSelected, MSG_VAR_ITEM_NAME}, + [MSG_GIVE_TO_MON] = {gText_GiveToAPkmn, MSG_VAR_NONE}, + [MSG_PLACED_IN_BAG] = {gText_PlacedItemInBag, MSG_VAR_ITEM_NAME}, + [MSG_BAG_FULL] = {gText_BagIsFull2, MSG_VAR_NONE}, + [MSG_PUT_IN_BAG] = {gText_PutItemInBag, MSG_VAR_NONE}, + [MSG_ITEM_IS_HELD] = {gText_ItemIsNowHeld, MSG_VAR_ITEM_NAME}, + [MSG_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, MSG_VAR_ITEM_NAME}, + [MSG_CANT_STORE_MAIL] = {gText_MailCantBeStored, MSG_VAR_NONE}, }; static const struct WindowTemplate sYesNoWindowTemplate = @@ -1040,7 +1055,7 @@ static const struct WindowTemplate sYesNoWindowTemplate = .baseBlock = 0x5C, }; -static const struct OamData sOamData_CursorMon = +static const struct OamData sOamData_DisplayMon = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1121,19 +1136,19 @@ static const struct SpriteTemplate sSpriteTemplate_Waveform = .callback = SpriteCallbackDummy, }; -static const struct OamData sOamData_85728EC; -static const struct SpriteTemplate gUnknown_085728D4 = +static const struct OamData sOamData_MonIcon; +static const struct SpriteTemplate sSpriteTemplate_MonIcon = { .tileTag = GFXTAG_18, .paletteTag = PALTAG_MON_ICON_0, - .oam = &sOamData_85728EC, + .oam = &sOamData_MonIcon, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -static const struct OamData sOamData_85728EC = +static const struct OamData sOamData_MonIcon = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1150,23 +1165,23 @@ static const struct OamData sOamData_85728EC = .affineParam = 0 }; -static const union AffineAnimCmd gSpriteAffineAnim_85728F4[] = +static const union AffineAnimCmd sAffineAnim_ReleaseMon_Release[] = { AFFINEANIMCMD_FRAME(-2, -2, 0, 120), AFFINEANIMCMD_END }; -static const union AffineAnimCmd gSpriteAffineAnim_8572904[] = +static const union AffineAnimCmd sAffineAnim_ReleaseMon_CameBack[] = { AFFINEANIMCMD_FRAME(16, 16, 0, 0), AFFINEANIMCMD_FRAME(16, 16, 0, 15), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const gSpriteAffineAnimTable_857291C[] = +static const union AffineAnimCmd *const sAffineAnims_ReleaseMon[] = { - gSpriteAffineAnim_85728F4, - gSpriteAffineAnim_8572904 + [RELEASE_ANIM_RELEASE] = sAffineAnim_ReleaseMon_Release, + [RELEASE_ANIM_CAME_BACK] = sAffineAnim_ReleaseMon_CameBack }; #include "data/wallpapers.h" @@ -1247,9 +1262,9 @@ static const struct SpriteTemplate sSpriteTemplate_Arrow = .callback = SpriteCB_Arrow }; -static const u16 gHandCursorPalette[] = INCBIN_U16("graphics/pokemon_storage/hand_cursor.gbapal"); -static const u8 gHandCursorTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor.4bpp"); -static const u8 gHandCursorShadowTiles[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor_shadow.4bpp"); +static const u16 sHandCursor_Pal[] = INCBIN_U16("graphics/pokemon_storage/hand_cursor.gbapal"); +static const u8 sHandCursor_Gfx[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor.4bpp"); +static const u8 sHandCursorShadow_Gfx[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor_shadow.4bpp"); void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, s32 bytesToBuffer) { @@ -2026,7 +2041,7 @@ static void Cb_InitPSS(u8 taskId) sub_80C7F1C(); break; case 4: - sub_80CAF04(); + InitMonIconFields(); if (!sPSSData->isReshowingPSS) sub_80CD36C(); else @@ -2059,8 +2074,8 @@ static void Cb_InitPSS(u8 taskId) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - sPSSData->markMenu.baseTileTag = GFXTAG_13; - sPSSData->markMenu.basePaletteTag = PALTAG_14; + sPSSData->markMenu.baseTileTag = GFXTAG_MARKING_MENU; + sPSSData->markMenu.basePaletteTag = PALTAG_MARKING_MENU; InitMonMarkingsMenu(&sPSSData->markMenu); BufferMonMarkingsMenuTiles(); } @@ -2169,7 +2184,7 @@ static void Cb_MainPSS(u8 taskId) case INPUT_6: if (sPSSData->boxOption == OPTION_MOVE_MONS) { - if (IsMonBeingMoved() && ItemIsMail(sPSSData->cursorMonItemId)) + if (IsMonBeingMoved() && ItemIsMail(sPSSData->displayMonItemId)) sPSSData->state = 5; else SetPSSCallback(Cb_HidePartyPokemon); @@ -2227,7 +2242,7 @@ static void Cb_MainPSS(u8 taskId) case INPUT_11: if (!CanMovePartyMon()) { - if (ItemIsMail(sPSSData->cursorMonItemId)) + if (ItemIsMail(sPSSData->displayMonItemId)) { sPSSData->state = 5; } @@ -2326,7 +2341,7 @@ static void Cb_MainPSS(u8 taskId) sub_80CA9EC(); if (sPSSData->setMosaic) - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); sPSSData->state = 0; } break; @@ -2337,7 +2352,7 @@ static void Cb_MainPSS(u8 taskId) if (!sInPartyMenu && !IsMonBeingMoved()) { sub_80CE00C(); - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); } if (sPSSData->boxOption == OPTION_MOVE_ITEMS) @@ -2387,7 +2402,7 @@ static void Cb_MainPSS(u8 taskId) if (!sub_80D01E4()) { if (sPSSData->setMosaic) - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); sPSSData->state = 0; } break; @@ -2440,7 +2455,7 @@ static void Cb_HidePartyPokemon(u8 taskId) if (!sub_80CD554()) { if (sPSSData->setMosaic) - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); SetPSSCallback(Cb_MainPSS); } break; @@ -2452,12 +2467,12 @@ static void Cb_OnSelectedMon(u8 taskId) switch (sPSSData->state) { case 0: - if (!GetCursorMonMosaic()) + if (!IsDisplayMosaicActive()) { PlaySE(SE_SELECT); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) PrintMessage(MSG_IS_SELECTED); - else if (IsMovingItem() || sPSSData->cursorMonItemId != ITEM_NONE) + else if (IsMovingItem() || sPSSData->displayMonItemId != ITEM_NONE) PrintMessage(MSG_IS_SELECTED2); else PrintMessage(MSG_GIVE_TO_MON); @@ -2517,7 +2532,7 @@ static void Cb_OnSelectedMon(u8 taskId) { sPSSData->state = 3; } - else if (ItemIsMail(sPSSData->cursorMonItemId)) + else if (ItemIsMail(sPSSData->displayMonItemId)) { sPSSData->state = 4; } @@ -2533,11 +2548,11 @@ static void Cb_OnSelectedMon(u8 taskId) { sPSSData->state = 3; } - else if (sPSSData->cursorMonIsEgg) + else if (sPSSData->displayMonIsEgg) { sPSSData->state = 5; // Cannot release an Egg. } - else if (ItemIsMail(sPSSData->cursorMonItemId)) + else if (ItemIsMail(sPSSData->displayMonItemId)) { sPSSData->state = 4; } @@ -2655,7 +2670,7 @@ static void Cb_ShiftMon(u8 taskId) case 1: if (!DoMonPlaceChange()) { - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); SetPSSCallback(Cb_MainPSS); } break; @@ -2764,7 +2779,7 @@ static void Cb_DepositMenu(u8 taskId) if (!sub_80CB9BC()) { sub_80CE22C(); - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); sub_80CAB20(); SetPSSCallback(Cb_MainPSS); } @@ -2792,33 +2807,33 @@ static void Cb_ReleaseMon(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case MENU_B_PRESSED: - case 1: + case 1: // No ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); break; - case 0: + case 0: // Yes ClearBottomWindow(); - InitCanRelaseMonVars(); - sub_80CE250(); + InitCanReleaseMonVars(); + InitReleaseMon(); sPSSData->state++; break; } break; case 2: RunCanReleaseMon(); - if (!sub_80CE2A8()) + if (!TryHideReleaseMon()) { while (1) { - s8 r0 = RunCanReleaseMon(); - if (r0 == 1) + s8 canRelease = RunCanReleaseMon(); + if (canRelease == TRUE) { sPSSData->state++; break; } - else if (r0 == 0) + else if (!canRelease) { - sPSSData->state = 8; // Can't release the mon. + sPSSData->state = 8; break; } } @@ -2826,7 +2841,7 @@ static void Cb_ReleaseMon(u8 taskId) break; case 3: ReleaseMon(); - RefreshCursorMonData(); + RefreshDisplayMonData(); PrintMessage(MSG_WAS_RELEASED); sPSSData->state++; break; @@ -2857,7 +2872,7 @@ static void Cb_ReleaseMon(u8 taskId) if (!sub_80CB9BC()) { sub_80CE00C(); - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); sub_80CAB20(); sPSSData->state++; } @@ -2866,6 +2881,7 @@ static void Cb_ReleaseMon(u8 taskId) SetPSSCallback(Cb_MainPSS); break; case 8: + // Start "can't release" sequence PrintMessage(MSG_WAS_RELEASED); sPSSData->state++; break; @@ -2880,14 +2896,14 @@ static void Cb_ReleaseMon(u8 taskId) if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sub_80CC064(); + ReshowReleaseMon(); sPSSData->state++; } break; case 11: - if (!sub_80CC0A0()) + if (!ResetReleaseMonSpritePtr()) { - sub_80CE324(); + TrySetCursorFistAnim(); PrintMessage(MSG_CAME_BACK); sPSSData->state++; } @@ -2915,8 +2931,8 @@ static void Cb_ShowMarkMenu(u8 taskId) { case 0: PrintMessage(MSG_MARK_POKE); - sPSSData->markMenu.markings = sPSSData->cursorMonMarkings; - OpenMonMarkingsMenu(sPSSData->cursorMonMarkings, 0xb0, 0x10); + sPSSData->markMenu.markings = sPSSData->displayMonMarkings; + OpenMonMarkingsMenu(sPSSData->displayMonMarkings, 0xb0, 0x10); sPSSData->state++; break; case 1: @@ -2925,7 +2941,7 @@ static void Cb_ShowMarkMenu(u8 taskId) FreeMonMarkingsMenu(); ClearBottomWindow(); SetMonMarkings(sPSSData->markMenu.markings); - RefreshCursorMonData(); + RefreshDisplayMonData(); SetPSSCallback(Cb_MainPSS); } break; @@ -2937,7 +2953,7 @@ static void Cb_TakeItemForMoving(u8 taskId) switch (sPSSData->state) { case 0: - if (!ItemIsMail(sPSSData->cursorMonItemId)) + if (!ItemIsMail(sPSSData->displayMonItemId)) { ClearBottomWindow(); sPSSData->state++; @@ -2948,17 +2964,17 @@ static void Cb_TakeItemForMoving(u8 taskId) } break; case 1: - sub_80CFE54(2); + StartCursorAnim(CURSOR_ANIM_OPEN); Item_FromMonToMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); sPSSData->state++; break; case 2: if (!IsItemIconAnimActive()) { - sub_80CFE54(3); + StartCursorAnim(CURSOR_ANIM_FIST); ClearBottomWindow(); sub_80CE00C(); - PrintCursorMonInfo(); + PrintDisplayMonInfo(); sPSSData->state++; } break; @@ -2978,16 +2994,16 @@ static void Cb_GiveMovingItemToMon(u8 taskId) sPSSData->state++; break; case 1: - sub_80CFE54(2); + StartCursorAnim(CURSOR_ANIM_OPEN); Item_GiveMovingToMon((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); sPSSData->state++; break; case 2: if (!IsItemIconAnimActive()) { - sub_80CFE54(0); + StartCursorAnim(CURSOR_ANIM_BOUNCE); sub_80CE00C(); - PrintCursorMonInfo(); + PrintDisplayMonInfo(); PrintMessage(MSG_ITEM_IS_HELD); sPSSData->state++; } @@ -3011,7 +3027,7 @@ static void Cb_ItemToBag(u8 taskId) switch (sPSSData->state) { case 0: - if (!AddBagItem(sPSSData->cursorMonItemId, 1)) + if (!AddBagItem(sPSSData->displayMonItemId, 1)) { PlaySE(SE_FAILURE); PrintMessage(MSG_BAG_FULL); @@ -3036,7 +3052,7 @@ static void Cb_ItemToBag(u8 taskId) { ClearBottomWindow(); sub_80CE00C(); - PrintCursorMonInfo(); + PrintDisplayMonInfo(); sPSSData->state = 4; } break; @@ -3059,7 +3075,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) switch (sPSSData->state) { case 0: - if (!ItemIsMail(sPSSData->cursorMonItemId)) + if (!ItemIsMail(sPSSData->displayMonItemId)) { ClearBottomWindow(); sPSSData->state++; @@ -3070,16 +3086,16 @@ static void Cb_SwitchSelectedItem(u8 taskId) } break; case 1: - sub_80CFE54(2); + StartCursorAnim(CURSOR_ANIM_OPEN); Item_SwitchMonsWithMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); sPSSData->state++; break; case 2: if (!IsItemIconAnimActive()) { - sub_80CFE54(3); + StartCursorAnim(CURSOR_ANIM_FIST); sub_80CE00C(); - PrintCursorMonInfo(); + PrintDisplayMonInfo(); PrintMessage(MSG_CHANGED_TO_ITEM); sPSSData->state++; } @@ -3187,7 +3203,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) case 4: if (!IsItemIconAnimActive()) { - sub_80CFE54(0); + StartCursorAnim(CURSOR_ANIM_BOUNCE); SetPSSCallback(Cb_MainPSS); } break; @@ -3666,8 +3682,8 @@ static void FreePSSData(void) static void SetScrollingBackground(void) { SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_16COLOR | BGCNT_SCREENBASE(31)); - DecompressAndLoadBgGfxUsingHeap(3, gPokemonStorageScrollingBGTileset, 0, 0, 0); - LZ77UnCompVram(gPokemonStorageScrollingBGTilemap, (void *)BG_SCREEN_ADDR(31)); + DecompressAndLoadBgGfxUsingHeap(3, sScrollingBg_Gfx, 0, 0, 0); + LZ77UnCompVram(sScrollingBg_Tilemap, (void *)BG_SCREEN_ADDR(31)); } static void ScrollBackground(void) @@ -3688,7 +3704,7 @@ static void LoadPSSMenuGfx(void) static bool8 InitPSSWindows(void) { - if (!InitWindows(gUnknown_08572714)) + if (!InitWindows(sWindowTemplates)) { return FALSE; } @@ -3715,20 +3731,20 @@ static void sub_80CA0D8(void) LoadPalette(gUnknown_0857243C, 0x30, 0x20); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30)); - CreateCursorMonSprite(); + CreateDisplayMonSprite(); CreateMarkingComboSprite(); CreateWaveformSprites(); - RefreshCursorMonData(); + RefreshDisplayMonData(); } static void CreateMarkingComboSprite(void) { - sPSSData->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MON_MARKING, PALTAG_MON_MARKING, NULL); + sPSSData->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MARKING_COMBO, PALTAG_MARKING_COMBO, NULL); sPSSData->markingComboSprite->oam.priority = 1; sPSSData->markingComboSprite->subpriority = 1; sPSSData->markingComboSprite->pos1.x = 40; sPSSData->markingComboSprite->pos1.y = 150; - sPSSData->markingComboTilesPtr = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MON_MARKING); + sPSSData->markingComboTilesPtr = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MARKING_COMBO); } static void CreateWaveformSprites(void) @@ -3744,33 +3760,33 @@ static void CreateWaveformSprites(void) } } -static void RefreshCursorMonData(void) +static void RefreshDisplayMonData(void) { - LoadCursorMonGfx(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality); - PrintCursorMonInfo(); + LoadDisplayMonGfx(sPSSData->displayMonSpecies, sPSSData->displayMonPersonality); + PrintDisplayMonInfo(); UpdateWaveformAnimation(); ScheduleBgCopyTilemapToVram(0); } -static void BoxSetMosaic(void) +static void StartDisplayMonMosaicEffect(void) { - RefreshCursorMonData(); - if (sPSSData->cursorMonSprite) + RefreshDisplayMonData(); + if (sPSSData->displayMonSprite) { - sPSSData->cursorMonSprite->oam.mosaic = TRUE; - sPSSData->cursorMonSprite->data[0] = 10; - sPSSData->cursorMonSprite->data[1] = 1; - sPSSData->cursorMonSprite->callback = sub_80CA2D0; - SetGpuReg(REG_OFFSET_MOSAIC, (sPSSData->cursorMonSprite->data[0] << 12) | (sPSSData->cursorMonSprite->data[0] << 8)); + sPSSData->displayMonSprite->oam.mosaic = TRUE; + sPSSData->displayMonSprite->data[0] = 10; + sPSSData->displayMonSprite->data[1] = 1; + sPSSData->displayMonSprite->callback = SpriteCB_DisplayMonMosaic; + SetGpuReg(REG_OFFSET_MOSAIC, (sPSSData->displayMonSprite->data[0] << 12) | (sPSSData->displayMonSprite->data[0] << 8)); } } -static u8 GetCursorMonMosaic(void) +static u8 IsDisplayMosaicActive(void) { - return sPSSData->cursorMonSprite->oam.mosaic; + return sPSSData->displayMonSprite->oam.mosaic; } -static void sub_80CA2D0(struct Sprite *sprite) +static void SpriteCB_DisplayMonMosaic(struct Sprite *sprite) { sprite->data[0] -= sprite->data[1]; if (sprite->data[0] < 0) @@ -3783,22 +3799,22 @@ static void sub_80CA2D0(struct Sprite *sprite) } } -static void CreateCursorMonSprite(void) +static void CreateDisplayMonSprite(void) { u16 i; u16 tileStart; u8 palSlot; u8 spriteId; - struct SpriteSheet sheet = {sPSSData->tileBuffer, MON_PIC_SIZE, GFXTAG_CURSOR_MON}; - struct SpritePalette palette = {sPSSData->cursorMonPalBuffer, PALTAG_CURSOR_MON}; - struct SpriteTemplate template = sSpriteTemplate_CursorMon; + struct SpriteSheet sheet = {sPSSData->tileBuffer, MON_PIC_SIZE, GFXTAG_DISPLAY_MON}; + struct SpritePalette palette = {sPSSData->displayMonPalBuffer, PALTAG_DISPLAY_MON}; + struct SpriteTemplate template = sSpriteTemplate_DisplayMon; for (i = 0; i < MON_PIC_SIZE; i++) sPSSData->tileBuffer[i] = 0; for (i = 0; i < 16; i++) - sPSSData->cursorMonPalBuffer[i] = 0; + sPSSData->displayMonPalBuffer[i] = 0; - sPSSData->cursorMonSprite = NULL; + sPSSData->displayMonSprite = NULL; do { @@ -3814,59 +3830,59 @@ static void CreateCursorMonSprite(void) if (spriteId == MAX_SPRITES) break; - sPSSData->cursorMonSprite = &gSprites[spriteId]; - sPSSData->cursorMonPalOffset = palSlot * 16 + 0x100; - sPSSData->cursorMonTilePtr = (void*) OBJ_VRAM0 + tileStart * 32; + sPSSData->displayMonSprite = &gSprites[spriteId]; + sPSSData->displayMonPalOffset = palSlot * 16 + 0x100; + sPSSData->displayMonTilePtr = (void*) OBJ_VRAM0 + tileStart * 32; } while (0); - if (sPSSData->cursorMonSprite == NULL) + if (sPSSData->displayMonSprite == NULL) { - FreeSpriteTilesByTag(GFXTAG_CURSOR_MON); - FreeSpritePaletteByTag(PALTAG_CURSOR_MON); + FreeSpriteTilesByTag(GFXTAG_DISPLAY_MON); + FreeSpritePaletteByTag(PALTAG_DISPLAY_MON); } } -static void LoadCursorMonGfx(u16 species, u32 pid) +static void LoadDisplayMonGfx(u16 species, u32 pid) { - if (sPSSData->cursorMonSprite == NULL) + if (sPSSData->displayMonSprite == NULL) return; if (species != SPECIES_NONE) { LoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->tileBuffer, species, pid, TRUE); - LZ77UnCompWram(sPSSData->cursorMonPalette, sPSSData->cursorMonPalBuffer); - CpuCopy32(sPSSData->tileBuffer, sPSSData->cursorMonTilePtr, MON_PIC_SIZE); - LoadPalette(sPSSData->cursorMonPalBuffer, sPSSData->cursorMonPalOffset, 0x20); - sPSSData->cursorMonSprite->invisible = FALSE; + LZ77UnCompWram(sPSSData->displayMonPalette, sPSSData->displayMonPalBuffer); + CpuCopy32(sPSSData->tileBuffer, sPSSData->displayMonTilePtr, MON_PIC_SIZE); + LoadPalette(sPSSData->displayMonPalBuffer, sPSSData->displayMonPalOffset, 0x20); + sPSSData->displayMonSprite->invisible = FALSE; } else { - sPSSData->cursorMonSprite->invisible = TRUE; + sPSSData->displayMonSprite->invisible = TRUE; } } -static void PrintCursorMonInfo(void) +static void PrintDisplayMonInfo(void) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - AddTextPrinterParameterized(0, 1, sPSSData->cursorMonNickText, 6, 0, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->cursorMonSpeciesName, 6, 15, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->cursorMonGenderLvlText, 10, 29, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 0, sPSSData->cursorMonItemName, 6, 43, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 1, sPSSData->displayMonNameText, 6, 0, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sPSSData->displayMonSpeciesName, 6, 15, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sPSSData->displayMonGenderLvlText, 10, 29, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 0, sPSSData->displayMonItemName, 6, 43, TEXT_SPEED_FF, NULL); } else { - AddTextPrinterParameterized(0, 0, sPSSData->cursorMonItemName, 6, 0, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 1, sPSSData->cursorMonNickText, 6, 13, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->cursorMonSpeciesName, 6, 28, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->cursorMonGenderLvlText, 10, 42, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 0, sPSSData->displayMonItemName, 6, 0, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 1, sPSSData->displayMonNameText, 6, 13, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sPSSData->displayMonSpeciesName, 6, 28, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sPSSData->displayMonGenderLvlText, 10, 42, TEXT_SPEED_FF, NULL); } CopyWindowToVram(0, 2); - if (sPSSData->cursorMonSpecies != SPECIES_NONE) + if (sPSSData->displayMonSpecies != SPECIES_NONE) { - UpdateMonMarkingTiles(sPSSData->cursorMonMarkings, sPSSData->markingComboTilesPtr); + UpdateMonMarkingTiles(sPSSData->displayMonMarkings, sPSSData->markingComboTilesPtr); sPSSData->markingComboSprite->invisible = FALSE; } else @@ -3880,7 +3896,7 @@ static void UpdateWaveformAnimation(void) { u16 i; - if (sPSSData->cursorMonSpecies != SPECIES_NONE) + if (sPSSData->displayMonSpecies != SPECIES_NONE) { // Start animation sub_80D27AC(0, 0, 0, 8, 2); @@ -4039,7 +4055,7 @@ static void sub_80CAA74(void) for (i = 1; i < PARTY_SIZE; i++) { - s32 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); + s32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); sub_80CAAA8(i, (species != SPECIES_NONE)); } } @@ -4098,7 +4114,7 @@ static bool8 DoShowPartyMenu(void) if (!sub_80CD554()) { if (sPSSData->setMosaic) - BoxSetMosaic(); + StartDisplayMonMosaicEffect(); sPSSData->showPartyMenuState++; } break; @@ -4132,23 +4148,23 @@ static void PrintMessage(u8 id) DynamicPlaceholderTextUtil_Reset(); switch (sMessages[id].format) { - case MSG_FORMAT_NORMAL: + case MSG_VAR_NONE: break; - case MSG_FORMAT_MON_NAME_1: - case MSG_FORMAT_MON_NAME_2: - case MSG_FORMAT_MON_NAME_3: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->cursorMonNick); + case MSG_VAR_MON_NAME_1: + case MSG_VAR_MON_NAME_2: + case MSG_VAR_MON_NAME_3: + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->displayMonName); break; - case MSG_FORMAT_MON_NAME_4: - case MSG_FORMAT_MON_NAME_5: - case MSG_FORMAT_MON_NAME_6: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->field_21E0); + case MSG_VAR_RELEASE_MON_1: + case MSG_VAR_RELEASE_MON_2: + case MSG_VAR_RELEASE_MON_3: + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->releaseMonName); break; - case MSG_FORMAT_ITEM_NAME: + case MSG_VAR_ITEM_NAME: if (IsMovingItem()) txtPtr = StringCopy(sPSSData->itemName, GetMovingItemName()); else - txtPtr = StringCopy(sPSSData->itemName, sPSSData->cursorMonItemName); + txtPtr = StringCopy(sPSSData->itemName, sPSSData->displayMonItemName); while (*(txtPtr - 1) == CHAR_SPACE) txtPtr--; @@ -4242,19 +4258,19 @@ static void sub_80CAEAC(void) if (sMovingItemId != ITEM_NONE) { sub_80D0F38(sMovingItemId); - sub_80CFE54(3); + StartCursorAnim(CURSOR_ANIM_FIST); } } -static void sub_80CAF04(void) +static void InitMonIconFields(void) { u16 i; LoadMonIconPalettes(); - for (i = 0; i < 40; i++) - sPSSData->field_B08[i] = 0; - for (i = 0; i < 40; i++) - sPSSData->field_B58[i] = 0; + for (i = 0; i < MAX_MON_ICONS; i++) + sPSSData->numIconsPerSpecies[i] = 0; + for (i = 0; i < MAX_MON_ICONS; i++) + sPSSData->iconSpeciesList[i] = SPECIES_NONE; for (i = 0; i < PARTY_SIZE; i++) sPSSData->partySprites[i] = NULL; for (i = 0; i < IN_BOX_COUNT; i++) @@ -4264,7 +4280,7 @@ static void sub_80CAF04(void) sPSSData->field_78C = 0; } -static u8 sub_80CAFAC(void) +static u8 GetMonIconPriorityByCursorPos(void) { return (IsCursorInBox() ? 2 : 1); } @@ -4273,10 +4289,10 @@ static void CreateMovingMonIcon(void) { u32 personality = GetMonData(&sPSSData->movingMon, MON_DATA_PERSONALITY); u16 species = GetMonData(&sPSSData->movingMon, MON_DATA_SPECIES2); - u8 priority = sub_80CAFAC(); + u8 priority = GetMonIconPriorityByCursorPos(); sPSSData->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7); - sPSSData->movingMonSprite->callback = sub_80CC100; + sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; } static void InitBoxMonSprites(u8 boxId) @@ -4744,8 +4760,8 @@ static void sub_80CBC14(u8 mode, u8 id) return; } - sPSSData->movingMonSprite->callback = sub_80CC100; - sPSSData->movingMonSprite->oam.priority = sub_80CAFAC(); + sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; + sPSSData->movingMonSprite->oam.priority = GetMonIconPriorityByCursorPos(); sPSSData->movingMonSprite->subpriority = 7; } @@ -4796,7 +4812,7 @@ static bool8 sub_80CBDC4(void) { sPSSData->movingMonSprite->oam.priority = (*sPSSData->field_B00)->oam.priority; sPSSData->movingMonSprite->subpriority = (*sPSSData->field_B00)->subpriority; - (*sPSSData->field_B00)->oam.priority = sub_80CAFAC(); + (*sPSSData->field_B00)->oam.priority = GetMonIconPriorityByCursorPos(); (*sPSSData->field_B00)->subpriority = 7; } @@ -4806,76 +4822,77 @@ static bool8 sub_80CBDC4(void) sPSSData->movingMonSprite = (*sPSSData->field_B00); *sPSSData->field_B00 = sprite; - sPSSData->movingMonSprite->callback = sub_80CC100; + sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; (*sPSSData->field_B00)->callback = SpriteCallbackDummy; } return TRUE; } -static void sub_80CBF14(u8 mode, u8 position) +static void SetReleaseMon(u8 mode, u8 position) { switch (mode) { case MODE_PARTY: - sPSSData->field_B04 = &sPSSData->partySprites[position]; + sPSSData->releaseMonSpritePtr = &sPSSData->partySprites[position]; break; case MODE_BOX: - sPSSData->field_B04 = &sPSSData->boxMonsSprites[position]; + sPSSData->releaseMonSpritePtr = &sPSSData->boxMonsSprites[position]; break; case MODE_MOVE: - sPSSData->field_B04 = &sPSSData->movingMonSprite; + sPSSData->releaseMonSpritePtr = &sPSSData->movingMonSprite; break; default: return; } - if (*sPSSData->field_B04 != NULL) + if (*sPSSData->releaseMonSpritePtr != NULL) { - InitSpriteAffineAnim(*sPSSData->field_B04); - (*sPSSData->field_B04)->oam.affineMode = ST_OAM_AFFINE_NORMAL; - (*sPSSData->field_B04)->affineAnims = gSpriteAffineAnimTable_857291C; - StartSpriteAffineAnim(*sPSSData->field_B04, 0); + InitSpriteAffineAnim(*sPSSData->releaseMonSpritePtr); + (*sPSSData->releaseMonSpritePtr)->oam.affineMode = ST_OAM_AFFINE_NORMAL; + (*sPSSData->releaseMonSpritePtr)->affineAnims = sAffineAnims_ReleaseMon; + StartSpriteAffineAnim(*sPSSData->releaseMonSpritePtr, RELEASE_ANIM_RELEASE); } } -static bool8 sub_80CBFD8(void) +static bool8 TryHideReleaseMonSprite(void) { - if (*sPSSData->field_B04 == NULL || (*sPSSData->field_B04)->invisible) + if (*sPSSData->releaseMonSpritePtr == NULL + || (*sPSSData->releaseMonSpritePtr)->invisible) return FALSE; - if ((*sPSSData->field_B04)->affineAnimEnded) - (*sPSSData->field_B04)->invisible = TRUE; + if ((*sPSSData->releaseMonSpritePtr)->affineAnimEnded) + (*sPSSData->releaseMonSpritePtr)->invisible = TRUE; return TRUE; } -static void sub_80CC020(void) +static void DestroyReleaseMonIcon(void) { - if (*sPSSData->field_B04 != NULL) + if (*sPSSData->releaseMonSpritePtr != NULL) { - FreeOamMatrix((*sPSSData->field_B04)->oam.matrixNum); - DestroyBoxMonIcon(*sPSSData->field_B04); - *sPSSData->field_B04 = NULL; + FreeOamMatrix((*sPSSData->releaseMonSpritePtr)->oam.matrixNum); + DestroyBoxMonIcon(*sPSSData->releaseMonSpritePtr); + *sPSSData->releaseMonSpritePtr = NULL; } } -static void sub_80CC064(void) +static void ReshowReleaseMon(void) { - if (*sPSSData->field_B04 != NULL) + if (*sPSSData->releaseMonSpritePtr != NULL) { - (*sPSSData->field_B04)->invisible = FALSE; - StartSpriteAffineAnim(*sPSSData->field_B04, 1); + (*sPSSData->releaseMonSpritePtr)->invisible = FALSE; + StartSpriteAffineAnim(*sPSSData->releaseMonSpritePtr, RELEASE_ANIM_CAME_BACK); } } -static bool8 sub_80CC0A0(void) +static bool8 ResetReleaseMonSpritePtr(void) { - if (sPSSData->field_B04 == NULL) + if (sPSSData->releaseMonSpritePtr == NULL) return FALSE; - if ((*sPSSData->field_B04)->affineAnimEnded) - sPSSData->field_B04 = NULL; + if ((*sPSSData->releaseMonSpritePtr)->affineAnimEnded) + sPSSData->releaseMonSpritePtr = NULL; return TRUE; } @@ -4885,51 +4902,57 @@ static void SetMovingMonPriority(u8 priority) sPSSData->movingMonSprite->oam.priority = priority; } -static void sub_80CC100(struct Sprite *sprite) +static void SpriteCB_HeldMon(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->field_CB4->pos1.x; - sprite->pos1.y = sPSSData->field_CB4->pos1.y + sPSSData->field_CB4->pos2.y + 4; + sprite->pos1.x = sPSSData->cursorSprite->pos1.x; + sprite->pos1.y = sPSSData->cursorSprite->pos1.y + sPSSData->cursorSprite->pos2.y + 4; } -static u16 sub_80CC124(u16 species) +static u16 TryLoadMonIconTiles(u16 species) { - u16 i, var; + u16 i, offset; - for (i = 0; i < 40; i++) + // Search icon list for this species + for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->field_B58[i] == species) + if (sPSSData->iconSpeciesList[i] == species) break; } - if (i == 40) + if (i == MAX_MON_ICONS) { - for (i = 0; i < 40; i++) + // Species not present in the list + // Find first empty spot in the list to put it + for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->field_B58[i] == 0) + if (sPSSData->iconSpeciesList[i] == 0) break; } - if (i == 40) + + // Failed to find an empty spot + if (i == MAX_MON_ICONS) return 0xFFFF; } - sPSSData->field_B58[i] = species; - sPSSData->field_B08[i]++; - var = 16 * i; - CpuCopy32(GetMonIconTiles(species, TRUE), (void*)(OBJ_VRAM0) + var * 32, 0x200); + // Add species to icon list and load tiles + sPSSData->iconSpeciesList[i] = species; + sPSSData->numIconsPerSpecies[i]++; + offset = 16 * i; + CpuCopy32(GetMonIconTiles(species, TRUE), (void*)(OBJ_VRAM0) + offset * 32, 0x200); - return var; + return offset; } -static void sub_80CC1E0(u16 species) +static void RemoveSpeciesFromIconList(u16 species) { u16 i; - for (i = 0; i < 40; i++) + for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->field_B58[i] == species) + if (sPSSData->iconSpeciesList[i] == species) { - if (--sPSSData->field_B08[i] == 0) - sPSSData->field_B58[i] = 0; + if (--sPSSData->numIconsPerSpecies[i] == 0) + sPSSData->iconSpeciesList[i] = SPECIES_NONE; break; } } @@ -4939,18 +4962,18 @@ static struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s { u16 tileNum; u8 spriteId; - struct SpriteTemplate template = gUnknown_085728D4; + struct SpriteTemplate template = sSpriteTemplate_MonIcon; species = GetIconSpecies(species, personality); template.paletteTag = PALTAG_MON_ICON_0 + gMonIconPaletteIndices[species]; - tileNum = sub_80CC124(species); + tileNum = TryLoadMonIconTiles(species); if (tileNum == 0xFFFF) return NULL; spriteId = CreateSprite(&template, x, y, subpriority); if (spriteId == MAX_SPRITES) { - sub_80CC1E0(species); + RemoveSpeciesFromIconList(species); return NULL; } @@ -4962,7 +4985,7 @@ static struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s static void DestroyBoxMonIcon(struct Sprite *sprite) { - sub_80CC1E0(sprite->data[0]); + RemoveSpeciesFromIconList(sprite->data[0]); DestroySprite(sprite); } @@ -5580,7 +5603,7 @@ static void sub_80CD3EC(void) } } -static void sub_80CD444(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y) +static void GetCursorCoordsByPos(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y) { switch (cursorArea) { @@ -5591,36 +5614,36 @@ static void sub_80CD444(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y) case CURSOR_AREA_IN_PARTY: if (cursorPosition == 0) { - *x = 0x68; - *y = 0x34; + *x = 104; + *y = 52; } else if (cursorPosition == PARTY_SIZE) { - *x = 0x98; - *y = 0x84; + *x = 152; + *y = 132; } else { - *x = 0x98; + *x = 152; *y = (cursorPosition - 1) * 24 + 4; } break; case CURSOR_AREA_BOX: - *x = 0xa2; - *y = 0x0c; + *x = 162; + *y = 12; break; case CURSOR_AREA_BUTTONS: *y = sIsMonBeingMoved ? 8 : 14; - *x = cursorPosition * 0x58 + 0x78; + *x = cursorPosition * 88 + 120; break; case 4: - *x = 0xa0; - *y = 0x60; + *x = 160; + *y = 96; break; } } -static u16 sub_80CD504(void) +static u16 GetSpeciesAtCursorPosition(void) { switch (sBoxCursorArea) { @@ -5648,35 +5671,35 @@ static bool8 sub_80CD554(void) { sPSSData->field_CBC += sPSSData->field_CC4; sPSSData->field_CC0 += sPSSData->field_CC8; - sPSSData->field_CB4->pos1.x = sPSSData->field_CBC >> 8; - sPSSData->field_CB4->pos1.y = sPSSData->field_CC0 >> 8; - if (sPSSData->field_CB4->pos1.x > DISPLAY_WIDTH + 16) + sPSSData->cursorSprite->pos1.x = sPSSData->field_CBC >> 8; + sPSSData->cursorSprite->pos1.y = sPSSData->field_CC0 >> 8; + if (sPSSData->cursorSprite->pos1.x > DISPLAY_WIDTH + 16) { - tmp = sPSSData->field_CB4->pos1.x - (DISPLAY_WIDTH + 16); - sPSSData->field_CB4->pos1.x = tmp + 64; + tmp = sPSSData->cursorSprite->pos1.x - (DISPLAY_WIDTH + 16); + sPSSData->cursorSprite->pos1.x = tmp + 64; } - if (sPSSData->field_CB4->pos1.x < 64) + if (sPSSData->cursorSprite->pos1.x < 64) { - tmp = 64 - sPSSData->field_CB4->pos1.x; - sPSSData->field_CB4->pos1.x = DISPLAY_WIDTH + 16 - tmp; + tmp = 64 - sPSSData->cursorSprite->pos1.x; + sPSSData->cursorSprite->pos1.x = DISPLAY_WIDTH + 16 - tmp; } - if (sPSSData->field_CB4->pos1.y > DISPLAY_HEIGHT + 16) + if (sPSSData->cursorSprite->pos1.y > DISPLAY_HEIGHT + 16) { - tmp = sPSSData->field_CB4->pos1.y - (DISPLAY_HEIGHT + 16); - sPSSData->field_CB4->pos1.y = tmp - 16; + tmp = sPSSData->cursorSprite->pos1.y - (DISPLAY_HEIGHT + 16); + sPSSData->cursorSprite->pos1.y = tmp - 16; } - if (sPSSData->field_CB4->pos1.y < -16) + if (sPSSData->cursorSprite->pos1.y < -16) { - tmp = -16 - sPSSData->field_CB4->pos1.y; - sPSSData->field_CB4->pos1.y = DISPLAY_HEIGHT + 16 - tmp; + tmp = -16 - sPSSData->cursorSprite->pos1.y; + sPSSData->cursorSprite->pos1.y = DISPLAY_HEIGHT + 16 - tmp; } if (sPSSData->field_CD7 && --sPSSData->field_CD7 == 0) - sPSSData->field_CB4->vFlip = (sPSSData->field_CB4->vFlip == FALSE); + sPSSData->cursorSprite->vFlip = (sPSSData->cursorSprite->vFlip == FALSE); } else { - sPSSData->field_CB4->pos1.x = sPSSData->field_CCC; - sPSSData->field_CB4->pos1.y = sPSSData->field_CCE; + sPSSData->cursorSprite->pos1.x = sPSSData->field_CCC; + sPSSData->cursorSprite->pos1.y = sPSSData->field_CCE; sub_80CDA68(); } @@ -5687,7 +5710,7 @@ static void sub_80CD6AC(u8 newCursorArea, u8 newCursorPosition) { u16 x, y; - sub_80CD444(newCursorArea, newCursorPosition, &x, &y); + GetCursorCoordsByPos(newCursorArea, newCursorPosition, &x, &y); sPSSData->field_CD4 = newCursorArea; sPSSData->field_CD5 = newCursorPosition; sPSSData->field_CCC = x; @@ -5709,26 +5732,26 @@ static void sub_80CD70C(void) switch (sPSSData->field_CD2) { default: - r7 = sPSSData->field_CCE - sPSSData->field_CB4->pos1.y; + r7 = sPSSData->field_CCE - sPSSData->cursorSprite->pos1.y; break; case -1: - r7 = sPSSData->field_CCE - 0xc0 - sPSSData->field_CB4->pos1.y; + r7 = sPSSData->field_CCE - 0xc0 - sPSSData->cursorSprite->pos1.y; break; case 1: - r7 = sPSSData->field_CCE + 0xc0 - sPSSData->field_CB4->pos1.y; + r7 = sPSSData->field_CCE + 0xc0 - sPSSData->cursorSprite->pos1.y; break; } switch (sPSSData->field_CD3) { default: - r0 = sPSSData->field_CCC - sPSSData->field_CB4->pos1.x; + r0 = sPSSData->field_CCC - sPSSData->cursorSprite->pos1.x; break; case -1: - r0 = sPSSData->field_CCC - 0xc0 - sPSSData->field_CB4->pos1.x; + r0 = sPSSData->field_CCC - 0xc0 - sPSSData->cursorSprite->pos1.x; break; case 1: - r0 = sPSSData->field_CCC + 0xc0 - sPSSData->field_CB4->pos1.x; + r0 = sPSSData->field_CCC + 0xc0 - sPSSData->cursorSprite->pos1.x; break; } @@ -5736,8 +5759,8 @@ static void sub_80CD70C(void) r0 <<= 8; sPSSData->field_CC4 = r0 / sPSSData->field_CD0; sPSSData->field_CC8 = r7 / sPSSData->field_CD0; - sPSSData->field_CBC = sPSSData->field_CB4->pos1.x << 8; - sPSSData->field_CC0 = sPSSData->field_CB4->pos1.y << 8; + sPSSData->field_CBC = sPSSData->cursorSprite->pos1.x << 8; + sPSSData->field_CC0 = sPSSData->cursorSprite->pos1.y << 8; } static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) @@ -5747,12 +5770,12 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) - StartSpriteAnim(sPSSData->field_CB4, 1); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); } else { if (!IsMovingItem()) - StartSpriteAnim(sPSSData->field_CB4, 1); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); } if (sPSSData->boxOption == OPTION_MOVE_ITEMS) @@ -5779,19 +5802,19 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) case CURSOR_AREA_IN_PARTY: case CURSOR_AREA_BOX: case CURSOR_AREA_BUTTONS: - sPSSData->field_CB4->oam.priority = 1; + sPSSData->cursorSprite->oam.priority = 1; sPSSData->field_CB8->invisible = TRUE; sPSSData->field_CB8->oam.priority = 1; break; case CURSOR_AREA_IN_BOX: if (sPSSData->inBoxMovingMode != 0) { - sPSSData->field_CB4->oam.priority = 0; + sPSSData->cursorSprite->oam.priority = 0; sPSSData->field_CB8->invisible = TRUE; } else { - sPSSData->field_CB4->oam.priority = 2; + sPSSData->cursorSprite->oam.priority = 2; if (sBoxCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) SetMovingMonPriority(2); } @@ -5806,12 +5829,12 @@ static void sub_80CDA68(void) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) - StartSpriteAnim(sPSSData->field_CB4, 0); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); } else { if (!IsMovingItem()) - StartSpriteAnim(sPSSData->field_CB4, 0); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); } sub_80CEB40(); @@ -5830,7 +5853,7 @@ static void sub_80CDA68(void) case CURSOR_AREA_IN_BOX: if (sPSSData->inBoxMovingMode == 0) { - sPSSData->field_CB4->oam.priority = 1; + sPSSData->cursorSprite->oam.priority = 1; sPSSData->field_CB8->oam.priority = 2; sPSSData->field_CB8->subpriority = 21; sPSSData->field_CB8->invisible = FALSE; @@ -5854,7 +5877,7 @@ static void sub_80CDBA0(void) if (partyCount >= PARTY_SIZE) partyCount = PARTY_SIZE - 1; } - if (sPSSData->field_CB4->vFlip) + if (sPSSData->cursorSprite->vFlip) sPSSData->field_CD7 = 1; sub_80CD894(CURSOR_AREA_IN_PARTY, partyCount); } @@ -5916,13 +5939,13 @@ static bool8 MonPlaceChange_Move(void) case 0: if (sIsMonBeingMoved) return FALSE; - StartSpriteAnim(sPSSData->field_CB4, 2); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); sPSSData->monPlaceChangeState++; break; case 1: if (!sub_80CDED4()) { - StartSpriteAnim(sPSSData->field_CB4, 3); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); MoveMon(); sPSSData->monPlaceChangeState++; } @@ -5945,7 +5968,7 @@ static bool8 MonPlaceChange_Place(void) case 0: if (!sub_80CDED4()) { - StartSpriteAnim(sPSSData->field_CB4, 2); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); PlaceMon(); sPSSData->monPlaceChangeState++; } @@ -5953,7 +5976,7 @@ static bool8 MonPlaceChange_Place(void) case 1: if (!sub_80CDF08()) { - StartSpriteAnim(sPSSData->field_CB4, 0); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); sPSSData->monPlaceChangeState++; } break; @@ -5980,14 +6003,14 @@ static bool8 MonPlaceChange_Shift(void) default: return FALSE; } - StartSpriteAnim(sPSSData->field_CB4, 2); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); sub_80CBD5C(sPSSData->field_D91, sBoxCursorPosition); sPSSData->monPlaceChangeState++; break; case 1: if (!sub_80CBDC4()) { - StartSpriteAnim(sPSSData->field_CB4, 3); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); SetShiftedMonData(sPSSData->field_D91, sBoxCursorPosition); sPSSData->monPlaceChangeState++; } @@ -6011,13 +6034,13 @@ static bool8 sub_80CDEC4(void) static bool8 sub_80CDED4(void) { - switch (sPSSData->field_CB4->pos2.y) + switch (sPSSData->cursorSprite->pos2.y) { default: - sPSSData->field_CB4->pos2.y++; + sPSSData->cursorSprite->pos2.y++; break; case 0: - sPSSData->field_CB4->pos2.y++; + sPSSData->cursorSprite->pos2.y++; break; case 8: return FALSE; @@ -6028,12 +6051,12 @@ static bool8 sub_80CDED4(void) static bool8 sub_80CDF08(void) { - switch (sPSSData->field_CB4->pos2.y) + switch (sPSSData->cursorSprite->pos2.y) { case 0: return FALSE; default: - sPSSData->field_CB4->pos2.y--; + sPSSData->cursorSprite->pos2.y--; break; } @@ -6125,13 +6148,13 @@ static void PurgeMonOrBoxMon(u8 boxId, u8 position) static void SetShiftedMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) - sPSSData->field_2108 = gPlayerParty[position]; + sPSSData->tempMon = gPlayerParty[position]; else - BoxMonAtToMon(boxId, position, &sPSSData->field_2108); + BoxMonAtToMon(boxId, position, &sPSSData->tempMon); SetPlacedMonData(boxId, position); - sPSSData->movingMon = sPSSData->field_2108; - SetCursorMonData(&sPSSData->movingMon, MODE_PARTY); + sPSSData->movingMon = sPSSData->tempMon; + SetDisplayMonData(&sPSSData->movingMon, MODE_PARTY); sMovingMonOrigBoxId = boxId; sMovingMonOrigBoxPos = position; } @@ -6158,17 +6181,17 @@ static bool8 TryStorePartyMonInBox(u8 boxId) if (boxId == StorageGetCurrentBox()) sub_80CB140(boxPosition); - StartSpriteAnim(sPSSData->field_CB4, 1); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); return TRUE; } static void sub_80CE22C(void) { - StartSpriteAnim(sPSSData->field_CB4, 0); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); sub_80CEB40(); } -static void sub_80CE250(void) +static void InitReleaseMon(void) { u8 mode; @@ -6179,15 +6202,15 @@ static void sub_80CE250(void) else mode = MODE_BOX; - sub_80CBF14(mode, sBoxCursorPosition); - StringCopy(sPSSData->field_21E0, sPSSData->cursorMonNick); + SetReleaseMon(mode, sBoxCursorPosition); + StringCopy(sPSSData->releaseMonName, sPSSData->displayMonName); } -static bool8 sub_80CE2A8(void) +static bool8 TryHideReleaseMon(void) { - if (!sub_80CBFD8()) + if (!TryHideReleaseMonSprite()) { - StartSpriteAnim(sPSSData->field_CB4, 0); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); return FALSE; } else @@ -6200,7 +6223,7 @@ static void ReleaseMon(void) { u8 boxId; - sub_80CC020(); + DestroyReleaseMonIcon(); if (sIsMonBeingMoved) { sIsMonBeingMoved = FALSE; @@ -6217,18 +6240,22 @@ static void ReleaseMon(void) sub_80CEB40(); } -static void sub_80CE324(void) +static void TrySetCursorFistAnim(void) { if (sIsMonBeingMoved) - StartSpriteAnim(sPSSData->field_CB4, 3); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); } +// If the player is on the listed map (or any map, if none is specified), +// they may not release their last Pokémon that knows the specified move. +// This is to stop the player from softlocking themselves by not having +// a Pokémon that knows a required field move. struct { s8 mapGroup; s8 mapNum; u16 move; -} static const gUnknown_0857B9A4[] = +} static const sRestrictedReleaseMoves[] = { {MAP_GROUPS_COUNT, 0, MOVE_SURF}, {MAP_GROUPS_COUNT, 0, MOVE_DIVE}, @@ -6238,73 +6265,79 @@ struct {MAP_GROUP(EVER_GRANDE_CITY_POKEMON_LEAGUE_2F), MAP_NUM(EVER_GRANDE_CITY_POKEMON_LEAGUE_2F), MOVE_ROCK_SMASH}, }; -static void sub_80CE350(u16 *moves) +static void GetRestrictedReleaseMoves(u16 *moves) { s32 i; - for (i = 0; i < ARRAY_COUNT(gUnknown_0857B9A4); i++) + for (i = 0; i < ARRAY_COUNT(sRestrictedReleaseMoves); i++) { - if (gUnknown_0857B9A4[i].mapGroup == MAP_GROUPS_COUNT - || (gUnknown_0857B9A4[i].mapGroup == gSaveBlock1Ptr->location.mapGroup && gUnknown_0857B9A4[i].mapNum == gSaveBlock1Ptr->location.mapNum)) + if (sRestrictedReleaseMoves[i].mapGroup == MAP_GROUPS_COUNT + || (sRestrictedReleaseMoves[i].mapGroup == gSaveBlock1Ptr->location.mapGroup + && sRestrictedReleaseMoves[i].mapNum == gSaveBlock1Ptr->location.mapNum)) { - *moves = gUnknown_0857B9A4[i].move; + *moves = sRestrictedReleaseMoves[i].move; moves++; } } - *moves = MOVES_COUNT; } -static void InitCanRelaseMonVars(void) +static void InitCanReleaseMonVars(void) { if (!AtLeastThreeUsableMons()) { - sPSSData->field_216D = 1; - sPSSData->field_216C = 0; + // The player only has 1 or 2 usable + // Pokémon, this one can't be released + sPSSData->releaseStatusResolved = TRUE; + sPSSData->canReleaseMon = FALSE; return; } if (sIsMonBeingMoved) { - sPSSData->field_2108 = sPSSData->movingMon; - sPSSData->field_2170 = -1; - sPSSData->field_2171 = -1; + sPSSData->tempMon = sPSSData->movingMon; + sPSSData->releaseBoxId = -1; + sPSSData->releaseBoxPos = -1; } else { if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) { - sPSSData->field_2108 = gPlayerParty[sBoxCursorPosition]; - sPSSData->field_2170 = TOTAL_BOXES_COUNT; + sPSSData->tempMon = gPlayerParty[sBoxCursorPosition]; + sPSSData->releaseBoxId = TOTAL_BOXES_COUNT; } else { - BoxMonAtToMon(StorageGetCurrentBox(), sBoxCursorPosition, &sPSSData->field_2108); - sPSSData->field_2170 = StorageGetCurrentBox(); + BoxMonAtToMon(StorageGetCurrentBox(), sBoxCursorPosition, &sPSSData->tempMon); + sPSSData->releaseBoxId = StorageGetCurrentBox(); } - sPSSData->field_2171 = sBoxCursorPosition; + sPSSData->releaseBoxPos = sBoxCursorPosition; } - sub_80CE350(sPSSData->field_2176); - sPSSData->field_2174 = GetMonData(&sPSSData->field_2108, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); - if (sPSSData->field_2174 != 0) + GetRestrictedReleaseMoves(sPSSData->restrictedMoveList); + sPSSData->restrictedReleaseMonMoves = GetMonData(&sPSSData->tempMon, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); + if (sPSSData->restrictedReleaseMonMoves != 0) { - sPSSData->field_216D = 0; + // Pokémon knows at least one restricted release move + // Need to check if another Pokémon has this move first + sPSSData->releaseStatusResolved = FALSE; } else { - sPSSData->field_216D = 1; - sPSSData->field_216C = 1; + // Pokémon knows no restricted moves, can be released + sPSSData->releaseStatusResolved = TRUE; + sPSSData->canReleaseMon = TRUE; } - sPSSData->field_2172 = 0; + sPSSData->releaseCheckState = 0; } static bool32 AtLeastThreeUsableMons(void) { - s32 i, j, count; - - count = (sIsMonBeingMoved != FALSE); + s32 i, j; + s32 count = (sIsMonBeingMoved != FALSE); + + // Check party for usable Pokémon for (j = 0; j < PARTY_SIZE; j++) { if (GetMonData(&gPlayerParty[j], MON_DATA_SANITY_HAS_SPECIES)) @@ -6314,6 +6347,7 @@ static bool32 AtLeastThreeUsableMons(void) if (count >= 3) return TRUE; + // Check PC for usable Pokémon for (i = 0; i < TOTAL_BOXES_COUNT; i++) { for (j = 0; j < IN_BOX_COUNT; j++) @@ -6334,54 +6368,69 @@ static s8 RunCanReleaseMon(void) u16 i; u16 knownMoves; - if (sPSSData->field_216D) - return sPSSData->field_216C; + if (sPSSData->releaseStatusResolved) + return sPSSData->canReleaseMon; - switch (sPSSData->field_2172) + switch (sPSSData->releaseCheckState) { case 0: + // Check party for other Pokémon that know any restricted + // moves the release Pokémon knows for (i = 0; i < PARTY_SIZE; i++) { - if (sPSSData->field_2170 != TOTAL_BOXES_COUNT || sPSSData->field_2171 != i) + // Make sure party Pokémon isn't the one we're releasing first + if (sPSSData->releaseBoxId != TOTAL_BOXES_COUNT || sPSSData->releaseBoxPos != i) { - knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); - sPSSData->field_2174 &= ~(knownMoves); + knownMoves = GetMonData(&gPlayerParty[i], MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); + sPSSData->restrictedReleaseMonMoves &= ~(knownMoves); } } - if (sPSSData->field_2174 == 0) + if (sPSSData->restrictedReleaseMonMoves == 0) { - sPSSData->field_216D = 1; - sPSSData->field_216C = 1; + // No restricted moves on release Pokémon that + // aren't resolved by the party, it can be released. + sPSSData->releaseStatusResolved = TRUE; + sPSSData->canReleaseMon = TRUE; } else { - sPSSData->field_216E = 0; - sPSSData->field_216F = 0; - sPSSData->field_2172++; + // Release Pokémon has restricted moves not resolved by the party. + // Continue and check the PC next + sPSSData->releaseCheckBoxId = 0; + sPSSData->releaseCheckBoxPos = 0; + sPSSData->releaseCheckState++; } break; case 1: + // Check PC for other Pokémon that know any restricted + // moves the release Pokémon knows for (i = 0; i < IN_BOX_COUNT; i++) { - knownMoves = GetAndCopyBoxMonDataAt(sPSSData->field_216E, sPSSData->field_216F, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); - if (knownMoves != 0 - && !(sPSSData->field_2170 == sPSSData->field_216E && sPSSData->field_2171 == sPSSData->field_216F)) + knownMoves = GetAndCopyBoxMonDataAt(sPSSData->releaseCheckBoxId, sPSSData->releaseCheckBoxPos, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); + if (knownMoves != 0 && !(sPSSData->releaseBoxId == sPSSData->releaseCheckBoxId + && sPSSData->releaseBoxPos == sPSSData->releaseCheckBoxPos)) { - sPSSData->field_2174 &= ~(knownMoves); - if (sPSSData->field_2174 == 0) + // Found PC Pokémon with restricted move, clear move from list + sPSSData->restrictedReleaseMonMoves &= ~(knownMoves); + if (sPSSData->restrictedReleaseMonMoves == 0) { - sPSSData->field_216D = 1; - sPSSData->field_216C = 1; + // No restricted moves on release Pokémon that + // aren't resolved, it can be released. + sPSSData->releaseStatusResolved = TRUE; + sPSSData->canReleaseMon = TRUE; break; } } - if (++sPSSData->field_216F >= IN_BOX_COUNT) + if (++sPSSData->releaseCheckBoxPos >= IN_BOX_COUNT) { - sPSSData->field_216F = 0; - if (++sPSSData->field_216E >= TOTAL_BOXES_COUNT) + sPSSData->releaseCheckBoxPos = 0; + if (++sPSSData->releaseCheckBoxId >= TOTAL_BOXES_COUNT) { - sPSSData->field_216D = 1; - sPSSData->field_216C = 0; + // Checked every Pokémon in the PC, release Pokémon is + // the sole owner of at least one restricted move. + // It cannot be released. + sPSSData->releaseStatusResolved = TRUE; + sPSSData->canReleaseMon = FALSE; } } } @@ -6449,7 +6498,7 @@ s16 CompactPartySlots(void) for (i = 0, last = 0; i < PARTY_SIZE; i++) { - u16 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); + u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); if (species != SPECIES_NONE) { if (i != last) @@ -6462,14 +6511,14 @@ s16 CompactPartySlots(void) } } for (; last < PARTY_SIZE; last++) - ZeroMonData(gPlayerParty + last); + ZeroMonData(&gPlayerParty[last]); return retVal; } static void SetMonMarkings(u8 markings) { - sPSSData->cursorMonMarkings = markings; + sPSSData->displayMonMarkings = markings; if (sIsMonBeingMoved) { SetMonData(&sPSSData->movingMon, MON_DATA_MARKINGS, &markings); @@ -6477,7 +6526,7 @@ static void SetMonMarkings(u8 markings) else { if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - SetMonData(gPlayerParty + sBoxCursorPosition, MON_DATA_MARKINGS, &markings); + SetMonData(&gPlayerParty[sBoxCursorPosition], MON_DATA_MARKINGS, &markings); if (sBoxCursorArea == CURSOR_AREA_IN_BOX) SetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_MARKINGS, &markings); } @@ -6497,7 +6546,7 @@ static bool8 CanShiftMon(void) { if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0) { - if (sPSSData->cursorMonIsEgg || GetMonData(&sPSSData->movingMon, MON_DATA_HP) == 0) + if (sPSSData->displayMonIsEgg || GetMonData(&sPSSData->movingMon, MON_DATA_HP) == 0) return FALSE; } return TRUE; @@ -6535,16 +6584,16 @@ static void sub_80CEB40(void) case CURSOR_AREA_IN_PARTY: if (sBoxCursorPosition < PARTY_SIZE) { - SetCursorMonData(&gPlayerParty[sBoxCursorPosition], MODE_PARTY); + SetDisplayMonData(&gPlayerParty[sBoxCursorPosition], MODE_PARTY); break; } // fallthrough case CURSOR_AREA_BUTTONS: case CURSOR_AREA_BOX: - SetCursorMonData(NULL, MODE_MOVE); + SetDisplayMonData(NULL, MODE_MOVE); break; case CURSOR_AREA_IN_BOX: - SetCursorMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sBoxCursorPosition), MODE_BOX); + SetDisplayMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sBoxCursorPosition), MODE_BOX); break; } } @@ -6553,105 +6602,105 @@ static void sub_80CEB40(void) static void sub_80CEBDC(void) { if (sIsMonBeingMoved) - SetCursorMonData(&gUnknown_02039D14, MODE_PARTY); + SetDisplayMonData(&gUnknown_02039D14, MODE_PARTY); else sub_80CEB40(); } -static void SetCursorMonData(void *pokemon, u8 mode) +static void SetDisplayMonData(void *pokemon, u8 mode) { u8 *txtPtr; u16 gender; bool8 sanityIsBadEgg; - sPSSData->cursorMonItemId = ITEM_NONE; + sPSSData->displayMonItemId = ITEM_NONE; gender = MON_MALE; sanityIsBadEgg = FALSE; if (mode == MODE_PARTY) { struct Pokemon *mon = (struct Pokemon *)pokemon; - sPSSData->cursorMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); - if (sPSSData->cursorMonSpecies != SPECIES_NONE) + sPSSData->displayMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); + if (sPSSData->displayMonSpecies != SPECIES_NONE) { sanityIsBadEgg = GetMonData(mon, MON_DATA_SANITY_IS_BAD_EGG); if (sanityIsBadEgg) - sPSSData->cursorMonIsEgg = TRUE; + sPSSData->displayMonIsEgg = TRUE; else - sPSSData->cursorMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); - - GetMonData(mon, MON_DATA_NICKNAME, sPSSData->cursorMonNick); - StringGetEnd10(sPSSData->cursorMonNick); - sPSSData->cursorMonLevel = GetMonData(mon, MON_DATA_LEVEL); - sPSSData->cursorMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); - sPSSData->cursorMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); - sPSSData->cursorMonPalette = GetMonFrontSpritePal(mon); + sPSSData->displayMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); + + GetMonData(mon, MON_DATA_NICKNAME, sPSSData->displayMonName); + StringGetEnd10(sPSSData->displayMonName); + sPSSData->displayMonLevel = GetMonData(mon, MON_DATA_LEVEL); + sPSSData->displayMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); + sPSSData->displayMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); + sPSSData->displayMonPalette = GetMonFrontSpritePal(mon); gender = GetMonGender(mon); - sPSSData->cursorMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); + sPSSData->displayMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); } } else if (mode == MODE_BOX) { struct BoxPokemon *boxMon = (struct BoxPokemon *)pokemon; - sPSSData->cursorMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); - if (sPSSData->cursorMonSpecies != SPECIES_NONE) + sPSSData->displayMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); + if (sPSSData->displayMonSpecies != SPECIES_NONE) { u32 otId = GetBoxMonData(boxMon, MON_DATA_OT_ID); sanityIsBadEgg = GetBoxMonData(boxMon, MON_DATA_SANITY_IS_BAD_EGG); if (sanityIsBadEgg) - sPSSData->cursorMonIsEgg = TRUE; + sPSSData->displayMonIsEgg = TRUE; else - sPSSData->cursorMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); + sPSSData->displayMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); - GetBoxMonData(boxMon, MON_DATA_NICKNAME, sPSSData->cursorMonNick); - StringGetEnd10(sPSSData->cursorMonNick); - sPSSData->cursorMonLevel = GetLevelFromBoxMonExp(boxMon); - sPSSData->cursorMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); - sPSSData->cursorMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); - sPSSData->cursorMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, otId, sPSSData->cursorMonPersonality); - gender = GetGenderFromSpeciesAndPersonality(sPSSData->cursorMonSpecies, sPSSData->cursorMonPersonality); - sPSSData->cursorMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); + GetBoxMonData(boxMon, MON_DATA_NICKNAME, sPSSData->displayMonName); + StringGetEnd10(sPSSData->displayMonName); + sPSSData->displayMonLevel = GetLevelFromBoxMonExp(boxMon); + sPSSData->displayMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); + sPSSData->displayMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); + sPSSData->displayMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sPSSData->displayMonSpecies, otId, sPSSData->displayMonPersonality); + gender = GetGenderFromSpeciesAndPersonality(sPSSData->displayMonSpecies, sPSSData->displayMonPersonality); + sPSSData->displayMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); } } else { - sPSSData->cursorMonSpecies = SPECIES_NONE; - sPSSData->cursorMonItemId = ITEM_NONE; + sPSSData->displayMonSpecies = SPECIES_NONE; + sPSSData->displayMonItemId = ITEM_NONE; } - if (sPSSData->cursorMonSpecies == SPECIES_NONE) + if (sPSSData->displayMonSpecies == SPECIES_NONE) { - StringFill(sPSSData->cursorMonNick, CHAR_SPACE, 5); - StringFill(sPSSData->cursorMonNickText, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonSpeciesName, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonGenderLvlText, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonItemName, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonName, CHAR_SPACE, 5); + StringFill(sPSSData->displayMonNameText, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonSpeciesName, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonGenderLvlText, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); } - else if (sPSSData->cursorMonIsEgg) + else if (sPSSData->displayMonIsEgg) { if (sanityIsBadEgg) - StringCopyPadded(sPSSData->cursorMonNickText, sPSSData->cursorMonNick, CHAR_SPACE, 5); + StringCopyPadded(sPSSData->displayMonNameText, sPSSData->displayMonName, CHAR_SPACE, 5); else - StringCopyPadded(sPSSData->cursorMonNickText, gText_EggNickname, CHAR_SPACE, 8); + StringCopyPadded(sPSSData->displayMonNameText, gText_EggNickname, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonSpeciesName, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonGenderLvlText, CHAR_SPACE, 8); - StringFill(sPSSData->cursorMonItemName, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonSpeciesName, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonGenderLvlText, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); } else { - if (sPSSData->cursorMonSpecies == SPECIES_NIDORAN_F || sPSSData->cursorMonSpecies == SPECIES_NIDORAN_M) + if (sPSSData->displayMonSpecies == SPECIES_NIDORAN_F || sPSSData->displayMonSpecies == SPECIES_NIDORAN_M) gender = MON_GENDERLESS; - StringCopyPadded(sPSSData->cursorMonNickText, sPSSData->cursorMonNick, CHAR_SPACE, 5); + StringCopyPadded(sPSSData->displayMonNameText, sPSSData->displayMonName, CHAR_SPACE, 5); - txtPtr = sPSSData->cursorMonSpeciesName; + txtPtr = sPSSData->displayMonSpeciesName; *(txtPtr)++ = CHAR_SLASH; - StringCopyPadded(txtPtr, gSpeciesNames[sPSSData->cursorMonSpecies], CHAR_SPACE, 5); + StringCopyPadded(txtPtr, gSpeciesNames[sPSSData->displayMonSpecies], CHAR_SPACE, 5); - txtPtr = sPSSData->cursorMonGenderLvlText; + txtPtr = sPSSData->displayMonGenderLvlText; *(txtPtr)++ = EXT_CTRL_CODE_BEGIN; *(txtPtr)++ = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; switch (gender) @@ -6685,14 +6734,14 @@ static void SetCursorMonData(void *pokemon, u8 mode) *(txtPtr++) = CHAR_EXTRA_SYMBOL; *(txtPtr++) = CHAR_LV_2; - txtPtr = ConvertIntToDecimalStringN(txtPtr, sPSSData->cursorMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); + txtPtr = ConvertIntToDecimalStringN(txtPtr, sPSSData->displayMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); txtPtr[0] = CHAR_SPACE; txtPtr[1] = EOS; - if (sPSSData->cursorMonItemId != ITEM_NONE) - StringCopyPadded(sPSSData->cursorMonItemName, ItemId_GetName(sPSSData->cursorMonItemId), CHAR_SPACE, 8); + if (sPSSData->displayMonItemId != ITEM_NONE) + StringCopyPadded(sPSSData->displayMonItemName, ItemId_GetName(sPSSData->displayMonItemId), CHAR_SPACE, 8); else - StringFill(sPSSData->cursorMonItemName, CHAR_SPACE, 8); + StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); } } @@ -6916,7 +6965,7 @@ static u8 InBoxInput_GrabbingMultiple(void) } else { - sIsMonBeingMoved = (sPSSData->cursorMonSpecies != SPECIES_NONE); + sIsMonBeingMoved = (sPSSData->displayMonSpecies != SPECIES_NONE); sPSSData->inBoxMovingMode = 2; sMovingMonOrigBoxId = StorageGetCurrentBox(); return INPUT_23; @@ -7316,18 +7365,18 @@ static u8 sub_80CFA5C(void) static bool8 sub_80CFA84(void) { - u16 var0 = sub_80CD504(); + u16 species = GetSpeciesAtCursorPosition(); switch (sPSSData->boxOption) { case OPTION_DEPOSIT: - if (var0) + if (species != SPECIES_NONE) SetMenuText(MENU_STORE); else return FALSE; break; case OPTION_WITHDRAW: - if (var0) + if (species != SPECIES_NONE) SetMenuText(MENU_WITHDRAW); else return FALSE; @@ -7335,14 +7384,14 @@ static bool8 sub_80CFA84(void) case OPTION_MOVE_MONS: if (sIsMonBeingMoved) { - if (var0) + if (species != SPECIES_NONE) SetMenuText(MENU_SHIFT); else SetMenuText(MENU_PLACE); } else { - if (var0) + if (species != SPECIES_NONE) SetMenuText(MENU_MOVE); else return FALSE; @@ -7370,21 +7419,21 @@ static bool8 sub_80CFA84(void) static bool8 sub_80CFB44(void) { - if (sPSSData->cursorMonSpecies == SPECIES_EGG) + if (sPSSData->displayMonSpecies == SPECIES_EGG) return FALSE; if (!IsMovingItem()) { - if (sPSSData->cursorMonItemId == ITEM_NONE) + if (sPSSData->displayMonItemId == ITEM_NONE) { - if (sPSSData->cursorMonSpecies == SPECIES_NONE) + if (sPSSData->displayMonSpecies == SPECIES_NONE) return FALSE; SetMenuText(MENU_GIVE_2); } else { - if (!ItemIsMail(sPSSData->cursorMonItemId)) + if (!ItemIsMail(sPSSData->displayMonItemId)) { SetMenuText(MENU_TAKE); SetMenuText(MENU_BAG); @@ -7394,16 +7443,16 @@ static bool8 sub_80CFB44(void) } else { - if (sPSSData->cursorMonItemId == ITEM_NONE) + if (sPSSData->displayMonItemId == ITEM_NONE) { - if (sPSSData->cursorMonSpecies == SPECIES_NONE) + if (sPSSData->displayMonSpecies == SPECIES_NONE) return FALSE; SetMenuText(MENU_GIVE); } else { - if (ItemIsMail(sPSSData->cursorMonItemId) == TRUE) + if (ItemIsMail(sPSSData->displayMonItemId) == TRUE) return FALSE; SetMenuText(MENU_SWITCH); @@ -7414,10 +7463,10 @@ static bool8 sub_80CFB44(void) return TRUE; } -static void sub_80CFBF4(struct Sprite *sprite) +static void SpriteCB_CursorShadow(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->field_CB4->pos1.x; - sprite->pos1.y = sPSSData->field_CB4->pos1.y + 20; + sprite->pos1.x = sPSSData->cursorSprite->pos1.x; + sprite->pos1.y = sPSSData->cursorSprite->pos1.y + 20; } static void sub_80CFC14(void) @@ -7427,100 +7476,100 @@ static void sub_80CFC14(void) u8 priority, subpriority; struct SpriteSheet spriteSheets[] = { - {gHandCursorTiles, 0x800, 0}, - {gHandCursorShadowTiles, 0x80, 1}, + {sHandCursor_Gfx, 0x800, GFXTAG_CURSOR}, + {sHandCursorShadow_Gfx, 0x80, GFXTAG_CURSOR_SHADOW}, {} }; struct SpritePalette spritePalettes[] = { - {gHandCursorPalette, PALTAG_7}, + {sHandCursor_Pal, PALTAG_7}, {} }; - static const struct OamData sOamData_857BA0C = + static const struct OamData sOamData_Cursor = { .shape = SPRITE_SHAPE(32x32), .size = SPRITE_SIZE(32x32), .priority = 1, }; - static const struct OamData sOamData_857BA14 = + static const struct OamData sOamData_CursorShadow = { .shape = SPRITE_SHAPE(16x16), .size = SPRITE_SIZE(16x16), .priority = 1, }; - static const union AnimCmd sSpriteAnim_857BA1C[] = + static const union AnimCmd sAnim_Cursor_Bouncing[] = { ANIMCMD_FRAME(0, 30), ANIMCMD_FRAME(16, 30), ANIMCMD_JUMP(0) }; - static const union AnimCmd sSpriteAnim_857BA28[] = + static const union AnimCmd sAnim_Cursor_Still[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; - static const union AnimCmd sSpriteAnim_857BA30[] = + static const union AnimCmd sAnim_Cursor_Open[] = { ANIMCMD_FRAME(32, 5), ANIMCMD_END }; - static const union AnimCmd sSpriteAnim_857BA38[] = + static const union AnimCmd sAnim_Cursor_Fist[] = { ANIMCMD_FRAME(48, 5), ANIMCMD_END }; - static const union AnimCmd *const sSpriteAnimTable_857BA40[] = + static const union AnimCmd *const sAnims_Cursor[] = { - sSpriteAnim_857BA1C, - sSpriteAnim_857BA28, - sSpriteAnim_857BA30, - sSpriteAnim_857BA38 + [CURSOR_ANIM_BOUNCE] = sAnim_Cursor_Bouncing, + [CURSOR_ANIM_STILL] = sAnim_Cursor_Still, + [CURSOR_ANIM_OPEN] = sAnim_Cursor_Open, + [CURSOR_ANIM_FIST] = sAnim_Cursor_Fist }; - static const struct SpriteTemplate gSpriteTemplate_857BA50 = + static const struct SpriteTemplate sSpriteTemplate_Cursor = { - .tileTag = TAG_TILE_0, + .tileTag = GFXTAG_CURSOR, .paletteTag = PALTAG_10, - .oam = &sOamData_857BA0C, - .anims = sSpriteAnimTable_857BA40, + .oam = &sOamData_Cursor, + .anims = sAnims_Cursor, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; - static const struct SpriteTemplate gSpriteTemplate_857BA68 = + static const struct SpriteTemplate sSpriteTemplate_CursorShadow = { - .tileTag = TAG_TILE_1, + .tileTag = GFXTAG_CURSOR_SHADOW, .paletteTag = PALTAG_10, - .oam = &sOamData_857BA14, + .oam = &sOamData_CursorShadow, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80CFBF4, + .callback = SpriteCB_CursorShadow, }; LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePalettes); - sPSSData->field_CD8[0] = IndexOfSpritePaletteTag(PALTAG_10); - sPSSData->field_CD8[1] = IndexOfSpritePaletteTag(PALTAG_7); + sPSSData->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); + sPSSData->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); - sub_80CD444(sBoxCursorArea, sBoxCursorPosition, &x, &y); - spriteId = CreateSprite(&gSpriteTemplate_857BA50, x, y, 6); + GetCursorCoordsByPos(sBoxCursorArea, sBoxCursorPosition, &x, &y); + spriteId = CreateSprite(&sSpriteTemplate_Cursor, x, y, 6); if (spriteId != MAX_SPRITES) { - sPSSData->field_CB4 = &gSprites[spriteId]; - sPSSData->field_CB4->oam.paletteNum = sPSSData->field_CD8[sCanOnlyMove]; - sPSSData->field_CB4->oam.priority = 1; + sPSSData->cursorSprite = &gSprites[spriteId]; + sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sCanOnlyMove]; + sPSSData->cursorSprite->oam.priority = 1; if (sIsMonBeingMoved) - StartSpriteAnim(sPSSData->field_CB4, 3); + StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); } else { - sPSSData->field_CB4 = NULL; + sPSSData->cursorSprite = NULL; } if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) @@ -7534,7 +7583,7 @@ static void sub_80CFC14(void) priority = 2; } - spriteId = CreateSprite(&gSpriteTemplate_857BA68, 0, 0, subpriority); + spriteId = CreateSprite(&sSpriteTemplate_CursorShadow, 0, 0, subpriority); if (spriteId != MAX_SPRITES) { sPSSData->field_CB8 = &gSprites[spriteId]; @@ -7551,7 +7600,7 @@ static void sub_80CFC14(void) static void sub_80CFDC4(void) { sCanOnlyMove = !sCanOnlyMove; - sPSSData->field_CB4->oam.paletteNum = sPSSData->field_CD8[sCanOnlyMove]; + sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sCanOnlyMove]; } static u8 GetBoxCursorPosition(void) @@ -7573,9 +7622,9 @@ static void sub_80CFE14(u8 *arg0, u8 *arg1) } } -static void sub_80CFE54(u8 animNum) +static void StartCursorAnim(u8 animNum) { - StartSpriteAnim(sPSSData->field_CB4, animNum); + StartSpriteAnim(sPSSData->cursorSprite, animNum); } static u8 sub_80CFE78(void) @@ -7583,9 +7632,9 @@ static u8 sub_80CFE78(void) return sMovingMonOrigBoxId; } -static void sub_80CFE84(void) +static void SetCursorPriorityTo1(void) { - sPSSData->field_CB4->oam.priority = 1; + sPSSData->cursorSprite->oam.priority = 1; } static void sub_80CFEA8(void) @@ -7777,8 +7826,7 @@ EWRAM_DATA static struct u16 bgY; u16 field_10; struct BoxPokemon boxMons[IN_BOX_COUNT]; -} -*sMoveMonsPtr = NULL; +} *sMoveMonsPtr = NULL; static bool8 sub_80D0164(void) { @@ -7851,7 +7899,7 @@ static bool8 sub_80D024C(void) PutWindowTilemap(sPSSData->field_2200); CopyWindowToVram8Bit(sPSSData->field_2200, 3); BlendPalettes(0x3F00, 8, RGB_WHITE); - sub_80CFE54(2); + StartCursorAnim(CURSOR_ANIM_OPEN); SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); sMoveMonsPtr->state++; break; @@ -7877,13 +7925,13 @@ static bool8 sub_80D0344(void) break; case 1: sub_80D0B5C(); - sub_80CFE54(0); + StartCursorAnim(CURSOR_ANIM_BOUNCE); sMoveMonsPtr->state++; break; case 2: if (!IsDma3ManagerBusyWithBgCopy()) { - sub_80CFE84(); + SetCursorPriorityTo1(); LoadPalette(GetTextWindowPalette(3), 0xD0, 0x20); ShowBg(0); return FALSE; @@ -7931,7 +7979,7 @@ static bool8 sub_80D0420(void) case 1: if (!DoMonPlaceChange()) { - sub_80CFE54(3); + StartCursorAnim(CURSOR_ANIM_FIST); sub_80D0884(0, 256, 8); sub_80CDC64(TRUE); sMoveMonsPtr->state++; @@ -7973,7 +8021,7 @@ static bool8 sub_80D04C8(void) if (!DoMonPlaceChange() && !sub_80D0894()) { sub_80D0A1C(); - sub_80CFE54(2); + StartCursorAnim(CURSOR_ANIM_OPEN); sub_80CDC64(TRUE); HideBg(0); sMoveMonsPtr->state++; @@ -7982,7 +8030,7 @@ static bool8 sub_80D04C8(void) case 2: if (!DoMonPlaceChange()) { - sub_80CFE54(0); + StartCursorAnim(CURSOR_ANIM_BOUNCE); sub_80D0B5C(); sMoveMonsPtr->state++; } @@ -7991,7 +8039,7 @@ static bool8 sub_80D04C8(void) if (!IsDma3ManagerBusyWithBgCopy()) { LoadPalette(GetTextWindowPalette(3), 0xD0, 0x20); - sub_80CFE84(); + SetCursorPriorityTo1(); ShowBg(0); return FALSE; } @@ -8524,7 +8572,7 @@ static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) SetPartyMonIconObjMode(cursorPos, 1); } - sPSSData->movingItemId = sPSSData->cursorMonItemId; + sPSSData->movingItemId = sPSSData->displayMonItemId; } static void sub_80D0F38(u16 itemId) @@ -8635,7 +8683,7 @@ static void sub_80D11CC(void) for (i = 0; i < MAX_ITEM_ICONS; i++) { if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].cursorArea == CURSOR_AREA_IN_PARTY) + && sPSSData->itemIcons[i].area == CURSOR_AREA_IN_PARTY) SetItemIconCallback(i, ITEM_CB_HIDE_PARTY, CURSOR_AREA_IN_HAND, 0); } } @@ -8668,7 +8716,7 @@ static bool8 IsMovingItem(void) for (i = 0; i < MAX_ITEM_ICONS; i++) { if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].cursorArea == CURSOR_AREA_IN_HAND) + && sPSSData->itemIcons[i].area == CURSOR_AREA_IN_HAND) return TRUE; } } @@ -8707,8 +8755,8 @@ static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos) for (i = 0; i < MAX_ITEM_ICONS; i++) { if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].cursorArea == cursorArea - && sPSSData->itemIcons[i].cursorPos == cursorPos) + && sPSSData->itemIcons[i].area == cursorArea + && sPSSData->itemIcons[i].pos == cursorPos) return TRUE; } return FALSE; @@ -8721,8 +8769,8 @@ static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos) for (i = 0; i < MAX_ITEM_ICONS; i++) { if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].cursorArea == cursorArea - && sPSSData->itemIcons[i].cursorPos == cursorPos) + && sPSSData->itemIcons[i].area == cursorArea + && sPSSData->itemIcons[i].pos == cursorPos) return i; } return MAX_ITEM_ICONS; @@ -8772,8 +8820,8 @@ static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) break; } - sPSSData->itemIcons[id].cursorArea = cursorArea; - sPSSData->itemIcons[id].cursorPos = cursorPos; + sPSSData->itemIcons[id].area = cursorArea; + sPSSData->itemIcons[id].pos = cursorPos; } static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) @@ -8874,7 +8922,7 @@ static void PrintItemDescription(void) if (IsMovingItem()) description = ItemId_GetDescription(sPSSData->movingItemId); else - description = ItemId_GetDescription(sPSSData->cursorMonItemId); + description = ItemId_GetDescription(sPSSData->displayMonItemId); FillWindowPixelBuffer(2, PIXEL_FILL(1)); AddTextPrinterParameterized5(2, 1, description, 4, 0, 0, NULL, 0, 1); @@ -8974,9 +9022,9 @@ static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite) static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->field_CB4->pos1.x + 4; - sprite->pos1.y = sPSSData->field_CB4->pos1.y + sPSSData->field_CB4->pos2.y + 8; - sprite->oam.priority = sPSSData->field_CB4->oam.priority; + sprite->pos1.x = sPSSData->cursorSprite->pos1.x + 4; + sprite->pos1.y = sPSSData->cursorSprite->pos1.y + sPSSData->cursorSprite->pos2.y + 8; + sprite->oam.priority = sPSSData->cursorSprite->oam.priority; } static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite) @@ -9133,9 +9181,9 @@ u32 GetBoxMonLevelAt(u8 boxId, u8 boxPosition) if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT && GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], MON_DATA_SANITY_HAS_SPECIES)) lvl = GetLevelFromBoxMonExp(&gPokemonStoragePtr->boxes[boxId][boxPosition]); - #ifdef BUGFIX +#ifdef BUGFIX else - #endif +#endif lvl = 0; return lvl; -- cgit v1.2.3 From 80cc7d46aeab92cf00e508d6c595cb7b590b3615 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 16 Apr 2021 05:14:35 -0400 Subject: Doc storage - fix row/column flip --- src/pokemon_storage_system.c | 214 +++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index f86a4bbbf..3b97b9153 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -4306,9 +4306,9 @@ static void InitBoxMonSprites(u8 boxId) boxPosition = 0; // For each box slot, create a Pokémon icon if a species is present - for (i = 0; i < IN_BOX_COLUMNS; i++) + for (i = 0; i < IN_BOX_ROWS; i++) { - for (j = 0; j < IN_BOX_ROWS; j++) + for (j = 0; j < IN_BOX_COLUMNS; j++) { species = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); if (species != SPECIES_NONE) @@ -4342,11 +4342,11 @@ static void sub_80CB140(u8 boxPosition) if (species != SPECIES_NONE) { - s16 x = 8 * (3 * (boxPosition % IN_BOX_ROWS)) + 100; - s16 y = 8 * (3 * (boxPosition / IN_BOX_ROWS)) + 44; + s16 x = 8 * (3 * (boxPosition % IN_BOX_COLUMNS)) + 100; + s16 y = 8 * (3 * (boxPosition / IN_BOX_COLUMNS)) + 44; u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY); - sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_ROWS)); + sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_COLUMNS)); if (sPSSData->boxOption == OPTION_MOVE_ITEMS) sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; } @@ -4397,19 +4397,19 @@ static void sub_80CB278(struct Sprite *sprite) } } -static void DestroyAllIconsInRow(u8 row) +static void DestroyAllIconsInColumn(u8 column) { - u16 column; - u8 boxPosition = row; + u16 row; + u8 boxPosition = column; - for (column = 0; column < IN_BOX_COLUMNS; column++) + for (row = 0; row < IN_BOX_ROWS; row++) { if (sPSSData->boxMonsSprites[boxPosition] != NULL) { DestroyBoxMonIcon(sPSSData->boxMonsSprites[boxPosition]); sPSSData->boxMonsSprites[boxPosition] = NULL; } - boxPosition += IN_BOX_ROWS; + boxPosition += IN_BOX_COLUMNS; } } @@ -4425,7 +4425,7 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - for (i = 0; i < IN_BOX_COLUMNS; i++) + for (i = 0; i < IN_BOX_ROWS; i++) { if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) { @@ -4441,13 +4441,13 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) count++; } } - boxPosition += IN_BOX_ROWS; + boxPosition += IN_BOX_COLUMNS; y += 24; } } else { - for (i = 0; i < IN_BOX_COLUMNS; i++) + for (i = 0; i < IN_BOX_ROWS; i++) { if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) { @@ -4465,7 +4465,7 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) count++; } } - boxPosition += IN_BOX_ROWS; + boxPosition += IN_BOX_COLUMNS; y += 24; } } @@ -4485,7 +4485,7 @@ static void sub_80CB4CC(u8 boxId, s8 direction) if (direction > 0) sPSSData->field_C68 = 0; else - sPSSData->field_C68 = IN_BOX_ROWS - 1; + sPSSData->field_C68 = IN_BOX_COLUMNS - 1; sPSSData->field_C62 = (24 * sPSSData->field_C68) + 100; sub_80CB1F0(sPSSData->field_C64); @@ -4502,7 +4502,7 @@ static bool8 sub_80CB584(void) sPSSData->field_C62 += sPSSData->field_C64; if (sPSSData->field_C62 <= 64 || sPSSData->field_C62 >= 252) { - DestroyAllIconsInRow(sPSSData->field_C68); + DestroyAllIconsInColumn(sPSSData->field_C68); sPSSData->field_C62 += sPSSData->field_C69 * 24; sPSSData->field_C6A++; } @@ -4510,7 +4510,7 @@ static bool8 sub_80CB584(void) case 1: sPSSData->field_C62 += sPSSData->field_C64; sPSSData->field_C66 += sub_80CB2F8(sPSSData->field_C68, sPSSData->field_C60, sPSSData->field_C64); - if ((sPSSData->field_C69 > 0 && sPSSData->field_C68 == IN_BOX_ROWS - 1) + if ((sPSSData->field_C69 > 0 && sPSSData->field_C68 == IN_BOX_COLUMNS - 1) || (sPSSData->field_C69 < 0 && sPSSData->field_C68 == 0)) { sPSSData->field_C6A++; @@ -4540,9 +4540,9 @@ static void SetBoxSpeciesAndPersonalities(u8 boxId) s32 i, j, boxPosition; boxPosition = 0; - for (i = 0; i < IN_BOX_COLUMNS; i++) + for (i = 0; i < IN_BOX_ROWS; i++) { - for (j = 0; j < IN_BOX_ROWS; j++) + for (j = 0; j < IN_BOX_COLUMNS; j++) { sPSSData->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) @@ -4777,7 +4777,7 @@ static void sub_80CBCAC(u8 boxId, u8 position) { sPSSData->boxMonsSprites[position] = sPSSData->movingMonSprite; sPSSData->boxMonsSprites[position]->oam.priority = 2; - sPSSData->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_ROWS); + sPSSData->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_COLUMNS); } sPSSData->movingMonSprite->callback = SpriteCallbackDummy; sPSSData->movingMonSprite = NULL; @@ -5608,8 +5608,8 @@ static void GetCursorCoordsByPos(u8 cursorArea, u8 cursorPosition, u16 *x, u16 * switch (cursorArea) { case CURSOR_AREA_IN_BOX: - *x = (cursorPosition % IN_BOX_ROWS) * 24 + 100; - *y = (cursorPosition / IN_BOX_ROWS) * 24 + 32; + *x = (cursorPosition % IN_BOX_COLUMNS) * 24 + 100; + *y = (cursorPosition / IN_BOX_COLUMNS) * 24 + 32; break; case CURSOR_AREA_IN_PARTY: if (cursorPosition == 0) @@ -6776,9 +6776,9 @@ static u8 InBoxInput_Normal(void) if (JOY_REPEAT(DPAD_UP)) { retVal = INPUT_1; - if (sBoxCursorPosition >= IN_BOX_ROWS) + if (sBoxCursorPosition >= IN_BOX_COLUMNS) { - cursorPosition -= IN_BOX_ROWS; + cursorPosition -= IN_BOX_COLUMNS; } else { @@ -6790,7 +6790,7 @@ static u8 InBoxInput_Normal(void) else if (JOY_REPEAT(DPAD_DOWN)) { retVal = INPUT_1; - cursorPosition += IN_BOX_ROWS; + cursorPosition += IN_BOX_COLUMNS; if (cursorPosition >= IN_BOX_COUNT) { cursorArea = CURSOR_AREA_BUTTONS; @@ -6804,28 +6804,28 @@ static u8 InBoxInput_Normal(void) else if (JOY_REPEAT(DPAD_LEFT)) { retVal = INPUT_1; - if (sBoxCursorPosition % IN_BOX_ROWS != 0) + if (sBoxCursorPosition % IN_BOX_COLUMNS != 0) { cursorPosition--; } else { sPSSData->field_CD3 = -1; - cursorPosition += (IN_BOX_ROWS - 1); + cursorPosition += (IN_BOX_COLUMNS - 1); } break; } else if (JOY_REPEAT(DPAD_RIGHT)) { retVal = INPUT_1; - if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) + if ((sBoxCursorPosition + 1) % IN_BOX_COLUMNS != 0) { cursorPosition++; } else { sPSSData->field_CD3 = 1; - cursorPosition -= (IN_BOX_ROWS - 1); + cursorPosition -= (IN_BOX_COLUMNS - 1); } break; } @@ -6904,9 +6904,9 @@ static u8 InBoxInput_GrabbingMultiple(void) { if (JOY_REPEAT(DPAD_UP)) { - if (sBoxCursorPosition / IN_BOX_ROWS != 0) + if (sBoxCursorPosition / IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); + sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_COLUMNS); return INPUT_21; } else @@ -6916,9 +6916,9 @@ static u8 InBoxInput_GrabbingMultiple(void) } else if (JOY_REPEAT(DPAD_DOWN)) { - if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT) + if (sBoxCursorPosition + IN_BOX_COLUMNS < IN_BOX_COUNT) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); + sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_COLUMNS); return INPUT_21; } else @@ -6928,7 +6928,7 @@ static u8 InBoxInput_GrabbingMultiple(void) } else if (JOY_REPEAT(DPAD_LEFT)) { - if (sBoxCursorPosition % IN_BOX_ROWS != 0) + if (sBoxCursorPosition % IN_BOX_COLUMNS != 0) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); return INPUT_21; @@ -6940,7 +6940,7 @@ static u8 InBoxInput_GrabbingMultiple(void) } else if (JOY_REPEAT(DPAD_RIGHT)) { - if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) + if ((sBoxCursorPosition + 1) % IN_BOX_COLUMNS != 0) { sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); return INPUT_21; @@ -6979,7 +6979,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (sub_80D0580(0)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); + sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_COLUMNS); return INPUT_25; } else @@ -6991,7 +6991,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (sub_80D0580(1)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); + sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_COLUMNS); return INPUT_25; } else @@ -7608,17 +7608,17 @@ static u8 GetBoxCursorPosition(void) return sBoxCursorPosition; } -static void sub_80CFE14(u8 *arg0, u8 *arg1) +static void sub_80CFE14(u8 *x, u8 *y) { if (sBoxCursorArea == CURSOR_AREA_IN_BOX) { - *arg0 = sBoxCursorPosition % IN_BOX_ROWS; - *arg1 = sBoxCursorPosition / IN_BOX_ROWS; + *x = sBoxCursorPosition % IN_BOX_COLUMNS; + *y = sBoxCursorPosition / IN_BOX_COLUMNS; } else { - *arg0 = 0; - *arg1 = 0; + *x = 0; + *y = 0; } } @@ -7812,16 +7812,16 @@ EWRAM_DATA static struct { u8 field_0; u8 state; - u8 fromRow; u8 fromColumn; - u8 toRow; + u8 fromRow; u8 toColumn; + u8 toRow; u8 field_6; u8 field_7; - u8 minRow; u8 minColumn; + u8 minRow; + u8 columnsTotal; u8 rowsTotal; - u8 columsTotal; u16 bgX; u16 bgY; u16 field_10; @@ -7887,14 +7887,14 @@ static bool8 sub_80D024C(void) sMoveMonsPtr->state++; break; case 1: - sub_80CFE14(&sMoveMonsPtr->fromRow, &sMoveMonsPtr->fromColumn); - sMoveMonsPtr->toRow = sMoveMonsPtr->fromRow; + sub_80CFE14(&sMoveMonsPtr->fromColumn, &sMoveMonsPtr->fromRow); sMoveMonsPtr->toColumn = sMoveMonsPtr->fromColumn; + sMoveMonsPtr->toRow = sMoveMonsPtr->fromRow; ChangeBgX(0, -1024, 0); ChangeBgY(0, -1024, 0); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); FillWindowPixelBuffer8Bit(sPSSData->field_2200, PIXEL_FILL(0)); - sub_80D07B0(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn); + sub_80D07B0(sMoveMonsPtr->fromColumn, sMoveMonsPtr->fromRow); SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); PutWindowTilemap(sPSSData->field_2200); CopyWindowToVram8Bit(sPSSData->field_2200, 3); @@ -7951,8 +7951,8 @@ static bool8 sub_80D03B0(void) { sub_80CFE14(&sMoveMonsPtr->field_6, &sMoveMonsPtr->field_7); sub_80D062C(); - sMoveMonsPtr->toRow = sMoveMonsPtr->field_6; - sMoveMonsPtr->toColumn = sMoveMonsPtr->field_7; + sMoveMonsPtr->toColumn = sMoveMonsPtr->field_6; + sMoveMonsPtr->toRow = sMoveMonsPtr->field_7; CopyWindowToVram8Bit(sPSSData->field_2200, 2); sMoveMonsPtr->state++; } @@ -8054,27 +8054,27 @@ static bool8 sub_80D0580(u8 arg0) switch (arg0) { case 0: - if (sMoveMonsPtr->minColumn == 0) + if (sMoveMonsPtr->minRow == 0) return FALSE; - sMoveMonsPtr->minColumn--; + sMoveMonsPtr->minRow--; sub_80D0884(0, 1024, 6); break; case 1: - if (sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal >= 5) + if (sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal >= IN_BOX_ROWS) return FALSE; - sMoveMonsPtr->minColumn++; + sMoveMonsPtr->minRow++; sub_80D0884(0, -1024, 6); break; case 2: - if (sMoveMonsPtr->minRow == 0) + if (sMoveMonsPtr->minColumn == 0) return FALSE; - sMoveMonsPtr->minRow--; + sMoveMonsPtr->minColumn--; sub_80D0884(1024, 0, 6); break; case 3: - if (sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal > 5) + if (sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal >= IN_BOX_COLUMNS) return FALSE; - sMoveMonsPtr->minRow++; + sMoveMonsPtr->minColumn++; sub_80D0884(-1024, 0, 6); break; } @@ -8084,25 +8084,25 @@ static bool8 sub_80D0580(u8 arg0) static void sub_80D062C(void) { - s16 var = (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->field_6)) - (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow)); - s16 var2 = (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->field_7)) - (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn)); + s16 var = (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->field_6)) - (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn)); + s16 var2 = (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->field_7)) - (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow)); if (var > 0) - sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); if (var < 0) { - sub_80D0740(sMoveMonsPtr->toRow, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + sub_80D0740(sMoveMonsPtr->toColumn, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); } if (var2 > 0) - sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); if (var2 < 0) { - sub_80D0778(sMoveMonsPtr->toColumn, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + sub_80D0778(sMoveMonsPtr->toRow, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); } } @@ -8162,9 +8162,9 @@ static void sub_80D0778(u8 arg0, u8 arg1, u8 arg2) sub_80D0834(arg1++, arg0); } -static void sub_80D07B0(u8 arg0, u8 arg1) +static void sub_80D07B0(u8 x, u8 y) { - u8 position = arg0 + (6 * arg1); + u8 position = x + (IN_BOX_COLUMNS * y); u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); u32 personality = GetCurrentBoxMonData(position, MON_DATA_PERSONALITY); @@ -8179,34 +8179,34 @@ static void sub_80D07B0(u8 arg0, u8 arg1) 0, 32, 32, - 24 * arg0, - 24 * arg1, + 24 * x, + 24 * y, 32, 32, index); } } -static void sub_80D0834(u8 arg0, u8 arg1) +static void sub_80D0834(u8 x, u8 y) { - u8 position = arg0 + (6 * arg1); + u8 position = x + (IN_BOX_COLUMNS * y); u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); if (species != SPECIES_NONE) { FillWindowPixelRect8Bit(sPSSData->field_2200, PIXEL_FILL(0), - 24 * arg0, - 24 * arg1, + 24 * x, + 24 * y, 32, 32); } } -static void sub_80D0884(u16 arg0, u16 arg1, u16 arg2) +static void sub_80D0884(u16 x, u16 y, u16 arg2) { - sMoveMonsPtr->bgX = arg0; - sMoveMonsPtr->bgY = arg1; + sMoveMonsPtr->bgX = x; + sMoveMonsPtr->bgY = y; sMoveMonsPtr->field_10 = arg2; } @@ -8225,22 +8225,22 @@ static u8 sub_80D0894(void) static void sub_80D08CC(void) { s32 i, j; - s32 rowCount, columnCount; + s32 columnCount, rowCount; u8 boxId; u8 monArrayId; - sMoveMonsPtr->minRow = min(sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); sMoveMonsPtr->minColumn = min(sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + sMoveMonsPtr->minRow = min(sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + sMoveMonsPtr->columnsTotal = abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn) + 1; sMoveMonsPtr->rowsTotal = abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow) + 1; - sMoveMonsPtr->columsTotal = abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn) + 1; boxId = StorageGetCurrentBox(); monArrayId = 0; + columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) + for (i = sMoveMonsPtr->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; + for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) { struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); // UB: possible null dereference @@ -8259,14 +8259,14 @@ static void sub_80D08CC(void) static void sub_80D09A4(void) { s32 i, j; + s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; u8 boxId = StorageGetCurrentBox(); - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) + for (i = sMoveMonsPtr->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; + for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) { DestroyBoxMonIconAtPosition(boxPosition); ZeroBoxMonAt(boxId, boxPosition); @@ -8278,14 +8278,14 @@ static void sub_80D09A4(void) static void sub_80D0A1C(void) { s32 i, j; + s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; u8 monArrayId = 0; - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) + for (i = sMoveMonsPtr->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; + for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) { if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) sub_80CB140(boxPosition); @@ -8298,15 +8298,15 @@ static void sub_80D0A1C(void) static void sub_80D0AAC(void) { s32 i, j; + s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; u8 boxId = StorageGetCurrentBox(); u8 monArrayId = 0; - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) + for (i = sMoveMonsPtr->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; + for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) { if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) SetBoxMonAt(boxId, boxPosition, &sMoveMonsPtr->boxMons[monArrayId]); @@ -8328,20 +8328,20 @@ static void sub_80D0B5C(void) static u8 sub_80D0BA4(void) { - return (IN_BOX_ROWS * sMoveMonsPtr->fromColumn) + sMoveMonsPtr->fromRow; + return (IN_BOX_COLUMNS * sMoveMonsPtr->fromRow) + sMoveMonsPtr->fromColumn; } static bool8 sub_80D0BC0(void) { s32 i, j; + s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; u8 monArrayId = 0; - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) + for (i = sMoveMonsPtr->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; + for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) { if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES) && GetCurrentBoxMonData(boxPosition, MON_DATA_SANITY_HAS_SPECIES)) @@ -8791,7 +8791,7 @@ static u8 GetItemIconIdxBySprite(struct Sprite *sprite) static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) { - u8 row, column; + u8 x, y; if (id >= MAX_ITEM_ICONS) return; @@ -8799,10 +8799,10 @@ static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) switch (cursorArea) { case CURSOR_AREA_IN_BOX: - row = cursorPos % IN_BOX_ROWS; - column = cursorPos / IN_BOX_ROWS; - sPSSData->itemIcons[id].sprite->pos1.x = (24 * row) + 112; - sPSSData->itemIcons[id].sprite->pos1.y = (24 * column) + 56; + x = cursorPos % IN_BOX_COLUMNS; + y = cursorPos / IN_BOX_COLUMNS; + sPSSData->itemIcons[id].sprite->pos1.x = (24 * x) + 112; + sPSSData->itemIcons[id].sprite->pos1.y = (24 * y) + 56; sPSSData->itemIcons[id].sprite->oam.priority = 2; break; case CURSOR_AREA_IN_PARTY: -- cgit v1.2.3 From 96dabc1a7f991a57d955723f67989e2d4101f2bd Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 16 Apr 2021 17:05:44 -0400 Subject: Doc storage - multi move --- src/pokemon_storage_system.c | 1208 ++++++++++++++++++++++-------------------- 1 file changed, 629 insertions(+), 579 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 3b97b9153..5b16011fb 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -150,29 +150,29 @@ enum { INPUT_1, INPUT_2, // Unused INPUT_3, // Unused - INPUT_4, - INPUT_5, - INPUT_6, - INPUT_7, - INPUT_8, - INPUT_9, - INPUT_10, - INPUT_11, - INPUT_12, - INPUT_13, - INPUT_14, - INPUT_15, - INPUT_16, - INPUT_17, - INPUT_18, - INPUT_19, - INPUT_20, - INPUT_21, - INPUT_22, - INPUT_23, - INPUT_24, - INPUT_25, - INPUT_26, + INPUT_CLOSE_BOX, + INPUT_SHOW_PARTY, + INPUT_HIDE_PARTY, + INPUT_BOX_OPTIONS, + INPUT_IN_MENU, + INPUT_SCROLL_RIGHT, + INPUT_SCROLL_LEFT, + INPUT_DEPOSIT, + INPUT_WITHDRAW, + INPUT_MOVE_MON, + INPUT_SHIFT_MON, + INPUT_PLACE_MON, + INPUT_TAKE_ITEM, + INPUT_GIVE_ITEM, + INPUT_SWITCH_ITEMS, + INPUT_PRESSED_B, + INPUT_MULTIMOVE_START, + INPUT_MULTIMOVE_CHANGE_SELECTION, + INPUT_MULTIMOVE_SINGLE, + INPUT_MULTIMOVE_GRAB_SELECTION, + INPUT_MULTIMOVE_UNABLE, + INPUT_MULTIMOVE_MOVE_MONS, + INPUT_MULTIMOVE_PLACE_MONS, }; enum { @@ -284,6 +284,31 @@ enum { RELEASE_ANIM_CAME_BACK, }; +// Modes for selecting and moving Pokémon in the box. +// "MULTIPLE" mode allows up to an entire box to be +// picked up at once by pressing Select then holding +// down the A button. While holding A down, the player +// may move the cursor around to select multiple Pokémon. +// This is MOVE_MODE_MULTIPLE_SELECTING. After releasing A +// those Pokémon will be picked up and can be moved around +// as a single unit. This is MOVE_MODE_MULTIPLE_MOVING +enum { + MOVE_MODE_NORMAL, + MOVE_MODE_MULTIPLE_SELECTING, + MOVE_MODE_MULTIPLE_MOVING, +}; + +// IDs for the main functions for moving multiple Pokémon. +// Given as arguments to MultiMove_SetFunction +enum { + MULTIMOVE_START, + MULTIMOVE_CANCEL, + MULTIMOVE_CHANGE_SELECTION, + MULTIMOVE_GRAB_SELECTION, + MULTIMOVE_MOVE_MONS, + MULTIMOVE_PLACE_MONS, +}; + struct Wallpaper { const u32 *tiles; @@ -439,7 +464,7 @@ struct PokemonStorageSystemData u32 field_CC8; s16 field_CCC; s16 field_CCE; - u16 field_CD0; + u16 cursorMoveSteps; s8 field_CD2; s8 field_CD3; u8 field_CD4; @@ -493,7 +518,7 @@ struct PokemonStorageSystemData u8 releaseMonName[POKEMON_NAME_LENGTH + 1]; u8 itemName[20]; u8 inBoxMovingMode; - u16 field_2200; + u16 multiMoveWindowId; struct ItemIcon itemIcons[MAX_ITEM_ICONS]; u16 movingItemId; u16 itemInfoWindowOffset; @@ -547,12 +572,12 @@ EWRAM_DATA static u8 sWhichToReshow = 0; EWRAM_DATA static u8 sLastUsedBox = 0; EWRAM_DATA static u16 sMovingItemId = 0; EWRAM_DATA static struct Pokemon gUnknown_02039D14 = {0}; -EWRAM_DATA static s8 sBoxCursorArea = 0; -EWRAM_DATA static s8 sBoxCursorPosition = 0; +EWRAM_DATA static s8 sCursorArea = 0; +EWRAM_DATA static s8 sCursorPosition = 0; EWRAM_DATA static bool8 sIsMonBeingMoved = 0; EWRAM_DATA static u8 sMovingMonOrigBoxId = 0; EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0; -EWRAM_DATA static bool8 sCanOnlyMove = 0; +EWRAM_DATA static bool8 sAutoActionOn = 0; static void CreateMainMenu(u8, s16 *); static void Cb2_EnterPSS(u8); @@ -573,7 +598,7 @@ static void ScrollBackground(void); static void ChooseBoxMenu_MoveRight(void); static void ChooseBoxMenu_PrintInfo(void); static void sub_80CAA14(void); -static void sub_80CFDC4(void); +static void ToggleCursorAutoAction(void); static void sub_80CE790(void); static void sub_80CE8E4(void); static void GiveChosenBagItem(void); @@ -598,7 +623,6 @@ static void sub_80CA0D8(void); static void AddMenu(void); static void InitReleaseMon(void); static void InitCanReleaseMonVars(void); -static void sub_80D01B8(void); static void ReleaseMon(void); static void RefreshDisplayMonData(void); static void CreateDisplayMonSprite(void); @@ -649,9 +673,7 @@ static bool32 WaitForWallpaperGfxLoad(void); static bool8 InitPSSWindows(void); static bool8 ResetReleaseMonSpritePtr(void); static bool8 TryHideReleaseMon(void); -static bool8 sub_80D0164(void); static bool8 IsInitBoxActive(void); -static bool8 sub_80D01E4(void); static bool8 sub_80CDED4(void); static bool8 sub_80CDF08(void); static bool8 UpdateItemInfoWindowSlideIn(void); @@ -659,16 +681,14 @@ static bool8 UpdateItemInfoWindowSlideOut(void); static bool8 DoShowPartyMenu(void); static bool8 IsItemIconAnimActive(void); static bool8 ScrollToBox(void); -static bool8 sub_80CD554(void); +static bool8 UpdateCursorPos(void); static bool8 HidePartyMenu(void); static bool8 IsMovingItem(void); -static bool8 sub_80D0580(u8); -static bool8 sub_80D0BC0(void); static bool8 IsDisplayMosaicActive(void); static bool8 DoWallpaperGfxChange(void); static bool8 DoMonPlaceChange(void); static bool8 IsMenuLoading(void); -static bool8 CanMovePartyMon(void); +static bool8 IsRemovingLastPartyMon(void); static bool8 CanShiftMon(void); static bool8 IsCursorOnCloseBox(void); static bool8 IsCursorOnBox(void); @@ -713,14 +733,13 @@ static void InitMonPlaceChange(u8); static void SetMonMarkings(u8); static void ShowYesNoWindow(s8); static void sub_80CDBF8(u8); -static void sub_80D01D0(u8); static void AnimateBoxScrollArrows(bool8); static void sub_80CA984(bool8); static void CreatePartyMonsSprites(bool8); static void PrintMessage(u8 id); static s16 HandleMenuInput(void); static s8 RunCanReleaseMon(void); -static u8 GetBoxCursorPosition(void); +static u8 GetCursorPosition(void); static void Item_FromMonToMoving(u8, u8); static void Item_GiveMovingToMon(u8, u8); static void Item_TakeMons(u8, u8); @@ -764,32 +783,11 @@ static void SetDisplayMonData(void *, u8); static bool32 AtLeastThreeUsableMons(void); static u8 InBoxInput_Normal(void); static u8 InBoxInput_MovingMultiple(void); -static u8 InBoxInput_GrabbingMultiple(void); +static u8 InBoxInput_SelectingMultiple(void); static s8 GetMenuItemTextId(u8); -static u8 sub_80CFA5C(void); -static u8 sub_80D0BA4(void); -static bool8 sub_80CFA84(void); -static bool8 sub_80CFB44(void); -static bool8 sub_80D024C(void); -static bool8 sub_80D0344(void); -static bool8 sub_80D03B0(void); -static bool8 sub_80D0420(void); -static bool8 sub_80D04A0(void); -static bool8 sub_80D04C8(void); -static void sub_80D07B0(u8, u8); -static void sub_80D0834(u8, u8); -static void sub_80D0B5C(void); -static void sub_80D062C(void); -static void sub_80D0884(u16, u16, u16); -static void sub_80D08CC(void); -static void sub_80D09A4(void); -static void sub_80D0A1C(void); -static void sub_80D0AAC(void); -static u8 sub_80D0894(void); -static void sub_80D0778(u8, u8, u8); -static void sub_80D0708(u8, u8, u8); -static void sub_80D06D0(u8, u8, u8); -static void sub_80D0740(u8, u8, u8); +static u8 SetSelectionMenuTexts(void); +static bool8 SetMenuTexts_Mon(void); +static bool8 SetMenuTexts_Item(void); static void sub_80D27AC(u8, u16, u16, u16, u16); static void sub_80D27F4(u8, u8, s8); static void sub_80D2644(u8, u8, const void *, u16, u16); @@ -806,6 +804,35 @@ static void sub_80D2C1C(struct UnkStruct_2000028 *); static u8 GetBoxWallpaper(u8); static void SetBoxWallpaper(u8, u8); +// Functions for moving multiple Pokémon at once +static void MultiMove_Free(void); +static bool8 MultiMove_Init(void); +static bool8 MultiMove_RunFunction(void); +static bool8 MultiMove_TryMoveGroup(u8); +static bool8 MultiMove_CanPlaceSelection(void); +static void MultiMove_SetFunction(u8); +static u8 MultiMove_GetOrigin(void); +static bool8 MultiMove_Start(void); +static bool8 MultiMove_Cancel(void); +static bool8 MultiMove_ChangeSelection(void); +static bool8 MultiMove_GrabSelection(void); +static bool8 MultiMove_MoveMons(void); +static bool8 MultiMove_PlaceMons(void); +static void MultiMove_SetIconToBg(u8, u8); +static void MultiMove_ClearIconFromBg(u8, u8); +static void MultiMove_ResetBg(void); +static void MultiMove_UpdateSelectedIcons(void); +static void MultiMove_InitMove(u16, u16, u16); +static void MultiMove_GetMonsFromSelection(void); +static void MultiMove_RemoveMonsFromBox(void); +static void MultiMove_CreatePlacedMonIcons(void); +static void MultiMove_SetPlacedMonData(void); +static u8 MultiMove_UpdateMove(void); +static void MultiMove_DeselectRow(u8, u8, u8); +static void MultiMove_SelectRow(u8, u8, u8); +static void MultiMove_SelectColumn(u8, u8, u8); +static void MultiMove_DeselectColumn(u8, u8, u8); + struct { const u8 *text; const u8 *desc; @@ -2048,7 +2075,7 @@ static void Cb_InitPSS(u8 taskId) sub_80CD3EC(); break; case 5: - if (!sub_80D0164()) + if (!MultiMove_Init()) { SetPSSCallback(Cb_ChangeScreen); return; @@ -2158,22 +2185,38 @@ static void Cb_ReshowPSS(u8 taskId) } } +// States for the outer switch in Cb_MainPSS +enum { + MSTATE_HANDLE_INPUT, + MSTATE_1, + MSTATE_SCROLL_BOX, + MSTATE_WAIT_MSG, + MSTATE_ERROR_LAST_PARTY_MON, + MSTATE_ERROR_HAS_MAIL, + MSTATE_WAIT_ERROR_MSG, + MSTATE_MULTIMOVE_RUN, + MSTATE_MULTIMOVE_RUN_CANCEL, + MSTATE_MULTIMOVE_RUN_MOVED, + MSTATE_SCROLL_BOX_ITEM, + MSTATE_WAIT_ITEM_ANIM, +}; + static void Cb_MainPSS(u8 taskId) { switch (sPSSData->state) { - case 0: + case MSTATE_HANDLE_INPUT: switch (HandleInput()) { case INPUT_1: PlaySE(SE_SELECT); - sPSSData->state = 1; + sPSSData->state = MSTATE_1; break; - case INPUT_5: + case INPUT_SHOW_PARTY: if (sPSSData->boxOption != OPTION_MOVE_MONS && sPSSData->boxOption != OPTION_MOVE_ITEMS) { PrintMessage(MSG_WHICH_ONE_WILL_TAKE); - sPSSData->state = 3; + sPSSData->state = MSTATE_WAIT_MSG; } else { @@ -2181,11 +2224,11 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_ShowPartyPokemon); } break; - case INPUT_6: + case INPUT_HIDE_PARTY: if (sPSSData->boxOption == OPTION_MOVE_MONS) { if (IsMonBeingMoved() && ItemIsMail(sPSSData->displayMonItemId)) - sPSSData->state = 5; + sPSSData->state = MSTATE_ERROR_HAS_MAIL; else SetPSSCallback(Cb_HidePartyPokemon); } @@ -2194,20 +2237,20 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_HidePartyPokemon); } break; - case INPUT_4: + case INPUT_CLOSE_BOX: SetPSSCallback(Cb_OnCloseBoxPressed); break; - case INPUT_19: + case INPUT_PRESSED_B: SetPSSCallback(Cb_OnBPressed); break; - case INPUT_7: + case INPUT_BOX_OPTIONS: PlaySE(SE_SELECT); SetPSSCallback(Cb_HandleBoxOptions); break; - case INPUT_8: + case INPUT_IN_MENU: SetPSSCallback(Cb_OnSelectedMon); break; - case INPUT_9: + case INPUT_SCROLL_RIGHT: PlaySE(SE_SELECT); sPSSData->newCurrBoxId = StorageGetCurrentBox() + 1; if (sPSSData->newCurrBoxId >= TOTAL_BOXES_COUNT) @@ -2215,15 +2258,15 @@ static void Cb_MainPSS(u8 taskId) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = 2; + sPSSData->state = MSTATE_SCROLL_BOX; } else { sub_80CFEA8(); - sPSSData->state = 10; + sPSSData->state = MSTATE_SCROLL_BOX_ITEM; } break; - case INPUT_10: + case INPUT_SCROLL_LEFT: PlaySE(SE_SELECT); sPSSData->newCurrBoxId = StorageGetCurrentBox() - 1; if (sPSSData->newCurrBoxId < 0) @@ -2231,20 +2274,20 @@ static void Cb_MainPSS(u8 taskId) if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = 2; + sPSSData->state = MSTATE_SCROLL_BOX; } else { sub_80CFEA8(); - sPSSData->state = 10; + sPSSData->state = MSTATE_SCROLL_BOX_ITEM; } break; - case INPUT_11: - if (!CanMovePartyMon()) + case INPUT_DEPOSIT: + if (!IsRemovingLastPartyMon()) { if (ItemIsMail(sPSSData->displayMonItemId)) { - sPSSData->state = 5; + sPSSData->state = MSTATE_ERROR_HAS_MAIL; } else { @@ -2254,13 +2297,13 @@ static void Cb_MainPSS(u8 taskId) } else { - sPSSData->state = 4; + sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; } break; - case INPUT_13: - if (CanMovePartyMon()) + case INPUT_MOVE_MON: + if (IsRemovingLastPartyMon()) { - sPSSData->state = 4; + sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; } else { @@ -2268,10 +2311,10 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_MoveMon); } break; - case INPUT_14: + case INPUT_SHIFT_MON: if (!CanShiftMon()) { - sPSSData->state = 4; + sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; } else { @@ -2279,61 +2322,63 @@ static void Cb_MainPSS(u8 taskId) SetPSSCallback(Cb_ShiftMon); } break; - case INPUT_12: + case INPUT_WITHDRAW: PlaySE(SE_SELECT); SetPSSCallback(Cb_WithdrawMon); break; - case INPUT_15: + case INPUT_PLACE_MON: PlaySE(SE_SELECT); SetPSSCallback(Cb_PlaceMon); break; - case INPUT_16: + case INPUT_TAKE_ITEM: PlaySE(SE_SELECT); SetPSSCallback(Cb_TakeItemForMoving); break; - case INPUT_17: + case INPUT_GIVE_ITEM: PlaySE(SE_SELECT); SetPSSCallback(Cb_GiveMovingItemToMon); break; - case INPUT_18: + case INPUT_SWITCH_ITEMS: PlaySE(SE_SELECT); SetPSSCallback(Cb_SwitchSelectedItem); break; - case INPUT_20: + case INPUT_MULTIMOVE_START: PlaySE(SE_SELECT); - sub_80D01D0(0); - sPSSData->state = 7; + MultiMove_SetFunction(MULTIMOVE_START); + sPSSData->state = MSTATE_MULTIMOVE_RUN; break; - case INPUT_22: - sub_80D01D0(1); - sPSSData->state = 8; + case INPUT_MULTIMOVE_SINGLE: + MultiMove_SetFunction(MULTIMOVE_CANCEL); + sPSSData->state = MSTATE_MULTIMOVE_RUN_CANCEL; break; - case INPUT_21: + case INPUT_MULTIMOVE_CHANGE_SELECTION: PlaySE(SE_SELECT); - sub_80D01D0(2); - sPSSData->state = 9; + MultiMove_SetFunction(MULTIMOVE_CHANGE_SELECTION); + sPSSData->state = MSTATE_MULTIMOVE_RUN_MOVED; break; - case INPUT_23: - sub_80D01D0(3); - sPSSData->state = 7; + case INPUT_MULTIMOVE_GRAB_SELECTION: + MultiMove_SetFunction(MULTIMOVE_GRAB_SELECTION); + sPSSData->state = MSTATE_MULTIMOVE_RUN; break; - case INPUT_25: + case INPUT_MULTIMOVE_MOVE_MONS: PlaySE(SE_SELECT); - sub_80D01D0(4); - sPSSData->state = 9; + MultiMove_SetFunction(MULTIMOVE_MOVE_MONS); + sPSSData->state = MSTATE_MULTIMOVE_RUN_MOVED; break; - case INPUT_26: + case INPUT_MULTIMOVE_PLACE_MONS: PlaySE(SE_SELECT); - sub_80D01D0(5); - sPSSData->state = 7; + MultiMove_SetFunction(MULTIMOVE_PLACE_MONS); + sPSSData->state = MSTATE_MULTIMOVE_RUN; break; - case INPUT_24: + case INPUT_MULTIMOVE_UNABLE: + // When selecting/moving multiple Pokémon the + // cursor may not wrap around the edges. PlaySE(SE_FAILURE); break; } break; - case 1: - if (!sub_80CD554()) + case MSTATE_1: + if (!UpdateCursorPos()) { if (IsCursorOnCloseBox()) sub_80CA9C0(); @@ -2342,10 +2387,10 @@ static void Cb_MainPSS(u8 taskId) if (sPSSData->setMosaic) StartDisplayMonMosaicEffect(); - sPSSData->state = 0; + sPSSData->state = MSTATE_HANDLE_INPUT; } break; - case 2: + case MSTATE_SCROLL_BOX: if (!ScrollToBox()) { SetCurrentBox(sPSSData->newCurrBoxId); @@ -2358,64 +2403,68 @@ static void Cb_MainPSS(u8 taskId) if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { sub_80CFECC(); - sPSSData->state = 11; + sPSSData->state = MSTATE_WAIT_ITEM_ANIM; } else { - sPSSData->state = 0; + sPSSData->state = MSTATE_HANDLE_INPUT; } } break; - case 3: + case MSTATE_WAIT_MSG: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state = 0; + sPSSData->state = MSTATE_HANDLE_INPUT; } break; - case 4: + case MSTATE_ERROR_LAST_PARTY_MON: PlaySE(SE_FAILURE); PrintMessage(MSG_LAST_POKE); - sPSSData->state = 6; + sPSSData->state = MSTATE_WAIT_ERROR_MSG; break; - case 5: + case MSTATE_ERROR_HAS_MAIL: PlaySE(SE_FAILURE); PrintMessage(MSG_PLEASE_REMOVE_MAIL); - sPSSData->state = 6; + sPSSData->state = MSTATE_WAIT_ERROR_MSG; break; - case 6: + case MSTATE_WAIT_ERROR_MSG: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); } break; - case 7: - if (!sub_80D01E4()) - sPSSData->state = 0; + case MSTATE_MULTIMOVE_RUN: + if (!MultiMove_RunFunction()) + sPSSData->state = MSTATE_HANDLE_INPUT; break; - case 8: - if (!sub_80D01E4()) + case MSTATE_MULTIMOVE_RUN_CANCEL: + // Began a multiple Pokémon selection but + // ended up selecting a single Pokémon. + // Wait for multi move to cancel, then + // do a normal move. + if (!MultiMove_RunFunction()) SetPSSCallback(Cb_MoveMon); break; - case 9: - if (!sub_80D01E4()) + case MSTATE_MULTIMOVE_RUN_MOVED: + if (!MultiMove_RunFunction()) { if (sPSSData->setMosaic) StartDisplayMonMosaicEffect(); - sPSSData->state = 0; + sPSSData->state = MSTATE_HANDLE_INPUT; } break; - case 10: + case MSTATE_SCROLL_BOX_ITEM: if (!IsItemIconAnimActive()) { SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = 2; + sPSSData->state = MSTATE_SCROLL_BOX; } break; - case 11: + case MSTATE_WAIT_ITEM_ANIM: if (!IsItemIconAnimActive()) - sPSSData->state = 0; + sPSSData->state = MSTATE_HANDLE_INPUT; break; } } @@ -2452,7 +2501,7 @@ static void Cb_HidePartyPokemon(u8 taskId) } break; case 2: - if (!sub_80CD554()) + if (!UpdateCursorPos()) { if (sPSSData->setMosaic) StartDisplayMonMosaicEffect(); @@ -2494,7 +2543,7 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_MainPSS); break; case MENU_MOVE: - if (CanMovePartyMon()) + if (IsRemovingLastPartyMon()) { sPSSData->state = 3; } @@ -2528,7 +2577,7 @@ static void Cb_OnSelectedMon(u8 taskId) SetPSSCallback(Cb_WithdrawMon); break; case MENU_STORE: - if (CanMovePartyMon()) + if (IsRemovingLastPartyMon()) { sPSSData->state = 3; } @@ -2544,7 +2593,7 @@ static void Cb_OnSelectedMon(u8 taskId) } break; case MENU_RELEASE: - if (CanMovePartyMon()) + if (IsRemovingLastPartyMon()) { sPSSData->state = 3; } @@ -2965,7 +3014,7 @@ static void Cb_TakeItemForMoving(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_FromMonToMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + Item_FromMonToMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: @@ -2995,7 +3044,7 @@ static void Cb_GiveMovingItemToMon(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_GiveMovingToMon((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + Item_GiveMovingToMon((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: @@ -3036,7 +3085,7 @@ static void Cb_ItemToBag(u8 taskId) else { PlaySE(SE_SELECT); - Item_TakeMons((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + Item_TakeMons((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state = 1; } break; @@ -3087,7 +3136,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_SwitchMonsWithMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + Item_SwitchMonsWithMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: @@ -3259,6 +3308,7 @@ static void Cb_PrintCantStoreMail(u8 taskId) } } +// Handle options menu that shows when the box title bar is selected static void Cb_HandleBoxOptions(u8 taskId) { switch (sPSSData->state) @@ -3656,25 +3706,24 @@ static void Cb_ChangeScreen(u8 taskId) static void GiveChosenBagItem(void) { - u16 item = gSpecialVar_ItemId; + u16 itemId = gSpecialVar_ItemId; - if (item != 0) + if (itemId != ITEM_NONE) { - u8 id = GetBoxCursorPosition(); - + u8 pos = GetCursorPosition(); if (sInPartyMenu) - SetMonData(&gPlayerParty[id], MON_DATA_HELD_ITEM, &item); + SetMonData(&gPlayerParty[pos], MON_DATA_HELD_ITEM, &itemId); else - SetCurrentBoxMonData(id, MON_DATA_HELD_ITEM, &item); + SetCurrentBoxMonData(pos, MON_DATA_HELD_ITEM, &itemId); - RemoveBagItem(item, 1); + RemoveBagItem(itemId, 1); } } static void FreePSSData(void) { sub_80D25F0(); - sub_80D01B8(); + MultiMove_Free(); FREE_AND_SET_NULL(sPSSData); FreeAllWindowBuffers(); } @@ -4111,7 +4160,7 @@ static bool8 DoShowPartyMenu(void) } break; case 1: - if (!sub_80CD554()) + if (!UpdateCursorPos()) { if (sPSSData->setMosaic) StartDisplayMonMosaicEffect(); @@ -4250,9 +4299,9 @@ static void sub_80CAEAC(void) if (!IsCursorOnBox()) { if (sInPartyMenu) - sub_80D0D8C(CURSOR_AREA_IN_PARTY, GetBoxCursorPosition()); + sub_80D0D8C(CURSOR_AREA_IN_PARTY, GetCursorPosition()); else - sub_80D0D8C(CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + sub_80D0D8C(CURSOR_AREA_IN_BOX, GetCursorPosition()); } if (sMovingItemId != ITEM_NONE) @@ -5574,19 +5623,19 @@ static struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority static void sub_80CD36C(void) { if (sPSSData->boxOption != OPTION_DEPOSIT) - sBoxCursorArea = CURSOR_AREA_IN_BOX; + sCursorArea = CURSOR_AREA_IN_BOX; else - sBoxCursorArea = CURSOR_AREA_IN_PARTY; + sCursorArea = CURSOR_AREA_IN_PARTY; - sBoxCursorPosition = 0; + sCursorPosition = 0; sIsMonBeingMoved = FALSE; sMovingMonOrigBoxId = 0; sMovingMonOrigBoxPos = 0; - sCanOnlyMove = FALSE; + sAutoActionOn = FALSE; sub_80CDC0C(); sub_80CFC14(); sPSSData->field_CD6 = 1; - sPSSData->inBoxMovingMode = 0; + sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; sub_80CEB40(); } @@ -5595,7 +5644,7 @@ static void sub_80CD3EC(void) sub_80CFC14(); sub_80CEBDC(); sPSSData->field_CD6 = 1; - sPSSData->inBoxMovingMode = 0; + sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; if (sIsMonBeingMoved) { sPSSData->movingMon = gUnknown_02039D14; @@ -5645,29 +5694,29 @@ static void GetCursorCoordsByPos(u8 cursorArea, u8 cursorPosition, u16 *x, u16 * static u16 GetSpeciesAtCursorPosition(void) { - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - return GetMonData(&gPlayerParty[sBoxCursorPosition], MON_DATA_SPECIES); + return GetMonData(&gPlayerParty[sCursorPosition], MON_DATA_SPECIES); case CURSOR_AREA_IN_BOX: - return GetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_SPECIES); + return GetCurrentBoxMonData(sCursorPosition, MON_DATA_SPECIES); default: return SPECIES_NONE; } } -static bool8 sub_80CD554(void) +static bool8 UpdateCursorPos(void) { s16 tmp; - if (sPSSData->field_CD0 == 0) + if (sPSSData->cursorMoveSteps == 0) { if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return FALSE; else return IsItemIconAnimActive(); } - else if (--sPSSData->field_CD0 != 0) + else if (--sPSSData->cursorMoveSteps != 0) { sPSSData->field_CBC += sPSSData->field_CC4; sPSSData->field_CC0 += sPSSData->field_CC8; @@ -5722,12 +5771,12 @@ static void sub_80CD70C(void) int r7, r0; if (sPSSData->field_CD2 != 0 || sPSSData->field_CD3 != 0) - sPSSData->field_CD0 = 12; + sPSSData->cursorMoveSteps = 12; else - sPSSData->field_CD0 = 6; + sPSSData->cursorMoveSteps = 6; if (sPSSData->field_CD7) - sPSSData->field_CD7 = sPSSData->field_CD0 >> 1; + sPSSData->field_CD7 = sPSSData->cursorMoveSteps >> 1; switch (sPSSData->field_CD2) { @@ -5757,8 +5806,8 @@ static void sub_80CD70C(void) r7 <<= 8; r0 <<= 8; - sPSSData->field_CC4 = r0 / sPSSData->field_CD0; - sPSSData->field_CC8 = r7 / sPSSData->field_CD0; + sPSSData->field_CC4 = r0 / sPSSData->cursorMoveSteps; + sPSSData->field_CC8 = r7 / sPSSData->cursorMoveSteps; sPSSData->field_CBC = sPSSData->cursorSprite->pos1.x << 8; sPSSData->field_CC0 = sPSSData->cursorSprite->pos1.y << 8; } @@ -5769,7 +5818,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) sub_80CD70C(); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) + if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); } else @@ -5780,10 +5829,10 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0E50(CURSOR_AREA_IN_BOX, sBoxCursorPosition); - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - sub_80D0E50(CURSOR_AREA_IN_PARTY, sBoxCursorPosition); + if (sCursorArea == CURSOR_AREA_IN_BOX) + sub_80D0E50(CURSOR_AREA_IN_BOX, sCursorPosition); + else if (sCursorArea == CURSOR_AREA_IN_PARTY) + sub_80D0E50(CURSOR_AREA_IN_PARTY, sCursorPosition); if (newCursorArea == CURSOR_AREA_IN_BOX) sub_80D0D8C(newCursorArea, newCursorPosition); @@ -5791,7 +5840,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) sub_80D0D8C(newCursorArea, newCursorPosition); } - if (newCursorArea == CURSOR_AREA_IN_PARTY && sBoxCursorArea != CURSOR_AREA_IN_PARTY) + if (newCursorArea == CURSOR_AREA_IN_PARTY && sCursorArea != CURSOR_AREA_IN_PARTY) { sPSSData->field_CD6 = newCursorArea; sPSSData->field_CB8->invisible = TRUE; @@ -5807,7 +5856,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) sPSSData->field_CB8->oam.priority = 1; break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode != 0) + if (sPSSData->inBoxMovingMode != MOVE_MODE_NORMAL) { sPSSData->cursorSprite->oam.priority = 0; sPSSData->field_CB8->invisible = TRUE; @@ -5815,7 +5864,7 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) else { sPSSData->cursorSprite->oam.priority = 2; - if (sBoxCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) + if (sCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) SetMovingMonPriority(2); } break; @@ -5824,11 +5873,11 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) static void sub_80CDA68(void) { - sBoxCursorArea = sPSSData->field_CD4; - sBoxCursorPosition = sPSSData->field_CD5; + sCursorArea = sPSSData->field_CD4; + sCursorPosition = sPSSData->field_CD5; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { - if (sPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) + if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); } else @@ -5838,7 +5887,7 @@ static void sub_80CDA68(void) } sub_80CEB40(); - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_BUTTONS: SetMovingMonPriority(1); @@ -5851,7 +5900,7 @@ static void sub_80CDA68(void) SetMovingMonPriority(1); break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode == 0) + if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) { sPSSData->cursorSprite->oam.priority = 1; sPSSData->field_CB8->oam.priority = 2; @@ -5896,7 +5945,7 @@ static void sub_80CDC0C(void) static void sub_80CDC18(void) { - gUnknown_02039D7E = sBoxCursorPosition; + gUnknown_02039D7E = sCursorPosition; } static u8 sub_80CDC2C(void) @@ -5992,7 +6041,7 @@ static bool8 MonPlaceChange_Shift(void) switch (sPSSData->monPlaceChangeState) { case 0: - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: sPSSData->field_D91 = TOTAL_BOXES_COUNT; @@ -6004,14 +6053,14 @@ static bool8 MonPlaceChange_Shift(void) return FALSE; } StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); - sub_80CBD5C(sPSSData->field_D91, sBoxCursorPosition); + sub_80CBD5C(sPSSData->field_D91, sCursorPosition); sPSSData->monPlaceChangeState++; break; case 1: if (!sub_80CBDC4()) { StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); - SetShiftedMonData(sPSSData->field_D91, sBoxCursorPosition); + SetShiftedMonData(sPSSData->field_D91, sCursorPosition); sPSSData->monPlaceChangeState++; } break; @@ -6065,17 +6114,17 @@ static bool8 sub_80CDF08(void) static void MoveMon(void) { - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); - sub_80CBC14(MODE_PARTY, sBoxCursorPosition); + SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + sub_80CBC14(MODE_PARTY, sCursorPosition); break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode == 0) + if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) { - SetMovedMonData(StorageGetCurrentBox(), sBoxCursorPosition); - sub_80CBC14(MODE_BOX, sBoxCursorPosition); + SetMovedMonData(StorageGetCurrentBox(), sCursorPosition); + sub_80CBC14(MODE_BOX, sCursorPosition); } break; default: @@ -6089,16 +6138,16 @@ static void PlaceMon(void) { u8 boxId; - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - SetPlacedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); - sub_80CBCAC(TOTAL_BOXES_COUNT, sBoxCursorPosition); + SetPlacedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + sub_80CBCAC(TOTAL_BOXES_COUNT, sCursorPosition); break; case CURSOR_AREA_IN_BOX: boxId = StorageGetCurrentBox(); - SetPlacedMonData(boxId, sBoxCursorPosition); - sub_80CBCAC(boxId, sBoxCursorPosition); + SetPlacedMonData(boxId, sCursorPosition); + sub_80CBCAC(boxId, sCursorPosition); break; default: return; @@ -6115,7 +6164,7 @@ static void sub_80CE00C(void) static void SetMovedMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) - sPSSData->movingMon = gPlayerParty[sBoxCursorPosition]; + sPSSData->movingMon = gPlayerParty[sCursorPosition]; else BoxMonAtToMon(boxId, position, &sPSSData->movingMon); @@ -6173,9 +6222,9 @@ static bool8 TryStorePartyMonInBox(u8 boxId) } else { - SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); + SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); SetPlacedMonData(boxId, boxPosition); - DestroyPartyMonIcon(sBoxCursorPosition); + DestroyPartyMonIcon(sCursorPosition); } if (boxId == StorageGetCurrentBox()) @@ -6197,12 +6246,12 @@ static void InitReleaseMon(void) if (sIsMonBeingMoved) mode = MODE_MOVE; - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) + else if (sCursorArea == CURSOR_AREA_IN_PARTY) mode = MODE_PARTY; else mode = MODE_BOX; - SetReleaseMon(mode, sBoxCursorPosition); + SetReleaseMon(mode, sCursorPosition); StringCopy(sPSSData->releaseMonName, sPSSData->displayMonName); } @@ -6230,12 +6279,12 @@ static void ReleaseMon(void) } else { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) + if (sCursorArea == CURSOR_AREA_IN_PARTY) boxId = TOTAL_BOXES_COUNT; else boxId = StorageGetCurrentBox(); - PurgeMonOrBoxMon(boxId, sBoxCursorPosition); + PurgeMonOrBoxMon(boxId, sCursorPosition); } sub_80CEB40(); } @@ -6301,17 +6350,17 @@ static void InitCanReleaseMonVars(void) } else { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) + if (sCursorArea == CURSOR_AREA_IN_PARTY) { - sPSSData->tempMon = gPlayerParty[sBoxCursorPosition]; + sPSSData->tempMon = gPlayerParty[sCursorPosition]; sPSSData->releaseBoxId = TOTAL_BOXES_COUNT; } else { - BoxMonAtToMon(StorageGetCurrentBox(), sBoxCursorPosition, &sPSSData->tempMon); + BoxMonAtToMon(StorageGetCurrentBox(), sCursorPosition, &sPSSData->tempMon); sPSSData->releaseBoxId = StorageGetCurrentBox(); } - sPSSData->releaseBoxPos = sBoxCursorPosition; + sPSSData->releaseBoxPos = sCursorPosition; } GetRestrictedReleaseMoves(sPSSData->restrictedMoveList); @@ -6467,17 +6516,17 @@ static void sub_80CE7E8(void) sPSSData->field_2186 = 0; sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) + else if (sCursorArea == CURSOR_AREA_IN_PARTY) { sPSSData->field_218C.mon = gPlayerParty; - sPSSData->field_2187 = sBoxCursorPosition; + sPSSData->field_2187 = sCursorPosition; sPSSData->field_2186 = CountPartyMons() - 1; sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } else { sPSSData->field_218C.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); - sPSSData->field_2187 = sBoxCursorPosition; + sPSSData->field_2187 = sCursorPosition; sPSSData->field_2186 = IN_BOX_COUNT - 1; sPSSData->summaryScreenMode = SUMMARY_MODE_BOX; } @@ -6488,7 +6537,7 @@ static void sub_80CE8E4(void) if (sIsMonBeingMoved) sub_80CE790(); else - sBoxCursorPosition = gLastViewedMonIndex; + sCursorPosition = gLastViewedMonIndex; } s16 CompactPartySlots(void) @@ -6525,16 +6574,16 @@ static void SetMonMarkings(u8 markings) } else { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - SetMonData(&gPlayerParty[sBoxCursorPosition], MON_DATA_MARKINGS, &markings); - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - SetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_MARKINGS, &markings); + if (sCursorArea == CURSOR_AREA_IN_PARTY) + SetMonData(&gPlayerParty[sCursorPosition], MON_DATA_MARKINGS, &markings); + if (sCursorArea == CURSOR_AREA_IN_BOX) + SetCurrentBoxMonData(sCursorPosition, MON_DATA_MARKINGS, &markings); } } -static bool8 CanMovePartyMon(void) +static bool8 IsRemovingLastPartyMon(void) { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && !sIsMonBeingMoved && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0) + if (sCursorArea == CURSOR_AREA_IN_PARTY && !sIsMonBeingMoved && CountPartyAliveNonEggMonsExcept(sCursorPosition) == 0) return TRUE; else return FALSE; @@ -6544,7 +6593,7 @@ static bool8 CanShiftMon(void) { if (sIsMonBeingMoved) { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0) + if (sCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sCursorPosition) == 0) { if (sPSSData->displayMonIsEgg || GetMonData(&sPSSData->movingMon, MON_DATA_HP) == 0) return FALSE; @@ -6561,17 +6610,17 @@ static bool8 IsMonBeingMoved(void) static bool8 IsCursorOnBox(void) { - return (sBoxCursorArea == CURSOR_AREA_BOX); + return (sCursorArea == CURSOR_AREA_BOX); } static bool8 IsCursorOnCloseBox(void) { - return (sBoxCursorArea == CURSOR_AREA_BUTTONS && sBoxCursorPosition == 1); + return (sCursorArea == CURSOR_AREA_BUTTONS && sCursorPosition == 1); } static bool8 IsCursorInBox(void) { - return (sBoxCursorArea == CURSOR_AREA_IN_BOX); + return (sCursorArea == CURSOR_AREA_IN_BOX); } static void sub_80CEB40(void) @@ -6579,12 +6628,12 @@ static void sub_80CEB40(void) sPSSData->setMosaic = (sIsMonBeingMoved == FALSE); if (!sIsMonBeingMoved) { - switch (sBoxCursorArea) + switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - if (sBoxCursorPosition < PARTY_SIZE) + if (sCursorPosition < PARTY_SIZE) { - SetDisplayMonData(&gPlayerParty[sBoxCursorPosition], MODE_PARTY); + SetDisplayMonData(&gPlayerParty[sCursorPosition], MODE_PARTY); break; } // fallthrough @@ -6593,7 +6642,7 @@ static void sub_80CEB40(void) SetDisplayMonData(NULL, MODE_MOVE); break; case CURSOR_AREA_IN_BOX: - SetDisplayMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sBoxCursorPosition), MODE_BOX); + SetDisplayMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sCursorPosition), MODE_BOX); break; } } @@ -6749,12 +6798,12 @@ static u8 HandleInput_InBox(void) { switch (sPSSData->inBoxMovingMode) { - case 0: + case MOVE_MODE_NORMAL: default: return InBoxInput_Normal(); - case 1: - return InBoxInput_GrabbingMultiple(); - case 2: + case MOVE_MODE_MULTIPLE_SELECTING: + return InBoxInput_SelectingMultiple(); + case MOVE_MODE_MULTIPLE_MOVING: return InBoxInput_MovingMultiple(); } } @@ -6767,8 +6816,8 @@ static u8 InBoxInput_Normal(void) do { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; sPSSData->field_CD2 = 0; sPSSData->field_CD3 = 0; sPSSData->field_CD7 = 0; @@ -6776,7 +6825,7 @@ static u8 InBoxInput_Normal(void) if (JOY_REPEAT(DPAD_UP)) { retVal = INPUT_1; - if (sBoxCursorPosition >= IN_BOX_COLUMNS) + if (sCursorPosition >= IN_BOX_COLUMNS) { cursorPosition -= IN_BOX_COLUMNS; } @@ -6804,7 +6853,7 @@ static u8 InBoxInput_Normal(void) else if (JOY_REPEAT(DPAD_LEFT)) { retVal = INPUT_1; - if (sBoxCursorPosition % IN_BOX_COLUMNS != 0) + if (sCursorPosition % IN_BOX_COLUMNS != 0) { cursorPosition--; } @@ -6818,7 +6867,7 @@ static u8 InBoxInput_Normal(void) else if (JOY_REPEAT(DPAD_RIGHT)) { retVal = INPUT_1; - if ((sBoxCursorPosition + 1) % IN_BOX_COLUMNS != 0) + if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) { cursorPosition++; } @@ -6837,54 +6886,54 @@ static u8 InBoxInput_Normal(void) break; } - if ((JOY_NEW(A_BUTTON)) && sub_80CFA5C()) + if ((JOY_NEW(A_BUTTON)) && SetSelectionMenuTexts()) { - if (!sCanOnlyMove) - return INPUT_8; + if (!sAutoActionOn) + return INPUT_IN_MENU; if (sPSSData->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) { switch (GetMenuItemTextId(0)) { case MENU_STORE: - return INPUT_11; + return INPUT_DEPOSIT; case MENU_WITHDRAW: - return INPUT_12; + return INPUT_WITHDRAW; case MENU_MOVE: - return INPUT_13; + return INPUT_MOVE_MON; case MENU_SHIFT: - return INPUT_14; + return INPUT_SHIFT_MON; case MENU_PLACE: - return INPUT_15; + return INPUT_PLACE_MON; case MENU_TAKE: - return INPUT_16; + return INPUT_TAKE_ITEM; case MENU_GIVE: - return INPUT_17; + return INPUT_GIVE_ITEM; case MENU_SWITCH: - return INPUT_18; + return INPUT_SWITCH_ITEMS; } } else { - sPSSData->inBoxMovingMode = 1; - return INPUT_20; + sPSSData->inBoxMovingMode = MOVE_MODE_MULTIPLE_SELECTING; + return INPUT_MULTIMOVE_START; } } if (JOY_NEW(B_BUTTON)) - return INPUT_19; + return INPUT_PRESSED_B; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return INPUT_10; + return INPUT_SCROLL_LEFT; if (JOY_HELD(R_BUTTON)) - return INPUT_9; + return INPUT_SCROLL_RIGHT; } if (JOY_NEW(SELECT_BUTTON)) { - sub_80CFDC4(); + ToggleCursorAutoAction(); return INPUT_NONE; } @@ -6898,56 +6947,56 @@ static u8 InBoxInput_Normal(void) return retVal; } -static u8 InBoxInput_GrabbingMultiple(void) +static u8 InBoxInput_SelectingMultiple(void) { if (JOY_HELD(A_BUTTON)) { if (JOY_REPEAT(DPAD_UP)) { - if (sBoxCursorPosition / IN_BOX_COLUMNS != 0) + if (sCursorPosition / IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_COLUMNS); - return INPUT_21; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_CHANGE_SELECTION; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_REPEAT(DPAD_DOWN)) { - if (sBoxCursorPosition + IN_BOX_COLUMNS < IN_BOX_COUNT) + if (sCursorPosition + IN_BOX_COLUMNS < IN_BOX_COUNT) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_COLUMNS); - return INPUT_21; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_CHANGE_SELECTION; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_REPEAT(DPAD_LEFT)) { - if (sBoxCursorPosition % IN_BOX_COLUMNS != 0) + if (sCursorPosition % IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return INPUT_21; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + return INPUT_MULTIMOVE_CHANGE_SELECTION; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_REPEAT(DPAD_RIGHT)) { - if ((sBoxCursorPosition + 1) % IN_BOX_COLUMNS != 0) + if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return INPUT_21; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + return INPUT_MULTIMOVE_CHANGE_SELECTION; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else @@ -6957,18 +7006,19 @@ static u8 InBoxInput_GrabbingMultiple(void) } else { - if (sub_80D0BA4() == sBoxCursorPosition) + if (MultiMove_GetOrigin() == sCursorPosition) { - sPSSData->inBoxMovingMode = 0; + // Doing a multiple mon selection but only chose 1 mon + sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; sPSSData->field_CB8->invisible = FALSE; - return INPUT_22; + return INPUT_MULTIMOVE_SINGLE; } else { sIsMonBeingMoved = (sPSSData->displayMonSpecies != SPECIES_NONE); - sPSSData->inBoxMovingMode = 2; + sPSSData->inBoxMovingMode = MOVE_MODE_MULTIPLE_MOVING; sMovingMonOrigBoxId = StorageGetCurrentBox(); - return INPUT_23; + return INPUT_MULTIMOVE_GRAB_SELECTION; } } } @@ -6977,77 +7027,77 @@ static u8 InBoxInput_MovingMultiple(void) { if (JOY_REPEAT(DPAD_UP)) { - if (sub_80D0580(0)) + if (MultiMove_TryMoveGroup(0)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_COLUMNS); - return INPUT_25; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_MOVE_MONS; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_REPEAT(DPAD_DOWN)) { - if (sub_80D0580(1)) + if (MultiMove_TryMoveGroup(1)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_COLUMNS); - return INPUT_25; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_MOVE_MONS; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_REPEAT(DPAD_LEFT)) { - if (sub_80D0580(2)) + if (MultiMove_TryMoveGroup(2)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return INPUT_25; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + return INPUT_MULTIMOVE_MOVE_MONS; } else { - return INPUT_10; + return INPUT_SCROLL_LEFT; } } else if (JOY_REPEAT(DPAD_RIGHT)) { - if (sub_80D0580(3)) + if (MultiMove_TryMoveGroup(3)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return INPUT_25; + sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + return INPUT_MULTIMOVE_MOVE_MONS; } else { - return INPUT_9; + return INPUT_SCROLL_RIGHT; } } else if (JOY_NEW(A_BUTTON)) { - if (sub_80D0BC0()) + if (MultiMove_CanPlaceSelection()) { sIsMonBeingMoved = FALSE; - sPSSData->inBoxMovingMode = 0; - return INPUT_26; + sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; + return INPUT_MULTIMOVE_PLACE_MONS; } else { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } } else if (JOY_NEW(B_BUTTON)) { - return INPUT_24; + return INPUT_MULTIMOVE_UNABLE; } else { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return INPUT_10; + return INPUT_SCROLL_LEFT; if (JOY_HELD(R_BUTTON)) - return INPUT_9; + return INPUT_SCROLL_RIGHT; } return INPUT_NONE; @@ -7063,8 +7113,8 @@ static u8 HandleInput_InParty(void) do { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; sPSSData->field_CD3 = 0; sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; @@ -7075,7 +7125,7 @@ static u8 HandleInput_InParty(void) { if (--cursorPosition < 0) cursorPosition = PARTY_SIZE; - if (cursorPosition != sBoxCursorPosition) + if (cursorPosition != sCursorPosition) retVal = INPUT_1; break; } @@ -7083,27 +7133,27 @@ static u8 HandleInput_InParty(void) { if (++cursorPosition > PARTY_SIZE) cursorPosition = 0; - if (cursorPosition != sBoxCursorPosition) + if (cursorPosition != sCursorPosition) retVal = INPUT_1; break; } - else if (JOY_REPEAT(DPAD_LEFT) && sBoxCursorPosition != 0) + else if (JOY_REPEAT(DPAD_LEFT) && sCursorPosition != 0) { retVal = INPUT_1; - sPSSData->field_CD6 = sBoxCursorPosition; + sPSSData->field_CD6 = sCursorPosition; cursorPosition = 0; break; } else if (JOY_REPEAT(DPAD_RIGHT)) { - if (sBoxCursorPosition == 0) + if (sCursorPosition == 0) { retVal = INPUT_1; cursorPosition = sPSSData->field_CD6; } else { - retVal = INPUT_6; + retVal = INPUT_HIDE_PARTY; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } @@ -7112,36 +7162,36 @@ static u8 HandleInput_InParty(void) if (JOY_NEW(A_BUTTON)) { - if (sBoxCursorPosition == PARTY_SIZE) + if (sCursorPosition == PARTY_SIZE) { if (sPSSData->boxOption == OPTION_DEPOSIT) - return INPUT_4; + return INPUT_CLOSE_BOX; gotoBox = TRUE; } - else if (sub_80CFA5C()) + else if (SetSelectionMenuTexts()) { - if (!sCanOnlyMove) - return INPUT_8; + if (!sAutoActionOn) + return INPUT_IN_MENU; switch (GetMenuItemTextId(0)) { case MENU_STORE: - return INPUT_11; + return INPUT_DEPOSIT; case MENU_WITHDRAW: - return INPUT_12; + return INPUT_WITHDRAW; case MENU_MOVE: - return INPUT_13; + return INPUT_MOVE_MON; case MENU_SHIFT: - return INPUT_14; + return INPUT_SHIFT_MON; case MENU_PLACE: - return INPUT_15; + return INPUT_PLACE_MON; case MENU_TAKE: - return INPUT_16; + return INPUT_TAKE_ITEM; case MENU_GIVE: - return INPUT_17; + return INPUT_GIVE_ITEM; case MENU_SWITCH: - return INPUT_18; + return INPUT_SWITCH_ITEMS; } } } @@ -7149,20 +7199,20 @@ static u8 HandleInput_InParty(void) if (JOY_NEW(B_BUTTON)) { if (sPSSData->boxOption == OPTION_DEPOSIT) - return INPUT_19; + return INPUT_PRESSED_B; gotoBox = TRUE; } if (gotoBox) { - retVal = INPUT_6; + retVal = INPUT_HIDE_PARTY; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } else if (JOY_NEW(SELECT_BUTTON)) { - sub_80CFDC4(); + ToggleCursorAutoAction(); return INPUT_NONE; } @@ -7170,7 +7220,7 @@ static u8 HandleInput_InParty(void) if (retVal != INPUT_NONE) { - if (retVal != INPUT_6) + if (retVal != INPUT_HIDE_PARTY) sub_80CD894(cursorArea, cursorPosition); } @@ -7206,31 +7256,31 @@ static u8 HandleInput_OnBox(void) } if (JOY_HELD(DPAD_LEFT)) - return INPUT_10; + return INPUT_SCROLL_LEFT; if (JOY_HELD(DPAD_RIGHT)) - return INPUT_9; + return INPUT_SCROLL_RIGHT; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { if (JOY_HELD(L_BUTTON)) - return INPUT_10; + return INPUT_SCROLL_LEFT; if (JOY_HELD(R_BUTTON)) - return INPUT_9; + return INPUT_SCROLL_RIGHT; } if (JOY_NEW(A_BUTTON)) { AnimateBoxScrollArrows(FALSE); AddBoxMenu(); - return INPUT_7; + return INPUT_BOX_OPTIONS; } if (JOY_NEW(B_BUTTON)) - return INPUT_19; + return INPUT_PRESSED_B; if (JOY_NEW(SELECT_BUTTON)) { - sub_80CFDC4(); + ToggleCursorAutoAction(); return INPUT_NONE; } @@ -7256,8 +7306,8 @@ static u8 HandleInput_OnButtons(void) do { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; sPSSData->field_CD3 = 0; sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; @@ -7267,7 +7317,7 @@ static u8 HandleInput_OnButtons(void) retVal = INPUT_1; cursorArea = CURSOR_AREA_IN_BOX; sPSSData->field_CD2 = -1; - if (sBoxCursorPosition == 0) + if (sCursorPosition == 0) cursorPosition = IN_BOX_COUNT - 1 - 5; else cursorPosition = IN_BOX_COUNT - 1; @@ -7299,14 +7349,16 @@ static u8 HandleInput_OnButtons(void) break; } + // Button was pressed, determine which if (JOY_NEW(A_BUTTON)) - return (cursorPosition == 0) ? INPUT_5 : INPUT_4; + return (cursorPosition == 0) ? INPUT_SHOW_PARTY : INPUT_CLOSE_BOX; + if (JOY_NEW(B_BUTTON)) - return INPUT_19; + return INPUT_PRESSED_B; if (JOY_NEW(SELECT_BUTTON)) { - sub_80CFDC4(); + ToggleCursorAutoAction(); return INPUT_NONE; } @@ -7337,7 +7389,7 @@ static u8 HandleInput(void) u16 i = 0; while (inputFuncs[i].func != NULL) { - if (inputFuncs[i].area == sBoxCursorArea) + if (inputFuncs[i].area == sCursorArea) return inputFuncs[i].func(); i++; } @@ -7354,16 +7406,16 @@ static void AddBoxMenu(void) SetMenuText(MENU_CANCEL); } -static u8 sub_80CFA5C(void) +static u8 SetSelectionMenuTexts(void) { InitMenu(); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) - return sub_80CFA84(); + return SetMenuTexts_Mon(); else - return sub_80CFB44(); + return SetMenuTexts_Item(); } -static bool8 sub_80CFA84(void) +static bool8 SetMenuTexts_Mon(void) { u16 species = GetSpeciesAtCursorPosition(); @@ -7405,7 +7457,7 @@ static bool8 sub_80CFA84(void) SetMenuText(MENU_SUMMARY); if (sPSSData->boxOption == OPTION_MOVE_MONS) { - if (!sBoxCursorArea) + if (sCursorArea == CURSOR_AREA_IN_BOX) SetMenuText(MENU_WITHDRAW); else SetMenuText(MENU_STORE); @@ -7417,7 +7469,7 @@ static bool8 sub_80CFA84(void) return TRUE; } -static bool8 sub_80CFB44(void) +static bool8 SetMenuTexts_Item(void) { if (sPSSData->displayMonSpecies == SPECIES_EGG) return FALSE; @@ -7554,15 +7606,15 @@ static void sub_80CFC14(void) LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePalettes); - sPSSData->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); - sPSSData->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); + sPSSData->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); // White hand, normal + sPSSData->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); // Yellow hand, when auto-action is on - GetCursorCoordsByPos(sBoxCursorArea, sBoxCursorPosition, &x, &y); + GetCursorCoordsByPos(sCursorArea, sCursorPosition, &x, &y); spriteId = CreateSprite(&sSpriteTemplate_Cursor, x, y, 6); if (spriteId != MAX_SPRITES) { sPSSData->cursorSprite = &gSprites[spriteId]; - sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sCanOnlyMove]; + sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sAutoActionOn]; sPSSData->cursorSprite->oam.priority = 1; if (sIsMonBeingMoved) StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); @@ -7572,7 +7624,7 @@ static void sub_80CFC14(void) sPSSData->cursorSprite = NULL; } - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) + if (sCursorArea == CURSOR_AREA_IN_PARTY) { subpriority = 13; priority = 1; @@ -7588,7 +7640,7 @@ static void sub_80CFC14(void) { sPSSData->field_CB8 = &gSprites[spriteId]; sPSSData->field_CB8->oam.priority = priority; - if (sBoxCursorArea) + if (sCursorArea) sPSSData->field_CB8->invisible = 1; } else @@ -7597,28 +7649,28 @@ static void sub_80CFC14(void) } } -static void sub_80CFDC4(void) +static void ToggleCursorAutoAction(void) { - sCanOnlyMove = !sCanOnlyMove; - sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sCanOnlyMove]; + sAutoActionOn = !sAutoActionOn; + sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sAutoActionOn]; } -static u8 GetBoxCursorPosition(void) +static u8 GetCursorPosition(void) { - return sBoxCursorPosition; + return sCursorPosition; } -static void sub_80CFE14(u8 *x, u8 *y) +static void GetCursorBoxColumnAndRow(u8 *column, u8 *row) { - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) + if (sCursorArea == CURSOR_AREA_IN_BOX) { - *x = sBoxCursorPosition % IN_BOX_COLUMNS; - *y = sBoxCursorPosition / IN_BOX_COLUMNS; + *column = sCursorPosition % IN_BOX_COLUMNS; + *row = sCursorPosition / IN_BOX_COLUMNS; } else { - *x = 0; - *y = 0; + *column = 0; + *row = 0; } } @@ -7639,14 +7691,14 @@ static void SetCursorPriorityTo1(void) static void sub_80CFEA8(void) { - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0E50(CURSOR_AREA_IN_BOX, sBoxCursorPosition); + if (sCursorArea == CURSOR_AREA_IN_BOX) + sub_80D0E50(CURSOR_AREA_IN_BOX, sCursorPosition); } static void sub_80CFECC(void) { - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0D8C(CURSOR_AREA_IN_BOX, sBoxCursorPosition); + if (sCursorArea == CURSOR_AREA_IN_BOX) + sub_80D0D8C(CURSOR_AREA_IN_BOX, sCursorPosition); } static void InitMenu(void) @@ -7793,11 +7845,17 @@ static void RemoveMenu(void) RemoveWindow(sPSSData->menuWindowId); } -// The functions below handle moving and grabbing multiple mons at once. -// The icons are converted to background 0 which coordinates are changed while moving mons. -// There is also a bit of math involved in determining how many column/rows of mons to grab/move. -static const struct WindowTemplate gUnknown_0857BB1C = +//------------------------------------------------------------------------------ +// MultiMove +// +// The functions below handle moving and selecting multiple Pokémon at once. +// The icon sprites are moved to bg 0, and this bg is manipulated to move +// them as a group. +//------------------------------------------------------------------------------ + + +static const struct WindowTemplate sWindowTemplate_MultiMove = { .bg = 0, .tilemapLeft = 10, @@ -7810,33 +7868,33 @@ static const struct WindowTemplate gUnknown_0857BB1C = EWRAM_DATA static struct { - u8 field_0; + u8 funcId; u8 state; u8 fromColumn; u8 fromRow; u8 toColumn; u8 toRow; - u8 field_6; - u8 field_7; + u8 cursorColumn; + u8 cursorRow; u8 minColumn; u8 minRow; u8 columnsTotal; u8 rowsTotal; u16 bgX; u16 bgY; - u16 field_10; + u16 bgMoveSteps; struct BoxPokemon boxMons[IN_BOX_COUNT]; -} *sMoveMonsPtr = NULL; +} *sMultiMove = NULL; -static bool8 sub_80D0164(void) +static bool8 MultiMove_Init(void) { - sMoveMonsPtr = Alloc(sizeof(*sMoveMonsPtr)); - if (sMoveMonsPtr != NULL) + sMultiMove = Alloc(sizeof(*sMultiMove)); + if (sMultiMove != NULL) { - sPSSData->field_2200 = AddWindow8Bit(&gUnknown_0857BB1C); - if (sPSSData->field_2200 != 0xFF) + sPSSData->multiMoveWindowId = AddWindow8Bit(&sWindowTemplate_MultiMove); + if (sPSSData->multiMoveWindowId != WINDOW_NONE) { - FillWindowPixelBuffer(sPSSData->field_2200, PIXEL_FILL(0)); + FillWindowPixelBuffer(sPSSData->multiMoveWindowId, PIXEL_FILL(0)); return TRUE; } } @@ -7844,64 +7902,64 @@ static bool8 sub_80D0164(void) return FALSE; } -static void sub_80D01B8(void) +static void MultiMove_Free(void) { - if (sMoveMonsPtr != NULL) - Free(sMoveMonsPtr); + if (sMultiMove != NULL) + Free(sMultiMove); } -static void sub_80D01D0(u8 arg0) +static void MultiMove_SetFunction(u8 id) { - sMoveMonsPtr->field_0 = arg0; - sMoveMonsPtr->state = 0; + sMultiMove->funcId = id; + sMultiMove->state = 0; } -static bool8 sub_80D01E4(void) +// Returns TRUE if the called function has more to do, FALSE otherwise +static bool8 MultiMove_RunFunction(void) { - switch (sMoveMonsPtr->field_0) + switch (sMultiMove->funcId) { - case 0: - return sub_80D024C(); - case 1: - return sub_80D0344(); - case 2: - return sub_80D03B0(); - case 3: - return sub_80D0420(); - case 4: - return sub_80D04A0(); - case 5: - return sub_80D04C8(); + case MULTIMOVE_START: + return MultiMove_Start(); + case MULTIMOVE_CANCEL: + return MultiMove_Cancel(); + case MULTIMOVE_CHANGE_SELECTION: + return MultiMove_ChangeSelection(); + case MULTIMOVE_GRAB_SELECTION: + return MultiMove_GrabSelection(); + case MULTIMOVE_MOVE_MONS: + return MultiMove_MoveMons(); + case MULTIMOVE_PLACE_MONS: + return MultiMove_PlaceMons(); } - return FALSE; } -static bool8 sub_80D024C(void) +static bool8 MultiMove_Start(void) { - switch (sMoveMonsPtr->state) + switch (sMultiMove->state) { case 0: HideBg(0); sub_80D304C(0x80); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 1: - sub_80CFE14(&sMoveMonsPtr->fromColumn, &sMoveMonsPtr->fromRow); - sMoveMonsPtr->toColumn = sMoveMonsPtr->fromColumn; - sMoveMonsPtr->toRow = sMoveMonsPtr->fromRow; + GetCursorBoxColumnAndRow(&sMultiMove->fromColumn, &sMultiMove->fromRow); + sMultiMove->toColumn = sMultiMove->fromColumn; + sMultiMove->toRow = sMultiMove->fromRow; ChangeBgX(0, -1024, 0); ChangeBgY(0, -1024, 0); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); - FillWindowPixelBuffer8Bit(sPSSData->field_2200, PIXEL_FILL(0)); - sub_80D07B0(sMoveMonsPtr->fromColumn, sMoveMonsPtr->fromRow); + FillWindowPixelBuffer8Bit(sPSSData->multiMoveWindowId, PIXEL_FILL(0)); + MultiMove_SetIconToBg(sMultiMove->fromColumn, sMultiMove->fromRow); SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); - PutWindowTilemap(sPSSData->field_2200); - CopyWindowToVram8Bit(sPSSData->field_2200, 3); + PutWindowTilemap(sPSSData->multiMoveWindowId); + CopyWindowToVram8Bit(sPSSData->multiMoveWindowId, 3); BlendPalettes(0x3F00, 8, RGB_WHITE); StartCursorAnim(CURSOR_ANIM_OPEN); SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 2: if (!IsDma3ManagerBusyWithBgCopy()) @@ -7915,18 +7973,18 @@ static bool8 sub_80D024C(void) return TRUE; } -static bool8 sub_80D0344(void) +static bool8 MultiMove_Cancel(void) { - switch (sMoveMonsPtr->state) + switch (sMultiMove->state) { case 0: HideBg(0); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 1: - sub_80D0B5C(); + MultiMove_ResetBg(); StartCursorAnim(CURSOR_ANIM_BOUNCE); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 2: if (!IsDma3ManagerBusyWithBgCopy()) @@ -7942,19 +8000,19 @@ static bool8 sub_80D0344(void) return TRUE; } -static bool8 sub_80D03B0(void) +static bool8 MultiMove_ChangeSelection(void) { - switch (sMoveMonsPtr->state) + switch (sMultiMove->state) { case 0: - if (!sub_80CD554()) + if (!UpdateCursorPos()) { - sub_80CFE14(&sMoveMonsPtr->field_6, &sMoveMonsPtr->field_7); - sub_80D062C(); - sMoveMonsPtr->toColumn = sMoveMonsPtr->field_6; - sMoveMonsPtr->toRow = sMoveMonsPtr->field_7; - CopyWindowToVram8Bit(sPSSData->field_2200, 2); - sMoveMonsPtr->state++; + GetCursorBoxColumnAndRow(&sMultiMove->cursorColumn, &sMultiMove->cursorRow); + MultiMove_UpdateSelectedIcons(); + sMultiMove->toColumn = sMultiMove->cursorColumn; + sMultiMove->toRow = sMultiMove->cursorRow; + CopyWindowToVram8Bit(sPSSData->multiMoveWindowId, 2); + sMultiMove->state++; } break; case 1: @@ -7964,75 +8022,75 @@ static bool8 sub_80D03B0(void) return TRUE; } -static bool8 sub_80D0420(void) +static bool8 MultiMove_GrabSelection(void) { - u8 var1, var2; + bool8 movingBg, movingMon; - switch (sMoveMonsPtr->state) + switch (sMultiMove->state) { case 0: - sub_80D08CC(); - sub_80D09A4(); + MultiMove_GetMonsFromSelection(); + MultiMove_RemoveMonsFromBox(); sub_80CDC64(FALSE); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 1: if (!DoMonPlaceChange()) { StartCursorAnim(CURSOR_ANIM_FIST); - sub_80D0884(0, 256, 8); + MultiMove_InitMove(0, 256, 8); sub_80CDC64(TRUE); - sMoveMonsPtr->state++; + sMultiMove->state++; } break; case 2: - var1 = sub_80D0894(); - var2 = DoMonPlaceChange(); - if (!var1 && !var2) - return FALSE; + movingBg = MultiMove_UpdateMove(); + movingMon = DoMonPlaceChange(); + if (!movingBg && !movingMon) + return FALSE; // Finished break; } return TRUE; } -static bool8 sub_80D04A0(void) +static bool8 MultiMove_MoveMons(void) { - u8 var1 = sub_80CD554(); - u8 var2 = sub_80D0894(); + bool8 movingCursor = UpdateCursorPos(); + bool8 movingBg = MultiMove_UpdateMove(); - if (!var1 && !var2) + if (!movingCursor && !movingBg) return FALSE; else return TRUE; } -static bool8 sub_80D04C8(void) +static bool8 MultiMove_PlaceMons(void) { - switch (sMoveMonsPtr->state) + switch (sMultiMove->state) { case 0: - sub_80D0AAC(); - sub_80D0884(0, -256, 8); + MultiMove_SetPlacedMonData(); + MultiMove_InitMove(0, -256, 8); sub_80CDC64(FALSE); - sMoveMonsPtr->state++; + sMultiMove->state++; break; case 1: - if (!DoMonPlaceChange() && !sub_80D0894()) + if (!DoMonPlaceChange() && !MultiMove_UpdateMove()) { - sub_80D0A1C(); + MultiMove_CreatePlacedMonIcons(); StartCursorAnim(CURSOR_ANIM_OPEN); sub_80CDC64(TRUE); HideBg(0); - sMoveMonsPtr->state++; + sMultiMove->state++; } break; case 2: if (!DoMonPlaceChange()) { StartCursorAnim(CURSOR_ANIM_BOUNCE); - sub_80D0B5C(); - sMoveMonsPtr->state++; + MultiMove_ResetBg(); + sMultiMove->state++; } break; case 3: @@ -8045,124 +8103,115 @@ static bool8 sub_80D04C8(void) } break; } - return TRUE; } -static bool8 sub_80D0580(u8 arg0) +// Returns TRUE if the movement was successful, FALSE otherwise +static bool8 MultiMove_TryMoveGroup(u8 dir) { - switch (arg0) + switch (dir) { - case 0: - if (sMoveMonsPtr->minRow == 0) + case 0: // Up + if (sMultiMove->minRow == 0) return FALSE; - sMoveMonsPtr->minRow--; - sub_80D0884(0, 1024, 6); + sMultiMove->minRow--; + MultiMove_InitMove(0, 1024, 6); break; - case 1: - if (sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal >= IN_BOX_ROWS) + case 1: // Down + if (sMultiMove->minRow + sMultiMove->rowsTotal >= IN_BOX_ROWS) return FALSE; - sMoveMonsPtr->minRow++; - sub_80D0884(0, -1024, 6); + sMultiMove->minRow++; + MultiMove_InitMove(0, -1024, 6); break; - case 2: - if (sMoveMonsPtr->minColumn == 0) + case 2: // Left + if (sMultiMove->minColumn == 0) return FALSE; - sMoveMonsPtr->minColumn--; - sub_80D0884(1024, 0, 6); + sMultiMove->minColumn--; + MultiMove_InitMove(1024, 0, 6); break; - case 3: - if (sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal >= IN_BOX_COLUMNS) + case 3: // Right + if (sMultiMove->minColumn + sMultiMove->columnsTotal >= IN_BOX_COLUMNS) return FALSE; - sMoveMonsPtr->minColumn++; - sub_80D0884(-1024, 0, 6); + sMultiMove->minColumn++; + MultiMove_InitMove(-1024, 0, 6); break; } - return TRUE; } -static void sub_80D062C(void) +static void MultiMove_UpdateSelectedIcons(void) { - s16 var = (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->field_6)) - (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn)); - s16 var2 = (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->field_7)) - (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow)); + s16 columnChange = (abs(sMultiMove->fromColumn - sMultiMove->cursorColumn)) - (abs(sMultiMove->fromColumn - sMultiMove->toColumn)); + s16 rowChange = (abs(sMultiMove->fromRow - sMultiMove->cursorRow)) - (abs(sMultiMove->fromRow - sMultiMove->toRow)); - if (var > 0) - sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + if (columnChange > 0) + MultiMove_SelectColumn(sMultiMove->cursorColumn, sMultiMove->fromRow, sMultiMove->toRow); - if (var < 0) + if (columnChange < 0) { - sub_80D0740(sMoveMonsPtr->toColumn, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - sub_80D06D0(sMoveMonsPtr->field_6, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); + MultiMove_DeselectColumn(sMultiMove->toColumn, sMultiMove->fromRow, sMultiMove->toRow); + MultiMove_SelectColumn(sMultiMove->cursorColumn, sMultiMove->fromRow, sMultiMove->toRow); } - if (var2 > 0) - sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + if (rowChange > 0) + MultiMove_SelectRow(sMultiMove->cursorRow, sMultiMove->fromColumn, sMultiMove->toColumn); - if (var2 < 0) + if (rowChange < 0) { - sub_80D0778(sMoveMonsPtr->toRow, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - sub_80D0708(sMoveMonsPtr->field_7, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); + MultiMove_DeselectRow(sMultiMove->toRow, sMultiMove->fromColumn, sMultiMove->toColumn); + MultiMove_SelectRow(sMultiMove->cursorRow, sMultiMove->fromColumn, sMultiMove->toColumn); } } -static void sub_80D06D0(u8 arg0, u8 arg1, u8 arg2) +static void MultiMove_SelectColumn(u8 column, u8 minRow, u8 maxRow) { - u8 var1 = arg1; - - if (arg1 > arg2) + if (minRow > maxRow) { - arg1 = arg2; - arg2 = var1; + u8 temp; + SWAP(minRow, maxRow, temp); } - while (arg1 <= arg2) - sub_80D07B0(arg0, arg1++); + while (minRow <= maxRow) + MultiMove_SetIconToBg(column, minRow++); } -static void sub_80D0708(u8 arg0, u8 arg1, u8 arg2) +static void MultiMove_SelectRow(u8 row, u8 minColumn, u8 maxColumn) { - u8 var1 = arg1; - - if (arg1 > arg2) + if (minColumn > maxColumn) { - arg1 = arg2; - arg2 = var1; + u8 temp; + SWAP(minColumn, maxColumn, temp); } - while (arg1 <= arg2) - sub_80D07B0(arg1++, arg0); + while (minColumn <= maxColumn) + MultiMove_SetIconToBg(minColumn++, row); } -static void sub_80D0740(u8 arg0, u8 arg1, u8 arg2) +static void MultiMove_DeselectColumn(u8 column, u8 minRow, u8 maxRow) { - u8 var1 = arg1; - - if (arg1 > arg2) + if (minRow > maxRow) { - arg1 = arg2; - arg2 = var1; + u8 temp; + SWAP(minRow, maxRow, temp); } - while (arg1 <= arg2) - sub_80D0834(arg0, arg1++); + while (minRow <= maxRow) + MultiMove_ClearIconFromBg(column, minRow++); } -static void sub_80D0778(u8 arg0, u8 arg1, u8 arg2) +static void MultiMove_DeselectRow(u8 row, u8 minColumn, u8 maxColumn) { - u8 var1 = arg1; - - if (arg1 > arg2) + if (minColumn > maxColumn) { - arg1 = arg2; - arg2 = var1; + u8 temp; + SWAP(minColumn, maxColumn, temp); } - while (arg1 <= arg2) - sub_80D0834(arg1++, arg0); + while (minColumn <= maxColumn) + MultiMove_ClearIconFromBg(minColumn++, row); } -static void sub_80D07B0(u8 x, u8 y) +static void MultiMove_SetIconToBg(u8 x, u8 y) { u8 position = x + (IN_BOX_COLUMNS * y); u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); @@ -8173,7 +8222,7 @@ static void sub_80D07B0(u8 x, u8 y) const u8 *iconGfx = GetMonIconPtr(species, personality, 1); u8 index = GetValidMonIconPalIndex(species) + 8; - BlitBitmapRectToWindow4BitTo8Bit(sPSSData->field_2200, + BlitBitmapRectToWindow4BitTo8Bit(sPSSData->multiMoveWindowId, iconGfx, 0, 0, @@ -8187,14 +8236,14 @@ static void sub_80D07B0(u8 x, u8 y) } } -static void sub_80D0834(u8 x, u8 y) +static void MultiMove_ClearIconFromBg(u8 x, u8 y) { u8 position = x + (IN_BOX_COLUMNS * y); u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); if (species != SPECIES_NONE) { - FillWindowPixelRect8Bit(sPSSData->field_2200, + FillWindowPixelRect8Bit(sPSSData->multiMoveWindowId, PIXEL_FILL(0), 24 * x, 24 * y, @@ -8203,70 +8252,72 @@ static void sub_80D0834(u8 x, u8 y) } } -static void sub_80D0884(u16 x, u16 y, u16 arg2) +static void MultiMove_InitMove(u16 x, u16 y, u16 arg2) { - sMoveMonsPtr->bgX = x; - sMoveMonsPtr->bgY = y; - sMoveMonsPtr->field_10 = arg2; + sMultiMove->bgX = x; + sMultiMove->bgY = y; + sMultiMove->bgMoveSteps = arg2; } -static u8 sub_80D0894(void) +static u8 MultiMove_UpdateMove(void) { - if (sMoveMonsPtr->field_10 != 0) + if (sMultiMove->bgMoveSteps != 0) { - ChangeBgX(0, sMoveMonsPtr->bgX, 1); - ChangeBgY(0, sMoveMonsPtr->bgY, 1); - sMoveMonsPtr->field_10--; + ChangeBgX(0, sMultiMove->bgX, 1); + ChangeBgY(0, sMultiMove->bgY, 1); + sMultiMove->bgMoveSteps--; } - return sMoveMonsPtr->field_10; + return sMultiMove->bgMoveSteps; } -static void sub_80D08CC(void) +// Store the Pokémon that the player is picking up +static void MultiMove_GetMonsFromSelection(void) { s32 i, j; s32 columnCount, rowCount; u8 boxId; u8 monArrayId; - sMoveMonsPtr->minColumn = min(sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - sMoveMonsPtr->minRow = min(sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - sMoveMonsPtr->columnsTotal = abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn) + 1; - sMoveMonsPtr->rowsTotal = abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow) + 1; + sMultiMove->minColumn = min(sMultiMove->fromColumn, sMultiMove->toColumn); + sMultiMove->minRow = min(sMultiMove->fromRow, sMultiMove->toRow); + sMultiMove->columnsTotal = abs(sMultiMove->fromColumn - sMultiMove->toColumn) + 1; + sMultiMove->rowsTotal = abs(sMultiMove->fromRow - sMultiMove->toRow) + 1; boxId = StorageGetCurrentBox(); monArrayId = 0; - columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; - rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - for (i = sMoveMonsPtr->minRow; i < rowCount; i++) + columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + for (i = sMultiMove->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; - for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) { struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); // UB: possible null dereference #ifdef UBFIX if (boxMon != NULL) - sMoveMonsPtr->boxMons[monArrayId] = *boxMon; -#else - sMoveMonsPtr->boxMons[monArrayId] = *boxMon; #endif + sMultiMove->boxMons[monArrayId] = *boxMon; + monArrayId++; boxPosition++; } } } -static void sub_80D09A4(void) +// The Pokémon the player has picked up have been stored, now delete +// them from their original positions +static void MultiMove_RemoveMonsFromBox(void) { s32 i, j; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; u8 boxId = StorageGetCurrentBox(); - for (i = sMoveMonsPtr->minRow; i < rowCount; i++) + for (i = sMultiMove->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; - for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) { DestroyBoxMonIconAtPosition(boxPosition); ZeroBoxMonAt(boxId, boxPosition); @@ -8275,19 +8326,19 @@ static void sub_80D09A4(void) } } -static void sub_80D0A1C(void) +static void MultiMove_CreatePlacedMonIcons(void) { s32 i, j; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; u8 monArrayId = 0; - for (i = sMoveMonsPtr->minRow; i < rowCount; i++) + for (i = sMultiMove->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; - for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) sub_80CB140(boxPosition); monArrayId++; boxPosition++; @@ -8295,28 +8346,28 @@ static void sub_80D0A1C(void) } } -static void sub_80D0AAC(void) +static void MultiMove_SetPlacedMonData(void) { s32 i, j; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; u8 boxId = StorageGetCurrentBox(); u8 monArrayId = 0; - for (i = sMoveMonsPtr->minRow; i < rowCount; i++) + for (i = sMultiMove->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; - for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) - SetBoxMonAt(boxId, boxPosition, &sMoveMonsPtr->boxMons[monArrayId]); + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) + SetBoxMonAt(boxId, boxPosition, &sMultiMove->boxMons[monArrayId]); boxPosition++; monArrayId++; } } } -static void sub_80D0B5C(void) +static void MultiMove_ResetBg(void) { ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); @@ -8326,24 +8377,24 @@ static void sub_80D0B5C(void) CopyBgTilemapBufferToVram(0); } -static u8 sub_80D0BA4(void) +static u8 MultiMove_GetOrigin(void) { - return (IN_BOX_COLUMNS * sMoveMonsPtr->fromRow) + sMoveMonsPtr->fromColumn; + return (IN_BOX_COLUMNS * sMultiMove->fromRow) + sMultiMove->fromColumn; } -static bool8 sub_80D0BC0(void) +static bool8 MultiMove_CanPlaceSelection(void) { s32 i, j; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columnsTotal; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; u8 monArrayId = 0; - for (i = sMoveMonsPtr->minRow; i < rowCount; i++) + for (i = sMultiMove->minRow; i < rowCount; i++) { - u8 boxPosition = (IN_BOX_COLUMNS * i) + sMoveMonsPtr->minColumn; - for (j = sMoveMonsPtr->minColumn; j < columnCount; j++) + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES) + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES) && GetCurrentBoxMonData(boxPosition, MON_DATA_SANITY_HAS_SPECIES)) return FALSE; @@ -8351,7 +8402,6 @@ static bool8 sub_80D0BC0(void) boxPosition++; } } - return TRUE; } -- cgit v1.2.3 From cd2a99b7c44bb875135c2c97589ecc160dad71f0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 00:49:51 -0400 Subject: Doc storage - misc cleanup, some item/cursor --- src/pokemon_storage_system.c | 842 ++++++++++++++++++++++--------------------- 1 file changed, 434 insertions(+), 408 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 5b16011fb..2db3e67cd 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -147,7 +147,7 @@ enum { // Return IDs for input handlers enum { INPUT_NONE, - INPUT_1, + INPUT_MOVE_CURSOR, INPUT_2, // Unused INPUT_3, // Unused INPUT_CLOSE_BOX, @@ -191,10 +191,10 @@ enum { enum { CURSOR_AREA_IN_BOX, CURSOR_AREA_IN_PARTY, - CURSOR_AREA_BOX, + CURSOR_AREA_BOX_TITLE, CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box }; -#define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX // Alt name for cursor area used by Move Items +#define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX_TITLE // Alt name for cursor area used by Move Items enum { CURSOR_ANIM_BOUNCE, @@ -244,7 +244,7 @@ enum { GFXTAG_15, // Unused GFXTAG_MARKING_COMBO, GFXTAG_17, // Unused - GFXTAG_18, + GFXTAG_MON_ICON, }; // The maximum number of Pokémon icons that can appear on-screen. @@ -302,7 +302,7 @@ enum { // Given as arguments to MultiMove_SetFunction enum { MULTIMOVE_START, - MULTIMOVE_CANCEL, + MULTIMOVE_CANCEL, // If only 1 Pokémon is grabbed MULTIMOVE_CHANGE_SELECTION, MULTIMOVE_GRAB_SELECTION, MULTIMOVE_MOVE_MONS, @@ -316,12 +316,6 @@ struct Wallpaper const u16 *palettes; }; -struct PokemonStorageSystemFunc -{ - u8 (*func)(void); - s8 unk4; -}; - struct StorageMessage { const u8 *text; @@ -385,28 +379,28 @@ struct PokemonStorageSystemData u8 taskId; struct UnkStruct_2000020 unk_0020; struct UnkStruct_2000028 unk_0028[8]; - u16 field_B0[528 / 2]; - u16 field_2C0; - u16 field_2C2; + u16 partyMenuTilemapBuffer[0x108]; + u16 partyMenuUnused; // Never read + u16 partyMenuY; u8 field_2C4; // Unused - u8 field_2C5; + u8 partyMenuMoveTimer; u8 showPartyMenuState; - u8 unk_02C7; - u8 unk_02C8; - bool8 unk_02C9; + bool8 closeBoxFlashing; + u8 closeBoxFlashTimer; + bool8 closeBoxFlashState; s16 newCurrBoxId; u16 bg2_X; s16 scrollSpeed; - u16 field_2D0; + u16 scrollTimer; u8 wallpaperOffset; - u8 field_2D3; // Written to, but never read. - u8 scrollToBoxIdUnused; // Written to, but never read. - u16 field_2D6; // Written to, but never read. - s16 scrollDirectionUnused; // Written to, but never read. - u16 field_2DA; // Written to, but never read. - u16 field_2DC; // Written to, but never read. - u16 field_2DE; // Written to, but never read. - u16 field_2E0; // Written to, but never read. + u8 scrollUnused1; // Never read + u8 scrollToBoxIdUnused; // Never read + u16 scrollUnused2; // Never read + s16 scrollDirectionUnused; // Never read. + u16 scrollUnused3; // Never read + u16 scrollUnused4; // Never read + u16 scrollUnused5; // Never read + u16 scrollUnused6; // Never read u8 filler[22]; u8 boxTitleTiles[1024]; u8 boxTitleCycleId; @@ -421,7 +415,7 @@ struct PokemonStorageSystemData struct Sprite *arrowSprites[2]; u32 boxTitlePalBits; u8 field_73C[80]; // Unused - u16 field_78C; // Written to, but never read. + u16 field_78C; // Never read. s16 wallpaperSetId; s16 wallpaperId; u16 wallpaperTilemap[360]; @@ -449,34 +443,34 @@ struct PokemonStorageSystemData u8 field_C68; s8 field_C69; u8 field_C6A; - u8 field_C6B; // Written to, but never read. + u8 field_C6B; // Never read. struct WindowTemplate menuWindow; struct StorageMenu menuItems[7]; u8 menuItemsCount; u8 menuWidth; - u8 field_CAE; // Written to, but never read. + u8 menuUnusedField; // Never read. u16 menuWindowId; struct Sprite *cursorSprite; - struct Sprite *field_CB8; - s32 field_CBC; - s32 field_CC0; - u32 field_CC4; - u32 field_CC8; - s16 field_CCC; - s16 field_CCE; + struct Sprite *cursorShadowSprite; + s32 cursorNewX; + s32 cursorNewY; + u32 cursorSpeedX; + u32 cursorSpeedY; + s16 cursorTargetX; + s16 cursorTargetY; u16 cursorMoveSteps; - s8 field_CD2; - s8 field_CD3; - u8 field_CD4; - u8 field_CD5; - u8 field_CD6; - u8 field_CD7; + s8 cursorVerticalWrap; + s8 cursorHorizontalWrap; + u8 newCursorArea; + u8 newCursorPosition; + u8 cursorPrevHorizPos; + u8 cursorFlipTimer; u8 cursorPalNums[2]; const u32 *displayMonPalette; u32 displayMonPersonality; u16 displayMonSpecies; u16 displayMonItemId; - u16 field_CE8; + u16 displayUnusedVar; bool8 setMosaic; u8 displayMonMarkings; u8 displayMonLevel; @@ -505,15 +499,15 @@ struct PokemonStorageSystemData u16 releaseCheckState; u16 restrictedReleaseMonMoves; u16 restrictedMoveList[8]; - u8 field_2186; - u8 field_2187; + u8 summaryMaxPos; + u8 summaryStartPos; u8 summaryScreenMode; union { struct Pokemon *mon; struct BoxPokemon *box; - } field_218C; - u8 field_2190[40]; + } summaryMon; + u8 messageText[40]; u8 boxTitleText[40]; u8 releaseMonName[POKEMON_NAME_LENGTH + 1]; u8 itemName[20]; @@ -531,7 +525,7 @@ struct PokemonStorageSystemData u8 field_2AC4[0x1800]; // Unused u8 field_42C4[0x800]; u8 wallpaperBgTilemapBuffer[0x1000]; - u8 field_5AC4[0x800]; + u8 displayMenuTilemapBuffer[0x800]; }; struct UnkSubStruct_2039D84 @@ -571,7 +565,7 @@ EWRAM_DATA static u8 sDepositBoxId = 0; EWRAM_DATA static u8 sWhichToReshow = 0; EWRAM_DATA static u8 sLastUsedBox = 0; EWRAM_DATA static u16 sMovingItemId = 0; -EWRAM_DATA static struct Pokemon gUnknown_02039D14 = {0}; +EWRAM_DATA static struct Pokemon sSavedMovingMon = {0}; EWRAM_DATA static s8 sCursorArea = 0; EWRAM_DATA static s8 sCursorPosition = 0; EWRAM_DATA static bool8 sIsMonBeingMoved = 0; @@ -583,7 +577,7 @@ static void CreateMainMenu(u8, s16 *); static void Cb2_EnterPSS(u8); static u8 GetCurrentBoxOption(void); static u8 HandleInput(void); -static u8 sub_80CDC2C(void); +static u8 GetSavedCursorPos(void); static u8 sub_80CB9BC(void); static void LoadWallpaperGfx(u8, s8); static void CreateIncomingBoxTitle(u8, s8); @@ -597,17 +591,17 @@ static void ChooseBoxMenu_MoveLeft(void); static void ScrollBackground(void); static void ChooseBoxMenu_MoveRight(void); static void ChooseBoxMenu_PrintInfo(void); -static void sub_80CAA14(void); +static void UpdateCloseBoxButtonFlash(void); static void ToggleCursorAutoAction(void); -static void sub_80CE790(void); +static void LoadSavedMovingMon(void); static void sub_80CE8E4(void); static void GiveChosenBagItem(void); static void SetUpHidePartyMenu(void); static void DestroyAllPartyMonIcons(void); -static void sub_80D11CC(void); +static void MoveHeldItemWithPartyMenu(void); static void LoadPSSMenuGfx(void); static void LoadWaveformSpritePalette(void); -static void sub_80CDC18(void); +static void SaveCursorPos(void); static void sub_80CD36C(void); static void sub_80CD3EC(void); static void sub_80CAC1C(void); @@ -616,8 +610,8 @@ static void SetScrollingBackground(void); static void sub_80CABE0(void); static void sub_80CAEAC(void); static void CreateItemIconSprites(void); -static void sub_80CFEA8(void); -static void sub_80CDC0C(void); +static void TryHideItemAtCursor(void); +static void ClearSavedCursorPos(void); static void InitMonIconFields(void); static void sub_80CA0D8(void); static void AddMenu(void); @@ -633,26 +627,26 @@ static void TrySetCursorFistAnim(void); static void ClearBottomWindow(void); static void sub_80CA704(void); static void RemoveMenu(void); -static void sub_80CE00C(void); -static void sub_80D1194(void); +static void RefreshDisplayMon(void); +static void MoveItemFromCursorToBag(void); static void PrintDisplayMonInfo(void); static void UpdateWaveformAnimation(void); static void AddWallpaperSetsMenu(void); static void CreateBoxScrollArrows(void); static void InitMenu(void); static void StopBoxScrollArrowsSlide(void); -static void sub_80CFC14(void); -static void sub_80CEB40(void); +static void CreateCursorSprites(void); +static void TryRefreshDisplayMon(void); static void CycleBoxTitleSprites(void); static void InitItemInfoWindow(void); static void DrawItemInfoWindow(u32); static void sub_80CAA74(void); static void PrintItemDescription(void); -static void sub_80CE760(void); -static void sub_80CDBA0(void); -static void sub_80CE7E8(void); -static void sub_80CFECC(void); -static void sub_80CA9EC(void); +static void SaveMovingMon(void); +static void SetCursorInParty(void); +static void InitSummaryScreenData(void); +static void TryShowItemAtCursor(void); +static void StopFlashingCloseBoxButton(void); static void FreePSSData(void); static void AddBoxMenu(void); static void CycleBoxTitleColor(void); @@ -660,9 +654,9 @@ static void MoveMon(void); static void PlaceMon(void); static void sub_80CAB20(void); static void sub_80CE22C(void); -static void sub_80CDA68(void); +static void DoCursorNewPosUpdate(void); static void sub_80CB950(void); -static void sub_80CA9C0(void); +static void StartFlashingCloseBoxButton(void); static void SetUpDoShowPartyMenu(void); static void StartDisplayMonMosaicEffect(void); static void SpriteCB_ChooseBoxArrow(struct Sprite *); @@ -691,7 +685,7 @@ static bool8 IsMenuLoading(void); static bool8 IsRemovingLastPartyMon(void); static bool8 CanShiftMon(void); static bool8 IsCursorOnCloseBox(void); -static bool8 IsCursorOnBox(void); +static bool8 IsCursorOnBoxTitle(void); static bool8 IsCursorInBox(void); static bool8 IsMonBeingMoved(void); static bool8 TryStorePartyMonInBox(u8); @@ -732,7 +726,7 @@ static void SetMovingMonPriority(u8); static void InitMonPlaceChange(u8); static void SetMonMarkings(u8); static void ShowYesNoWindow(s8); -static void sub_80CDBF8(u8); +static void SetCursorBoxPosition(u8); static void AnimateBoxScrollArrows(bool8); static void sub_80CA984(bool8); static void CreatePartyMonsSprites(bool8); @@ -740,10 +734,10 @@ static void PrintMessage(u8 id); static s16 HandleMenuInput(void); static s8 RunCanReleaseMon(void); static u8 GetCursorPosition(void); -static void Item_FromMonToMoving(u8, u8); -static void Item_GiveMovingToMon(u8, u8); -static void Item_TakeMons(u8, u8); -static void Item_SwitchMonsWithMoving(u8, u8); +static void TakeItemFromMon(u8, u8); +static void GiveItemToMon(u8, u8); +static void MoveItemFromMonToBag(u8, u8); +static void SwapItemsWithMon(u8, u8); static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); static void SetWallpaperForCurrentBox(u8); static void AddWallpapersMenu(u8); @@ -753,13 +747,13 @@ static void SpriteCB_DisplayMonMosaic(struct Sprite *); static void SpriteCB_OutgoingBoxTitle(struct Sprite *); static void sub_80CBA3C(struct Sprite *); static void SpriteCB_IncomingBoxTitle(struct Sprite *); -static void sub_80CBAF0(s16); +static void MovePartySprites(s16); static void sub_80CAAA8(u8, bool8); static const u8 *GetMovingItemName(void); static void SetMenuText(u8); -static void sub_80D0D8C(u8, u8); -static void sub_80D0E50(u8, u8); -static void sub_80D0F38(u16); +static void TryLoadItemIconAtPos(u8, u8); +static void TryHideItemIconAtPos(u8, u8); +static void InitItemIconInCursor(u16); static struct Sprite *CreateMonIconSprite(u16, u32, s16, s16, u8, u8); static void DestroyBoxMonIcon(struct Sprite *); static void SetBoxSpeciesAndPersonalities(u8); @@ -776,7 +770,7 @@ static bool8 sub_80CDEC4(void); static bool8 sub_80CDEB4(void); static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *); static void SetShiftedMonData(u8, u8); -static void SetMovedMonData(u8, u8); +static void SetMovingMonData(u8, u8); static void SetPlacedMonData(u8, u8); static void PurgeMonOrBoxMon(u8, u8); static void SetDisplayMonData(void *, u8); @@ -833,6 +827,25 @@ static void MultiMove_SelectRow(u8, u8, u8); static void MultiMove_SelectColumn(u8, u8, u8); static void MultiMove_DeselectColumn(u8, u8, u8); +// Functions for Move Items mode +static bool32 IsItemIconAtPosition(u8, u8); +static const u32 *GetItemIconPic(u16); +static const u32 *GetItemIconPalette(u16); +static u8 GetNewItemIconIdx(void); +static void SetItemIconPosition(u8, u8, u8); +static void LoadItemIconGfx(u8, const u32 *, const u32 *); +static void SetItemIconAffineAnim(u8, u8); +static void SetItemIconActive(u8, bool8); +static u8 GetItemIconIdxByPosition(u8, u8); +static void SetItemIconCallback(u8, u8, u8, u8); +static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *); +static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *); +static void SpriteCB_ItemIcon_ToHand(struct Sprite *); +static void SpriteCB_ItemIcon_ToMon(struct Sprite *); +static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *); +static void SpriteCB_ItemIcon_HideParty(struct Sprite *); +static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *); + struct { const u8 *text; const u8 *desc; @@ -908,8 +921,8 @@ static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); -static const u32 gUnknown_08572280[] = INCBIN_U32("graphics/unknown/unknown_572280.gbapal"); -static const u32 gUnknown_085722A0[] = INCBIN_U32("graphics/unknown/unknown_5722A0.bin.lz"); +static const u16 sDisplayMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/display_menu.gbapal"); // Unused +static const u32 sDisplayMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/display_menu.bin.lz"); static const u16 gUnknown_0857239C[] = { @@ -974,7 +987,7 @@ static const struct WindowTemplate sWindowTemplates[] = DUMMY_WIN_TEMPLATE }; -static const struct BgTemplate gUnknown_08572734[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, @@ -1166,7 +1179,7 @@ static const struct SpriteTemplate sSpriteTemplate_Waveform = static const struct OamData sOamData_MonIcon; static const struct SpriteTemplate sSpriteTemplate_MonIcon = { - .tileTag = GFXTAG_18, + .tileTag = GFXTAG_MON_ICON, .paletteTag = PALTAG_MON_ICON_0, .oam = &sOamData_MonIcon, .anims = gDummySpriteAnimTable, @@ -1927,7 +1940,7 @@ static void Cb2_PSS(void) RunTasks(); DoScheduledBgTilemapCopiesToVram(); ScrollBackground(); - sub_80CAA14(); + UpdateCloseBoxButtonFlash(); AnimateSprites(); BuildOamBuffer(); } @@ -1997,12 +2010,12 @@ static void sub_80C7E98(void) sub_80D259C(3); sub_80D2644(0, 1, gUnknown_0857239C, 8, 4); sub_80D2770(0, 1, 0); - sPSSData->unk_02C7 = 0; + sPSSData->closeBoxFlashing = FALSE; } static void sub_80C7F1C(void) { - sub_80CDC0C(); + ClearSavedCursorPos(); sInPartyMenu = (sPSSData->boxOption == OPTION_DEPOSIT); sDepositBoxId = 0; } @@ -2035,13 +2048,16 @@ static void Cb_InitPSS(u8 taskId) { switch (sWhichToReshow) { - case 1: - sub_80CE790(); + case SCREEN_CHANGE_NAME_BOX - 1: + // Return from naming box + LoadSavedMovingMon(); break; - case 0: + case SCREEN_CHANGE_SUMMARY_SCREEN - 1: + // Return from summary screen sub_80CE8E4(); break; - case 2: + case SCREEN_CHANGE_ITEM_FROM_BAG - 1: + // Return from bag menu GiveChosenBagItem(); break; } @@ -2160,7 +2176,7 @@ static void Cb_ReshowPSS(u8 taskId) case 1: if (!UpdatePaletteFade()) { - if (sWhichToReshow == 2 && gSpecialVar_ItemId != 0) + if (sWhichToReshow == SCREEN_CHANGE_ITEM_FROM_BAG - 1 && gSpecialVar_ItemId != ITEM_NONE) { PrintMessage(MSG_ITEM_IS_HELD); sPSSData->state++; @@ -2188,7 +2204,7 @@ static void Cb_ReshowPSS(u8 taskId) // States for the outer switch in Cb_MainPSS enum { MSTATE_HANDLE_INPUT, - MSTATE_1, + MSTATE_MOVE_CURSOR, MSTATE_SCROLL_BOX, MSTATE_WAIT_MSG, MSTATE_ERROR_LAST_PARTY_MON, @@ -2208,9 +2224,9 @@ static void Cb_MainPSS(u8 taskId) case MSTATE_HANDLE_INPUT: switch (HandleInput()) { - case INPUT_1: + case INPUT_MOVE_CURSOR: PlaySE(SE_SELECT); - sPSSData->state = MSTATE_1; + sPSSData->state = MSTATE_MOVE_CURSOR; break; case INPUT_SHOW_PARTY: if (sPSSData->boxOption != OPTION_MOVE_MONS && sPSSData->boxOption != OPTION_MOVE_ITEMS) @@ -2220,7 +2236,7 @@ static void Cb_MainPSS(u8 taskId) } else { - sub_80CDC0C(); + ClearSavedCursorPos(); SetPSSCallback(Cb_ShowPartyPokemon); } break; @@ -2262,7 +2278,7 @@ static void Cb_MainPSS(u8 taskId) } else { - sub_80CFEA8(); + TryHideItemAtCursor(); sPSSData->state = MSTATE_SCROLL_BOX_ITEM; } break; @@ -2278,7 +2294,7 @@ static void Cb_MainPSS(u8 taskId) } else { - sub_80CFEA8(); + TryHideItemAtCursor(); sPSSData->state = MSTATE_SCROLL_BOX_ITEM; } break; @@ -2377,13 +2393,13 @@ static void Cb_MainPSS(u8 taskId) break; } break; - case MSTATE_1: + case MSTATE_MOVE_CURSOR: if (!UpdateCursorPos()) { if (IsCursorOnCloseBox()) - sub_80CA9C0(); + StartFlashingCloseBoxButton(); else - sub_80CA9EC(); + StopFlashingCloseBoxButton(); if (sPSSData->setMosaic) StartDisplayMonMosaicEffect(); @@ -2396,13 +2412,13 @@ static void Cb_MainPSS(u8 taskId) SetCurrentBox(sPSSData->newCurrBoxId); if (!sInPartyMenu && !IsMonBeingMoved()) { - sub_80CE00C(); + RefreshDisplayMon(); StartDisplayMonMosaicEffect(); } if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { - sub_80CFECC(); + TryShowItemAtCursor(); sPSSData->state = MSTATE_WAIT_ITEM_ANIM; } else @@ -2496,7 +2512,7 @@ static void Cb_HidePartyPokemon(u8 taskId) case 1: if (!HidePartyMenu()) { - sub_80CDBF8(sub_80CDC2C()); + SetCursorBoxPosition(GetSavedCursorPos()); sPSSData->state++; } break; @@ -2738,7 +2754,7 @@ static void Cb_WithdrawMon(u8 taskId) } else { - sub_80CDC18(); + SaveCursorPos(); InitMonPlaceChange(0); sPSSData->state = 2; } @@ -2920,7 +2936,7 @@ static void Cb_ReleaseMon(u8 taskId) case 6: if (!sub_80CB9BC()) { - sub_80CE00C(); + RefreshDisplayMon(); StartDisplayMonMosaicEffect(); sub_80CAB20(); sPSSData->state++; @@ -3014,7 +3030,7 @@ static void Cb_TakeItemForMoving(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_FromMonToMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); + TakeItemFromMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: @@ -3022,7 +3038,7 @@ static void Cb_TakeItemForMoving(u8 taskId) { StartCursorAnim(CURSOR_ANIM_FIST); ClearBottomWindow(); - sub_80CE00C(); + RefreshDisplayMon(); PrintDisplayMonInfo(); sPSSData->state++; } @@ -3044,14 +3060,14 @@ static void Cb_GiveMovingItemToMon(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_GiveMovingToMon((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); + GiveItemToMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: if (!IsItemIconAnimActive()) { StartCursorAnim(CURSOR_ANIM_BOUNCE); - sub_80CE00C(); + RefreshDisplayMon(); PrintDisplayMonInfo(); PrintMessage(MSG_ITEM_IS_HELD); sPSSData->state++; @@ -3085,7 +3101,7 @@ static void Cb_ItemToBag(u8 taskId) else { PlaySE(SE_SELECT); - Item_TakeMons((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); + MoveItemFromMonToBag(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state = 1; } break; @@ -3100,7 +3116,7 @@ static void Cb_ItemToBag(u8 taskId) if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sub_80CE00C(); + RefreshDisplayMon(); PrintDisplayMonInfo(); sPSSData->state = 4; } @@ -3136,14 +3152,14 @@ static void Cb_SwitchSelectedItem(u8 taskId) break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); - Item_SwitchMonsWithMoving((sInPartyMenu != FALSE) ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); + SwapItemsWithMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); sPSSData->state++; break; case 2: if (!IsItemIconAnimActive()) { StartCursorAnim(CURSOR_ANIM_FIST); - sub_80CE00C(); + RefreshDisplayMon(); PrintDisplayMonInfo(); PrintMessage(MSG_CHANGED_TO_ITEM); sPSSData->state++; @@ -3246,7 +3262,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) } break; case 3: - sub_80D1194(); + MoveItemFromCursorToBag(); sPSSData->state = 4; break; case 4: @@ -3486,14 +3502,14 @@ static void Cb_NameBox(u8 taskId) switch (sPSSData->state) { case 0: - sub_80CE760(); + SaveMovingMon(); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sPSSData->state++; break; case 1: if (!UpdatePaletteFade()) { - sWhichToReshow = 1; + sWhichToReshow = SCREEN_CHANGE_NAME_BOX - 1; sPSSData->screenChangeType = SCREEN_CHANGE_NAME_BOX; SetPSSCallback(Cb_ChangeScreen); } @@ -3506,14 +3522,14 @@ static void Cb_ShowMonSummary(u8 taskId) switch (sPSSData->state) { case 0: - sub_80CE7E8(); + InitSummaryScreenData(); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sPSSData->state++; break; case 1: if (!UpdatePaletteFade()) { - sWhichToReshow = 0; + sWhichToReshow = SCREEN_CHANGE_SUMMARY_SCREEN - 1; sPSSData->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN; SetPSSCallback(Cb_ChangeScreen); } @@ -3532,7 +3548,7 @@ static void Cb_GiveItemFromBag(u8 taskId) case 1: if (!UpdatePaletteFade()) { - sWhichToReshow = 2; + sWhichToReshow = SCREEN_CHANGE_ITEM_FROM_BAG - 1; sPSSData->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG; SetPSSCallback(Cb_ChangeScreen); } @@ -3681,12 +3697,12 @@ static void Cb_ChangeScreen(u8 taskId) SetMainCallback2(Cb2_ExitPSS); break; case SCREEN_CHANGE_SUMMARY_SCREEN: - boxMons = sPSSData->field_218C.box; - monIndex = sPSSData->field_2187; - maxMonIndex = sPSSData->field_2186; + boxMons = sPSSData->summaryMon.box; + monIndex = sPSSData->summaryStartPos; + maxMonIndex = sPSSData->summaryMaxPos; mode = sPSSData->summaryScreenMode; FreePSSData(); - if (mode == SUMMARY_MODE_NORMAL && boxMons == &gUnknown_02039D14.box) + if (mode == SUMMARY_MODE_NORMAL && boxMons == &sSavedMovingMon.box) ShowPokemonSummaryScreenSet40EF(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); else ShowPokemonSummaryScreen(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); @@ -3743,10 +3759,10 @@ static void ScrollBackground(void) static void LoadPSSMenuGfx(void) { - InitBgsFromTemplates(0, gUnknown_08572734, ARRAY_COUNT(gUnknown_08572734)); - DecompressAndLoadBgGfxUsingHeap(1, gPSSMenu_Gfx, 0, 0, 0); - LZ77UnCompWram(gUnknown_085722A0, sPSSData->field_5AC4); - SetBgTilemapBuffer(1, sPSSData->field_5AC4); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); + DecompressAndLoadBgGfxUsingHeap(1, gStorageSystemMenu_Gfx, 0, 0, 0); + LZ77UnCompWram(sDisplayMenu_Tilemap, sPSSData->displayMenuTilemapBuffer); + SetBgTilemapBuffer(1, sPSSData->displayMenuTilemapBuffer); ShowBg(1); ScheduleBgCopyTilemapToVram(1); } @@ -3966,9 +3982,9 @@ static void UpdateWaveformAnimation(void) static void sub_80CA704(void) { - LZ77UnCompWram(gUnknown_08DD36C8, sPSSData->field_B0); - LoadPalette(gPSSMenu_Pal, 0x10, 0x20); - sub_80D2644(1, 1, sPSSData->field_B0, 12, 22); + LZ77UnCompWram(gStorageSystemPartyMenu_Tilemap, sPSSData->partyMenuTilemapBuffer); + LoadPalette(gStorageSystemPartyMenu_Pal, 0x10, 0x20); + sub_80D2644(1, 1, sPSSData->partyMenuTilemapBuffer, 12, 22); sub_80D2644(2, 1, gUnknown_0857245C, 9, 4); sub_80D2770(1, 10, 0); sub_80D2770(2, 21, 0); @@ -3989,29 +4005,29 @@ static void sub_80CA704(void) } ScheduleBgCopyTilemapToVram(1); - sPSSData->unk_02C7 = 0; + sPSSData->closeBoxFlashing = FALSE; } static void SetUpShowPartyMenu(void) { - sPSSData->field_2C0 = 20; - sPSSData->field_2C2 = 2; - sPSSData->field_2C5 = 0; + sPSSData->partyMenuUnused = 20; + sPSSData->partyMenuY = 2; + sPSSData->partyMenuMoveTimer = 0; CreatePartyMonsSprites(FALSE); } static bool8 ShowPartyMenu(void) { - if (sPSSData->field_2C5 == 20) + if (sPSSData->partyMenuMoveTimer == 20) return FALSE; - sPSSData->field_2C0--; - sPSSData->field_2C2++; + sPSSData->partyMenuUnused--; + sPSSData->partyMenuY++; sub_80D27F4(1, 3, 1); sub_80D2918(1); ScheduleBgCopyTilemapToVram(1); - sub_80CBAF0(8); - if (++sPSSData->field_2C5 == 20) + MovePartySprites(8); + if (++sPSSData->partyMenuMoveTimer == 20) { sInPartyMenu = TRUE; return FALSE; @@ -4024,24 +4040,24 @@ static bool8 ShowPartyMenu(void) static void SetUpHidePartyMenu(void) { - sPSSData->field_2C0 = 0; - sPSSData->field_2C2 = 22; - sPSSData->field_2C5 = 0; + sPSSData->partyMenuUnused = 0; + sPSSData->partyMenuY = 22; + sPSSData->partyMenuMoveTimer = 0; if (sPSSData->boxOption == OPTION_MOVE_ITEMS) - sub_80D11CC(); + MoveHeldItemWithPartyMenu(); } static bool8 HidePartyMenu(void) { - if (sPSSData->field_2C5 != 20) + if (sPSSData->partyMenuMoveTimer != 20) { - sPSSData->field_2C0++; - sPSSData->field_2C2--; + sPSSData->partyMenuUnused++; + sPSSData->partyMenuY--; sub_80D27F4(1, 3, -1); sub_80D2918(1); - FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sPSSData->field_2C2, 12, 1); - sub_80CBAF0(-8); - if (++sPSSData->field_2C5 != 20) + FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sPSSData->partyMenuY, 12, 1); + MovePartySprites(-8); + if (++sPSSData->partyMenuMoveTimer != 20) { ScheduleBgCopyTilemapToVram(1); return TRUE; @@ -4061,40 +4077,40 @@ static bool8 HidePartyMenu(void) return FALSE; } -static void sub_80CA984(bool8 arg0) +static void sub_80CA984(bool8 normal) { - if (arg0) + if (normal) sub_80D27AC(2, 0, 0, 9, 2); - else + else // flashing sub_80D27AC(2, 0, 2, 9, 2); sub_80D2918(2); ScheduleBgCopyTilemapToVram(1); } -static void sub_80CA9C0(void) +static void StartFlashingCloseBoxButton(void) { - sPSSData->unk_02C7 = 1; - sPSSData->unk_02C8 = 30; - sPSSData->unk_02C9 = TRUE; + sPSSData->closeBoxFlashing = TRUE; + sPSSData->closeBoxFlashTimer = 30; + sPSSData->closeBoxFlashState = TRUE; } -static void sub_80CA9EC(void) +static void StopFlashingCloseBoxButton(void) { - if (sPSSData->unk_02C7) + if (sPSSData->closeBoxFlashing) { - sPSSData->unk_02C7 = 0; + sPSSData->closeBoxFlashing = FALSE; sub_80CA984(TRUE); } } -static void sub_80CAA14(void) +static void UpdateCloseBoxButtonFlash(void) { - if (sPSSData->unk_02C7 && ++sPSSData->unk_02C8 > 30) + if (sPSSData->closeBoxFlashing && ++sPSSData->closeBoxFlashTimer > 30) { - sPSSData->unk_02C8 = 0; - sPSSData->unk_02C9 = (sPSSData->unk_02C9 == FALSE); - sub_80CA984(sPSSData->unk_02C9); + sPSSData->closeBoxFlashTimer = 0; + sPSSData->closeBoxFlashState = (sPSSData->closeBoxFlashState == FALSE); + sub_80CA984(sPSSData->closeBoxFlashState); } } @@ -4125,9 +4141,8 @@ static void sub_80CAAA8(u8 arg0, bool8 isPartyMon) for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) - { - sPSSData->field_B0[index + j] = data[j]; - } + sPSSData->partyMenuTilemapBuffer[index + j] = data[j]; + data += 4; index += 12; } @@ -4155,7 +4170,7 @@ static bool8 DoShowPartyMenu(void) case 0: if (!ShowPartyMenu()) { - sub_80CDBA0(); + SetCursorInParty(); sPSSData->showPartyMenuState++; } break; @@ -4223,9 +4238,9 @@ static void PrintMessage(u8 id) break; } - DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->field_2190, sMessages[id].text); + DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->messageText, sMessages[id].text); FillWindowPixelBuffer(1, PIXEL_FILL(1)); - AddTextPrinterParameterized(1, 1, sPSSData->field_2190, 0, 1, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(1, 1, sPSSData->messageText, 0, 1, TEXT_SPEED_FF, NULL); DrawTextBorderOuter(1, 2, 14); PutWindowTilemap(1); CopyWindowToVram(1, 2); @@ -4296,17 +4311,17 @@ static u8 GetCurrentBoxOption(void) static void sub_80CAEAC(void) { - if (!IsCursorOnBox()) + if (!IsCursorOnBoxTitle()) { if (sInPartyMenu) - sub_80D0D8C(CURSOR_AREA_IN_PARTY, GetCursorPosition()); + TryLoadItemIconAtPos(CURSOR_AREA_IN_PARTY, GetCursorPosition()); else - sub_80D0D8C(CURSOR_AREA_IN_BOX, GetCursorPosition()); + TryLoadItemIconAtPos(CURSOR_AREA_IN_BOX, GetCursorPosition()); } if (sMovingItemId != ITEM_NONE) { - sub_80D0F38(sMovingItemId); + InitItemIconInCursor(sMovingItemId); StartCursorAnim(CURSOR_ANIM_FIST); } } @@ -4742,7 +4757,7 @@ static void DestroyMovingMonIcon(void) } } -static void sub_80CBAF0(s16 yDelta) +static void MovePartySprites(s16 yDelta) { u16 i, posY; @@ -4792,7 +4807,7 @@ static void SetPartyMonIconObjMode(u8 partyId, u8 objMode) } } -static void sub_80CBC14(u8 mode, u8 id) +static void SetMovingMonSprite(u8 mode, u8 id) { if (mode == MODE_PARTY) { @@ -5104,16 +5119,16 @@ static void SetUpScrollToBox(u8 boxId) s8 direction = DetermineBoxScrollDirection(boxId); sPSSData->scrollSpeed = (direction > 0) ? 6 : -6; - sPSSData->field_2D3 = (direction > 0) ? 1 : 2; - sPSSData->field_2D0 = 32; + sPSSData->scrollUnused1 = (direction > 0) ? 1 : 2; + sPSSData->scrollTimer = 32; sPSSData->scrollToBoxIdUnused = boxId; - sPSSData->field_2D6 = (direction <= 0) ? 5 : 0; + sPSSData->scrollUnused2 = (direction <= 0) ? 5 : 0; sPSSData->scrollDirectionUnused = direction; - sPSSData->field_2DA = (direction > 0) ? 264 : 56; - sPSSData->field_2DC = (direction <= 0) ? 5 : 0; - sPSSData->field_2DE = 0; - sPSSData->field_2E0 = 2; + sPSSData->scrollUnused3 = (direction > 0) ? 264 : 56; + sPSSData->scrollUnused4 = (direction <= 0) ? 5 : 0; + sPSSData->scrollUnused5 = 0; + sPSSData->scrollUnused6 = 2; sPSSData->scrollToBoxId = boxId; sPSSData->scrollDirection = direction; sPSSData->scrollState = 0; @@ -5138,10 +5153,10 @@ static bool8 ScrollToBox(void) break; case 2: var = sub_80CB584(); - if (sPSSData->field_2D0 != 0) + if (sPSSData->scrollTimer != 0) { sPSSData->bg2_X += sPSSData->scrollSpeed; - if (--sPSSData->field_2D0 != 0) + if (--sPSSData->scrollTimer != 0) return TRUE; CycleBoxTitleSprites(); StopBoxScrollArrowsSlide(); @@ -5494,7 +5509,7 @@ static void CreateBoxScrollArrows(void) sPSSData->arrowSprites[i] = sprite; } } - if (IsCursorOnBox()) + if (IsCursorOnBoxTitle()) AnimateBoxScrollArrows(TRUE); } @@ -5632,22 +5647,22 @@ static void sub_80CD36C(void) sMovingMonOrigBoxId = 0; sMovingMonOrigBoxPos = 0; sAutoActionOn = FALSE; - sub_80CDC0C(); - sub_80CFC14(); - sPSSData->field_CD6 = 1; + ClearSavedCursorPos(); + CreateCursorSprites(); + sPSSData->cursorPrevHorizPos = 1; sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; - sub_80CEB40(); + TryRefreshDisplayMon(); } static void sub_80CD3EC(void) { - sub_80CFC14(); + CreateCursorSprites(); sub_80CEBDC(); - sPSSData->field_CD6 = 1; + sPSSData->cursorPrevHorizPos = 1; sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; if (sIsMonBeingMoved) { - sPSSData->movingMon = gUnknown_02039D14; + sPSSData->movingMon = sSavedMovingMon; CreateMovingMonIcon(); } } @@ -5677,7 +5692,7 @@ static void GetCursorCoordsByPos(u8 cursorArea, u8 cursorPosition, u16 *x, u16 * *y = (cursorPosition - 1) * 24 + 4; } break; - case CURSOR_AREA_BOX: + case CURSOR_AREA_BOX_TITLE: *x = 162; *y = 12; break; @@ -5718,104 +5733,116 @@ static bool8 UpdateCursorPos(void) } else if (--sPSSData->cursorMoveSteps != 0) { - sPSSData->field_CBC += sPSSData->field_CC4; - sPSSData->field_CC0 += sPSSData->field_CC8; - sPSSData->cursorSprite->pos1.x = sPSSData->field_CBC >> 8; - sPSSData->cursorSprite->pos1.y = sPSSData->field_CC0 >> 8; + // Update position toward target + sPSSData->cursorNewX += sPSSData->cursorSpeedX; + sPSSData->cursorNewY += sPSSData->cursorSpeedY; + sPSSData->cursorSprite->pos1.x = sPSSData->cursorNewX >> 8; + sPSSData->cursorSprite->pos1.y = sPSSData->cursorNewY >> 8; + + // Limit cursor on right if (sPSSData->cursorSprite->pos1.x > DISPLAY_WIDTH + 16) { tmp = sPSSData->cursorSprite->pos1.x - (DISPLAY_WIDTH + 16); sPSSData->cursorSprite->pos1.x = tmp + 64; } + + // Limit cursor on left if (sPSSData->cursorSprite->pos1.x < 64) { tmp = 64 - sPSSData->cursorSprite->pos1.x; sPSSData->cursorSprite->pos1.x = DISPLAY_WIDTH + 16 - tmp; } + + // Limit cursor on bottom if (sPSSData->cursorSprite->pos1.y > DISPLAY_HEIGHT + 16) { tmp = sPSSData->cursorSprite->pos1.y - (DISPLAY_HEIGHT + 16); sPSSData->cursorSprite->pos1.y = tmp - 16; } + + // Limit cursor on top if (sPSSData->cursorSprite->pos1.y < -16) { tmp = -16 - sPSSData->cursorSprite->pos1.y; sPSSData->cursorSprite->pos1.y = DISPLAY_HEIGHT + 16 - tmp; } - if (sPSSData->field_CD7 && --sPSSData->field_CD7 == 0) + + // Cursor flips vertically when moving on/off the top buttons + if (sPSSData->cursorFlipTimer && --sPSSData->cursorFlipTimer == 0) sPSSData->cursorSprite->vFlip = (sPSSData->cursorSprite->vFlip == FALSE); } else { - sPSSData->cursorSprite->pos1.x = sPSSData->field_CCC; - sPSSData->cursorSprite->pos1.y = sPSSData->field_CCE; - sub_80CDA68(); + // Time is up for cursor movement, make sure it's exactly at target + sPSSData->cursorSprite->pos1.x = sPSSData->cursorTargetX; + sPSSData->cursorSprite->pos1.y = sPSSData->cursorTargetY; + DoCursorNewPosUpdate(); } return TRUE; } -static void sub_80CD6AC(u8 newCursorArea, u8 newCursorPosition) +static void InitNewCursorPos(u8 newCursorArea, u8 newCursorPosition) { u16 x, y; GetCursorCoordsByPos(newCursorArea, newCursorPosition, &x, &y); - sPSSData->field_CD4 = newCursorArea; - sPSSData->field_CD5 = newCursorPosition; - sPSSData->field_CCC = x; - sPSSData->field_CCE = y; + sPSSData->newCursorArea = newCursorArea; + sPSSData->newCursorPosition = newCursorPosition; + sPSSData->cursorTargetX = x; + sPSSData->cursorTargetY = y; } -static void sub_80CD70C(void) +static void InitCursorMove(void) { - int r7, r0; + int yDistance, xDistance; - if (sPSSData->field_CD2 != 0 || sPSSData->field_CD3 != 0) + if (sPSSData->cursorVerticalWrap != 0 || sPSSData->cursorHorizontalWrap != 0) sPSSData->cursorMoveSteps = 12; else sPSSData->cursorMoveSteps = 6; - if (sPSSData->field_CD7) - sPSSData->field_CD7 = sPSSData->cursorMoveSteps >> 1; + if (sPSSData->cursorFlipTimer) + sPSSData->cursorFlipTimer = sPSSData->cursorMoveSteps >> 1; - switch (sPSSData->field_CD2) + switch (sPSSData->cursorVerticalWrap) { - default: - r7 = sPSSData->field_CCE - sPSSData->cursorSprite->pos1.y; + default: // No wrap + yDistance = sPSSData->cursorTargetY - sPSSData->cursorSprite->pos1.y; break; - case -1: - r7 = sPSSData->field_CCE - 0xc0 - sPSSData->cursorSprite->pos1.y; + case -1: // Wrap from top to bottom + yDistance = sPSSData->cursorTargetY - 192 - sPSSData->cursorSprite->pos1.y; break; - case 1: - r7 = sPSSData->field_CCE + 0xc0 - sPSSData->cursorSprite->pos1.y; + case 1: // Wrap from bottom to top + yDistance = sPSSData->cursorTargetY + 192 - sPSSData->cursorSprite->pos1.y; break; } - switch (sPSSData->field_CD3) + switch (sPSSData->cursorHorizontalWrap) { - default: - r0 = sPSSData->field_CCC - sPSSData->cursorSprite->pos1.x; + default: // No Wrap + xDistance = sPSSData->cursorTargetX - sPSSData->cursorSprite->pos1.x; break; - case -1: - r0 = sPSSData->field_CCC - 0xc0 - sPSSData->cursorSprite->pos1.x; + case -1: // Wrap from left to right + xDistance = sPSSData->cursorTargetX - 192 - sPSSData->cursorSprite->pos1.x; break; - case 1: - r0 = sPSSData->field_CCC + 0xc0 - sPSSData->cursorSprite->pos1.x; + case 1: // Wrap from right to left + xDistance = sPSSData->cursorTargetX + 192 - sPSSData->cursorSprite->pos1.x; break; } - r7 <<= 8; - r0 <<= 8; - sPSSData->field_CC4 = r0 / sPSSData->cursorMoveSteps; - sPSSData->field_CC8 = r7 / sPSSData->cursorMoveSteps; - sPSSData->field_CBC = sPSSData->cursorSprite->pos1.x << 8; - sPSSData->field_CC0 = sPSSData->cursorSprite->pos1.y << 8; + yDistance <<= 8; + xDistance <<= 8; + sPSSData->cursorSpeedX = xDistance / sPSSData->cursorMoveSteps; + sPSSData->cursorSpeedY = yDistance / sPSSData->cursorMoveSteps; + sPSSData->cursorNewX = sPSSData->cursorSprite->pos1.x << 8; + sPSSData->cursorNewY = sPSSData->cursorSprite->pos1.y << 8; } -static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) +static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) { - sub_80CD6AC(newCursorArea, newCursorPosition); - sub_80CD70C(); + InitNewCursorPos(newCursorArea, newCursorPosition); + InitCursorMove(); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) @@ -5830,36 +5857,36 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { if (sCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0E50(CURSOR_AREA_IN_BOX, sCursorPosition); + TryHideItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); else if (sCursorArea == CURSOR_AREA_IN_PARTY) - sub_80D0E50(CURSOR_AREA_IN_PARTY, sCursorPosition); + TryHideItemIconAtPos(CURSOR_AREA_IN_PARTY, sCursorPosition); if (newCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0D8C(newCursorArea, newCursorPosition); + TryLoadItemIconAtPos(newCursorArea, newCursorPosition); else if (newCursorArea == CURSOR_AREA_IN_PARTY) - sub_80D0D8C(newCursorArea, newCursorPosition); + TryLoadItemIconAtPos(newCursorArea, newCursorPosition); } if (newCursorArea == CURSOR_AREA_IN_PARTY && sCursorArea != CURSOR_AREA_IN_PARTY) { - sPSSData->field_CD6 = newCursorArea; - sPSSData->field_CB8->invisible = TRUE; + sPSSData->cursorPrevHorizPos = 1; + sPSSData->cursorShadowSprite->invisible = TRUE; } switch (newCursorArea) { case CURSOR_AREA_IN_PARTY: - case CURSOR_AREA_BOX: + case CURSOR_AREA_BOX_TITLE: case CURSOR_AREA_BUTTONS: sPSSData->cursorSprite->oam.priority = 1; - sPSSData->field_CB8->invisible = TRUE; - sPSSData->field_CB8->oam.priority = 1; + sPSSData->cursorShadowSprite->invisible = TRUE; + sPSSData->cursorShadowSprite->oam.priority = 1; break; case CURSOR_AREA_IN_BOX: if (sPSSData->inBoxMovingMode != MOVE_MODE_NORMAL) { sPSSData->cursorSprite->oam.priority = 0; - sPSSData->field_CB8->invisible = TRUE; + sPSSData->cursorShadowSprite->invisible = TRUE; } else { @@ -5871,10 +5898,10 @@ static void sub_80CD894(u8 newCursorArea, u8 newCursorPosition) } } -static void sub_80CDA68(void) +static void DoCursorNewPosUpdate(void) { - sCursorArea = sPSSData->field_CD4; - sCursorPosition = sPSSData->field_CD5; + sCursorArea = sPSSData->newCursorArea; + sCursorPosition = sPSSData->newCursorPosition; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) @@ -5886,33 +5913,33 @@ static void sub_80CDA68(void) StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); } - sub_80CEB40(); + TryRefreshDisplayMon(); switch (sCursorArea) { case CURSOR_AREA_BUTTONS: SetMovingMonPriority(1); break; - case CURSOR_AREA_BOX: + case CURSOR_AREA_BOX_TITLE: AnimateBoxScrollArrows(TRUE); break; case CURSOR_AREA_IN_PARTY: - sPSSData->field_CB8->subpriority = 13; + sPSSData->cursorShadowSprite->subpriority = 13; SetMovingMonPriority(1); break; case CURSOR_AREA_IN_BOX: if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) { sPSSData->cursorSprite->oam.priority = 1; - sPSSData->field_CB8->oam.priority = 2; - sPSSData->field_CB8->subpriority = 21; - sPSSData->field_CB8->invisible = FALSE; + sPSSData->cursorShadowSprite->oam.priority = 2; + sPSSData->cursorShadowSprite->subpriority = 21; + sPSSData->cursorShadowSprite->invisible = FALSE; SetMovingMonPriority(2); } break; } } -static void sub_80CDBA0(void) +static void SetCursorInParty(void) { u8 partyCount; @@ -5927,30 +5954,30 @@ static void sub_80CDBA0(void) partyCount = PARTY_SIZE - 1; } if (sPSSData->cursorSprite->vFlip) - sPSSData->field_CD7 = 1; - sub_80CD894(CURSOR_AREA_IN_PARTY, partyCount); + sPSSData->cursorFlipTimer = 1; + SetCursorPosition(CURSOR_AREA_IN_PARTY, partyCount); } -static void sub_80CDBF8(u8 cursorBoxPosition) +static void SetCursorBoxPosition(u8 cursorBoxPosition) { - sub_80CD894(CURSOR_AREA_IN_BOX, cursorBoxPosition); + SetCursorPosition(CURSOR_AREA_IN_BOX, cursorBoxPosition); } -EWRAM_DATA static u8 gUnknown_02039D7E = 0; +EWRAM_DATA static u8 sSavedCursorPosition = 0; -static void sub_80CDC0C(void) +static void ClearSavedCursorPos(void) { - gUnknown_02039D7E = 0; + sSavedCursorPosition = 0; } -static void sub_80CDC18(void) +static void SaveCursorPos(void) { - gUnknown_02039D7E = sCursorPosition; + sSavedCursorPosition = sCursorPosition; } -static u8 sub_80CDC2C(void) +static u8 GetSavedCursorPos(void) { - return gUnknown_02039D7E; + return sSavedCursorPosition; } static void InitMonPlaceChange(u8 a0) @@ -6117,14 +6144,14 @@ static void MoveMon(void) switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); - sub_80CBC14(MODE_PARTY, sCursorPosition); + SetMovingMonData(TOTAL_BOXES_COUNT, sCursorPosition); + SetMovingMonSprite(MODE_PARTY, sCursorPosition); break; case CURSOR_AREA_IN_BOX: if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) { - SetMovedMonData(StorageGetCurrentBox(), sCursorPosition); - sub_80CBC14(MODE_BOX, sCursorPosition); + SetMovingMonData(StorageGetCurrentBox(), sCursorPosition); + SetMovingMonSprite(MODE_BOX, sCursorPosition); } break; default: @@ -6156,12 +6183,12 @@ static void PlaceMon(void) sIsMonBeingMoved = FALSE; } -static void sub_80CE00C(void) +static void RefreshDisplayMon(void) { - sub_80CEB40(); + TryRefreshDisplayMon(); } -static void SetMovedMonData(u8 boxId, u8 position) +static void SetMovingMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) sPSSData->movingMon = gPlayerParty[sCursorPosition]; @@ -6222,7 +6249,7 @@ static bool8 TryStorePartyMonInBox(u8 boxId) } else { - SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + SetMovingMonData(TOTAL_BOXES_COUNT, sCursorPosition); SetPlacedMonData(boxId, boxPosition); DestroyPartyMonIcon(sCursorPosition); } @@ -6237,7 +6264,7 @@ static bool8 TryStorePartyMonInBox(u8 boxId) static void sub_80CE22C(void) { StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); - sub_80CEB40(); + TryRefreshDisplayMon(); } static void InitReleaseMon(void) @@ -6286,7 +6313,7 @@ static void ReleaseMon(void) PurgeMonOrBoxMon(boxId, sCursorPosition); } - sub_80CEB40(); + TryRefreshDisplayMon(); } static void TrySetCursorFistAnim(void) @@ -6489,45 +6516,45 @@ static s8 RunCanReleaseMon(void) return -1; } -static void sub_80CE760(void) +static void SaveMovingMon(void) { if (sIsMonBeingMoved) - gUnknown_02039D14 = sPSSData->movingMon; + sSavedMovingMon = sPSSData->movingMon; } -static void sub_80CE790(void) +static void LoadSavedMovingMon(void) { if (sIsMonBeingMoved) { if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT) - sPSSData->movingMon = gUnknown_02039D14; + sPSSData->movingMon = sSavedMovingMon; else - sPSSData->movingMon.box = gUnknown_02039D14.box; + sPSSData->movingMon.box = sSavedMovingMon.box; } } -static void sub_80CE7E8(void) +static void InitSummaryScreenData(void) { if (sIsMonBeingMoved) { - sub_80CE760(); - sPSSData->field_218C.mon = &gUnknown_02039D14; - sPSSData->field_2187 = 0; - sPSSData->field_2186 = 0; + SaveMovingMon(); + sPSSData->summaryMon.mon = &sSavedMovingMon; + sPSSData->summaryStartPos = 0; + sPSSData->summaryMaxPos = 0; sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } else if (sCursorArea == CURSOR_AREA_IN_PARTY) { - sPSSData->field_218C.mon = gPlayerParty; - sPSSData->field_2187 = sCursorPosition; - sPSSData->field_2186 = CountPartyMons() - 1; + sPSSData->summaryMon.mon = gPlayerParty; + sPSSData->summaryStartPos = sCursorPosition; + sPSSData->summaryMaxPos = CountPartyMons() - 1; sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; } else { - sPSSData->field_218C.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); - sPSSData->field_2187 = sCursorPosition; - sPSSData->field_2186 = IN_BOX_COUNT - 1; + sPSSData->summaryMon.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); + sPSSData->summaryStartPos = sCursorPosition; + sPSSData->summaryMaxPos = IN_BOX_COUNT - 1; sPSSData->summaryScreenMode = SUMMARY_MODE_BOX; } } @@ -6535,7 +6562,7 @@ static void sub_80CE7E8(void) static void sub_80CE8E4(void) { if (sIsMonBeingMoved) - sub_80CE790(); + LoadSavedMovingMon(); else sCursorPosition = gLastViewedMonIndex; } @@ -6608,9 +6635,9 @@ static bool8 IsMonBeingMoved(void) return sIsMonBeingMoved; } -static bool8 IsCursorOnBox(void) +static bool8 IsCursorOnBoxTitle(void) { - return (sCursorArea == CURSOR_AREA_BOX); + return (sCursorArea == CURSOR_AREA_BOX_TITLE); } static bool8 IsCursorOnCloseBox(void) @@ -6623,11 +6650,15 @@ static bool8 IsCursorInBox(void) return (sCursorArea == CURSOR_AREA_IN_BOX); } -static void sub_80CEB40(void) +static void TryRefreshDisplayMon(void) { + // If a Pokémon is currently being moved, don't start + // mosaic or update display. Keep displaying the + // currently held Pokémon. sPSSData->setMosaic = (sIsMonBeingMoved == FALSE); if (!sIsMonBeingMoved) { + // Update display Pokémon switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: @@ -6638,7 +6669,7 @@ static void sub_80CEB40(void) } // fallthrough case CURSOR_AREA_BUTTONS: - case CURSOR_AREA_BOX: + case CURSOR_AREA_BOX_TITLE: SetDisplayMonData(NULL, MODE_MOVE); break; case CURSOR_AREA_IN_BOX: @@ -6651,9 +6682,9 @@ static void sub_80CEB40(void) static void sub_80CEBDC(void) { if (sIsMonBeingMoved) - SetDisplayMonData(&gUnknown_02039D14, MODE_PARTY); + SetDisplayMonData(&sSavedMovingMon, MODE_PARTY); else - sub_80CEB40(); + TryRefreshDisplayMon(); } static void SetDisplayMonData(void *pokemon, u8 mode) @@ -6770,7 +6801,7 @@ static void SetDisplayMonData(void *pokemon, u8 mode) *(txtPtr)++ = TEXT_COLOR_DARK_GRAY; *(txtPtr)++ = TEXT_COLOR_WHITE; *(txtPtr)++ = TEXT_COLOR_LIGHT_GRAY; - *(txtPtr)++ = CHAR_UNK_SPACER; + *(txtPtr)++ = CHAR_GENDERLESS; break; } @@ -6818,70 +6849,70 @@ static u8 InBoxInput_Normal(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->field_CD2 = 0; - sPSSData->field_CD3 = 0; - sPSSData->field_CD7 = 0; + sPSSData->cursorVerticalWrap = 0; + sPSSData->cursorHorizontalWrap = 0; + sPSSData->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; if (sCursorPosition >= IN_BOX_COLUMNS) { cursorPosition -= IN_BOX_COLUMNS; } else { - cursorArea = CURSOR_AREA_BOX; + cursorArea = CURSOR_AREA_BOX_TITLE; cursorPosition = 0; } break; } else if (JOY_REPEAT(DPAD_DOWN)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; cursorPosition += IN_BOX_COLUMNS; if (cursorPosition >= IN_BOX_COUNT) { cursorArea = CURSOR_AREA_BUTTONS; cursorPosition -= IN_BOX_COUNT; cursorPosition /= 3; - sPSSData->field_CD2 = 1; - sPSSData->field_CD7 = 1; + sPSSData->cursorVerticalWrap = 1; + sPSSData->cursorFlipTimer = 1; } break; } else if (JOY_REPEAT(DPAD_LEFT)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; if (sCursorPosition % IN_BOX_COLUMNS != 0) { cursorPosition--; } else { - sPSSData->field_CD3 = -1; + sPSSData->cursorHorizontalWrap = -1; cursorPosition += (IN_BOX_COLUMNS - 1); } break; } else if (JOY_REPEAT(DPAD_RIGHT)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) { cursorPosition++; } else { - sPSSData->field_CD3 = 1; + sPSSData->cursorHorizontalWrap = 1; cursorPosition -= (IN_BOX_COLUMNS - 1); } break; } else if (JOY_NEW(START_BUTTON)) { - retVal = INPUT_1; - cursorArea = CURSOR_AREA_BOX; + retVal = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_BOX_TITLE; cursorPosition = 0; break; } @@ -6942,7 +6973,7 @@ static u8 InBoxInput_Normal(void) } while (0); if (retVal) - sub_80CD894(cursorArea, cursorPosition); + SetCursorPosition(cursorArea, cursorPosition); return retVal; } @@ -6955,7 +6986,7 @@ static u8 InBoxInput_SelectingMultiple(void) { if (sCursorPosition / IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); return INPUT_MULTIMOVE_CHANGE_SELECTION; } else @@ -6967,7 +6998,7 @@ static u8 InBoxInput_SelectingMultiple(void) { if (sCursorPosition + IN_BOX_COLUMNS < IN_BOX_COUNT) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); return INPUT_MULTIMOVE_CHANGE_SELECTION; } else @@ -6979,7 +7010,7 @@ static u8 InBoxInput_SelectingMultiple(void) { if (sCursorPosition % IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - 1); return INPUT_MULTIMOVE_CHANGE_SELECTION; } else @@ -6991,7 +7022,7 @@ static u8 InBoxInput_SelectingMultiple(void) { if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + 1); return INPUT_MULTIMOVE_CHANGE_SELECTION; } else @@ -7010,7 +7041,7 @@ static u8 InBoxInput_SelectingMultiple(void) { // Doing a multiple mon selection but only chose 1 mon sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; - sPSSData->field_CB8->invisible = FALSE; + sPSSData->cursorShadowSprite->invisible = FALSE; return INPUT_MULTIMOVE_SINGLE; } else @@ -7029,7 +7060,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (MultiMove_TryMoveGroup(0)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); return INPUT_MULTIMOVE_MOVE_MONS; } else @@ -7041,7 +7072,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (MultiMove_TryMoveGroup(1)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); return INPUT_MULTIMOVE_MOVE_MONS; } else @@ -7053,7 +7084,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (MultiMove_TryMoveGroup(2)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - 1); return INPUT_MULTIMOVE_MOVE_MONS; } else @@ -7065,7 +7096,7 @@ static u8 InBoxInput_MovingMultiple(void) { if (MultiMove_TryMoveGroup(3)) { - sub_80CD894(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + 1); return INPUT_MULTIMOVE_MOVE_MONS; } else @@ -7115,9 +7146,9 @@ static u8 HandleInput_InParty(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; + sPSSData->cursorHorizontalWrap = 0; + sPSSData->cursorVerticalWrap = 0; + sPSSData->cursorFlipTimer = 0; gotoBox = FALSE; retVal = INPUT_NONE; @@ -7126,7 +7157,7 @@ static u8 HandleInput_InParty(void) if (--cursorPosition < 0) cursorPosition = PARTY_SIZE; if (cursorPosition != sCursorPosition) - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; break; } else if (JOY_REPEAT(DPAD_DOWN)) @@ -7134,13 +7165,13 @@ static u8 HandleInput_InParty(void) if (++cursorPosition > PARTY_SIZE) cursorPosition = 0; if (cursorPosition != sCursorPosition) - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; break; } else if (JOY_REPEAT(DPAD_LEFT) && sCursorPosition != 0) { - retVal = INPUT_1; - sPSSData->field_CD6 = sCursorPosition; + retVal = INPUT_MOVE_CURSOR; + sPSSData->cursorPrevHorizPos = sCursorPosition; cursorPosition = 0; break; } @@ -7148,8 +7179,8 @@ static u8 HandleInput_InParty(void) { if (sCursorPosition == 0) { - retVal = INPUT_1; - cursorPosition = sPSSData->field_CD6; + retVal = INPUT_MOVE_CURSOR; + cursorPosition = sPSSData->cursorPrevHorizPos; } else { @@ -7221,7 +7252,7 @@ static u8 HandleInput_InParty(void) if (retVal != INPUT_NONE) { if (retVal != INPUT_HIDE_PARTY) - sub_80CD894(cursorArea, cursorPosition); + SetCursorPosition(cursorArea, cursorPosition); } return retVal; @@ -7235,21 +7266,21 @@ static u8 HandleInput_OnBox(void) do { - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; + sPSSData->cursorHorizontalWrap = 0; + sPSSData->cursorVerticalWrap = 0; + sPSSData->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_BUTTONS; cursorPosition = 0; - sPSSData->field_CD7 = 1; + sPSSData->cursorFlipTimer = 1; break; } else if (JOY_REPEAT(DPAD_DOWN)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 2; break; @@ -7290,9 +7321,9 @@ static u8 HandleInput_OnBox(void) if (retVal != INPUT_NONE) { - if (cursorArea != CURSOR_AREA_BOX) + if (cursorArea != CURSOR_AREA_BOX_TITLE) AnimateBoxScrollArrows(FALSE); - sub_80CD894(cursorArea, cursorPosition); + SetCursorPosition(cursorArea, cursorPosition); } return retVal; @@ -7308,42 +7339,42 @@ static u8 HandleInput_OnButtons(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; + sPSSData->cursorHorizontalWrap = 0; + sPSSData->cursorVerticalWrap = 0; + sPSSData->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_IN_BOX; - sPSSData->field_CD2 = -1; + sPSSData->cursorVerticalWrap = -1; if (sCursorPosition == 0) cursorPosition = IN_BOX_COUNT - 1 - 5; else cursorPosition = IN_BOX_COUNT - 1; - sPSSData->field_CD7 = 1; + sPSSData->cursorFlipTimer = 1; break; } if (JOY_REPEAT(DPAD_DOWN | START_BUTTON)) { - retVal = INPUT_1; - cursorArea = CURSOR_AREA_BOX; + retVal = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_BOX_TITLE; cursorPosition = 0; - sPSSData->field_CD7 = 1; + sPSSData->cursorFlipTimer = 1; break; } if (JOY_REPEAT(DPAD_LEFT)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; if (--cursorPosition < 0) cursorPosition = 1; break; } else if (JOY_REPEAT(DPAD_RIGHT)) { - retVal = INPUT_1; + retVal = INPUT_MOVE_CURSOR; if (++cursorPosition > 1) cursorPosition = 0; break; @@ -7366,7 +7397,7 @@ static u8 HandleInput_OnButtons(void) } while (0); if (retVal != INPUT_NONE) - sub_80CD894(cursorArea, cursorPosition); + SetCursorPosition(cursorArea, cursorPosition); return retVal; } @@ -7381,7 +7412,7 @@ static u8 HandleInput(void) { {HandleInput_InBox, CURSOR_AREA_IN_BOX}, {HandleInput_InParty, CURSOR_AREA_IN_PARTY}, - {HandleInput_OnBox, CURSOR_AREA_BOX}, + {HandleInput_OnBox, CURSOR_AREA_BOX_TITLE}, {HandleInput_OnButtons, CURSOR_AREA_BUTTONS}, {}, }; @@ -7521,7 +7552,7 @@ static void SpriteCB_CursorShadow(struct Sprite *sprite) sprite->pos1.y = sPSSData->cursorSprite->pos1.y + 20; } -static void sub_80CFC14(void) +static void CreateCursorSprites(void) { u16 x, y; u8 spriteId; @@ -7638,14 +7669,14 @@ static void sub_80CFC14(void) spriteId = CreateSprite(&sSpriteTemplate_CursorShadow, 0, 0, subpriority); if (spriteId != MAX_SPRITES) { - sPSSData->field_CB8 = &gSprites[spriteId]; - sPSSData->field_CB8->oam.priority = priority; + sPSSData->cursorShadowSprite = &gSprites[spriteId]; + sPSSData->cursorShadowSprite->oam.priority = priority; if (sCursorArea) - sPSSData->field_CB8->invisible = 1; + sPSSData->cursorShadowSprite->invisible = TRUE; } else { - sPSSData->field_CB8 = NULL; + sPSSData->cursorShadowSprite = NULL; } } @@ -7689,16 +7720,16 @@ static void SetCursorPriorityTo1(void) sPSSData->cursorSprite->oam.priority = 1; } -static void sub_80CFEA8(void) +static void TryHideItemAtCursor(void) { if (sCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0E50(CURSOR_AREA_IN_BOX, sCursorPosition); + TryHideItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); } -static void sub_80CFECC(void) +static void TryShowItemAtCursor(void) { if (sCursorArea == CURSOR_AREA_IN_BOX) - sub_80D0D8C(CURSOR_AREA_IN_BOX, sCursorPosition); + TryLoadItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); } static void InitMenu(void) @@ -7790,7 +7821,7 @@ static void AddMenu(void) PrintMenuTable(sPSSData->menuWindowId, sPSSData->menuItemsCount, (void*)sPSSData->menuItems); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sPSSData->menuWindowId, sPSSData->menuItemsCount, 0); ScheduleBgCopyTilemapToVram(0); - sPSSData->field_CAE = 0; + sPSSData->menuUnusedField = 0; } // Called after AddMenu to determine whether or not the handler callback should @@ -7847,7 +7878,7 @@ static void RemoveMenu(void) //------------------------------------------------------------------------------ -// MultiMove +// SECTION: MultiMove // // The functions below handle moving and selecting multiple Pokémon at once. // The icon sprites are moved to bg 0, and this bg is manipulated to move @@ -8405,24 +8436,13 @@ static bool8 MultiMove_CanPlaceSelection(void) return TRUE; } -// The functions below handle new features of MOVE_ITEMS box option. -static bool32 IsItemIconAtPosition(u8, u8); -static const u32 *GetItemIconPic(u16); -static const u32 *GetItemIconPalette(u16); -static u8 GetNewItemIconIdx(void); -static void SetItemIconPosition(u8, u8, u8); -static void LoadItemIconGfx(u8, const u32 *, const u32 *); -static void SetItemIconAffineAnim(u8, u8); -static void SetItemIconActive(u8, bool8); -static u8 GetItemIconIdxByPosition(u8, u8); -static void SetItemIconCallback(u8, u8, u8, u8); -static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *); -static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *); -static void SpriteCB_ItemIcon_ToHand(struct Sprite *); -static void SpriteCB_ItemIcon_ToMon(struct Sprite *); -static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *); -static void SpriteCB_ItemIcon_HideParty(struct Sprite *); -static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *); + +//------------------------------------------------------------------------------ +// SECTION: Item mode +// +// The functions below handle the Move Items mode +//------------------------------------------------------------------------------ + static const u32 sItemInfoFrame_Gfx[] = INCBIN_U32("graphics/pokemon_storage/item_info_frame.4bpp"); @@ -8546,7 +8566,7 @@ static void CreateItemIconSprites(void) sPSSData->movingItemId = ITEM_NONE; } -static void sub_80D0D8C(u8 cursorArea, u8 cursorPos) +static void TryLoadItemIconAtPos(u8 cursorArea, u8 cursorPos) { u16 heldItem; @@ -8586,7 +8606,7 @@ static void sub_80D0D8C(u8 cursorArea, u8 cursorPos) } } -static void sub_80D0E50(u8 cursorArea, u8 cursorPos) +static void TryHideItemIconAtPos(u8 cursorArea, u8 cursorPos) { u8 id; @@ -8598,7 +8618,7 @@ static void sub_80D0E50(u8 cursorArea, u8 cursorPos) SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); } -static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) +static void TakeItemFromMon(u8 cursorArea, u8 cursorPos) { u8 id; u16 itemId; @@ -8625,7 +8645,7 @@ static void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) sPSSData->movingItemId = sPSSData->displayMonItemId; } -static void sub_80D0F38(u16 itemId) +static void InitItemIconInCursor(u16 itemId) { const u32 *tiles = GetItemIconPic(itemId); const u32 *pal = GetItemIconPalette(itemId); @@ -8638,7 +8658,7 @@ static void sub_80D0F38(u16 itemId) sPSSData->movingItemId = itemId; } -static void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) +static void SwapItemsWithMon(u8 cursorArea, u8 cursorPos) { u8 id; u16 itemId; @@ -8667,7 +8687,7 @@ static void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) SetItemIconCallback(id, ITEM_CB_SWAP_TO_MON, cursorArea, cursorPos); } -static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) +static void GiveItemToMon(u8 cursorArea, u8 cursorPos) { u8 id; @@ -8689,31 +8709,31 @@ static void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) } } -static void Item_TakeMons(u8 cursorArea, u8 cursorPos) +static void MoveItemFromMonToBag(u8 cursorArea, u8 cursorPos) { u8 id; - u16 item; + u16 itemId; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) return; - item = 0; + itemId = ITEM_NONE; id = GetItemIconIdxByPosition(cursorArea, cursorPos); SetItemIconAffineAnim(id, ITEM_ANIM_DISAPPEAR); SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); if (cursorArea == CURSOR_AREA_IN_BOX) { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &itemId); SetBoxMonIconObjMode(cursorPos, 1); } else { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &itemId); SetPartyMonIconObjMode(cursorPos, 1); } } -static void sub_80D1194(void) +static void MoveItemFromCursorToBag(void) { if (sPSSData->boxOption == OPTION_MOVE_ITEMS) { @@ -8723,7 +8743,10 @@ static void sub_80D1194(void) } } -static void sub_80D11CC(void) +// The party menu is being closed, if the cursor is on +// a Pokémon that has a held item make sure it slides +// up along with the closing menu. +static void MoveHeldItemWithPartyMenu(void) { s32 i; @@ -9171,14 +9194,16 @@ static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite) #undef sCursorArea #undef sCursorPos -static void ItemIconDummy_1(void) +// Unused, leftover from FRLG +static void BackupPokemonStorage(void/*struct PokemonStorage * dest*/) { - + //*dest = *gPokemonStoragePtr; } -static void ItemIconDummy_2(void) +// Unused, leftover from FRLG +static void RestorePokemonStorage(void/*struct PokemonStorage * src*/) { - + //*gPokemonStoragePtr = *src; } // Functions here are general utility functions. @@ -9320,17 +9345,18 @@ static void SetBoxWallpaper(u8 boxId, u8 wallpaperId) gPokemonStoragePtr->boxWallpapers[boxId] = wallpaperId; } -s16 sub_80D214C(struct BoxPokemon *boxMons, u8 currIndex, u8 maxIndex, u8 arg3) +// For moving to the next Pokémon while viewing the summary screen +s16 AdvanceStorageMonIndex(struct BoxPokemon *boxMons, u8 currIndex, u8 maxIndex, u8 mode) { s16 i; - s16 adder = -1; + s16 direction = -1; - if (arg3 < 2) - adder = 1; + if (mode == 0 || mode == 1) + direction = 1; - if (arg3 == 1 || arg3 == 3) + if (mode == 1 || mode == 3) { - for (i = (s8)currIndex + adder; i >= 0 && i <= maxIndex; i += adder) + for (i = (s8)currIndex + direction; i >= 0 && i <= maxIndex; i += direction) { if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE) return i; @@ -9338,7 +9364,7 @@ s16 sub_80D214C(struct BoxPokemon *boxMons, u8 currIndex, u8 maxIndex, u8 arg3) } else { - for (i = (s8)currIndex + adder; i >= 0 && i <= maxIndex; i += adder) + for (i = (s8)currIndex + direction; i >= 0 && i <= maxIndex; i += direction) { if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetBoxMonData(&boxMons[i], MON_DATA_IS_EGG)) -- cgit v1.2.3 From 1c3e387d43e0e9afad23b2bc5d187524b5a45461 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 14:33:00 -0400 Subject: Doc storage - party menu --- src/pokemon_storage_system.c | 120 ++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 52 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 2db3e67cd..8b07c17b5 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -435,7 +435,7 @@ struct PokemonStorageSystemData u32 boxPersonalities[IN_BOX_COUNT]; u8 field_C5C; u8 field_C5D; - u8 field_C5E; + u8 numPartyToCompact; u16 field_C60; s16 field_C62; s16 field_C64; @@ -578,7 +578,7 @@ static void Cb2_EnterPSS(u8); static u8 GetCurrentBoxOption(void); static u8 HandleInput(void); static u8 GetSavedCursorPos(void); -static u8 sub_80CB9BC(void); +static u8 GetNumPartySpritesCompacting(void); static void LoadWallpaperGfx(u8, s8); static void CreateIncomingBoxTitle(u8, s8); static void StartBoxScrollArrowsSlide(s8); @@ -640,7 +640,7 @@ static void TryRefreshDisplayMon(void); static void CycleBoxTitleSprites(void); static void InitItemInfoWindow(void); static void DrawItemInfoWindow(u32); -static void sub_80CAA74(void); +static void SetPartySlotTilemaps(void); static void PrintItemDescription(void); static void SaveMovingMon(void); static void SetCursorInParty(void); @@ -655,7 +655,7 @@ static void PlaceMon(void); static void sub_80CAB20(void); static void sub_80CE22C(void); static void DoCursorNewPosUpdate(void); -static void sub_80CB950(void); +static void CompactPartySprites(void); static void StartFlashingCloseBoxButton(void); static void SetUpDoShowPartyMenu(void); static void StartDisplayMonMosaicEffect(void); @@ -745,10 +745,10 @@ static u16 GetMovingItemId(void); static void LoadDisplayMonGfx(u16, u32); static void SpriteCB_DisplayMonMosaic(struct Sprite *); static void SpriteCB_OutgoingBoxTitle(struct Sprite *); -static void sub_80CBA3C(struct Sprite *); +static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *); static void SpriteCB_IncomingBoxTitle(struct Sprite *); static void MovePartySprites(s16); -static void sub_80CAAA8(u8, bool8); +static void SetPartySlotTilemap(u8, bool8); static const u8 *GetMovingItemName(void); static void SetMenuText(u8); static void TryLoadItemIconAtPos(u8, u8); @@ -757,7 +757,7 @@ static void InitItemIconInCursor(u16); static struct Sprite *CreateMonIconSprite(u16, u32, s16, s16, u8, u8); static void DestroyBoxMonIcon(struct Sprite *); static void SetBoxSpeciesAndPersonalities(u8); -static void sub_80CB9D0(struct Sprite *, u16); +static void MovePartySpriteToNextSlot(struct Sprite *, u16); static void Task_InitBox(u8); static void InitBoxTitle(u8); static s8 DetermineBoxScrollDirection(u8); @@ -935,17 +935,17 @@ static const u16 gUnknown_085723FC[] = INCBIN_U16("graphics/unknown/unknown_5723 static const u16 gUnknown_0857241C[] = INCBIN_U16("graphics/unknown/unknown_57241C.gbapal"); static const u16 gUnknown_0857243C[] = INCBIN_U16("graphics/unknown/unknown_57243C.gbapal"); -static const u16 gUnknown_0857245C[] = +static const u16 sCloseBoxButton_Tilemap[] = { 0x014c, 0x014d, 0x014e, 0x014f, 0x0170, 0x0171, 0x0172, 0x0173, 0x0174, 0x015c, 0x015d, 0x015e, 0x015f, 0x0180, 0x0181, 0x0182, 0x0183, 0x0184, 0x0175, 0x0176, 0x0177, 0x0178, 0x0179, 0x017a, 0x017b, 0x017c, 0x017d, 0x0185, 0x0186, 0x0187, 0x0188, 0x0189, 0x018a, 0x018b, 0x018c, 0x018d }; -static const u16 gUnknown_085724A4[] = +static const u16 sPartySlotFilled_Tilemap[] = { 0x1140, 0x1141, 0x1141, 0x1142, 0x1150, 0x1151, 0x1151, 0x1152, 0x1160, 0x1161, 0x1161, 0x1162, }; -static const u16 gUnknown_085724BC[] = +static const u16 sPartySlotEmpty_Tilemap[] = { 0x1143, 0x1144, 0x1144, 0x1145, 0x1153, 0x1154, 0x1154, 0x1155, 0x1163, 0x1164, 0x1164, 0x1165, }; @@ -2837,11 +2837,11 @@ static void Cb_DepositMenu(u8 taskId) break; case 2: CompactPartySlots(); - sub_80CB950(); + CompactPartySprites(); sPSSData->state++; break; case 3: - if (!sub_80CB9BC()) + if (GetNumPartySpritesCompacting() == 0) { sub_80CE22C(); StartDisplayMonMosaicEffect(); @@ -2924,7 +2924,7 @@ static void Cb_ReleaseMon(u8 taskId) if (sInPartyMenu) { CompactPartySlots(); - sub_80CB950(); + CompactPartySprites(); sPSSData->state++; } else @@ -2934,7 +2934,7 @@ static void Cb_ReleaseMon(u8 taskId) } break; case 6: - if (!sub_80CB9BC()) + if (GetNumPartySpritesCompacting() == 0) { RefreshDisplayMon(); StartDisplayMonMosaicEffect(); @@ -3285,11 +3285,11 @@ static void Cb_HandleMovingMonFromParty(u8 taskId) { case 0: CompactPartySlots(); - sub_80CB950(); + CompactPartySprites(); sPSSData->state++; break; case 1: - if (!sub_80CB9BC()) + if (GetNumPartySpritesCompacting() == 0) { sub_80CAB20(); SetPSSCallback(Cb_MainPSS); @@ -3985,10 +3985,10 @@ static void sub_80CA704(void) LZ77UnCompWram(gStorageSystemPartyMenu_Tilemap, sPSSData->partyMenuTilemapBuffer); LoadPalette(gStorageSystemPartyMenu_Pal, 0x10, 0x20); sub_80D2644(1, 1, sPSSData->partyMenuTilemapBuffer, 12, 22); - sub_80D2644(2, 1, gUnknown_0857245C, 9, 4); + sub_80D2644(2, 1, sCloseBoxButton_Tilemap, 9, 4); sub_80D2770(1, 10, 0); sub_80D2770(2, 21, 0); - sub_80CAA74(); + SetPartySlotTilemaps(); if (sInPartyMenu) { sub_80CA984(TRUE); @@ -4114,28 +4114,30 @@ static void UpdateCloseBoxButtonFlash(void) } } -static void sub_80CAA74(void) +static void SetPartySlotTilemaps(void) { u8 i; + // Skips first party slot, it should always be drawn + // as if it has a Pokémon in it for (i = 1; i < PARTY_SIZE; i++) { s32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); - sub_80CAAA8(i, (species != SPECIES_NONE)); + SetPartySlotTilemap(i, species != SPECIES_NONE); } } -static void sub_80CAAA8(u8 arg0, bool8 isPartyMon) +static void SetPartySlotTilemap(u8 partyId, bool8 hasMon) { u16 i, j, index; const u16 *data; - if (isPartyMon) - data = gUnknown_085724A4; + if (hasMon) + data = sPartySlotFilled_Tilemap; else - data = gUnknown_085724BC; + data = sPartySlotEmpty_Tilemap; - index = 3 * (3 * (arg0 - 1) + 1); + index = 3 * (3 * (partyId - 1) + 1); index *= 4; index += 7; for (i = 0; i < 3; i++) @@ -4150,7 +4152,7 @@ static void sub_80CAAA8(u8 arg0, bool8 isPartyMon) static void sub_80CAB20(void) { - sub_80CAA74(); + SetPartySlotTilemaps(); sub_80D27AC(1, 0, 0, 12, 22); sub_80D2918(1); ScheduleBgCopyTilemapToVram(1); @@ -4677,62 +4679,69 @@ static void CreatePartyMonsSprites(bool8 arg0) } } -static void sub_80CB950(void) +static void CompactPartySprites(void) { - u16 i, count; + u16 i, targetSlot; - sPSSData->field_C5E = 0; - for (i = 0, count = 0; i < PARTY_SIZE; i++) + sPSSData->numPartyToCompact = 0; + for (i = 0, targetSlot = 0; i < PARTY_SIZE; i++) { if (sPSSData->partySprites[i] != NULL) { - if (i != count) + if (i != targetSlot) { - sub_80CB9D0(sPSSData->partySprites[i], count); + MovePartySpriteToNextSlot(sPSSData->partySprites[i], targetSlot); sPSSData->partySprites[i] = NULL; - sPSSData->field_C5E++; + sPSSData->numPartyToCompact++; } - count++; + targetSlot++; } } } -static u8 sub_80CB9BC(void) +static u8 GetNumPartySpritesCompacting(void) { - return sPSSData->field_C5E; + return sPSSData->numPartyToCompact; } -static void sub_80CB9D0(struct Sprite *sprite, u16 partyId) +#define sPartyId data[1] +#define sMonX data[2] +#define sMonY data[3] +#define sSpeedX data[4] +#define sSpeedY data[5] +#define sMoveSteps data[6] + +static void MovePartySpriteToNextSlot(struct Sprite *sprite, u16 partyId) { s16 x, y; - sprite->data[1] = partyId; + sprite->sPartyId = partyId; if (partyId == 0) x = 104, y = 64; else x = 152, y = 8 * (3 * (partyId - 1)) + 16; - sprite->data[2] = (u16)(sprite->pos1.x) * 8; - sprite->data[3] = (u16)(sprite->pos1.y) * 8; - sprite->data[4] = ((x * 8) - sprite->data[2]) / 8; - sprite->data[5] = ((y * 8) - sprite->data[3]) / 8; + sprite->sMonX = (u16)(sprite->pos1.x) * 8; + sprite->sMonY = (u16)(sprite->pos1.y) * 8; + sprite->sSpeedX = ((x * 8) - sprite->sMonX) / 8; + sprite->sSpeedY = ((y * 8) - sprite->sMonY) / 8; sprite->data[6] = 8; - sprite->callback = sub_80CBA3C; + sprite->callback = SpriteCB_MovePartyMonToNextSlot; } -static void sub_80CBA3C(struct Sprite *sprite) +static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *sprite) { - if (sprite->data[6] != 0) + if (sprite->sMoveSteps != 0) { - s16 x = sprite->data[2] += sprite->data[4]; - s16 y = sprite->data[3] += sprite->data[5]; + s16 x = sprite->sMonX += sprite->sSpeedX; + s16 y = sprite->sMonY += sprite->sSpeedY; sprite->pos1.x = x / 8u; sprite->pos1.y = y / 8u; - sprite->data[6]--; + sprite->sMoveSteps--; } else { - if (sprite->data[1] == 0) + if (sprite->sPartyId == 0) { sprite->pos1.x = 104; sprite->pos1.y = 64; @@ -4740,14 +4749,21 @@ static void sub_80CBA3C(struct Sprite *sprite) else { sprite->pos1.x = 152; - sprite->pos1.y = 8 * (3 * (sprite->data[1] - 1)) + 16; + sprite->pos1.y = 8 * (3 * (sprite->sPartyId - 1)) + 16; } sprite->callback = SpriteCallbackDummy; - sPSSData->partySprites[sprite->data[1]] = sprite; - sPSSData->field_C5E--; + sPSSData->partySprites[sprite->sPartyId] = sprite; + sPSSData->numPartyToCompact--; } } +#undef sPartyId +#undef sMonX +#undef sMonY +#undef sSpeedX +#undef sSpeedY +#undef sMoveSteps + static void DestroyMovingMonIcon(void) { if (sPSSData->movingMonSprite != NULL) -- cgit v1.2.3 From c921994ce11952581dd423a1fa0cfa70f0fb240c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 17:28:18 -0400 Subject: Doc storage - tilemap util, place change --- src/pokemon_storage_system.c | 551 +++++++++++++++++++++++-------------------- 1 file changed, 300 insertions(+), 251 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 8b07c17b5..9a6ac1469 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -284,6 +284,13 @@ enum { RELEASE_ANIM_CAME_BACK, }; +// IDs for InitMonPlaceChange +enum { + CHANGE_GRAB, + CHANGE_PLACE, + CHANGE_SHIFT, +}; + // Modes for selecting and moving Pokémon in the box. // "MULTIPLE" mode allows up to an entire box to be // picked up at once by pressing Select then holding @@ -309,6 +316,13 @@ enum { MULTIMOVE_PLACE_MONS, }; +enum { + TILEMAPID_PKMN_DATA, // The "Pkmn Data" text at the top of the display + TILEMAPID_PARTY_MENU, + TILEMAPID_CLOSE_BUTTON, + TILEMAPID_COUNT +}; + struct Wallpaper { const u32 *tiles; @@ -528,32 +542,6 @@ struct PokemonStorageSystemData u8 displayMenuTilemapBuffer[0x800]; }; -struct UnkSubStruct_2039D84 -{ - s16 field_0; - s16 field_2; - u16 field_4; - u16 field_6; - s16 field_8; - s16 field_A; -}; - -struct UnkStruct_2039D84 -{ - struct UnkSubStruct_2039D84 field_0[2]; - const void *field_18; - const void *field_1C; - u16 field_20; - u16 field_22; - u16 field_24; - u16 field_26; - u16 field_28; - u8 field_2A; - u8 field_2B; - u8 field_2C; - u8 field_2D; -}; - static u32 sItemIconGfxBuffer[98]; EWRAM_DATA static u8 sPreviousBoxOption = 0; @@ -605,7 +593,7 @@ static void SaveCursorPos(void); static void sub_80CD36C(void); static void sub_80CD3EC(void); static void sub_80CAC1C(void); -static void sub_80CEBDC(void); +static void ReshowDisplayMon(void); static void SetScrollingBackground(void); static void sub_80CABE0(void); static void sub_80CAEAC(void); @@ -625,7 +613,7 @@ static void CreateWaveformSprites(void); static void ReshowReleaseMon(void); static void TrySetCursorFistAnim(void); static void ClearBottomWindow(void); -static void sub_80CA704(void); +static void InitSupplementalTilemaps(void); static void RemoveMenu(void); static void RefreshDisplayMon(void); static void MoveItemFromCursorToBag(void); @@ -652,7 +640,7 @@ static void AddBoxMenu(void); static void CycleBoxTitleColor(void); static void MoveMon(void); static void PlaceMon(void); -static void sub_80CAB20(void); +static void UpdatePartySlotColors(void); static void sub_80CE22C(void); static void DoCursorNewPosUpdate(void); static void CompactPartySprites(void); @@ -668,8 +656,8 @@ static bool8 InitPSSWindows(void); static bool8 ResetReleaseMonSpritePtr(void); static bool8 TryHideReleaseMon(void); static bool8 IsInitBoxActive(void); -static bool8 sub_80CDED4(void); -static bool8 sub_80CDF08(void); +static bool8 MonPlaceChange_CursorDown(void); +static bool8 MonPlaceChange_CursorUp(void); static bool8 UpdateItemInfoWindowSlideIn(void); static bool8 UpdateItemInfoWindowSlideOut(void); static bool8 DoShowPartyMenu(void); @@ -728,7 +716,7 @@ static void SetMonMarkings(u8); static void ShowYesNoWindow(s8); static void SetCursorBoxPosition(u8); static void AnimateBoxScrollArrows(bool8); -static void sub_80CA984(bool8); +static void UpdateCloseBoxButtonTilemap(bool8); static void CreatePartyMonsSprites(bool8); static void PrintMessage(u8 id); static s16 HandleMenuInput(void); @@ -764,10 +752,10 @@ static s8 DetermineBoxScrollDirection(u8); static void DrawWallpaper(const void *, s8, u8); static s16 GetBoxTitleBaseX(const u8 *); static bool8 MonPlaceChange_Shift(void); -static bool8 MonPlaceChange_Move(void); +static bool8 MonPlaceChange_Grab(void); static bool8 MonPlaceChange_Place(void); -static bool8 sub_80CDEC4(void); -static bool8 sub_80CDEB4(void); +static bool8 MultiMonPlaceChange_Up(void); +static bool8 MultiMonPlaceChange_Down(void); static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *); static void SetShiftedMonData(u8, u8); static void SetMovingMonData(u8, u8); @@ -782,15 +770,6 @@ static s8 GetMenuItemTextId(u8); static u8 SetSelectionMenuTexts(void); static bool8 SetMenuTexts_Mon(void); static bool8 SetMenuTexts_Item(void); -static void sub_80D27AC(u8, u16, u16, u16, u16); -static void sub_80D27F4(u8, u8, s8); -static void sub_80D2644(u8, u8, const void *, u16, u16); -static void sub_80D2770(u8, u16, u16); -static void sub_80D259C(u8); -static void sub_80D25F0(void); -static void sub_80D2918(u8); -static void sub_80D2960(u8); -static void sub_80D29F8(u8); static void sub_80D2A90(struct UnkStruct_2000020 *, struct UnkStruct_2000028 *, u32); static void sub_80D2AA4(void); static void sub_80D2B88(struct UnkStruct_2000028 *); @@ -846,6 +825,17 @@ static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *); static void SpriteCB_ItemIcon_HideParty(struct Sprite *); static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *); +// Functions for the tilemap updating utility +static void TilemapUtil_SetRect(u8, u16, u16, u16, u16); +static void TilemapUtil_Move(u8, u8, s8); +static void TilemapUtil_SetMap(u8, u8, const void *, u16, u16); +static void TilemapUtil_SetPos(u8, u16, u16); +static void TilemapUtil_Init(u8); +static void TilemapUtil_Free(void); +static void TilemapUtil_Update(u8); +static void TilemapUtil_DrawPrev(u8); +static void TilemapUtil_Draw(u8); + struct { const u8 *text; const u8 *desc; @@ -916,24 +906,25 @@ static const union AffineAnimCmd *const sAffineAnims_ChooseBoxMenu[] = static const u8 sChooseBoxMenu_TextColors[] = {TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5}; static const u8 sText_OutOf30[] = _("/30"); -static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal"); +static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal"); static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp"); -static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); -static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); -static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); -static const u16 sDisplayMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/display_menu.gbapal"); // Unused -static const u32 sDisplayMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/display_menu.bin.lz"); +static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp"); +static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); +static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); +static const u16 sDisplayMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/display_menu.gbapal"); // Unused +static const u32 sDisplayMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/display_menu.bin.lz"); -static const u16 gUnknown_0857239C[] = +static const u16 sPkmnData_Tilemap[] = { 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0111, 0x0112, 0x0113, 0x0114, 0x0115, 0x0116, 0x0117, 0x0118, 0x2101, 0x2102, 0x2103, 0x2104, 0x2105, 0x2106, 0x2107, 0x2108, 0x2111, 0x2112, 0x2113, 0x2114, 0x2115, 0x2116, 0x2117, 0x2118, }; -static const u16 gUnknown_085723DC[] = INCBIN_U16("graphics/unknown/unknown_5723DC.gbapal"); // Left-most part and Close Box. -static const u16 gUnknown_085723FC[] = INCBIN_U16("graphics/unknown/unknown_5723FC.gbapal"); -static const u16 gUnknown_0857241C[] = INCBIN_U16("graphics/unknown/unknown_57241C.gbapal"); -static const u16 gUnknown_0857243C[] = INCBIN_U16("graphics/unknown/unknown_57243C.gbapal"); +// sInterface_Pal - parts of the display frame, "PkmnData"'s normal color, Close Box +static const u16 sInterface_Pal[] = INCBIN_U16("graphics/pokemon_storage/interface.gbapal"); +static const u16 sPkmnDataGray_Pal[] = INCBIN_U16("graphics/pokemon_storage/pkmn_data_gray.gbapal"); +static const u16 sBg_Pal[] = INCBIN_U16("graphics/pokemon_storage/bg.gbapal"); +static const u16 sBgMoveItems_Pal[] = INCBIN_U16("graphics/pokemon_storage/bg_move_items.gbapal"); static const u16 sCloseBoxButton_Tilemap[] = { @@ -952,8 +943,8 @@ static const u16 sPartySlotEmpty_Tilemap[] = static const u16 sWaveform_Pal[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal"); static const u32 sWaveform_Gfx[] = INCBIN_U32("graphics/pokemon_storage/waveform.4bpp"); -static const u32 gUnknown_085726B4[] = INCBIN_U32("graphics/unused/unknown_5726B4.gbapal"); -static const u32 gUnknown_085726F4[] = INCBIN_U32("graphics/unknown/unknown_5726F4.gbapal"); +static const u16 gUnknown_085726B4[] = INCBIN_U16("graphics/unused/unknown_5726B4.gbapal"); +static const u16 gUnknown_085726F4[] = INCBIN_U16("graphics/unknown/unknown_5726F4.gbapal"); static const struct WindowTemplate sWindowTemplates[] = { @@ -1353,9 +1344,9 @@ void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero } // Unused -void sub_80C6EAC(const u8 *string, void *dst, u16 arg2, u8 arg3, u8 clr2, u8 clr3) +static void UnusedDrawTextWindow(const u8 *string, void *dst, u16 offset, u8 bgColor, u8 fgColor, u8 shadowColor) { - u32 var; + u32 tileSize; u8 windowId; u8 txtColor[3]; u8 *tileData1, *tileData2; @@ -1363,17 +1354,17 @@ void sub_80C6EAC(const u8 *string, void *dst, u16 arg2, u8 arg3, u8 clr2, u8 clr winTemplate.width = StringLength_Multibyte(string); winTemplate.height = 2; - var = winTemplate.width * 32; + tileSize = winTemplate.width * 32; windowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(windowId, PIXEL_FILL(arg3)); + FillWindowPixelBuffer(windowId, PIXEL_FILL(bgColor)); tileData1 = (u8*) GetWindowAttribute(windowId, WINDOW_TILE_DATA); tileData2 = (winTemplate.width * 32) + tileData1; - txtColor[0] = arg3; - txtColor[1] = clr2; - txtColor[2] = clr3; + txtColor[0] = bgColor; + txtColor[1] = fgColor; + txtColor[2] = shadowColor; AddTextPrinterParameterized4(windowId, 1, 0, 2, 0, 0, txtColor, -1, string); - CpuCopy16(tileData1, dst, var); - CpuCopy16(tileData2, dst + arg2, var); + CpuCopy16(tileData1, dst, tileSize); + CpuCopy16(tileData2, dst + offset, tileSize); RemoveWindow(windowId); } @@ -2007,9 +1998,9 @@ static void sub_80C7E98(void) sub_80D2A90(&sPSSData->unk_0020, sPSSData->unk_0028, 8); gKeyRepeatStartDelay = 20; ClearScheduledBgCopiesToVram(); - sub_80D259C(3); - sub_80D2644(0, 1, gUnknown_0857239C, 8, 4); - sub_80D2770(0, 1, 0); + TilemapUtil_Init(TILEMAPID_COUNT); + TilemapUtil_SetMap(TILEMAPID_PKMN_DATA, 1, sPkmnData_Tilemap, 8, 4); + TilemapUtil_SetPos(TILEMAPID_PKMN_DATA, 1, 0); sPSSData->closeBoxFlashing = FALSE; } @@ -2106,7 +2097,7 @@ static void Cb_InitPSS(u8 taskId) sub_80CA0D8(); break; case 7: - sub_80CA704(); + InitSupplementalTilemaps(); break; case 8: CreateInitBoxTask(StorageGetCurrentBox()); @@ -2689,7 +2680,7 @@ static void Cb_MoveMon(u8 taskId) switch (sPSSData->state) { case 0: - InitMonPlaceChange(0); + InitMonPlaceChange(CHANGE_GRAB); sPSSData->state++; break; case 1: @@ -2709,7 +2700,7 @@ static void Cb_PlaceMon(u8 taskId) switch (sPSSData->state) { case 0: - InitMonPlaceChange(1); + InitMonPlaceChange(CHANGE_PLACE); sPSSData->state++; break; case 1: @@ -2729,7 +2720,7 @@ static void Cb_ShiftMon(u8 taskId) switch (sPSSData->state) { case 0: - InitMonPlaceChange(2); + InitMonPlaceChange(CHANGE_SHIFT); sPSSData->state++; break; case 1: @@ -2755,7 +2746,7 @@ static void Cb_WithdrawMon(u8 taskId) else { SaveCursorPos(); - InitMonPlaceChange(0); + InitMonPlaceChange(CHANGE_GRAB); sPSSData->state = 2; } break; @@ -2777,14 +2768,14 @@ static void Cb_WithdrawMon(u8 taskId) case 3: if (!DoShowPartyMenu()) { - InitMonPlaceChange(1); + InitMonPlaceChange(CHANGE_PLACE); sPSSData->state++; } break; case 4: if (!DoMonPlaceChange()) { - sub_80CAB20(); + UpdatePartySlotColors(); sPSSData->state++; } break; @@ -2845,7 +2836,7 @@ static void Cb_DepositMenu(u8 taskId) { sub_80CE22C(); StartDisplayMonMosaicEffect(); - sub_80CAB20(); + UpdatePartySlotColors(); SetPSSCallback(Cb_MainPSS); } break; @@ -2938,7 +2929,7 @@ static void Cb_ReleaseMon(u8 taskId) { RefreshDisplayMon(); StartDisplayMonMosaicEffect(); - sub_80CAB20(); + UpdatePartySlotColors(); sPSSData->state++; } break; @@ -3291,7 +3282,7 @@ static void Cb_HandleMovingMonFromParty(u8 taskId) case 1: if (GetNumPartySpritesCompacting() == 0) { - sub_80CAB20(); + UpdatePartySlotColors(); SetPSSCallback(Cb_MainPSS); } break; @@ -3738,7 +3729,7 @@ static void GiveChosenBagItem(void) static void FreePSSData(void) { - sub_80D25F0(); + TilemapUtil_Free(); MultiMove_Free(); FREE_AND_SET_NULL(sPSSData); FreeAllWindowBuffers(); @@ -3787,13 +3778,13 @@ static void LoadWaveformSpritePalette(void) static void sub_80CA0D8(void) { - LoadPalette(gUnknown_085723DC, 0, 0x20); - LoadPalette(gUnknown_085723FC, 0x20, 0x20); - LoadPalette(gUnknown_085726F4, 0xF0, 0x20); + LoadPalette(sInterface_Pal, 0, sizeof(sInterface_Pal)); + LoadPalette(sPkmnDataGray_Pal, 0x20, sizeof(sPkmnDataGray_Pal)); + LoadPalette(gUnknown_085726F4, 0xF0, sizeof(gUnknown_085726F4)); if (sPSSData->boxOption != OPTION_MOVE_ITEMS) - LoadPalette(gUnknown_0857241C, 0x30, 0x20); + LoadPalette(sBg_Pal, 0x30, sizeof(sBg_Pal)); else - LoadPalette(gUnknown_0857243C, 0x30, 0x20); + LoadPalette(sBgMoveItems_Pal, 0x30, sizeof(sBgMoveItems_Pal)); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30)); CreateDisplayMonSprite(); @@ -3963,45 +3954,45 @@ static void UpdateWaveformAnimation(void) if (sPSSData->displayMonSpecies != SPECIES_NONE) { - // Start animation - sub_80D27AC(0, 0, 0, 8, 2); + // Start waveform animation and color "Pkmn Data" + TilemapUtil_SetRect(TILEMAPID_PKMN_DATA, 0, 0, 8, 2); for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) StartSpriteAnimIfDifferent(sPSSData->waveformSprites[i], i * 2 + 1); } else { - // Stop animation - sub_80D27AC(0, 0, 2, 8, 2); + // Stop waveform animation and gray out "Pkmn Data" + TilemapUtil_SetRect(TILEMAPID_PKMN_DATA, 0, 2, 8, 2); for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) StartSpriteAnim(sPSSData->waveformSprites[i], i * 2); } - sub_80D2918(0); + TilemapUtil_Update(TILEMAPID_PKMN_DATA); ScheduleBgCopyTilemapToVram(1); } -static void sub_80CA704(void) +static void InitSupplementalTilemaps(void) { LZ77UnCompWram(gStorageSystemPartyMenu_Tilemap, sPSSData->partyMenuTilemapBuffer); LoadPalette(gStorageSystemPartyMenu_Pal, 0x10, 0x20); - sub_80D2644(1, 1, sPSSData->partyMenuTilemapBuffer, 12, 22); - sub_80D2644(2, 1, sCloseBoxButton_Tilemap, 9, 4); - sub_80D2770(1, 10, 0); - sub_80D2770(2, 21, 0); + TilemapUtil_SetMap(TILEMAPID_PARTY_MENU, 1, sPSSData->partyMenuTilemapBuffer, 12, 22); + TilemapUtil_SetMap(TILEMAPID_CLOSE_BUTTON, 1, sCloseBoxButton_Tilemap, 9, 4); + TilemapUtil_SetPos(TILEMAPID_PARTY_MENU, 10, 0); + TilemapUtil_SetPos(TILEMAPID_CLOSE_BUTTON, 21, 0); SetPartySlotTilemaps(); if (sInPartyMenu) { - sub_80CA984(TRUE); + UpdateCloseBoxButtonTilemap(TRUE); CreatePartyMonsSprites(TRUE); - sub_80D2918(2); - sub_80D2918(1); + TilemapUtil_Update(TILEMAPID_CLOSE_BUTTON); + TilemapUtil_Update(TILEMAPID_PARTY_MENU); } else { - sub_80D27AC(1, 0, 20, 12, 2); - sub_80CA984(TRUE); - sub_80D2918(1); - sub_80D2918(2); + TilemapUtil_SetRect(TILEMAPID_PARTY_MENU, 0, 20, 12, 2); + UpdateCloseBoxButtonTilemap(TRUE); + TilemapUtil_Update(TILEMAPID_PARTY_MENU); + TilemapUtil_Update(TILEMAPID_CLOSE_BUTTON); } ScheduleBgCopyTilemapToVram(1); @@ -4023,8 +4014,8 @@ static bool8 ShowPartyMenu(void) sPSSData->partyMenuUnused--; sPSSData->partyMenuY++; - sub_80D27F4(1, 3, 1); - sub_80D2918(1); + TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, 1); + TilemapUtil_Update(TILEMAPID_PARTY_MENU); ScheduleBgCopyTilemapToVram(1); MovePartySprites(8); if (++sPSSData->partyMenuMoveTimer == 20) @@ -4053,8 +4044,8 @@ static bool8 HidePartyMenu(void) { sPSSData->partyMenuUnused++; sPSSData->partyMenuY--; - sub_80D27F4(1, 3, -1); - sub_80D2918(1); + TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, -1); + TilemapUtil_Update(TILEMAPID_PARTY_MENU); FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sPSSData->partyMenuY, 12, 1); MovePartySprites(-8); if (++sPSSData->partyMenuMoveTimer != 20) @@ -4067,8 +4058,11 @@ static bool8 HidePartyMenu(void) sInPartyMenu = FALSE; DestroyAllPartyMonIcons(); CompactPartySlots(); - sub_80D27AC(2, 0, 0, 9, 2); - sub_80D2918(2); + + // The close box button gets partially covered by + // the party menu, restore it + TilemapUtil_SetRect(TILEMAPID_CLOSE_BUTTON, 0, 0, 9, 2); + TilemapUtil_Update(TILEMAPID_CLOSE_BUTTON); ScheduleBgCopyTilemapToVram(1); return FALSE; } @@ -4077,14 +4071,14 @@ static bool8 HidePartyMenu(void) return FALSE; } -static void sub_80CA984(bool8 normal) +static void UpdateCloseBoxButtonTilemap(bool8 normal) { if (normal) - sub_80D27AC(2, 0, 0, 9, 2); + TilemapUtil_SetRect(TILEMAPID_CLOSE_BUTTON, 0, 0, 9, 2); else // flashing - sub_80D27AC(2, 0, 2, 9, 2); + TilemapUtil_SetRect(TILEMAPID_CLOSE_BUTTON, 0, 2, 9, 2); - sub_80D2918(2); + TilemapUtil_Update(TILEMAPID_CLOSE_BUTTON); ScheduleBgCopyTilemapToVram(1); } @@ -4100,7 +4094,7 @@ static void StopFlashingCloseBoxButton(void) if (sPSSData->closeBoxFlashing) { sPSSData->closeBoxFlashing = FALSE; - sub_80CA984(TRUE); + UpdateCloseBoxButtonTilemap(TRUE); } } @@ -4110,7 +4104,7 @@ static void UpdateCloseBoxButtonFlash(void) { sPSSData->closeBoxFlashTimer = 0; sPSSData->closeBoxFlashState = (sPSSData->closeBoxFlashState == FALSE); - sub_80CA984(sPSSData->closeBoxFlashState); + UpdateCloseBoxButtonTilemap(sPSSData->closeBoxFlashState); } } @@ -4150,11 +4144,11 @@ static void SetPartySlotTilemap(u8 partyId, bool8 hasMon) } } -static void sub_80CAB20(void) +static void UpdatePartySlotColors(void) { SetPartySlotTilemaps(); - sub_80D27AC(1, 0, 0, 12, 22); - sub_80D2918(1); + TilemapUtil_SetRect(TILEMAPID_PARTY_MENU, 0, 0, 12, 22); + TilemapUtil_Update(TILEMAPID_PARTY_MENU); ScheduleBgCopyTilemapToVram(1); } @@ -4637,7 +4631,7 @@ static void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode) } } -static void CreatePartyMonsSprites(bool8 arg0) +static void CreatePartyMonsSprites(bool8 visible) { u16 i, count; u16 species = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES2); @@ -4660,7 +4654,7 @@ static void CreatePartyMonsSprites(bool8 arg0) } } - if (!arg0) + if (!visible) { for (i = 0; i < count; i++) { @@ -5426,7 +5420,7 @@ static void CreateIncomingBoxTitle(u8 boxId, s8 direction) StringCopyPadded(sPSSData->boxTitleText, GetBoxNamePtr(boxId), 0, 8); DrawTextWindowAndBufferTiles(sPSSData->boxTitleText, sPSSData->boxTitleTiles, 0, 0, 2); LoadSpriteSheet(&spriteSheet); - LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], palOffset, 4); + LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], palOffset, sizeof(sBoxTitleColors[0])); x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); adjustedX = x; adjustedX += direction * 192; @@ -5673,7 +5667,7 @@ static void sub_80CD36C(void) static void sub_80CD3EC(void) { CreateCursorSprites(); - sub_80CEBDC(); + ReshowDisplayMon(); sPSSData->cursorPrevHorizPos = 1; sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; if (sIsMonBeingMoved) @@ -5996,25 +5990,27 @@ static u8 GetSavedCursorPos(void) return sSavedCursorPosition; } -static void InitMonPlaceChange(u8 a0) +static void InitMonPlaceChange(u8 type) { static bool8 (*const placeChangeFuncs[])(void) = { - MonPlaceChange_Move, - MonPlaceChange_Place, - MonPlaceChange_Shift, + [CHANGE_GRAB] = MonPlaceChange_Grab, + [CHANGE_PLACE] = MonPlaceChange_Place, + [CHANGE_SHIFT] = MonPlaceChange_Shift, }; - sPSSData->monPlaceChangeFunc = placeChangeFuncs[a0]; + sPSSData->monPlaceChangeFunc = placeChangeFuncs[type]; sPSSData->monPlaceChangeState = 0; } -static void sub_80CDC64(bool8 arg0) +// No Shift while moving multiple Pokémon, only grab and place +// For both grab/place, the cursor moves down, then up +static void InitMultiMonPlaceChange(bool8 up) { - if (!arg0) - sPSSData->monPlaceChangeFunc = sub_80CDEB4; + if (!up) + sPSSData->monPlaceChangeFunc = MultiMonPlaceChange_Down; else - sPSSData->monPlaceChangeFunc = sub_80CDEC4; + sPSSData->monPlaceChangeFunc = MultiMonPlaceChange_Up; sPSSData->monPlaceChangeState = 0; } @@ -6024,7 +6020,7 @@ static bool8 DoMonPlaceChange(void) return sPSSData->monPlaceChangeFunc(); } -static bool8 MonPlaceChange_Move(void) +static bool8 MonPlaceChange_Grab(void) { switch (sPSSData->monPlaceChangeState) { @@ -6035,7 +6031,7 @@ static bool8 MonPlaceChange_Move(void) sPSSData->monPlaceChangeState++; break; case 1: - if (!sub_80CDED4()) + if (!MonPlaceChange_CursorDown()) { StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); MoveMon(); @@ -6043,7 +6039,7 @@ static bool8 MonPlaceChange_Move(void) } break; case 2: - if (!sub_80CDF08()) + if (!MonPlaceChange_CursorUp()) sPSSData->monPlaceChangeState++; break; case 3: @@ -6058,7 +6054,7 @@ static bool8 MonPlaceChange_Place(void) switch (sPSSData->monPlaceChangeState) { case 0: - if (!sub_80CDED4()) + if (!MonPlaceChange_CursorDown()) { StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); PlaceMon(); @@ -6066,7 +6062,7 @@ static bool8 MonPlaceChange_Place(void) } break; case 1: - if (!sub_80CDF08()) + if (!MonPlaceChange_CursorUp()) { StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); sPSSData->monPlaceChangeState++; @@ -6114,17 +6110,17 @@ static bool8 MonPlaceChange_Shift(void) return TRUE; } -static bool8 sub_80CDEB4(void) +static bool8 MultiMonPlaceChange_Down(void) { - return sub_80CDED4(); + return MonPlaceChange_CursorDown(); } -static bool8 sub_80CDEC4(void) +static bool8 MultiMonPlaceChange_Up(void) { - return sub_80CDF08(); + return MonPlaceChange_CursorUp(); } -static bool8 sub_80CDED4(void) +static bool8 MonPlaceChange_CursorDown(void) { switch (sPSSData->cursorSprite->pos2.y) { @@ -6134,18 +6130,18 @@ static bool8 sub_80CDED4(void) case 0: sPSSData->cursorSprite->pos2.y++; break; - case 8: + case 8: // Cursor has reached bottom return FALSE; } return TRUE; } -static bool8 sub_80CDF08(void) +static bool8 MonPlaceChange_CursorUp(void) { switch (sPSSData->cursorSprite->pos2.y) { - case 0: + case 0: // Cursor has reached top return FALSE; default: sPSSData->cursorSprite->pos2.y--; @@ -6542,6 +6538,8 @@ static void LoadSavedMovingMon(void) { if (sIsMonBeingMoved) { + // If it came from the party load a struct Pokemon, + // otherwise load a BoxPokemon if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT) sPSSData->movingMon = sSavedMovingMon; else @@ -6695,7 +6693,7 @@ static void TryRefreshDisplayMon(void) } } -static void sub_80CEBDC(void) +static void ReshowDisplayMon(void) { if (sIsMonBeingMoved) SetDisplayMonData(&sSavedMovingMon, MODE_PARTY); @@ -7726,7 +7724,8 @@ static void StartCursorAnim(u8 animNum) StartSpriteAnim(sPSSData->cursorSprite, animNum); } -static u8 sub_80CFE78(void) +// Unused +static u8 GetMovingMonOriginalBoxId(void) { return sMovingMonOrigBoxId; } @@ -8078,7 +8077,7 @@ static bool8 MultiMove_GrabSelection(void) case 0: MultiMove_GetMonsFromSelection(); MultiMove_RemoveMonsFromBox(); - sub_80CDC64(FALSE); + InitMultiMonPlaceChange(FALSE); sMultiMove->state++; break; case 1: @@ -8086,7 +8085,7 @@ static bool8 MultiMove_GrabSelection(void) { StartCursorAnim(CURSOR_ANIM_FIST); MultiMove_InitMove(0, 256, 8); - sub_80CDC64(TRUE); + InitMultiMonPlaceChange(TRUE); sMultiMove->state++; } break; @@ -8119,7 +8118,7 @@ static bool8 MultiMove_PlaceMons(void) case 0: MultiMove_SetPlacedMonData(); MultiMove_InitMove(0, -256, 8); - sub_80CDC64(FALSE); + InitMultiMonPlaceChange(FALSE); sMultiMove->state++; break; case 1: @@ -8127,7 +8126,7 @@ static bool8 MultiMove_PlaceMons(void) { MultiMove_CreatePlacedMonIcons(); StartCursorAnim(CURSOR_ANIM_OPEN); - sub_80CDC64(TRUE); + InitMultiMonPlaceChange(TRUE); HideBg(0); sMultiMove->state++; } @@ -9210,6 +9209,12 @@ static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite) #undef sCursorArea #undef sCursorPos + +//------------------------------------------------------------------------------ +// SECTION: General utility +//------------------------------------------------------------------------------ + + // Unused, leftover from FRLG static void BackupPokemonStorage(void/*struct PokemonStorage * dest*/) { @@ -9474,6 +9479,12 @@ bool32 AnyStorageMonWithMove(u16 moveId) return FALSE; } + +//------------------------------------------------------------------------------ +// SECTION: Walda +//------------------------------------------------------------------------------ + + void ResetWaldaWallpaper(void) { gSaveBlock1Ptr->waldaPhrase.iconId = 0; @@ -9542,205 +9553,243 @@ bool32 IsWaldaPhraseEmpty(void) return (gSaveBlock1Ptr->waldaPhrase.text[0] == EOS); } -// Not sure what the purpose of these functions is. -// They seem to only be called while PSS is initialized. -EWRAM_DATA static struct UnkStruct_2039D84 *gUnknown_02039D84 = NULL; -EWRAM_DATA static u16 gUnknown_02039D88 = 0; +//------------------------------------------------------------------------------ +// SECTION: TilemapUtil +// +// Handles 3 particular tilemaps in a somewhat unusual way. +// For example, while the cursor is on the Close Box button it flashes between +// two states alternately. Both these states are their own part of the same +// tilemap that's always present. The utility shifts the tilemap up and down +// to show/hide the states, and limits the view with a rectangle that only +// reveals one at a time. +// Each tilemap is tracked with a TILEMAPID that can be used to reference it. +//------------------------------------------------------------------------------ + + +struct TilemapUtil_RectData +{ + s16 x; + s16 y; + u16 width; + u16 height; + s16 destX; + s16 destY; +}; + +struct TilemapUtil +{ + struct TilemapUtil_RectData prev; // Only read in unused function + struct TilemapUtil_RectData cur; + const void *savedTilemap; // Only written in unused function + const void *tilemap; + u16 altWidth; + u16 altHeight; // Never read + u16 width; + u16 height; // Never read + u16 rowSize; // Never read + u8 tileSize; + u8 bg; + bool8 active; +}; + +EWRAM_DATA static struct TilemapUtil *sTilemapUtil = NULL; +EWRAM_DATA static u16 sNumTilemapUtilIds = 0; -static void sub_80D259C(u8 count) +static void TilemapUtil_Init(u8 count) { u16 i; - gUnknown_02039D84 = Alloc(sizeof(*gUnknown_02039D84) * count); - gUnknown_02039D88 = (gUnknown_02039D84 == NULL) ? 0 : count; - for (i = 0; i < gUnknown_02039D88; i++) + sTilemapUtil = Alloc(sizeof(*sTilemapUtil) * count); + sNumTilemapUtilIds = (sTilemapUtil == NULL) ? 0 : count; + for (i = 0; i < sNumTilemapUtilIds; i++) { - gUnknown_02039D84[i].field_18 = NULL; - gUnknown_02039D84[i].field_2C = 0; + sTilemapUtil[i].savedTilemap = NULL; + sTilemapUtil[i].active = FALSE; } } -static void sub_80D25F0(void) +static void TilemapUtil_Free(void) { - Free(gUnknown_02039D84); + Free(sTilemapUtil); } -static void sub_80D2604(void) +// Unused +static void TilemapUtil_UpdateAll(void) { s32 i; - for (i = 0; i < gUnknown_02039D88; i++) + for (i = 0; i < sNumTilemapUtilIds; i++) { - if (gUnknown_02039D84[i].field_2C == 1) - sub_80D2918(i); + if (sTilemapUtil[i].active == TRUE) + TilemapUtil_Update(i); } } struct { - u16 a; - u16 b; -} -static const sUnkVars[][4] = + u16 width; + u16 height; +} static const sTilemapDimensions[][4] = { { - {0x0100, 0x0100}, - {0x0200, 0x0100}, - {0x0100, 0x0200}, - {0x0200, 0x0200}, + { 256, 256}, + { 512, 256}, + { 256, 512}, + { 512, 512}, }, { - {0x0080, 0x0080}, - {0x0100, 0x0100}, - {0x0200, 0x0200}, - {0x0400, 0x0400}, + { 128, 128}, + { 256, 256}, + { 512, 512}, + {1024, 1024}, }, }; -static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4) +static void TilemapUtil_SetMap(u8 id, u8 bg, const void *tilemap, u16 width, u16 height) { u16 bgScreenSize, bgType; - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - gUnknown_02039D84[id].field_18 = NULL; - gUnknown_02039D84[id].field_1C = arg2; - gUnknown_02039D84[id].field_2B = bg; - gUnknown_02039D84[id].field_24 = arg3; - gUnknown_02039D84[id].field_26 = arg4; + sTilemapUtil[id].savedTilemap = NULL; + sTilemapUtil[id].tilemap = tilemap; + sTilemapUtil[id].bg = bg; + sTilemapUtil[id].width = width; + sTilemapUtil[id].height = height; bgScreenSize = GetBgAttribute(bg, BG_ATTR_SCREENSIZE); bgType = GetBgAttribute(bg, BG_ATTR_TYPE); - gUnknown_02039D84[id].field_20 = sUnkVars[bgType][bgScreenSize].a; - gUnknown_02039D84[id].field_22 = sUnkVars[bgType][bgScreenSize].b; + sTilemapUtil[id].altWidth = sTilemapDimensions[bgType][bgScreenSize].width; + sTilemapUtil[id].altHeight = sTilemapDimensions[bgType][bgScreenSize].height; if (bgType != 0) - gUnknown_02039D84[id].field_2A = 1; + sTilemapUtil[id].tileSize = 1; else - gUnknown_02039D84[id].field_2A = 2; + sTilemapUtil[id].tileSize = 2; - gUnknown_02039D84[id].field_28 = gUnknown_02039D84[id].field_2A * arg3; - gUnknown_02039D84[id].field_0[1].field_4 = arg3; - gUnknown_02039D84[id].field_0[1].field_6 = arg4; - gUnknown_02039D84[id].field_0[1].field_0 = 0; - gUnknown_02039D84[id].field_0[1].field_2 = 0; - gUnknown_02039D84[id].field_0[1].field_8 = 0; - gUnknown_02039D84[id].field_0[1].field_A = 0; - gUnknown_02039D84[id].field_0[0] = gUnknown_02039D84[id].field_0[1]; - gUnknown_02039D84[id].field_2C = 1; + sTilemapUtil[id].rowSize = sTilemapUtil[id].tileSize * width; + sTilemapUtil[id].cur.width = width; + sTilemapUtil[id].cur.height = height; + sTilemapUtil[id].cur.x = 0; + sTilemapUtil[id].cur.y = 0; + sTilemapUtil[id].cur.destX = 0; + sTilemapUtil[id].cur.destY = 0; + sTilemapUtil[id].prev = sTilemapUtil[id].cur; + sTilemapUtil[id].active = TRUE; } -static void sub_80D2740(u8 id, const void *arg1) +// Unused +static void TilemapUtil_SetSavedMap(u8 id, const void *tilemap) { - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - gUnknown_02039D84[id].field_18 = arg1; - gUnknown_02039D84[id].field_2C = 1; + sTilemapUtil[id].savedTilemap = tilemap; + sTilemapUtil[id].active = TRUE; } -static void sub_80D2770(u8 id, u16 arg1, u16 arg2) +static void TilemapUtil_SetPos(u8 id, u16 x, u16 y) { - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - gUnknown_02039D84[id].field_0[1].field_8 = arg1; - gUnknown_02039D84[id].field_0[1].field_A = arg2; - gUnknown_02039D84[id].field_2C = 1; + sTilemapUtil[id].cur.destX = x; + sTilemapUtil[id].cur.destY = y; + sTilemapUtil[id].active = TRUE; } -static void sub_80D27AC(u8 id, u16 arg1, u16 arg2, u16 arg3, u16 arg4) +static void TilemapUtil_SetRect(u8 id, u16 x, u16 y, u16 width, u16 height) { - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - gUnknown_02039D84[id].field_0[1].field_0 = arg1; - gUnknown_02039D84[id].field_0[1].field_2 = arg2; - gUnknown_02039D84[id].field_0[1].field_4 = arg3; - gUnknown_02039D84[id].field_0[1].field_6 = arg4; - gUnknown_02039D84[id].field_2C = 1; + sTilemapUtil[id].cur.x = x; + sTilemapUtil[id].cur.y = y; + sTilemapUtil[id].cur.width = width; + sTilemapUtil[id].cur.height = height; + sTilemapUtil[id].active = TRUE; } -static void sub_80D27F4(u8 id, u8 arg1, s8 arg2) +static void TilemapUtil_Move(u8 id, u8 mode, s8 val) { - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - switch (arg1) + switch (mode) { case 0: - gUnknown_02039D84[id].field_0[1].field_8 += arg2; - gUnknown_02039D84[id].field_0[1].field_4 -= arg2; + sTilemapUtil[id].cur.destX += val; + sTilemapUtil[id].cur.width -= val; break; case 1: - gUnknown_02039D84[id].field_0[1].field_0 += arg2; - gUnknown_02039D84[id].field_0[1].field_4 += arg2; + sTilemapUtil[id].cur.x += val; + sTilemapUtil[id].cur.width += val; break; case 2: - gUnknown_02039D84[id].field_0[1].field_A += arg2; - gUnknown_02039D84[id].field_0[1].field_6 -= arg2; + sTilemapUtil[id].cur.destY += val; + sTilemapUtil[id].cur.height -= val; break; case 3: - gUnknown_02039D84[id].field_0[1].field_2 -= arg2; - gUnknown_02039D84[id].field_0[1].field_6 += arg2; + sTilemapUtil[id].cur.y -= val; + sTilemapUtil[id].cur.height += val; break; case 4: - gUnknown_02039D84[id].field_0[1].field_8 += arg2; + sTilemapUtil[id].cur.destX += val; break; case 5: - gUnknown_02039D84[id].field_0[1].field_A += arg2; + sTilemapUtil[id].cur.destY += val; break; } - gUnknown_02039D84[id].field_2C = 1; + sTilemapUtil[id].active = TRUE; } -static void sub_80D2918(u8 id) +static void TilemapUtil_Update(u8 id) { - if (id >= gUnknown_02039D88) + if (id >= sNumTilemapUtilIds) return; - if (gUnknown_02039D84[id].field_18 != NULL) - sub_80D2960(id); + if (sTilemapUtil[id].savedTilemap != NULL) + TilemapUtil_DrawPrev(id); // Never called, above always FALSE - sub_80D29F8(id); - gUnknown_02039D84[id].field_0[0] = gUnknown_02039D84[id].field_0[1]; + TilemapUtil_Draw(id); + sTilemapUtil[id].prev = sTilemapUtil[id].cur; } -static void sub_80D2960(u8 id) +static void TilemapUtil_DrawPrev(u8 id) { s32 i; - u32 adder = gUnknown_02039D84[id].field_2A * gUnknown_02039D84[id].field_20; - const void *tiles = (gUnknown_02039D84[id].field_18 + (adder * gUnknown_02039D84[id].field_0[0].field_A)) - + (gUnknown_02039D84[id].field_2A * gUnknown_02039D84[id].field_0[0].field_8); + u32 adder = sTilemapUtil[id].tileSize * sTilemapUtil[id].altWidth; + const void *tiles = (sTilemapUtil[id].savedTilemap + (adder * sTilemapUtil[id].prev.destY)) + + (sTilemapUtil[id].tileSize * sTilemapUtil[id].prev.destX); - for (i = 0; i < gUnknown_02039D84[id].field_0[0].field_6; i++) + for (i = 0; i < sTilemapUtil[id].prev.height; i++) { - CopyToBgTilemapBufferRect(gUnknown_02039D84[id].field_2B, + CopyToBgTilemapBufferRect(sTilemapUtil[id].bg, tiles, - gUnknown_02039D84[id].field_0[0].field_8, - gUnknown_02039D84[id].field_0[0].field_A + i, - gUnknown_02039D84[id].field_0[0].field_4, + sTilemapUtil[id].prev.destX, + sTilemapUtil[id].prev.destY + i, + sTilemapUtil[id].prev.width, 1); tiles += adder; } } -static void sub_80D29F8(u8 id) +static void TilemapUtil_Draw(u8 id) { s32 i; - u32 adder = gUnknown_02039D84[id].field_2A * gUnknown_02039D84[id].field_24; - const void *tiles = (gUnknown_02039D84[id].field_1C + (adder * gUnknown_02039D84[id].field_0[1].field_2)) - + (gUnknown_02039D84[id].field_2A * gUnknown_02039D84[id].field_0[1].field_0); + u32 adder = sTilemapUtil[id].tileSize * sTilemapUtil[id].width; + const void *tiles = (sTilemapUtil[id].tilemap + (adder * sTilemapUtil[id].cur.y)) + + (sTilemapUtil[id].tileSize * sTilemapUtil[id].cur.x); - for (i = 0; i < gUnknown_02039D84[id].field_0[1].field_6; i++) + for (i = 0; i < sTilemapUtil[id].cur.height; i++) { - CopyToBgTilemapBufferRect(gUnknown_02039D84[id].field_2B, + CopyToBgTilemapBufferRect(sTilemapUtil[id].bg, tiles, - gUnknown_02039D84[id].field_0[1].field_8, - gUnknown_02039D84[id].field_0[1].field_A + i, - gUnknown_02039D84[id].field_0[1].field_4, + sTilemapUtil[id].cur.destX, + sTilemapUtil[id].cur.destY + i, + sTilemapUtil[id].cur.width, 1); tiles += adder; } -- cgit v1.2.3 From 7bf89d64466040f958903d0d4fc8a77c7c6c2737 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 19:28:31 -0400 Subject: Doc storage - icon scroll --- src/pokemon_storage_system.c | 200 ++++++++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 87 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 9a6ac1469..82d33227d 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -450,14 +450,14 @@ struct PokemonStorageSystemData u8 field_C5C; u8 field_C5D; u8 numPartyToCompact; - u16 field_C60; - s16 field_C62; - s16 field_C64; - u16 field_C66; - u8 field_C68; - s8 field_C69; - u8 field_C6A; - u8 field_C6B; // Never read. + u16 iconScrollDistance; + s16 iconScrollPos; + s16 iconScrollSpeed; + u16 iconScrollNumIncoming; + u8 iconScrollCurColumn; + s8 iconScrollDirection; // Unnecessary duplicate of scrollDirection + u8 iconScrollState; + u8 iconScrollToBoxId; // Unnecessary duplicate of scrollToBoxId struct WindowTemplate menuWindow; struct StorageMenu menuItems[7]; u8 menuItemsCount; @@ -582,7 +582,7 @@ static void ChooseBoxMenu_PrintInfo(void); static void UpdateCloseBoxButtonFlash(void); static void ToggleCursorAutoAction(void); static void LoadSavedMovingMon(void); -static void sub_80CE8E4(void); +static void SetSelectionAfterSummaryScreen(void); static void GiveChosenBagItem(void); static void SetUpHidePartyMenu(void); static void DestroyAllPartyMonIcons(void); @@ -649,7 +649,7 @@ static void SetUpDoShowPartyMenu(void); static void StartDisplayMonMosaicEffect(void); static void SpriteCB_ChooseBoxArrow(struct Sprite *); static void SpriteCB_HeldMon(struct Sprite *); -static void sub_80CB278(struct Sprite *); +static void SpriteCB_BoxMonIconScrollOut(struct Sprite *); static void SpriteCB_Arrow(struct Sprite *); static bool32 WaitForWallpaperGfxLoad(void); static bool8 InitPSSWindows(void); @@ -2045,7 +2045,7 @@ static void Cb_InitPSS(u8 taskId) break; case SCREEN_CHANGE_SUMMARY_SCREEN - 1: // Return from summary screen - sub_80CE8E4(); + SetSelectionAfterSummaryScreen(); break; case SCREEN_CHANGE_ITEM_FROM_BAG - 1: // Return from bag menu @@ -4396,7 +4396,7 @@ static void InitBoxMonSprites(u8 boxId) } } -static void sub_80CB140(u8 boxPosition) +static void CreateBoxMonIconAtPos(u8 boxPosition) { u16 species = GetCurrentBoxMonData(boxPosition, MON_DATA_SPECIES2); @@ -4412,7 +4412,13 @@ static void sub_80CB140(u8 boxPosition) } } -static void sub_80CB1F0(s16 arg0) +#define sDistance data[1] +#define sSpeed data[2] +#define sScrollInDestX data[3] +#define sDelay data[4] +#define sScrollOutX data[5] + +static void StartBoxMonIconsScrollOut(s16 speed) { u16 i; @@ -4420,44 +4426,51 @@ static void sub_80CB1F0(s16 arg0) { if (sPSSData->boxMonsSprites[i] != NULL) { - sPSSData->boxMonsSprites[i]->data[2] = arg0; - sPSSData->boxMonsSprites[i]->data[4] = 1; - sPSSData->boxMonsSprites[i]->callback = sub_80CB278; + sPSSData->boxMonsSprites[i]->sSpeed = speed; + sPSSData->boxMonsSprites[i]->sDelay = 1; + sPSSData->boxMonsSprites[i]->callback = SpriteCB_BoxMonIconScrollOut; } } } -static void sub_80CB234(struct Sprite *sprite) +static void SpriteCB_BoxMonIconScrollIn(struct Sprite *sprite) { - if (sprite->data[1] != 0) + if (sprite->sDistance != 0) { - sprite->data[1]--; - sprite->pos1.x += sprite->data[2]; + // Icon moving + sprite->sDistance--; + sprite->pos1.x += sprite->sSpeed; } else { - sPSSData->field_C66--; - sprite->pos1.x = sprite->data[3]; + // Icon arrived + sPSSData->iconScrollNumIncoming--; + sprite->pos1.x = sprite->sScrollInDestX; sprite->callback = SpriteCallbackDummy; } } -static void sub_80CB278(struct Sprite *sprite) +static void SpriteCB_BoxMonIconScrollOut(struct Sprite *sprite) { - if (sprite->data[4] != 0) + if (sprite->sDelay != 0) { - sprite->data[4]--; + sprite->sDelay--; } else { - sprite->pos1.x += sprite->data[2]; - sprite->data[5] = sprite->pos1.x + sprite->pos2.x; - if (sprite->data[5] <= 68 || sprite->data[5] >= 252) + // Icon moving + sprite->pos1.x += sprite->sSpeed; + sprite->sScrollOutX = sprite->pos1.x + sprite->pos2.x; + + // Check if icon offscreen + if (sprite->sScrollOutX <= 68 || sprite->sScrollOutX >= 252) sprite->callback = SpriteCallbackDummy; } } -static void DestroyAllIconsInColumn(u8 column) +// Sprites for Pokémon icons are destroyed during +// the box scroll once they've gone offscreen +static void DestroyBoxMonIconsInColumn(u8 column) { u16 row; u8 boxPosition = column; @@ -4473,15 +4486,16 @@ static void DestroyAllIconsInColumn(u8 column) } } -static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) +// Create the appearing icons for the incoming scrolling box +static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) { s32 i; u16 y = 44; - s16 xDest = 8 * (3 * row) + 100; - u16 x = xDest - ((times + 1) * xDelta); - u8 subpriority = 19 - row; - u8 count = 0; - u8 boxPosition = row; + s16 xDest = 8 * (3 * column) + 100; + u16 x = xDest - ((distance + 1) * speed); + u8 subpriority = 19 - column; + u8 iconsCreated = 0; + u8 boxPosition = column; if (sPSSData->boxOption != OPTION_MOVE_ITEMS) { @@ -4494,11 +4508,11 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) x, y, 2, subpriority); if (sPSSData->boxMonsSprites[boxPosition] != NULL) { - sPSSData->boxMonsSprites[boxPosition]->data[1] = times; - sPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta; - sPSSData->boxMonsSprites[boxPosition]->data[3] = xDest; - sPSSData->boxMonsSprites[boxPosition]->callback = sub_80CB234; - count++; + sPSSData->boxMonsSprites[boxPosition]->sDistance = distance; + sPSSData->boxMonsSprites[boxPosition]->sSpeed = speed; + sPSSData->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; + sPSSData->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + iconsCreated++; } } boxPosition += IN_BOX_COLUMNS; @@ -4507,6 +4521,8 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) } else { + // Separate case for Move Items mode is used + // to create the icons with the proper blend for (i = 0; i < IN_BOX_ROWS; i++) { if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) @@ -4516,13 +4532,13 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) x, y, 2, subpriority); if (sPSSData->boxMonsSprites[boxPosition] != NULL) { - sPSSData->boxMonsSprites[boxPosition]->data[1] = times; - sPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta; - sPSSData->boxMonsSprites[boxPosition]->data[3] = xDest; - sPSSData->boxMonsSprites[boxPosition]->callback = sub_80CB234; - if (GetBoxMonDataAt(sPSSData->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == 0) + sPSSData->boxMonsSprites[boxPosition]->sDistance = distance; + sPSSData->boxMonsSprites[boxPosition]->sSpeed = speed; + sPSSData->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; + sPSSData->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + if (GetBoxMonDataAt(sPSSData->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; - count++; + iconsCreated++; } } boxPosition += IN_BOX_COLUMNS; @@ -4530,61 +4546,73 @@ static u8 sub_80CB2F8(u8 row, u16 times, s16 xDelta) } } - return count; + return iconsCreated; } -static void sub_80CB4CC(u8 boxId, s8 direction) -{ - sPSSData->field_C6A = 0; - sPSSData->field_C6B = boxId; - sPSSData->field_C69 = direction; - sPSSData->field_C60 = 32; - sPSSData->field_C64 = -(6 * direction); - sPSSData->field_C66 = 0; +#undef sDistance +#undef sSpeed +#undef sScrollInDestX +#undef sDelay +#undef sScrollOutX + +static void InitBoxMonIconScroll(u8 boxId, s8 direction) +{ + sPSSData->iconScrollState = 0; + sPSSData->iconScrollToBoxId = boxId; + sPSSData->iconScrollDirection = direction; + sPSSData->iconScrollDistance = 32; + sPSSData->iconScrollSpeed = -(6 * direction); + sPSSData->iconScrollNumIncoming = 0; SetBoxSpeciesAndPersonalities(boxId); if (direction > 0) - sPSSData->field_C68 = 0; + sPSSData->iconScrollCurColumn = 0; else - sPSSData->field_C68 = IN_BOX_COLUMNS - 1; + sPSSData->iconScrollCurColumn = IN_BOX_COLUMNS - 1; - sPSSData->field_C62 = (24 * sPSSData->field_C68) + 100; - sub_80CB1F0(sPSSData->field_C64); + sPSSData->iconScrollPos = (24 * sPSSData->iconScrollCurColumn) + 100; + StartBoxMonIconsScrollOut(sPSSData->iconScrollSpeed); } -static bool8 sub_80CB584(void) +static bool8 UpdateBoxMonIconScroll(void) { - if (sPSSData->field_C60 != 0) - sPSSData->field_C60--; + if (sPSSData->iconScrollDistance != 0) + sPSSData->iconScrollDistance--; - switch (sPSSData->field_C6A) + switch (sPSSData->iconScrollState) { case 0: - sPSSData->field_C62 += sPSSData->field_C64; - if (sPSSData->field_C62 <= 64 || sPSSData->field_C62 >= 252) + sPSSData->iconScrollPos += sPSSData->iconScrollSpeed; + if (sPSSData->iconScrollPos <= 64 || sPSSData->iconScrollPos >= 252) { - DestroyAllIconsInColumn(sPSSData->field_C68); - sPSSData->field_C62 += sPSSData->field_C69 * 24; - sPSSData->field_C6A++; + // A column of icons has gone offscreen, destroy them + DestroyBoxMonIconsInColumn(sPSSData->iconScrollCurColumn); + sPSSData->iconScrollPos += sPSSData->iconScrollDirection * 24; + sPSSData->iconScrollState++; } break; case 1: - sPSSData->field_C62 += sPSSData->field_C64; - sPSSData->field_C66 += sub_80CB2F8(sPSSData->field_C68, sPSSData->field_C60, sPSSData->field_C64); - if ((sPSSData->field_C69 > 0 && sPSSData->field_C68 == IN_BOX_COLUMNS - 1) - || (sPSSData->field_C69 < 0 && sPSSData->field_C68 == 0)) + // Create the new incoming column of icons + sPSSData->iconScrollPos += sPSSData->iconScrollSpeed; + sPSSData->iconScrollNumIncoming += CreateBoxMonIconsInColumn(sPSSData->iconScrollCurColumn, sPSSData->iconScrollDistance, sPSSData->iconScrollSpeed); + + if ((sPSSData->iconScrollDirection > 0 && sPSSData->iconScrollCurColumn == IN_BOX_COLUMNS - 1) + || (sPSSData->iconScrollDirection < 0 && sPSSData->iconScrollCurColumn == 0)) { - sPSSData->field_C6A++; + // Scroll has reached final column + sPSSData->iconScrollState++; } else { - sPSSData->field_C68 += sPSSData->field_C69; - sPSSData->field_C6A = 0; + // Continue scrolling + sPSSData->iconScrollCurColumn += sPSSData->iconScrollDirection; + sPSSData->iconScrollState = 0; } break; case 2: - if (sPSSData->field_C66 == 0) + // Wait to make sure all icons have arrived + if (sPSSData->iconScrollNumIncoming == 0) { - sPSSData->field_C60++; + sPSSData->iconScrollDistance++; return FALSE; } break; @@ -4626,9 +4654,7 @@ static void DestroyBoxMonIconAtPosition(u8 boxPosition) static void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode) { if (sPSSData->boxMonsSprites[boxPosition] != NULL) - { sPSSData->boxMonsSprites[boxPosition]->oam.objMode = objMode; - } } static void CreatePartyMonsSprites(bool8 visible) @@ -4667,7 +4693,7 @@ static void CreatePartyMonsSprites(bool8 visible) { for (i = 0; i < PARTY_SIZE; i++) { - if (sPSSData->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == 0) + if (sPSSData->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == ITEM_NONE) sPSSData->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND; } } @@ -5146,7 +5172,7 @@ static void SetUpScrollToBox(u8 boxId) static bool8 ScrollToBox(void) { - bool8 var; + bool8 iconsScrolling; switch (sPSSData->scrollState) { @@ -5157,12 +5183,12 @@ static bool8 ScrollToBox(void) if (!WaitForWallpaperGfxLoad()) return TRUE; - sub_80CB4CC(sPSSData->scrollToBoxId, sPSSData->scrollDirection); + InitBoxMonIconScroll(sPSSData->scrollToBoxId, sPSSData->scrollDirection); CreateIncomingBoxTitle(sPSSData->scrollToBoxId, sPSSData->scrollDirection); StartBoxScrollArrowsSlide(sPSSData->scrollDirection); break; case 2: - var = sub_80CB584(); + iconsScrolling = UpdateBoxMonIconScroll(); if (sPSSData->scrollTimer != 0) { sPSSData->bg2_X += sPSSData->scrollSpeed; @@ -5171,7 +5197,7 @@ static bool8 ScrollToBox(void) CycleBoxTitleSprites(); StopBoxScrollArrowsSlide(); } - return var; + return iconsScrolling; } sPSSData->scrollState++; @@ -6267,7 +6293,7 @@ static bool8 TryStorePartyMonInBox(u8 boxId) } if (boxId == StorageGetCurrentBox()) - sub_80CB140(boxPosition); + CreateBoxMonIconAtPos(boxPosition); StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); return TRUE; @@ -6573,7 +6599,7 @@ static void InitSummaryScreenData(void) } } -static void sub_80CE8E4(void) +static void SetSelectionAfterSummaryScreen(void) { if (sIsMonBeingMoved) LoadSavedMovingMon(); @@ -8385,7 +8411,7 @@ static void MultiMove_CreatePlacedMonIcons(void) for (j = sMultiMove->minColumn; j < columnCount; j++) { if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) - sub_80CB140(boxPosition); + CreateBoxMonIconAtPos(boxPosition); monArrayId++; boxPosition++; } -- cgit v1.2.3 From 33c68255de5db6a936929faade6a635ba97d33d0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 23:31:29 -0400 Subject: Doc storage - unk utility --- src/pokemon_storage_system.c | 137 ++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 61 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 82d33227d..6c25dcfce 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -342,21 +342,21 @@ struct StorageMenu int textId; }; -struct UnkStruct_2000028 -{ - const u8 *unk_00; - u8 *unk_04; - u16 unk_08; - u16 unk_0a; - u16 newField; - void (*unk_0c)(struct UnkStruct_2000028 *data); +struct UnkUtilData +{ + const u8 *src; + u8 *dest; + u16 size; + u16 unk; + u16 height; + void (*func)(struct UnkUtilData *data); }; -struct UnkStruct_2000020 +struct UnkUtil { - struct UnkStruct_2000028 *unk_00; - u8 unk_04; - u8 unk_05; + struct UnkUtilData *data; + u8 numActive; + u8 max; }; struct ChooseBoxMenu @@ -391,8 +391,8 @@ struct PokemonStorageSystemData u8 screenChangeType; bool8 isReshowingPSS; u8 taskId; - struct UnkStruct_2000020 unk_0020; - struct UnkStruct_2000028 unk_0028[8]; + struct UnkUtil unkUtil; + struct UnkUtilData unkUtilData[8]; u16 partyMenuTilemapBuffer[0x108]; u16 partyMenuUnused; // Never read u16 partyMenuY; @@ -770,10 +770,6 @@ static s8 GetMenuItemTextId(u8); static u8 SetSelectionMenuTexts(void); static bool8 SetMenuTexts_Mon(void); static bool8 SetMenuTexts_Item(void); -static void sub_80D2A90(struct UnkStruct_2000020 *, struct UnkStruct_2000028 *, u32); -static void sub_80D2AA4(void); -static void sub_80D2B88(struct UnkStruct_2000028 *); -static void sub_80D2C1C(struct UnkStruct_2000028 *); static u8 GetBoxWallpaper(u8); static void SetBoxWallpaper(u8, u8); @@ -836,6 +832,12 @@ static void TilemapUtil_Update(u8); static void TilemapUtil_DrawPrev(u8); static void TilemapUtil_Draw(u8); +// Functions for unknown utility +static void UnkUtil_Init(struct UnkUtil *, struct UnkUtilData *, u32); +static void UnkUtil_Run(void); +static void UnkUtil_CpuRun(struct UnkUtilData *); +static void UnkUtil_DmaRun(struct UnkUtilData *); + struct { const u8 *text; const u8 *desc; @@ -1921,7 +1923,7 @@ static void VblankCb_PSS(void) { LoadOam(); ProcessSpriteCopyRequests(); - sub_80D2AA4(); + UnkUtil_Run(); TransferPlttBuffer(); SetGpuReg(REG_OFFSET_BG2HOFS, sPSSData->bg2_X); } @@ -1995,7 +1997,7 @@ static void sub_80C7E98(void) FreeAllSpritePalettes(); ClearDma3Requests(); gReservedSpriteTileCount = 0x280; - sub_80D2A90(&sPSSData->unk_0020, sPSSData->unk_0028, 8); + UnkUtil_Init(&sPSSData->unkUtil, sPSSData->unkUtilData, ARRAY_COUNT(sPSSData->unkUtilData)); gKeyRepeatStartDelay = 20; ClearScheduledBgCopiesToVram(); TilemapUtil_Init(TILEMAPID_COUNT); @@ -9821,83 +9823,96 @@ static void TilemapUtil_Draw(u8 id) } } -EWRAM_DATA static struct UnkStruct_2000020 *gUnknown_02039D8C = NULL; -static void sub_80D2A90(struct UnkStruct_2000020 *arg0, struct UnkStruct_2000028 *arg1, u32 arg2) +//------------------------------------------------------------------------------ +// SECTION: UnkUtil +// +// Some data transfer utility that goes functionally unused. +// It gets initialized with UnkUtil_Init, and run every vblank in Pokémon +// Storage with UnkUtil_Run, but neither of the Add functions are ever used, +// so UnkUtil_Run performs no actions. +//------------------------------------------------------------------------------ + + +EWRAM_DATA static struct UnkUtil *sUnkUtil = NULL; + +static void UnkUtil_Init(struct UnkUtil *util, struct UnkUtilData *data, u32 max) { - gUnknown_02039D8C = arg0; - arg0->unk_00 = arg1; - arg0->unk_05 = arg2; - arg0->unk_04 = 0; + sUnkUtil = util; + util->data = data; + util->max = max; + util->numActive = 0; } -static void sub_80D2AA4(void) +static void UnkUtil_Run(void) { u16 i; - - if (gUnknown_02039D8C->unk_04) + if (sUnkUtil->numActive) { - for (i = 0; i < gUnknown_02039D8C->unk_04; i++) + for (i = 0; i < sUnkUtil->numActive; i++) { - struct UnkStruct_2000028 *unkStruct = &gUnknown_02039D8C->unk_00[i]; - unkStruct->unk_0c(unkStruct); + struct UnkUtilData *data = &sUnkUtil->data[i]; + data->func(data); } - - gUnknown_02039D8C->unk_04 = 0; + sUnkUtil->numActive = 0; } } -static bool8 sub_80D2AEC(u8 *dest, u16 dLeft, u16 dTop, const u8 *src, u16 sLeft, u16 sTop, u16 width, u16 height, u16 unkArg) +// Unused +static bool8 UnkUtil_CpuAdd(u8 *dest, u16 dLeft, u16 dTop, const u8 *src, u16 sLeft, u16 sTop, u16 width, u16 height, u16 unkArg) { - struct UnkStruct_2000028 *unkStruct; + struct UnkUtilData *data; - if (gUnknown_02039D8C->unk_04 >= gUnknown_02039D8C->unk_05) + if (sUnkUtil->numActive >= sUnkUtil->max) return FALSE; - unkStruct = &gUnknown_02039D8C->unk_00[gUnknown_02039D8C->unk_04++]; - unkStruct->unk_08 = width * 2; - unkStruct->unk_04 = dest + 2 * (dTop * 32 + dLeft); - unkStruct->unk_00 = src + 2 * (sTop * unkArg + sLeft); - unkStruct->newField = height; - unkStruct->unk_0a = unkArg; - unkStruct->unk_0c = sub_80D2B88; + data = &sUnkUtil->data[sUnkUtil->numActive++]; + data->size = width * 2; + data->dest = dest + 2 * (dTop * 32 + dLeft); + data->src = src + 2 * (sTop * unkArg + sLeft); + data->height = height; + data->unk = unkArg; + data->func = UnkUtil_CpuRun; return TRUE; } -static void sub_80D2B88(struct UnkStruct_2000028 *unkStruct) +// Functionally unused +static void UnkUtil_CpuRun(struct UnkUtilData *data) { u16 i; - for (i = 0; i < unkStruct->newField; i++) + for (i = 0; i < data->height; i++) { - CpuSet(unkStruct->unk_00, unkStruct->unk_04, (unkStruct->unk_08 / 2)); - unkStruct->unk_04 += 64; - unkStruct->unk_00 += (unkStruct->unk_0a * 2); + CpuSet(data->src, data->dest, data->size / 2); + data->dest += 64; + data->src += data->unk * 2; } } -static bool8 sub_80D2BC0(void *dest, u16 dLeft, u16 dTop, u16 width, u16 height) +// Unused +static bool8 UnkUtil_DmaAdd(void *dest, u16 dLeft, u16 dTop, u16 width, u16 height) { - struct UnkStruct_2000028 *unkStruct; + struct UnkUtilData *data; - if (gUnknown_02039D8C->unk_04 >= gUnknown_02039D8C->unk_05) + if (sUnkUtil->numActive >= sUnkUtil->max) return FALSE; - unkStruct = &gUnknown_02039D8C->unk_00[gUnknown_02039D8C->unk_04++]; - unkStruct->unk_08 = width * 2; - unkStruct->unk_04 = dest + ((dTop * 32) + dLeft) * 2; - unkStruct->newField = height; - unkStruct->unk_0c = sub_80D2C1C; + data = &sUnkUtil->data[sUnkUtil->numActive++]; + data->size = width * 2; + data->dest = dest + (dTop * 32 + dLeft) * 2; + data->height = height; + data->func = UnkUtil_DmaRun; return TRUE; } -static void sub_80D2C1C(struct UnkStruct_2000028 *unkStruct) +// Functionally unused +static void UnkUtil_DmaRun(struct UnkUtilData *data) { u16 i; - for (i = 0; i < unkStruct->newField; i++) + for (i = 0; i < data->height; i++) { - Dma3FillLarge_(0, unkStruct->unk_04, unkStruct->unk_08, 16); - unkStruct->unk_04 += 64; + Dma3FillLarge16_(0, data->dest, data->size); + data->dest += 64; } } -- cgit v1.2.3 From 6f967ff6ad90e4a8438fe802c18dbc29cedda1ee Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 23:40:27 -0400 Subject: Doc storage - standardize names, drop PSS --- src/pokemon_storage_system.c | 2506 +++++++++++++++++++++--------------------- 1 file changed, 1253 insertions(+), 1253 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 6c25dcfce..c4b3c6f60 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -389,7 +389,7 @@ struct PokemonStorageSystemData u8 state; u8 boxOption; u8 screenChangeType; - bool8 isReshowingPSS; + bool8 isReopening; u8 taskId; struct UnkUtil unkUtil; struct UnkUtilData unkUtilData[8]; @@ -546,7 +546,7 @@ static u32 sItemIconGfxBuffer[98]; EWRAM_DATA static u8 sPreviousBoxOption = 0; EWRAM_DATA static struct ChooseBoxMenu *sChooseBoxMenu = NULL; -EWRAM_DATA static struct PokemonStorageSystemData *sPSSData = NULL; +EWRAM_DATA static struct PokemonStorageSystemData *sStorage = NULL; EWRAM_DATA static bool8 sInPartyMenu = 0; EWRAM_DATA static u8 sCurrentBoxOption = 0; EWRAM_DATA static u8 sDepositBoxId = 0; @@ -562,7 +562,7 @@ EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0; EWRAM_DATA static bool8 sAutoActionOn = 0; static void CreateMainMenu(u8, s16 *); -static void Cb2_EnterPSS(u8); +static void EnterPokeStorage(u8); static u8 GetCurrentBoxOption(void); static u8 HandleInput(void); static u8 GetSavedCursorPos(void); @@ -587,7 +587,7 @@ static void GiveChosenBagItem(void); static void SetUpHidePartyMenu(void); static void DestroyAllPartyMonIcons(void); static void MoveHeldItemWithPartyMenu(void); -static void LoadPSSMenuGfx(void); +static void LoadPokeStorageMenuGfx(void); static void LoadWaveformSpritePalette(void); static void SaveCursorPos(void); static void sub_80CD36C(void); @@ -635,7 +635,7 @@ static void SetCursorInParty(void); static void InitSummaryScreenData(void); static void TryShowItemAtCursor(void); static void StopFlashingCloseBoxButton(void); -static void FreePSSData(void); +static void FreePokeStorageData(void); static void AddBoxMenu(void); static void CycleBoxTitleColor(void); static void MoveMon(void); @@ -652,7 +652,7 @@ static void SpriteCB_HeldMon(struct Sprite *); static void SpriteCB_BoxMonIconScrollOut(struct Sprite *); static void SpriteCB_Arrow(struct Sprite *); static bool32 WaitForWallpaperGfxLoad(void); -static bool8 InitPSSWindows(void); +static bool8 InitPokeStorageWindows(void); static bool8 ResetReleaseMonSpritePtr(void); static bool8 TryHideReleaseMon(void); static bool8 IsInitBoxActive(void); @@ -677,37 +677,37 @@ static bool8 IsCursorOnBoxTitle(void); static bool8 IsCursorInBox(void); static bool8 IsMonBeingMoved(void); static bool8 TryStorePartyMonInBox(u8); -static void Cb_InitPSS(u8); -static void Cb_PlaceMon(u8); -static void Cb_ChangeScreen(u8); -static void Cb_ShowPSS(u8); -static void Cb_OnBPressed(u8); -static void Cb_HandleBoxOptions(u8); -static void Cb_OnSelectedMon(u8); -static void Cb_OnCloseBoxPressed(u8); -static void Cb_HidePartyPokemon(u8); -static void Cb_DepositMenu(u8); -static void Cb_MoveMon(u8); -static void Cb_GiveMovingItemToMon(u8); -static void Cb_SwitchSelectedItem(u8); -static void Cb_TakeItemForMoving(u8); -static void Cb_WithdrawMon(u8); -static void Cb_ShiftMon(u8); -static void Cb_ShowPartyPokemon(u8); -static void Cb_ShowItemInfo(u8); -static void Cb_GiveItemFromBag(u8); -static void Cb_ItemToBag(u8); -static void Cb_TakeItemForMoving(u8); -static void Cb_ShowMarkMenu(u8); -static void Cb_ShowMonSummary(u8); -static void Cb_ReleaseMon(u8); -static void Cb_ReshowPSS(u8); -static void Cb_MainPSS(u8); -static void Cb_JumpBox(u8); -static void Cb_HandleWallpapers(u8); -static void Cb_NameBox(u8); -static void Cb_PrintCantStoreMail(u8); -static void Cb_HandleMovingMonFromParty(u8); +static void Task_InitPokeStorage(u8); +static void Task_PlaceMon(u8); +static void Task_ChangeScreen(u8); +static void Task_ShowPokeStorage(u8); +static void Task_OnBPressed(u8); +static void Task_HandleBoxOptions(u8); +static void Task_OnSelectedMon(u8); +static void Task_OnCloseBoxPressed(u8); +static void Task_HidePartyPokemon(u8); +static void Task_DepositMenu(u8); +static void Task_MoveMon(u8); +static void Task_GiveMovingItemToMon(u8); +static void Task_SwitchSelectedItem(u8); +static void Task_TakeItemForMoving(u8); +static void Task_WithdrawMon(u8); +static void Task_ShiftMon(u8); +static void Task_ShowPartyPokemon(u8); +static void Task_ShowItemInfo(u8); +static void Task_GiveItemFromBag(u8); +static void Task_ItemToBag(u8); +static void Task_TakeItemForMoving(u8); +static void Task_ShowMarkMenu(u8); +static void Task_ShowMonSummary(u8); +static void Task_ReleaseMon(u8); +static void Task_ReshowPokeStorage(u8); +static void Task_PokeStorageMain(u8); +static void Task_JumpBox(u8); +static void Task_HandleWallpapers(u8); +static void Task_NameBox(u8); +static void Task_PrintCantStoreMail(u8); +static void Task_HandleMovingMonFromParty(u8); static void SetUpScrollToBox(u8); static void StartCursorAnim(u8); static void SetMovingMonPriority(u8); @@ -1604,7 +1604,7 @@ static void Task_PCMainMenu(u8 taskId) if (!gPaletteFade.active) { CleanupOverworldWindowsAndTilemaps(); - Cb2_EnterPSS(task->tInput); + EnterPokeStorage(task->tInput); RemoveWindow(task->tWindowId); DestroyTask(taskId); } @@ -1620,7 +1620,7 @@ void ShowPokemonStorageSystemPC(void) ScriptContext2_Enable(); } -static void FieldCb_ReturnToPcMenu(void) +static void FieldTask_ReturnToPcMenu(void) { u8 taskId; MainCallback vblankCb = gMain.vblankCallback; @@ -1653,10 +1653,10 @@ static void CreateMainMenu(u8 whichMenu, s16 *windowIdPtr) *windowIdPtr = windowId; } -static void Cb2_ExitPSS(void) +static void CB2_ExitPokeStorage(void) { sPreviousBoxOption = GetCurrentBoxOption(); - gFieldCallback = FieldCb_ReturnToPcMenu; + gFieldCallback = FieldTask_ReturnToPcMenu; SetMainCallback2(CB2_ReturnToField); } @@ -1919,16 +1919,16 @@ static void SpriteCB_ChooseBoxArrow(struct Sprite *sprite) } } -static void VblankCb_PSS(void) +static void VBlankCB_PokeStorage(void) { LoadOam(); ProcessSpriteCopyRequests(); UnkUtil_Run(); TransferPlttBuffer(); - SetGpuReg(REG_OFFSET_BG2HOFS, sPSSData->bg2_X); + SetGpuReg(REG_OFFSET_BG2HOFS, sStorage->bg2_X); } -static void Cb2_PSS(void) +static void CB2_PokeStorage(void) { RunTasks(); DoScheduledBgTilemapCopiesToVram(); @@ -1938,42 +1938,42 @@ static void Cb2_PSS(void) BuildOamBuffer(); } -static void Cb2_EnterPSS(u8 boxOption) +static void EnterPokeStorage(u8 boxOption) { ResetTasks(); sCurrentBoxOption = boxOption; - sPSSData = Alloc(sizeof(*sPSSData)); - if (sPSSData == NULL) + sStorage = Alloc(sizeof(*sStorage)); + if (sStorage == NULL) { - SetMainCallback2(Cb2_ExitPSS); + SetMainCallback2(CB2_ExitPokeStorage); } else { - sPSSData->boxOption = boxOption; - sPSSData->isReshowingPSS = FALSE; + sStorage->boxOption = boxOption; + sStorage->isReopening = FALSE; sMovingItemId = ITEM_NONE; - sPSSData->state = 0; - sPSSData->taskId = CreateTask(Cb_InitPSS, 3); + sStorage->state = 0; + sStorage->taskId = CreateTask(Task_InitPokeStorage, 3); sLastUsedBox = StorageGetCurrentBox(); - SetMainCallback2(Cb2_PSS); + SetMainCallback2(CB2_PokeStorage); } } -static void Cb2_ReturnToPSS(void) +static void CB2_ReturnToPokeStorage(void) { ResetTasks(); - sPSSData = Alloc(sizeof(*sPSSData)); - if (sPSSData == NULL) + sStorage = Alloc(sizeof(*sStorage)); + if (sStorage == NULL) { - SetMainCallback2(Cb2_ExitPSS); + SetMainCallback2(CB2_ExitPokeStorage); } else { - sPSSData->boxOption = sCurrentBoxOption; - sPSSData->isReshowingPSS = TRUE; - sPSSData->state = 0; - sPSSData->taskId = CreateTask(Cb_InitPSS, 3); - SetMainCallback2(Cb2_PSS); + sStorage->boxOption = sCurrentBoxOption; + sStorage->isReopening = TRUE; + sStorage->state = 0; + sStorage->taskId = CreateTask(Task_InitPokeStorage, 3); + SetMainCallback2(CB2_PokeStorage); } } @@ -1997,25 +1997,25 @@ static void sub_80C7E98(void) FreeAllSpritePalettes(); ClearDma3Requests(); gReservedSpriteTileCount = 0x280; - UnkUtil_Init(&sPSSData->unkUtil, sPSSData->unkUtilData, ARRAY_COUNT(sPSSData->unkUtilData)); + UnkUtil_Init(&sStorage->unkUtil, sStorage->unkUtilData, ARRAY_COUNT(sStorage->unkUtilData)); gKeyRepeatStartDelay = 20; ClearScheduledBgCopiesToVram(); TilemapUtil_Init(TILEMAPID_COUNT); TilemapUtil_SetMap(TILEMAPID_PKMN_DATA, 1, sPkmnData_Tilemap, 8, 4); TilemapUtil_SetPos(TILEMAPID_PKMN_DATA, 1, 0); - sPSSData->closeBoxFlashing = FALSE; + sStorage->closeBoxFlashing = FALSE; } static void sub_80C7F1C(void) { ClearSavedCursorPos(); - sInPartyMenu = (sPSSData->boxOption == OPTION_DEPOSIT); + sInPartyMenu = (sStorage->boxOption == OPTION_DEPOSIT); sDepositBoxId = 0; } static void SetMonIconTransparency(void) { - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(7, 11)); @@ -2023,21 +2023,21 @@ static void SetMonIconTransparency(void) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_1D_MAP); } -static void SetPSSCallback(TaskFunc newFunc) +static void SetPokeStorageTask(TaskFunc newFunc) { - gTasks[sPSSData->taskId].func = newFunc; - sPSSData->state = 0; + gTasks[sStorage->taskId].func = newFunc; + sStorage->state = 0; } -static void Cb_InitPSS(u8 taskId) +static void Task_InitPokeStorage(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: SetVBlankCallback(NULL); SetGpuReg(REG_OFFSET_DISPCNT, 0); sub_80C7E98(); - if (sPSSData->isReshowingPSS) + if (sStorage->isReopening) { switch (sWhichToReshow) { @@ -2055,13 +2055,13 @@ static void Cb_InitPSS(u8 taskId) break; } } - LoadPSSMenuGfx(); + LoadPokeStorageMenuGfx(); LoadWaveformSpritePalette(); break; case 1: - if (!InitPSSWindows()) + if (!InitPokeStorageWindows()) { - SetPSSCallback(Cb_ChangeScreen); + SetPokeStorageTask(Task_ChangeScreen); return; } break; @@ -2073,12 +2073,12 @@ static void Cb_InitPSS(u8 taskId) break; case 3: ResetAllBgCoords(); - if (!sPSSData->isReshowingPSS) + if (!sStorage->isReopening) sub_80C7F1C(); break; case 4: InitMonIconFields(); - if (!sPSSData->isReshowingPSS) + if (!sStorage->isReopening) sub_80CD36C(); else sub_80CD3EC(); @@ -2086,7 +2086,7 @@ static void Cb_InitPSS(u8 taskId) case 5: if (!MultiMove_Init()) { - SetPSSCallback(Cb_ChangeScreen); + SetPokeStorageTask(Task_ChangeScreen); return; } else @@ -2108,11 +2108,11 @@ static void Cb_InitPSS(u8 taskId) if (IsInitBoxActive()) return; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - sPSSData->markMenu.baseTileTag = GFXTAG_MARKING_MENU; - sPSSData->markMenu.basePaletteTag = PALTAG_MARKING_MENU; - InitMonMarkingsMenu(&sPSSData->markMenu); + sStorage->markMenu.baseTileTag = GFXTAG_MARKING_MENU; + sStorage->markMenu.basePaletteTag = PALTAG_MARKING_MENU; + InitMonMarkingsMenu(&sStorage->markMenu); BufferMonMarkingsMenuTiles(); } else @@ -2123,48 +2123,48 @@ static void Cb_InitPSS(u8 taskId) break; case 10: SetMonIconTransparency(); - if (!sPSSData->isReshowingPSS) + if (!sStorage->isReopening) { BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); - SetPSSCallback(Cb_ShowPSS); + SetPokeStorageTask(Task_ShowPokeStorage); } else { BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); - SetPSSCallback(Cb_ReshowPSS); + SetPokeStorageTask(Task_ReshowPokeStorage); } - SetVBlankCallback(VblankCb_PSS); + SetVBlankCallback(VBlankCB_PokeStorage); return; default: return; } - sPSSData->state++; + sStorage->state++; } -static void Cb_ShowPSS(u8 taskId) +static void Task_ShowPokeStorage(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PlaySE(SE_PC_LOGIN); ComputerScreenOpenEffect(20, 0, 1); - sPSSData->state++; + sStorage->state++; break; case 1: if (!IsComputerScreenOpenEffectActive()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_ReshowPSS(u8 taskId) +static void Task_ReshowPokeStorage(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: BeginNormalPaletteFade(PALETTES_ALL, -1, 0x10, 0, RGB_BLACK); - sPSSData->state++; + sStorage->state++; break; case 1: if (!UpdatePaletteFade()) @@ -2172,11 +2172,11 @@ static void Cb_ReshowPSS(u8 taskId) if (sWhichToReshow == SCREEN_CHANGE_ITEM_FROM_BAG - 1 && gSpecialVar_ItemId != ITEM_NONE) { PrintMessage(MSG_ITEM_IS_HELD); - sPSSData->state++; + sStorage->state++; } else { - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } } break; @@ -2184,17 +2184,17 @@ static void Cb_ReshowPSS(u8 taskId) if (!IsDma3ManagerBusyWithBgCopy() && JOY_NEW(A_BUTTON | B_BUTTON)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } break; case 3: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -// States for the outer switch in Cb_MainPSS +// States for the outer switch in Task_PokeStorageMain enum { MSTATE_HANDLE_INPUT, MSTATE_MOVE_CURSOR, @@ -2210,174 +2210,174 @@ enum { MSTATE_WAIT_ITEM_ANIM, }; -static void Cb_MainPSS(u8 taskId) +static void Task_PokeStorageMain(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case MSTATE_HANDLE_INPUT: switch (HandleInput()) { case INPUT_MOVE_CURSOR: PlaySE(SE_SELECT); - sPSSData->state = MSTATE_MOVE_CURSOR; + sStorage->state = MSTATE_MOVE_CURSOR; break; case INPUT_SHOW_PARTY: - if (sPSSData->boxOption != OPTION_MOVE_MONS && sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_MONS && sStorage->boxOption != OPTION_MOVE_ITEMS) { PrintMessage(MSG_WHICH_ONE_WILL_TAKE); - sPSSData->state = MSTATE_WAIT_MSG; + sStorage->state = MSTATE_WAIT_MSG; } else { ClearSavedCursorPos(); - SetPSSCallback(Cb_ShowPartyPokemon); + SetPokeStorageTask(Task_ShowPartyPokemon); } break; case INPUT_HIDE_PARTY: - if (sPSSData->boxOption == OPTION_MOVE_MONS) + if (sStorage->boxOption == OPTION_MOVE_MONS) { - if (IsMonBeingMoved() && ItemIsMail(sPSSData->displayMonItemId)) - sPSSData->state = MSTATE_ERROR_HAS_MAIL; + if (IsMonBeingMoved() && ItemIsMail(sStorage->displayMonItemId)) + sStorage->state = MSTATE_ERROR_HAS_MAIL; else - SetPSSCallback(Cb_HidePartyPokemon); + SetPokeStorageTask(Task_HidePartyPokemon); } - else if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + else if (sStorage->boxOption == OPTION_MOVE_ITEMS) { - SetPSSCallback(Cb_HidePartyPokemon); + SetPokeStorageTask(Task_HidePartyPokemon); } break; case INPUT_CLOSE_BOX: - SetPSSCallback(Cb_OnCloseBoxPressed); + SetPokeStorageTask(Task_OnCloseBoxPressed); break; case INPUT_PRESSED_B: - SetPSSCallback(Cb_OnBPressed); + SetPokeStorageTask(Task_OnBPressed); break; case INPUT_BOX_OPTIONS: PlaySE(SE_SELECT); - SetPSSCallback(Cb_HandleBoxOptions); + SetPokeStorageTask(Task_HandleBoxOptions); break; case INPUT_IN_MENU: - SetPSSCallback(Cb_OnSelectedMon); + SetPokeStorageTask(Task_OnSelectedMon); break; case INPUT_SCROLL_RIGHT: PlaySE(SE_SELECT); - sPSSData->newCurrBoxId = StorageGetCurrentBox() + 1; - if (sPSSData->newCurrBoxId >= TOTAL_BOXES_COUNT) - sPSSData->newCurrBoxId = 0; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + sStorage->newCurrBoxId = StorageGetCurrentBox() + 1; + if (sStorage->newCurrBoxId >= TOTAL_BOXES_COUNT) + sStorage->newCurrBoxId = 0; + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = MSTATE_SCROLL_BOX; + SetUpScrollToBox(sStorage->newCurrBoxId); + sStorage->state = MSTATE_SCROLL_BOX; } else { TryHideItemAtCursor(); - sPSSData->state = MSTATE_SCROLL_BOX_ITEM; + sStorage->state = MSTATE_SCROLL_BOX_ITEM; } break; case INPUT_SCROLL_LEFT: PlaySE(SE_SELECT); - sPSSData->newCurrBoxId = StorageGetCurrentBox() - 1; - if (sPSSData->newCurrBoxId < 0) - sPSSData->newCurrBoxId = TOTAL_BOXES_COUNT - 1; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + sStorage->newCurrBoxId = StorageGetCurrentBox() - 1; + if (sStorage->newCurrBoxId < 0) + sStorage->newCurrBoxId = TOTAL_BOXES_COUNT - 1; + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = MSTATE_SCROLL_BOX; + SetUpScrollToBox(sStorage->newCurrBoxId); + sStorage->state = MSTATE_SCROLL_BOX; } else { TryHideItemAtCursor(); - sPSSData->state = MSTATE_SCROLL_BOX_ITEM; + sStorage->state = MSTATE_SCROLL_BOX_ITEM; } break; case INPUT_DEPOSIT: if (!IsRemovingLastPartyMon()) { - if (ItemIsMail(sPSSData->displayMonItemId)) + if (ItemIsMail(sStorage->displayMonItemId)) { - sPSSData->state = MSTATE_ERROR_HAS_MAIL; + sStorage->state = MSTATE_ERROR_HAS_MAIL; } else { PlaySE(SE_SELECT); - SetPSSCallback(Cb_DepositMenu); + SetPokeStorageTask(Task_DepositMenu); } } else { - sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; + sStorage->state = MSTATE_ERROR_LAST_PARTY_MON; } break; case INPUT_MOVE_MON: if (IsRemovingLastPartyMon()) { - sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; + sStorage->state = MSTATE_ERROR_LAST_PARTY_MON; } else { PlaySE(SE_SELECT); - SetPSSCallback(Cb_MoveMon); + SetPokeStorageTask(Task_MoveMon); } break; case INPUT_SHIFT_MON: if (!CanShiftMon()) { - sPSSData->state = MSTATE_ERROR_LAST_PARTY_MON; + sStorage->state = MSTATE_ERROR_LAST_PARTY_MON; } else { PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShiftMon); + SetPokeStorageTask(Task_ShiftMon); } break; case INPUT_WITHDRAW: PlaySE(SE_SELECT); - SetPSSCallback(Cb_WithdrawMon); + SetPokeStorageTask(Task_WithdrawMon); break; case INPUT_PLACE_MON: PlaySE(SE_SELECT); - SetPSSCallback(Cb_PlaceMon); + SetPokeStorageTask(Task_PlaceMon); break; case INPUT_TAKE_ITEM: PlaySE(SE_SELECT); - SetPSSCallback(Cb_TakeItemForMoving); + SetPokeStorageTask(Task_TakeItemForMoving); break; case INPUT_GIVE_ITEM: PlaySE(SE_SELECT); - SetPSSCallback(Cb_GiveMovingItemToMon); + SetPokeStorageTask(Task_GiveMovingItemToMon); break; case INPUT_SWITCH_ITEMS: PlaySE(SE_SELECT); - SetPSSCallback(Cb_SwitchSelectedItem); + SetPokeStorageTask(Task_SwitchSelectedItem); break; case INPUT_MULTIMOVE_START: PlaySE(SE_SELECT); MultiMove_SetFunction(MULTIMOVE_START); - sPSSData->state = MSTATE_MULTIMOVE_RUN; + sStorage->state = MSTATE_MULTIMOVE_RUN; break; case INPUT_MULTIMOVE_SINGLE: MultiMove_SetFunction(MULTIMOVE_CANCEL); - sPSSData->state = MSTATE_MULTIMOVE_RUN_CANCEL; + sStorage->state = MSTATE_MULTIMOVE_RUN_CANCEL; break; case INPUT_MULTIMOVE_CHANGE_SELECTION: PlaySE(SE_SELECT); MultiMove_SetFunction(MULTIMOVE_CHANGE_SELECTION); - sPSSData->state = MSTATE_MULTIMOVE_RUN_MOVED; + sStorage->state = MSTATE_MULTIMOVE_RUN_MOVED; break; case INPUT_MULTIMOVE_GRAB_SELECTION: MultiMove_SetFunction(MULTIMOVE_GRAB_SELECTION); - sPSSData->state = MSTATE_MULTIMOVE_RUN; + sStorage->state = MSTATE_MULTIMOVE_RUN; break; case INPUT_MULTIMOVE_MOVE_MONS: PlaySE(SE_SELECT); MultiMove_SetFunction(MULTIMOVE_MOVE_MONS); - sPSSData->state = MSTATE_MULTIMOVE_RUN_MOVED; + sStorage->state = MSTATE_MULTIMOVE_RUN_MOVED; break; case INPUT_MULTIMOVE_PLACE_MONS: PlaySE(SE_SELECT); MultiMove_SetFunction(MULTIMOVE_PLACE_MONS); - sPSSData->state = MSTATE_MULTIMOVE_RUN; + sStorage->state = MSTATE_MULTIMOVE_RUN; break; case INPUT_MULTIMOVE_UNABLE: // When selecting/moving multiple Pokémon the @@ -2394,29 +2394,29 @@ static void Cb_MainPSS(u8 taskId) else StopFlashingCloseBoxButton(); - if (sPSSData->setMosaic) + if (sStorage->setMosaic) StartDisplayMonMosaicEffect(); - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; } break; case MSTATE_SCROLL_BOX: if (!ScrollToBox()) { - SetCurrentBox(sPSSData->newCurrBoxId); + SetCurrentBox(sStorage->newCurrBoxId); if (!sInPartyMenu && !IsMonBeingMoved()) { RefreshDisplayMon(); StartDisplayMonMosaicEffect(); } - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { TryShowItemAtCursor(); - sPSSData->state = MSTATE_WAIT_ITEM_ANIM; + sStorage->state = MSTATE_WAIT_ITEM_ANIM; } else { - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; } } break; @@ -2424,29 +2424,29 @@ static void Cb_MainPSS(u8 taskId) if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; } break; case MSTATE_ERROR_LAST_PARTY_MON: PlaySE(SE_FAILURE); PrintMessage(MSG_LAST_POKE); - sPSSData->state = MSTATE_WAIT_ERROR_MSG; + sStorage->state = MSTATE_WAIT_ERROR_MSG; break; case MSTATE_ERROR_HAS_MAIL: PlaySE(SE_FAILURE); PrintMessage(MSG_PLEASE_REMOVE_MAIL); - sPSSData->state = MSTATE_WAIT_ERROR_MSG; + sStorage->state = MSTATE_WAIT_ERROR_MSG; break; case MSTATE_WAIT_ERROR_MSG: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case MSTATE_MULTIMOVE_RUN: if (!MultiMove_RunFunction()) - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; break; case MSTATE_MULTIMOVE_RUN_CANCEL: // Began a multiple Pokémon selection but @@ -2454,94 +2454,94 @@ static void Cb_MainPSS(u8 taskId) // Wait for multi move to cancel, then // do a normal move. if (!MultiMove_RunFunction()) - SetPSSCallback(Cb_MoveMon); + SetPokeStorageTask(Task_MoveMon); break; case MSTATE_MULTIMOVE_RUN_MOVED: if (!MultiMove_RunFunction()) { - if (sPSSData->setMosaic) + if (sStorage->setMosaic) StartDisplayMonMosaicEffect(); - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; } break; case MSTATE_SCROLL_BOX_ITEM: if (!IsItemIconAnimActive()) { - SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state = MSTATE_SCROLL_BOX; + SetUpScrollToBox(sStorage->newCurrBoxId); + sStorage->state = MSTATE_SCROLL_BOX; } break; case MSTATE_WAIT_ITEM_ANIM: if (!IsItemIconAnimActive()) - sPSSData->state = MSTATE_HANDLE_INPUT; + sStorage->state = MSTATE_HANDLE_INPUT; break; } } -static void Cb_ShowPartyPokemon(u8 taskId) +static void Task_ShowPartyPokemon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: SetUpDoShowPartyMenu(); - sPSSData->state++; + sStorage->state++; break; case 1: if (!DoShowPartyMenu()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_HidePartyPokemon(u8 taskId) +static void Task_HidePartyPokemon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PlaySE(SE_SELECT); SetUpHidePartyMenu(); - sPSSData->state++; + sStorage->state++; break; case 1: if (!HidePartyMenu()) { SetCursorBoxPosition(GetSavedCursorPos()); - sPSSData->state++; + sStorage->state++; } break; case 2: if (!UpdateCursorPos()) { - if (sPSSData->setMosaic) + if (sStorage->setMosaic) StartDisplayMonMosaicEffect(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_OnSelectedMon(u8 taskId) +static void Task_OnSelectedMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: if (!IsDisplayMosaicActive()) { PlaySE(SE_SELECT); - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) PrintMessage(MSG_IS_SELECTED); - else if (IsMovingItem() || sPSSData->displayMonItemId != ITEM_NONE) + else if (IsMovingItem() || sStorage->displayMonItemId != ITEM_NONE) PrintMessage(MSG_IS_SELECTED2); else PrintMessage(MSG_GIVE_TO_MON); AddMenu(); - sPSSData->state = 1; + sStorage->state = 1; } break; case 1: if (!IsMenuLoading()) - sPSSData->state = 2; + sStorage->state = 2; break; case 2: switch (HandleMenuInput()) @@ -2549,214 +2549,214 @@ static void Cb_OnSelectedMon(u8 taskId) case MENU_B_PRESSED: case MENU_CANCEL: ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case MENU_MOVE: if (IsRemovingLastPartyMon()) { - sPSSData->state = 3; + sStorage->state = 3; } else { PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_MoveMon); + SetPokeStorageTask(Task_MoveMon); } break; case MENU_PLACE: PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_PlaceMon); + SetPokeStorageTask(Task_PlaceMon); break; case MENU_SHIFT: if (!CanShiftMon()) { - sPSSData->state = 3; + sStorage->state = 3; } else { PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_ShiftMon); + SetPokeStorageTask(Task_ShiftMon); } break; case MENU_WITHDRAW: PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_WithdrawMon); + SetPokeStorageTask(Task_WithdrawMon); break; case MENU_STORE: if (IsRemovingLastPartyMon()) { - sPSSData->state = 3; + sStorage->state = 3; } - else if (ItemIsMail(sPSSData->displayMonItemId)) + else if (ItemIsMail(sStorage->displayMonItemId)) { - sPSSData->state = 4; + sStorage->state = 4; } else { PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_DepositMenu); + SetPokeStorageTask(Task_DepositMenu); } break; case MENU_RELEASE: if (IsRemovingLastPartyMon()) { - sPSSData->state = 3; + sStorage->state = 3; } - else if (sPSSData->displayMonIsEgg) + else if (sStorage->displayMonIsEgg) { - sPSSData->state = 5; // Cannot release an Egg. + sStorage->state = 5; // Cannot release an Egg. } - else if (ItemIsMail(sPSSData->displayMonItemId)) + else if (ItemIsMail(sStorage->displayMonItemId)) { - sPSSData->state = 4; + sStorage->state = 4; } else { PlaySE(SE_SELECT); - SetPSSCallback(Cb_ReleaseMon); + SetPokeStorageTask(Task_ReleaseMon); } break; case MENU_SUMMARY: PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShowMonSummary); + SetPokeStorageTask(Task_ShowMonSummary); break; case MENU_MARK: PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShowMarkMenu); + SetPokeStorageTask(Task_ShowMarkMenu); break; case MENU_TAKE: PlaySE(SE_SELECT); - SetPSSCallback(Cb_TakeItemForMoving); + SetPokeStorageTask(Task_TakeItemForMoving); break; case MENU_GIVE: PlaySE(SE_SELECT); - SetPSSCallback(Cb_GiveMovingItemToMon); + SetPokeStorageTask(Task_GiveMovingItemToMon); break; case MENU_BAG: - SetPSSCallback(Cb_ItemToBag); + SetPokeStorageTask(Task_ItemToBag); break; case MENU_SWITCH: PlaySE(SE_SELECT); - SetPSSCallback(Cb_SwitchSelectedItem); + SetPokeStorageTask(Task_SwitchSelectedItem); break; case MENU_GIVE_2: PlaySE(SE_SELECT); - SetPSSCallback(Cb_GiveItemFromBag); + SetPokeStorageTask(Task_GiveItemFromBag); break; case MENU_INFO: - SetPSSCallback(Cb_ShowItemInfo); + SetPokeStorageTask(Task_ShowItemInfo); break; } break; case 3: PlaySE(SE_FAILURE); PrintMessage(MSG_LAST_POKE); - sPSSData->state = 6; + sStorage->state = 6; break; case 5: PlaySE(SE_FAILURE); PrintMessage(MSG_CANT_RELEASE_EGG); - sPSSData->state = 6; + sStorage->state = 6; break; case 4: PlaySE(SE_FAILURE); PrintMessage(MSG_PLEASE_REMOVE_MAIL); - sPSSData->state = 6; + sStorage->state = 6; break; case 6: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_MoveMon(u8 taskId) +static void Task_MoveMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: InitMonPlaceChange(CHANGE_GRAB); - sPSSData->state++; + sStorage->state++; break; case 1: if (!DoMonPlaceChange()) { if (sInPartyMenu) - SetPSSCallback(Cb_HandleMovingMonFromParty); + SetPokeStorageTask(Task_HandleMovingMonFromParty); else - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_PlaceMon(u8 taskId) +static void Task_PlaceMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: InitMonPlaceChange(CHANGE_PLACE); - sPSSData->state++; + sStorage->state++; break; case 1: if (!DoMonPlaceChange()) { if (sInPartyMenu) - SetPSSCallback(Cb_HandleMovingMonFromParty); + SetPokeStorageTask(Task_HandleMovingMonFromParty); else - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_ShiftMon(u8 taskId) +static void Task_ShiftMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: InitMonPlaceChange(CHANGE_SHIFT); - sPSSData->state++; + sStorage->state++; break; case 1: if (!DoMonPlaceChange()) { StartDisplayMonMosaicEffect(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_WithdrawMon(u8 taskId) +static void Task_WithdrawMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: if (CalculatePlayerPartyCount() == PARTY_SIZE) { PrintMessage(MSG_PARTY_FULL); - sPSSData->state = 1; + sStorage->state = 1; } else { SaveCursorPos(); InitMonPlaceChange(CHANGE_GRAB); - sPSSData->state = 2; + sStorage->state = 2; } break; case 1: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 2: @@ -2764,40 +2764,40 @@ static void Cb_WithdrawMon(u8 taskId) { SetMovingMonPriority(1); SetUpDoShowPartyMenu(); - sPSSData->state++; + sStorage->state++; } break; case 3: if (!DoShowPartyMenu()) { InitMonPlaceChange(CHANGE_PLACE); - sPSSData->state++; + sStorage->state++; } break; case 4: if (!DoMonPlaceChange()) { UpdatePartySlotColors(); - sPSSData->state++; + sStorage->state++; } break; case 5: - SetPSSCallback(Cb_HidePartyPokemon); + SetPokeStorageTask(Task_HidePartyPokemon); break; } } -static void Cb_DepositMenu(u8 taskId) +static void Task_DepositMenu(u8 taskId) { u8 boxId; - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); - LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); + LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); CreateChooseBoxMenuSprites(sDepositBoxId); - sPSSData->state++; + sStorage->state++; break; case 1: boxId = HandleChooseBoxMenuInput(); @@ -2809,7 +2809,7 @@ static void Cb_DepositMenu(u8 taskId) ClearBottomWindow(); DestroyChooseBoxMenuSprites(); FreeChooseBoxMenu(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; default: if (TryStorePartyMonInBox(boxId)) @@ -2818,12 +2818,12 @@ static void Cb_DepositMenu(u8 taskId) ClearBottomWindow(); DestroyChooseBoxMenuSprites(); FreeChooseBoxMenu(); - sPSSData->state = 2; + sStorage->state = 2; } else { PrintMessage(MSG_BOX_IS_FULL); - sPSSData->state = 4; + sStorage->state = 4; } break; } @@ -2831,7 +2831,7 @@ static void Cb_DepositMenu(u8 taskId) case 2: CompactPartySlots(); CompactPartySprites(); - sPSSData->state++; + sStorage->state++; break; case 3: if (GetNumPartySpritesCompacting() == 0) @@ -2839,27 +2839,27 @@ static void Cb_DepositMenu(u8 taskId) sub_80CE22C(); StartDisplayMonMosaicEffect(); UpdatePartySlotColors(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 4: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); - sPSSData->state = 1; + sStorage->state = 1; } break; } } -static void Cb_ReleaseMon(u8 taskId) +static void Task_ReleaseMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_RELEASE_POKE); ShowYesNoWindow(1); - sPSSData->state++; + sStorage->state++; // fallthrough case 1: switch (Menu_ProcessInputNoWrapClearOnChoose()) @@ -2867,13 +2867,13 @@ static void Cb_ReleaseMon(u8 taskId) case MENU_B_PRESSED: case 1: // No ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 0: // Yes ClearBottomWindow(); InitCanReleaseMonVars(); InitReleaseMon(); - sPSSData->state++; + sStorage->state++; break; } break; @@ -2886,12 +2886,12 @@ static void Cb_ReleaseMon(u8 taskId) s8 canRelease = RunCanReleaseMon(); if (canRelease == TRUE) { - sPSSData->state++; + sStorage->state++; break; } else if (!canRelease) { - sPSSData->state = 8; + sStorage->state = 8; break; } } @@ -2901,13 +2901,13 @@ static void Cb_ReleaseMon(u8 taskId) ReleaseMon(); RefreshDisplayMonData(); PrintMessage(MSG_WAS_RELEASED); - sPSSData->state++; + sStorage->state++; break; case 4: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintMessage(MSG_BYE_BYE); - sPSSData->state++; + sStorage->state++; } break; case 5: @@ -2918,11 +2918,11 @@ static void Cb_ReleaseMon(u8 taskId) { CompactPartySlots(); CompactPartySprites(); - sPSSData->state++; + sStorage->state++; } else { - sPSSData->state = 7; + sStorage->state = 7; } } break; @@ -2932,22 +2932,22 @@ static void Cb_ReleaseMon(u8 taskId) RefreshDisplayMon(); StartDisplayMonMosaicEffect(); UpdatePartySlotColors(); - sPSSData->state++; + sStorage->state++; } break; case 7: - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 8: // Start "can't release" sequence PrintMessage(MSG_WAS_RELEASED); - sPSSData->state++; + sStorage->state++; break; case 9: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintMessage(MSG_SURPRISE); - sPSSData->state++; + sStorage->state++; } break; case 10: @@ -2955,7 +2955,7 @@ static void Cb_ReleaseMon(u8 taskId) { ClearBottomWindow(); ReshowReleaseMon(); - sPSSData->state++; + sStorage->state++; } break; case 11: @@ -2963,68 +2963,68 @@ static void Cb_ReleaseMon(u8 taskId) { TrySetCursorFistAnim(); PrintMessage(MSG_CAME_BACK); - sPSSData->state++; + sStorage->state++; } break; case 12: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintMessage(MSG_WORRIED); - sPSSData->state++; + sStorage->state++; } break; case 13: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_ShowMarkMenu(u8 taskId) +static void Task_ShowMarkMenu(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_MARK_POKE); - sPSSData->markMenu.markings = sPSSData->displayMonMarkings; - OpenMonMarkingsMenu(sPSSData->displayMonMarkings, 0xb0, 0x10); - sPSSData->state++; + sStorage->markMenu.markings = sStorage->displayMonMarkings; + OpenMonMarkingsMenu(sStorage->displayMonMarkings, 0xb0, 0x10); + sStorage->state++; break; case 1: if (!HandleMonMarkingsMenuInput()) { FreeMonMarkingsMenu(); ClearBottomWindow(); - SetMonMarkings(sPSSData->markMenu.markings); + SetMonMarkings(sStorage->markMenu.markings); RefreshDisplayMonData(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_TakeItemForMoving(u8 taskId) +static void Task_TakeItemForMoving(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: - if (!ItemIsMail(sPSSData->displayMonItemId)) + if (!ItemIsMail(sStorage->displayMonItemId)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } else { - SetPSSCallback(Cb_PrintCantStoreMail); + SetPokeStorageTask(Task_PrintCantStoreMail); } break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); TakeItemFromMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); - sPSSData->state++; + sStorage->state++; break; case 2: if (!IsItemIconAnimActive()) @@ -3033,28 +3033,28 @@ static void Cb_TakeItemForMoving(u8 taskId) ClearBottomWindow(); RefreshDisplayMon(); PrintDisplayMonInfo(); - sPSSData->state++; + sStorage->state++; } break; case 3: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_GiveMovingItemToMon(u8 taskId) +static void Task_GiveMovingItemToMon(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); GiveItemToMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); - sPSSData->state++; + sStorage->state++; break; case 2: if (!IsItemIconAnimActive()) @@ -3063,46 +3063,46 @@ static void Cb_GiveMovingItemToMon(u8 taskId) RefreshDisplayMon(); PrintDisplayMonInfo(); PrintMessage(MSG_ITEM_IS_HELD); - sPSSData->state++; + sStorage->state++; } break; case 3: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } break; case 4: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_ItemToBag(u8 taskId) +static void Task_ItemToBag(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: - if (!AddBagItem(sPSSData->displayMonItemId, 1)) + if (!AddBagItem(sStorage->displayMonItemId, 1)) { PlaySE(SE_FAILURE); PrintMessage(MSG_BAG_FULL); - sPSSData->state = 3; + sStorage->state = 3; } else { PlaySE(SE_SELECT); MoveItemFromMonToBag(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); - sPSSData->state = 1; + sStorage->state = 1; } break; case 1: if (!IsItemIconAnimActive()) { PrintMessage(MSG_PLACED_IN_BAG); - sPSSData->state = 2; + sStorage->state = 2; } break; case 2: @@ -3111,42 +3111,42 @@ static void Cb_ItemToBag(u8 taskId) ClearBottomWindow(); RefreshDisplayMon(); PrintDisplayMonInfo(); - sPSSData->state = 4; + sStorage->state = 4; } break; case 4: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 3: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_SwitchSelectedItem(u8 taskId) +static void Task_SwitchSelectedItem(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: - if (!ItemIsMail(sPSSData->displayMonItemId)) + if (!ItemIsMail(sStorage->displayMonItemId)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } else { - SetPSSCallback(Cb_PrintCantStoreMail); + SetPokeStorageTask(Task_PrintCantStoreMail); } break; case 1: StartCursorAnim(CURSOR_ANIM_OPEN); SwapItemsWithMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetCursorPosition()); - sPSSData->state++; + sStorage->state++; break; case 2: if (!IsItemIconAnimActive()) @@ -3155,30 +3155,30 @@ static void Cb_SwitchSelectedItem(u8 taskId) RefreshDisplayMon(); PrintDisplayMonInfo(); PrintMessage(MSG_CHANGED_TO_ITEM); - sPSSData->state++; + sStorage->state++; } break; case 3: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } break; case 4: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_ShowItemInfo(u8 taskId) +static void Task_ShowItemInfo(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; break; case 1: if (!IsDma3ManagerBusyWithBgCopy()) @@ -3186,44 +3186,44 @@ static void Cb_ShowItemInfo(u8 taskId) PlaySE(SE_WIN_OPEN); PrintItemDescription(); InitItemInfoWindow(); - sPSSData->state++; + sStorage->state++; } break; case 2: if (!UpdateItemInfoWindowSlideIn()) - sPSSData->state++; + sStorage->state++; break; case 3: if (!IsDma3ManagerBusyWithBgCopy()) - sPSSData->state++; + sStorage->state++; break; case 4: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { PlaySE(SE_WIN_OPEN); - sPSSData->state++; + sStorage->state++; } break; case 5: if (!UpdateItemInfoWindowSlideOut()) - sPSSData->state++; + sStorage->state++; break; case 6: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_CloseBoxWhileHoldingItem(u8 taskId) +static void Task_CloseBoxWhileHoldingItem(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PlaySE(SE_SELECT); PrintMessage(MSG_PUT_IN_BAG); ShowYesNoWindow(0); - sPSSData->state = 1; + sStorage->state = 1; break; case 1: switch (Menu_ProcessInputNoWrapClearOnChoose()) @@ -3231,18 +3231,18 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) case MENU_B_PRESSED: case 1: // No ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 0:// Yes - if (AddBagItem(sPSSData->movingItemId, 1) == TRUE) + if (AddBagItem(sStorage->movingItemId, 1) == TRUE) { ClearBottomWindow(); - sPSSData->state = 3; + sStorage->state = 3; } else { PrintMessage(MSG_BAG_FULL); - sPSSData->state = 2; + sStorage->state = 2; } break; } @@ -3251,86 +3251,86 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state = 5; + sStorage->state = 5; } break; case 3: MoveItemFromCursorToBag(); - sPSSData->state = 4; + sStorage->state = 4; break; case 4: if (!IsItemIconAnimActive()) { StartCursorAnim(CURSOR_ANIM_BOUNCE); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 5: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } -static void Cb_HandleMovingMonFromParty(u8 taskId) +static void Task_HandleMovingMonFromParty(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: CompactPartySlots(); CompactPartySprites(); - sPSSData->state++; + sStorage->state++; break; case 1: if (GetNumPartySpritesCompacting() == 0) { UpdatePartySlotColors(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_PrintCantStoreMail(u8 taskId) +static void Task_PrintCantStoreMail(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_CANT_STORE_MAIL); - sPSSData->state++; + sStorage->state++; break; case 1: if (!IsDma3ManagerBusyWithBgCopy()) - sPSSData->state++; + sStorage->state++; break; case 2: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; } break; case 3: if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; } } // Handle options menu that shows when the box title bar is selected -static void Cb_HandleBoxOptions(u8 taskId) +static void Task_HandleBoxOptions(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_WHAT_YOU_DO); AddMenu(); - sPSSData->state++; + sStorage->state++; break; case 1: if (IsMenuLoading()) return; - sPSSData->state++; + sStorage->state++; case 2: switch (HandleMenuInput()) { @@ -3338,48 +3338,48 @@ static void Cb_HandleBoxOptions(u8 taskId) case MENU_CANCEL: AnimateBoxScrollArrows(TRUE); ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case MENU_NAME: PlaySE(SE_SELECT); - SetPSSCallback(Cb_NameBox); + SetPokeStorageTask(Task_NameBox); break; case MENU_WALLPAPER: PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_HandleWallpapers); + SetPokeStorageTask(Task_HandleWallpapers); break; case MENU_JUMP: PlaySE(SE_SELECT); ClearBottomWindow(); - SetPSSCallback(Cb_JumpBox); + SetPokeStorageTask(Task_JumpBox); break; } break; } } -static void Cb_HandleWallpapers(u8 taskId) +static void Task_HandleWallpapers(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: AddWallpaperSetsMenu(); PrintMessage(MSG_PICK_A_THEME); - sPSSData->state++; + sStorage->state++; break; case 1: if (!IsMenuLoading()) - sPSSData->state++; + sStorage->state++; break; case 2: - sPSSData->wallpaperSetId = HandleMenuInput(); - switch (sPSSData->wallpaperSetId) + sStorage->wallpaperSetId = HandleMenuInput(); + switch (sStorage->wallpaperSetId) { case MENU_B_PRESSED: AnimateBoxScrollArrows(TRUE); ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case MENU_SCENERY_1: case MENU_SCENERY_2: @@ -3387,43 +3387,43 @@ static void Cb_HandleWallpapers(u8 taskId) case MENU_ETCETERA: PlaySE(SE_SELECT); RemoveMenu(); - sPSSData->wallpaperSetId -= MENU_WALLPAPER_SETS_START; - sPSSData->state++; + sStorage->wallpaperSetId -= MENU_WALLPAPER_SETS_START; + sStorage->state++; break; case MENU_FRIENDS: // New wallpaper from Walda. PlaySE(SE_SELECT); - sPSSData->wallpaperId = WALLPAPER_FRIENDS; + sStorage->wallpaperId = WALLPAPER_FRIENDS; RemoveMenu(); ClearBottomWindow(); - sPSSData->state = 6; + sStorage->state = 6; break; } break; case 3: if (!IsDma3ManagerBusyWithBgCopy()) { - AddWallpapersMenu(sPSSData->wallpaperSetId); + AddWallpapersMenu(sStorage->wallpaperSetId); PrintMessage(MSG_PICK_A_WALLPAPER); - sPSSData->state++; + sStorage->state++; } break; case 4: - sPSSData->wallpaperId = HandleMenuInput(); - switch (sPSSData->wallpaperId) + sStorage->wallpaperId = HandleMenuInput(); + switch (sStorage->wallpaperId) { case MENU_NOTHING_CHOSEN: break; case MENU_B_PRESSED: ClearBottomWindow(); - sPSSData->state = 0; + sStorage->state = 0; break; default: PlaySE(SE_SELECT); ClearBottomWindow(); - sPSSData->wallpaperId -= MENU_WALLPAPERS_START; - SetWallpaperForCurrentBox(sPSSData->wallpaperId); - sPSSData->state++; + sStorage->wallpaperId -= MENU_WALLPAPERS_START; + SetWallpaperForCurrentBox(sStorage->wallpaperId); + sStorage->state++; break; } break; @@ -3431,32 +3431,32 @@ static void Cb_HandleWallpapers(u8 taskId) if (!DoWallpaperGfxChange()) { AnimateBoxScrollArrows(TRUE); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 6: if (!IsDma3ManagerBusyWithBgCopy()) { - SetWallpaperForCurrentBox(sPSSData->wallpaperId); - sPSSData->state = 5; + SetWallpaperForCurrentBox(sStorage->wallpaperId); + sStorage->state = 5; } break; } } -static void Cb_JumpBox(u8 taskId) +static void Task_JumpBox(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: PrintMessage(MSG_JUMP_TO_WHICH_BOX); - LoadChooseBoxMenuGfx(&sPSSData->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); + LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); CreateChooseBoxMenuSprites(StorageGetCurrentBox()); - sPSSData->state++; + sStorage->state++; break; case 1: - sPSSData->newCurrBoxId = HandleChooseBoxMenuInput(); - switch (sPSSData->newCurrBoxId) + sStorage->newCurrBoxId = HandleChooseBoxMenuInput(); + switch (sStorage->newCurrBoxId) { case BOXID_NONE_CHOSEN: break; @@ -3464,119 +3464,119 @@ static void Cb_JumpBox(u8 taskId) ClearBottomWindow(); DestroyChooseBoxMenuSprites(); FreeChooseBoxMenu(); - if (sPSSData->newCurrBoxId == BOXID_CANCELED || sPSSData->newCurrBoxId == StorageGetCurrentBox()) + if (sStorage->newCurrBoxId == BOXID_CANCELED || sStorage->newCurrBoxId == StorageGetCurrentBox()) { AnimateBoxScrollArrows(TRUE); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } else { - sPSSData->state++; + sStorage->state++; } break; } break; case 2: - SetUpScrollToBox(sPSSData->newCurrBoxId); - sPSSData->state++; + SetUpScrollToBox(sStorage->newCurrBoxId); + sStorage->state++; break; case 3: if (!ScrollToBox()) { - SetCurrentBox(sPSSData->newCurrBoxId); - SetPSSCallback(Cb_MainPSS); + SetCurrentBox(sStorage->newCurrBoxId); + SetPokeStorageTask(Task_PokeStorageMain); } break; } } -static void Cb_NameBox(u8 taskId) +static void Task_NameBox(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: SaveMovingMon(); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sPSSData->state++; + sStorage->state++; break; case 1: if (!UpdatePaletteFade()) { sWhichToReshow = SCREEN_CHANGE_NAME_BOX - 1; - sPSSData->screenChangeType = SCREEN_CHANGE_NAME_BOX; - SetPSSCallback(Cb_ChangeScreen); + sStorage->screenChangeType = SCREEN_CHANGE_NAME_BOX; + SetPokeStorageTask(Task_ChangeScreen); } break; } } -static void Cb_ShowMonSummary(u8 taskId) +static void Task_ShowMonSummary(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: InitSummaryScreenData(); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sPSSData->state++; + sStorage->state++; break; case 1: if (!UpdatePaletteFade()) { sWhichToReshow = SCREEN_CHANGE_SUMMARY_SCREEN - 1; - sPSSData->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN; - SetPSSCallback(Cb_ChangeScreen); + sStorage->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN; + SetPokeStorageTask(Task_ChangeScreen); } break; } } -static void Cb_GiveItemFromBag(u8 taskId) +static void Task_GiveItemFromBag(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sPSSData->state++; + sStorage->state++; break; case 1: if (!UpdatePaletteFade()) { sWhichToReshow = SCREEN_CHANGE_ITEM_FROM_BAG - 1; - sPSSData->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG; - SetPSSCallback(Cb_ChangeScreen); + sStorage->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG; + SetPokeStorageTask(Task_ChangeScreen); } break; } } -static void Cb_OnCloseBoxPressed(u8 taskId) +static void Task_OnCloseBoxPressed(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: if (IsMonBeingMoved()) { PlaySE(SE_FAILURE); PrintMessage(MSG_HOLDING_POKE); - sPSSData->state = 1; + sStorage->state = 1; } else if (IsMovingItem()) { - SetPSSCallback(Cb_CloseBoxWhileHoldingItem); + SetPokeStorageTask(Task_CloseBoxWhileHoldingItem); } else { PlaySE(SE_SELECT); PrintMessage(MSG_EXIT_BOX); ShowYesNoWindow(0); - sPSSData->state = 2; + sStorage->state = 2; } break; case 1: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 2: @@ -3585,59 +3585,59 @@ static void Cb_OnCloseBoxPressed(u8 taskId) case MENU_B_PRESSED: case 1: ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 0: PlaySE(SE_PC_OFF); ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; break; } break; case 3: ComputerScreenCloseEffect(20, 0, 1); - sPSSData->state++; + sStorage->state++; break; case 4: if (!IsComputerScreenCloseEffectActive()) { sub_80CABE0(); gPlayerPartyCount = CalculatePlayerPartyCount(); - sPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX; - SetPSSCallback(Cb_ChangeScreen); + sStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; + SetPokeStorageTask(Task_ChangeScreen); } break; } } -static void Cb_OnBPressed(u8 taskId) +static void Task_OnBPressed(u8 taskId) { - switch (sPSSData->state) + switch (sStorage->state) { case 0: if (IsMonBeingMoved()) { PlaySE(SE_FAILURE); PrintMessage(MSG_HOLDING_POKE); - sPSSData->state = 1; + sStorage->state = 1; } else if (IsMovingItem()) { - SetPSSCallback(Cb_CloseBoxWhileHoldingItem); + SetPokeStorageTask(Task_CloseBoxWhileHoldingItem); } else { PlaySE(SE_SELECT); PrintMessage(MSG_CONTINUE_BOX); ShowYesNoWindow(0); - sPSSData->state = 2; + sStorage->state = 2; } break; case 1: if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); } break; case 2: @@ -3645,39 +3645,39 @@ static void Cb_OnBPressed(u8 taskId) { case 0: ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); + SetPokeStorageTask(Task_PokeStorageMain); break; case 1: case MENU_B_PRESSED: PlaySE(SE_PC_OFF); ClearBottomWindow(); - sPSSData->state++; + sStorage->state++; break; } break; case 3: ComputerScreenCloseEffect(20, 0, 0); - sPSSData->state++; + sStorage->state++; break; case 4: if (!IsComputerScreenCloseEffectActive()) { sub_80CABE0(); gPlayerPartyCount = CalculatePlayerPartyCount(); - sPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX; - SetPSSCallback(Cb_ChangeScreen); + sStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; + SetPokeStorageTask(Task_ChangeScreen); } break; } } -static void Cb_ChangeScreen(u8 taskId) +static void Task_ChangeScreen(u8 taskId) { struct BoxPokemon *boxMons; u8 mode, monIndex, maxMonIndex; - u8 screenChangeType = sPSSData->screenChangeType; + u8 screenChangeType = sStorage->screenChangeType; - if (sPSSData->boxOption == OPTION_MOVE_ITEMS && IsMovingItem() == TRUE) + if (sStorage->boxOption == OPTION_MOVE_ITEMS && IsMovingItem() == TRUE) sMovingItemId = GetMovingItemId(); else sMovingItemId = ITEM_NONE; @@ -3686,27 +3686,27 @@ static void Cb_ChangeScreen(u8 taskId) { case SCREEN_CHANGE_EXIT_BOX: default: - FreePSSData(); - SetMainCallback2(Cb2_ExitPSS); + FreePokeStorageData(); + SetMainCallback2(CB2_ExitPokeStorage); break; case SCREEN_CHANGE_SUMMARY_SCREEN: - boxMons = sPSSData->summaryMon.box; - monIndex = sPSSData->summaryStartPos; - maxMonIndex = sPSSData->summaryMaxPos; - mode = sPSSData->summaryScreenMode; - FreePSSData(); + boxMons = sStorage->summaryMon.box; + monIndex = sStorage->summaryStartPos; + maxMonIndex = sStorage->summaryMaxPos; + mode = sStorage->summaryScreenMode; + FreePokeStorageData(); if (mode == SUMMARY_MODE_NORMAL && boxMons == &sSavedMovingMon.box) - ShowPokemonSummaryScreenSet40EF(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); + ShowPokemonSummaryScreenSet40EF(mode, boxMons, monIndex, maxMonIndex, CB2_ReturnToPokeStorage); else - ShowPokemonSummaryScreen(mode, boxMons, monIndex, maxMonIndex, Cb2_ReturnToPSS); + ShowPokemonSummaryScreen(mode, boxMons, monIndex, maxMonIndex, CB2_ReturnToPokeStorage); break; case SCREEN_CHANGE_NAME_BOX: - FreePSSData(); - DoNamingScreen(NAMING_SCREEN_BOX, GetBoxNamePtr(StorageGetCurrentBox()), 0, 0, 0, Cb2_ReturnToPSS); + FreePokeStorageData(); + DoNamingScreen(NAMING_SCREEN_BOX, GetBoxNamePtr(StorageGetCurrentBox()), 0, 0, 0, CB2_ReturnToPokeStorage); break; case SCREEN_CHANGE_ITEM_FROM_BAG: - FreePSSData(); - GoToBagMenu(ITEMMENULOCATION_PCBOX, 0, Cb2_ReturnToPSS); + FreePokeStorageData(); + GoToBagMenu(ITEMMENULOCATION_PCBOX, 0, CB2_ReturnToPokeStorage); break; } @@ -3729,11 +3729,11 @@ static void GiveChosenBagItem(void) } } -static void FreePSSData(void) +static void FreePokeStorageData(void) { TilemapUtil_Free(); MultiMove_Free(); - FREE_AND_SET_NULL(sPSSData); + FREE_AND_SET_NULL(sStorage); FreeAllWindowBuffers(); } @@ -3750,17 +3750,17 @@ static void ScrollBackground(void) ChangeBgY(3, 128, 2); } -static void LoadPSSMenuGfx(void) +static void LoadPokeStorageMenuGfx(void) { InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); DecompressAndLoadBgGfxUsingHeap(1, gStorageSystemMenu_Gfx, 0, 0, 0); - LZ77UnCompWram(sDisplayMenu_Tilemap, sPSSData->displayMenuTilemapBuffer); - SetBgTilemapBuffer(1, sPSSData->displayMenuTilemapBuffer); + LZ77UnCompWram(sDisplayMenu_Tilemap, sStorage->displayMenuTilemapBuffer); + SetBgTilemapBuffer(1, sStorage->displayMenuTilemapBuffer); ShowBg(1); ScheduleBgCopyTilemapToVram(1); } -static bool8 InitPSSWindows(void) +static bool8 InitPokeStorageWindows(void) { if (!InitWindows(sWindowTemplates)) { @@ -3783,7 +3783,7 @@ static void sub_80CA0D8(void) LoadPalette(sInterface_Pal, 0, sizeof(sInterface_Pal)); LoadPalette(sPkmnDataGray_Pal, 0x20, sizeof(sPkmnDataGray_Pal)); LoadPalette(gUnknown_085726F4, 0xF0, sizeof(gUnknown_085726F4)); - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) LoadPalette(sBg_Pal, 0x30, sizeof(sBg_Pal)); else LoadPalette(sBgMoveItems_Pal, 0x30, sizeof(sBgMoveItems_Pal)); @@ -3797,12 +3797,12 @@ static void sub_80CA0D8(void) static void CreateMarkingComboSprite(void) { - sPSSData->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MARKING_COMBO, PALTAG_MARKING_COMBO, NULL); - sPSSData->markingComboSprite->oam.priority = 1; - sPSSData->markingComboSprite->subpriority = 1; - sPSSData->markingComboSprite->pos1.x = 40; - sPSSData->markingComboSprite->pos1.y = 150; - sPSSData->markingComboTilesPtr = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MARKING_COMBO); + sStorage->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MARKING_COMBO, PALTAG_MARKING_COMBO, NULL); + sStorage->markingComboSprite->oam.priority = 1; + sStorage->markingComboSprite->subpriority = 1; + sStorage->markingComboSprite->pos1.x = 40; + sStorage->markingComboSprite->pos1.y = 150; + sStorage->markingComboTilesPtr = (void*) OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MARKING_COMBO); } static void CreateWaveformSprites(void) @@ -3811,16 +3811,16 @@ static void CreateWaveformSprites(void) struct SpriteSheet sheet = sSpriteSheet_Waveform; LoadSpriteSheet(&sheet); - for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) + for (i = 0; i < ARRAY_COUNT(sStorage->waveformSprites); i++) { u8 spriteId = CreateSprite(&sSpriteTemplate_Waveform, i * 63 + 8, 9, 2); - sPSSData->waveformSprites[i] = &gSprites[spriteId]; + sStorage->waveformSprites[i] = &gSprites[spriteId]; } } static void RefreshDisplayMonData(void) { - LoadDisplayMonGfx(sPSSData->displayMonSpecies, sPSSData->displayMonPersonality); + LoadDisplayMonGfx(sStorage->displayMonSpecies, sStorage->displayMonPersonality); PrintDisplayMonInfo(); UpdateWaveformAnimation(); ScheduleBgCopyTilemapToVram(0); @@ -3829,19 +3829,19 @@ static void RefreshDisplayMonData(void) static void StartDisplayMonMosaicEffect(void) { RefreshDisplayMonData(); - if (sPSSData->displayMonSprite) + if (sStorage->displayMonSprite) { - sPSSData->displayMonSprite->oam.mosaic = TRUE; - sPSSData->displayMonSprite->data[0] = 10; - sPSSData->displayMonSprite->data[1] = 1; - sPSSData->displayMonSprite->callback = SpriteCB_DisplayMonMosaic; - SetGpuReg(REG_OFFSET_MOSAIC, (sPSSData->displayMonSprite->data[0] << 12) | (sPSSData->displayMonSprite->data[0] << 8)); + sStorage->displayMonSprite->oam.mosaic = TRUE; + sStorage->displayMonSprite->data[0] = 10; + sStorage->displayMonSprite->data[1] = 1; + sStorage->displayMonSprite->callback = SpriteCB_DisplayMonMosaic; + SetGpuReg(REG_OFFSET_MOSAIC, (sStorage->displayMonSprite->data[0] << 12) | (sStorage->displayMonSprite->data[0] << 8)); } } static u8 IsDisplayMosaicActive(void) { - return sPSSData->displayMonSprite->oam.mosaic; + return sStorage->displayMonSprite->oam.mosaic; } static void SpriteCB_DisplayMonMosaic(struct Sprite *sprite) @@ -3863,16 +3863,16 @@ static void CreateDisplayMonSprite(void) u16 tileStart; u8 palSlot; u8 spriteId; - struct SpriteSheet sheet = {sPSSData->tileBuffer, MON_PIC_SIZE, GFXTAG_DISPLAY_MON}; - struct SpritePalette palette = {sPSSData->displayMonPalBuffer, PALTAG_DISPLAY_MON}; + struct SpriteSheet sheet = {sStorage->tileBuffer, MON_PIC_SIZE, GFXTAG_DISPLAY_MON}; + struct SpritePalette palette = {sStorage->displayMonPalBuffer, PALTAG_DISPLAY_MON}; struct SpriteTemplate template = sSpriteTemplate_DisplayMon; for (i = 0; i < MON_PIC_SIZE; i++) - sPSSData->tileBuffer[i] = 0; + sStorage->tileBuffer[i] = 0; for (i = 0; i < 16; i++) - sPSSData->displayMonPalBuffer[i] = 0; + sStorage->displayMonPalBuffer[i] = 0; - sPSSData->displayMonSprite = NULL; + sStorage->displayMonSprite = NULL; do { @@ -3888,12 +3888,12 @@ static void CreateDisplayMonSprite(void) if (spriteId == MAX_SPRITES) break; - sPSSData->displayMonSprite = &gSprites[spriteId]; - sPSSData->displayMonPalOffset = palSlot * 16 + 0x100; - sPSSData->displayMonTilePtr = (void*) OBJ_VRAM0 + tileStart * 32; + sStorage->displayMonSprite = &gSprites[spriteId]; + sStorage->displayMonPalOffset = palSlot * 16 + 0x100; + sStorage->displayMonTilePtr = (void*) OBJ_VRAM0 + tileStart * 32; } while (0); - if (sPSSData->displayMonSprite == NULL) + if (sStorage->displayMonSprite == NULL) { FreeSpriteTilesByTag(GFXTAG_DISPLAY_MON); FreeSpritePaletteByTag(PALTAG_DISPLAY_MON); @@ -3902,50 +3902,50 @@ static void CreateDisplayMonSprite(void) static void LoadDisplayMonGfx(u16 species, u32 pid) { - if (sPSSData->displayMonSprite == NULL) + if (sStorage->displayMonSprite == NULL) return; if (species != SPECIES_NONE) { - LoadSpecialPokePic(&gMonFrontPicTable[species], sPSSData->tileBuffer, species, pid, TRUE); - LZ77UnCompWram(sPSSData->displayMonPalette, sPSSData->displayMonPalBuffer); - CpuCopy32(sPSSData->tileBuffer, sPSSData->displayMonTilePtr, MON_PIC_SIZE); - LoadPalette(sPSSData->displayMonPalBuffer, sPSSData->displayMonPalOffset, 0x20); - sPSSData->displayMonSprite->invisible = FALSE; + LoadSpecialPokePic(&gMonFrontPicTable[species], sStorage->tileBuffer, species, pid, TRUE); + LZ77UnCompWram(sStorage->displayMonPalette, sStorage->displayMonPalBuffer); + CpuCopy32(sStorage->tileBuffer, sStorage->displayMonTilePtr, MON_PIC_SIZE); + LoadPalette(sStorage->displayMonPalBuffer, sStorage->displayMonPalOffset, 0x20); + sStorage->displayMonSprite->invisible = FALSE; } else { - sPSSData->displayMonSprite->invisible = TRUE; + sStorage->displayMonSprite->invisible = TRUE; } } static void PrintDisplayMonInfo(void) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - AddTextPrinterParameterized(0, 1, sPSSData->displayMonNameText, 6, 0, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->displayMonSpeciesName, 6, 15, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->displayMonGenderLvlText, 10, 29, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 0, sPSSData->displayMonItemName, 6, 43, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 1, sStorage->displayMonNameText, 6, 0, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sStorage->displayMonSpeciesName, 6, 15, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sStorage->displayMonGenderLvlText, 10, 29, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 0, sStorage->displayMonItemName, 6, 43, TEXT_SPEED_FF, NULL); } else { - AddTextPrinterParameterized(0, 0, sPSSData->displayMonItemName, 6, 0, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 1, sPSSData->displayMonNameText, 6, 13, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->displayMonSpeciesName, 6, 28, TEXT_SPEED_FF, NULL); - AddTextPrinterParameterized(0, 2, sPSSData->displayMonGenderLvlText, 10, 42, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 0, sStorage->displayMonItemName, 6, 0, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 1, sStorage->displayMonNameText, 6, 13, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sStorage->displayMonSpeciesName, 6, 28, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(0, 2, sStorage->displayMonGenderLvlText, 10, 42, TEXT_SPEED_FF, NULL); } CopyWindowToVram(0, 2); - if (sPSSData->displayMonSpecies != SPECIES_NONE) + if (sStorage->displayMonSpecies != SPECIES_NONE) { - UpdateMonMarkingTiles(sPSSData->displayMonMarkings, sPSSData->markingComboTilesPtr); - sPSSData->markingComboSprite->invisible = FALSE; + UpdateMonMarkingTiles(sStorage->displayMonMarkings, sStorage->markingComboTilesPtr); + sStorage->markingComboSprite->invisible = FALSE; } else { - sPSSData->markingComboSprite->invisible = TRUE; + sStorage->markingComboSprite->invisible = TRUE; } } @@ -3954,19 +3954,19 @@ static void UpdateWaveformAnimation(void) { u16 i; - if (sPSSData->displayMonSpecies != SPECIES_NONE) + if (sStorage->displayMonSpecies != SPECIES_NONE) { // Start waveform animation and color "Pkmn Data" TilemapUtil_SetRect(TILEMAPID_PKMN_DATA, 0, 0, 8, 2); - for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) - StartSpriteAnimIfDifferent(sPSSData->waveformSprites[i], i * 2 + 1); + for (i = 0; i < ARRAY_COUNT(sStorage->waveformSprites); i++) + StartSpriteAnimIfDifferent(sStorage->waveformSprites[i], i * 2 + 1); } else { // Stop waveform animation and gray out "Pkmn Data" TilemapUtil_SetRect(TILEMAPID_PKMN_DATA, 0, 2, 8, 2); - for (i = 0; i < ARRAY_COUNT(sPSSData->waveformSprites); i++) - StartSpriteAnim(sPSSData->waveformSprites[i], i * 2); + for (i = 0; i < ARRAY_COUNT(sStorage->waveformSprites); i++) + StartSpriteAnim(sStorage->waveformSprites[i], i * 2); } TilemapUtil_Update(TILEMAPID_PKMN_DATA); @@ -3975,9 +3975,9 @@ static void UpdateWaveformAnimation(void) static void InitSupplementalTilemaps(void) { - LZ77UnCompWram(gStorageSystemPartyMenu_Tilemap, sPSSData->partyMenuTilemapBuffer); + LZ77UnCompWram(gStorageSystemPartyMenu_Tilemap, sStorage->partyMenuTilemapBuffer); LoadPalette(gStorageSystemPartyMenu_Pal, 0x10, 0x20); - TilemapUtil_SetMap(TILEMAPID_PARTY_MENU, 1, sPSSData->partyMenuTilemapBuffer, 12, 22); + TilemapUtil_SetMap(TILEMAPID_PARTY_MENU, 1, sStorage->partyMenuTilemapBuffer, 12, 22); TilemapUtil_SetMap(TILEMAPID_CLOSE_BUTTON, 1, sCloseBoxButton_Tilemap, 9, 4); TilemapUtil_SetPos(TILEMAPID_PARTY_MENU, 10, 0); TilemapUtil_SetPos(TILEMAPID_CLOSE_BUTTON, 21, 0); @@ -3998,29 +3998,29 @@ static void InitSupplementalTilemaps(void) } ScheduleBgCopyTilemapToVram(1); - sPSSData->closeBoxFlashing = FALSE; + sStorage->closeBoxFlashing = FALSE; } static void SetUpShowPartyMenu(void) { - sPSSData->partyMenuUnused = 20; - sPSSData->partyMenuY = 2; - sPSSData->partyMenuMoveTimer = 0; + sStorage->partyMenuUnused = 20; + sStorage->partyMenuY = 2; + sStorage->partyMenuMoveTimer = 0; CreatePartyMonsSprites(FALSE); } static bool8 ShowPartyMenu(void) { - if (sPSSData->partyMenuMoveTimer == 20) + if (sStorage->partyMenuMoveTimer == 20) return FALSE; - sPSSData->partyMenuUnused--; - sPSSData->partyMenuY++; + sStorage->partyMenuUnused--; + sStorage->partyMenuY++; TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, 1); TilemapUtil_Update(TILEMAPID_PARTY_MENU); ScheduleBgCopyTilemapToVram(1); MovePartySprites(8); - if (++sPSSData->partyMenuMoveTimer == 20) + if (++sStorage->partyMenuMoveTimer == 20) { sInPartyMenu = TRUE; return FALSE; @@ -4033,24 +4033,24 @@ static bool8 ShowPartyMenu(void) static void SetUpHidePartyMenu(void) { - sPSSData->partyMenuUnused = 0; - sPSSData->partyMenuY = 22; - sPSSData->partyMenuMoveTimer = 0; - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + sStorage->partyMenuUnused = 0; + sStorage->partyMenuY = 22; + sStorage->partyMenuMoveTimer = 0; + if (sStorage->boxOption == OPTION_MOVE_ITEMS) MoveHeldItemWithPartyMenu(); } static bool8 HidePartyMenu(void) { - if (sPSSData->partyMenuMoveTimer != 20) + if (sStorage->partyMenuMoveTimer != 20) { - sPSSData->partyMenuUnused++; - sPSSData->partyMenuY--; + sStorage->partyMenuUnused++; + sStorage->partyMenuY--; TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, -1); TilemapUtil_Update(TILEMAPID_PARTY_MENU); - FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sPSSData->partyMenuY, 12, 1); + FillBgTilemapBufferRect_Palette0(1, 0x100, 10, sStorage->partyMenuY, 12, 1); MovePartySprites(-8); - if (++sPSSData->partyMenuMoveTimer != 20) + if (++sStorage->partyMenuMoveTimer != 20) { ScheduleBgCopyTilemapToVram(1); return TRUE; @@ -4086,27 +4086,27 @@ static void UpdateCloseBoxButtonTilemap(bool8 normal) static void StartFlashingCloseBoxButton(void) { - sPSSData->closeBoxFlashing = TRUE; - sPSSData->closeBoxFlashTimer = 30; - sPSSData->closeBoxFlashState = TRUE; + sStorage->closeBoxFlashing = TRUE; + sStorage->closeBoxFlashTimer = 30; + sStorage->closeBoxFlashState = TRUE; } static void StopFlashingCloseBoxButton(void) { - if (sPSSData->closeBoxFlashing) + if (sStorage->closeBoxFlashing) { - sPSSData->closeBoxFlashing = FALSE; + sStorage->closeBoxFlashing = FALSE; UpdateCloseBoxButtonTilemap(TRUE); } } static void UpdateCloseBoxButtonFlash(void) { - if (sPSSData->closeBoxFlashing && ++sPSSData->closeBoxFlashTimer > 30) + if (sStorage->closeBoxFlashing && ++sStorage->closeBoxFlashTimer > 30) { - sPSSData->closeBoxFlashTimer = 0; - sPSSData->closeBoxFlashState = (sPSSData->closeBoxFlashState == FALSE); - UpdateCloseBoxButtonTilemap(sPSSData->closeBoxFlashState); + sStorage->closeBoxFlashTimer = 0; + sStorage->closeBoxFlashState = (sStorage->closeBoxFlashState == FALSE); + UpdateCloseBoxButtonTilemap(sStorage->closeBoxFlashState); } } @@ -4139,7 +4139,7 @@ static void SetPartySlotTilemap(u8 partyId, bool8 hasMon) for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) - sPSSData->partyMenuTilemapBuffer[index + j] = data[j]; + sStorage->partyMenuTilemapBuffer[index + j] = data[j]; data += 4; index += 12; @@ -4156,28 +4156,28 @@ static void UpdatePartySlotColors(void) static void SetUpDoShowPartyMenu(void) { - sPSSData->showPartyMenuState = 0; + sStorage->showPartyMenuState = 0; PlaySE(SE_WIN_OPEN); SetUpShowPartyMenu(); } static bool8 DoShowPartyMenu(void) { - switch (sPSSData->showPartyMenuState) + switch (sStorage->showPartyMenuState) { case 0: if (!ShowPartyMenu()) { SetCursorInParty(); - sPSSData->showPartyMenuState++; + sStorage->showPartyMenuState++; } break; case 1: if (!UpdateCursorPos()) { - if (sPSSData->setMosaic) + if (sStorage->setMosaic) StartDisplayMonMosaicEffect(); - sPSSData->showPartyMenuState++; + sStorage->showPartyMenuState++; } break; case 2: @@ -4215,30 +4215,30 @@ static void PrintMessage(u8 id) case MSG_VAR_MON_NAME_1: case MSG_VAR_MON_NAME_2: case MSG_VAR_MON_NAME_3: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->displayMonName); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sStorage->displayMonName); break; case MSG_VAR_RELEASE_MON_1: case MSG_VAR_RELEASE_MON_2: case MSG_VAR_RELEASE_MON_3: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->releaseMonName); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sStorage->releaseMonName); break; case MSG_VAR_ITEM_NAME: if (IsMovingItem()) - txtPtr = StringCopy(sPSSData->itemName, GetMovingItemName()); + txtPtr = StringCopy(sStorage->itemName, GetMovingItemName()); else - txtPtr = StringCopy(sPSSData->itemName, sPSSData->displayMonItemName); + txtPtr = StringCopy(sStorage->itemName, sStorage->displayMonItemName); while (*(txtPtr - 1) == CHAR_SPACE) txtPtr--; *txtPtr = EOS; - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sPSSData->itemName); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, sStorage->itemName); break; } - DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->messageText, sMessages[id].text); + DynamicPlaceholderTextUtil_ExpandPlaceholders(sStorage->messageText, sMessages[id].text); FillWindowPixelBuffer(1, PIXEL_FILL(1)); - AddTextPrinterParameterized(1, 1, sPSSData->messageText, 0, 1, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(1, 1, sStorage->messageText, 0, 1, TEXT_SPEED_FF, NULL); DrawTextBorderOuter(1, 2, 14); PutWindowTilemap(1); CopyWindowToVram(1, 2); @@ -4330,16 +4330,16 @@ static void InitMonIconFields(void) LoadMonIconPalettes(); for (i = 0; i < MAX_MON_ICONS; i++) - sPSSData->numIconsPerSpecies[i] = 0; + sStorage->numIconsPerSpecies[i] = 0; for (i = 0; i < MAX_MON_ICONS; i++) - sPSSData->iconSpeciesList[i] = SPECIES_NONE; + sStorage->iconSpeciesList[i] = SPECIES_NONE; for (i = 0; i < PARTY_SIZE; i++) - sPSSData->partySprites[i] = NULL; + sStorage->partySprites[i] = NULL; for (i = 0; i < IN_BOX_COUNT; i++) - sPSSData->boxMonsSprites[i] = NULL; + sStorage->boxMonsSprites[i] = NULL; - sPSSData->movingMonSprite = NULL; - sPSSData->field_78C = 0; + sStorage->movingMonSprite = NULL; + sStorage->field_78C = 0; } static u8 GetMonIconPriorityByCursorPos(void) @@ -4349,12 +4349,12 @@ static u8 GetMonIconPriorityByCursorPos(void) static void CreateMovingMonIcon(void) { - u32 personality = GetMonData(&sPSSData->movingMon, MON_DATA_PERSONALITY); - u16 species = GetMonData(&sPSSData->movingMon, MON_DATA_SPECIES2); + u32 personality = GetMonData(&sStorage->movingMon, MON_DATA_PERSONALITY); + u16 species = GetMonData(&sStorage->movingMon, MON_DATA_SPECIES2); u8 priority = GetMonIconPriorityByCursorPos(); - sPSSData->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7); - sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; + sStorage->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7); + sStorage->movingMonSprite->callback = SpriteCB_HeldMon; } static void InitBoxMonSprites(u8 boxId) @@ -4376,11 +4376,11 @@ static void InitBoxMonSprites(u8 boxId) if (species != SPECIES_NONE) { personality = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); - sPSSData->boxMonsSprites[count] = CreateMonIconSprite(species, personality, 8 * (3 * j) + 100, 8 * (3 * i) + 44, 2, 19 - j); + sStorage->boxMonsSprites[count] = CreateMonIconSprite(species, personality, 8 * (3 * j) + 100, 8 * (3 * i) + 44, 2, 19 - j); } else { - sPSSData->boxMonsSprites[count] = NULL; + sStorage->boxMonsSprites[count] = NULL; } boxPosition++; count++; @@ -4388,12 +4388,12 @@ static void InitBoxMonSprites(u8 boxId) } // If in item mode, set all Pokémon icons with no item to be transparent - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++) { if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) - sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + sStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; } } } @@ -4408,9 +4408,9 @@ static void CreateBoxMonIconAtPos(u8 boxPosition) s16 y = 8 * (3 * (boxPosition / IN_BOX_COLUMNS)) + 44; u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY); - sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_COLUMNS)); - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) - sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + sStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_COLUMNS)); + if (sStorage->boxOption == OPTION_MOVE_ITEMS) + sStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; } } @@ -4426,11 +4426,11 @@ static void StartBoxMonIconsScrollOut(s16 speed) for (i = 0; i < IN_BOX_COUNT; i++) { - if (sPSSData->boxMonsSprites[i] != NULL) + if (sStorage->boxMonsSprites[i] != NULL) { - sPSSData->boxMonsSprites[i]->sSpeed = speed; - sPSSData->boxMonsSprites[i]->sDelay = 1; - sPSSData->boxMonsSprites[i]->callback = SpriteCB_BoxMonIconScrollOut; + sStorage->boxMonsSprites[i]->sSpeed = speed; + sStorage->boxMonsSprites[i]->sDelay = 1; + sStorage->boxMonsSprites[i]->callback = SpriteCB_BoxMonIconScrollOut; } } } @@ -4446,7 +4446,7 @@ static void SpriteCB_BoxMonIconScrollIn(struct Sprite *sprite) else { // Icon arrived - sPSSData->iconScrollNumIncoming--; + sStorage->iconScrollNumIncoming--; sprite->pos1.x = sprite->sScrollInDestX; sprite->callback = SpriteCallbackDummy; } @@ -4479,10 +4479,10 @@ static void DestroyBoxMonIconsInColumn(u8 column) for (row = 0; row < IN_BOX_ROWS; row++) { - if (sPSSData->boxMonsSprites[boxPosition] != NULL) + if (sStorage->boxMonsSprites[boxPosition] != NULL) { - DestroyBoxMonIcon(sPSSData->boxMonsSprites[boxPosition]); - sPSSData->boxMonsSprites[boxPosition] = NULL; + DestroyBoxMonIcon(sStorage->boxMonsSprites[boxPosition]); + sStorage->boxMonsSprites[boxPosition] = NULL; } boxPosition += IN_BOX_COLUMNS; } @@ -4499,21 +4499,21 @@ static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) u8 iconsCreated = 0; u8 boxPosition = column; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { for (i = 0; i < IN_BOX_ROWS; i++) { - if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) + if (sStorage->boxSpecies[boxPosition] != SPECIES_NONE) { - sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(sPSSData->boxSpecies[boxPosition], - sPSSData->boxPersonalities[boxPosition], + sStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(sStorage->boxSpecies[boxPosition], + sStorage->boxPersonalities[boxPosition], x, y, 2, subpriority); - if (sPSSData->boxMonsSprites[boxPosition] != NULL) + if (sStorage->boxMonsSprites[boxPosition] != NULL) { - sPSSData->boxMonsSprites[boxPosition]->sDistance = distance; - sPSSData->boxMonsSprites[boxPosition]->sSpeed = speed; - sPSSData->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; - sPSSData->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + sStorage->boxMonsSprites[boxPosition]->sDistance = distance; + sStorage->boxMonsSprites[boxPosition]->sSpeed = speed; + sStorage->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; + sStorage->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; iconsCreated++; } } @@ -4527,19 +4527,19 @@ static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) // to create the icons with the proper blend for (i = 0; i < IN_BOX_ROWS; i++) { - if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) + if (sStorage->boxSpecies[boxPosition] != SPECIES_NONE) { - sPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(sPSSData->boxSpecies[boxPosition], - sPSSData->boxPersonalities[boxPosition], + sStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(sStorage->boxSpecies[boxPosition], + sStorage->boxPersonalities[boxPosition], x, y, 2, subpriority); - if (sPSSData->boxMonsSprites[boxPosition] != NULL) + if (sStorage->boxMonsSprites[boxPosition] != NULL) { - sPSSData->boxMonsSprites[boxPosition]->sDistance = distance; - sPSSData->boxMonsSprites[boxPosition]->sSpeed = speed; - sPSSData->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; - sPSSData->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; - if (GetBoxMonDataAt(sPSSData->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) - sPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + sStorage->boxMonsSprites[boxPosition]->sDistance = distance; + sStorage->boxMonsSprites[boxPosition]->sSpeed = speed; + sStorage->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; + sStorage->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + if (GetBoxMonDataAt(sStorage->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) + sStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; iconsCreated++; } } @@ -4559,62 +4559,62 @@ static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) static void InitBoxMonIconScroll(u8 boxId, s8 direction) { - sPSSData->iconScrollState = 0; - sPSSData->iconScrollToBoxId = boxId; - sPSSData->iconScrollDirection = direction; - sPSSData->iconScrollDistance = 32; - sPSSData->iconScrollSpeed = -(6 * direction); - sPSSData->iconScrollNumIncoming = 0; + sStorage->iconScrollState = 0; + sStorage->iconScrollToBoxId = boxId; + sStorage->iconScrollDirection = direction; + sStorage->iconScrollDistance = 32; + sStorage->iconScrollSpeed = -(6 * direction); + sStorage->iconScrollNumIncoming = 0; SetBoxSpeciesAndPersonalities(boxId); if (direction > 0) - sPSSData->iconScrollCurColumn = 0; + sStorage->iconScrollCurColumn = 0; else - sPSSData->iconScrollCurColumn = IN_BOX_COLUMNS - 1; + sStorage->iconScrollCurColumn = IN_BOX_COLUMNS - 1; - sPSSData->iconScrollPos = (24 * sPSSData->iconScrollCurColumn) + 100; - StartBoxMonIconsScrollOut(sPSSData->iconScrollSpeed); + sStorage->iconScrollPos = (24 * sStorage->iconScrollCurColumn) + 100; + StartBoxMonIconsScrollOut(sStorage->iconScrollSpeed); } static bool8 UpdateBoxMonIconScroll(void) { - if (sPSSData->iconScrollDistance != 0) - sPSSData->iconScrollDistance--; + if (sStorage->iconScrollDistance != 0) + sStorage->iconScrollDistance--; - switch (sPSSData->iconScrollState) + switch (sStorage->iconScrollState) { case 0: - sPSSData->iconScrollPos += sPSSData->iconScrollSpeed; - if (sPSSData->iconScrollPos <= 64 || sPSSData->iconScrollPos >= 252) + sStorage->iconScrollPos += sStorage->iconScrollSpeed; + if (sStorage->iconScrollPos <= 64 || sStorage->iconScrollPos >= 252) { // A column of icons has gone offscreen, destroy them - DestroyBoxMonIconsInColumn(sPSSData->iconScrollCurColumn); - sPSSData->iconScrollPos += sPSSData->iconScrollDirection * 24; - sPSSData->iconScrollState++; + DestroyBoxMonIconsInColumn(sStorage->iconScrollCurColumn); + sStorage->iconScrollPos += sStorage->iconScrollDirection * 24; + sStorage->iconScrollState++; } break; case 1: // Create the new incoming column of icons - sPSSData->iconScrollPos += sPSSData->iconScrollSpeed; - sPSSData->iconScrollNumIncoming += CreateBoxMonIconsInColumn(sPSSData->iconScrollCurColumn, sPSSData->iconScrollDistance, sPSSData->iconScrollSpeed); + sStorage->iconScrollPos += sStorage->iconScrollSpeed; + sStorage->iconScrollNumIncoming += CreateBoxMonIconsInColumn(sStorage->iconScrollCurColumn, sStorage->iconScrollDistance, sStorage->iconScrollSpeed); - if ((sPSSData->iconScrollDirection > 0 && sPSSData->iconScrollCurColumn == IN_BOX_COLUMNS - 1) - || (sPSSData->iconScrollDirection < 0 && sPSSData->iconScrollCurColumn == 0)) + if ((sStorage->iconScrollDirection > 0 && sStorage->iconScrollCurColumn == IN_BOX_COLUMNS - 1) + || (sStorage->iconScrollDirection < 0 && sStorage->iconScrollCurColumn == 0)) { // Scroll has reached final column - sPSSData->iconScrollState++; + sStorage->iconScrollState++; } else { // Continue scrolling - sPSSData->iconScrollCurColumn += sPSSData->iconScrollDirection; - sPSSData->iconScrollState = 0; + sStorage->iconScrollCurColumn += sStorage->iconScrollDirection; + sStorage->iconScrollState = 0; } break; case 2: // Wait to make sure all icons have arrived - if (sPSSData->iconScrollNumIncoming == 0) + if (sStorage->iconScrollNumIncoming == 0) { - sPSSData->iconScrollDistance++; + sStorage->iconScrollDistance++; return FALSE; } break; @@ -4634,29 +4634,29 @@ static void SetBoxSpeciesAndPersonalities(u8 boxId) { for (j = 0; j < IN_BOX_COLUMNS; j++) { - sPSSData->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); - if (sPSSData->boxSpecies[boxPosition] != SPECIES_NONE) - sPSSData->boxPersonalities[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); + sStorage->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); + if (sStorage->boxSpecies[boxPosition] != SPECIES_NONE) + sStorage->boxPersonalities[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); boxPosition++; } } - sPSSData->field_C5C = boxId; + sStorage->field_C5C = boxId; } static void DestroyBoxMonIconAtPosition(u8 boxPosition) { - if (sPSSData->boxMonsSprites[boxPosition] != NULL) + if (sStorage->boxMonsSprites[boxPosition] != NULL) { - DestroyBoxMonIcon(sPSSData->boxMonsSprites[boxPosition]); - sPSSData->boxMonsSprites[boxPosition] = NULL; + DestroyBoxMonIcon(sStorage->boxMonsSprites[boxPosition]); + sStorage->boxMonsSprites[boxPosition] = NULL; } } static void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode) { - if (sPSSData->boxMonsSprites[boxPosition] != NULL) - sPSSData->boxMonsSprites[boxPosition]->oam.objMode = objMode; + if (sStorage->boxMonsSprites[boxPosition] != NULL) + sStorage->boxMonsSprites[boxPosition]->oam.objMode = objMode; } static void CreatePartyMonsSprites(bool8 visible) @@ -4665,7 +4665,7 @@ static void CreatePartyMonsSprites(bool8 visible) u16 species = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES2); u32 personality = GetMonData(&gPlayerParty[0], MON_DATA_PERSONALITY); - sPSSData->partySprites[0] = CreateMonIconSprite(species, personality, 104, 64, 1, 12); + sStorage->partySprites[0] = CreateMonIconSprite(species, personality, 104, 64, 1, 12); count = 1; for (i = 1; i < PARTY_SIZE; i++) { @@ -4673,12 +4673,12 @@ static void CreatePartyMonsSprites(bool8 visible) if (species != SPECIES_NONE) { personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); - sPSSData->partySprites[i] = CreateMonIconSprite(species, personality, 152, 8 * (3 * (i - 1)) + 16, 1, 12); + sStorage->partySprites[i] = CreateMonIconSprite(species, personality, 152, 8 * (3 * (i - 1)) + 16, 1, 12); count++; } else { - sPSSData->partySprites[i] = NULL; + sStorage->partySprites[i] = NULL; } } @@ -4686,17 +4686,17 @@ static void CreatePartyMonsSprites(bool8 visible) { for (i = 0; i < count; i++) { - sPSSData->partySprites[i]->pos1.y -= 160; - sPSSData->partySprites[i]->invisible = TRUE; + sStorage->partySprites[i]->pos1.y -= 160; + sStorage->partySprites[i]->invisible = TRUE; } } - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { for (i = 0; i < PARTY_SIZE; i++) { - if (sPSSData->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == ITEM_NONE) - sPSSData->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND; + if (sStorage->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == ITEM_NONE) + sStorage->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND; } } } @@ -4705,16 +4705,16 @@ static void CompactPartySprites(void) { u16 i, targetSlot; - sPSSData->numPartyToCompact = 0; + sStorage->numPartyToCompact = 0; for (i = 0, targetSlot = 0; i < PARTY_SIZE; i++) { - if (sPSSData->partySprites[i] != NULL) + if (sStorage->partySprites[i] != NULL) { if (i != targetSlot) { - MovePartySpriteToNextSlot(sPSSData->partySprites[i], targetSlot); - sPSSData->partySprites[i] = NULL; - sPSSData->numPartyToCompact++; + MovePartySpriteToNextSlot(sStorage->partySprites[i], targetSlot); + sStorage->partySprites[i] = NULL; + sStorage->numPartyToCompact++; } targetSlot++; } @@ -4723,7 +4723,7 @@ static void CompactPartySprites(void) static u8 GetNumPartySpritesCompacting(void) { - return sPSSData->numPartyToCompact; + return sStorage->numPartyToCompact; } #define sPartyId data[1] @@ -4774,8 +4774,8 @@ static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *sprite) sprite->pos1.y = 8 * (3 * (sprite->sPartyId - 1)) + 16; } sprite->callback = SpriteCallbackDummy; - sPSSData->partySprites[sprite->sPartyId] = sprite; - sPSSData->numPartyToCompact--; + sStorage->partySprites[sprite->sPartyId] = sprite; + sStorage->numPartyToCompact--; } } @@ -4788,10 +4788,10 @@ static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *sprite) static void DestroyMovingMonIcon(void) { - if (sPSSData->movingMonSprite != NULL) + if (sStorage->movingMonSprite != NULL) { - DestroyBoxMonIcon(sPSSData->movingMonSprite); - sPSSData->movingMonSprite = NULL; + DestroyBoxMonIcon(sStorage->movingMonSprite); + sStorage->movingMonSprite = NULL; } } @@ -4801,25 +4801,25 @@ static void MovePartySprites(s16 yDelta) for (i = 0; i < PARTY_SIZE; i++) { - if (sPSSData->partySprites[i] != NULL) + if (sStorage->partySprites[i] != NULL) { - sPSSData->partySprites[i]->pos1.y += yDelta; - posY = sPSSData->partySprites[i]->pos1.y + sPSSData->partySprites[i]->pos2.y + sPSSData->partySprites[i]->centerToCornerVecY; + sStorage->partySprites[i]->pos1.y += yDelta; + posY = sStorage->partySprites[i]->pos1.y + sStorage->partySprites[i]->pos2.y + sStorage->partySprites[i]->centerToCornerVecY; posY += 16; if (posY > 192) - sPSSData->partySprites[i]->invisible = TRUE; + sStorage->partySprites[i]->invisible = TRUE; else - sPSSData->partySprites[i]->invisible = FALSE; + sStorage->partySprites[i]->invisible = FALSE; } } } static void DestroyPartyMonIcon(u8 partyId) { - if (sPSSData->partySprites[partyId] != NULL) + if (sStorage->partySprites[partyId] != NULL) { - DestroyBoxMonIcon(sPSSData->partySprites[partyId]); - sPSSData->partySprites[partyId] = NULL; + DestroyBoxMonIcon(sStorage->partySprites[partyId]); + sStorage->partySprites[partyId] = NULL; } } @@ -4829,19 +4829,19 @@ static void DestroyAllPartyMonIcons(void) for (i = 0; i < PARTY_SIZE; i++) { - if (sPSSData->partySprites[i] != NULL) + if (sStorage->partySprites[i] != NULL) { - DestroyBoxMonIcon(sPSSData->partySprites[i]); - sPSSData->partySprites[i] = NULL; + DestroyBoxMonIcon(sStorage->partySprites[i]); + sStorage->partySprites[i] = NULL; } } } static void SetPartyMonIconObjMode(u8 partyId, u8 objMode) { - if (sPSSData->partySprites[partyId] != NULL) + if (sStorage->partySprites[partyId] != NULL) { - sPSSData->partySprites[partyId]->oam.objMode = objMode; + sStorage->partySprites[partyId]->oam.objMode = objMode; } } @@ -4849,83 +4849,83 @@ static void SetMovingMonSprite(u8 mode, u8 id) { if (mode == MODE_PARTY) { - sPSSData->movingMonSprite = sPSSData->partySprites[id]; - sPSSData->partySprites[id] = NULL; + sStorage->movingMonSprite = sStorage->partySprites[id]; + sStorage->partySprites[id] = NULL; } else if (mode == MODE_BOX) { - sPSSData->movingMonSprite = sPSSData->boxMonsSprites[id]; - sPSSData->boxMonsSprites[id] = NULL; + sStorage->movingMonSprite = sStorage->boxMonsSprites[id]; + sStorage->boxMonsSprites[id] = NULL; } else { return; } - sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; - sPSSData->movingMonSprite->oam.priority = GetMonIconPriorityByCursorPos(); - sPSSData->movingMonSprite->subpriority = 7; + sStorage->movingMonSprite->callback = SpriteCB_HeldMon; + sStorage->movingMonSprite->oam.priority = GetMonIconPriorityByCursorPos(); + sStorage->movingMonSprite->subpriority = 7; } static void sub_80CBCAC(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) // party mon { - sPSSData->partySprites[position] = sPSSData->movingMonSprite; - sPSSData->partySprites[position]->oam.priority = 1; - sPSSData->partySprites[position]->subpriority = 12; + sStorage->partySprites[position] = sStorage->movingMonSprite; + sStorage->partySprites[position]->oam.priority = 1; + sStorage->partySprites[position]->subpriority = 12; } else { - sPSSData->boxMonsSprites[position] = sPSSData->movingMonSprite; - sPSSData->boxMonsSprites[position]->oam.priority = 2; - sPSSData->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_COLUMNS); + sStorage->boxMonsSprites[position] = sStorage->movingMonSprite; + sStorage->boxMonsSprites[position]->oam.priority = 2; + sStorage->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_COLUMNS); } - sPSSData->movingMonSprite->callback = SpriteCallbackDummy; - sPSSData->movingMonSprite = NULL; + sStorage->movingMonSprite->callback = SpriteCallbackDummy; + sStorage->movingMonSprite = NULL; } static void sub_80CBD5C(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) // party mon - sPSSData->field_B00 = &sPSSData->partySprites[position]; + sStorage->field_B00 = &sStorage->partySprites[position]; else - sPSSData->field_B00 = &sPSSData->boxMonsSprites[position]; + sStorage->field_B00 = &sStorage->boxMonsSprites[position]; - sPSSData->movingMonSprite->callback = SpriteCallbackDummy; - sPSSData->field_C5D = 0; + sStorage->movingMonSprite->callback = SpriteCallbackDummy; + sStorage->field_C5D = 0; } static bool8 sub_80CBDC4(void) { - if (sPSSData->field_C5D == 16) + if (sStorage->field_C5D == 16) return FALSE; - sPSSData->field_C5D++; - if (sPSSData->field_C5D & 1) + sStorage->field_C5D++; + if (sStorage->field_C5D & 1) { - (*sPSSData->field_B00)->pos1.y--; - sPSSData->movingMonSprite->pos1.y++; + (*sStorage->field_B00)->pos1.y--; + sStorage->movingMonSprite->pos1.y++; } - (*sPSSData->field_B00)->pos2.x = gSineTable[sPSSData->field_C5D * 8] / 16; - sPSSData->movingMonSprite->pos2.x = -(gSineTable[sPSSData->field_C5D * 8] / 16); - if (sPSSData->field_C5D == 8) + (*sStorage->field_B00)->pos2.x = gSineTable[sStorage->field_C5D * 8] / 16; + sStorage->movingMonSprite->pos2.x = -(gSineTable[sStorage->field_C5D * 8] / 16); + if (sStorage->field_C5D == 8) { - sPSSData->movingMonSprite->oam.priority = (*sPSSData->field_B00)->oam.priority; - sPSSData->movingMonSprite->subpriority = (*sPSSData->field_B00)->subpriority; - (*sPSSData->field_B00)->oam.priority = GetMonIconPriorityByCursorPos(); - (*sPSSData->field_B00)->subpriority = 7; + sStorage->movingMonSprite->oam.priority = (*sStorage->field_B00)->oam.priority; + sStorage->movingMonSprite->subpriority = (*sStorage->field_B00)->subpriority; + (*sStorage->field_B00)->oam.priority = GetMonIconPriorityByCursorPos(); + (*sStorage->field_B00)->subpriority = 7; } - if (sPSSData->field_C5D == 16) + if (sStorage->field_C5D == 16) { - struct Sprite *sprite = sPSSData->movingMonSprite; - sPSSData->movingMonSprite = (*sPSSData->field_B00); - *sPSSData->field_B00 = sprite; + struct Sprite *sprite = sStorage->movingMonSprite; + sStorage->movingMonSprite = (*sStorage->field_B00); + *sStorage->field_B00 = sprite; - sPSSData->movingMonSprite->callback = SpriteCB_HeldMon; - (*sPSSData->field_B00)->callback = SpriteCallbackDummy; + sStorage->movingMonSprite->callback = SpriteCB_HeldMon; + (*sStorage->field_B00)->callback = SpriteCallbackDummy; } return TRUE; @@ -4936,78 +4936,78 @@ static void SetReleaseMon(u8 mode, u8 position) switch (mode) { case MODE_PARTY: - sPSSData->releaseMonSpritePtr = &sPSSData->partySprites[position]; + sStorage->releaseMonSpritePtr = &sStorage->partySprites[position]; break; case MODE_BOX: - sPSSData->releaseMonSpritePtr = &sPSSData->boxMonsSprites[position]; + sStorage->releaseMonSpritePtr = &sStorage->boxMonsSprites[position]; break; case MODE_MOVE: - sPSSData->releaseMonSpritePtr = &sPSSData->movingMonSprite; + sStorage->releaseMonSpritePtr = &sStorage->movingMonSprite; break; default: return; } - if (*sPSSData->releaseMonSpritePtr != NULL) + if (*sStorage->releaseMonSpritePtr != NULL) { - InitSpriteAffineAnim(*sPSSData->releaseMonSpritePtr); - (*sPSSData->releaseMonSpritePtr)->oam.affineMode = ST_OAM_AFFINE_NORMAL; - (*sPSSData->releaseMonSpritePtr)->affineAnims = sAffineAnims_ReleaseMon; - StartSpriteAffineAnim(*sPSSData->releaseMonSpritePtr, RELEASE_ANIM_RELEASE); + InitSpriteAffineAnim(*sStorage->releaseMonSpritePtr); + (*sStorage->releaseMonSpritePtr)->oam.affineMode = ST_OAM_AFFINE_NORMAL; + (*sStorage->releaseMonSpritePtr)->affineAnims = sAffineAnims_ReleaseMon; + StartSpriteAffineAnim(*sStorage->releaseMonSpritePtr, RELEASE_ANIM_RELEASE); } } static bool8 TryHideReleaseMonSprite(void) { - if (*sPSSData->releaseMonSpritePtr == NULL - || (*sPSSData->releaseMonSpritePtr)->invisible) + if (*sStorage->releaseMonSpritePtr == NULL + || (*sStorage->releaseMonSpritePtr)->invisible) return FALSE; - if ((*sPSSData->releaseMonSpritePtr)->affineAnimEnded) - (*sPSSData->releaseMonSpritePtr)->invisible = TRUE; + if ((*sStorage->releaseMonSpritePtr)->affineAnimEnded) + (*sStorage->releaseMonSpritePtr)->invisible = TRUE; return TRUE; } static void DestroyReleaseMonIcon(void) { - if (*sPSSData->releaseMonSpritePtr != NULL) + if (*sStorage->releaseMonSpritePtr != NULL) { - FreeOamMatrix((*sPSSData->releaseMonSpritePtr)->oam.matrixNum); - DestroyBoxMonIcon(*sPSSData->releaseMonSpritePtr); - *sPSSData->releaseMonSpritePtr = NULL; + FreeOamMatrix((*sStorage->releaseMonSpritePtr)->oam.matrixNum); + DestroyBoxMonIcon(*sStorage->releaseMonSpritePtr); + *sStorage->releaseMonSpritePtr = NULL; } } static void ReshowReleaseMon(void) { - if (*sPSSData->releaseMonSpritePtr != NULL) + if (*sStorage->releaseMonSpritePtr != NULL) { - (*sPSSData->releaseMonSpritePtr)->invisible = FALSE; - StartSpriteAffineAnim(*sPSSData->releaseMonSpritePtr, RELEASE_ANIM_CAME_BACK); + (*sStorage->releaseMonSpritePtr)->invisible = FALSE; + StartSpriteAffineAnim(*sStorage->releaseMonSpritePtr, RELEASE_ANIM_CAME_BACK); } } static bool8 ResetReleaseMonSpritePtr(void) { - if (sPSSData->releaseMonSpritePtr == NULL) + if (sStorage->releaseMonSpritePtr == NULL) return FALSE; - if ((*sPSSData->releaseMonSpritePtr)->affineAnimEnded) - sPSSData->releaseMonSpritePtr = NULL; + if ((*sStorage->releaseMonSpritePtr)->affineAnimEnded) + sStorage->releaseMonSpritePtr = NULL; return TRUE; } static void SetMovingMonPriority(u8 priority) { - sPSSData->movingMonSprite->oam.priority = priority; + sStorage->movingMonSprite->oam.priority = priority; } static void SpriteCB_HeldMon(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->cursorSprite->pos1.x; - sprite->pos1.y = sPSSData->cursorSprite->pos1.y + sPSSData->cursorSprite->pos2.y + 4; + sprite->pos1.x = sStorage->cursorSprite->pos1.x; + sprite->pos1.y = sStorage->cursorSprite->pos1.y + sStorage->cursorSprite->pos2.y + 4; } static u16 TryLoadMonIconTiles(u16 species) @@ -5017,7 +5017,7 @@ static u16 TryLoadMonIconTiles(u16 species) // Search icon list for this species for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->iconSpeciesList[i] == species) + if (sStorage->iconSpeciesList[i] == species) break; } @@ -5027,7 +5027,7 @@ static u16 TryLoadMonIconTiles(u16 species) // Find first empty spot in the list to put it for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->iconSpeciesList[i] == 0) + if (sStorage->iconSpeciesList[i] == 0) break; } @@ -5037,8 +5037,8 @@ static u16 TryLoadMonIconTiles(u16 species) } // Add species to icon list and load tiles - sPSSData->iconSpeciesList[i] = species; - sPSSData->numIconsPerSpecies[i]++; + sStorage->iconSpeciesList[i] = species; + sStorage->numIconsPerSpecies[i]++; offset = 16 * i; CpuCopy32(GetMonIconTiles(species, TRUE), (void*)(OBJ_VRAM0) + offset * 32, 0x200); @@ -5051,10 +5051,10 @@ static void RemoveSpeciesFromIconList(u16 species) for (i = 0; i < MAX_MON_ICONS; i++) { - if (sPSSData->iconSpeciesList[i] == species) + if (sStorage->iconSpeciesList[i] == species) { - if (--sPSSData->numIconsPerSpecies[i] == 0) - sPSSData->iconSpeciesList[i] = SPECIES_NONE; + if (--sStorage->numIconsPerSpecies[i] == 0) + sStorage->iconSpeciesList[i] = SPECIES_NONE; break; } } @@ -5114,15 +5114,15 @@ static void Task_InitBox(u8 taskId) switch (task->tState) { case 0: - sPSSData->wallpaperOffset = 0; - sPSSData->bg2_X = 0; - task->tDmaIdx = RequestDma3Fill(0, sPSSData->wallpaperBgTilemapBuffer, sizeof(sPSSData->wallpaperBgTilemapBuffer), 1); + sStorage->wallpaperOffset = 0; + sStorage->bg2_X = 0; + task->tDmaIdx = RequestDma3Fill(0, sStorage->wallpaperBgTilemapBuffer, sizeof(sStorage->wallpaperBgTilemapBuffer), 1); break; case 1: if (CheckForSpaceForDma3Request(task->tDmaIdx) == -1) return; - SetBgTilemapBuffer(2, sPSSData->wallpaperBgTilemapBuffer); + SetBgTilemapBuffer(2, sStorage->wallpaperBgTilemapBuffer); ShowBg(2); break; case 2: @@ -5156,45 +5156,45 @@ static void SetUpScrollToBox(u8 boxId) { s8 direction = DetermineBoxScrollDirection(boxId); - sPSSData->scrollSpeed = (direction > 0) ? 6 : -6; - sPSSData->scrollUnused1 = (direction > 0) ? 1 : 2; - sPSSData->scrollTimer = 32; - sPSSData->scrollToBoxIdUnused = boxId; - sPSSData->scrollUnused2 = (direction <= 0) ? 5 : 0; - sPSSData->scrollDirectionUnused = direction; + sStorage->scrollSpeed = (direction > 0) ? 6 : -6; + sStorage->scrollUnused1 = (direction > 0) ? 1 : 2; + sStorage->scrollTimer = 32; + sStorage->scrollToBoxIdUnused = boxId; + sStorage->scrollUnused2 = (direction <= 0) ? 5 : 0; + sStorage->scrollDirectionUnused = direction; - sPSSData->scrollUnused3 = (direction > 0) ? 264 : 56; - sPSSData->scrollUnused4 = (direction <= 0) ? 5 : 0; - sPSSData->scrollUnused5 = 0; - sPSSData->scrollUnused6 = 2; - sPSSData->scrollToBoxId = boxId; - sPSSData->scrollDirection = direction; - sPSSData->scrollState = 0; + sStorage->scrollUnused3 = (direction > 0) ? 264 : 56; + sStorage->scrollUnused4 = (direction <= 0) ? 5 : 0; + sStorage->scrollUnused5 = 0; + sStorage->scrollUnused6 = 2; + sStorage->scrollToBoxId = boxId; + sStorage->scrollDirection = direction; + sStorage->scrollState = 0; } static bool8 ScrollToBox(void) { bool8 iconsScrolling; - switch (sPSSData->scrollState) + switch (sStorage->scrollState) { case 0: - LoadWallpaperGfx(sPSSData->scrollToBoxId, sPSSData->scrollDirection); - sPSSData->scrollState++; + LoadWallpaperGfx(sStorage->scrollToBoxId, sStorage->scrollDirection); + sStorage->scrollState++; case 1: if (!WaitForWallpaperGfxLoad()) return TRUE; - InitBoxMonIconScroll(sPSSData->scrollToBoxId, sPSSData->scrollDirection); - CreateIncomingBoxTitle(sPSSData->scrollToBoxId, sPSSData->scrollDirection); - StartBoxScrollArrowsSlide(sPSSData->scrollDirection); + InitBoxMonIconScroll(sStorage->scrollToBoxId, sStorage->scrollDirection); + CreateIncomingBoxTitle(sStorage->scrollToBoxId, sStorage->scrollDirection); + StartBoxScrollArrowsSlide(sStorage->scrollDirection); break; case 2: iconsScrolling = UpdateBoxMonIconScroll(); - if (sPSSData->scrollTimer != 0) + if (sStorage->scrollTimer != 0) { - sPSSData->bg2_X += sPSSData->scrollSpeed; - if (--sPSSData->scrollTimer != 0) + sStorage->bg2_X += sStorage->scrollSpeed; + if (--sStorage->scrollTimer != 0) return TRUE; CycleBoxTitleSprites(); StopBoxScrollArrowsSlide(); @@ -5202,7 +5202,7 @@ static bool8 ScrollToBox(void) return iconsScrolling; } - sPSSData->scrollState++; + sStorage->scrollState++; return TRUE; } @@ -5225,36 +5225,36 @@ static void SetWallpaperForCurrentBox(u8 wallpaperId) { u8 boxId = StorageGetCurrentBox(); SetBoxWallpaper(boxId, wallpaperId); - sPSSData->wallpaperChangeState = 0; + sStorage->wallpaperChangeState = 0; } static bool8 DoWallpaperGfxChange(void) { - switch (sPSSData->wallpaperChangeState) + switch (sStorage->wallpaperChangeState) { case 0: - BeginNormalPaletteFade(sPSSData->boxTitlePalBits, 1, 0, 16, RGB_WHITEALPHA); - sPSSData->wallpaperChangeState++; + BeginNormalPaletteFade(sStorage->boxTitlePalBits, 1, 0, 16, RGB_WHITEALPHA); + sStorage->wallpaperChangeState++; break; case 1: if (!UpdatePaletteFade()) { u8 curBox = StorageGetCurrentBox(); LoadWallpaperGfx(curBox, 0); - sPSSData->wallpaperChangeState++; + sStorage->wallpaperChangeState++; } break; case 2: if (WaitForWallpaperGfxLoad() == TRUE) { CycleBoxTitleColor(); - BeginNormalPaletteFade(sPSSData->boxTitlePalBits, 1, 16, 0, RGB_WHITEALPHA); - sPSSData->wallpaperChangeState++; + BeginNormalPaletteFade(sStorage->boxTitlePalBits, 1, 16, 0, RGB_WHITEALPHA); + sStorage->wallpaperChangeState++; } break; case 3: if (!UpdatePaletteFade()) - sPSSData->wallpaperChangeState++; + sStorage->wallpaperChangeState++; break; case 4: return FALSE; @@ -5270,50 +5270,50 @@ static void LoadWallpaperGfx(u8 boxId, s8 direction) void *iconGfx; u32 tilesSize, iconSize; - sPSSData->wallpaperLoadState = 0; - sPSSData->wallpaperLoadBoxId = boxId; - sPSSData->wallpaperLoadDir = direction; - if (sPSSData->wallpaperLoadDir != 0) + sStorage->wallpaperLoadState = 0; + sStorage->wallpaperLoadBoxId = boxId; + sStorage->wallpaperLoadDir = direction; + if (sStorage->wallpaperLoadDir != 0) { - sPSSData->wallpaperOffset = (sPSSData->wallpaperOffset == 0); - TrimOldWallpaper(sPSSData->wallpaperBgTilemapBuffer); + sStorage->wallpaperOffset = (sStorage->wallpaperOffset == 0); + TrimOldWallpaper(sStorage->wallpaperBgTilemapBuffer); } - wallpaperId = GetBoxWallpaper(sPSSData->wallpaperLoadBoxId); + wallpaperId = GetBoxWallpaper(sStorage->wallpaperLoadBoxId); if (wallpaperId != WALLPAPER_FRIENDS) { wallpaper = &sWallpapers[wallpaperId]; - LZ77UnCompWram(wallpaper->tilemap, sPSSData->wallpaperTilemap); - DrawWallpaper(sPSSData->wallpaperTilemap, sPSSData->wallpaperLoadDir, sPSSData->wallpaperOffset); + LZ77UnCompWram(wallpaper->tilemap, sStorage->wallpaperTilemap); + DrawWallpaper(sStorage->wallpaperTilemap, sStorage->wallpaperLoadDir, sStorage->wallpaperOffset); - if (sPSSData->wallpaperLoadDir != 0) - LoadPalette(wallpaper->palettes, (sPSSData->wallpaperOffset * 32) + 0x40, 0x40); + if (sStorage->wallpaperLoadDir != 0) + LoadPalette(wallpaper->palettes, (sStorage->wallpaperOffset * 32) + 0x40, 0x40); else - CpuCopy16(wallpaper->palettes, &gPlttBufferUnfaded[(sPSSData->wallpaperOffset * 32) + 0x40], 0x40); + CpuCopy16(wallpaper->palettes, &gPlttBufferUnfaded[(sStorage->wallpaperOffset * 32) + 0x40], 0x40); - sPSSData->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); - LoadBgTiles(2, sPSSData->wallpaperTiles, tilesSize, sPSSData->wallpaperOffset << 8); + sStorage->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); + LoadBgTiles(2, sStorage->wallpaperTiles, tilesSize, sStorage->wallpaperOffset << 8); } else { wallpaper = &sWaldaWallpapers[GetWaldaWallpaperPatternId()]; - LZ77UnCompWram(wallpaper->tilemap, sPSSData->wallpaperTilemap); - DrawWallpaper(sPSSData->wallpaperTilemap, sPSSData->wallpaperLoadDir, sPSSData->wallpaperOffset); + LZ77UnCompWram(wallpaper->tilemap, sStorage->wallpaperTilemap); + DrawWallpaper(sStorage->wallpaperTilemap, sStorage->wallpaperLoadDir, sStorage->wallpaperOffset); - CpuCopy16(wallpaper->palettes, sPSSData->wallpaperTilemap, 0x40); - CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->wallpaperTilemap[1], 4); - CpuCopy16(GetWaldaWallpaperColorsPtr(), &sPSSData->wallpaperTilemap[17], 4); + CpuCopy16(wallpaper->palettes, sStorage->wallpaperTilemap, 0x40); + CpuCopy16(GetWaldaWallpaperColorsPtr(), &sStorage->wallpaperTilemap[1], 4); + CpuCopy16(GetWaldaWallpaperColorsPtr(), &sStorage->wallpaperTilemap[17], 4); - if (sPSSData->wallpaperLoadDir != 0) - LoadPalette(sPSSData->wallpaperTilemap, (sPSSData->wallpaperOffset * 32) + 0x40, 0x40); + if (sStorage->wallpaperLoadDir != 0) + LoadPalette(sStorage->wallpaperTilemap, (sStorage->wallpaperOffset * 32) + 0x40, 0x40); else - CpuCopy16(sPSSData->wallpaperTilemap, &gPlttBufferUnfaded[(sPSSData->wallpaperOffset * 32) + 0x40], 0x40); + CpuCopy16(sStorage->wallpaperTilemap, &gPlttBufferUnfaded[(sStorage->wallpaperOffset * 32) + 0x40], 0x40); - sPSSData->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); + sStorage->wallpaperTiles = malloc_and_decompress(wallpaper->tiles, &tilesSize); iconGfx = malloc_and_decompress(sWaldaWallpaperIcons[GetWaldaWallpaperIconId()], &iconSize); - CpuCopy32(iconGfx, sPSSData->wallpaperTiles + 0x800, iconSize); + CpuCopy32(iconGfx, sStorage->wallpaperTiles + 0x800, iconSize); Free(iconGfx); - LoadBgTiles(2, sPSSData->wallpaperTiles, tilesSize, sPSSData->wallpaperOffset << 8); + LoadBgTiles(2, sStorage->wallpaperTiles, tilesSize, sStorage->wallpaperOffset << 8); } CopyBgTilemapBufferToVram(2); @@ -5324,8 +5324,8 @@ static bool32 WaitForWallpaperGfxLoad(void) if (IsDma3ManagerBusyWithBgCopy()) return FALSE; - if (sPSSData->wallpaperTiles != NULL) - FREE_AND_SET_NULL(sPSSData->wallpaperTiles); + if (sStorage->wallpaperTiles != NULL) + FREE_AND_SET_NULL(sStorage->wallpaperTiles); return TRUE; } @@ -5333,7 +5333,7 @@ static bool32 WaitForWallpaperGfxLoad(void) static void DrawWallpaper(const void *tilemap, s8 direction, u8 offset) { s16 var = (offset * 2) + 3; - s16 x = ((sPSSData->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; + s16 x = ((sStorage->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, offset << 8, var); @@ -5351,7 +5351,7 @@ static void TrimOldWallpaper(void *tilemap) { u16 i; u16 *dest = tilemap; - s16 r3 = ((sPSSData->bg2_X / 8) + 30) & 0x3F; + s16 r3 = ((sStorage->bg2_X / 8) + 30) & 0x3F; if (r3 <= 31) dest += r3 + 0x260; @@ -5375,33 +5375,33 @@ static void InitBoxTitle(u8 boxId) s16 x; u16 i; - struct SpriteSheet spriteSheet = {sPSSData->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; + struct SpriteSheet spriteSheet = {sStorage->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; struct SpritePalette palettes[] = { - {sPSSData->boxTitlePal, PALTAG_BOX_TITLE}, + {sStorage->boxTitlePal, PALTAG_BOX_TITLE}, {} }; u16 wallpaperId = GetBoxWallpaper(boxId); - sPSSData->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; // Shadow color - sPSSData->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; // Text Color + sStorage->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; // Shadow color + sStorage->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; // Text Color LoadSpritePalettes(palettes); - sPSSData->boxTitlePalBits = 0x3f0; + sStorage->boxTitlePalBits = 0x3f0; tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); - sPSSData->boxTitlePalOffset = 0x10e + 16 * tagIndex; - sPSSData->boxTitlePalBits |= 0x10000 << tagIndex; + sStorage->boxTitlePalOffset = 0x10e + 16 * tagIndex; + sStorage->boxTitlePalBits |= 0x10000 << tagIndex; // The below seems intended to have separately tracked // the incoming wallpaper title's palette, but as they now // share a palette tag, all colors (and fields in some cases) // this is redundant along with the use of boxTitleAltPalOffset tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); - sPSSData->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; - sPSSData->boxTitlePalBits |= 0x10000 << tagIndex; + sStorage->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; + sStorage->boxTitlePalBits |= 0x10000 << tagIndex; - StringCopyPadded(sPSSData->boxTitleText, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(sPSSData->boxTitleText, sPSSData->boxTitleTiles, 0, 0, 2); + StringCopyPadded(sStorage->boxTitleText, GetBoxNamePtr(boxId), 0, 8); + DrawTextWindowAndBufferTiles(sStorage->boxTitleText, sStorage->boxTitleTiles, 0, 0, 2); LoadSpriteSheet(&spriteSheet); x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); @@ -5409,10 +5409,10 @@ static void InitBoxTitle(u8 boxId) for (i = 0; i < 2; i++) { u8 spriteId = CreateSprite(&sSpriteTemplate_BoxTitle, x + i * 32, 28, 24); - sPSSData->curBoxTitleSprites[i] = &gSprites[spriteId]; - StartSpriteAnim(sPSSData->curBoxTitleSprites[i], i); + sStorage->curBoxTitleSprites[i] = &gSprites[spriteId]; + StartSpriteAnim(sStorage->curBoxTitleSprites[i], i); } - sPSSData->boxTitleCycleId = 0; + sStorage->boxTitleCycleId = 0; } // Sprite data for moving title text @@ -5428,25 +5428,25 @@ static void CreateIncomingBoxTitle(u8 boxId, s8 direction) u16 palOffset; s16 x, adjustedX; u16 i; - struct SpriteSheet spriteSheet = {sPSSData->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; + struct SpriteSheet spriteSheet = {sStorage->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; struct SpriteTemplate template = sSpriteTemplate_BoxTitle; - sPSSData->boxTitleCycleId = (sPSSData->boxTitleCycleId == 0); - if (sPSSData->boxTitleCycleId == 0) + sStorage->boxTitleCycleId = (sStorage->boxTitleCycleId == 0); + if (sStorage->boxTitleCycleId == 0) { spriteSheet.tag = GFXTAG_BOX_TITLE; - palOffset = sPSSData->boxTitlePalOffset; + palOffset = sStorage->boxTitlePalOffset; } else { spriteSheet.tag = GFXTAG_BOX_TITLE_ALT; - palOffset = sPSSData->boxTitlePalOffset; + palOffset = sStorage->boxTitlePalOffset; template.tileTag = GFXTAG_BOX_TITLE_ALT; template.paletteTag = PALTAG_BOX_TITLE; } - StringCopyPadded(sPSSData->boxTitleText, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(sPSSData->boxTitleText, sPSSData->boxTitleTiles, 0, 0, 2); + StringCopyPadded(sStorage->boxTitleText, GetBoxNamePtr(boxId), 0, 8); + DrawTextWindowAndBufferTiles(sStorage->boxTitleText, sStorage->boxTitleTiles, 0, 0, 2); LoadSpriteSheet(&spriteSheet); LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], palOffset, sizeof(sBoxTitleColors[0])); x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); @@ -5458,28 +5458,28 @@ static void CreateIncomingBoxTitle(u8 boxId, s8 direction) { u8 spriteId = CreateSprite(&template, i * 32 + adjustedX, 28, 24); - sPSSData->nextBoxTitleSprites[i] = &gSprites[spriteId]; - sPSSData->nextBoxTitleSprites[i]->sSpeed = (-direction) * 6; - sPSSData->nextBoxTitleSprites[i]->sIncomingX = i * 32 + x; - sPSSData->nextBoxTitleSprites[i]->sIncomingDelay = 0; - sPSSData->nextBoxTitleSprites[i]->callback = SpriteCB_IncomingBoxTitle; - StartSpriteAnim(sPSSData->nextBoxTitleSprites[i], i); + sStorage->nextBoxTitleSprites[i] = &gSprites[spriteId]; + sStorage->nextBoxTitleSprites[i]->sSpeed = (-direction) * 6; + sStorage->nextBoxTitleSprites[i]->sIncomingX = i * 32 + x; + sStorage->nextBoxTitleSprites[i]->sIncomingDelay = 0; + sStorage->nextBoxTitleSprites[i]->callback = SpriteCB_IncomingBoxTitle; + StartSpriteAnim(sStorage->nextBoxTitleSprites[i], i); - sPSSData->curBoxTitleSprites[i]->sSpeed = (-direction) * 6; - sPSSData->curBoxTitleSprites[i]->sOutgoingDelay = 1; - sPSSData->curBoxTitleSprites[i]->callback = SpriteCB_OutgoingBoxTitle; + sStorage->curBoxTitleSprites[i]->sSpeed = (-direction) * 6; + sStorage->curBoxTitleSprites[i]->sOutgoingDelay = 1; + sStorage->curBoxTitleSprites[i]->callback = SpriteCB_OutgoingBoxTitle; } } static void CycleBoxTitleSprites(void) { - if (sPSSData->boxTitleCycleId == 0) + if (sStorage->boxTitleCycleId == 0) FreeSpriteTilesByTag(GFXTAG_BOX_TITLE_ALT); else FreeSpriteTilesByTag(GFXTAG_BOX_TITLE); - sPSSData->curBoxTitleSprites[0] = sPSSData->nextBoxTitleSprites[0]; - sPSSData->curBoxTitleSprites[1] = sPSSData->nextBoxTitleSprites[1]; + sStorage->curBoxTitleSprites[0] = sStorage->nextBoxTitleSprites[0]; + sStorage->curBoxTitleSprites[1] = sStorage->nextBoxTitleSprites[1]; } static void SpriteCB_IncomingBoxTitle(struct Sprite *sprite) @@ -5515,10 +5515,10 @@ static void CycleBoxTitleColor(void) { u8 boxId = StorageGetCurrentBox(); u8 wallpaperId = GetBoxWallpaper(boxId); - if (sPSSData->boxTitleCycleId == 0) - CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sPSSData->boxTitlePalOffset, 4); + if (sStorage->boxTitleCycleId == 0) + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sStorage->boxTitlePalOffset, 4); else - CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sPSSData->boxTitleAltPalOffset, 4); + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + sStorage->boxTitleAltPalOffset, 4); } static s16 GetBoxTitleBaseX(const u8 *string) @@ -5544,7 +5544,7 @@ static void CreateBoxScrollArrows(void) struct Sprite *sprite = &gSprites[spriteId]; StartSpriteAnim(sprite, i); sprite->sSpeed = (i == 0) ? -1 : 1; - sPSSData->arrowSprites[i] = sprite; + sStorage->arrowSprites[i] = sprite; } } if (IsCursorOnBoxTitle()) @@ -5558,25 +5558,25 @@ static void StartBoxScrollArrowsSlide(s8 direction) for (i = 0; i < 2; i++) { - sPSSData->arrowSprites[i]->pos2.x = 0; - sPSSData->arrowSprites[i]->sState = 2; + sStorage->arrowSprites[i]->pos2.x = 0; + sStorage->arrowSprites[i]->sState = 2; } if (direction < 0) { - sPSSData->arrowSprites[0]->sTimer = 29; - sPSSData->arrowSprites[1]->sTimer = 5; - sPSSData->arrowSprites[0]->data[2] = 72; - sPSSData->arrowSprites[1]->data[2] = 72; + sStorage->arrowSprites[0]->sTimer = 29; + sStorage->arrowSprites[1]->sTimer = 5; + sStorage->arrowSprites[0]->data[2] = 72; + sStorage->arrowSprites[1]->data[2] = 72; } else { - sPSSData->arrowSprites[0]->sTimer = 5; - sPSSData->arrowSprites[1]->sTimer = 29; - sPSSData->arrowSprites[0]->data[2] = DISPLAY_WIDTH + 8; - sPSSData->arrowSprites[1]->data[2] = DISPLAY_WIDTH + 8; + sStorage->arrowSprites[0]->sTimer = 5; + sStorage->arrowSprites[1]->sTimer = 29; + sStorage->arrowSprites[0]->data[2] = DISPLAY_WIDTH + 8; + sStorage->arrowSprites[1]->data[2] = DISPLAY_WIDTH + 8; } - sPSSData->arrowSprites[0]->data[7] = 0; - sPSSData->arrowSprites[1]->data[7] = 1; + sStorage->arrowSprites[0]->data[7] = 0; + sStorage->arrowSprites[1]->data[7] = 1; } // New box's scroll arrows have entered, stop sliding and set their position @@ -5586,9 +5586,9 @@ static void StopBoxScrollArrowsSlide(void) for (i = 0; i < 2; i++) { - sPSSData->arrowSprites[i]->pos1.x = 136 * i + 92; - sPSSData->arrowSprites[i]->pos2.x = 0; - sPSSData->arrowSprites[i]->invisible = FALSE; + sStorage->arrowSprites[i]->pos1.x = 136 * i + 92; + sStorage->arrowSprites[i]->pos2.x = 0; + sStorage->arrowSprites[i]->invisible = FALSE; } AnimateBoxScrollArrows(TRUE); } @@ -5603,17 +5603,17 @@ static void AnimateBoxScrollArrows(bool8 animate) // Start arrows moving for (i = 0; i < 2; i++) { - sPSSData->arrowSprites[i]->sState = 1; - sPSSData->arrowSprites[i]->sTimer = 0; - sPSSData->arrowSprites[i]->data[2] = 0; - sPSSData->arrowSprites[i]->data[4] = 0; + sStorage->arrowSprites[i]->sState = 1; + sStorage->arrowSprites[i]->sTimer = 0; + sStorage->arrowSprites[i]->data[2] = 0; + sStorage->arrowSprites[i]->data[4] = 0; } } else { // Stop arrows moving for (i = 0; i < 2; i++) - sPSSData->arrowSprites[i]->sState = 0; + sStorage->arrowSprites[i]->sState = 0; } } @@ -5640,7 +5640,7 @@ static void SpriteCB_Arrow(struct Sprite *sprite) sprite->sState = 3; break; case 3: - sprite->pos1.x -= sPSSData->scrollSpeed; + sprite->pos1.x -= sStorage->scrollSpeed; if (sprite->pos1.x <= 72 || sprite->pos1.x >= DISPLAY_WIDTH + 8) sprite->invisible = TRUE; if (--sprite->sTimer == 0) @@ -5651,7 +5651,7 @@ static void SpriteCB_Arrow(struct Sprite *sprite) } break; case 4: - sprite->pos1.x -= sPSSData->scrollSpeed; + sprite->pos1.x -= sStorage->scrollSpeed; break; } } @@ -5675,7 +5675,7 @@ static struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority static void sub_80CD36C(void) { - if (sPSSData->boxOption != OPTION_DEPOSIT) + if (sStorage->boxOption != OPTION_DEPOSIT) sCursorArea = CURSOR_AREA_IN_BOX; else sCursorArea = CURSOR_AREA_IN_PARTY; @@ -5687,8 +5687,8 @@ static void sub_80CD36C(void) sAutoActionOn = FALSE; ClearSavedCursorPos(); CreateCursorSprites(); - sPSSData->cursorPrevHorizPos = 1; - sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; + sStorage->cursorPrevHorizPos = 1; + sStorage->inBoxMovingMode = MOVE_MODE_NORMAL; TryRefreshDisplayMon(); } @@ -5696,11 +5696,11 @@ static void sub_80CD3EC(void) { CreateCursorSprites(); ReshowDisplayMon(); - sPSSData->cursorPrevHorizPos = 1; - sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; + sStorage->cursorPrevHorizPos = 1; + sStorage->inBoxMovingMode = MOVE_MODE_NORMAL; if (sIsMonBeingMoved) { - sPSSData->movingMon = sSavedMovingMon; + sStorage->movingMon = sSavedMovingMon; CreateMovingMonIcon(); } } @@ -5762,58 +5762,58 @@ static bool8 UpdateCursorPos(void) { s16 tmp; - if (sPSSData->cursorMoveSteps == 0) + if (sStorage->cursorMoveSteps == 0) { - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return FALSE; else return IsItemIconAnimActive(); } - else if (--sPSSData->cursorMoveSteps != 0) + else if (--sStorage->cursorMoveSteps != 0) { // Update position toward target - sPSSData->cursorNewX += sPSSData->cursorSpeedX; - sPSSData->cursorNewY += sPSSData->cursorSpeedY; - sPSSData->cursorSprite->pos1.x = sPSSData->cursorNewX >> 8; - sPSSData->cursorSprite->pos1.y = sPSSData->cursorNewY >> 8; + sStorage->cursorNewX += sStorage->cursorSpeedX; + sStorage->cursorNewY += sStorage->cursorSpeedY; + sStorage->cursorSprite->pos1.x = sStorage->cursorNewX >> 8; + sStorage->cursorSprite->pos1.y = sStorage->cursorNewY >> 8; // Limit cursor on right - if (sPSSData->cursorSprite->pos1.x > DISPLAY_WIDTH + 16) + if (sStorage->cursorSprite->pos1.x > DISPLAY_WIDTH + 16) { - tmp = sPSSData->cursorSprite->pos1.x - (DISPLAY_WIDTH + 16); - sPSSData->cursorSprite->pos1.x = tmp + 64; + tmp = sStorage->cursorSprite->pos1.x - (DISPLAY_WIDTH + 16); + sStorage->cursorSprite->pos1.x = tmp + 64; } // Limit cursor on left - if (sPSSData->cursorSprite->pos1.x < 64) + if (sStorage->cursorSprite->pos1.x < 64) { - tmp = 64 - sPSSData->cursorSprite->pos1.x; - sPSSData->cursorSprite->pos1.x = DISPLAY_WIDTH + 16 - tmp; + tmp = 64 - sStorage->cursorSprite->pos1.x; + sStorage->cursorSprite->pos1.x = DISPLAY_WIDTH + 16 - tmp; } // Limit cursor on bottom - if (sPSSData->cursorSprite->pos1.y > DISPLAY_HEIGHT + 16) + if (sStorage->cursorSprite->pos1.y > DISPLAY_HEIGHT + 16) { - tmp = sPSSData->cursorSprite->pos1.y - (DISPLAY_HEIGHT + 16); - sPSSData->cursorSprite->pos1.y = tmp - 16; + tmp = sStorage->cursorSprite->pos1.y - (DISPLAY_HEIGHT + 16); + sStorage->cursorSprite->pos1.y = tmp - 16; } // Limit cursor on top - if (sPSSData->cursorSprite->pos1.y < -16) + if (sStorage->cursorSprite->pos1.y < -16) { - tmp = -16 - sPSSData->cursorSprite->pos1.y; - sPSSData->cursorSprite->pos1.y = DISPLAY_HEIGHT + 16 - tmp; + tmp = -16 - sStorage->cursorSprite->pos1.y; + sStorage->cursorSprite->pos1.y = DISPLAY_HEIGHT + 16 - tmp; } // Cursor flips vertically when moving on/off the top buttons - if (sPSSData->cursorFlipTimer && --sPSSData->cursorFlipTimer == 0) - sPSSData->cursorSprite->vFlip = (sPSSData->cursorSprite->vFlip == FALSE); + if (sStorage->cursorFlipTimer && --sStorage->cursorFlipTimer == 0) + sStorage->cursorSprite->vFlip = (sStorage->cursorSprite->vFlip == FALSE); } else { // Time is up for cursor movement, make sure it's exactly at target - sPSSData->cursorSprite->pos1.x = sPSSData->cursorTargetX; - sPSSData->cursorSprite->pos1.y = sPSSData->cursorTargetY; + sStorage->cursorSprite->pos1.x = sStorage->cursorTargetX; + sStorage->cursorSprite->pos1.y = sStorage->cursorTargetY; DoCursorNewPosUpdate(); } @@ -5825,74 +5825,74 @@ static void InitNewCursorPos(u8 newCursorArea, u8 newCursorPosition) u16 x, y; GetCursorCoordsByPos(newCursorArea, newCursorPosition, &x, &y); - sPSSData->newCursorArea = newCursorArea; - sPSSData->newCursorPosition = newCursorPosition; - sPSSData->cursorTargetX = x; - sPSSData->cursorTargetY = y; + sStorage->newCursorArea = newCursorArea; + sStorage->newCursorPosition = newCursorPosition; + sStorage->cursorTargetX = x; + sStorage->cursorTargetY = y; } static void InitCursorMove(void) { int yDistance, xDistance; - if (sPSSData->cursorVerticalWrap != 0 || sPSSData->cursorHorizontalWrap != 0) - sPSSData->cursorMoveSteps = 12; + if (sStorage->cursorVerticalWrap != 0 || sStorage->cursorHorizontalWrap != 0) + sStorage->cursorMoveSteps = 12; else - sPSSData->cursorMoveSteps = 6; + sStorage->cursorMoveSteps = 6; - if (sPSSData->cursorFlipTimer) - sPSSData->cursorFlipTimer = sPSSData->cursorMoveSteps >> 1; + if (sStorage->cursorFlipTimer) + sStorage->cursorFlipTimer = sStorage->cursorMoveSteps >> 1; - switch (sPSSData->cursorVerticalWrap) + switch (sStorage->cursorVerticalWrap) { default: // No wrap - yDistance = sPSSData->cursorTargetY - sPSSData->cursorSprite->pos1.y; + yDistance = sStorage->cursorTargetY - sStorage->cursorSprite->pos1.y; break; case -1: // Wrap from top to bottom - yDistance = sPSSData->cursorTargetY - 192 - sPSSData->cursorSprite->pos1.y; + yDistance = sStorage->cursorTargetY - 192 - sStorage->cursorSprite->pos1.y; break; case 1: // Wrap from bottom to top - yDistance = sPSSData->cursorTargetY + 192 - sPSSData->cursorSprite->pos1.y; + yDistance = sStorage->cursorTargetY + 192 - sStorage->cursorSprite->pos1.y; break; } - switch (sPSSData->cursorHorizontalWrap) + switch (sStorage->cursorHorizontalWrap) { default: // No Wrap - xDistance = sPSSData->cursorTargetX - sPSSData->cursorSprite->pos1.x; + xDistance = sStorage->cursorTargetX - sStorage->cursorSprite->pos1.x; break; case -1: // Wrap from left to right - xDistance = sPSSData->cursorTargetX - 192 - sPSSData->cursorSprite->pos1.x; + xDistance = sStorage->cursorTargetX - 192 - sStorage->cursorSprite->pos1.x; break; case 1: // Wrap from right to left - xDistance = sPSSData->cursorTargetX + 192 - sPSSData->cursorSprite->pos1.x; + xDistance = sStorage->cursorTargetX + 192 - sStorage->cursorSprite->pos1.x; break; } yDistance <<= 8; xDistance <<= 8; - sPSSData->cursorSpeedX = xDistance / sPSSData->cursorMoveSteps; - sPSSData->cursorSpeedY = yDistance / sPSSData->cursorMoveSteps; - sPSSData->cursorNewX = sPSSData->cursorSprite->pos1.x << 8; - sPSSData->cursorNewY = sPSSData->cursorSprite->pos1.y << 8; + sStorage->cursorSpeedX = xDistance / sStorage->cursorMoveSteps; + sStorage->cursorSpeedY = yDistance / sStorage->cursorMoveSteps; + sStorage->cursorNewX = sStorage->cursorSprite->pos1.x << 8; + sStorage->cursorNewY = sStorage->cursorSprite->pos1.y << 8; } static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) { InitNewCursorPos(newCursorArea, newCursorPosition); InitCursorMove(); - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); + if (sStorage->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_STILL); } else { if (!IsMovingItem()) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_STILL); } - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { if (sCursorArea == CURSOR_AREA_IN_BOX) TryHideItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); @@ -5907,8 +5907,8 @@ static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) if (newCursorArea == CURSOR_AREA_IN_PARTY && sCursorArea != CURSOR_AREA_IN_PARTY) { - sPSSData->cursorPrevHorizPos = 1; - sPSSData->cursorShadowSprite->invisible = TRUE; + sStorage->cursorPrevHorizPos = 1; + sStorage->cursorShadowSprite->invisible = TRUE; } switch (newCursorArea) @@ -5916,19 +5916,19 @@ static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) case CURSOR_AREA_IN_PARTY: case CURSOR_AREA_BOX_TITLE: case CURSOR_AREA_BUTTONS: - sPSSData->cursorSprite->oam.priority = 1; - sPSSData->cursorShadowSprite->invisible = TRUE; - sPSSData->cursorShadowSprite->oam.priority = 1; + sStorage->cursorSprite->oam.priority = 1; + sStorage->cursorShadowSprite->invisible = TRUE; + sStorage->cursorShadowSprite->oam.priority = 1; break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode != MOVE_MODE_NORMAL) + if (sStorage->inBoxMovingMode != MOVE_MODE_NORMAL) { - sPSSData->cursorSprite->oam.priority = 0; - sPSSData->cursorShadowSprite->invisible = TRUE; + sStorage->cursorSprite->oam.priority = 0; + sStorage->cursorShadowSprite->invisible = TRUE; } else { - sPSSData->cursorSprite->oam.priority = 2; + sStorage->cursorSprite->oam.priority = 2; if (sCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) SetMovingMonPriority(2); } @@ -5938,17 +5938,17 @@ static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) static void DoCursorNewPosUpdate(void) { - sCursorArea = sPSSData->newCursorArea; - sCursorPosition = sPSSData->newCursorPosition; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + sCursorArea = sStorage->newCursorArea; + sCursorPosition = sStorage->newCursorPosition; + if (sStorage->boxOption != OPTION_MOVE_ITEMS) { - if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); + if (sStorage->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); } else { if (!IsMovingItem()) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); } TryRefreshDisplayMon(); @@ -5961,16 +5961,16 @@ static void DoCursorNewPosUpdate(void) AnimateBoxScrollArrows(TRUE); break; case CURSOR_AREA_IN_PARTY: - sPSSData->cursorShadowSprite->subpriority = 13; + sStorage->cursorShadowSprite->subpriority = 13; SetMovingMonPriority(1); break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) + if (sStorage->inBoxMovingMode == MOVE_MODE_NORMAL) { - sPSSData->cursorSprite->oam.priority = 1; - sPSSData->cursorShadowSprite->oam.priority = 2; - sPSSData->cursorShadowSprite->subpriority = 21; - sPSSData->cursorShadowSprite->invisible = FALSE; + sStorage->cursorSprite->oam.priority = 1; + sStorage->cursorShadowSprite->oam.priority = 2; + sStorage->cursorShadowSprite->subpriority = 21; + sStorage->cursorShadowSprite->invisible = FALSE; SetMovingMonPriority(2); } break; @@ -5991,8 +5991,8 @@ static void SetCursorInParty(void) if (partyCount >= PARTY_SIZE) partyCount = PARTY_SIZE - 1; } - if (sPSSData->cursorSprite->vFlip) - sPSSData->cursorFlipTimer = 1; + if (sStorage->cursorSprite->vFlip) + sStorage->cursorFlipTimer = 1; SetCursorPosition(CURSOR_AREA_IN_PARTY, partyCount); } @@ -6027,8 +6027,8 @@ static void InitMonPlaceChange(u8 type) [CHANGE_SHIFT] = MonPlaceChange_Shift, }; - sPSSData->monPlaceChangeFunc = placeChangeFuncs[type]; - sPSSData->monPlaceChangeState = 0; + sStorage->monPlaceChangeFunc = placeChangeFuncs[type]; + sStorage->monPlaceChangeState = 0; } // No Shift while moving multiple Pokémon, only grab and place @@ -6036,39 +6036,39 @@ static void InitMonPlaceChange(u8 type) static void InitMultiMonPlaceChange(bool8 up) { if (!up) - sPSSData->monPlaceChangeFunc = MultiMonPlaceChange_Down; + sStorage->monPlaceChangeFunc = MultiMonPlaceChange_Down; else - sPSSData->monPlaceChangeFunc = MultiMonPlaceChange_Up; + sStorage->monPlaceChangeFunc = MultiMonPlaceChange_Up; - sPSSData->monPlaceChangeState = 0; + sStorage->monPlaceChangeState = 0; } static bool8 DoMonPlaceChange(void) { - return sPSSData->monPlaceChangeFunc(); + return sStorage->monPlaceChangeFunc(); } static bool8 MonPlaceChange_Grab(void) { - switch (sPSSData->monPlaceChangeState) + switch (sStorage->monPlaceChangeState) { case 0: if (sIsMonBeingMoved) return FALSE; - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); - sPSSData->monPlaceChangeState++; + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_OPEN); + sStorage->monPlaceChangeState++; break; case 1: if (!MonPlaceChange_CursorDown()) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_FIST); MoveMon(); - sPSSData->monPlaceChangeState++; + sStorage->monPlaceChangeState++; } break; case 2: if (!MonPlaceChange_CursorUp()) - sPSSData->monPlaceChangeState++; + sStorage->monPlaceChangeState++; break; case 3: return FALSE; @@ -6079,21 +6079,21 @@ static bool8 MonPlaceChange_Grab(void) static bool8 MonPlaceChange_Place(void) { - switch (sPSSData->monPlaceChangeState) + switch (sStorage->monPlaceChangeState) { case 0: if (!MonPlaceChange_CursorDown()) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_OPEN); PlaceMon(); - sPSSData->monPlaceChangeState++; + sStorage->monPlaceChangeState++; } break; case 1: if (!MonPlaceChange_CursorUp()) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); - sPSSData->monPlaceChangeState++; + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); + sStorage->monPlaceChangeState++; } break; case 2: @@ -6105,30 +6105,30 @@ static bool8 MonPlaceChange_Place(void) static bool8 MonPlaceChange_Shift(void) { - switch (sPSSData->monPlaceChangeState) + switch (sStorage->monPlaceChangeState) { case 0: switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - sPSSData->field_D91 = TOTAL_BOXES_COUNT; + sStorage->field_D91 = TOTAL_BOXES_COUNT; break; case CURSOR_AREA_IN_BOX: - sPSSData->field_D91 = StorageGetCurrentBox(); + sStorage->field_D91 = StorageGetCurrentBox(); break; default: return FALSE; } - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_OPEN); - sub_80CBD5C(sPSSData->field_D91, sCursorPosition); - sPSSData->monPlaceChangeState++; + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_OPEN); + sub_80CBD5C(sStorage->field_D91, sCursorPosition); + sStorage->monPlaceChangeState++; break; case 1: if (!sub_80CBDC4()) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); - SetShiftedMonData(sPSSData->field_D91, sCursorPosition); - sPSSData->monPlaceChangeState++; + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_FIST); + SetShiftedMonData(sStorage->field_D91, sCursorPosition); + sStorage->monPlaceChangeState++; } break; case 2: @@ -6150,13 +6150,13 @@ static bool8 MultiMonPlaceChange_Up(void) static bool8 MonPlaceChange_CursorDown(void) { - switch (sPSSData->cursorSprite->pos2.y) + switch (sStorage->cursorSprite->pos2.y) { default: - sPSSData->cursorSprite->pos2.y++; + sStorage->cursorSprite->pos2.y++; break; case 0: - sPSSData->cursorSprite->pos2.y++; + sStorage->cursorSprite->pos2.y++; break; case 8: // Cursor has reached bottom return FALSE; @@ -6167,12 +6167,12 @@ static bool8 MonPlaceChange_CursorDown(void) static bool8 MonPlaceChange_CursorUp(void) { - switch (sPSSData->cursorSprite->pos2.y) + switch (sStorage->cursorSprite->pos2.y) { case 0: // Cursor has reached top return FALSE; default: - sPSSData->cursorSprite->pos2.y--; + sStorage->cursorSprite->pos2.y--; break; } @@ -6188,7 +6188,7 @@ static void MoveMon(void) SetMovingMonSprite(MODE_PARTY, sCursorPosition); break; case CURSOR_AREA_IN_BOX: - if (sPSSData->inBoxMovingMode == MOVE_MODE_NORMAL) + if (sStorage->inBoxMovingMode == MOVE_MODE_NORMAL) { SetMovingMonData(StorageGetCurrentBox(), sCursorPosition); SetMovingMonSprite(MODE_BOX, sCursorPosition); @@ -6231,9 +6231,9 @@ static void RefreshDisplayMon(void) static void SetMovingMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) - sPSSData->movingMon = gPlayerParty[sCursorPosition]; + sStorage->movingMon = gPlayerParty[sCursorPosition]; else - BoxMonAtToMon(boxId, position, &sPSSData->movingMon); + BoxMonAtToMon(boxId, position, &sStorage->movingMon); PurgeMonOrBoxMon(boxId, position); sMovingMonOrigBoxId = boxId; @@ -6244,12 +6244,12 @@ static void SetPlacedMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) { - gPlayerParty[position] = sPSSData->movingMon; + gPlayerParty[position] = sStorage->movingMon; } else { - BoxMonRestorePP(&sPSSData->movingMon.box); - SetBoxMonAt(boxId, position, &sPSSData->movingMon.box); + BoxMonRestorePP(&sStorage->movingMon.box); + SetBoxMonAt(boxId, position, &sStorage->movingMon.box); } } @@ -6264,13 +6264,13 @@ static void PurgeMonOrBoxMon(u8 boxId, u8 position) static void SetShiftedMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) - sPSSData->tempMon = gPlayerParty[position]; + sStorage->tempMon = gPlayerParty[position]; else - BoxMonAtToMon(boxId, position, &sPSSData->tempMon); + BoxMonAtToMon(boxId, position, &sStorage->tempMon); SetPlacedMonData(boxId, position); - sPSSData->movingMon = sPSSData->tempMon; - SetDisplayMonData(&sPSSData->movingMon, MODE_PARTY); + sStorage->movingMon = sStorage->tempMon; + SetDisplayMonData(&sStorage->movingMon, MODE_PARTY); sMovingMonOrigBoxId = boxId; sMovingMonOrigBoxPos = position; } @@ -6297,13 +6297,13 @@ static bool8 TryStorePartyMonInBox(u8 boxId) if (boxId == StorageGetCurrentBox()) CreateBoxMonIconAtPos(boxPosition); - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_STILL); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_STILL); return TRUE; } static void sub_80CE22C(void) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); TryRefreshDisplayMon(); } @@ -6319,14 +6319,14 @@ static void InitReleaseMon(void) mode = MODE_BOX; SetReleaseMon(mode, sCursorPosition); - StringCopy(sPSSData->releaseMonName, sPSSData->displayMonName); + StringCopy(sStorage->releaseMonName, sStorage->displayMonName); } static bool8 TryHideReleaseMon(void) { if (!TryHideReleaseMonSprite()) { - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_BOUNCE); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); return FALSE; } else @@ -6359,7 +6359,7 @@ static void ReleaseMon(void) static void TrySetCursorFistAnim(void) { if (sIsMonBeingMoved) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_FIST); } // If the player is on the listed map (or any map, if none is specified), @@ -6404,48 +6404,48 @@ static void InitCanReleaseMonVars(void) { // The player only has 1 or 2 usable // Pokémon, this one can't be released - sPSSData->releaseStatusResolved = TRUE; - sPSSData->canReleaseMon = FALSE; + sStorage->releaseStatusResolved = TRUE; + sStorage->canReleaseMon = FALSE; return; } if (sIsMonBeingMoved) { - sPSSData->tempMon = sPSSData->movingMon; - sPSSData->releaseBoxId = -1; - sPSSData->releaseBoxPos = -1; + sStorage->tempMon = sStorage->movingMon; + sStorage->releaseBoxId = -1; + sStorage->releaseBoxPos = -1; } else { if (sCursorArea == CURSOR_AREA_IN_PARTY) { - sPSSData->tempMon = gPlayerParty[sCursorPosition]; - sPSSData->releaseBoxId = TOTAL_BOXES_COUNT; + sStorage->tempMon = gPlayerParty[sCursorPosition]; + sStorage->releaseBoxId = TOTAL_BOXES_COUNT; } else { - BoxMonAtToMon(StorageGetCurrentBox(), sCursorPosition, &sPSSData->tempMon); - sPSSData->releaseBoxId = StorageGetCurrentBox(); + BoxMonAtToMon(StorageGetCurrentBox(), sCursorPosition, &sStorage->tempMon); + sStorage->releaseBoxId = StorageGetCurrentBox(); } - sPSSData->releaseBoxPos = sCursorPosition; + sStorage->releaseBoxPos = sCursorPosition; } - GetRestrictedReleaseMoves(sPSSData->restrictedMoveList); - sPSSData->restrictedReleaseMonMoves = GetMonData(&sPSSData->tempMon, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); - if (sPSSData->restrictedReleaseMonMoves != 0) + GetRestrictedReleaseMoves(sStorage->restrictedMoveList); + sStorage->restrictedReleaseMonMoves = GetMonData(&sStorage->tempMon, MON_DATA_KNOWN_MOVES, (u8*)sStorage->restrictedMoveList); + if (sStorage->restrictedReleaseMonMoves != 0) { // Pokémon knows at least one restricted release move // Need to check if another Pokémon has this move first - sPSSData->releaseStatusResolved = FALSE; + sStorage->releaseStatusResolved = FALSE; } else { // Pokémon knows no restricted moves, can be released - sPSSData->releaseStatusResolved = TRUE; - sPSSData->canReleaseMon = TRUE; + sStorage->releaseStatusResolved = TRUE; + sStorage->canReleaseMon = TRUE; } - sPSSData->releaseCheckState = 0; + sStorage->releaseCheckState = 0; } static bool32 AtLeastThreeUsableMons(void) @@ -6484,10 +6484,10 @@ static s8 RunCanReleaseMon(void) u16 i; u16 knownMoves; - if (sPSSData->releaseStatusResolved) - return sPSSData->canReleaseMon; + if (sStorage->releaseStatusResolved) + return sStorage->canReleaseMon; - switch (sPSSData->releaseCheckState) + switch (sStorage->releaseCheckState) { case 0: // Check party for other Pokémon that know any restricted @@ -6495,26 +6495,26 @@ static s8 RunCanReleaseMon(void) for (i = 0; i < PARTY_SIZE; i++) { // Make sure party Pokémon isn't the one we're releasing first - if (sPSSData->releaseBoxId != TOTAL_BOXES_COUNT || sPSSData->releaseBoxPos != i) + if (sStorage->releaseBoxId != TOTAL_BOXES_COUNT || sStorage->releaseBoxPos != i) { - knownMoves = GetMonData(&gPlayerParty[i], MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); - sPSSData->restrictedReleaseMonMoves &= ~(knownMoves); + knownMoves = GetMonData(&gPlayerParty[i], MON_DATA_KNOWN_MOVES, (u8*)sStorage->restrictedMoveList); + sStorage->restrictedReleaseMonMoves &= ~(knownMoves); } } - if (sPSSData->restrictedReleaseMonMoves == 0) + if (sStorage->restrictedReleaseMonMoves == 0) { // No restricted moves on release Pokémon that // aren't resolved by the party, it can be released. - sPSSData->releaseStatusResolved = TRUE; - sPSSData->canReleaseMon = TRUE; + sStorage->releaseStatusResolved = TRUE; + sStorage->canReleaseMon = TRUE; } else { // Release Pokémon has restricted moves not resolved by the party. // Continue and check the PC next - sPSSData->releaseCheckBoxId = 0; - sPSSData->releaseCheckBoxPos = 0; - sPSSData->releaseCheckState++; + sStorage->releaseCheckBoxId = 0; + sStorage->releaseCheckBoxPos = 0; + sStorage->releaseCheckState++; } break; case 1: @@ -6522,31 +6522,31 @@ static s8 RunCanReleaseMon(void) // moves the release Pokémon knows for (i = 0; i < IN_BOX_COUNT; i++) { - knownMoves = GetAndCopyBoxMonDataAt(sPSSData->releaseCheckBoxId, sPSSData->releaseCheckBoxPos, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->restrictedMoveList); - if (knownMoves != 0 && !(sPSSData->releaseBoxId == sPSSData->releaseCheckBoxId - && sPSSData->releaseBoxPos == sPSSData->releaseCheckBoxPos)) + knownMoves = GetAndCopyBoxMonDataAt(sStorage->releaseCheckBoxId, sStorage->releaseCheckBoxPos, MON_DATA_KNOWN_MOVES, (u8*)sStorage->restrictedMoveList); + if (knownMoves != 0 && !(sStorage->releaseBoxId == sStorage->releaseCheckBoxId + && sStorage->releaseBoxPos == sStorage->releaseCheckBoxPos)) { // Found PC Pokémon with restricted move, clear move from list - sPSSData->restrictedReleaseMonMoves &= ~(knownMoves); - if (sPSSData->restrictedReleaseMonMoves == 0) + sStorage->restrictedReleaseMonMoves &= ~(knownMoves); + if (sStorage->restrictedReleaseMonMoves == 0) { // No restricted moves on release Pokémon that // aren't resolved, it can be released. - sPSSData->releaseStatusResolved = TRUE; - sPSSData->canReleaseMon = TRUE; + sStorage->releaseStatusResolved = TRUE; + sStorage->canReleaseMon = TRUE; break; } } - if (++sPSSData->releaseCheckBoxPos >= IN_BOX_COUNT) + if (++sStorage->releaseCheckBoxPos >= IN_BOX_COUNT) { - sPSSData->releaseCheckBoxPos = 0; - if (++sPSSData->releaseCheckBoxId >= TOTAL_BOXES_COUNT) + sStorage->releaseCheckBoxPos = 0; + if (++sStorage->releaseCheckBoxId >= TOTAL_BOXES_COUNT) { // Checked every Pokémon in the PC, release Pokémon is // the sole owner of at least one restricted move. // It cannot be released. - sPSSData->releaseStatusResolved = TRUE; - sPSSData->canReleaseMon = FALSE; + sStorage->releaseStatusResolved = TRUE; + sStorage->canReleaseMon = FALSE; } } } @@ -6559,7 +6559,7 @@ static s8 RunCanReleaseMon(void) static void SaveMovingMon(void) { if (sIsMonBeingMoved) - sSavedMovingMon = sPSSData->movingMon; + sSavedMovingMon = sStorage->movingMon; } static void LoadSavedMovingMon(void) @@ -6569,9 +6569,9 @@ static void LoadSavedMovingMon(void) // If it came from the party load a struct Pokemon, // otherwise load a BoxPokemon if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT) - sPSSData->movingMon = sSavedMovingMon; + sStorage->movingMon = sSavedMovingMon; else - sPSSData->movingMon.box = sSavedMovingMon.box; + sStorage->movingMon.box = sSavedMovingMon.box; } } @@ -6580,24 +6580,24 @@ static void InitSummaryScreenData(void) if (sIsMonBeingMoved) { SaveMovingMon(); - sPSSData->summaryMon.mon = &sSavedMovingMon; - sPSSData->summaryStartPos = 0; - sPSSData->summaryMaxPos = 0; - sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; + sStorage->summaryMon.mon = &sSavedMovingMon; + sStorage->summaryStartPos = 0; + sStorage->summaryMaxPos = 0; + sStorage->summaryScreenMode = SUMMARY_MODE_NORMAL; } else if (sCursorArea == CURSOR_AREA_IN_PARTY) { - sPSSData->summaryMon.mon = gPlayerParty; - sPSSData->summaryStartPos = sCursorPosition; - sPSSData->summaryMaxPos = CountPartyMons() - 1; - sPSSData->summaryScreenMode = SUMMARY_MODE_NORMAL; + sStorage->summaryMon.mon = gPlayerParty; + sStorage->summaryStartPos = sCursorPosition; + sStorage->summaryMaxPos = CountPartyMons() - 1; + sStorage->summaryScreenMode = SUMMARY_MODE_NORMAL; } else { - sPSSData->summaryMon.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); - sPSSData->summaryStartPos = sCursorPosition; - sPSSData->summaryMaxPos = IN_BOX_COUNT - 1; - sPSSData->summaryScreenMode = SUMMARY_MODE_BOX; + sStorage->summaryMon.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); + sStorage->summaryStartPos = sCursorPosition; + sStorage->summaryMaxPos = IN_BOX_COUNT - 1; + sStorage->summaryScreenMode = SUMMARY_MODE_BOX; } } @@ -6636,10 +6636,10 @@ s16 CompactPartySlots(void) static void SetMonMarkings(u8 markings) { - sPSSData->displayMonMarkings = markings; + sStorage->displayMonMarkings = markings; if (sIsMonBeingMoved) { - SetMonData(&sPSSData->movingMon, MON_DATA_MARKINGS, &markings); + SetMonData(&sStorage->movingMon, MON_DATA_MARKINGS, &markings); } else { @@ -6664,7 +6664,7 @@ static bool8 CanShiftMon(void) { if (sCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sCursorPosition) == 0) { - if (sPSSData->displayMonIsEgg || GetMonData(&sPSSData->movingMon, MON_DATA_HP) == 0) + if (sStorage->displayMonIsEgg || GetMonData(&sStorage->movingMon, MON_DATA_HP) == 0) return FALSE; } return TRUE; @@ -6697,7 +6697,7 @@ static void TryRefreshDisplayMon(void) // If a Pokémon is currently being moved, don't start // mosaic or update display. Keep displaying the // currently held Pokémon. - sPSSData->setMosaic = (sIsMonBeingMoved == FALSE); + sStorage->setMosaic = (sIsMonBeingMoved == FALSE); if (!sIsMonBeingMoved) { // Update display Pokémon @@ -6735,94 +6735,94 @@ static void SetDisplayMonData(void *pokemon, u8 mode) u16 gender; bool8 sanityIsBadEgg; - sPSSData->displayMonItemId = ITEM_NONE; + sStorage->displayMonItemId = ITEM_NONE; gender = MON_MALE; sanityIsBadEgg = FALSE; if (mode == MODE_PARTY) { struct Pokemon *mon = (struct Pokemon *)pokemon; - sPSSData->displayMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); - if (sPSSData->displayMonSpecies != SPECIES_NONE) + sStorage->displayMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); + if (sStorage->displayMonSpecies != SPECIES_NONE) { sanityIsBadEgg = GetMonData(mon, MON_DATA_SANITY_IS_BAD_EGG); if (sanityIsBadEgg) - sPSSData->displayMonIsEgg = TRUE; + sStorage->displayMonIsEgg = TRUE; else - sPSSData->displayMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); - - GetMonData(mon, MON_DATA_NICKNAME, sPSSData->displayMonName); - StringGetEnd10(sPSSData->displayMonName); - sPSSData->displayMonLevel = GetMonData(mon, MON_DATA_LEVEL); - sPSSData->displayMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); - sPSSData->displayMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); - sPSSData->displayMonPalette = GetMonFrontSpritePal(mon); + sStorage->displayMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); + + GetMonData(mon, MON_DATA_NICKNAME, sStorage->displayMonName); + StringGetEnd10(sStorage->displayMonName); + sStorage->displayMonLevel = GetMonData(mon, MON_DATA_LEVEL); + sStorage->displayMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); + sStorage->displayMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); + sStorage->displayMonPalette = GetMonFrontSpritePal(mon); gender = GetMonGender(mon); - sPSSData->displayMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); + sStorage->displayMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); } } else if (mode == MODE_BOX) { struct BoxPokemon *boxMon = (struct BoxPokemon *)pokemon; - sPSSData->displayMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); - if (sPSSData->displayMonSpecies != SPECIES_NONE) + sStorage->displayMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); + if (sStorage->displayMonSpecies != SPECIES_NONE) { u32 otId = GetBoxMonData(boxMon, MON_DATA_OT_ID); sanityIsBadEgg = GetBoxMonData(boxMon, MON_DATA_SANITY_IS_BAD_EGG); if (sanityIsBadEgg) - sPSSData->displayMonIsEgg = TRUE; + sStorage->displayMonIsEgg = TRUE; else - sPSSData->displayMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); + sStorage->displayMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); - GetBoxMonData(boxMon, MON_DATA_NICKNAME, sPSSData->displayMonName); - StringGetEnd10(sPSSData->displayMonName); - sPSSData->displayMonLevel = GetLevelFromBoxMonExp(boxMon); - sPSSData->displayMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); - sPSSData->displayMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); - sPSSData->displayMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sPSSData->displayMonSpecies, otId, sPSSData->displayMonPersonality); - gender = GetGenderFromSpeciesAndPersonality(sPSSData->displayMonSpecies, sPSSData->displayMonPersonality); - sPSSData->displayMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); + GetBoxMonData(boxMon, MON_DATA_NICKNAME, sStorage->displayMonName); + StringGetEnd10(sStorage->displayMonName); + sStorage->displayMonLevel = GetLevelFromBoxMonExp(boxMon); + sStorage->displayMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); + sStorage->displayMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); + sStorage->displayMonPalette = GetMonSpritePalFromSpeciesAndPersonality(sStorage->displayMonSpecies, otId, sStorage->displayMonPersonality); + gender = GetGenderFromSpeciesAndPersonality(sStorage->displayMonSpecies, sStorage->displayMonPersonality); + sStorage->displayMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); } } else { - sPSSData->displayMonSpecies = SPECIES_NONE; - sPSSData->displayMonItemId = ITEM_NONE; + sStorage->displayMonSpecies = SPECIES_NONE; + sStorage->displayMonItemId = ITEM_NONE; } - if (sPSSData->displayMonSpecies == SPECIES_NONE) + if (sStorage->displayMonSpecies == SPECIES_NONE) { - StringFill(sPSSData->displayMonName, CHAR_SPACE, 5); - StringFill(sPSSData->displayMonNameText, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonSpeciesName, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonGenderLvlText, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); + StringFill(sStorage->displayMonName, CHAR_SPACE, 5); + StringFill(sStorage->displayMonNameText, CHAR_SPACE, 8); + StringFill(sStorage->displayMonSpeciesName, CHAR_SPACE, 8); + StringFill(sStorage->displayMonGenderLvlText, CHAR_SPACE, 8); + StringFill(sStorage->displayMonItemName, CHAR_SPACE, 8); } - else if (sPSSData->displayMonIsEgg) + else if (sStorage->displayMonIsEgg) { if (sanityIsBadEgg) - StringCopyPadded(sPSSData->displayMonNameText, sPSSData->displayMonName, CHAR_SPACE, 5); + StringCopyPadded(sStorage->displayMonNameText, sStorage->displayMonName, CHAR_SPACE, 5); else - StringCopyPadded(sPSSData->displayMonNameText, gText_EggNickname, CHAR_SPACE, 8); + StringCopyPadded(sStorage->displayMonNameText, gText_EggNickname, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonSpeciesName, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonGenderLvlText, CHAR_SPACE, 8); - StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); + StringFill(sStorage->displayMonSpeciesName, CHAR_SPACE, 8); + StringFill(sStorage->displayMonGenderLvlText, CHAR_SPACE, 8); + StringFill(sStorage->displayMonItemName, CHAR_SPACE, 8); } else { - if (sPSSData->displayMonSpecies == SPECIES_NIDORAN_F || sPSSData->displayMonSpecies == SPECIES_NIDORAN_M) + if (sStorage->displayMonSpecies == SPECIES_NIDORAN_F || sStorage->displayMonSpecies == SPECIES_NIDORAN_M) gender = MON_GENDERLESS; - StringCopyPadded(sPSSData->displayMonNameText, sPSSData->displayMonName, CHAR_SPACE, 5); + StringCopyPadded(sStorage->displayMonNameText, sStorage->displayMonName, CHAR_SPACE, 5); - txtPtr = sPSSData->displayMonSpeciesName; + txtPtr = sStorage->displayMonSpeciesName; *(txtPtr)++ = CHAR_SLASH; - StringCopyPadded(txtPtr, gSpeciesNames[sPSSData->displayMonSpecies], CHAR_SPACE, 5); + StringCopyPadded(txtPtr, gSpeciesNames[sStorage->displayMonSpecies], CHAR_SPACE, 5); - txtPtr = sPSSData->displayMonGenderLvlText; + txtPtr = sStorage->displayMonGenderLvlText; *(txtPtr)++ = EXT_CTRL_CODE_BEGIN; *(txtPtr)++ = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; switch (gender) @@ -6856,20 +6856,20 @@ static void SetDisplayMonData(void *pokemon, u8 mode) *(txtPtr++) = CHAR_EXTRA_SYMBOL; *(txtPtr++) = CHAR_LV_2; - txtPtr = ConvertIntToDecimalStringN(txtPtr, sPSSData->displayMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); + txtPtr = ConvertIntToDecimalStringN(txtPtr, sStorage->displayMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); txtPtr[0] = CHAR_SPACE; txtPtr[1] = EOS; - if (sPSSData->displayMonItemId != ITEM_NONE) - StringCopyPadded(sPSSData->displayMonItemName, ItemId_GetName(sPSSData->displayMonItemId), CHAR_SPACE, 8); + if (sStorage->displayMonItemId != ITEM_NONE) + StringCopyPadded(sStorage->displayMonItemName, ItemId_GetName(sStorage->displayMonItemId), CHAR_SPACE, 8); else - StringFill(sPSSData->displayMonItemName, CHAR_SPACE, 8); + StringFill(sStorage->displayMonItemName, CHAR_SPACE, 8); } } static u8 HandleInput_InBox(void) { - switch (sPSSData->inBoxMovingMode) + switch (sStorage->inBoxMovingMode) { case MOVE_MODE_NORMAL: default: @@ -6891,9 +6891,9 @@ static u8 InBoxInput_Normal(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->cursorVerticalWrap = 0; - sPSSData->cursorHorizontalWrap = 0; - sPSSData->cursorFlipTimer = 0; + sStorage->cursorVerticalWrap = 0; + sStorage->cursorHorizontalWrap = 0; + sStorage->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { @@ -6918,8 +6918,8 @@ static u8 InBoxInput_Normal(void) cursorArea = CURSOR_AREA_BUTTONS; cursorPosition -= IN_BOX_COUNT; cursorPosition /= 3; - sPSSData->cursorVerticalWrap = 1; - sPSSData->cursorFlipTimer = 1; + sStorage->cursorVerticalWrap = 1; + sStorage->cursorFlipTimer = 1; } break; } @@ -6932,7 +6932,7 @@ static u8 InBoxInput_Normal(void) } else { - sPSSData->cursorHorizontalWrap = -1; + sStorage->cursorHorizontalWrap = -1; cursorPosition += (IN_BOX_COLUMNS - 1); } break; @@ -6946,7 +6946,7 @@ static u8 InBoxInput_Normal(void) } else { - sPSSData->cursorHorizontalWrap = 1; + sStorage->cursorHorizontalWrap = 1; cursorPosition -= (IN_BOX_COLUMNS - 1); } break; @@ -6964,7 +6964,7 @@ static u8 InBoxInput_Normal(void) if (!sAutoActionOn) return INPUT_IN_MENU; - if (sPSSData->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) + if (sStorage->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) { switch (GetMenuItemTextId(0)) { @@ -6988,7 +6988,7 @@ static u8 InBoxInput_Normal(void) } else { - sPSSData->inBoxMovingMode = MOVE_MODE_MULTIPLE_SELECTING; + sStorage->inBoxMovingMode = MOVE_MODE_MULTIPLE_SELECTING; return INPUT_MULTIMOVE_START; } } @@ -7082,14 +7082,14 @@ static u8 InBoxInput_SelectingMultiple(void) if (MultiMove_GetOrigin() == sCursorPosition) { // Doing a multiple mon selection but only chose 1 mon - sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; - sPSSData->cursorShadowSprite->invisible = FALSE; + sStorage->inBoxMovingMode = MOVE_MODE_NORMAL; + sStorage->cursorShadowSprite->invisible = FALSE; return INPUT_MULTIMOVE_SINGLE; } else { - sIsMonBeingMoved = (sPSSData->displayMonSpecies != SPECIES_NONE); - sPSSData->inBoxMovingMode = MOVE_MODE_MULTIPLE_MOVING; + sIsMonBeingMoved = (sStorage->displayMonSpecies != SPECIES_NONE); + sStorage->inBoxMovingMode = MOVE_MODE_MULTIPLE_MOVING; sMovingMonOrigBoxId = StorageGetCurrentBox(); return INPUT_MULTIMOVE_GRAB_SELECTION; } @@ -7151,7 +7151,7 @@ static u8 InBoxInput_MovingMultiple(void) if (MultiMove_CanPlaceSelection()) { sIsMonBeingMoved = FALSE; - sPSSData->inBoxMovingMode = MOVE_MODE_NORMAL; + sStorage->inBoxMovingMode = MOVE_MODE_NORMAL; return INPUT_MULTIMOVE_PLACE_MONS; } else @@ -7188,9 +7188,9 @@ static u8 HandleInput_InParty(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->cursorHorizontalWrap = 0; - sPSSData->cursorVerticalWrap = 0; - sPSSData->cursorFlipTimer = 0; + sStorage->cursorHorizontalWrap = 0; + sStorage->cursorVerticalWrap = 0; + sStorage->cursorFlipTimer = 0; gotoBox = FALSE; retVal = INPUT_NONE; @@ -7213,7 +7213,7 @@ static u8 HandleInput_InParty(void) else if (JOY_REPEAT(DPAD_LEFT) && sCursorPosition != 0) { retVal = INPUT_MOVE_CURSOR; - sPSSData->cursorPrevHorizPos = sCursorPosition; + sStorage->cursorPrevHorizPos = sCursorPosition; cursorPosition = 0; break; } @@ -7222,7 +7222,7 @@ static u8 HandleInput_InParty(void) if (sCursorPosition == 0) { retVal = INPUT_MOVE_CURSOR; - cursorPosition = sPSSData->cursorPrevHorizPos; + cursorPosition = sStorage->cursorPrevHorizPos; } else { @@ -7237,7 +7237,7 @@ static u8 HandleInput_InParty(void) { if (sCursorPosition == PARTY_SIZE) { - if (sPSSData->boxOption == OPTION_DEPOSIT) + if (sStorage->boxOption == OPTION_DEPOSIT) return INPUT_CLOSE_BOX; gotoBox = TRUE; @@ -7271,7 +7271,7 @@ static u8 HandleInput_InParty(void) if (JOY_NEW(B_BUTTON)) { - if (sPSSData->boxOption == OPTION_DEPOSIT) + if (sStorage->boxOption == OPTION_DEPOSIT) return INPUT_PRESSED_B; gotoBox = TRUE; @@ -7308,16 +7308,16 @@ static u8 HandleInput_OnBox(void) do { - sPSSData->cursorHorizontalWrap = 0; - sPSSData->cursorVerticalWrap = 0; - sPSSData->cursorFlipTimer = 0; + sStorage->cursorHorizontalWrap = 0; + sStorage->cursorVerticalWrap = 0; + sStorage->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_BUTTONS; cursorPosition = 0; - sPSSData->cursorFlipTimer = 1; + sStorage->cursorFlipTimer = 1; break; } else if (JOY_REPEAT(DPAD_DOWN)) @@ -7381,20 +7381,20 @@ static u8 HandleInput_OnButtons(void) { cursorArea = sCursorArea; cursorPosition = sCursorPosition; - sPSSData->cursorHorizontalWrap = 0; - sPSSData->cursorVerticalWrap = 0; - sPSSData->cursorFlipTimer = 0; + sStorage->cursorHorizontalWrap = 0; + sStorage->cursorVerticalWrap = 0; + sStorage->cursorFlipTimer = 0; if (JOY_REPEAT(DPAD_UP)) { retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_IN_BOX; - sPSSData->cursorVerticalWrap = -1; + sStorage->cursorVerticalWrap = -1; if (sCursorPosition == 0) cursorPosition = IN_BOX_COUNT - 1 - 5; else cursorPosition = IN_BOX_COUNT - 1; - sPSSData->cursorFlipTimer = 1; + sStorage->cursorFlipTimer = 1; break; } @@ -7403,7 +7403,7 @@ static u8 HandleInput_OnButtons(void) retVal = INPUT_MOVE_CURSOR; cursorArea = CURSOR_AREA_BOX_TITLE; cursorPosition = 0; - sPSSData->cursorFlipTimer = 1; + sStorage->cursorFlipTimer = 1; break; } @@ -7482,7 +7482,7 @@ static void AddBoxMenu(void) static u8 SetSelectionMenuTexts(void) { InitMenu(); - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return SetMenuTexts_Mon(); else return SetMenuTexts_Item(); @@ -7492,7 +7492,7 @@ static bool8 SetMenuTexts_Mon(void) { u16 species = GetSpeciesAtCursorPosition(); - switch (sPSSData->boxOption) + switch (sStorage->boxOption) { case OPTION_DEPOSIT: if (species != SPECIES_NONE) @@ -7528,7 +7528,7 @@ static bool8 SetMenuTexts_Mon(void) } SetMenuText(MENU_SUMMARY); - if (sPSSData->boxOption == OPTION_MOVE_MONS) + if (sStorage->boxOption == OPTION_MOVE_MONS) { if (sCursorArea == CURSOR_AREA_IN_BOX) SetMenuText(MENU_WITHDRAW); @@ -7544,21 +7544,21 @@ static bool8 SetMenuTexts_Mon(void) static bool8 SetMenuTexts_Item(void) { - if (sPSSData->displayMonSpecies == SPECIES_EGG) + if (sStorage->displayMonSpecies == SPECIES_EGG) return FALSE; if (!IsMovingItem()) { - if (sPSSData->displayMonItemId == ITEM_NONE) + if (sStorage->displayMonItemId == ITEM_NONE) { - if (sPSSData->displayMonSpecies == SPECIES_NONE) + if (sStorage->displayMonSpecies == SPECIES_NONE) return FALSE; SetMenuText(MENU_GIVE_2); } else { - if (!ItemIsMail(sPSSData->displayMonItemId)) + if (!ItemIsMail(sStorage->displayMonItemId)) { SetMenuText(MENU_TAKE); SetMenuText(MENU_BAG); @@ -7568,16 +7568,16 @@ static bool8 SetMenuTexts_Item(void) } else { - if (sPSSData->displayMonItemId == ITEM_NONE) + if (sStorage->displayMonItemId == ITEM_NONE) { - if (sPSSData->displayMonSpecies == SPECIES_NONE) + if (sStorage->displayMonSpecies == SPECIES_NONE) return FALSE; SetMenuText(MENU_GIVE); } else { - if (ItemIsMail(sPSSData->displayMonItemId) == TRUE) + if (ItemIsMail(sStorage->displayMonItemId) == TRUE) return FALSE; SetMenuText(MENU_SWITCH); @@ -7590,8 +7590,8 @@ static bool8 SetMenuTexts_Item(void) static void SpriteCB_CursorShadow(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->cursorSprite->pos1.x; - sprite->pos1.y = sPSSData->cursorSprite->pos1.y + 20; + sprite->pos1.x = sStorage->cursorSprite->pos1.x; + sprite->pos1.y = sStorage->cursorSprite->pos1.y + 20; } static void CreateCursorSprites(void) @@ -7679,22 +7679,22 @@ static void CreateCursorSprites(void) LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePalettes); - sPSSData->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); // White hand, normal - sPSSData->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); // Yellow hand, when auto-action is on + sStorage->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); // White hand, normal + sStorage->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); // Yellow hand, when auto-action is on GetCursorCoordsByPos(sCursorArea, sCursorPosition, &x, &y); spriteId = CreateSprite(&sSpriteTemplate_Cursor, x, y, 6); if (spriteId != MAX_SPRITES) { - sPSSData->cursorSprite = &gSprites[spriteId]; - sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sAutoActionOn]; - sPSSData->cursorSprite->oam.priority = 1; + sStorage->cursorSprite = &gSprites[spriteId]; + sStorage->cursorSprite->oam.paletteNum = sStorage->cursorPalNums[sAutoActionOn]; + sStorage->cursorSprite->oam.priority = 1; if (sIsMonBeingMoved) - StartSpriteAnim(sPSSData->cursorSprite, CURSOR_ANIM_FIST); + StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_FIST); } else { - sPSSData->cursorSprite = NULL; + sStorage->cursorSprite = NULL; } if (sCursorArea == CURSOR_AREA_IN_PARTY) @@ -7711,21 +7711,21 @@ static void CreateCursorSprites(void) spriteId = CreateSprite(&sSpriteTemplate_CursorShadow, 0, 0, subpriority); if (spriteId != MAX_SPRITES) { - sPSSData->cursorShadowSprite = &gSprites[spriteId]; - sPSSData->cursorShadowSprite->oam.priority = priority; + sStorage->cursorShadowSprite = &gSprites[spriteId]; + sStorage->cursorShadowSprite->oam.priority = priority; if (sCursorArea) - sPSSData->cursorShadowSprite->invisible = TRUE; + sStorage->cursorShadowSprite->invisible = TRUE; } else { - sPSSData->cursorShadowSprite = NULL; + sStorage->cursorShadowSprite = NULL; } } static void ToggleCursorAutoAction(void) { sAutoActionOn = !sAutoActionOn; - sPSSData->cursorSprite->oam.paletteNum = sPSSData->cursorPalNums[sAutoActionOn]; + sStorage->cursorSprite->oam.paletteNum = sStorage->cursorPalNums[sAutoActionOn]; } static u8 GetCursorPosition(void) @@ -7749,7 +7749,7 @@ static void GetCursorBoxColumnAndRow(u8 *column, u8 *row) static void StartCursorAnim(u8 animNum) { - StartSpriteAnim(sPSSData->cursorSprite, animNum); + StartSpriteAnim(sStorage->cursorSprite, animNum); } // Unused @@ -7760,7 +7760,7 @@ static u8 GetMovingMonOriginalBoxId(void) static void SetCursorPriorityTo1(void) { - sPSSData->cursorSprite->oam.priority = 1; + sStorage->cursorSprite->oam.priority = 1; } static void TryHideItemAtCursor(void) @@ -7777,11 +7777,11 @@ static void TryShowItemAtCursor(void) static void InitMenu(void) { - sPSSData->menuItemsCount = 0; - sPSSData->menuWidth = 0; - sPSSData->menuWindow.bg = 0; - sPSSData->menuWindow.paletteNum = 15; - sPSSData->menuWindow.baseBlock = 92; + sStorage->menuItemsCount = 0; + sStorage->menuWidth = 0; + sStorage->menuWindow.bg = 0; + sStorage->menuWindow.paletteNum = 15; + sStorage->menuWindow.baseBlock = 92; } static const u8 *const sMenuTexts[] = @@ -7829,42 +7829,42 @@ static const u8 *const sMenuTexts[] = static void SetMenuText(u8 textId) { - if (sPSSData->menuItemsCount < ARRAY_COUNT(sPSSData->menuItems)) + if (sStorage->menuItemsCount < ARRAY_COUNT(sStorage->menuItems)) { u8 len; - struct StorageMenu *menu = &sPSSData->menuItems[sPSSData->menuItemsCount]; + struct StorageMenu *menu = &sStorage->menuItems[sStorage->menuItemsCount]; menu->text = sMenuTexts[textId]; menu->textId = textId; len = StringLength(menu->text); - if (len > sPSSData->menuWidth) - sPSSData->menuWidth = len; + if (len > sStorage->menuWidth) + sStorage->menuWidth = len; - sPSSData->menuItemsCount++; + sStorage->menuItemsCount++; } } static s8 GetMenuItemTextId(u8 menuIdx) { - if (menuIdx >= sPSSData->menuItemsCount) + if (menuIdx >= sStorage->menuItemsCount) return -1; else - return sPSSData->menuItems[menuIdx].textId; + return sStorage->menuItems[menuIdx].textId; } static void AddMenu(void) { - sPSSData->menuWindow.width = sPSSData->menuWidth + 2; - sPSSData->menuWindow.height = 2 * sPSSData->menuItemsCount; - sPSSData->menuWindow.tilemapLeft = 29 - sPSSData->menuWindow.width; - sPSSData->menuWindow.tilemapTop = 15 - sPSSData->menuWindow.height; - sPSSData->menuWindowId = AddWindow(&sPSSData->menuWindow); - ClearWindowTilemap(sPSSData->menuWindowId); - DrawStdFrameWithCustomTileAndPalette(sPSSData->menuWindowId, FALSE, 11, 14); - PrintMenuTable(sPSSData->menuWindowId, sPSSData->menuItemsCount, (void*)sPSSData->menuItems); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sPSSData->menuWindowId, sPSSData->menuItemsCount, 0); + sStorage->menuWindow.width = sStorage->menuWidth + 2; + sStorage->menuWindow.height = 2 * sStorage->menuItemsCount; + sStorage->menuWindow.tilemapLeft = 29 - sStorage->menuWindow.width; + sStorage->menuWindow.tilemapTop = 15 - sStorage->menuWindow.height; + sStorage->menuWindowId = AddWindow(&sStorage->menuWindow); + ClearWindowTilemap(sStorage->menuWindowId); + DrawStdFrameWithCustomTileAndPalette(sStorage->menuWindowId, FALSE, 11, 14); + PrintMenuTable(sStorage->menuWindowId, sStorage->menuItemsCount, (void*)sStorage->menuItems); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sStorage->menuWindowId, sStorage->menuItemsCount, 0); ScheduleBgCopyTilemapToVram(0); - sPSSData->menuUnusedField = 0; + sStorage->menuUnusedField = 0; } // Called after AddMenu to determine whether or not the handler callback should @@ -7908,15 +7908,15 @@ static s16 HandleMenuInput(void) RemoveMenu(); if (input >= 0) - input = sPSSData->menuItems[input].textId; + input = sStorage->menuItems[input].textId; return input; } static void RemoveMenu(void) { - ClearStdWindowAndFrameToTransparent(sPSSData->menuWindowId, TRUE); - RemoveWindow(sPSSData->menuWindowId); + ClearStdWindowAndFrameToTransparent(sStorage->menuWindowId, TRUE); + RemoveWindow(sStorage->menuWindowId); } @@ -7965,10 +7965,10 @@ static bool8 MultiMove_Init(void) sMultiMove = Alloc(sizeof(*sMultiMove)); if (sMultiMove != NULL) { - sPSSData->multiMoveWindowId = AddWindow8Bit(&sWindowTemplate_MultiMove); - if (sPSSData->multiMoveWindowId != WINDOW_NONE) + sStorage->multiMoveWindowId = AddWindow8Bit(&sWindowTemplate_MultiMove); + if (sStorage->multiMoveWindowId != WINDOW_NONE) { - FillWindowPixelBuffer(sPSSData->multiMoveWindowId, PIXEL_FILL(0)); + FillWindowPixelBuffer(sStorage->multiMoveWindowId, PIXEL_FILL(0)); return TRUE; } } @@ -8025,11 +8025,11 @@ static bool8 MultiMove_Start(void) ChangeBgX(0, -1024, 0); ChangeBgY(0, -1024, 0); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); - FillWindowPixelBuffer8Bit(sPSSData->multiMoveWindowId, PIXEL_FILL(0)); + FillWindowPixelBuffer8Bit(sStorage->multiMoveWindowId, PIXEL_FILL(0)); MultiMove_SetIconToBg(sMultiMove->fromColumn, sMultiMove->fromRow); SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); - PutWindowTilemap(sPSSData->multiMoveWindowId); - CopyWindowToVram8Bit(sPSSData->multiMoveWindowId, 3); + PutWindowTilemap(sStorage->multiMoveWindowId); + CopyWindowToVram8Bit(sStorage->multiMoveWindowId, 3); BlendPalettes(0x3F00, 8, RGB_WHITE); StartCursorAnim(CURSOR_ANIM_OPEN); SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); @@ -8085,7 +8085,7 @@ static bool8 MultiMove_ChangeSelection(void) MultiMove_UpdateSelectedIcons(); sMultiMove->toColumn = sMultiMove->cursorColumn; sMultiMove->toRow = sMultiMove->cursorRow; - CopyWindowToVram8Bit(sPSSData->multiMoveWindowId, 2); + CopyWindowToVram8Bit(sStorage->multiMoveWindowId, 2); sMultiMove->state++; } break; @@ -8296,7 +8296,7 @@ static void MultiMove_SetIconToBg(u8 x, u8 y) const u8 *iconGfx = GetMonIconPtr(species, personality, 1); u8 index = GetValidMonIconPalIndex(species) + 8; - BlitBitmapRectToWindow4BitTo8Bit(sPSSData->multiMoveWindowId, + BlitBitmapRectToWindow4BitTo8Bit(sStorage->multiMoveWindowId, iconGfx, 0, 0, @@ -8317,7 +8317,7 @@ static void MultiMove_ClearIconFromBg(u8 x, u8 y) if (species != SPECIES_NONE) { - FillWindowPixelRect8Bit(sPSSData->multiMoveWindowId, + FillWindowPixelRect8Bit(sStorage->multiMoveWindowId, PIXEL_FILL(0), 24 * x, 24 * y, @@ -8584,7 +8584,7 @@ static void CreateItemIconSprites(void) struct CompressedSpriteSheet spriteSheet; struct SpriteTemplate spriteTemplate; - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { spriteSheet.data = sItemIconGfxBuffer; spriteSheet.size = 0x200; @@ -8594,26 +8594,26 @@ static void CreateItemIconSprites(void) { spriteSheet.tag = GFXTAG_ITEM_ICON_0 + i; LoadCompressedSpriteSheet(&spriteSheet); - sPSSData->itemIcons[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * 32 + (void*)(OBJ_VRAM0); - sPSSData->itemIcons[i].palIndex = AllocSpritePalette(PALTAG_ITEM_ICON_0 + i); - sPSSData->itemIcons[i].palIndex *= 16; - sPSSData->itemIcons[i].palIndex += 0x100; + sStorage->itemIcons[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * 32 + (void*)(OBJ_VRAM0); + sStorage->itemIcons[i].palIndex = AllocSpritePalette(PALTAG_ITEM_ICON_0 + i); + sStorage->itemIcons[i].palIndex *= 16; + sStorage->itemIcons[i].palIndex += 0x100; spriteTemplate.tileTag = GFXTAG_ITEM_ICON_0 + i; spriteTemplate.paletteTag = PALTAG_ITEM_ICON_0 + i; spriteId = CreateSprite(&spriteTemplate, 0, 0, 11); - sPSSData->itemIcons[i].sprite = &gSprites[spriteId]; - sPSSData->itemIcons[i].sprite->invisible = TRUE; - sPSSData->itemIcons[i].active = FALSE; + sStorage->itemIcons[i].sprite = &gSprites[spriteId]; + sStorage->itemIcons[i].sprite->invisible = TRUE; + sStorage->itemIcons[i].active = FALSE; } } - sPSSData->movingItemId = ITEM_NONE; + sStorage->movingItemId = ITEM_NONE; } static void TryLoadItemIconAtPos(u8 cursorArea, u8 cursorPos) { u16 heldItem; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; // If we've already loaded the item here, stop @@ -8653,7 +8653,7 @@ static void TryHideItemIconAtPos(u8 cursorArea, u8 cursorPos) { u8 id; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; id = GetItemIconIdxByPosition(cursorArea, cursorPos); @@ -8666,7 +8666,7 @@ static void TakeItemFromMon(u8 cursorArea, u8 cursorPos) u8 id; u16 itemId; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; id = GetItemIconIdxByPosition(cursorArea, cursorPos); @@ -8685,7 +8685,7 @@ static void TakeItemFromMon(u8 cursorArea, u8 cursorPos) SetPartyMonIconObjMode(cursorPos, 1); } - sPSSData->movingItemId = sPSSData->displayMonItemId; + sStorage->movingItemId = sStorage->displayMonItemId; } static void InitItemIconInCursor(u16 itemId) @@ -8698,7 +8698,7 @@ static void InitItemIconInCursor(u16 itemId) SetItemIconCallback(id, ITEM_CB_TO_HAND, CURSOR_AREA_IN_BOX, 0); SetItemIconPosition(id, CURSOR_AREA_IN_HAND, 0); SetItemIconActive(id, TRUE); - sPSSData->movingItemId = itemId; + sStorage->movingItemId = itemId; } static void SwapItemsWithMon(u8 cursorArea, u8 cursorPos) @@ -8706,7 +8706,7 @@ static void SwapItemsWithMon(u8 cursorArea, u8 cursorPos) u8 id; u16 itemId; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; id = GetItemIconIdxByPosition(cursorArea, cursorPos); @@ -8715,14 +8715,14 @@ static void SwapItemsWithMon(u8 cursorArea, u8 cursorPos) if (cursorArea == CURSOR_AREA_IN_BOX) { itemId = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItemId); - sPSSData->movingItemId = itemId; + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sStorage->movingItemId); + sStorage->movingItemId = itemId; } else { itemId = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItemId); - sPSSData->movingItemId = itemId; + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sStorage->movingItemId); + sStorage->movingItemId = itemId; } id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); @@ -8734,7 +8734,7 @@ static void GiveItemToMon(u8 cursorArea, u8 cursorPos) { u8 id; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); @@ -8742,12 +8742,12 @@ static void GiveItemToMon(u8 cursorArea, u8 cursorPos) SetItemIconCallback(id, ITEM_CB_TO_MON, cursorArea, cursorPos); if (cursorArea == CURSOR_AREA_IN_BOX) { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sPSSData->movingItemId); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &sStorage->movingItemId); SetBoxMonIconObjMode(cursorPos, 0); } else { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sPSSData->movingItemId); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &sStorage->movingItemId); SetPartyMonIconObjMode(cursorPos, 0); } } @@ -8757,7 +8757,7 @@ static void MoveItemFromMonToBag(u8 cursorArea, u8 cursorPos) u8 id; u16 itemId; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; itemId = ITEM_NONE; @@ -8778,7 +8778,7 @@ static void MoveItemFromMonToBag(u8 cursorArea, u8 cursorPos) static void MoveItemFromCursorToBag(void) { - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { u8 id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); SetItemIconAffineAnim(id, ITEM_ANIM_PUT_AWAY); @@ -8793,13 +8793,13 @@ static void MoveHeldItemWithPartyMenu(void) { s32 i; - if (sPSSData->boxOption != OPTION_MOVE_ITEMS) + if (sStorage->boxOption != OPTION_MOVE_ITEMS) return; for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].area == CURSOR_AREA_IN_PARTY) + if (sStorage->itemIcons[i].active + && sStorage->itemIcons[i].area == CURSOR_AREA_IN_PARTY) SetItemIconCallback(i, ITEM_CB_HIDE_PARTY, CURSOR_AREA_IN_HAND, 0); } } @@ -8810,13 +8810,13 @@ static bool8 IsItemIconAnimActive(void) for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active) + if (sStorage->itemIcons[i].active) { - if (!sPSSData->itemIcons[i].sprite->affineAnimEnded - && sPSSData->itemIcons[i].sprite->affineAnimBeginning) + if (!sStorage->itemIcons[i].sprite->affineAnimEnded + && sStorage->itemIcons[i].sprite->affineAnimBeginning) return TRUE; - if (sPSSData->itemIcons[i].sprite->callback != SpriteCallbackDummy - && sPSSData->itemIcons[i].sprite->callback != SpriteCB_ItemIcon_SetPosToCursor) + if (sStorage->itemIcons[i].sprite->callback != SpriteCallbackDummy + && sStorage->itemIcons[i].sprite->callback != SpriteCB_ItemIcon_SetPosToCursor) return TRUE; } } @@ -8827,12 +8827,12 @@ static bool8 IsMovingItem(void) { s32 i; - if (sPSSData->boxOption == OPTION_MOVE_ITEMS) + if (sStorage->boxOption == OPTION_MOVE_ITEMS) { for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].area == CURSOR_AREA_IN_HAND) + if (sStorage->itemIcons[i].active + && sStorage->itemIcons[i].area == CURSOR_AREA_IN_HAND) return TRUE; } } @@ -8841,12 +8841,12 @@ static bool8 IsMovingItem(void) static const u8 *GetMovingItemName(void) { - return ItemId_GetName(sPSSData->movingItemId); + return ItemId_GetName(sStorage->movingItemId); } static u16 GetMovingItemId(void) { - return sPSSData->movingItemId; + return sStorage->movingItemId; } static u8 GetNewItemIconIdx(void) @@ -8855,9 +8855,9 @@ static u8 GetNewItemIconIdx(void) for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (!sPSSData->itemIcons[i].active) + if (!sStorage->itemIcons[i].active) { - sPSSData->itemIcons[i].active = TRUE; + sStorage->itemIcons[i].active = TRUE; return i; } } @@ -8870,9 +8870,9 @@ static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos) for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].area == cursorArea - && sPSSData->itemIcons[i].pos == cursorPos) + if (sStorage->itemIcons[i].active + && sStorage->itemIcons[i].area == cursorArea + && sStorage->itemIcons[i].pos == cursorPos) return TRUE; } return FALSE; @@ -8884,9 +8884,9 @@ static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos) for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].area == cursorArea - && sPSSData->itemIcons[i].pos == cursorPos) + if (sStorage->itemIcons[i].active + && sStorage->itemIcons[i].area == cursorArea + && sStorage->itemIcons[i].pos == cursorPos) return i; } return MAX_ITEM_ICONS; @@ -8898,8 +8898,8 @@ static u8 GetItemIconIdxBySprite(struct Sprite *sprite) for (i = 0; i < MAX_ITEM_ICONS; i++) { - if (sPSSData->itemIcons[i].active - && sPSSData->itemIcons[i].sprite == sprite) + if (sStorage->itemIcons[i].active + && sStorage->itemIcons[i].sprite == sprite) return i; } return MAX_ITEM_ICONS; @@ -8917,27 +8917,27 @@ static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) case CURSOR_AREA_IN_BOX: x = cursorPos % IN_BOX_COLUMNS; y = cursorPos / IN_BOX_COLUMNS; - sPSSData->itemIcons[id].sprite->pos1.x = (24 * x) + 112; - sPSSData->itemIcons[id].sprite->pos1.y = (24 * y) + 56; - sPSSData->itemIcons[id].sprite->oam.priority = 2; + sStorage->itemIcons[id].sprite->pos1.x = (24 * x) + 112; + sStorage->itemIcons[id].sprite->pos1.y = (24 * y) + 56; + sStorage->itemIcons[id].sprite->oam.priority = 2; break; case CURSOR_AREA_IN_PARTY: if (cursorPos == 0) { - sPSSData->itemIcons[id].sprite->pos1.x = 116; - sPSSData->itemIcons[id].sprite->pos1.y = 76; + sStorage->itemIcons[id].sprite->pos1.x = 116; + sStorage->itemIcons[id].sprite->pos1.y = 76; } else { - sPSSData->itemIcons[id].sprite->pos1.x = 164; - sPSSData->itemIcons[id].sprite->pos1.y = 24 * (cursorPos - 1) + 28; + sStorage->itemIcons[id].sprite->pos1.x = 164; + sStorage->itemIcons[id].sprite->pos1.y = 24 * (cursorPos - 1) + 28; } - sPSSData->itemIcons[id].sprite->oam.priority = 1; + sStorage->itemIcons[id].sprite->oam.priority = 1; break; } - sPSSData->itemIcons[id].area = cursorArea; - sPSSData->itemIcons[id].pos = cursorPos; + sStorage->itemIcons[id].area = cursorArea; + sStorage->itemIcons[id].pos = cursorPos; } static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) @@ -8947,14 +8947,14 @@ static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) if (id >= MAX_ITEM_ICONS) return; - CpuFastFill(0, sPSSData->field_42C4, 0x200); - LZ77UnCompWram(itemTiles, sPSSData->tileBuffer); + CpuFastFill(0, sStorage->field_42C4, 0x200); + LZ77UnCompWram(itemTiles, sStorage->tileBuffer); for (i = 0; i < 3; i++) - CpuFastCopy(&sPSSData->tileBuffer[i * 0x60], &sPSSData->field_42C4[i * 0x80], 0x60); + CpuFastCopy(&sStorage->tileBuffer[i * 0x60], &sStorage->field_42C4[i * 0x80], 0x60); - CpuFastCopy(sPSSData->field_42C4, sPSSData->itemIcons[id].tiles, 0x200); - LZ77UnCompWram(itemPal, sPSSData->field_42C4); - LoadPalette(sPSSData->field_42C4, sPSSData->itemIcons[id].palIndex, 0x20); + CpuFastCopy(sStorage->field_42C4, sStorage->itemIcons[id].tiles, 0x200); + LZ77UnCompWram(itemPal, sStorage->field_42C4); + LoadPalette(sStorage->field_42C4, sStorage->itemIcons[id].palIndex, 0x20); } static void SetItemIconAffineAnim(u8 id, u8 animNum) @@ -8962,7 +8962,7 @@ static void SetItemIconAffineAnim(u8 id, u8 animNum) if (id >= MAX_ITEM_ICONS) return; - StartSpriteAffineAnim(sPSSData->itemIcons[id].sprite, animNum); + StartSpriteAffineAnim(sStorage->itemIcons[id].sprite, animNum); } #define sItemIconId data[0] @@ -8978,36 +8978,36 @@ static void SetItemIconCallback(u8 id, u8 callbackId, u8 cursorArea, u8 cursorPo switch (callbackId) { case ITEM_CB_WAIT_ANIM: - sPSSData->itemIcons[id].sprite->sItemIconId = id; - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_WaitAnim; + sStorage->itemIcons[id].sprite->sItemIconId = id; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_WaitAnim; break; case ITEM_CB_TO_HAND: - sPSSData->itemIcons[id].sprite->sState = 0; - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToHand; + sStorage->itemIcons[id].sprite->sState = 0; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToHand; break; case ITEM_CB_TO_MON: - sPSSData->itemIcons[id].sprite->sState = 0; - sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToMon; + sStorage->itemIcons[id].sprite->sState = 0; + sStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + sStorage->itemIcons[id].sprite->sCursorPos = cursorPos; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToMon; break; case ITEM_CB_SWAP_TO_HAND: - sPSSData->itemIcons[id].sprite->sState = 0; - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToHand; - sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; + sStorage->itemIcons[id].sprite->sState = 0; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToHand; + sStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + sStorage->itemIcons[id].sprite->sCursorPos = cursorPos; break; case ITEM_CB_SWAP_TO_MON: - sPSSData->itemIcons[id].sprite->sState = 0; - sPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - sPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToMon; + sStorage->itemIcons[id].sprite->sState = 0; + sStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + sStorage->itemIcons[id].sprite->sCursorPos = cursorPos; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToMon; break; case ITEM_CB_HIDE_PARTY: // If cursor is on a Pokémon with a held item and // the player closes the party menu, have the held // item follow the Pokémon as the menu slides out - sPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_HideParty; + sStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_HideParty; break; } } @@ -9017,8 +9017,8 @@ static void SetItemIconActive(u8 id, bool8 active) if (id >= MAX_ITEM_ICONS) return; - sPSSData->itemIcons[id].active = active; - sPSSData->itemIcons[id].sprite->invisible = (active == FALSE); + sStorage->itemIcons[id].active = active; + sStorage->itemIcons[id].sprite->invisible = (active == FALSE); } static const u32 *GetItemIconPic(u16 itemId) @@ -9036,9 +9036,9 @@ static void PrintItemDescription(void) const u8 *description; if (IsMovingItem()) - description = ItemId_GetDescription(sPSSData->movingItemId); + description = ItemId_GetDescription(sStorage->movingItemId); else - description = ItemId_GetDescription(sPSSData->displayMonItemId); + description = ItemId_GetDescription(sStorage->displayMonItemId); FillWindowPixelBuffer(2, PIXEL_FILL(1)); AddTextPrinterParameterized5(2, 1, description, 4, 0, 0, NULL, 0, 1); @@ -9046,7 +9046,7 @@ static void PrintItemDescription(void) static void InitItemInfoWindow(void) { - sPSSData->itemInfoWindowOffset = 21; + sStorage->itemInfoWindowOffset = 21; LoadBgTiles(0, sItemInfoFrame_Gfx, 0x80, 0x13A); DrawItemInfoWindow(0); } @@ -9055,33 +9055,33 @@ static bool8 UpdateItemInfoWindowSlideIn(void) { s32 i, pos; - if (sPSSData->itemInfoWindowOffset == 0) + if (sStorage->itemInfoWindowOffset == 0) return FALSE; - sPSSData->itemInfoWindowOffset--; - pos = 21 - sPSSData->itemInfoWindowOffset; + sStorage->itemInfoWindowOffset--; + pos = 21 - sStorage->itemInfoWindowOffset; for (i = 0; i < pos; i++) - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sStorage->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); DrawItemInfoWindow(pos); - return (sPSSData->itemInfoWindowOffset != 0); + return (sStorage->itemInfoWindowOffset != 0); } static bool8 UpdateItemInfoWindowSlideOut(void) { s32 i, pos; - if (sPSSData->itemInfoWindowOffset == 22) + if (sStorage->itemInfoWindowOffset == 22) return FALSE; - if (sPSSData->itemInfoWindowOffset == 0) + if (sStorage->itemInfoWindowOffset == 0) FillBgTilemapBufferRect(0, 0, 21, 12, 1, 9, 17); - sPSSData->itemInfoWindowOffset++; - pos = 21 - sPSSData->itemInfoWindowOffset; + sStorage->itemInfoWindowOffset++; + pos = 21 - sStorage->itemInfoWindowOffset; for (i = 0; i < pos; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sStorage->itemInfoWindowOffset + i, i, 13, 1, 7, 15, 21); } if (pos >= 0) @@ -9138,9 +9138,9 @@ static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite) static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite) { - sprite->pos1.x = sPSSData->cursorSprite->pos1.x + 4; - sprite->pos1.y = sPSSData->cursorSprite->pos1.y + sPSSData->cursorSprite->pos2.y + 8; - sprite->oam.priority = sPSSData->cursorSprite->oam.priority; + sprite->pos1.x = sStorage->cursorSprite->pos1.x + 4; + sprite->pos1.y = sStorage->cursorSprite->pos1.y + sStorage->cursorSprite->pos2.y + 8; + sprite->oam.priority = sStorage->cursorSprite->oam.priority; } static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite) -- cgit v1.2.3 From 52495e889fcc5a0045a77234ab28e06fd957f542 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 17 Apr 2021 23:55:24 -0400 Subject: Doc storage - cleanup --- src/pokemon_storage_system.c | 707 ++++++++++++++++++++++++++----------------- 1 file changed, 434 insertions(+), 273 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index c4b3c6f60..c17b20437 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -42,6 +42,14 @@ #include "constants/rgb.h" #include "constants/songs.h" +/* + NOTE: This file is large. Some general groups of functions have + been labeled with commented headers to make navigation easier. + Search for "SECTION:" to locate them. These sections are not + hard and fast rules, but give a basic idea of where certain + types of functions are likely located. +*/ + // PC main menu options enum { OPTION_WITHDRAW, @@ -215,10 +223,10 @@ enum { PALTAG_4, // Unused PALTAG_5, // Unused PALTAG_DISPLAY_MON, - PALTAG_7, + PALTAG_MISC_1, PALTAG_MARKING_COMBO, PALTAG_BOX_TITLE, - PALTAG_10, + PALTAG_MISC_2, PALTAG_ITEM_ICON_0, PALTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites PALTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites @@ -316,6 +324,7 @@ enum { MULTIMOVE_PLACE_MONS, }; +// IDs for TilemapUtil enum { TILEMAPID_PKMN_DATA, // The "Pkmn Data" text at the top of the display TILEMAPID_PARTY_MENU, @@ -394,9 +403,9 @@ struct PokemonStorageSystemData struct UnkUtil unkUtil; struct UnkUtilData unkUtilData[8]; u16 partyMenuTilemapBuffer[0x108]; - u16 partyMenuUnused; // Never read + u16 partyMenuUnused1; // Never read u16 partyMenuY; - u8 field_2C4; // Unused + u8 partyMenuUnused2; // Unused u8 partyMenuMoveTimer; u8 showPartyMenuState; bool8 closeBoxFlashing; @@ -415,7 +424,7 @@ struct PokemonStorageSystemData u16 scrollUnused4; // Never read u16 scrollUnused5; // Never read u16 scrollUnused6; // Never read - u8 filler[22]; + u8 filler1[22]; u8 boxTitleTiles[1024]; u8 boxTitleCycleId; u8 wallpaperLoadState; // Written to, but never read. @@ -427,9 +436,9 @@ struct PokemonStorageSystemData struct Sprite *curBoxTitleSprites[2]; struct Sprite *nextBoxTitleSprites[2]; struct Sprite *arrowSprites[2]; - u32 boxTitlePalBits; - u8 field_73C[80]; // Unused - u16 field_78C; // Never read. + u32 wallpaperPalBits; + u8 filler2[80]; // Unused + u16 unkUnused1; // Never read. s16 wallpaperSetId; s16 wallpaperId; u16 wallpaperTilemap[360]; @@ -441,14 +450,14 @@ struct PokemonStorageSystemData struct Sprite *movingMonSprite; struct Sprite *partySprites[PARTY_SIZE]; struct Sprite *boxMonsSprites[IN_BOX_COUNT]; - struct Sprite **field_B00; + struct Sprite **shiftMonSpritePtr; struct Sprite **releaseMonSpritePtr; u16 numIconsPerSpecies[MAX_MON_ICONS]; u16 iconSpeciesList[MAX_MON_ICONS]; u16 boxSpecies[IN_BOX_COUNT]; u32 boxPersonalities[IN_BOX_COUNT]; - u8 field_C5C; - u8 field_C5D; + u8 incomingBoxId; + u8 shiftTimer; u8 numPartyToCompact; u16 iconScrollDistance; s16 iconScrollPos; @@ -496,7 +505,7 @@ struct PokemonStorageSystemData u8 displayMonItemName[36]; bool8 (*monPlaceChangeFunc)(void); u8 monPlaceChangeState; - u8 field_D91; + u8 shiftBoxId; struct Sprite *markingComboSprite; struct Sprite *waveformSprites[2]; u16 *markingComboTilesPtr; @@ -530,14 +539,14 @@ struct PokemonStorageSystemData struct ItemIcon itemIcons[MAX_ITEM_ICONS]; u16 movingItemId; u16 itemInfoWindowOffset; - u8 field_2238; // Unused + u8 unkUnused2; // Unused u16 displayMonPalOffset; u16 *displayMonTilePtr; struct Sprite *displayMonSprite; u16 displayMonPalBuffer[0x40]; u8 tileBuffer[0x800]; - u8 field_2AC4[0x1800]; // Unused - u8 field_42C4[0x800]; + u8 unusedBuffer[0x1800]; // Unused + u8 itemIconBuffer[0x800]; u8 wallpaperBgTilemapBuffer[0x1000]; u8 displayMenuTilemapBuffer[0x800]; }; @@ -561,122 +570,8 @@ EWRAM_DATA static u8 sMovingMonOrigBoxId = 0; EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0; EWRAM_DATA static bool8 sAutoActionOn = 0; -static void CreateMainMenu(u8, s16 *); +// Main tasks static void EnterPokeStorage(u8); -static u8 GetCurrentBoxOption(void); -static u8 HandleInput(void); -static u8 GetSavedCursorPos(void); -static u8 GetNumPartySpritesCompacting(void); -static void LoadWallpaperGfx(u8, s8); -static void CreateIncomingBoxTitle(u8, s8); -static void StartBoxScrollArrowsSlide(s8); -static void SetCurrentBox(u8); -static void CreateInitBoxTask(u8); -static void ChooseBoxMenu_CreateSprites(u8); -static void TrimOldWallpaper(void *); -static void ChooseBoxMenu_DestroySprites(void); -static void ChooseBoxMenu_MoveLeft(void); -static void ScrollBackground(void); -static void ChooseBoxMenu_MoveRight(void); -static void ChooseBoxMenu_PrintInfo(void); -static void UpdateCloseBoxButtonFlash(void); -static void ToggleCursorAutoAction(void); -static void LoadSavedMovingMon(void); -static void SetSelectionAfterSummaryScreen(void); -static void GiveChosenBagItem(void); -static void SetUpHidePartyMenu(void); -static void DestroyAllPartyMonIcons(void); -static void MoveHeldItemWithPartyMenu(void); -static void LoadPokeStorageMenuGfx(void); -static void LoadWaveformSpritePalette(void); -static void SaveCursorPos(void); -static void sub_80CD36C(void); -static void sub_80CD3EC(void); -static void sub_80CAC1C(void); -static void ReshowDisplayMon(void); -static void SetScrollingBackground(void); -static void sub_80CABE0(void); -static void sub_80CAEAC(void); -static void CreateItemIconSprites(void); -static void TryHideItemAtCursor(void); -static void ClearSavedCursorPos(void); -static void InitMonIconFields(void); -static void sub_80CA0D8(void); -static void AddMenu(void); -static void InitReleaseMon(void); -static void InitCanReleaseMonVars(void); -static void ReleaseMon(void); -static void RefreshDisplayMonData(void); -static void CreateDisplayMonSprite(void); -static void CreateMarkingComboSprite(void); -static void CreateWaveformSprites(void); -static void ReshowReleaseMon(void); -static void TrySetCursorFistAnim(void); -static void ClearBottomWindow(void); -static void InitSupplementalTilemaps(void); -static void RemoveMenu(void); -static void RefreshDisplayMon(void); -static void MoveItemFromCursorToBag(void); -static void PrintDisplayMonInfo(void); -static void UpdateWaveformAnimation(void); -static void AddWallpaperSetsMenu(void); -static void CreateBoxScrollArrows(void); -static void InitMenu(void); -static void StopBoxScrollArrowsSlide(void); -static void CreateCursorSprites(void); -static void TryRefreshDisplayMon(void); -static void CycleBoxTitleSprites(void); -static void InitItemInfoWindow(void); -static void DrawItemInfoWindow(u32); -static void SetPartySlotTilemaps(void); -static void PrintItemDescription(void); -static void SaveMovingMon(void); -static void SetCursorInParty(void); -static void InitSummaryScreenData(void); -static void TryShowItemAtCursor(void); -static void StopFlashingCloseBoxButton(void); -static void FreePokeStorageData(void); -static void AddBoxMenu(void); -static void CycleBoxTitleColor(void); -static void MoveMon(void); -static void PlaceMon(void); -static void UpdatePartySlotColors(void); -static void sub_80CE22C(void); -static void DoCursorNewPosUpdate(void); -static void CompactPartySprites(void); -static void StartFlashingCloseBoxButton(void); -static void SetUpDoShowPartyMenu(void); -static void StartDisplayMonMosaicEffect(void); -static void SpriteCB_ChooseBoxArrow(struct Sprite *); -static void SpriteCB_HeldMon(struct Sprite *); -static void SpriteCB_BoxMonIconScrollOut(struct Sprite *); -static void SpriteCB_Arrow(struct Sprite *); -static bool32 WaitForWallpaperGfxLoad(void); -static bool8 InitPokeStorageWindows(void); -static bool8 ResetReleaseMonSpritePtr(void); -static bool8 TryHideReleaseMon(void); -static bool8 IsInitBoxActive(void); -static bool8 MonPlaceChange_CursorDown(void); -static bool8 MonPlaceChange_CursorUp(void); -static bool8 UpdateItemInfoWindowSlideIn(void); -static bool8 UpdateItemInfoWindowSlideOut(void); -static bool8 DoShowPartyMenu(void); -static bool8 IsItemIconAnimActive(void); -static bool8 ScrollToBox(void); -static bool8 UpdateCursorPos(void); -static bool8 HidePartyMenu(void); -static bool8 IsMovingItem(void); -static bool8 IsDisplayMosaicActive(void); -static bool8 DoWallpaperGfxChange(void); -static bool8 DoMonPlaceChange(void); -static bool8 IsMenuLoading(void); -static bool8 IsRemovingLastPartyMon(void); -static bool8 CanShiftMon(void); -static bool8 IsCursorOnCloseBox(void); -static bool8 IsCursorOnBoxTitle(void); -static bool8 IsCursorInBox(void); -static bool8 IsMonBeingMoved(void); -static bool8 TryStorePartyMonInBox(u8); static void Task_InitPokeStorage(u8); static void Task_PlaceMon(u8); static void Task_ChangeScreen(u8); @@ -708,72 +603,81 @@ static void Task_HandleWallpapers(u8); static void Task_NameBox(u8); static void Task_PrintCantStoreMail(u8); static void Task_HandleMovingMonFromParty(u8); -static void SetUpScrollToBox(u8); -static void StartCursorAnim(u8); -static void SetMovingMonPriority(u8); -static void InitMonPlaceChange(u8); -static void SetMonMarkings(u8); -static void ShowYesNoWindow(s8); -static void SetCursorBoxPosition(u8); -static void AnimateBoxScrollArrows(bool8); -static void UpdateCloseBoxButtonTilemap(bool8); -static void CreatePartyMonsSprites(bool8); -static void PrintMessage(u8 id); + +// Input handlers +static u8 InBoxInput_Normal(void); +static u8 InBoxInput_MovingMultiple(void); +static u8 InBoxInput_SelectingMultiple(void); +static u8 HandleInput(void); +static void AddBoxOptionsMenu(void); +static u8 SetSelectionMenuTexts(void); +static bool8 SetMenuTexts_Mon(void); +static bool8 SetMenuTexts_Item(void); + +// Choose box menu +static void ChooseBoxMenu_CreateSprites(u8); +static void ChooseBoxMenu_DestroySprites(void); +static void ChooseBoxMenu_MoveLeft(void); +static void ChooseBoxMenu_MoveRight(void); +static void ChooseBoxMenu_PrintInfo(void); +static void SpriteCB_ChooseBoxArrow(struct Sprite *); + +// Options menus +static void InitMenu(void); +static void SetMenuText(u8); +static s8 GetMenuItemTextId(u8); +static void AddMenu(void); +static bool8 IsMenuLoading(void); static s16 HandleMenuInput(void); -static s8 RunCanReleaseMon(void); -static u8 GetCursorPosition(void); -static void TakeItemFromMon(u8, u8); -static void GiveItemToMon(u8, u8); -static void MoveItemFromMonToBag(u8, u8); -static void SwapItemsWithMon(u8, u8); -static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); -static void SetWallpaperForCurrentBox(u8); -static void AddWallpapersMenu(u8); -static u16 GetMovingItemId(void); -static void LoadDisplayMonGfx(u16, u32); -static void SpriteCB_DisplayMonMosaic(struct Sprite *); -static void SpriteCB_OutgoingBoxTitle(struct Sprite *); +static void RemoveMenu(void); + +// Pokémon sprites +static void InitMonIconFields(void); +static void SpriteCB_BoxMonIconScrollOut(struct Sprite *); +static void GetIncomingBoxMonData(u8); +static void CreatePartyMonsSprites(bool8); +static void CompactPartySprites(void); +static u8 GetNumPartySpritesCompacting(void); +static void MovePartySpriteToNextSlot(struct Sprite *, u16); static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *); -static void SpriteCB_IncomingBoxTitle(struct Sprite *); static void MovePartySprites(s16); -static void SetPartySlotTilemap(u8, bool8); -static const u8 *GetMovingItemName(void); -static void SetMenuText(u8); -static void TryLoadItemIconAtPos(u8, u8); -static void TryHideItemIconAtPos(u8, u8); -static void InitItemIconInCursor(u16); +static void DestroyAllPartyMonIcons(void); +static void ReshowReleaseMon(void); +static bool8 ResetReleaseMonSpritePtr(void); +static void SetMovingMonPriority(u8); +static void SpriteCB_HeldMon(struct Sprite *); static struct Sprite *CreateMonIconSprite(u16, u32, s16, s16, u8, u8); static void DestroyBoxMonIcon(struct Sprite *); -static void SetBoxSpeciesAndPersonalities(u8); -static void MovePartySpriteToNextSlot(struct Sprite *, u16); -static void Task_InitBox(u8); -static void InitBoxTitle(u8); -static s8 DetermineBoxScrollDirection(u8); -static void DrawWallpaper(const void *, s8, u8); -static s16 GetBoxTitleBaseX(const u8 *); -static bool8 MonPlaceChange_Shift(void); -static bool8 MonPlaceChange_Grab(void); -static bool8 MonPlaceChange_Place(void); -static bool8 MultiMonPlaceChange_Up(void); -static bool8 MultiMonPlaceChange_Down(void); -static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *); -static void SetShiftedMonData(u8, u8); + +// Pokémon data +static void MoveMon(void); +static void PlaceMon(void); +static void RefreshDisplayMon(void); static void SetMovingMonData(u8, u8); static void SetPlacedMonData(u8, u8); static void PurgeMonOrBoxMon(u8, u8); -static void SetDisplayMonData(void *, u8); +static void SetShiftedMonData(u8, u8); +static bool8 TryStorePartyMonInBox(u8); +static void ResetSelectionAfterDeposit(void); +static void InitReleaseMon(void); +static bool8 TryHideReleaseMon(void); +static void InitCanReleaseMonVars(void); +static void ReleaseMon(void); static bool32 AtLeastThreeUsableMons(void); -static u8 InBoxInput_Normal(void); -static u8 InBoxInput_MovingMultiple(void); -static u8 InBoxInput_SelectingMultiple(void); -static s8 GetMenuItemTextId(u8); -static u8 SetSelectionMenuTexts(void); -static bool8 SetMenuTexts_Mon(void); -static bool8 SetMenuTexts_Item(void); -static u8 GetBoxWallpaper(u8); -static void SetBoxWallpaper(u8, u8); +static s8 RunCanReleaseMon(void); +static void SaveMovingMon(void); +static void LoadSavedMovingMon(void); +static void InitSummaryScreenData(void); +static void SetSelectionAfterSummaryScreen(void); +static void SetMonMarkings(u8); +static bool8 IsRemovingLastPartyMon(void); +static bool8 CanShiftMon(void); +static bool8 IsMonBeingMoved(void); +static void TryRefreshDisplayMon(void); +static void ReshowDisplayMon(void); +static void SetDisplayMonData(void *, u8); -// Functions for moving multiple Pokémon at once +// Moving multiple Pokémon at once static void MultiMove_Free(void); static bool8 MultiMove_Init(void); static bool8 MultiMove_RunFunction(void); @@ -802,7 +706,7 @@ static void MultiMove_SelectRow(u8, u8, u8); static void MultiMove_SelectColumn(u8, u8, u8); static void MultiMove_DeselectColumn(u8, u8, u8); -// Functions for Move Items mode +// Move Items mode static bool32 IsItemIconAtPosition(u8, u8); static const u32 *GetItemIconPic(u16); static const u32 *GetItemIconPalette(u16); @@ -812,6 +716,25 @@ static void LoadItemIconGfx(u8, const u32 *, const u32 *); static void SetItemIconAffineAnim(u8, u8); static void SetItemIconActive(u8, bool8); static u8 GetItemIconIdxByPosition(u8, u8); +static void CreateItemIconSprites(void); +static void TryLoadItemIconAtPos(u8, u8); +static void TryHideItemIconAtPos(u8, u8); +static void TakeItemFromMon(u8, u8); +static void InitItemIconInCursor(u16); +static void SwapItemsWithMon(u8, u8); +static void GiveItemToMon(u8, u8); +static void MoveItemFromMonToBag(u8, u8); +static void MoveItemFromCursorToBag(void); +static void MoveHeldItemWithPartyMenu(void); +static bool8 IsItemIconAnimActive(void); +static bool8 IsMovingItem(void); +static const u8 *GetMovingItemName(void); +static u16 GetMovingItemId(void); +static void PrintItemDescription(void); +static void InitItemInfoWindow(void); +static bool8 UpdateItemInfoWindowSlideIn(void); +static bool8 UpdateItemInfoWindowSlideOut(void); +static void DrawItemInfoWindow(u32); static void SetItemIconCallback(u8, u8, u8, u8); static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *); static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *); @@ -821,7 +744,116 @@ static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *); static void SpriteCB_ItemIcon_HideParty(struct Sprite *); static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *); -// Functions for the tilemap updating utility +// Cursor +static void CreateCursorSprites(void); +static void ToggleCursorAutoAction(void); +static u8 GetCursorPosition(void); +static void StartCursorAnim(u8); +static void TryHideItemAtCursor(void); +static void TryShowItemAtCursor(void); +static void InitCursor(void); +static void InitCursorOnReopen(void); +static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *); +static bool8 UpdateCursorPos(void); +static void DoCursorNewPosUpdate(void); +static void SetCursorInParty(void); +static void SetCursorBoxPosition(u8); +static void ClearSavedCursorPos(void); +static void SaveCursorPos(void); +static u8 GetSavedCursorPos(void); +static void InitMonPlaceChange(u8); +static bool8 DoMonPlaceChange(void); +static bool8 MonPlaceChange_Shift(void); +static bool8 MonPlaceChange_Grab(void); +static bool8 MonPlaceChange_Place(void); +static bool8 MultiMonPlaceChange_Up(void); +static bool8 MultiMonPlaceChange_Down(void); +static bool8 MonPlaceChange_CursorDown(void); +static bool8 MonPlaceChange_CursorUp(void); +static void TrySetCursorFistAnim(void); +static bool8 IsCursorOnCloseBox(void); +static bool8 IsCursorOnBoxTitle(void); +static bool8 IsCursorInBox(void); + +// Scroll arrows +static void CreateBoxScrollArrows(void); +static void StartBoxScrollArrowsSlide(s8); +static void StopBoxScrollArrowsSlide(void); +static void AnimateBoxScrollArrows(bool8); +static void SpriteCB_Arrow(struct Sprite *); +static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8); + +// Box title +static void InitBoxTitle(u8); +static void CreateIncomingBoxTitle(u8, s8); +static void CycleBoxTitleSprites(void); +static void SpriteCB_IncomingBoxTitle(struct Sprite *); +static void SpriteCB_OutgoingBoxTitle(struct Sprite *); +static void CycleBoxTitleColor(void); +static s16 GetBoxTitleBaseX(const u8 *); + +// Wallpaper +static void SetWallpaperForCurrentBox(u8); +static bool8 DoWallpaperGfxChange(void); +static void LoadWallpaperGfx(u8, s8); +static bool32 WaitForWallpaperGfxLoad(void); +static void DrawWallpaper(const void *, s8, u8); +static void TrimOldWallpaper(void *); +static void AddWallpaperSetsMenu(void); +static void AddWallpapersMenu(u8); +static u8 GetBoxWallpaper(u8); +static void SetBoxWallpaper(u8, u8); + +// General box +static void CreateInitBoxTask(u8); +static bool8 IsInitBoxActive(void); +static void Task_InitBox(u8); +static void SetUpScrollToBox(u8); +static bool8 ScrollToBox(void); +static s8 DetermineBoxScrollDirection(u8); +static void SetCurrentBox(u8); + +// Misc +static void CreateMainMenu(u8, s16 *); +static u8 GetCurrentBoxOption(void); +static void ScrollBackground(void); +static void UpdateCloseBoxButtonFlash(void); +static void GiveChosenBagItem(void); +static void SetUpHidePartyMenu(void); +static void LoadPokeStorageMenuGfx(void); +static void LoadWaveformSpritePalette(void); +static void InitPokeStorageBg0(void); +static void SetScrollingBackground(void); +static void UpdateBoxToSendMons(void); +static void InitCursorItemIcon(void); +static void InitPalettesAndSprites(void); +static void RefreshDisplayMonData(void); +static void CreateDisplayMonSprite(void); +static void CreateMarkingComboSprite(void); +static void CreateWaveformSprites(void); +static void ClearBottomWindow(void); +static void InitSupplementalTilemaps(void); +static void PrintDisplayMonInfo(void); +static void UpdateWaveformAnimation(void); +static void SetPartySlotTilemaps(void); +static void StopFlashingCloseBoxButton(void); +static void FreePokeStorageData(void); +static void UpdatePartySlotColors(void); +static void StartFlashingCloseBoxButton(void); +static void SetUpDoShowPartyMenu(void); +static void StartDisplayMonMosaicEffect(void); +static bool8 InitPokeStorageWindows(void); +static bool8 DoShowPartyMenu(void); +static bool8 HidePartyMenu(void); +static bool8 IsDisplayMosaicActive(void); +static void ShowYesNoWindow(s8); +static void UpdateCloseBoxButtonTilemap(bool8); +static void PrintMessage(u8 id); +static void LoadDisplayMonGfx(u16, u32); +static void SpriteCB_DisplayMonMosaic(struct Sprite *); +static void SetPartySlotTilemap(u8, bool8); + +// Tilemap utility static void TilemapUtil_SetRect(u8, u16, u16, u16, u16); static void TilemapUtil_Move(u8, u8, s8); static void TilemapUtil_SetMap(u8, u8, const void *, u16, u16); @@ -832,7 +864,7 @@ static void TilemapUtil_Update(u8); static void TilemapUtil_DrawPrev(u8); static void TilemapUtil_Draw(u8); -// Functions for unknown utility +// Unknown utility static void UnkUtil_Init(struct UnkUtil *, struct UnkUtilData *, u32); static void UnkUtil_Run(void); static void UnkUtil_CpuRun(struct UnkUtilData *); @@ -945,8 +977,8 @@ static const u16 sPartySlotEmpty_Tilemap[] = static const u16 sWaveform_Pal[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal"); static const u32 sWaveform_Gfx[] = INCBIN_U32("graphics/pokemon_storage/waveform.4bpp"); -static const u16 gUnknown_085726B4[] = INCBIN_U16("graphics/unused/unknown_5726B4.gbapal"); -static const u16 gUnknown_085726F4[] = INCBIN_U16("graphics/unknown/unknown_5726F4.gbapal"); +static const u16 sUnused_Pal[] = INCBIN_U16("graphics/pokemon_storage/unused.gbapal"); +static const u16 sUnknown_Pal[] = INCBIN_U16("graphics/pokemon_storage/unknown.gbapal"); static const struct WindowTemplate sWindowTemplates[] = { @@ -1022,7 +1054,7 @@ static const struct BgTemplate sBgTemplates[] = static const struct SpritePalette gWaveformSpritePalette = { - sWaveform_Pal, PALTAG_10 + sWaveform_Pal, PALTAG_MISC_2 }; static const struct SpriteSheet sSpriteSheet_Waveform = @@ -1161,7 +1193,7 @@ static const union AnimCmd *const sAnims_Waveform[] = static const struct SpriteTemplate sSpriteTemplate_Waveform = { .tileTag = GFXTAG_WAVEFORM, - .paletteTag = PALTAG_10, + .paletteTag = PALTAG_MISC_2, .oam = &sOamData_Waveform, .anims = sAnims_Waveform, .images = NULL, @@ -1254,7 +1286,7 @@ static const struct SpriteTemplate sSpriteTemplate_BoxTitle = .paletteTag = PALTAG_BOX_TITLE, .oam = &sOamData_BoxTitle, .anims = sAnims_BoxTitle, - .images NULL, + .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; @@ -1287,7 +1319,7 @@ static const union AnimCmd *const sAnims_Arrow[] = static const struct SpriteTemplate sSpriteTemplate_Arrow = { .tileTag = GFXTAG_ARROW, - .paletteTag = PALTAG_10, + .paletteTag = PALTAG_MISC_2, .oam = &sOamData_Arrow, .anims = sAnims_Arrow, .images = NULL, @@ -1299,6 +1331,12 @@ static const u16 sHandCursor_Pal[] = INCBIN_U16("graphics/pokemon_storage/hand_c static const u8 sHandCursor_Gfx[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor.4bpp"); static const u8 sHandCursorShadow_Gfx[] = INCBIN_U8("graphics/pokemon_storage/hand_cursor_shadow.4bpp"); + +//------------------------------------------------------------------------------ +// SECTION: Misc utility +//------------------------------------------------------------------------------ + + void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, s32 bytesToBuffer) { s32 i, tileBytesToBuffer, remainingBytes; @@ -1461,7 +1499,8 @@ u8 *StringCopyAndFillWithSpaces(u8 *dst, const u8 *src, u16 n) return str; } -static void sub_80C7128(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, u16 src_left, u16 src_top, u16 dest_width, u16 dest_height, u16 src_width) +// Unused +static void UnusedWriteRectCpu(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, u16 src_left, u16 src_top, u16 dest_width, u16 dest_height, u16 src_width) { u16 i; @@ -1476,7 +1515,8 @@ static void sub_80C7128(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, } } -static void sub_80C71A4(u16 *dest, u16 dest_left, u16 dest_top, u16 width, u16 height) +// Unused +static void UnusedWriteRectDma(u16 *dest, u16 dest_left, u16 dest_top, u16 width, u16 height) { u16 i; @@ -1486,6 +1526,16 @@ static void sub_80C71A4(u16 *dest, u16 dest_left, u16 dest_top, u16 width, u16 h Dma3FillLarge16_(0, dest, width); } + +//------------------------------------------------------------------------------ +// SECTION: Main menu +// +// The below functions generally handle the PC main menu where the main +// options can be selected (Withdraw, Deposit, etc.), as well as exiting +// Pokémon Storage back to this menu. +//------------------------------------------------------------------------------ + + enum { STATE_LOAD, STATE_FADE_IN, @@ -1714,6 +1764,16 @@ void ResetPokemonStorageSystem(void) ResetWaldaWallpaper(); } + +//------------------------------------------------------------------------------ +// SECTION: Choose Box menu +// +// The below functions handle the popup menu that allows the player to cycle +// through the boxes and select one. Used when storing Pokémon in Deposit mode +// and for the Jump feature. +//------------------------------------------------------------------------------ + + static void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *menu, u16 tileTag, u16 palTag, u8 subpriority, bool32 loadPal) { struct SpritePalette palette = @@ -1919,6 +1979,17 @@ static void SpriteCB_ChooseBoxArrow(struct Sprite *sprite) } } + +//------------------------------------------------------------------------------ +// SECTION: Main tasks +// +// Below are the main task callbacks that handle the primary actions the +// player can take in the PC. The most 'important' of these tasks is the +// primary one, Task_PokeStorageMain. Also included are some basic +// initialization functions. +//------------------------------------------------------------------------------ + + static void VBlankCB_PokeStorage(void) { LoadOam(); @@ -1989,7 +2060,7 @@ static void ResetAllBgCoords(void) SetGpuReg(REG_OFFSET_BG3VOFS, 0); } -static void sub_80C7E98(void) +static void ResetForPokeStorage(void) { ResetPaletteFade(); ResetSpriteData(); @@ -2006,7 +2077,7 @@ static void sub_80C7E98(void) sStorage->closeBoxFlashing = FALSE; } -static void sub_80C7F1C(void) +static void InitStartingPosData(void) { ClearSavedCursorPos(); sInPartyMenu = (sStorage->boxOption == OPTION_DEPOSIT); @@ -2036,7 +2107,7 @@ static void Task_InitPokeStorage(u8 taskId) case 0: SetVBlankCallback(NULL); SetGpuReg(REG_OFFSET_DISPCNT, 0); - sub_80C7E98(); + ResetForPokeStorage(); if (sStorage->isReopening) { switch (sWhichToReshow) @@ -2074,14 +2145,14 @@ static void Task_InitPokeStorage(u8 taskId) case 3: ResetAllBgCoords(); if (!sStorage->isReopening) - sub_80C7F1C(); + InitStartingPosData(); break; case 4: InitMonIconFields(); if (!sStorage->isReopening) - sub_80CD36C(); + InitCursor(); else - sub_80CD3EC(); + InitCursorOnReopen(); break; case 5: if (!MultiMove_Init()) @@ -2092,11 +2163,11 @@ static void Task_InitPokeStorage(u8 taskId) else { SetScrollingBackground(); - sub_80CAC1C(); + InitPokeStorageBg0(); } break; case 6: - sub_80CA0D8(); + InitPalettesAndSprites(); break; case 7: InitSupplementalTilemaps(); @@ -2118,7 +2189,7 @@ static void Task_InitPokeStorage(u8 taskId) else { CreateItemIconSprites(); - sub_80CAEAC(); + InitCursorItemIcon(); } break; case 10: @@ -2795,7 +2866,7 @@ static void Task_DepositMenu(u8 taskId) { case 0: PrintMessage(MSG_DEPOSIT_IN_WHICH_BOX); - LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); + LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_MISC_1, 3, FALSE); CreateChooseBoxMenuSprites(sDepositBoxId); sStorage->state++; break; @@ -2836,7 +2907,7 @@ static void Task_DepositMenu(u8 taskId) case 3: if (GetNumPartySpritesCompacting() == 0) { - sub_80CE22C(); + ResetSelectionAfterDeposit(); StartDisplayMonMosaicEffect(); UpdatePartySlotColors(); SetPokeStorageTask(Task_PokeStorageMain); @@ -3450,7 +3521,7 @@ static void Task_JumpBox(u8 taskId) { case 0: PrintMessage(MSG_JUMP_TO_WHICH_BOX); - LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_7, 3, FALSE); + LoadChooseBoxMenuGfx(&sStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU, PALTAG_MISC_1, 3, FALSE); CreateChooseBoxMenuSprites(StorageGetCurrentBox()); sStorage->state++; break; @@ -3601,7 +3672,7 @@ static void Task_OnCloseBoxPressed(u8 taskId) case 4: if (!IsComputerScreenCloseEffectActive()) { - sub_80CABE0(); + UpdateBoxToSendMons(); gPlayerPartyCount = CalculatePlayerPartyCount(); sStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; SetPokeStorageTask(Task_ChangeScreen); @@ -3662,7 +3733,7 @@ static void Task_OnBPressed(u8 taskId) case 4: if (!IsComputerScreenCloseEffectActive()) { - sub_80CABE0(); + UpdateBoxToSendMons(); gPlayerPartyCount = CalculatePlayerPartyCount(); sStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; SetPokeStorageTask(Task_ChangeScreen); @@ -3737,6 +3808,16 @@ static void FreePokeStorageData(void) FreeAllWindowBuffers(); } + +//------------------------------------------------------------------------------ +// SECTION: Misc +// +// No real uniform section below. Misc functions including more initialization, +// showing/hiding the party menu, updating the Close Box button, printing +// messages, doing the mosaic effect when transitioning between Pokémon, etc. +//------------------------------------------------------------------------------ + + static void SetScrollingBackground(void) { SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_16COLOR | BGCNT_SCREENBASE(31)); @@ -3778,11 +3859,11 @@ static void LoadWaveformSpritePalette(void) LoadSpritePalette(&gWaveformSpritePalette); } -static void sub_80CA0D8(void) +static void InitPalettesAndSprites(void) { LoadPalette(sInterface_Pal, 0, sizeof(sInterface_Pal)); LoadPalette(sPkmnDataGray_Pal, 0x20, sizeof(sPkmnDataGray_Pal)); - LoadPalette(gUnknown_085726F4, 0xF0, sizeof(gUnknown_085726F4)); + LoadPalette(sUnknown_Pal, 0xF0, sizeof(sUnknown_Pal)); if (sStorage->boxOption != OPTION_MOVE_ITEMS) LoadPalette(sBg_Pal, 0x30, sizeof(sBg_Pal)); else @@ -4003,7 +4084,7 @@ static void InitSupplementalTilemaps(void) static void SetUpShowPartyMenu(void) { - sStorage->partyMenuUnused = 20; + sStorage->partyMenuUnused1 = 20; sStorage->partyMenuY = 2; sStorage->partyMenuMoveTimer = 0; CreatePartyMonsSprites(FALSE); @@ -4014,7 +4095,7 @@ static bool8 ShowPartyMenu(void) if (sStorage->partyMenuMoveTimer == 20) return FALSE; - sStorage->partyMenuUnused--; + sStorage->partyMenuUnused1--; sStorage->partyMenuY++; TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, 1); TilemapUtil_Update(TILEMAPID_PARTY_MENU); @@ -4033,7 +4114,7 @@ static bool8 ShowPartyMenu(void) static void SetUpHidePartyMenu(void) { - sStorage->partyMenuUnused = 0; + sStorage->partyMenuUnused1 = 0; sStorage->partyMenuY = 22; sStorage->partyMenuMoveTimer = 0; if (sStorage->boxOption == OPTION_MOVE_ITEMS) @@ -4044,7 +4125,7 @@ static bool8 HidePartyMenu(void) { if (sStorage->partyMenuMoveTimer != 20) { - sStorage->partyMenuUnused++; + sStorage->partyMenuUnused1++; sStorage->partyMenuY--; TilemapUtil_Move(TILEMAPID_PARTY_MENU, 3, -1); TilemapUtil_Update(TILEMAPID_PARTY_MENU); @@ -4186,7 +4267,7 @@ static bool8 DoShowPartyMenu(void) return TRUE; } -static void sub_80CABE0(void) +static void UpdateBoxToSendMons(void) { if (sLastUsedBox != StorageGetCurrentBox()) { @@ -4195,7 +4276,7 @@ static void sub_80CABE0(void) } } -static void sub_80CAC1C(void) +static void InitPokeStorageBg0(void) { SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(29)); LoadUserWindowBorderGfx(1, 2, 208); @@ -4307,7 +4388,7 @@ static u8 GetCurrentBoxOption(void) return sCurrentBoxOption; } -static void sub_80CAEAC(void) +static void InitCursorItemIcon(void) { if (!IsCursorOnBoxTitle()) { @@ -4324,6 +4405,16 @@ static void sub_80CAEAC(void) } } + +//------------------------------------------------------------------------------ +// SECTION: Pokémon sprites +// +// The below functions generally handle the Pokémon icon sprites, including +// moving them with a scrolling box, shifting the party sprites, and +// animating released Pokémon. +//------------------------------------------------------------------------------ + + static void InitMonIconFields(void) { u16 i; @@ -4339,7 +4430,7 @@ static void InitMonIconFields(void) sStorage->boxMonsSprites[i] = NULL; sStorage->movingMonSprite = NULL; - sStorage->field_78C = 0; + sStorage->unkUnused1 = 0; } static u8 GetMonIconPriorityByCursorPos(void) @@ -4538,7 +4629,7 @@ static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) sStorage->boxMonsSprites[boxPosition]->sSpeed = speed; sStorage->boxMonsSprites[boxPosition]->sScrollInDestX = xDest; sStorage->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; - if (GetBoxMonDataAt(sStorage->field_C5C, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) + if (GetBoxMonDataAt(sStorage->incomingBoxId, boxPosition, MON_DATA_HELD_ITEM) == ITEM_NONE) sStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; iconsCreated++; } @@ -4565,7 +4656,7 @@ static void InitBoxMonIconScroll(u8 boxId, s8 direction) sStorage->iconScrollDistance = 32; sStorage->iconScrollSpeed = -(6 * direction); sStorage->iconScrollNumIncoming = 0; - SetBoxSpeciesAndPersonalities(boxId); + GetIncomingBoxMonData(boxId); if (direction > 0) sStorage->iconScrollCurColumn = 0; else @@ -4625,7 +4716,7 @@ static bool8 UpdateBoxMonIconScroll(void) return TRUE; } -static void SetBoxSpeciesAndPersonalities(u8 boxId) +static void GetIncomingBoxMonData(u8 boxId) { s32 i, j, boxPosition; @@ -4641,7 +4732,7 @@ static void SetBoxSpeciesAndPersonalities(u8 boxId) } } - sStorage->field_C5C = boxId; + sStorage->incomingBoxId = boxId; } static void DestroyBoxMonIconAtPosition(u8 boxPosition) @@ -4867,7 +4958,7 @@ static void SetMovingMonSprite(u8 mode, u8 id) sStorage->movingMonSprite->subpriority = 7; } -static void sub_80CBCAC(u8 boxId, u8 position) +static void SetPlacedMonSprite(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) // party mon { @@ -4885,47 +4976,47 @@ static void sub_80CBCAC(u8 boxId, u8 position) sStorage->movingMonSprite = NULL; } -static void sub_80CBD5C(u8 boxId, u8 position) +static void SaveMonSpriteAtPos(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) // party mon - sStorage->field_B00 = &sStorage->partySprites[position]; + sStorage->shiftMonSpritePtr = &sStorage->partySprites[position]; else - sStorage->field_B00 = &sStorage->boxMonsSprites[position]; + sStorage->shiftMonSpritePtr = &sStorage->boxMonsSprites[position]; sStorage->movingMonSprite->callback = SpriteCallbackDummy; - sStorage->field_C5D = 0; + sStorage->shiftTimer = 0; } -static bool8 sub_80CBDC4(void) +static bool8 MoveShiftingMons(void) { - if (sStorage->field_C5D == 16) + if (sStorage->shiftTimer == 16) return FALSE; - sStorage->field_C5D++; - if (sStorage->field_C5D & 1) + sStorage->shiftTimer++; + if (sStorage->shiftTimer & 1) { - (*sStorage->field_B00)->pos1.y--; + (*sStorage->shiftMonSpritePtr)->pos1.y--; sStorage->movingMonSprite->pos1.y++; } - (*sStorage->field_B00)->pos2.x = gSineTable[sStorage->field_C5D * 8] / 16; - sStorage->movingMonSprite->pos2.x = -(gSineTable[sStorage->field_C5D * 8] / 16); - if (sStorage->field_C5D == 8) + (*sStorage->shiftMonSpritePtr)->pos2.x = gSineTable[sStorage->shiftTimer * 8] / 16; + sStorage->movingMonSprite->pos2.x = -(gSineTable[sStorage->shiftTimer * 8] / 16); + if (sStorage->shiftTimer == 8) { - sStorage->movingMonSprite->oam.priority = (*sStorage->field_B00)->oam.priority; - sStorage->movingMonSprite->subpriority = (*sStorage->field_B00)->subpriority; - (*sStorage->field_B00)->oam.priority = GetMonIconPriorityByCursorPos(); - (*sStorage->field_B00)->subpriority = 7; + sStorage->movingMonSprite->oam.priority = (*sStorage->shiftMonSpritePtr)->oam.priority; + sStorage->movingMonSprite->subpriority = (*sStorage->shiftMonSpritePtr)->subpriority; + (*sStorage->shiftMonSpritePtr)->oam.priority = GetMonIconPriorityByCursorPos(); + (*sStorage->shiftMonSpritePtr)->subpriority = 7; } - if (sStorage->field_C5D == 16) + if (sStorage->shiftTimer == 16) { struct Sprite *sprite = sStorage->movingMonSprite; - sStorage->movingMonSprite = (*sStorage->field_B00); - *sStorage->field_B00 = sprite; + sStorage->movingMonSprite = (*sStorage->shiftMonSpritePtr); + *sStorage->shiftMonSpritePtr = sprite; sStorage->movingMonSprite->callback = SpriteCB_HeldMon; - (*sStorage->field_B00)->callback = SpriteCallbackDummy; + (*sStorage->shiftMonSpritePtr)->callback = SpriteCallbackDummy; } return TRUE; @@ -5091,6 +5182,14 @@ static void DestroyBoxMonIcon(struct Sprite *sprite) DestroySprite(sprite); } + +//------------------------------------------------------------------------------ +// SECTION: General box +// +// Some basic box functions, including initializing the box and scrolling. +//------------------------------------------------------------------------------ + + #define tState data[0] #define tDmaIdx data[1] #define tBoxId data[2] @@ -5221,6 +5320,12 @@ static s8 DetermineBoxScrollDirection(u8 boxId) return (i < TOTAL_BOXES_COUNT / 2) ? 1 : -1; } + +//------------------------------------------------------------------------------ +// SECTION: Wallpaper gfx +//------------------------------------------------------------------------------ + + static void SetWallpaperForCurrentBox(u8 wallpaperId) { u8 boxId = StorageGetCurrentBox(); @@ -5233,7 +5338,7 @@ static bool8 DoWallpaperGfxChange(void) switch (sStorage->wallpaperChangeState) { case 0: - BeginNormalPaletteFade(sStorage->boxTitlePalBits, 1, 0, 16, RGB_WHITEALPHA); + BeginNormalPaletteFade(sStorage->wallpaperPalBits, 1, 0, 16, RGB_WHITEALPHA); sStorage->wallpaperChangeState++; break; case 1: @@ -5248,7 +5353,7 @@ static bool8 DoWallpaperGfxChange(void) if (WaitForWallpaperGfxLoad() == TRUE) { CycleBoxTitleColor(); - BeginNormalPaletteFade(sStorage->boxTitlePalBits, 1, 16, 0, RGB_WHITEALPHA); + BeginNormalPaletteFade(sStorage->wallpaperPalBits, 1, 16, 0, RGB_WHITEALPHA); sStorage->wallpaperChangeState++; } break; @@ -5369,6 +5474,12 @@ static void TrimOldWallpaper(void *tilemap) } } + +//------------------------------------------------------------------------------ +// SECTION: Box Title +//------------------------------------------------------------------------------ + + static void InitBoxTitle(u8 boxId) { u8 tagIndex; @@ -5386,11 +5497,11 @@ static void InitBoxTitle(u8 boxId) sStorage->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; // Shadow color sStorage->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; // Text Color LoadSpritePalettes(palettes); - sStorage->boxTitlePalBits = 0x3f0; + sStorage->wallpaperPalBits = 0x3f0; tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); sStorage->boxTitlePalOffset = 0x10e + 16 * tagIndex; - sStorage->boxTitlePalBits |= 0x10000 << tagIndex; + sStorage->wallpaperPalBits |= 0x10000 << tagIndex; // The below seems intended to have separately tracked // the incoming wallpaper title's palette, but as they now @@ -5398,7 +5509,7 @@ static void InitBoxTitle(u8 boxId) // this is redundant along with the use of boxTitleAltPalOffset tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); sStorage->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; - sStorage->boxTitlePalBits |= 0x10000 << tagIndex; + sStorage->wallpaperPalBits |= 0x10000 << tagIndex; StringCopyPadded(sStorage->boxTitleText, GetBoxNamePtr(boxId), 0, 8); DrawTextWindowAndBufferTiles(sStorage->boxTitleText, sStorage->boxTitleTiles, 0, 0, 2); @@ -5526,6 +5637,12 @@ static s16 GetBoxTitleBaseX(const u8 *string) return DISPLAY_WIDTH - 64 - GetStringWidth(1, string, 0) / 2; } + +//------------------------------------------------------------------------------ +// SECTION: Scroll arrows +//------------------------------------------------------------------------------ + + // Sprite data for box scroll arrows #define sState data[0] #define sTimer data[1] @@ -5673,7 +5790,16 @@ static struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority return &gSprites[spriteId]; } -static void sub_80CD36C(void) + +//------------------------------------------------------------------------------ +// SECTION: Cursor movement +// +// The functions below generally handle the cursor's movement, including +// moving around the box and picking up/putting down Pokémon. +//------------------------------------------------------------------------------ + + +static void InitCursor(void) { if (sStorage->boxOption != OPTION_DEPOSIT) sCursorArea = CURSOR_AREA_IN_BOX; @@ -5692,7 +5818,7 @@ static void sub_80CD36C(void) TryRefreshDisplayMon(); } -static void sub_80CD3EC(void) +static void InitCursorOnReopen(void) { CreateCursorSprites(); ReshowDisplayMon(); @@ -6111,23 +6237,23 @@ static bool8 MonPlaceChange_Shift(void) switch (sCursorArea) { case CURSOR_AREA_IN_PARTY: - sStorage->field_D91 = TOTAL_BOXES_COUNT; + sStorage->shiftBoxId = TOTAL_BOXES_COUNT; break; case CURSOR_AREA_IN_BOX: - sStorage->field_D91 = StorageGetCurrentBox(); + sStorage->shiftBoxId = StorageGetCurrentBox(); break; default: return FALSE; } StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_OPEN); - sub_80CBD5C(sStorage->field_D91, sCursorPosition); + SaveMonSpriteAtPos(sStorage->shiftBoxId, sCursorPosition); sStorage->monPlaceChangeState++; break; case 1: - if (!sub_80CBDC4()) + if (!MoveShiftingMons()) { StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_FIST); - SetShiftedMonData(sStorage->field_D91, sCursorPosition); + SetShiftedMonData(sStorage->shiftBoxId, sCursorPosition); sStorage->monPlaceChangeState++; } break; @@ -6179,6 +6305,16 @@ static bool8 MonPlaceChange_CursorUp(void) return TRUE; } + +//------------------------------------------------------------------------------ +// SECTION: Pokémon data +// +// The functions below handle moving Pokémon data around while using the PC, +// including changing the positions of Pokémon, releasing Pokémon, viewing the +// summary screen, and updating the display of the currently selected Pokémon. +//------------------------------------------------------------------------------ + + static void MoveMon(void) { switch (sCursorArea) @@ -6209,12 +6345,12 @@ static void PlaceMon(void) { case CURSOR_AREA_IN_PARTY: SetPlacedMonData(TOTAL_BOXES_COUNT, sCursorPosition); - sub_80CBCAC(TOTAL_BOXES_COUNT, sCursorPosition); + SetPlacedMonSprite(TOTAL_BOXES_COUNT, sCursorPosition); break; case CURSOR_AREA_IN_BOX: boxId = StorageGetCurrentBox(); SetPlacedMonData(boxId, sCursorPosition); - sub_80CBCAC(boxId, sCursorPosition); + SetPlacedMonSprite(boxId, sCursorPosition); break; default: return; @@ -6301,7 +6437,7 @@ static bool8 TryStorePartyMonInBox(u8 boxId) return TRUE; } -static void sub_80CE22C(void) +static void ResetSelectionAfterDeposit(void) { StartSpriteAnim(sStorage->cursorSprite, CURSOR_ANIM_BOUNCE); TryRefreshDisplayMon(); @@ -6867,6 +7003,14 @@ static void SetDisplayMonData(void *pokemon, u8 mode) } } + +//------------------------------------------------------------------------------ +// SECTION: Input handlers +// +// The functions below process context-dependent input +//------------------------------------------------------------------------------ + + static u8 HandleInput_InBox(void) { switch (sStorage->inBoxMovingMode) @@ -7344,7 +7488,7 @@ static u8 HandleInput_OnBox(void) if (JOY_NEW(A_BUTTON)) { AnimateBoxScrollArrows(FALSE); - AddBoxMenu(); + AddBoxOptionsMenu(); return INPUT_BOX_OPTIONS; } @@ -7470,7 +7614,7 @@ static u8 HandleInput(void) return INPUT_NONE; } -static void AddBoxMenu(void) +static void AddBoxOptionsMenu(void) { InitMenu(); SetMenuText(MENU_JUMP); @@ -7588,6 +7732,14 @@ static bool8 SetMenuTexts_Item(void) return TRUE; } + +//------------------------------------------------------------------------------ +// SECTION: Cursor +// +// The functions below handle a few of the generic cursor features. +//------------------------------------------------------------------------------ + + static void SpriteCB_CursorShadow(struct Sprite *sprite) { sprite->pos1.x = sStorage->cursorSprite->pos1.x; @@ -7608,7 +7760,7 @@ static void CreateCursorSprites(void) struct SpritePalette spritePalettes[] = { - {sHandCursor_Pal, PALTAG_7}, + {sHandCursor_Pal, PALTAG_MISC_1}, {} }; @@ -7658,7 +7810,7 @@ static void CreateCursorSprites(void) static const struct SpriteTemplate sSpriteTemplate_Cursor = { .tileTag = GFXTAG_CURSOR, - .paletteTag = PALTAG_10, + .paletteTag = PALTAG_MISC_2, .oam = &sOamData_Cursor, .anims = sAnims_Cursor, .images = NULL, @@ -7669,7 +7821,7 @@ static void CreateCursorSprites(void) static const struct SpriteTemplate sSpriteTemplate_CursorShadow = { .tileTag = GFXTAG_CURSOR_SHADOW, - .paletteTag = PALTAG_10, + .paletteTag = PALTAG_MISC_2, .oam = &sOamData_CursorShadow, .anims = gDummySpriteAnimTable, .images = NULL, @@ -7679,8 +7831,8 @@ static void CreateCursorSprites(void) LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePalettes); - sStorage->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_10); // White hand, normal - sStorage->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_7); // Yellow hand, when auto-action is on + sStorage->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_MISC_2); // White hand, normal + sStorage->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_MISC_1); // Yellow hand, when auto-action is on GetCursorCoordsByPos(sCursorArea, sCursorPosition, &x, &y); spriteId = CreateSprite(&sSpriteTemplate_Cursor, x, y, 6); @@ -7775,6 +7927,15 @@ static void TryShowItemAtCursor(void) TryLoadItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); } + +//------------------------------------------------------------------------------ +// SECTION: Menu +// +// The functions below handle the generic options menu that comes up whenever +// something in the PC is selected. +//------------------------------------------------------------------------------ + + static void InitMenu(void) { sStorage->menuItemsCount = 0; @@ -8947,14 +9108,14 @@ static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) if (id >= MAX_ITEM_ICONS) return; - CpuFastFill(0, sStorage->field_42C4, 0x200); + CpuFastFill(0, sStorage->itemIconBuffer, 0x200); LZ77UnCompWram(itemTiles, sStorage->tileBuffer); for (i = 0; i < 3; i++) - CpuFastCopy(&sStorage->tileBuffer[i * 0x60], &sStorage->field_42C4[i * 0x80], 0x60); + CpuFastCopy(&sStorage->tileBuffer[i * 0x60], &sStorage->itemIconBuffer[i * 0x80], 0x60); - CpuFastCopy(sStorage->field_42C4, sStorage->itemIcons[id].tiles, 0x200); - LZ77UnCompWram(itemPal, sStorage->field_42C4); - LoadPalette(sStorage->field_42C4, sStorage->itemIcons[id].palIndex, 0x20); + CpuFastCopy(sStorage->itemIconBuffer, sStorage->itemIcons[id].tiles, 0x200); + LZ77UnCompWram(itemPal, sStorage->itemIconBuffer); + LoadPalette(sStorage->itemIconBuffer, sStorage->itemIcons[id].palIndex, 0x20); } static void SetItemIconAffineAnim(u8 id, u8 animNum) -- cgit v1.2.3 From 5ae5cf110d722c751a3fbfec38ec8f4498a85616 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Tue, 25 May 2021 04:03:11 -0400 Subject: [LEAK-INFORMED] fix fakematch in DrawWallpaper --- src/pokemon_storage_system.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index e5720d914..a7a418a30 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -5437,19 +5437,20 @@ static bool32 WaitForWallpaperGfxLoad(void) static void DrawWallpaper(const void *tilemap, s8 direction, u8 offset) { - s16 var = (offset * 2) + 3; + s16 var = offset * 256; + s16 var2 = (offset * 2) + 3; s16 x = ((sStorage->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; - CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, offset << 8, var); - - if (direction == 0) - return; - if (direction > 0) - x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference - else - x -= 4; + CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, var, var2); + if (direction) + { + if (direction > 0) + x += 0x14; + else + x -= 4; FillBgTilemapBufferRect(2, 0, x, 2, 4, 0x12, 0x11); + } } static void TrimOldWallpaper(void *tilemap) -- cgit v1.2.3 From 5d5327c0b73784c47d18734a291b5463289ca9c5 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Tue, 25 May 2021 04:32:47 -0400 Subject: better match --- src/pokemon_storage_system.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/pokemon_storage_system.c') diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index a7a418a30..c82caf0b0 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -5443,14 +5443,14 @@ static void DrawWallpaper(const void *tilemap, s8 direction, u8 offset) CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, var, var2); - if (direction) - { - if (direction > 0) - x += 0x14; - else - x -= 4; + if (direction == 0) + return; + if (direction > 0) + x += 0x14; + else + x -= 4; + FillBgTilemapBufferRect(2, 0, x, 2, 4, 0x12, 0x11); - } } static void TrimOldWallpaper(void *tilemap) -- cgit v1.2.3