summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/battle_pyramid_bag.c32
-rw-r--r--src/graphics.c2
-rwxr-xr-xsrc/item_menu.c14
-rw-r--r--src/item_menu_icons.c12
-rw-r--r--src/lilycove_lady.c2
-rw-r--r--src/menu_helpers.c60
-rw-r--r--src/player_pc.c20
-rw-r--r--src/pokeblock.c506
-rw-r--r--src/pokeblock_feed.c871
-rw-r--r--src/use_pokeblock.c2
10 files changed, 823 insertions, 698 deletions
diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c
index f39bbf522..23f2f9653 100644
--- a/src/battle_pyramid_bag.c
+++ b/src/battle_pyramid_bag.c
@@ -63,7 +63,7 @@ static void sub_81C56F8(void);
static void sub_81C5A20(void);
static void sub_81C6BD8(void);
static void sub_81C6EF4(void);
-static void sub_81C700C(void);
+static void CreateSwapLine(void);
static void sub_81C6E98(void);
static void sub_81C6F20(void);
static void sub_81C6404(void);
@@ -84,8 +84,8 @@ static void sub_81C5F08(u8 windowId, u8 horizontalCount, u8 verticalCount);
static bool8 IsValidMenuAction(s8 arg0);
static void sub_81C6DAC(u8 taskId, const struct YesNoFuncTable *yesNoTable);
static void sub_81C6CEC(u8 windowId);
-static void sub_81C704C(u8 y);
-static void sub_81C7028(bool8 invisible);
+static void UpdateSwapLinePos(u8 y);
+static void SetSwapLineInvisibility(bool8 invisible);
static void sub_81C6F68(struct Sprite *sprite);
static void BagAction_UseOnField(u8 taskId);
static void BagAction_Toss(u8 taskId);
@@ -489,7 +489,7 @@ static bool8 sub_81C5078(void)
gMain.state++;
break;
case 14:
- sub_81C700C();
+ CreateSwapLine();
gMain.state++;
break;
case 15:
@@ -555,7 +555,7 @@ static bool8 sub_81C5238(void)
gPyramidBagResources->state++;
break;
default:
- LoadListMenuArrowsGfx();
+ LoadListMenuSwapLineGfx();
gPyramidBagResources->state = 0;
return TRUE;
}
@@ -1268,7 +1268,7 @@ static void Task_BeginItemSwap(u8 taskId)
FillWindowPixelBuffer(1, PIXEL_FILL(0));
PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0);
sub_81C5A98(data[0], 1);
- sub_81C704C(data[1]);
+ UpdateSwapLinePos(data[1]);
gTasks[taskId].func = Task_ItemSwapHandleInput;
}
@@ -1287,8 +1287,8 @@ static void Task_ItemSwapHandleInput(u8 taskId)
{
s32 id = ListMenu_ProcessInput(data[0]);
ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition);
- sub_81C7028(FALSE);
- sub_81C704C(gPyramidBagCursorData.cursorPosition);
+ SetSwapLineInvisibility(FALSE);
+ UpdateSwapLinePos(gPyramidBagCursorData.cursorPosition);
switch (id)
{
case LIST_NOTHING_CHOSEN:
@@ -1324,7 +1324,7 @@ static void PerformItemSwap(u8 taskId)
{
MovePyramidBagItemSlotInList(data[1], var);
gPyramidBagResources->unk814 = 0xFF;
- sub_81C7028(TRUE);
+ SetSwapLineInvisibility(TRUE);
DestroyListMenuTask(data[0], scrollOffset, selectedRow);
if (data[1] < var)
gPyramidBagCursorData.cursorPosition--;
@@ -1341,7 +1341,7 @@ static void sub_81C6A14(u8 taskId)
u16 *selectedRow = &gPyramidBagCursorData.cursorPosition;
gPyramidBagResources->unk814 = 0xFF;
- sub_81C7028(TRUE);
+ SetSwapLineInvisibility(TRUE);
DestroyListMenuTask(data[0], scrollOffset, selectedRow);
if (data[1] < *scrollOffset + *selectedRow)
gPyramidBagCursorData.cursorPosition--;
@@ -1545,17 +1545,17 @@ static void sub_81C6FF8(u8 itemSpriteArrayId)
sub_81C6E38(itemSpriteArrayId + 1);
}
-static void sub_81C700C(void)
+static void CreateSwapLine(void)
{
- sub_8122344(&gPyramidBagResources->itemsSpriteIds[3], 8);
+ CreateSwapLineSprites(&gPyramidBagResources->itemsSpriteIds[3], 8);
}
-static void sub_81C7028(bool8 invisible)
+static void SetSwapLineInvisibility(bool8 invisible)
{
- sub_81223FC(&gPyramidBagResources->itemsSpriteIds[3], 8, invisible);
+ SetSwapLineSpritesInvisibility(&gPyramidBagResources->itemsSpriteIds[3], 8, invisible);
}
-static void sub_81C704C(u8 y)
+static void UpdateSwapLinePos(u8 y)
{
- sub_8122448(&gPyramidBagResources->itemsSpriteIds[3], 8 | 0x80, 120, (y + 1) * 16);
+ UpdateSwapLineSpritesPos(&gPyramidBagResources->itemsSpriteIds[3], 8 | 0x80, 120, (y + 1) * 16);
}
diff --git a/src/graphics.c b/src/graphics.c
index 7a7a11b2b..09779eab7 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1201,7 +1201,7 @@ const u32 gPokeblockBlack_Pal[] = INCBIN_U32("graphics/pokeblock/black.gbapal.lz
const u32 gPokeblockWhite_Pal[] = INCBIN_U32("graphics/pokeblock/white.gbapal.lz");
const u32 gPokeblockGold_Pal[] = INCBIN_U32("graphics/pokeblock/gold.gbapal.lz");
-const u32 gUnknown_08D9BA44[] = INCBIN_U32("graphics/interface/pokeblock_feeding_bg_map.bin.lz");
+const u32 gPokeblockFeedBg_Tilemap[] = INCBIN_U32("graphics/interface/pokeblock_feeding_bg_map.bin.lz");
#include "data/graphics/berries.h"
#include "data/graphics/rayquaza_scene.h"
diff --git a/src/item_menu.c b/src/item_menu.c
index 8836c0c63..865f8d8d1 100755
--- a/src/item_menu.c
+++ b/src/item_menu.c
@@ -707,7 +707,7 @@ bool8 SetupBagMenu(void)
gMain.state++;
break;
case 16:
- sub_80D4FAC();
+ CreateItemMenuSwapLine();
gMain.state++;
break;
case 17:
@@ -787,7 +787,7 @@ bool8 LoadBagMenu_Graphics(void)
gBagMenu->graphicsLoadState++;
break;
default:
- LoadListMenuArrowsGfx();
+ LoadListMenuSwapLineGfx();
gBagMenu->graphicsLoadState = 0;
return TRUE;
}
@@ -1373,7 +1373,7 @@ void BagMenu_SwapItems(u8 taskId)
StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where);
FillWindowPixelBuffer(1, PIXEL_FILL(0));
BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0);
- sub_80D4FEC(data[1]);
+ UpdateItemMenuSwapLinePos(data[1]);
BagDestroyPocketSwitchArrowPair();
BagMenu_PrintCursor_(data[0], 2);
gTasks[taskId].func = Task_HandleSwappingItemsInput;
@@ -1396,8 +1396,8 @@ static void Task_HandleSwappingItemsInput(u8 taskId)
{
input = ListMenu_ProcessInput(data[0]);
ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
- sub_80D4FC8(0);
- sub_80D4FEC(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
+ SetItemMenuSwapLineInvisibility(FALSE);
+ UpdateItemMenuSwapLinePos(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]);
switch (input)
{
case LIST_NOTHING_CHOSEN:
@@ -1435,7 +1435,7 @@ void sub_81AC498(u8 taskId)
gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--;
LoadBagItemListBuffers(gBagPositionStruct.pocket);
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
- sub_80D4FC8(1);
+ SetItemMenuSwapLineInvisibility(TRUE);
CreatePocketSwitchArrowPair();
gTasks[taskId].func = Task_BagMenu_HandleInput;
}
@@ -1453,7 +1453,7 @@ void sub_81AC590(u8 taskId)
gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--;
LoadBagItemListBuffers(gBagPositionStruct.pocket);
data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
- sub_80D4FC8(1);
+ SetItemMenuSwapLineInvisibility(TRUE);
CreatePocketSwitchArrowPair();
gTasks[taskId].func = Task_BagMenu_HandleInput;
}
diff --git a/src/item_menu_icons.c b/src/item_menu_icons.c
index dd0081161..d15409226 100644
--- a/src/item_menu_icons.c
+++ b/src/item_menu_icons.c
@@ -537,19 +537,19 @@ void RemoveBagItemIconSprite(u8 id)
RemoveBagSprite(id + 2);
}
-void sub_80D4FAC(void)
+void CreateItemMenuSwapLine(void)
{
- sub_8122344(&gBagMenu->spriteId[4], 8);
+ CreateSwapLineSprites(&gBagMenu->spriteId[4], 8);
}
-void sub_80D4FC8(u8 arg0)
+void SetItemMenuSwapLineInvisibility(bool8 invisible)
{
- sub_81223FC(&gBagMenu->spriteId[4], 8, arg0);
+ SetSwapLineSpritesInvisibility(&gBagMenu->spriteId[4], 8, invisible);
}
-void sub_80D4FEC(u8 arg0)
+void UpdateItemMenuSwapLinePos(u8 y)
{
- sub_8122448(&gBagMenu->spriteId[4], 136, 120, (arg0 + 1) * 16);
+ UpdateSwapLineSpritesPos(&gBagMenu->spriteId[4], 136, 120, (y + 1) * 16);
}
static void sub_80D5018(void *mem0, void *mem1)
diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c
index 22155ffd5..6fa8ba4eb 100644
--- a/src/lilycove_lady.c
+++ b/src/lilycove_lady.c
@@ -805,7 +805,7 @@ void Script_BufferContestLadyCategoryAndMonName(void)
void OpenPokeblockCaseForContestLady(void)
{
- OpenPokeblockCase(3, CB2_ReturnToField);
+ OpenPokeblockCase(PBLOCK_CASE_GIVE, CB2_ReturnToField);
}
void SetContestLadyGivenPokeblock(void)
diff --git a/src/menu_helpers.c b/src/menu_helpers.c
index e7385a5ed..5a6ac8394 100644
--- a/src/menu_helpers.c
+++ b/src/menu_helpers.c
@@ -18,19 +18,17 @@
#include "constants/items.h"
#include "constants/maps.h"
-// this file's functions
+#define TAG_SWAP_LINE 109
+
static void Task_ContinueTaskAfterMessagePrints(u8 taskId);
static void Task_CallYesOrNoCallback(u8 taskId);
-// EWRAM vars
EWRAM_DATA static struct YesNoFuncTable gUnknown_0203A138 = {0};
EWRAM_DATA static u8 gUnknown_0203A140 = 0;
-// IWRAM bss vars
static TaskFunc gUnknown_0300117C;
-// const rom data
-static const struct OamData sOamData_859F4E8 =
+static const struct OamData sOamData_SwapLine =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
@@ -47,47 +45,47 @@ static const struct OamData sOamData_859F4E8 =
.affineParam = 0
};
-static const union AnimCmd sSpriteAnim_859F4F0[] =
+static const union AnimCmd sAnim_SwapLine_RightArrow[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
-static const union AnimCmd sSpriteAnim_859F4F8[] =
+static const union AnimCmd sAnim_SwapLine_Line[] =
{
ANIMCMD_FRAME(4, 0),
ANIMCMD_END
};
-static const union AnimCmd sSpriteAnim_859F500[] =
+static const union AnimCmd sAnim_SwapLine_LeftArrow[] =
{
- ANIMCMD_FRAME(0, 0, 1, 0),
+ ANIMCMD_FRAME(0, 0, .hFlip = TRUE),
ANIMCMD_END
};
-static const union AnimCmd *const sSpriteAnimTable_859F508[] =
+static const union AnimCmd *const sAnims_SwapLine[] =
{
- sSpriteAnim_859F4F0,
- sSpriteAnim_859F4F8,
- sSpriteAnim_859F500
+ sAnim_SwapLine_RightArrow,
+ sAnim_SwapLine_Line,
+ sAnim_SwapLine_LeftArrow
};
-static const struct CompressedSpriteSheet gUnknown_0859F514 =
+static const struct CompressedSpriteSheet sSpriteSheet_SwapLine =
{
- gBagSwapLineGfx, 0x100, 109
+ gBagSwapLineGfx, 0x100, TAG_SWAP_LINE
};
-static const struct CompressedSpritePalette gUnknown_0859F51C =
+static const struct CompressedSpritePalette sSpritePalette_SwapLine =
{
- gBagSwapLinePal, 109
+ gBagSwapLinePal, TAG_SWAP_LINE
};
-static const struct SpriteTemplate gUnknown_0859F524 =
+static const struct SpriteTemplate sSpriteTemplate_SwapLine =
{
- .tileTag = 109,
- .paletteTag = 109,
- .oam = &sOamData_859F4E8,
- .anims = sSpriteAnimTable_859F508,
+ .tileTag = TAG_SWAP_LINE,
+ .paletteTag = TAG_SWAP_LINE,
+ .oam = &sOamData_SwapLine,
+ .anims = sAnims_SwapLine,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy,
@@ -390,19 +388,19 @@ void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4)
}
}
-void LoadListMenuArrowsGfx(void)
+void LoadListMenuSwapLineGfx(void)
{
- LoadCompressedSpriteSheet(&gUnknown_0859F514);
- LoadCompressedSpritePalette(&gUnknown_0859F51C);
+ LoadCompressedSpriteSheet(&sSpriteSheet_SwapLine);
+ LoadCompressedSpritePalette(&sSpritePalette_SwapLine);
}
-void sub_8122344(u8 *spriteIds, u8 count)
+void CreateSwapLineSprites(u8 *spriteIds, u8 count)
{
u8 i;
for (i = 0; i < count; i++)
{
- spriteIds[i] = CreateSprite(&gUnknown_0859F524, i * 16, 0, 0);
+ spriteIds[i] = CreateSprite(&sSpriteTemplate_SwapLine, i * 16, 0, 0);
if (i != 0)
StartSpriteAnim(&gSprites[spriteIds[i]], 1);
@@ -410,7 +408,7 @@ void sub_8122344(u8 *spriteIds, u8 count)
}
}
-void sub_81223B0(u8 *spriteIds, u8 count)
+void DestroySwapLineSprites(u8 *spriteIds, u8 count)
{
u8 i;
@@ -423,17 +421,15 @@ void sub_81223B0(u8 *spriteIds, u8 count)
}
}
-void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible)
+void SetSwapLineSpritesInvisibility(u8 *spriteIds, u8 count, bool8 invisible)
{
u8 i;
for (i = 0; i < count; i++)
- {
gSprites[spriteIds[i]].invisible = invisible;
- }
}
-void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y)
+void UpdateSwapLineSpritesPos(u8 *spriteIds, u8 count, s16 x, u16 y)
{
u8 i;
bool8 unknownBit = count & 0x80;
diff --git a/src/player_pc.c b/src/player_pc.c
index a06aad60e..e5c3c5a18 100644
--- a/src/player_pc.c
+++ b/src/player_pc.c
@@ -112,7 +112,7 @@ static void CopyItemName_PlayerPC(u8 *string, u16 itemId);
static void sub_816BC14(void);
static void sub_816BFE0(u8 y, u8, u8 speed);
static void sub_816BCC4(u8);
-static void sub_816C690(u8);
+static void UpdateSwapLinePos(u8);
static void sub_816C4FC(u8 taskId);
static void sub_816C0C8(void);
static void sub_816C060(u16 itemId);
@@ -558,8 +558,8 @@ static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss)
ItemStorage_SetItemAndMailCount(taskId);
sub_816BC14();
FreeAndReserveObjectSpritePalettes();
- LoadListMenuArrowsGfx();
- sub_8122344(gUnknown_0203BCC4->spriteIds, 7);
+ LoadListMenuSwapLineGfx();
+ CreateSwapLineSprites(gUnknown_0203BCC4->spriteIds, 7);
ClearDialogWindowAndFrame(0,0);
gTasks[taskId].func = ItemStorage_ProcessWithdrawTossInput;
}
@@ -1186,7 +1186,7 @@ static void ItemStorage_GoBackToPlayerPCMenu(u8 taskId)
sub_816C0C8();
ItemStorage_RemoveScrollIndicator();
DestroyListMenuTask(data[5], NULL, NULL);
- sub_81223B0(gUnknown_0203BCC4->spriteIds, 7);
+ DestroySwapLineSprites(gUnknown_0203BCC4->spriteIds, 7);
sub_816BC58();
gTasks[taskId].func = ItemStorage_GoBackToPlayerPCMenu_InitStorage;
}
@@ -1199,7 +1199,7 @@ static void ItemStorage_ItemSwapChoosePrompt(u8 taskId)
ListMenuSetUnkIndicatorsStructField(data[5], 16, 1);
gUnknown_0203BCC4->unk666 = (playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos);
sub_816BFB8(data[5], 0, 0);
- sub_816C690(gUnknown_0203BCC4->unk666);
+ UpdateSwapLinePos(gUnknown_0203BCC4->unk666);
CopyItemName(gSaveBlock1Ptr->pcItems[gUnknown_0203BCC4->unk666].itemId, gStringVar1);
ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_SWITCH_WHICH_ITEM));
gTasks[taskId].func = sub_816C4FC;
@@ -1219,8 +1219,8 @@ static void sub_816C4FC(u8 taskId)
}
id = ListMenu_ProcessInput(data[5]);
ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos));
- sub_81223FC(gUnknown_0203BCC4->spriteIds, 7, 0);
- sub_816C690(playerPCItemPageInfo.cursorPos);
+ SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, FALSE);
+ UpdateSwapLinePos(playerPCItemPageInfo.cursorPos);
switch(id)
{
case LIST_NOTHING_CHOSEN:
@@ -1268,16 +1268,16 @@ static void ItemStorage_DoItemSwap(u8 taskId, bool8 a)
if (gUnknown_0203BCC4->unk666 < b)
playerPCItemPageInfo.cursorPos--;
LABEL_SKIP_CURSOR_DECREMENT:
- sub_81223FC(gUnknown_0203BCC4->spriteIds, 7, 1);
+ SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, TRUE);
gUnknown_0203BCC4->unk666 = 0xFF;
data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos);
ScheduleBgCopyTilemapToVram(0);
gTasks[taskId].func = ItemStorage_ProcessInput;
}
-static void sub_816C690(u8 a)
+static void UpdateSwapLinePos(u8 y)
{
- sub_8122448(gUnknown_0203BCC4->spriteIds, 7, 128, ((a+1) * 16));
+ UpdateSwapLineSpritesPos(gUnknown_0203BCC4->spriteIds, 7, 128, ((y+1) * 16));
}
static void sub_816C6BC(u8 windowId, u16 value, u32 mode, u8 x, u8 y, u8 n)
diff --git a/src/pokeblock.c b/src/pokeblock.c
index 3513e7dd2..daf50a612 100644
--- a/src/pokeblock.c
+++ b/src/pokeblock.c
@@ -33,23 +33,46 @@
#include "constants/songs.h"
#include "constants/rgb.h"
+#define MAX_MENU_ITEMS 9
+#define MENU_MIDPOINT (MAX_MENU_ITEMS / 2)
+
+#define TILE_HIGHLIGHT_NONE 0x0005 // Tile number for the bg of an unselected menu item
+#define TILE_HIGHLIGHT_BLUE 0x1005 // Tile number for the bg of a selected menu item
+#define TILE_HIGHLIGHT_RED 0x2005 // Tile number for the bg of a menu item to swap
+
+#define TAG_POKEBLOCK_CASE 14800
+#define TAG_SCROLL_ARROW 1110
+
#define POKEBLOCK_MAX_FEEL 99
-#define FIELD_E75_COUNT 7
+
+enum {
+ WIN_TITLE,
+ WIN_LIST,
+ WIN_SPICY,
+ WIN_DRY,
+ WIN_SWEET,
+ WIN_BITTER,
+ WIN_SOUR,
+ WIN_FEEL,
+ WIN_ACTIONS_TALL,
+ WIN_ACTIONS,
+ WIN_TOSS_MSG,
+};
struct PokeblockMenuStruct
{
- u8 tilemap[0x800];
+ u8 tilemap[BG_SCREEN_SIZE];
void (*callbackOnUse)(void);
- const u8 *pokeblockOptionsIds;
- u8 optionsNo;
+ const u8 *pokeblockActionIds;
+ u8 numActions;
u8 caseId;
u8 itemsNo;
u8 maxShowed;
struct ListMenuItem items[POKEBLOCKS_COUNT + 1];
- u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][0x20]; // + 1 because of STOW CASE item
+ u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][32]; // + 1 because of STOW CASE item
u8 pokeblockCaseSpriteId;
- u8 field_E75[FIELD_E75_COUNT];
- u8 unkTaskId;
+ u8 swapLineSpriteIds[7];
+ u8 arrowTaskId;
bool8 isSwapping;
s16 gfxState;
u8 unused[8];
@@ -58,8 +81,8 @@ struct PokeblockMenuStruct
struct PokeblockSavedData
{
void (*callback)(void);
- u16 lastItemPos;
- u16 lastItemPage;
+ u16 selectedRow;
+ u16 scrollOffset;
};
enum
@@ -82,43 +105,41 @@ static bool8 LoadPokeblockMenuGfx(void);
static void HandleInitBackgrounds(void);
static void HandleInitWindows(void);
static void SetMenuItemsCountAndMaxShowed(void);
-static void sub_81362E0(void);
-static void sub_8136344(void);
-static void HandlePokeblockListMenuItems(void);
-static void sub_81363BC(void);
-static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2);
-static void PutPokeblockInfoText(void);
-static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1);
-static void PutPokeblockListMenuString(u8 *dst, u16 pkblId);
-static void Task_HandlePokeblockMenuInput(u8 taskId);
-static void PokeblockAction_UseOnField(u8 taskId);
-static void PokeblockAction_Toss(u8 taskId);
-static void PokeblockAction_Cancel(u8 taskId);
-static void PokeblockAction_UseInBattle(u8 taskId);
-static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId);
-static void PokeblockAction_GiveToContestLady(u8 taskId);
-static void TossPokeblockChoice_Yes(u8 taskId);
-static void TossPokeblockChoice_No(u8 taskId);
-static void Task_FreeDataAndExitPokeblockCase(u8 taskId);
-static void Task_HandlePokeblockOptionsInput(u8 taskId);
-static void PutPokeblockOptionsWindow(u8 taskId);
-static void Task_HandlePokeblocksSwapInput(u8 taskId);
-static void sub_8136470(struct Sprite *sprite);
-static void sub_8135FCC(s32 pkblId);
-static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap);
+static void LimitMenuScrollAndRow(void);
+static void SetInitialScroll(void);
+static void UpdatePokeblockList(void);
+static void CreateScrollArrows(void);
+static void MovePokeblockMenuCursor(s32, bool8, struct ListMenu *);
+static void DrawPokeblockMenuTitleText(void);
+static void DrawPokeblockMenuHighlight(u16, u16);
+static void PutPokeblockListMenuString(u8 *, u16);
+static void Task_HandlePokeblockMenuInput(u8);
+static void PokeblockAction_UseOnField(u8);
+static void PokeblockAction_Toss(u8);
+static void PokeblockAction_Cancel(u8);
+static void PokeblockAction_UseInBattle(u8);
+static void PokeblockAction_UseOnPokeblockFeeder(u8);
+static void PokeblockAction_GiveToContestLady(u8);
+static void TossedPokeblockMessage(u8);
+static void CloseTossPokeblockWindow(u8);
+static void Task_FreeDataAndExitPokeblockCase(u8);
+static void Task_HandlePokeblockActionsInput(u8);
+static void ShowPokeblockActionsWindow(u8);
+static void Task_HandlePokeblocksSwapInput(u8);
+static void SpriteCB_ShakePokeblockCase(struct Sprite *);
+static void DrawPokeblockInfo(s32);
+static void UpdatePokeblockSwapMenu(u8, bool8);
static void UsePokeblockOnField(void);
static void ReturnToPokeblockCaseOnField(void);
-static void CreateTossPokeblockYesNoMenu(u8 taskId);
-static void HandleErasePokeblock(u8 taskId);
+static void CreateTossPokeblockYesNoMenu(u8);
+static void TossPokeblock(u8);
-// ram variables
EWRAM_DATA static struct PokeblockSavedData sSavedPokeblockData = {0};
EWRAM_DATA static struct PokeblockMenuStruct *sPokeblockMenu = NULL;
-// const rom data
const s8 gPokeblockFlavorCompatibilityTable[NUM_NATURES * FLAVOR_COUNT] =
{
- // Cool, Beauty, Cute, Smart, Tough
+ // Spicy, Dry, Sweet, Bitter, Sour
0, 0, 0, 0, 0, // Hardy
1, 0, 0, 0, -1, // Lonely
1, 0, -1, 0, 0, // Brave
@@ -198,12 +219,12 @@ const u8 *const gPokeblockNames[] =
static const struct MenuAction sPokeblockMenuActions[] =
{
- {gMenuText_Use, PokeblockAction_UseOnField},
- {gMenuText_Toss, PokeblockAction_Toss},
- {gText_Cancel2, PokeblockAction_Cancel},
- {gMenuText_Use, PokeblockAction_UseInBattle},
- {gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder},
- {gMenuText_Give2, PokeblockAction_GiveToContestLady},
+ [PKBL_USE_ON_FIELD] = {gMenuText_Use, PokeblockAction_UseOnField},
+ [PKBL_TOSS] = {gMenuText_Toss, PokeblockAction_Toss},
+ [PKBL_CANCEL] = {gText_Cancel2, PokeblockAction_Cancel},
+ [PKBL_USE_IN_BATTLE] = {gMenuText_Use, PokeblockAction_UseInBattle},
+ [PKBL_USE_ON_FEEDER] = {gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder},
+ [PKBL_GIVE_TO_LADY] = {gMenuText_Give2, PokeblockAction_GiveToContestLady},
};
static const u8 sActionsOnField[] = {PKBL_USE_ON_FIELD, PKBL_TOSS, PKBL_CANCEL};
@@ -211,7 +232,7 @@ static const u8 sActionsInBattle[] = {PKBL_USE_IN_BATTLE, PKBL_CANCEL};
static const u8 sActionsOnPokeblockFeeder[] = {PKBL_USE_ON_FEEDER, PKBL_CANCEL};
static const u8 sActionsWhenGivingToLady[] = {PKBL_GIVE_TO_LADY, PKBL_CANCEL};
-static const struct YesNoFuncTable sTossYesNoFuncTable = {TossPokeblockChoice_Yes, TossPokeblockChoice_No};
+static const struct YesNoFuncTable sTossYesNoFuncTable = {TossedPokeblockMessage, CloseTossPokeblockWindow};
static const u8 sContestStatsMonData[] = {MON_DATA_COOL, MON_DATA_BEAUTY, MON_DATA_CUTE, MON_DATA_SMART, MON_DATA_TOUGH};
@@ -259,39 +280,39 @@ static const union AffineAnimCmd *const sSpriteAffineAnimTable_85B26F0[] =
const struct CompressedSpriteSheet gPokeblockCase_SpriteSheet =
{
- gMenuPokeblockDevice_Gfx, 0x800, GFX_TAG_POKEBLOCK_CASE
+ gMenuPokeblockDevice_Gfx, 0x800, TAG_POKEBLOCK_CASE
};
const struct CompressedSpritePalette gPokeblockCase_SpritePal =
{
- gMenuPokeblockDevice_Pal, GFX_TAG_POKEBLOCK_CASE
+ gMenuPokeblockDevice_Pal, TAG_POKEBLOCK_CASE
};
static const struct SpriteTemplate sSpriteTemplate_PokeblockCase =
{
- GFX_TAG_POKEBLOCK_CASE,
- GFX_TAG_POKEBLOCK_CASE,
- &sOamData_PokeblockCase,
- sSpriteAnimTable_PokeblockCase,
- NULL,
- gDummySpriteAffineAnimTable,
- SpriteCallbackDummy
+ .tileTag = TAG_POKEBLOCK_CASE,
+ .paletteTag = TAG_POKEBLOCK_CASE,
+ .oam = &sOamData_PokeblockCase,
+ .anims = sSpriteAnimTable_PokeblockCase,
+ .images = NULL,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCallbackDummy
};
-static const u8 sTextColorInPokeblockMenu[3] = {0, 2, 3};
+static const u8 sTextColor[3] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY};
-static const struct Pokeblock sFavoritePokeblocksTable[] =
+static const struct Pokeblock sFavoritePokeblocksTable[FLAVOR_COUNT] =
{
- { PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20},
- { PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20},
- { PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20},
- { PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20},
- { PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20}
+ [FLAVOR_SPICY] = { PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20},
+ [FLAVOR_DRY] = { PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20},
+ [FLAVOR_SWEET] = { PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20},
+ [FLAVOR_BITTER] = { PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20},
+ [FLAVOR_SOUR] = { PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20}
};
-static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
+static const struct WindowTemplate sWindowTemplates[] =
{
- {
+ [WIN_TITLE] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
@@ -300,7 +321,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x1E
},
- {
+ [WIN_LIST] = {
.bg = 0,
.tilemapLeft = 15,
.tilemapTop = 1,
@@ -309,7 +330,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x30
},
- {
+ [WIN_SPICY] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 13,
@@ -318,7 +339,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x12C
},
- {
+ [WIN_DRY] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
@@ -327,7 +348,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x136
},
- {
+ [WIN_SWEET] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 17,
@@ -336,7 +357,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x140
},
- {
+ [WIN_BITTER] = {
.bg = 0,
.tilemapLeft = 8,
.tilemapTop = 13,
@@ -345,7 +366,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x14A
},
- {
+ [WIN_SOUR] = {
.bg = 0,
.tilemapLeft = 8,
.tilemapTop = 15,
@@ -354,7 +375,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x154
},
- {
+ [WIN_FEEL] = {
.bg = 0,
.tilemapLeft = 11,
.tilemapTop = 17,
@@ -363,7 +384,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x15E
},
- {
+ [WIN_ACTIONS_TALL] = {
.bg = 1,
.tilemapLeft = 7,
.tilemapTop = 5,
@@ -372,7 +393,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x162
},
- {
+ [WIN_ACTIONS] = {
.bg = 1,
.tilemapLeft = 7,
.tilemapTop = 7,
@@ -381,7 +402,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.paletteNum = 15,
.baseBlock = 0x186
},
- {
+ [WIN_TOSS_MSG] = {
.bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
@@ -411,7 +432,7 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate =
.itemPrintFunc = NULL,
.totalItems = 0,
.maxShowed = 0,
- .windowId = 1,
+ .windowId = WIN_LIST,
.header_X = 0,
.item_X = 1,
.cursor_X = 0,
@@ -426,33 +447,32 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate =
.cursorKind = 1
};
-// code
void OpenPokeblockCase(u8 caseId, void (*callback)(void))
{
sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu));
sPokeblockMenu->caseId = caseId;
sPokeblockMenu->callbackOnUse = NULL;
- sPokeblockMenu->unkTaskId = TASK_NONE;
+ sPokeblockMenu->arrowTaskId = TASK_NONE;
sPokeblockMenu->isSwapping = FALSE;
sSavedPokeblockData.callback = callback;
switch (sPokeblockMenu->caseId)
{
case PBLOCK_CASE_BATTLE:
- sPokeblockMenu->pokeblockOptionsIds = sActionsInBattle;
- sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsInBattle);
+ sPokeblockMenu->pokeblockActionIds = sActionsInBattle;
+ sPokeblockMenu->numActions = ARRAY_COUNT(sActionsInBattle);
break;
case PBLOCK_CASE_FEEDER:
- sPokeblockMenu->pokeblockOptionsIds = sActionsOnPokeblockFeeder;
- sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnPokeblockFeeder);
+ sPokeblockMenu->pokeblockActionIds = sActionsOnPokeblockFeeder;
+ sPokeblockMenu->numActions = ARRAY_COUNT(sActionsOnPokeblockFeeder);
break;
case PBLOCK_CASE_GIVE:
- sPokeblockMenu->pokeblockOptionsIds = sActionsWhenGivingToLady;
- sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsWhenGivingToLady);
+ sPokeblockMenu->pokeblockActionIds = sActionsWhenGivingToLady;
+ sPokeblockMenu->numActions = ARRAY_COUNT(sActionsWhenGivingToLady);
break;
default: // PBLOCK_CASE_FIELD
- sPokeblockMenu->pokeblockOptionsIds = sActionsOnField;
- sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnField);
+ sPokeblockMenu->pokeblockActionIds = sActionsOnField;
+ sPokeblockMenu->numActions = ARRAY_COUNT(sActionsOnField);
break;
}
@@ -498,6 +518,10 @@ static void CB2_InitPokeblockMenu(void)
}
}
+#define tListTaskId data[0]
+#define tWindowId data[1]
+#define tToSwapId data[2]
+
static bool8 InitPokeblockMenu(void)
{
u8 taskId;
@@ -519,7 +543,7 @@ static bool8 InitPokeblockMenu(void)
break;
case 3:
ResetPaletteFade();
- gPaletteFade.bufferTransferDisabled = 1;
+ gPaletteFade.bufferTransferDisabled = TRUE;
gMain.state++;
break;
case 4:
@@ -543,8 +567,8 @@ static bool8 InitPokeblockMenu(void)
break;
case 8:
SetMenuItemsCountAndMaxShowed();
- sub_81362E0();
- sub_8136344();
+ LimitMenuScrollAndRow();
+ SetInitialScroll();
gMain.state++;
break;
case 9:
@@ -552,11 +576,11 @@ static bool8 InitPokeblockMenu(void)
gMain.state++;
break;
case 10:
- sub_8122344(sPokeblockMenu->field_E75, FIELD_E75_COUNT);
+ CreateSwapLineSprites(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds));
gMain.state++;
break;
case 11:
- HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE);
gMain.state++;
break;
case 12:
@@ -564,29 +588,29 @@ static bool8 InitPokeblockMenu(void)
gMain.state++;
break;
case 13:
- HandlePokeblockListMenuItems();
+ UpdatePokeblockList();
gMain.state++;
break;
case 14:
- sub_81363BC();
+ CreateScrollArrows();
gMain.state++;
break;
case 15:
taskId = CreateTask(Task_HandlePokeblockMenuInput, 0);
- gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
+ gTasks[taskId].tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.scrollOffset, sSavedPokeblockData.selectedRow);
gMain.state++;
break;
case 16:
- PutPokeblockInfoText();
+ DrawPokeblockMenuTitleText();
gMain.state++;
break;
case 17:
- BlendPalettes(PALETTES_ALL, 0x10, 0);
+ BlendPalettes(PALETTES_ALL, 16, 0);
gMain.state++;
break;
case 18:
- BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK);
- gPaletteFade.bufferTransferDisabled = 0;
+ BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
+ gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
default:
@@ -645,7 +669,7 @@ static bool8 LoadPokeblockMenuGfx(void)
sPokeblockMenu->gfxState++;
break;
case 5:
- LoadListMenuArrowsGfx();
+ LoadListMenuSwapLineGfx();
sPokeblockMenu->gfxState = 0;
return TRUE;
}
@@ -657,16 +681,14 @@ static void HandleInitWindows(void)
{
u8 i;
- InitWindows(sWindowTemplatesForPokeblockMenu);
+ InitWindows(sWindowTemplates);
DeactivateAllTextPrinters();
LoadUserWindowBorderGfx(0, 1, 0xE0);
LoadMessageBoxGfx(0, 0xA, 0xD0);
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
- for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++)
- {
+ for (i = 0; i < ARRAY_COUNT(sWindowTemplates) - 1; i++)
FillWindowPixelBuffer(i, PIXEL_FILL(0));
- }
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
@@ -674,29 +696,27 @@ static void HandleInitWindows(void)
static void PrintOnPokeblockWindow(u8 windowId, const u8 *string, s32 x)
{
- AddTextPrinterParameterized4(windowId, 1, x, 1, 0, 0, sTextColorInPokeblockMenu, 0, string);
+ AddTextPrinterParameterized4(windowId, 1, x, 1, 0, 0, sTextColor, 0, string);
}
-static void PutPokeblockInfoText(void)
+static void DrawPokeblockMenuTitleText(void)
{
u8 i;
const u8 *itemName = ItemId_GetName(ITEM_POKEBLOCK_CASE);
- PrintOnPokeblockWindow(0, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48));
+ PrintOnPokeblockWindow(WIN_TITLE, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48));
- PrintOnPokeblockWindow(2, gText_Spicy, 0);
- PrintOnPokeblockWindow(3, gText_Dry, 0);
- PrintOnPokeblockWindow(4, gText_Sweet, 0);
- PrintOnPokeblockWindow(5, gText_Bitter, 0);
- PrintOnPokeblockWindow(6, gText_Sour, 0);
+ PrintOnPokeblockWindow(WIN_SPICY, gText_Spicy, 0);
+ PrintOnPokeblockWindow(WIN_DRY, gText_Dry, 0);
+ PrintOnPokeblockWindow(WIN_SWEET, gText_Sweet, 0);
+ PrintOnPokeblockWindow(WIN_BITTER, gText_Bitter, 0);
+ PrintOnPokeblockWindow(WIN_SOUR, gText_Sour, 0);
- for (i = 0; i < 8; i++)
- {
+ for (i = 0; i < WIN_ACTIONS_TALL; i++)
PutWindowTilemap(i);
- }
}
-static void HandlePokeblockListMenuItems(void)
+static void UpdatePokeblockList(void)
{
u16 i;
@@ -731,19 +751,19 @@ static void PutPokeblockListMenuString(u8 *dst, u16 pkblId)
StringExpandPlaceholders(txtPtr, gText_LvVar1);
}
-static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2)
+static void MovePokeblockMenuCursor(s32 pkblId, bool8 onInit, struct ListMenu *list)
{
- if (arg1 != TRUE)
+ if (onInit != TRUE)
{
PlaySE(SE_SELECT);
- gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = sub_8136470;
+ gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = SpriteCB_ShakePokeblockCase;
}
if (!sPokeblockMenu->isSwapping)
- sub_8135FCC(pkblId);
+ DrawPokeblockInfo(pkblId);
}
-static void sub_8135FCC(s32 pkblId)
+static void DrawPokeblockInfo(s32 pkblId)
{
u8 i;
struct Pokeblock *pokeblock;
@@ -760,28 +780,32 @@ static void sub_8135FCC(s32 pkblId)
{
if (GetPokeblockData(pokeblock, PBLOCK_SPICY + i) > 0)
{
+ // Pokéblock has this flavor, draw Pokéblock icon next to it
rectTilemapSrc[0] = (i << 12) + 0x17;
rectTilemapSrc[1] = (i << 12) + 0x18;
}
else
{
+ // Pokéblock doesn't have this flavor, draw regular tiles
rectTilemapSrc[0] = 0xF;
rectTilemapSrc[1] = 0xF;
}
CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
}
+
+ // Print the Pokéblock's feel
ConvertIntToDecimalStringN(gStringVar1, GetPokeblocksFeel(pokeblock), STR_CONV_MODE_RIGHT_ALIGN, 2);
- PrintOnPokeblockWindow(7, gStringVar1, 4);
+ PrintOnPokeblockWindow(WIN_FEEL, gStringVar1, 4);
}
else
{
+ // Selected cancel, erase info
rectTilemapSrc[0] = 0xF;
rectTilemapSrc[1] = 0xF;
for (i = 0; i < FLAVOR_COUNT; i++)
- {
CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
- }
+
CopyWindowToVram(7, 2);
}
@@ -789,9 +813,9 @@ static void sub_8135FCC(s32 pkblId)
ScheduleBgCopyTilemapToVram(2);
}
-static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1)
+static void DrawPokeblockMenuHighlight(u16 cursorPos, u16 tileNum)
{
- FillBgTilemapBufferRect_Palette0(2, arg1, 0xF, (cursorPos * 2) + 1, 0xE, 2);
+ FillBgTilemapBufferRect_Palette0(2, tileNum, 0xF, (cursorPos * 2) + 1, 0xE, 2);
ScheduleBgCopyTilemapToVram(2);
}
@@ -813,7 +837,7 @@ static void CompactPokeblockSlots(void)
}
}
-static void SwapSortPokeblocksInternalData(u32 id1, u32 id2)
+static void SwapPokeblockMenuItems(u32 id1, u32 id2)
{
s16 i, count;
struct Pokeblock *pokeblocks = gSaveBlock1Ptr->pokeblocks;
@@ -843,8 +867,8 @@ static void SwapSortPokeblocksInternalData(u32 id1, u32 id2)
void ResetPokeblockScrollPositions(void)
{
- sSavedPokeblockData.lastItemPos = 0;
- sSavedPokeblockData.lastItemPage = 0;
+ sSavedPokeblockData.selectedRow = 0;
+ sSavedPokeblockData.scrollOffset = 0;
}
static void SetMenuItemsCountAndMaxShowed(void)
@@ -861,56 +885,56 @@ static void SetMenuItemsCountAndMaxShowed(void)
sPokeblockMenu->itemsNo++; // STOW CASE menu item
- if (sPokeblockMenu->itemsNo > 9)
- sPokeblockMenu->maxShowed = 9;
+ if (sPokeblockMenu->itemsNo > MAX_MENU_ITEMS)
+ sPokeblockMenu->maxShowed = MAX_MENU_ITEMS;
else
sPokeblockMenu->maxShowed = sPokeblockMenu->itemsNo;
}
-static void sub_81362E0(void)
+static void LimitMenuScrollAndRow(void)
{
- if (sSavedPokeblockData.lastItemPage != 0)
+ if (sSavedPokeblockData.scrollOffset != 0)
{
- if (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo)
- sSavedPokeblockData.lastItemPage = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed;
+ if (sSavedPokeblockData.scrollOffset + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo)
+ sSavedPokeblockData.scrollOffset = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed;
}
- if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos >= sPokeblockMenu->itemsNo)
+ if (sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow >= sPokeblockMenu->itemsNo)
{
if (sPokeblockMenu->itemsNo == 0)
- sSavedPokeblockData.lastItemPos = 0;
+ sSavedPokeblockData.selectedRow = 0;
else
- sSavedPokeblockData.lastItemPos = sPokeblockMenu->itemsNo - 1;
+ sSavedPokeblockData.selectedRow = sPokeblockMenu->itemsNo - 1;
}
}
-static void sub_8136344(void)
+static void SetInitialScroll(void)
{
- if (sSavedPokeblockData.lastItemPos > 4)
+ if (sSavedPokeblockData.selectedRow > MENU_MIDPOINT)
{
u8 i;
for (i = 0;
- (i < sSavedPokeblockData.lastItemPos - 4) && (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo);
- sSavedPokeblockData.lastItemPos--, sSavedPokeblockData.lastItemPage++, i++);
+ (i < sSavedPokeblockData.selectedRow - MENU_MIDPOINT) && (sSavedPokeblockData.scrollOffset + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo);
+ sSavedPokeblockData.selectedRow--, sSavedPokeblockData.scrollOffset++, i++);
}
}
-static void sub_81363BC(void)
+static void CreateScrollArrows(void)
{
- if (sPokeblockMenu->unkTaskId == TASK_NONE)
+ if (sPokeblockMenu->arrowTaskId == TASK_NONE)
{
- sPokeblockMenu->unkTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed,
- 0x456, 0x456, &sSavedPokeblockData.lastItemPage);
+ sPokeblockMenu->arrowTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed,
+ TAG_SCROLL_ARROW, TAG_SCROLL_ARROW, &sSavedPokeblockData.scrollOffset);
}
}
-static void sub_8136418(void)
+static void DestroyScrollArrows(void)
{
- if (sPokeblockMenu->unkTaskId != TASK_NONE)
+ if (sPokeblockMenu->arrowTaskId != TASK_NONE)
{
- RemoveScrollIndicatorArrowPair(sPokeblockMenu->unkTaskId);
- sPokeblockMenu->unkTaskId = TASK_NONE;
+ RemoveScrollIndicatorArrowPair(sPokeblockMenu->arrowTaskId);
+ sPokeblockMenu->arrowTaskId = TASK_NONE;
}
}
@@ -919,26 +943,29 @@ u8 CreatePokeblockCaseSprite(s16 x, s16 y, u8 subpriority)
return CreateSprite(&sSpriteTemplate_PokeblockCase, x, y, subpriority);
}
-static void sub_8136470(struct Sprite *sprite)
+#define sState data[0]
+#define sTimer data[1]
+
+static void SpriteCB_ShakePokeblockCase(struct Sprite *sprite)
{
- if (sprite->data[0] > 1)
- sprite->data[0] = 0;
+ if (sprite->sState > 1)
+ sprite->sState = 0;
- switch (sprite->data[0])
+ switch (sprite->sState)
{
case 0:
sprite->oam.affineMode = ST_OAM_AFFINE_NORMAL;
sprite->affineAnims = sSpriteAffineAnimTable_85B26F0;
InitSpriteAffineAnim(sprite);
- sprite->data[0] = 1;
- sprite->data[1] = 0;
+ sprite->sState = 1;
+ sprite->sTimer = 0;
break;
case 1:
- if (++sprite->data[1] > 11)
+ if (++sprite->sTimer > 11)
{
sprite->oam.affineMode = ST_OAM_AFFINE_OFF;
- sprite->data[0] = 0;
- sprite->data[1] = 0;
+ sprite->sState = 0;
+ sprite->sTimer = 0;
FreeOamMatrix(sprite->oam.matrixNum);
sprite->callback = SpriteCallbackDummy;
}
@@ -948,7 +975,7 @@ static void sub_8136470(struct Sprite *sprite)
static void FadePaletteAndSetTaskToClosePokeblockCase(u8 taskId)
{
- BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
+ BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_FreeDataAndExitPokeblockCase;
}
@@ -961,8 +988,8 @@ static void Task_FreeDataAndExitPokeblockCase(u8 taskId)
if (sPokeblockMenu->caseId == PBLOCK_CASE_FEEDER || sPokeblockMenu->caseId == PBLOCK_CASE_GIVE)
gFieldCallback = FieldCB_ContinueScriptHandleMusic;
- DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
- sub_8136418();
+ DestroyListMenuTask(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
+ DestroyScrollArrows();
ResetSpriteData();
FreeAllSpritePalettes();
@@ -985,29 +1012,31 @@ static void Task_HandlePokeblockMenuInput(u8 taskId)
{
if (JOY_NEW(SELECT_BUTTON))
{
- ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
- if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1)
+ ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
+ if (sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow != sPokeblockMenu->itemsNo - 1)
{
+ // Chose menu item to swap
PlaySE(SE_SELECT);
- HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x2005);
- data[2] = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
+ DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_RED);
+ tToSwapId = sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow;
sPokeblockMenu->isSwapping = TRUE;
gTasks[taskId].func = Task_HandlePokeblocksSwapInput;
}
}
else
{
- u16 oldPosition = sSavedPokeblockData.lastItemPos;
- s32 itemId = ListMenu_ProcessInput(data[0]);
+ u16 oldPosition = sSavedPokeblockData.selectedRow;
+ s32 input = ListMenu_ProcessInput(tListTaskId);
+ ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
- ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
- if (oldPosition != sSavedPokeblockData.lastItemPos)
+ if (oldPosition != sSavedPokeblockData.selectedRow)
{
- HandlePokeblockMenuCursor(oldPosition, 5);
- HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ // Moved cursor
+ DrawPokeblockMenuHighlight(oldPosition, TILE_HIGHLIGHT_NONE);
+ DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE);
}
- switch (itemId)
+ switch (input)
{
case LIST_NOTHING_CHOSEN:
break;
@@ -1018,9 +1047,10 @@ static void Task_HandlePokeblockMenuInput(u8 taskId)
FadePaletteAndSetTaskToClosePokeblockCase(taskId);
break;
default:
+ // Selected Pokéblock
PlaySE(SE_SELECT);
- gSpecialVar_ItemId = itemId;
- PutPokeblockOptionsWindow(taskId);
+ gSpecialVar_ItemId = input;
+ ShowPokeblockActionsWindow(taskId);
break;
}
}
@@ -1036,100 +1066,102 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId)
if (JOY_NEW(SELECT_BUTTON))
{
+ // Swap items
PlaySE(SE_SELECT);
- ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
- HandlePokeblocksSwap(taskId, FALSE);
+ ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
+ UpdatePokeblockSwapMenu(taskId, FALSE);
}
else
{
- u16 i = sSavedPokeblockData.lastItemPage;
- u16 var = sSavedPokeblockData.lastItemPos;
- s32 itemId = ListMenu_ProcessInput(data[0]);
+ u16 i = sSavedPokeblockData.scrollOffset;
+ u16 row = sSavedPokeblockData.selectedRow;
+ s32 input = ListMenu_ProcessInput(tListTaskId);
+ ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
- ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
- if (i != sSavedPokeblockData.lastItemPage || var != sSavedPokeblockData.lastItemPos)
+ if (i != sSavedPokeblockData.scrollOffset || row != sSavedPokeblockData.selectedRow)
{
- for (i = 0; i < 9; i++)
+ for (i = 0; i < MAX_MENU_ITEMS; i++)
{
- var = i + sSavedPokeblockData.lastItemPage;
- if (var == data[2])
- HandlePokeblockMenuCursor(i, 0x2005);
+ row = i + sSavedPokeblockData.scrollOffset;
+ if (row == tToSwapId)
+ DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_RED);
else
- HandlePokeblockMenuCursor(i, 5);
+ DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_NONE);
}
}
- sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0);
- sub_8122448(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0x80, (sSavedPokeblockData.lastItemPos * 16) + 8);
+ SetSwapLineSpritesInvisibility(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), FALSE);
+ UpdateSwapLineSpritesPos(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), 128, (sSavedPokeblockData.selectedRow * 16) + 8);
- switch (itemId)
+ switch (input)
{
case LIST_NOTHING_CHOSEN:
break;
- case LIST_CANCEL: // same id as STOW CASE field
+ case LIST_CANCEL:
PlaySE(SE_SELECT);
- if (JOY_NEW(A_BUTTON))
- HandlePokeblocksSwap(taskId, FALSE);
+ if (JOY_NEW(A_BUTTON)) // Pointless check, B Button has been pressed here
+ UpdatePokeblockSwapMenu(taskId, FALSE);
else
- HandlePokeblocksSwap(taskId, TRUE);
+ UpdatePokeblockSwapMenu(taskId, TRUE); // Canceled swapping
break;
default:
+ // Swap items
PlaySE(SE_SELECT);
- HandlePokeblocksSwap(taskId, FALSE);
+ UpdatePokeblockSwapMenu(taskId, FALSE);
break;
}
}
}
-static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap)
+static void UpdatePokeblockSwapMenu(u8 taskId, bool8 noSwap)
{
u8 i;
s16 *data = gTasks[taskId].data;
- u16 swappedFromId = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
+ u16 swappedFromId = sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow;
sPokeblockMenu->isSwapping = FALSE;
- DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ DestroyListMenuTask(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow);
- if (!noSwap && data[2] != swappedFromId && data[2] != swappedFromId - 1)
+ if (!noSwap && tToSwapId != swappedFromId && tToSwapId != swappedFromId - 1)
{
- SwapSortPokeblocksInternalData(data[2], swappedFromId);
- HandlePokeblockListMenuItems();
+ SwapPokeblockMenuItems(tToSwapId, swappedFromId);
+ UpdatePokeblockList();
}
- if (data[2] < swappedFromId)
- sSavedPokeblockData.lastItemPos--;
+ if (tToSwapId < swappedFromId)
+ sSavedPokeblockData.selectedRow--;
- data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
+ tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.scrollOffset, sSavedPokeblockData.selectedRow);
ScheduleBgCopyTilemapToVram(0);
- sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 1);
+ SetSwapLineSpritesInvisibility(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), TRUE);
- for (i = 0; i < 9; i++)
- HandlePokeblockMenuCursor(i, 5);
+ for (i = 0; i < MAX_MENU_ITEMS; i++)
+ DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_NONE);
- HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE);
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
}
-static void PutPokeblockOptionsWindow(u8 taskId)
+static void ShowPokeblockActionsWindow(u8 taskId)
{
s16 *data = gTasks[taskId].data;
- if (sPokeblockMenu->optionsNo == 3)
- data[1] = 8;
+ if (sPokeblockMenu->numActions == 3)
+ tWindowId = WIN_ACTIONS_TALL;
else
- data[1] = 9;
+ tWindowId = WIN_ACTIONS;
- sub_8136418();
- DrawStdFrameWithCustomTileAndPalette(data[1], 0, 1, 0xE);
- sub_81995E4(data[1], sPokeblockMenu->optionsNo, sPokeblockMenuActions, sPokeblockMenu->pokeblockOptionsIds);
- InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[1], sPokeblockMenu->optionsNo, 0);
- PutWindowTilemap(data[1]);
+ DestroyScrollArrows();
+ DrawStdFrameWithCustomTileAndPalette(tWindowId, 0, 1, 0xE);
+ sub_81995E4(tWindowId, sPokeblockMenu->numActions, sPokeblockMenuActions, sPokeblockMenu->pokeblockActionIds);
+ InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, sPokeblockMenu->numActions, 0);
+ PutWindowTilemap(tWindowId);
ScheduleBgCopyTilemapToVram(1);
- gTasks[taskId].func = Task_HandlePokeblockOptionsInput;
+ gTasks[taskId].func = Task_HandlePokeblockActionsInput;
}
-static void Task_HandlePokeblockOptionsInput(u8 taskId)
+static void Task_HandlePokeblockActionsInput(u8 taskId)
{
s8 itemId;
@@ -1149,7 +1181,7 @@ static void Task_HandlePokeblockOptionsInput(u8 taskId)
else
{
PlaySE(SE_SELECT);
- sPokeblockMenuActions[sPokeblockMenu->pokeblockOptionsIds[itemId]].func.void_u8(taskId);
+ sPokeblockMenuActions[sPokeblockMenu->pokeblockActionIds[itemId]].func.void_u8(taskId);
}
}
@@ -1173,10 +1205,10 @@ static void PokeblockAction_Toss(u8 taskId)
{
s16 *data = gTasks[taskId].data;
- ClearStdWindowAndFrameToTransparent(data[1], FALSE);
+ ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
StringExpandPlaceholders(gStringVar4, gText_ThrowAwayVar1);
- DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu);
+ DisplayMessageAndContinueTask(taskId, WIN_TOSS_MSG, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu);
}
static void CreateTossPokeblockYesNoMenu(u8 taskId)
@@ -1184,44 +1216,44 @@ static void CreateTossPokeblockYesNoMenu(u8 taskId)
CreateYesNoMenuWithCallbacks(taskId, &sTossPkblockWindowTemplate, 1, 0, 2, 1, 0xE, &sTossYesNoFuncTable);
}
-static void TossPokeblockChoice_Yes(u8 taskId)
+static void TossedPokeblockMessage(u8 taskId)
{
StringExpandPlaceholders(gStringVar4, gText_Var1ThrownAway);
- DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, HandleErasePokeblock);
+ DisplayMessageAndContinueTask(taskId, WIN_TOSS_MSG, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, TossPokeblock);
}
-static void HandleErasePokeblock(u8 taskId)
+static void TossPokeblock(u8 taskId)
{
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
s16 *data;
- u16 *lastPage, *lastPos;
+ u16 *scrollOffset, *selectedRow;
TryClearPokeblock(gSpecialVar_ItemId);
PlaySE(SE_SELECT);
- lastPage = &sSavedPokeblockData.lastItemPage;
- lastPos = &sSavedPokeblockData.lastItemPos;
+ scrollOffset = &sSavedPokeblockData.scrollOffset;
+ selectedRow = &sSavedPokeblockData.selectedRow;
data = gTasks[taskId].data;
- DestroyListMenuTask(data[0], lastPage, lastPos);
- HandlePokeblockMenuCursor(*lastPos, 5);
+ DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow);
+ DrawPokeblockMenuHighlight(*selectedRow, TILE_HIGHLIGHT_NONE);
SetMenuItemsCountAndMaxShowed();
- sub_81362E0();
- HandlePokeblockListMenuItems();
- data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *lastPage, *lastPos);
- HandlePokeblockMenuCursor(*lastPos, 0x1005);
+ LimitMenuScrollAndRow();
+ UpdatePokeblockList();
+ tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow);
+ DrawPokeblockMenuHighlight(*selectedRow, TILE_HIGHLIGHT_BLUE);
ScheduleBgCopyTilemapToVram(0);
ScheduleBgCopyTilemapToVram(1);
- TossPokeblockChoice_No(taskId);
+ CloseTossPokeblockWindow(taskId);
}
}
-static void TossPokeblockChoice_No(u8 taskId)
+static void CloseTossPokeblockWindow(u8 taskId)
{
- ClearDialogWindowAndFrameToTransparent(10, FALSE);
+ ClearDialogWindowAndFrameToTransparent(WIN_TOSS_MSG, FALSE);
ScheduleBgCopyTilemapToVram(1);
- sub_81363BC();
+ CreateScrollArrows();
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
}
@@ -1266,9 +1298,9 @@ static void PokeblockAction_Cancel(u8 taskId)
{
s16 *data = gTasks[taskId].data;
- ClearStdWindowAndFrameToTransparent(data[1], FALSE);
+ ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
ScheduleBgCopyTilemapToVram(1);
- sub_81363BC();
+ CreateScrollArrows();
gTasks[taskId].func = Task_HandlePokeblockMenuInput;
}
diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c
index e5b13e2f6..47e510562 100644
--- a/src/pokeblock_feed.c
+++ b/src/pokeblock_feed.c
@@ -26,207 +26,283 @@
#include "util.h"
#include "constants/rgb.h"
-struct PokeblockFeedStruct
+enum {
+ ANIMDATA_ROT_IDX,
+ ANIMDATA_ROT_SPEED,
+ ANIMDATA_SIN_AMPLITUDE,
+ ANIMDATA_COS_AMPLITUDE,
+ ANIMDATA_TIME,
+ ANIMDATA_ROT_ACCEL,
+ ANIMDATA_TARGET_X,
+ ANIMDATA_TARGET_Y,
+ ANIMDATA_APPR_TIME,
+ ANIMDATA_IS_LAST,
+ NUM_ANIMDATA
+};
+
+enum {
+ AFFINE_NONE,
+ AFFINE_TURN_UP,
+ AFFINE_TURN_UP_AND_DOWN,
+ AFFINE_TURN_DOWN,
+ AFFINE_TURN_DOWN_SLOW,
+ AFFINE_TURN_DOWN_SLIGHT,
+ AFFINE_TURN_UP_HIGH,
+ AFFINE_UNUSED_1,
+ AFFINE_UNUSED_2,
+ AFFINE_UNUSED_3,
+ NUM_MON_AFFINES,
+};
+
+#define MON_X 48
+#define MON_Y 80
+
+// The animation the Pokémon does during the feeding scene depends on their nature.
+// The below values are offsets into sMonPokeblockAnims of the animation data for that nature.
+#define ANIM_HARDY 0
+#define ANIM_LONELY (ANIM_HARDY + 3)
+#define ANIM_BRAVE (ANIM_LONELY + 1)
+#define ANIM_ADAMANT (ANIM_BRAVE + 1)
+#define ANIM_NAUGHTY (ANIM_ADAMANT + 5)
+#define ANIM_BOLD (ANIM_NAUGHTY + 3)
+#define ANIM_DOCILE (ANIM_BOLD + 2)
+#define ANIM_RELAXED (ANIM_DOCILE + 1)
+#define ANIM_IMPISH (ANIM_RELAXED + 2)
+#define ANIM_LAX (ANIM_IMPISH + 1)
+#define ANIM_TIMID (ANIM_LAX + 1)
+#define ANIM_HASTY (ANIM_TIMID + 5)
+#define ANIM_SERIOUS (ANIM_HASTY + 2)
+#define ANIM_JOLLY (ANIM_SERIOUS + 1)
+#define ANIM_NAIVE (ANIM_JOLLY + 1)
+#define ANIM_MODEST (ANIM_NAIVE + 4)
+#define ANIM_MILD (ANIM_MODEST + 3)
+#define ANIM_QUIET (ANIM_MILD + 1)
+#define ANIM_BASHFUL (ANIM_QUIET + 2)
+#define ANIM_RASH (ANIM_BASHFUL + 3)
+#define ANIM_CALM (ANIM_RASH + 3)
+#define ANIM_GENTLE (ANIM_CALM + 1)
+#define ANIM_SASSY (ANIM_GENTLE + 1)
+#define ANIM_CAREFUL (ANIM_SASSY + 1)
+#define ANIM_QUIRKY (ANIM_CAREFUL + 5)
+
+struct PokeblockFeed
{
struct Sprite *monSpritePtr;
struct Sprite savedMonSprite;
- u8 tilemapBuffer[0x808];
- s16 field_850[0x200];
- s16 field_C50[0x200];
- u8 field_1050;
+ u8 tilemapBuffer[BG_SCREEN_SIZE];
+ u8 unused1[8];
+ s16 monAnimX[0x200];
+ s16 monAnimY[0x200];
+ u8 animRunState;
u8 animId;
- u8 field_1052;
+ u8 unused2;
bool8 noMonFlip;
u16 species;
- u16 field_1056;
- u16 field_1058;
+ u16 monAnimLength;
+ u16 timer;
u8 nature;
- u8 monSpriteId_;
- u8 field_105C;
+ u8 monSpriteId_; // Duplicated unnecessarily
+ u8 unused3;
u8 monSpriteId;
u8 pokeblockCaseSpriteId;
u8 pokeblockSpriteId;
- s16 field_1060[15];
+ s16 animData[NUM_ANIMDATA];
+ s16 monInitX;
+ s16 monInitY;
+ s16 maxAnimStageTime;
+ s16 monX;
+ s16 monY;
s16 loadGfxState;
- u8 unused;
+ u8 unused4;
};
extern struct MusicPlayerInfo gMPlayInfo_BGM;
extern const u16 gUnknown_0860F074[];
-// this file's functions
static void HandleInitBackgrounds(void);
static void HandleInitWindows(void);
static void LaunchPokeblockFeedTask(void);
-static void SetPokeblockSpritePal(u8 pokeblockCaseId);
-static void sub_817A5CC(void);
-static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 arg1);
-static void PrepareMonToMoveToPokeblock(u8 spriteId);
-static void Task_HandleMonAtePokeblock(u8 taskId);
-static void Task_PaletteFadeToReturn(u8 taskId);
-static void sub_817A634(void);
-static void sub_817A468(struct Sprite *sprite);
-static void sub_817AB68(void);
-static void sub_817AA54(void);
-static bool8 sub_817A91C(void);
+static void SetPokeblockSpritePal(u8);
+static void CalculateMonAnimLength(void);
+static void DoPokeblockCaseThrowEffect(u8, bool8);
+static void StartMonJumpForPokeblock(u8);
+static void Task_PrintAtePokeblockMessage(u8);
+static void Task_FadeOutPokeblockFeed(u8);
+static void UpdateMonAnim(void);
+static void SpriteCB_MonJumpForPokeblock(struct Sprite *);
+static void CalculateMonAnimMovement(void);
+static void CalculateMonAnimMovementEnd(void);
+static bool8 InitMonAnimStage(void);
static bool8 FreeMonSpriteOamMatrix(void);
-static bool8 sub_817A9E4(void);
-static bool8 LoadMonAndSceneGfx(struct Pokemon *mon);
+static bool8 DoMonAnimStep(void);
+static bool8 LoadMonAndSceneGfx(struct Pokemon *);
static u8 CreatePokeblockSprite(void);
static u8 CreatePokeblockCaseSpriteForFeeding(void);
-static u8 CreateMonSprite(struct Pokemon *mon);
-static void SpriteCB_ThrownPokeblock(struct Sprite* sprite);
+static u8 CreateMonSprite(struct Pokemon *);
+static void SpriteCB_ThrownPokeblock(struct Sprite *);
-// ram variables
-EWRAM_DATA static struct PokeblockFeedStruct *sPokeblockFeed = NULL;
+EWRAM_DATA static struct PokeblockFeed *sPokeblockFeed = NULL;
EWRAM_DATA static struct CompressedSpritePalette sPokeblockSpritePal = {0};
-// const rom data
static const u8 sNatureToMonPokeblockAnim[NUM_NATURES][2] =
{
- [NATURE_HARDY] = { 0, 0 },
- [NATURE_LONELY] = { 3, 0 },
- [NATURE_BRAVE] = { 4, 1 },
- [NATURE_ADAMANT] = { 5, 0 },
- [NATURE_NAUGHTY] = { 10, 0 },
- [NATURE_BOLD] = { 13, 0 },
- [NATURE_DOCILE] = { 15, 0 },
- [NATURE_RELAXED] = { 16, 2 },
- [NATURE_IMPISH] = { 18, 0 },
- [NATURE_LAX] = { 19, 0 },
- [NATURE_TIMID] = { 20, 0 },
- [NATURE_HASTY] = { 25, 0 },
- [NATURE_SERIOUS] = { 27, 3 },
- [NATURE_JOLLY] = { 28, 0 },
- [NATURE_NAIVE] = { 29, 0 },
- [NATURE_MODEST] = { 33, 4 },
- [NATURE_MILD] = { 36, 0 },
- [NATURE_QUIET] = { 37, 0 },
- [NATURE_BASHFUL] = { 39, 0 },
- [NATURE_RASH] = { 42, 0 },
- [NATURE_CALM] = { 45, 0 },
- [NATURE_GENTLE] = { 46, 5 },
- [NATURE_SASSY] = { 47, 6 },
- [NATURE_CAREFUL] = { 48, 0 },
- [NATURE_QUIRKY] = { 53, 0 },
+ [NATURE_HARDY] = { ANIM_HARDY, AFFINE_NONE },
+ [NATURE_LONELY] = { ANIM_LONELY, AFFINE_NONE },
+ [NATURE_BRAVE] = { ANIM_BRAVE, AFFINE_TURN_UP },
+ [NATURE_ADAMANT] = { ANIM_ADAMANT, AFFINE_NONE },
+ [NATURE_NAUGHTY] = { ANIM_NAUGHTY, AFFINE_NONE },
+ [NATURE_BOLD] = { ANIM_BOLD, AFFINE_NONE },
+ [NATURE_DOCILE] = { ANIM_DOCILE, AFFINE_NONE },
+ [NATURE_RELAXED] = { ANIM_RELAXED, AFFINE_TURN_UP_AND_DOWN },
+ [NATURE_IMPISH] = { ANIM_IMPISH, AFFINE_NONE },
+ [NATURE_LAX] = { ANIM_LAX, AFFINE_NONE },
+ [NATURE_TIMID] = { ANIM_TIMID, AFFINE_NONE },
+ [NATURE_HASTY] = { ANIM_HASTY, AFFINE_NONE },
+ [NATURE_SERIOUS] = { ANIM_SERIOUS, AFFINE_TURN_DOWN },
+ [NATURE_JOLLY] = { ANIM_JOLLY, AFFINE_NONE },
+ [NATURE_NAIVE] = { ANIM_NAIVE, AFFINE_NONE },
+ [NATURE_MODEST] = { ANIM_MODEST, AFFINE_TURN_DOWN_SLOW },
+ [NATURE_MILD] = { ANIM_MILD, AFFINE_NONE },
+ [NATURE_QUIET] = { ANIM_QUIET, AFFINE_NONE },
+ [NATURE_BASHFUL] = { ANIM_BASHFUL, AFFINE_NONE },
+ [NATURE_RASH] = { ANIM_RASH, AFFINE_NONE },
+ [NATURE_CALM] = { ANIM_CALM, AFFINE_NONE },
+ [NATURE_GENTLE] = { ANIM_GENTLE, AFFINE_TURN_DOWN_SLIGHT },
+ [NATURE_SASSY] = { ANIM_SASSY, AFFINE_TURN_UP_HIGH },
+ [NATURE_CAREFUL] = { ANIM_CAREFUL, AFFINE_NONE },
+ [NATURE_QUIRKY] = { ANIM_QUIRKY, AFFINE_NONE },
};
-static const s16 sMonPokeblockAnims[][10] =
+// Data for the animation the Pokémon does while readying to jump for the Pokéblock
+// Each nature can have up to 8 anim 'stages' it progresses through, and each stage has its own array of data.
+// The elements in each array correspond in order to the following:
+// - ANIMDATA_ROT_IDX : Index into sin/cos table for circular movement
+// - ANIMDATA_ROT_SPEED : Circular movement speed
+// - ANIMDATA_SIN_AMPLITUDE: How far on the x to move
+// - ANIMDATA_COS_AMPLITUDE: How far on the y to move
+// - ANIMDATA_TIME : How long in frames this part of the animation takes
+// - ANIMDATA_ROT_ACCEL : How much to increase circular movement speed
+// - ANIMDATA_TARGET_X : Target x coord offset from start position
+// - ANIMDATA_TARGET_Y : Target y coord offset from start position
+// - ANIMDATA_APPR_TIME : The time over which the target position should be approached
+// - ANIMDATA_IS_LAST : TRUE if it's the last anim stage for this nature, FALSE otherwise
+//
+static const s16 sMonPokeblockAnims[][NUM_ANIMDATA] =
{
- // HARDY
- { 0, 4, 0, 8, 24, 0, 0, 0, 12, 0},
- { 0, 4, 0, 16, 24, 0, 0, 0, 12, 0},
- { 0, 4, 0, 32, 32, 0, 0, 0, 16, 1},
-
- // LONELY
- { 0, 3, 6, 0, 48, 0, 0, 0, 24, 1},
-
- // BRAVE
- { 64, 16, -24, 0, 32, 0, 0, 0, 0, 1},
-
- // ADAMANT
- { 0, 4, 8, 0, 16, 0, -8, 0, 0, 0},
- { 0, 0, 0, 0, 16, 0, 0, 0, 0, 0},
- { 0, 4, 8, 0, 16, 0, -8, 0, 0, 0},
- { 0, 0, 0, 0, 16, 0, 0, 0, 0, 0},
- { 0, 4, -16, 0, 4, 0, 16, 0, 0, 1},
-
- // NAUGHTY
- { 0, 3, 6, 0, 12, 0, 0, 0, 6, 0},
- { 0, 3, -6, 0, 12, 0, 0, 0, 6, 0},
- { 0, 16, 16, 0, 45, 1, 0, 0, 0, 1},
-
- // BOLD
- { 0, 16, 0, 24, 32, 0, 0, 0, 16, 0},
- { 0, 16, 0, 23, 32, 0, 0, 0, 16, 1},
-
- // DOCILE
- { 0, 0, 0, 0, 80, 0, 0, 0, 0, 1},
-
- // RELAXED
- { 0, 2, 8, 0, 32, 0, 0, 0, 0, 0},
- { 0, 2, -8, 0, 32, 0, 0, 0, 0, 1},
-
- // IMPISH
- { 0, 32, 2, 1, 48, 1, 0, 0, 24, 1},
-
- // LAX
- { 0, 2, 16, 16, 128, 0, 0, 0, 0, 1},
-
- // TIMID
- { 0, 2, -8, 0, 48, 0, -24, 0, 0, 0},
- { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
- { 64, 32, 2, 0, 36, 0, 0, 0, 0, 0},
- { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
- { 0, 2, 8, 0, 48, 0, 24, 0, 0, 1},
-
- // HASTY
- { 64, 24, 16, 0, 32, 0, 0, 0, 0, 0},
- { 0, 28, 2, 1, 32, 1, 0, 0, 16, 1},
-
- // SERIOUS
- { 0, 0, 0, 0, 32, 0, 0, 0, 0, 1},
-
- // JOLLY
- { 64, 16, -16, 2, 48, 0, 0, 0, 32, 1},
-
- // NAIVE
- { 0, 12, -8, 4, 24, 0, 8, 0, 12, 0},
- { 0, 12, 8, 8, 24, 0, -16, 0, 12, 0},
- { 0, 12, -8, 16, 24, 0, 16, 0, 12, 0},
- { 0, 12, 8, 28, 24, 0, -8, 0, 12, 1},
-
- // MODEST
- { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
- { 64, 16, -4, 0, 32, 0, 0, 0, 0, 0},
- { 0, 0, 0, 0, 8, 0, 0, 0, 0, 1},
-
- // MILD
- { 128, 4, 0, 8, 64, 0, 0, 0, 0, 1},
-
- // QUIET
- { 0, 2, 16, 0, 48, 0, 0, 0, 0, 0},
- { 128, 2, 16, 0, 48, 0, 0, 0, 0, 1},
-
- // BASHFUL
- { 0, 2, -4, 0, 48, 0, -48, 0, 0, 0},
- { 0, 0, 0, 0, 80, 0, 0, 0, 0, 0},
- { 0, 2, 8, 0, 24, 0, 48, 0, 0, 1},
-
- // RASH
- { 64, 4, 64, 58, 52, 0, -88, 0, 0, 0},
- { 0, 0, 0, 0, 80, 0, 0, 0, 0, 0},
- { 0, 24, 80, 0, 32, 0, 88, 0, 0, 1},
-
- // CALM
- { 0, 2, 16, 4, 64, 0, 0, 0, 0, 1},
-
- // GENTLE
- { 0, 0, 0, 0, 32, 0, 0, 0, 0, 1},
-
- // SASSY
- { 0, 0, 0, 0, 42, 0, 0, 0, 0, 1},
-
- // CAREFUL
- { 0, 4, 0, 8, 24, 0, 0, 0, 12, 0},
- { 0, 0, 0, 0, 12, 0, 0, 0, 0, 0},
- { 0, 4, 0, 12, 24, 0, 0, 0, 12, 0},
- { 0, 0, 0, 0, 12, 0, 0, 0, 0, 0},
- { 0, 4, 0, 4, 24, 0, 0, 0, 12, 1},
-
- // QUIRKY
- { 0, 4, 16, 12, 64, 0, 0, 0, 0, 0},
- { 0, -4, 16, 12, 64, 0, 0, 0, 0, 1},
+ [ANIM_HARDY] =
+ { 0, 4, 0, 8, 24, 0, 0, 0, 12, FALSE},
+ { 0, 4, 0, 16, 24, 0, 0, 0, 12, FALSE},
+ { 0, 4, 0, 32, 32, 0, 0, 0, 16, TRUE},
+
+ [ANIM_LONELY] =
+ { 0, 3, 6, 0, 48, 0, 0, 0, 24, TRUE},
+
+ [ANIM_BRAVE] =
+ { 64, 16, -24, 0, 32, 0, 0, 0, 0, TRUE},
+
+ [ANIM_ADAMANT] =
+ { 0, 4, 8, 0, 16, 0, -8, 0, 0, FALSE},
+ { 0, 0, 0, 0, 16, 0, 0, 0, 0, FALSE},
+ { 0, 4, 8, 0, 16, 0, -8, 0, 0, FALSE},
+ { 0, 0, 0, 0, 16, 0, 0, 0, 0, FALSE},
+ { 0, 4, -16, 0, 4, 0, 16, 0, 0, TRUE},
+
+ [ANIM_NAUGHTY] =
+ { 0, 3, 6, 0, 12, 0, 0, 0, 6, FALSE},
+ { 0, 3, -6, 0, 12, 0, 0, 0, 6, FALSE},
+ { 0, 16, 16, 0, 45, 1, 0, 0, 0, TRUE},
+
+ [ANIM_BOLD] =
+ { 0, 16, 0, 24, 32, 0, 0, 0, 16, FALSE},
+ { 0, 16, 0, 23, 32, 0, 0, 0, 16, TRUE},
+
+ [ANIM_DOCILE] =
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, TRUE},
+
+ [ANIM_RELAXED] =
+ { 0, 2, 8, 0, 32, 0, 0, 0, 0, FALSE},
+ { 0, 2, -8, 0, 32, 0, 0, 0, 0, TRUE},
+
+ [ANIM_IMPISH] =
+ { 0, 32, 2, 1, 48, 1, 0, 0, 24, TRUE},
+
+ [ANIM_LAX] =
+ { 0, 2, 16, 16, 128, 0, 0, 0, 0, TRUE},
+
+ [ANIM_TIMID] =
+ { 0, 2, -8, 0, 48, 0, -24, 0, 0, FALSE},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
+ { 64, 32, 2, 0, 36, 0, 0, 0, 0, FALSE},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
+ { 0, 2, 8, 0, 48, 0, 24, 0, 0, TRUE},
+
+ [ANIM_HASTY] =
+ { 64, 24, 16, 0, 32, 0, 0, 0, 0, FALSE},
+ { 0, 28, 2, 1, 32, 1, 0, 0, 16, TRUE},
+
+ [ANIM_SERIOUS] =
+ { 0, 0, 0, 0, 32, 0, 0, 0, 0, TRUE},
+
+ [ANIM_JOLLY] =
+ { 64, 16, -16, 2, 48, 0, 0, 0, 32, TRUE},
+
+ [ANIM_NAIVE] =
+ { 0, 12, -8, 4, 24, 0, 8, 0, 12, FALSE},
+ { 0, 12, 8, 8, 24, 0, -16, 0, 12, FALSE},
+ { 0, 12, -8, 16, 24, 0, 16, 0, 12, FALSE},
+ { 0, 12, 8, 28, 24, 0, -8, 0, 12, TRUE},
+
+ [ANIM_MODEST] =
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
+ { 64, 16, -4, 0, 32, 0, 0, 0, 0, FALSE},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, TRUE},
+
+ [ANIM_MILD] =
+ { 128, 4, 0, 8, 64, 0, 0, 0, 0, TRUE},
+
+ [ANIM_QUIET] =
+ { 0, 2, 16, 0, 48, 0, 0, 0, 0, FALSE},
+ { 128, 2, 16, 0, 48, 0, 0, 0, 0, TRUE},
+
+ [ANIM_BASHFUL] =
+ { 0, 2, -4, 0, 48, 0, -48, 0, 0, FALSE},
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, FALSE},
+ { 0, 2, 8, 0, 24, 0, 48, 0, 0, TRUE},
+
+ [ANIM_RASH] =
+ { 64, 4, 64, 58, 52, 0, -88, 0, 0, FALSE},
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, FALSE},
+ { 0, 24, 80, 0, 32, 0, 88, 0, 0, TRUE},
+
+ [ANIM_CALM] =
+ { 0, 2, 16, 4, 64, 0, 0, 0, 0, TRUE},
+
+ [ANIM_GENTLE] =
+ { 0, 0, 0, 0, 32, 0, 0, 0, 0, TRUE},
+
+ [ANIM_SASSY] =
+ { 0, 0, 0, 0, 42, 0, 0, 0, 0, TRUE},
+
+ [ANIM_CAREFUL] =
+ { 0, 4, 0, 8, 24, 0, 0, 0, 12, FALSE},
+ { 0, 0, 0, 0, 12, 0, 0, 0, 0, FALSE},
+ { 0, 4, 0, 12, 24, 0, 0, 0, 12, FALSE},
+ { 0, 0, 0, 0, 12, 0, 0, 0, 0, FALSE},
+ { 0, 4, 0, 4, 24, 0, 0, 0, 12, TRUE},
+
+ [ANIM_QUIRKY] =
+ { 0, 4, 16, 12, 64, 0, 0, 0, 0, FALSE},
+ { 0, -4, 16, 12, 64, 0, 0, 0, 0, TRUE},
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411E90[] =
+static const union AffineAnimCmd sAffineAnim_Mon_None[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411EA0[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUp[] =
{
AFFINEANIMCMD_FRAME(0, 0, 12, 1),
AFFINEANIMCMD_FRAME(0, 0, 0, 30),
@@ -234,7 +310,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411EA0[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411EC0[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUp_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0, 0, 12, 1),
@@ -243,7 +319,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411EC0[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411EE8[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUpAndDown[] =
{
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 32),
@@ -251,7 +327,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411EE8[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411F08[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUpAndDown_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
@@ -260,7 +336,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411F08[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411F30[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDown[] =
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
@@ -268,7 +344,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411F30[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411F50[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDown_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
@@ -277,7 +353,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411F50[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411F78[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlow[] =
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 32),
@@ -285,7 +361,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411F78[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411F98[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlow_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
@@ -294,7 +370,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411F98[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411FC0[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlight[] =
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 24),
@@ -302,7 +378,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411FC0[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8411FE0[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlight_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
@@ -311,7 +387,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8411FE0[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8412008[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUpHigh[] =
{
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
@@ -319,7 +395,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_8412008[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8412028[] =
+static const union AffineAnimCmd sAffineAnim_Mon_TurnUpHigh_Flipped[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
@@ -328,29 +404,33 @@ static const union AffineAnimCmd sSpriteAffineAnim_8412028[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F04FC[] =
+static const union AffineAnimCmd *const sAffineAnims_Mon[] =
{
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411EA0,
- sSpriteAffineAnim_8411EE8,
- sSpriteAffineAnim_8411F30,
- sSpriteAffineAnim_8411F78,
- sSpriteAffineAnim_8411FC0,
- sSpriteAffineAnim_8412008,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411EC0,
- sSpriteAffineAnim_8411F08,
- sSpriteAffineAnim_8411F50,
- sSpriteAffineAnim_8411F98,
- sSpriteAffineAnim_8411FE0,
- sSpriteAffineAnim_8412028,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
- sSpriteAffineAnim_8411E90,
+ // Animations for non-flipped mon sprites
+ [AFFINE_NONE] = sAffineAnim_Mon_None,
+ [AFFINE_TURN_UP] = sAffineAnim_Mon_TurnUp,
+ [AFFINE_TURN_UP_AND_DOWN] = sAffineAnim_Mon_TurnUpAndDown,
+ [AFFINE_TURN_DOWN] = sAffineAnim_Mon_TurnDown,
+ [AFFINE_TURN_DOWN_SLOW] = sAffineAnim_Mon_TurnDownSlow,
+ [AFFINE_TURN_DOWN_SLIGHT] = sAffineAnim_Mon_TurnDownSlight,
+ [AFFINE_TURN_UP_HIGH] = sAffineAnim_Mon_TurnUpHigh,
+ [AFFINE_UNUSED_1] = sAffineAnim_Mon_None,
+ [AFFINE_UNUSED_2] = sAffineAnim_Mon_None,
+ [AFFINE_UNUSED_3] = sAffineAnim_Mon_None,
+
+ // Animations for flipped mon sprites
+ [AFFINE_NONE + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
+ [AFFINE_TURN_UP + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUp_Flipped,
+ [AFFINE_TURN_UP_AND_DOWN + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUpAndDown_Flipped,
+ [AFFINE_TURN_DOWN + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDown_Flipped,
+ [AFFINE_TURN_DOWN_SLOW + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDownSlow_Flipped,
+ [AFFINE_TURN_DOWN_SLIGHT + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDownSlight_Flipped,
+ [AFFINE_TURN_UP_HIGH + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUpHigh_Flipped,
+ [AFFINE_UNUSED_1 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
+ [AFFINE_UNUSED_2 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
+ [AFFINE_UNUSED_3 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
+
+ sAffineAnim_Mon_None, // ? Extra for some reason
};
static const struct BgTemplate sBackgroundTemplates[] =
@@ -377,7 +457,15 @@ static const struct BgTemplate sBackgroundTemplates[] =
static const struct WindowTemplate sWindowTemplates[] =
{
- {0, 1, 0xF, 0x1C, 4, 0xF, 0xA},
+ {
+ .bg = 0,
+ .tilemapLeft = 1,
+ .tilemapTop = 15,
+ .width = 28,
+ .height = 4,
+ .paletteNum = 15,
+ .baseBlock = 0xA
+ },
DUMMY_WIN_TEMPLATE
};
@@ -400,7 +488,7 @@ static const u32* const sPokeblocksPals[] =
[PBLOCK_CLR_GOLD - 1] = gPokeblockGold_Pal
};
-static const union AffineAnimCmd sSpriteAffineAnim_84120DC[] =
+static const union AffineAnimCmd sAffineAnim_Still[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
@@ -408,10 +496,10 @@ static const union AffineAnimCmd sSpriteAffineAnim_84120DC[] =
static const union AffineAnimCmd *const sSpriteAffineAnimTable_MonNoFlip[] =
{
- sSpriteAffineAnim_84120DC
+ sAffineAnim_Still
};
-static const union AffineAnimCmd sSpriteAffineAnim_84120F0[] =
+static const union AffineAnimCmd sAffineAnim_PokeblockCase_ThrowFromVertical[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
@@ -426,7 +514,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_84120F0[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd sSpriteAffineAnim_8412148[] =
+static const union AffineAnimCmd sAffineAnim_PokeblockCase_ThrowFromHorizontal[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
@@ -441,22 +529,22 @@ static const union AffineAnimCmd sSpriteAffineAnim_8412148[] =
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F0664[] =
+static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_Still[] =
{
- sSpriteAffineAnim_84120DC
+ sAffineAnim_Still
};
-static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F0668[] =
+static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_ThrowFromVertical[] =
{
- sSpriteAffineAnim_84120F0
+ sAffineAnim_PokeblockCase_ThrowFromVertical
};
-static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F066C[] =
+static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_ThrowFromHorizontal[] =
{
- sSpriteAffineAnim_8412148
+ sAffineAnim_PokeblockCase_ThrowFromHorizontal
};
-static const struct OamData sThrownPokeblockOamData =
+static const struct OamData sOamData_Pokeblock =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_DOUBLE,
@@ -473,46 +561,45 @@ static const struct OamData sThrownPokeblockOamData =
.affineParam = 0,
};
-static const union AnimCmd sThrownPokeblockSpriteAnim[] =
+static const union AnimCmd sAnim_Pokeblock[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
-static const union AnimCmd *const sThrownPokeblockAnimTable[] =
+static const union AnimCmd *const sAnims_Pokeblock[] =
{
- sThrownPokeblockSpriteAnim,
+ sAnim_Pokeblock,
};
-static const union AffineAnimCmd sSpriteAffineAnim_84121C0[] =
+static const union AffineAnimCmd sAffineAnim_Pokeblock[] =
{
AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(-8, -8, 0, 1),
AFFINEANIMCMD_JUMP(1)
};
-static const union AffineAnimCmd *const sThrownPokeblockAffineAnimTable[] =
+static const union AffineAnimCmd *const sAffineAnims_Pokeblock[] =
{
- sSpriteAffineAnim_84121C0
+ sAffineAnim_Pokeblock
};
-static const struct CompressedSpriteSheet sPokeblock_SpriteSheet =
+static const struct CompressedSpriteSheet sSpriteSheet_Pokeblock =
{
- gPokeblock_Gfx, 0x20, GFX_TAG_POKEBLOCK
+ gPokeblock_Gfx, 0x20, TAG_POKEBLOCK
};
-static const struct SpriteTemplate sThrownPokeblockSpriteTemplate =
+static const struct SpriteTemplate sSpriteTemplate_Pokeblock =
{
- .tileTag = GFX_TAG_POKEBLOCK,
- .paletteTag = GFX_TAG_POKEBLOCK,
- .oam = &sThrownPokeblockOamData,
- .anims = sThrownPokeblockAnimTable,
+ .tileTag = TAG_POKEBLOCK,
+ .paletteTag = TAG_POKEBLOCK,
+ .oam = &sOamData_Pokeblock,
+ .anims = sAnims_Pokeblock,
.images = NULL,
- .affineAnims = sThrownPokeblockAffineAnimTable,
+ .affineAnims = sAffineAnims_Pokeblock,
.callback = SpriteCB_ThrownPokeblock
};
-// code
static void CB2_PokeblockFeed(void)
{
RunTasks();
@@ -529,7 +616,7 @@ static void VBlankCB_PokeblockFeed(void)
TransferPlttBuffer();
}
-static bool8 TransitionToPokeblockFeedScene(void)
+static bool8 LoadPokeblockFeedScene(void)
{
switch (gMain.state)
{
@@ -541,7 +628,7 @@ static bool8 TransitionToPokeblockFeedScene(void)
break;
case 1:
ResetPaletteFade();
- gPaletteFade.bufferTransferDisabled = 1;
+ gPaletteFade.bufferTransferDisabled = TRUE;
gMain.state++;
break;
case 2:
@@ -566,9 +653,7 @@ static bool8 TransitionToPokeblockFeedScene(void)
break;
case 7:
if (LoadMonAndSceneGfx(&gPlayerParty[gPokeblockMonId]))
- {
gMain.state++;
- }
break;
case 8:
sPokeblockFeed->pokeblockCaseSpriteId = CreatePokeblockCaseSpriteForFeeding();
@@ -587,12 +672,12 @@ static bool8 TransitionToPokeblockFeedScene(void)
gMain.state++;
break;
case 12:
- BlendPalettes(PALETTES_ALL, 0x10, 0);
+ BlendPalettes(PALETTES_ALL, 16, 0);
gMain.state++;
break;
case 13:
- BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK);
- gPaletteFade.bufferTransferDisabled = 0;
+ BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
+ gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
default:
@@ -603,13 +688,13 @@ static bool8 TransitionToPokeblockFeedScene(void)
return FALSE;
}
-void CB2_PreparePokeblockFeedScene(void)
+void PreparePokeblockFeedScene(void)
{
while (1)
{
if (MenuHelpers_CallLinkSomething() == TRUE)
break;
- if (TransitionToPokeblockFeedScene() == TRUE)
+ if (LoadPokeblockFeedScene() == TRUE)
break;
if (MenuHelpers_LinkSomething() == TRUE)
break;
@@ -643,12 +728,14 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
switch (sPokeblockFeed->loadGfxState)
{
case 0:
+ // Load mon gfx
species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
sPokeblockFeed->loadGfxState++;
break;
case 1:
+ // Load mon palette
species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
trainerId = GetMonData(mon, MON_DATA_OT_ID);
@@ -667,7 +754,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
sPokeblockFeed->loadGfxState++;
break;
case 4:
- LoadCompressedSpriteSheet(&sPokeblock_SpriteSheet);
+ LoadCompressedSpriteSheet(&sSpriteSheet_Pokeblock);
sPokeblockFeed->loadGfxState++;
break;
case 5:
@@ -683,7 +770,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
case 7:
if (FreeTempTileDataBuffersIfPossible() != TRUE)
{
- LZDecompressWram(gUnknown_08D9BA44, sPokeblockFeed->tilemapBuffer);
+ LZDecompressWram(gPokeblockFeedBg_Tilemap, sPokeblockFeed->tilemapBuffer);
sPokeblockFeed->loadGfxState++;
}
break;
@@ -711,63 +798,68 @@ static void SetPokeblockSpritePal(u8 pokeblockCaseId)
{
u8 colorId = GetPokeblockData(&gSaveBlock1Ptr->pokeblocks[pokeblockCaseId], PBLOCK_COLOR);
sPokeblockSpritePal.data = sPokeblocksPals[colorId - 1];
- sPokeblockSpritePal.tag = GFX_TAG_POKEBLOCK;
+ sPokeblockSpritePal.tag = TAG_POKEBLOCK;
}
// defines for task data fields
-#define tFrames data[0]
-#define tData1 data[1]
+#define tState data[0]
+#define tHorizontalThrow data[1]
+
+#define STATE_START_THROW 255 // If the length of the Pokémon's animation exceeds 255 the throw may happen twice
+#define STATE_SPAWN_PBLOCK (STATE_START_THROW + 14)
+#define STATE_START_JUMP (STATE_SPAWN_PBLOCK + 12)
+#define STATE_PRINT_MSG (STATE_START_JUMP + 16)
static void Task_HandlePokeblockFeed(u8 taskId)
{
if (!gPaletteFade.active)
{
- switch (gTasks[taskId].tFrames)
+ switch (gTasks[taskId].tState)
{
case 0:
- sPokeblockFeed->field_1050 = 0;
- sPokeblockFeed->field_1058 = 0;
- sub_817A5CC();
+ sPokeblockFeed->animRunState = 0;
+ sPokeblockFeed->timer = 0;
+ CalculateMonAnimLength();
break;
- case 255:
- DoPokeblockCaseThrowEffect(sPokeblockFeed->pokeblockCaseSpriteId, gTasks[taskId].tData1);
+ case STATE_START_THROW:
+ DoPokeblockCaseThrowEffect(sPokeblockFeed->pokeblockCaseSpriteId, gTasks[taskId].tHorizontalThrow);
break;
- case 269:
+ case STATE_SPAWN_PBLOCK:
sPokeblockFeed->pokeblockSpriteId = CreatePokeblockSprite();
break;
- case 281:
- PrepareMonToMoveToPokeblock(sPokeblockFeed->monSpriteId);
+ case STATE_START_JUMP:
+ StartMonJumpForPokeblock(sPokeblockFeed->monSpriteId);
break;
- case 297:
- gTasks[taskId].func = Task_HandleMonAtePokeblock;
+ case STATE_PRINT_MSG:
+ gTasks[taskId].func = Task_PrintAtePokeblockMessage;
return;
}
- if (sPokeblockFeed->field_1058 < sPokeblockFeed->field_1056)
- sub_817A634();
- else if (sPokeblockFeed->field_1058 == sPokeblockFeed->field_1056)
- gTasks[taskId].tFrames = 254;
+ if (sPokeblockFeed->timer < sPokeblockFeed->monAnimLength)
+ UpdateMonAnim();
+ else if (sPokeblockFeed->timer == sPokeblockFeed->monAnimLength)
+ gTasks[taskId].tState = STATE_START_THROW - 1;
- sPokeblockFeed->field_1058++;
- gTasks[taskId].tFrames++;
+ sPokeblockFeed->timer++;
+ gTasks[taskId].tState++;
}
}
static void LaunchPokeblockFeedTask(void)
{
u8 taskId = CreateTask(Task_HandlePokeblockFeed, 0);
- gTasks[taskId].tFrames = 0;
- gTasks[taskId].tData1 = 1;
+ gTasks[taskId].tState = 0;
+ gTasks[taskId].tHorizontalThrow = TRUE;
}
-static void Task_WaitForAtePokeblockText(u8 taskId)
+static void Task_WaitForAtePokeblockMessage(u8 taskId)
{
if (RunTextPrintersRetIsActive(0) != TRUE)
- gTasks[taskId].func = Task_PaletteFadeToReturn;
+ gTasks[taskId].func = Task_FadeOutPokeblockFeed;
}
-static void Task_HandleMonAtePokeblock(u8 taskId)
+static void Task_PrintAtePokeblockMessage(u8 taskId)
{
struct Pokemon *mon = &gPlayerParty[gPokeblockMonId];
struct Pokeblock *pokeblock = &gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId];
@@ -783,12 +875,12 @@ static void Task_HandleMonAtePokeblock(u8 taskId)
else
StringExpandPlaceholders(gStringVar4, gText_Var1DisdainfullyAteVar2);
- gTextFlags.canABSpeedUpPrint = 1;
+ gTextFlags.canABSpeedUpPrint = TRUE;
AddTextPrinterParameterized2(0, 1, gStringVar4, GetPlayerTextSpeedDelay(), NULL, 2, 1, 3);
- gTasks[taskId].func = Task_WaitForAtePokeblockText;
+ gTasks[taskId].func = Task_WaitForAtePokeblockMessage;
}
-static void Task_ReturnAfterPaletteFade(u8 taskId)
+static void Task_ExitPokeblockFeed(u8 taskId)
{
if (!gPaletteFade.active)
{
@@ -803,30 +895,29 @@ static void Task_ReturnAfterPaletteFade(u8 taskId)
}
}
-static void Task_PaletteFadeToReturn(u8 taskId)
+static void Task_FadeOutPokeblockFeed(u8 taskId)
{
- BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
- gTasks[taskId].func = Task_ReturnAfterPaletteFade;
+ BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
+ gTasks[taskId].func = Task_ExitPokeblockFeed;
}
-#undef tFrames
-#undef tData1
-
-// defines for mon sprite data fields
+#undef tState
+#undef tHorizontalThrow
-#define tDelta data[0]
-#define tDeltaMod data[1]
-#define tSpecies data[2]
+// Sprite data for Pokéblock and Pokémon
+#define sSpeed data[0]
+#define sAccel data[1]
+#define sSpecies data[2]
static u8 CreateMonSprite(struct Pokemon* mon)
{
u16 species = GetMonData(mon, MON_DATA_SPECIES2);
- u8 spriteId = CreateSprite(&gMultiuseSpriteTemplate, 48, 80, 2);
+ u8 spriteId = CreateSprite(&gMultiuseSpriteTemplate, MON_X, MON_Y, 2);
sPokeblockFeed->species = species;
sPokeblockFeed->monSpriteId_ = spriteId;
sPokeblockFeed->nature = GetNature(mon);
- gSprites[spriteId].tSpecies = species;
+ gSprites[spriteId].sSpecies = species;
gSprites[spriteId].callback = SpriteCallbackDummy;
sPokeblockFeed->noMonFlip = TRUE;
@@ -841,189 +932,191 @@ static u8 CreateMonSprite(struct Pokemon* mon)
return spriteId;
}
-static void PrepareMonToMoveToPokeblock(u8 spriteId)
+static void StartMonJumpForPokeblock(u8 spriteId)
{
- gSprites[spriteId].pos1.x = 48;
- gSprites[spriteId].pos1.y = 80;
- gSprites[spriteId].tDelta = -8;
- gSprites[spriteId].tDeltaMod = 1;
- gSprites[spriteId].callback = sub_817A468;
+ gSprites[spriteId].pos1.x = MON_X;
+ gSprites[spriteId].pos1.y = MON_Y;
+ gSprites[spriteId].sSpeed = -8;
+ gSprites[spriteId].sAccel = 1;
+ gSprites[spriteId].callback = SpriteCB_MonJumpForPokeblock;
}
-static void sub_817A468(struct Sprite* sprite)
+static void SpriteCB_MonJumpForPokeblock(struct Sprite* sprite)
{
sprite->pos1.x += 4;
- sprite->pos1.y += sprite->tDelta;
- sprite->tDelta += sprite->tDeltaMod;
+ sprite->pos1.y += sprite->sSpeed;
+ sprite->sSpeed += sprite->sAccel;
- if (sprite->tDelta == 0)
- PlayCry1(sprite->tSpecies, 0);
- if (sprite->tDelta == 9)
+ // Play cry at jump peak
+ if (sprite->sSpeed == 0)
+ PlayCry1(sprite->sSpecies, 0);
+
+ if (sprite->sSpeed == 9)
sprite->callback = SpriteCallbackDummy;
}
-#undef tDelta
-#undef tDeltaMod
-#undef tSpecies
-
static u8 CreatePokeblockCaseSpriteForFeeding(void)
{
u8 spriteId = CreatePokeblockCaseSprite(188, 100, 2);
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
- gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F0664;
+ gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_Still;
gSprites[spriteId].callback = SpriteCallbackDummy;
InitSpriteAffineAnim(&gSprites[spriteId]);
return spriteId;
}
-static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 a1)
+static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 horizontalThrow)
{
FreeOamMatrix(gSprites[spriteId].oam.matrixNum);
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_DOUBLE;
- if (!a1)
- gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F0668;
+ if (!horizontalThrow)
+ gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_ThrowFromVertical; // Never used, horizontalThrow always TRUE
else
- gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F066C;
+ gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_ThrowFromHorizontal;
InitSpriteAffineAnim(&gSprites[spriteId]);
}
-// defines for the pokeblock sprite data fields
-#define tDelta data[0]
-#define tDeltaMod data[1]
-
static u8 CreatePokeblockSprite(void)
{
- u8 spriteId = CreateSprite(&sThrownPokeblockSpriteTemplate, 174, 84, 1);
- gSprites[spriteId].tDelta = -12;
- gSprites[spriteId].tDeltaMod = 1;
+ u8 spriteId = CreateSprite(&sSpriteTemplate_Pokeblock, 174, 84, 1);
+ gSprites[spriteId].sSpeed = -12;
+ gSprites[spriteId].sAccel = 1;
return spriteId;
}
static void SpriteCB_ThrownPokeblock(struct Sprite* sprite)
{
sprite->pos1.x -= 4;
- sprite->pos1.y += sprite->tDelta;
- sprite->tDelta += sprite->tDeltaMod;
- if (sprite->tDelta == 10)
+ sprite->pos1.y += sprite->sSpeed;
+ sprite->sSpeed += sprite->sAccel;
+ if (sprite->sSpeed == 10)
DestroySprite(sprite);
}
-#undef tDelta
-#undef tDeltaMod
-
-static void sub_817A5CC(void)
+static void CalculateMonAnimLength(void)
{
u8 animId, i;
- struct PokeblockFeedStruct *pokeblockFeed;
+ struct PokeblockFeed *pokeblockFeed;
pokeblockFeed = sPokeblockFeed;
- pokeblockFeed->field_1056 = 1;
+ pokeblockFeed->monAnimLength = 1;
animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
+
+ // Add up the time each stage of the animation will take
for (i = 0; i < 8; i++, animId++)
{
- pokeblockFeed->field_1056 += sMonPokeblockAnims[animId][4];
- if (sMonPokeblockAnims[animId][9] == 1)
+ pokeblockFeed->monAnimLength += sMonPokeblockAnims[animId][ANIMDATA_TIME];
+ if (sMonPokeblockAnims[animId][ANIMDATA_IS_LAST] == TRUE)
break;
}
}
-static void sub_817A634(void)
+static void UpdateMonAnim(void)
{
- struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
- switch (pokeblockFeed->field_1050)
+ switch (pokeblockFeed->animRunState)
{
case 0:
pokeblockFeed->animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
pokeblockFeed->monSpritePtr = &gSprites[pokeblockFeed->monSpriteId_];
pokeblockFeed->savedMonSprite = *pokeblockFeed->monSpritePtr;
- pokeblockFeed->field_1050 = 10;
+ pokeblockFeed->animRunState = 10;
break;
case 1 ... 9:
break;
case 10:
- sub_817A91C();
- if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != 0)
+ InitMonAnimStage();
+ if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != AFFINE_NONE)
{
+ // Initialize affine anim
pokeblockFeed->monSpritePtr->oam.affineMode = ST_OAM_AFFINE_DOUBLE;
pokeblockFeed->monSpritePtr->oam.matrixNum = 0;
- pokeblockFeed->monSpritePtr->affineAnims = sSpriteAffineAnimTable_85F04FC;
+ pokeblockFeed->monSpritePtr->affineAnims = sAffineAnims_Mon;
InitSpriteAffineAnim(pokeblockFeed->monSpritePtr);
}
- pokeblockFeed->field_1050 = 50;
+ pokeblockFeed->animRunState = 50;
case 50:
- if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != 0)
+ if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != AFFINE_NONE)
{
+ // Start affine anim
if (!pokeblockFeed->noMonFlip) // double negation, so mon's sprite is flipped
- StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] + 10);
+ StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] + NUM_MON_AFFINES);
else
StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1]);
}
- pokeblockFeed->field_1050 = 60;
+ pokeblockFeed->animRunState = 60;
break;
case 60:
- if (sub_817A9E4() == TRUE)
+ if (DoMonAnimStep() == TRUE)
{
- if (pokeblockFeed->field_1060[9] == 0)
+ if (!pokeblockFeed->animData[ANIMDATA_IS_LAST])
{
+ // Continue to next stage of animation
pokeblockFeed->animId++;
- sub_817A91C();
- pokeblockFeed->field_1050 = 60;
+ InitMonAnimStage();
+ pokeblockFeed->animRunState = 60;
}
else
{
+ // End animation
FreeOamMatrix(pokeblockFeed->monSpritePtr->oam.matrixNum);
- pokeblockFeed->field_1050 = 70;
+ pokeblockFeed->animRunState = 70;
}
}
break;
case 70:
FreeMonSpriteOamMatrix();
pokeblockFeed->animId = 0;
- pokeblockFeed->field_1050 = 0;
+ pokeblockFeed->animRunState = 0;
break;
case 71 ... 90:
break;
}
}
-static bool8 sub_817A91C(void)
+static bool8 InitMonAnimStage(void)
{
- struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
u8 i;
- for (i = 0; i < 10; i++)
- pokeblockFeed->field_1060[i] = sMonPokeblockAnims[pokeblockFeed->animId][i];
+ for (i = 0; i < NUM_ANIMDATA; i++)
+ pokeblockFeed->animData[i] = sMonPokeblockAnims[pokeblockFeed->animId][i];
- if (pokeblockFeed->field_1060[4] == 0)
+ if (pokeblockFeed->animData[ANIMDATA_TIME] == 0)
{
return TRUE;
}
else
{
- pokeblockFeed->field_1060[10] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2]);
- pokeblockFeed->field_1060[11] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3]);
- pokeblockFeed->field_1060[12] = pokeblockFeed->field_1060[4];
- pokeblockFeed->field_1060[13] = pokeblockFeed->monSpritePtr->pos2.x;
- pokeblockFeed->field_1060[14] = pokeblockFeed->monSpritePtr->pos2.y;
- sub_817AB68();
- pokeblockFeed->field_1060[4] = pokeblockFeed->field_1060[12];
- sub_817AA54();
- pokeblockFeed->field_1060[4] = pokeblockFeed->field_1060[12];
+ pokeblockFeed->monInitX = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX], pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE]);
+ pokeblockFeed->monInitY = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX], pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE]);
+ pokeblockFeed->maxAnimStageTime = pokeblockFeed->animData[ANIMDATA_TIME];
+ pokeblockFeed->monX = pokeblockFeed->monSpritePtr->pos2.x;
+ pokeblockFeed->monY = pokeblockFeed->monSpritePtr->pos2.y;
+
+ // Calculate the positions to move to during the animation
+ // The time is counted down during this, so reset it afterwards
+ CalculateMonAnimMovement();
+ pokeblockFeed->animData[ANIMDATA_TIME] = pokeblockFeed->maxAnimStageTime;
+ CalculateMonAnimMovementEnd();
+ pokeblockFeed->animData[ANIMDATA_TIME] = pokeblockFeed->maxAnimStageTime; // Redundant
return FALSE;
}
}
-static bool8 sub_817A9E4(void)
+static bool8 DoMonAnimStep(void)
{
- u16 var = sPokeblockFeed->field_1060[12] - sPokeblockFeed->field_1060[4];
-
- sPokeblockFeed->monSpritePtr->pos2.x = sPokeblockFeed->field_850[var];
- sPokeblockFeed->monSpritePtr->pos2.y = sPokeblockFeed->field_C50[var];
-
- if (--sPokeblockFeed->field_1060[4] == 0)
+ // Update mon's position
+ u16 time = sPokeblockFeed->maxAnimStageTime - sPokeblockFeed->animData[ANIMDATA_TIME];
+ sPokeblockFeed->monSpritePtr->pos2.x = sPokeblockFeed->monAnimX[time];
+ sPokeblockFeed->monSpritePtr->pos2.y = sPokeblockFeed->monAnimY[time];
+
+ // Count down time remaining in this stage
+ // Return TRUE if this stage is complete
+ if (--sPokeblockFeed->animData[ANIMDATA_TIME] == 0)
return TRUE;
else
return FALSE;
@@ -1035,66 +1128,70 @@ static bool8 FreeMonSpriteOamMatrix(void)
return FALSE;
}
-static void sub_817AA54(void)
+static void CalculateMonAnimMovementEnd(void)
{
- struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
u16 i;
- u16 r8 = pokeblockFeed->field_1060[8];
- u16 r7 = pokeblockFeed->field_1060[12] - r8;
- s16 var3 = pokeblockFeed->field_1060[13] + pokeblockFeed->field_1060[6];
- s16 r9 = pokeblockFeed->field_1060[14] + pokeblockFeed->field_1060[7];
+ u16 approachTime = pokeblockFeed->animData[ANIMDATA_APPR_TIME];
+ u16 time = pokeblockFeed->maxAnimStageTime - approachTime;
+ s16 x = pokeblockFeed->monX + pokeblockFeed->animData[ANIMDATA_TARGET_X];
+ s16 y = pokeblockFeed->monY + pokeblockFeed->animData[ANIMDATA_TARGET_Y];
- for (i = 0; i < r7 - 1; i++)
+ for (i = 0; i < time - 1; i++)
{
- s16 r1 = pokeblockFeed->field_850[r8 + i] - (var3);
- s16 r4 = pokeblockFeed->field_C50[r8 + i] - r9;
+ s16 xOffset = pokeblockFeed->monAnimX[approachTime + i] - x;
+ s16 yOffset = pokeblockFeed->monAnimY[approachTime + i] - y;
- pokeblockFeed->field_850[r8 + i] -= r1 * (i + 1) / r7;
- pokeblockFeed->field_C50[r8 + i] -= r4 * (i + 1) / r7;
+ pokeblockFeed->monAnimX[approachTime + i] -= xOffset * (i + 1) / time;
+ pokeblockFeed->monAnimY[approachTime + i] -= yOffset * (i + 1) / time;
}
- pokeblockFeed->field_850[(r8 + r7) - 1] = var3;
- pokeblockFeed->field_C50[(r8 + r7) - 1] = r9;
+ pokeblockFeed->monAnimX[approachTime + time - 1] = x;
+ pokeblockFeed->monAnimY[approachTime + time - 1] = y;
}
-static void sub_817AB68(void)
+static void CalculateMonAnimMovement(void)
{
- struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
- bool8 var_24 = FALSE;
- s16 r8 = pokeblockFeed->field_1060[13] - pokeblockFeed->field_1060[10];
- s16 r7 = pokeblockFeed->field_1060[14] - pokeblockFeed->field_1060[11];
+ struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
+ bool8 negative = FALSE;
+ s16 x = pokeblockFeed->monX - pokeblockFeed->monInitX;
+ s16 y = pokeblockFeed->monY - pokeblockFeed->monInitY;
while (1)
{
- u16 r5;
- u16 r4;
- u16 var;
+ u16 amplitude;
+ u16 time;
+ u16 acceleration;
- var = abs(pokeblockFeed->field_1060[5]);
- r5 = var + pokeblockFeed->field_1060[3];
- pokeblockFeed->field_1060[3] = r5;
+ acceleration = abs(pokeblockFeed->animData[ANIMDATA_ROT_ACCEL]);
+ amplitude = acceleration + pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE];
+ pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] = amplitude;
- if (pokeblockFeed->field_1060[2] < 0)
- var_24 = TRUE;
+ if (pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] < 0)
+ negative = TRUE;
- r4 = pokeblockFeed->field_1060[12] - pokeblockFeed->field_1060[4];
+ time = pokeblockFeed->maxAnimStageTime - pokeblockFeed->animData[ANIMDATA_TIME];
- if (pokeblockFeed->field_1060[4] == 0)
+ if (pokeblockFeed->animData[ANIMDATA_TIME] == 0)
break;
- if (!var_24)
+ if (!negative)
{
- pokeblockFeed->field_850[r4] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2] + r5 / 0x100) + r8;
- pokeblockFeed->field_C50[r4] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3] + r5 / 0x100) + r7;
+ pokeblockFeed->monAnimX[time] = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
+ pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] + amplitude / 0x100) + x;
+ pokeblockFeed->monAnimY[time] = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
+ pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] + amplitude / 0x100) + y;
}
else
{
- pokeblockFeed->field_850[r4] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2] - r5 / 0x100) + r8;
- pokeblockFeed->field_C50[r4] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3] - r5 / 0x100) + r7;
+ pokeblockFeed->monAnimX[time] = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
+ pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] - amplitude / 0x100) + x;
+ pokeblockFeed->monAnimY[time] = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
+ pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] - amplitude / 0x100) + y;
}
- pokeblockFeed->field_1060[0] += pokeblockFeed->field_1060[1];
- pokeblockFeed->field_1060[0] &= 0xFF;
- pokeblockFeed->field_1060[4]--;
+ pokeblockFeed->animData[ANIMDATA_ROT_IDX] += pokeblockFeed->animData[ANIMDATA_ROT_SPEED];
+ pokeblockFeed->animData[ANIMDATA_ROT_IDX] &= 0xFF;
+ pokeblockFeed->animData[ANIMDATA_TIME]--;
}
}
diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c
index cfaec6f18..669b6ab25 100644
--- a/src/use_pokeblock.c
+++ b/src/use_pokeblock.c
@@ -708,7 +708,7 @@ static void FeedPokeblockToMon(void)
FREE_AND_SET_NULL(sMenu);
FreeAllWindowBuffers();
gMain.savedCallback = CB2_ReturnAndChooseMonToGivePokeblock;
- CB2_PreparePokeblockFeedScene();
+ PreparePokeblockFeedScene();
}
break;
}