diff --git a/graphics/interface/85DFC0C.bin b/graphics/pokeblock/use_screen/graph_data.bin similarity index 100% rename from graphics/interface/85DFC0C.bin rename to graphics/pokeblock/use_screen/graph_data.bin diff --git a/graphics/interface/85DFB60.bin b/graphics/pokeblock/use_screen/mon_frame.bin similarity index 100% rename from graphics/interface/85DFB60.bin rename to graphics/pokeblock/use_screen/mon_frame.bin diff --git a/graphics/interface/85DFA80.png b/graphics/pokeblock/use_screen/mon_frame.png similarity index 100% rename from graphics/interface/85DFA80.png rename to graphics/pokeblock/use_screen/mon_frame.png diff --git a/graphics/interface/85DFA60.bin b/graphics/pokeblock/use_screen/mon_frame_pal.bin similarity index 100% rename from graphics/interface/85DFA60.bin rename to graphics/pokeblock/use_screen/mon_frame_pal.bin diff --git a/graphics/pokenav/cancel.pal b/graphics/pokenav/condition/cancel.pal similarity index 100% rename from graphics/pokenav/cancel.pal rename to graphics/pokenav/condition/cancel.pal diff --git a/graphics/pokenav/cancel.png b/graphics/pokenav/condition/cancel.png similarity index 100% rename from graphics/pokenav/cancel.png rename to graphics/pokenav/condition/cancel.png diff --git a/graphics/pokenav/condition.bin b/graphics/pokenav/condition/graph.bin similarity index 100% rename from graphics/pokenav/condition.bin rename to graphics/pokenav/condition/graph.bin diff --git a/graphics/pokenav/condition.png b/graphics/pokenav/condition/graph.png similarity index 100% rename from graphics/pokenav/condition.png rename to graphics/pokenav/condition/graph.png diff --git a/graphics/pokenav/86231E8.pal b/graphics/pokenav/condition/graph_data.pal similarity index 100% rename from graphics/pokenav/86231E8.pal rename to graphics/pokenav/condition/graph_data.pal diff --git a/graphics/pokenav/marker.png b/graphics/pokenav/condition/marker.png similarity index 100% rename from graphics/pokenav/marker.png rename to graphics/pokenav/condition/marker.png diff --git a/graphics/pokenav/pokeball.png b/graphics/pokenav/condition/pokeball.png similarity index 100% rename from graphics/pokenav/pokeball.png rename to graphics/pokenav/condition/pokeball.png diff --git a/graphics/pokenav/pokeball_placeholder.png b/graphics/pokenav/condition/pokeball_placeholder.png similarity index 100% rename from graphics/pokenav/pokeball_placeholder.png rename to graphics/pokenav/condition/pokeball_placeholder.png diff --git a/graphics/pokenav/sparkle.png b/graphics/pokenav/condition/sparkle.png similarity index 100% rename from graphics/pokenav/sparkle.png rename to graphics/pokenav/condition/sparkle.png diff --git a/graphics/pokenav/8623208.pal b/graphics/pokenav/condition/text.pal similarity index 100% rename from graphics/pokenav/8623208.pal rename to graphics/pokenav/condition/text.pal diff --git a/include/menu_specialized.h b/include/menu_specialized.h index 14a246468..242e1c6b2 100644 --- a/include/menu_specialized.h +++ b/include/menu_specialized.h @@ -5,6 +5,15 @@ #include "player_pc.h" #include "list_menu.h" #include "pokemon.h" +#include "constants/berry.h" + +#define TAG_CONDITION_MON 100 +#define TAG_CONDITION_BALL 101 +#define TAG_CONDITION_CANCEL 102 +#define TAG_CONDITION_BALL_PLACEHOLDER 103 +#define TAG_CONDITION_SPARKLE 104 + +#define MAX_CONDITION_SPARKLES 10 struct UnknownSubStruct_81D1ED4 { @@ -12,12 +21,12 @@ struct UnknownSubStruct_81D1ED4 u16 unk2; }; -struct UnknownStruct_81D1ED4 +struct ConditionGraph { - /*0x000*/ u8 unk0[4][5]; - /*0x014*/ struct UnknownSubStruct_81D1ED4 unk14[4][5]; - /*0x064*/ struct UnknownSubStruct_81D1ED4 unk64[10][5]; - /*0x12C*/ struct UnknownSubStruct_81D1ED4 unk12C[5]; + /*0x000*/ u8 unk0[4][FLAVOR_COUNT]; + /*0x014*/ struct UnknownSubStruct_81D1ED4 unk14[4][FLAVOR_COUNT]; + /*0x064*/ struct UnknownSubStruct_81D1ED4 unk64[10][FLAVOR_COUNT]; + /*0x12C*/ struct UnknownSubStruct_81D1ED4 unk12C[FLAVOR_COUNT]; /*0x140*/ u16 unk140[66][2]; /*0x248*/ u16 unk248[66][2]; /*0x350*/ u16 unk350; @@ -32,35 +41,35 @@ u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page); void sub_81D1E90(struct PlayerPCItemPageStruct *page); void sub_81D1EC0(void); void sub_81D1D04(u8 a0); -void sub_81D1ED4(struct UnknownStruct_81D1ED4 *a0); -void sub_81D2108(struct UnknownStruct_81D1ED4 *arg0); +void sub_81D1ED4(struct ConditionGraph *graph); +void sub_81D2108(struct ConditionGraph *graph); void sub_81D21DC(u8 bg); -void sub_81D20AC(struct UnknownStruct_81D1ED4 *arg0); -void sub_81D2230(struct UnknownStruct_81D1ED4 *arg0); -bool8 sub_81D20BC(struct UnknownStruct_81D1ED4 *arg0); -bool32 sub_81D2074(struct UnknownStruct_81D1ED4 *a0); +void sub_81D20AC(struct ConditionGraph *graph); +void sub_81D2230(struct ConditionGraph *graph); +bool8 sub_81D20BC(struct ConditionGraph *graph); +bool32 TransitionConditionGraph(struct ConditionGraph *graph); void sub_81D2754(u8 *arg0, struct UnknownSubStruct_81D1ED4 *arg1); -void sub_81D1F84(struct UnknownStruct_81D1ED4 *arg0, struct UnknownSubStruct_81D1ED4 *arg1, struct UnknownSubStruct_81D1ED4 *arg2); +void sub_81D1F84(struct ConditionGraph *graph, struct UnknownSubStruct_81D1ED4 *arg1, struct UnknownSubStruct_81D1ED4 *arg2); void MoveRelearnerPrintText(u8 *str); bool16 MoveRelearnerRunTextPrinters(void); void MoveRelearnerCreateYesNoMenu(void); u8 LoadMoveRelearnerMovesList(const struct ListMenuItem *items, u16 numChoices); void InitMoveRelearnerWindows(bool8 useContextWindow); s32 GetBoxOrPartyMonData(u16 boxId, u16 monId, s32 request, u8 *dst); -void sub_81D2ED4(u8 *dst, u8 *nameDst, u16 boxId, u16 monId, u16 arg5, u16 arg6, bool8 arg7); -void sub_81D2F78(struct UnknownStruct_81D1ED4 *arg0, u8 *sheen, u16 boxId, u16 monId, u16 arg5, u16 id, u16 arg7, bool8 arg8); -void sub_81D3094(void *tilesDst, void *palDst, u16 boxId, u16 monId, u16 arg5, u16 arg6, bool8 arg7); -bool8 sub_81D312C(s16 *var); -bool8 sub_81D3150(s16 *var); -bool8 sub_81D3178(struct UnknownStruct_81D1ED4 *arg0, s16 *arg1); -bool8 sub_81D31A4(struct UnknownStruct_81D1ED4 *arg0, s16 *arg1); -void sub_81D31D0(struct SpriteSheet *sheet, struct SpriteTemplate *template, struct SpritePalette *pal); -void sub_81D321C(struct SpriteSheet *sheets, struct SpriteTemplate * template, struct SpritePalette *pals); -void sub_81D32B0(struct SpriteSheet *sheet, struct SpritePalette *pal); -void sub_81D3464(struct Sprite **sprites); -void sub_81D3480(struct Sprite **sprites, u8 arg1, u8 arg2); -void sub_81D3520(struct Sprite **sprites); -void sub_81D354C(struct Sprite **sprites); +void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId, u16 monId, u16 partyId, u16 numMons, bool8 excludesCancel); +void GetConditionMenuMonConditions(struct ConditionGraph *graph, u8 *sheen, u16 boxId, u16 monId, u16 partyId, u16 id, u16 numMons, bool8 excludesCancel); +void GetConditionMenuMonGfx(void *tilesDst, void *palDst, u16 boxId, u16 monId, u16 partyId, u16 numMons, bool8 excludesCancel); +bool8 MoveConditionMonOnscreen(s16 *x); +bool8 MoveConditionMonOffscreen(s16 *x); +bool8 TryUpdateConditionMonTransitionOn(struct ConditionGraph *graph, s16 *x); +bool8 TryUpdateConditionMonTransitionOff(struct ConditionGraph *graph, s16 *x); +void LoadConditionMonPicTemplate(struct SpriteSheet *sheet, struct SpriteTemplate *template, struct SpritePalette *pal); +void LoadConditionSelectionIcons(struct SpriteSheet *sheets, struct SpriteTemplate * template, struct SpritePalette *pals); +void LoadConditionSparkle(struct SpriteSheet *sheet, struct SpritePalette *pal); +void ResetConditionSparkleSprites(struct Sprite **sprites); +void CreateConditionSparkleSprites(struct Sprite **sprites, u8 monSpriteId, u8 count); +void DestroyConditionSparkleSprites(struct Sprite **sprites); +void FreeConditionSparkles(struct Sprite **sprites); void DrawLevelUpWindowPg1(u16 windowId, u16 *statsBefore, u16 *statsAfter, u8 bgClr, u8 fgClr, u8 shadowClr); void DrawLevelUpWindowPg2(u16 windowId, u16 *currStats, u8 bgClr, u8 fgClr, u8 shadowClr); void GetMonLevelUpWindowStats(struct Pokemon *mon, u16 *currStats); diff --git a/include/pokenav.h b/include/pokenav.h index 3eafe9af2..ac916f3ba 100644 --- a/include/pokenav.h +++ b/include/pokenav.h @@ -391,7 +391,7 @@ u32 sub_81CD070(void); void sub_81CD1C0(void); bool32 sub_81CD3C4(void); bool32 sub_81CDD5C(void); -struct UnknownStruct_81D1ED4 *sub_81CDC70(void); +struct ConditionGraph *sub_81CDC70(void); u16 sub_81CDC60(void); u16 sub_81CDC50(void); u8 sub_81CDDB0(void); diff --git a/src/graphics.c b/src/graphics.c index 18734c1b2..e0b2774d6 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1313,10 +1313,9 @@ const u16 gContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_scree // pokenav -const u16 gPokenavCondition_Pal[] = INCBIN_U16("graphics/pokenav/condition.gbapal"); - -const u32 gPokenavCondition_Gfx[] = INCBIN_U32("graphics/pokenav/condition.4bpp.lz"); -const u32 gPokenavCondition_Tilemap[] = INCBIN_U32("graphics/pokenav/condition.bin.lz"); +const u16 gPokenavCondition_Pal[] = INCBIN_U16("graphics/pokenav/condition/graph.gbapal"); +const u32 gPokenavCondition_Gfx[] = INCBIN_U32("graphics/pokenav/condition/graph.4bpp.lz"); +const u32 gPokenavCondition_Tilemap[] = INCBIN_U32("graphics/pokenav/condition/graph.bin.lz"); const u16 gPokenavOptions_Tilemap[] = INCBIN_U16("graphics/pokenav/options/options.bin"); const u32 gPokenavOptions_Gfx[] = INCBIN_U32("graphics/pokenav/options/options.4bpp.lz"); @@ -1347,11 +1346,11 @@ const u32 gPokenavMessageBox_Tilemap[] = INCBIN_U32("graphics/pokenav/message.bi const u16 gRegionMapCityZoomTiles_Pal[] = INCBIN_U16("graphics/pokenav/zoom_tiles.gbapal"); const u32 gRegionMapCityZoomText_Gfx[] = INCBIN_U32("graphics/pokenav/city_zoom_text.4bpp.lz"); -const u16 gPokenavConditionCancel_Pal[] = INCBIN_U16("graphics/pokenav/cancel.gbapal"); -const u8 gPokenavConditionCancel_Gfx[] = INCBIN_U8("graphics/pokenav/cancel.4bpp"); +const u16 gPokenavConditionCancel_Pal[] = INCBIN_U16("graphics/pokenav/condition/cancel.gbapal"); +const u8 gPokenavConditionCancel_Gfx[] = INCBIN_U8("graphics/pokenav/condition/cancel.4bpp"); -const u16 gPokenavConditionMarker_Pal[] = INCBIN_U16("graphics/pokenav/marker.gbapal"); -const u8 gPokenavConditionMarker_Gfx[] = INCBIN_U8("graphics/pokenav/marker.4bpp"); +const u16 gPokenavConditionMarker_Pal[] = INCBIN_U16("graphics/pokenav/condition/marker.gbapal"); +const u8 gPokenavConditionMarker_Gfx[] = INCBIN_U8("graphics/pokenav/condition/marker.4bpp"); const u16 gBerryBlenderMiscPalette[] = INCBIN_U16("graphics/berry_blender/misc.gbapal"); diff --git a/src/menu_specialized.c b/src/menu_specialized.c index ecef9982b..a99c5c9d0 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -23,6 +23,7 @@ #include "text_window.h" #include "trig.h" #include "window.h" +#include "constants/berry.h" #include "constants/songs.h" #include "constants/species.h" #include "gba/io_reg.h" @@ -33,13 +34,13 @@ EWRAM_DATA static u8 sUnknown_0203CF48[3] = {0}; EWRAM_DATA static struct ListMenuItem *sUnknown_0203CF4C = NULL; static void sub_81D1E7C(s32 itemIndex, bool8 onInit, struct ListMenu *list); -static void sub_81D24A4(struct UnknownStruct_81D1ED4 *a0); -static void sub_81D2634(struct UnknownStruct_81D1ED4 *a0); +static void sub_81D24A4(struct ConditionGraph *a0); +static void sub_81D2634(struct ConditionGraph *a0); static void MoveRelearnerCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list); static void nullsub_79(void); -static void sub_81D3408(struct Sprite *sprite); -static void sub_81D3564(struct Sprite *sprite); -static void sub_81D35E8(struct Sprite *sprite); +static void SetNextConditionSparkle(struct Sprite *sprite); +static void SpriteCB_ConditionSparkle(struct Sprite *sprite); +static void ShowAllConditionSparkles(struct Sprite *sprite); static const struct WindowTemplate sUnknown_086253E8[] = { @@ -79,7 +80,7 @@ static const u8 sPlayerNameTextColors[] = static const u8 sEmptyItemName[] = _(""); -static const struct ScanlineEffectParams sUnknown_08625404 = +static const struct ScanlineEffectParams sConditionGraphScanline = { .dmaDest = (void*)REG_ADDR_WIN0H, .dmaControl = SCANLINE_EFFECT_DMACNT_32BIT, @@ -319,11 +320,11 @@ void sub_81D1EC0(void) Free(sUnknown_0203CF4C); } -void sub_81D1ED4(struct UnknownStruct_81D1ED4 *a0) +void sub_81D1ED4(struct ConditionGraph *a0) { u8 i, j; - for (j = 0; j < 5; j++) + for (j = 0; j < FLAVOR_COUNT; j++) { for (i = 0; i < 10; i++) { @@ -345,7 +346,7 @@ void sub_81D1ED4(struct UnknownStruct_81D1ED4 *a0) a0->unk352 = 0; } -void sub_81D1F84(struct UnknownStruct_81D1ED4 *arg0, struct UnknownSubStruct_81D1ED4 *arg1, struct UnknownSubStruct_81D1ED4 *arg2) +void sub_81D1F84(struct ConditionGraph *graph, struct UnknownSubStruct_81D1ED4 *arg1, struct UnknownSubStruct_81D1ED4 *arg2) { u16 i, j; s32 r5, r6; @@ -356,30 +357,30 @@ void sub_81D1F84(struct UnknownStruct_81D1ED4 *arg0, struct UnknownSubStruct_81D r6 = ((arg2[i].unk0 - arg1[i].unk0) << 8) / 10; for (j = 0; j < 9; j++) { - arg0->unk64[j][i].unk0 = (r5 >> 8) + ((r5 >> 7) & 1); + graph->unk64[j][i].unk0 = (r5 >> 8) + ((r5 >> 7) & 1); r5 += r6; } - arg0->unk64[j][i].unk0 = arg2[i].unk0; + graph->unk64[j][i].unk0 = arg2[i].unk0; r5 = arg1[i].unk2 << 8; r6 = ((arg2[i].unk2 - arg1[i].unk2) << 8) / 10; for (j = 0; j < 9; j++) { - arg0->unk64[j][i].unk2 = (r5 >> 8) + ((r5 >> 7) & 1); + graph->unk64[j][i].unk2 = (r5 >> 8) + ((r5 >> 7) & 1); r5 += r6; } - arg0->unk64[j][i].unk2 = arg2[i].unk2; + graph->unk64[j][i].unk2 = arg2[i].unk2; } - arg0->unk352 = 0; + graph->unk352 = 0; } -bool32 sub_81D2074(struct UnknownStruct_81D1ED4 *a0) +bool32 TransitionConditionGraph(struct ConditionGraph *graph) { - if (a0->unk352 < 10) + if (graph->unk352 < 10) { - sub_81D2230(a0); - return (++a0->unk352 != 10); + sub_81D2230(graph); + return (++graph->unk352 != 10); } else { @@ -387,48 +388,48 @@ bool32 sub_81D2074(struct UnknownStruct_81D1ED4 *a0) } } -void sub_81D20AC(struct UnknownStruct_81D1ED4 *a0) +void sub_81D20AC(struct ConditionGraph *a0) { a0->unk355 = 0; } -bool8 sub_81D20BC(struct UnknownStruct_81D1ED4 *arg0) +bool8 sub_81D20BC(struct ConditionGraph *graph) { struct ScanlineEffectParams params; - switch (arg0->unk355) + switch (graph->unk355) { case 0: ScanlineEffect_Clear(); - arg0->unk355++; + graph->unk355++; return TRUE; case 1: - params = sUnknown_08625404; + params = sConditionGraphScanline; ScanlineEffect_SetParams(params); - arg0->unk355++; + graph->unk355++; return FALSE; default: return FALSE; } } -void sub_81D2108(struct UnknownStruct_81D1ED4 *arg0) +void sub_81D2108(struct ConditionGraph *graph) { u16 i; - if (arg0->unk354 == 0) + if (graph->unk354 == 0) return; - sub_81D24A4(arg0); - sub_81D2634(arg0); + sub_81D24A4(graph); + sub_81D2634(graph); for (i = 0; i < 66; i++) { - gScanlineEffectRegBuffers[1][(i + 55) * 2] = gScanlineEffectRegBuffers[0][(i + 55) * 2] = (arg0->unk140[i][0] << 8) | (arg0->unk140[i][1]); - gScanlineEffectRegBuffers[1][(i + 55) * 2 + 1] = gScanlineEffectRegBuffers[0][(i + 55) * 2 + 1] = (arg0->unk248[i][0] << 8) | (arg0->unk248[i][1]); + gScanlineEffectRegBuffers[1][(i + 55) * 2] = gScanlineEffectRegBuffers[0][(i + 55) * 2] = (graph->unk140[i][0] << 8) | (graph->unk140[i][1]); + gScanlineEffectRegBuffers[1][(i + 55) * 2 + 1] = gScanlineEffectRegBuffers[0][(i + 55) * 2 + 1] = (graph->unk248[i][0] << 8) | (graph->unk248[i][1]); } - arg0->unk354 = 0; + graph->unk354 = 0; } void sub_81D21DC(u8 bg) @@ -441,24 +442,24 @@ void sub_81D21DC(u8 bg) // Unset the WINOUT flag for the bg. flags = (WINOUT_WIN01_BG_ALL | WINOUT_WIN01_OBJ) & ~(1 << bg); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(0, 0xF0)); - SetGpuReg(REG_OFFSET_WIN1H, WIN_RANGE(0, 0x9B)); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(0x38, 0x79)); - SetGpuReg(REG_OFFSET_WIN1V, WIN_RANGE(0x38, 0x79)); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE( 0, DISPLAY_WIDTH)); + SetGpuReg(REG_OFFSET_WIN1H, WIN_RANGE( 0, 155)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(56, 121)); + SetGpuReg(REG_OFFSET_WIN1V, WIN_RANGE(56, 121)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN1_CLR); SetGpuReg(REG_OFFSET_WINOUT, flags); } -void sub_81D2230(struct UnknownStruct_81D1ED4 *arg0) +void sub_81D2230(struct ConditionGraph *graph) { u16 i; - for (i = 0; i < 5; i++) - arg0->unk12C[i] = arg0->unk64[arg0->unk352][i]; + for (i = 0; i < FLAVOR_COUNT; i++) + graph->unk12C[i] = graph->unk64[graph->unk352][i]; - arg0->unk354 = 1; + graph->unk354 = 1; } -static void sub_81D2278(struct UnknownStruct_81D1ED4 *arg0, u16 *arg1, struct UnknownSubStruct_81D1ED4 *arg2, struct UnknownSubStruct_81D1ED4 *arg3, u8 arg4, u16 *arg5) +static void sub_81D2278(struct ConditionGraph *graph, u16 *arg1, struct UnknownSubStruct_81D1ED4 *arg2, struct UnknownSubStruct_81D1ED4 *arg3, u8 arg4, u16 *arg5) { u16 i, r8, r10, r0, var_30; u16 *ptr; @@ -509,8 +510,8 @@ static void sub_81D2278(struct UnknownStruct_81D1ED4 *arg0, u16 *arg1, struct Un break; } - arg0->unk350 = r10 + i; - arg1 += (arg0->unk350 - 56) * 2; + graph->unk350 = r10 + i; + arg1 += (graph->unk350 - 56) * 2; for (; i < r8; i++) { arg1[arg4] = (r4 >> 10) + ((r4 >> 9) & 1) + arg4; @@ -535,8 +536,8 @@ static void sub_81D2278(struct UnknownStruct_81D1ED4 *arg0, u16 *arg1, struct Un arg1 += 2; } - arg0->unk350 = r10 + i; - arg5 += (arg0->unk350 - 56) * 2; + graph->unk350 = r10 + i; + arg5 += (graph->unk350 - 56) * 2; for (; i < r8; i++) { arg5[arg4] = (r4 >> 10) + ((r4 >> 9) & 1) + arg4; @@ -548,7 +549,7 @@ static void sub_81D2278(struct UnknownStruct_81D1ED4 *arg0, u16 *arg1, struct Un } else { - arg0->unk350 = r10; + graph->unk350 = r10; arg1 += (r10 - 56) * 2; arg5 += (r10 - 56) * 2; arg1[1] = arg2->unk0 + 1; @@ -560,87 +561,87 @@ static void sub_81D2278(struct UnknownStruct_81D1ED4 *arg0, u16 *arg1, struct Un ptr[arg4] = arg4 + var_30; } -static void sub_81D24A4(struct UnknownStruct_81D1ED4 *arg0) +static void sub_81D24A4(struct ConditionGraph *graph) { u16 i, r6, varMax; - if (arg0->unk12C[0].unk2 < arg0->unk12C[1].unk2) + if (graph->unk12C[0].unk2 < graph->unk12C[1].unk2) { - r6 = arg0->unk12C[0].unk2; - sub_81D2278(arg0, arg0->unk140[0], &arg0->unk12C[0], &arg0->unk12C[1], 1, NULL); + r6 = graph->unk12C[0].unk2; + sub_81D2278(graph, graph->unk140[0], &graph->unk12C[0], &graph->unk12C[1], 1, NULL); } else { - r6 = arg0->unk12C[1].unk2; - sub_81D2278(arg0, arg0->unk140[0], &arg0->unk12C[1], &arg0->unk12C[0], 0, NULL); + r6 = graph->unk12C[1].unk2; + sub_81D2278(graph, graph->unk140[0], &graph->unk12C[1], &graph->unk12C[0], 0, NULL); } - sub_81D2278(arg0, arg0->unk140[0], &arg0->unk12C[1], &arg0->unk12C[2], 1, NULL); + sub_81D2278(graph, graph->unk140[0], &graph->unk12C[1], &graph->unk12C[2], 1, NULL); - i = (arg0->unk12C[2].unk2 <= arg0->unk12C[3].unk2); - sub_81D2278(arg0, arg0->unk140[0], &arg0->unk12C[2], &arg0->unk12C[3], i, arg0->unk248[0]); + i = (graph->unk12C[2].unk2 <= graph->unk12C[3].unk2); + sub_81D2278(graph, graph->unk140[0], &graph->unk12C[2], &graph->unk12C[3], i, graph->unk248[0]); for (i = 56; i < r6; i++) { - arg0->unk140[i - 56][0] = 0; - arg0->unk140[i - 56][1] = 0; + graph->unk140[i - 56][0] = 0; + graph->unk140[i - 56][1] = 0; } - for (i = arg0->unk12C[0].unk2; i <= arg0->unk350; i++) - arg0->unk140[i - 56][0] = 155; + for (i = graph->unk12C[0].unk2; i <= graph->unk350; i++) + graph->unk140[i - 56][0] = 155; - varMax = max(arg0->unk350, arg0->unk12C[2].unk2); + varMax = max(graph->unk350, graph->unk12C[2].unk2); for (i = varMax + 1; i < 122; i++) { - arg0->unk140[i - 56][0] = 0; - arg0->unk140[i - 56][1] = 0; + graph->unk140[i - 56][0] = 0; + graph->unk140[i - 56][1] = 0; } for (i = 56; i < 122; i++) { - if (arg0->unk140[i - 56][0] == 0 && arg0->unk140[i - 56][1] != 0) - arg0->unk140[i - 56][0] = 155; + if (graph->unk140[i - 56][0] == 0 && graph->unk140[i - 56][1] != 0) + graph->unk140[i - 56][0] = 155; } } -static void sub_81D2634(struct UnknownStruct_81D1ED4 *arg0) +static void sub_81D2634(struct ConditionGraph *graph) { s32 i, r6, varMax; - if (arg0->unk12C[0].unk2 < arg0->unk12C[4].unk2) + if (graph->unk12C[0].unk2 < graph->unk12C[4].unk2) { - r6 = arg0->unk12C[0].unk2; - sub_81D2278(arg0, arg0->unk248[0], &arg0->unk12C[0], &arg0->unk12C[4], 0, NULL); + r6 = graph->unk12C[0].unk2; + sub_81D2278(graph, graph->unk248[0], &graph->unk12C[0], &graph->unk12C[4], 0, NULL); } else { - r6 = arg0->unk12C[4].unk2; - sub_81D2278(arg0, arg0->unk248[0], &arg0->unk12C[4], &arg0->unk12C[0], 1, NULL); + r6 = graph->unk12C[4].unk2; + sub_81D2278(graph, graph->unk248[0], &graph->unk12C[4], &graph->unk12C[0], 1, NULL); } - sub_81D2278(arg0, arg0->unk248[0], &arg0->unk12C[4], &arg0->unk12C[3], 0, NULL); + sub_81D2278(graph, graph->unk248[0], &graph->unk12C[4], &graph->unk12C[3], 0, NULL); for (i = 56; i < r6; i++) { - arg0->unk140[i + 10][0] = 0; - arg0->unk140[i + 10][1] = 0; + graph->unk140[i + 10][0] = 0; + graph->unk140[i + 10][1] = 0; } - for (i = arg0->unk12C[0].unk2; i <= arg0->unk350; i++) - arg0->unk140[i + 10][1] = 155; + for (i = graph->unk12C[0].unk2; i <= graph->unk350; i++) + graph->unk140[i + 10][1] = 155; - varMax = max(arg0->unk350, arg0->unk12C[3].unk2 + 1); + varMax = max(graph->unk350, graph->unk12C[3].unk2 + 1); for (i = varMax; i < 122; i++) { - arg0->unk140[i + 10][0] = 0; - arg0->unk140[i + 10][1] = 0; + graph->unk140[i + 10][0] = 0; + graph->unk140[i + 10][1] = 0; } for (i = 0; i < 66; i++) { - if (arg0->unk248[i][0] >= arg0->unk248[i][1]) + if (graph->unk248[i][0] >= graph->unk248[i][1]) { - arg0->unk248[i][1] = 0; - arg0->unk248[i][0] = 0; + graph->unk248[i][1] = 0; + graph->unk248[i][0] = 0; } } } @@ -877,7 +878,8 @@ s32 GetBoxOrPartyMonData(u16 boxId, u16 monId, s32 request, u8 *dst) return ret; } -static u8 *sub_81D2CD0(u8 *dst, u16 boxId, u16 monId) +// Gets the name/gender/level string for the condition menu +static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) { u16 species, level, gender; struct BoxPokemon *boxMon; @@ -964,7 +966,8 @@ static u8 *sub_81D2CD0(u8 *dst, u16 boxId, u16 monId) } } -static u8 *sub_81D2E7C(u8 *dst, const u8 *src, s16 n) +// Buffers the string in src to dest up to n chars. If src is less than n chars, fill with spaces +static u8 *BufferConditionMenuSpacedStringN(u8 *dst, const u8 *src, s16 n) { while (*src != EOS) { @@ -978,80 +981,83 @@ static u8 *sub_81D2E7C(u8 *dst, const u8 *src, s16 n) return dst; } -void sub_81D2ED4(u8 *dst, u8 *nameDst, u16 boxId, u16 monId, u16 arg5, u16 arg6, bool8 arg7) +void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId, u16 monId, u16 partyId, u16 numMons, bool8 excludesCancel) { u16 i; - if (!arg7) - arg6--; + // In this and the below 2 functions, numMons is passed as the number of menu selections (which includes Cancel) + // To indicate that the Cancel needs to be subtracted they pass an additional bool + // Unclear why they didn't just subtract 1 when it gets passed instead + if (!excludesCancel) + numMons--; - if (arg5 != arg6) + if (partyId != numMons) { - sub_81D2CD0(nameDst, boxId, monId); - dst[0] = EXT_CTRL_CODE_BEGIN; - dst[1] = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - dst[2] = TEXT_COLOR_BLUE; - dst[3] = TEXT_COLOR_TRANSPARENT; - dst[4] = TEXT_COLOR_LIGHT_BLUE; + GetConditionMenuMonString(nameDst, boxId, monId); + locationDst[0] = EXT_CTRL_CODE_BEGIN; + locationDst[1] = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + locationDst[2] = TEXT_COLOR_BLUE; + locationDst[3] = TEXT_COLOR_TRANSPARENT; + locationDst[4] = TEXT_COLOR_LIGHT_BLUE; if (boxId == TOTAL_BOXES_COUNT) // Party mon. { - sub_81D2E7C(dst + 5, gText_InParty, 8); + BufferConditionMenuSpacedStringN(&locationDst[5], gText_InParty, 8); } else { boxId++;boxId--; // Again...Someone fix this maybe? - sub_81D2E7C(dst + 5, GetBoxNamePtr(boxId), 8); + BufferConditionMenuSpacedStringN(&locationDst[5], GetBoxNamePtr(boxId), 8); } } else { - for (i = 0; i < 12; i++) + for (i = 0; i < POKEMON_NAME_LENGTH + 2; i++) nameDst[i] = CHAR_SPACE; nameDst[i] = EOS; for (i = 0; i < 8; i++) - dst[i] = CHAR_SPACE; - dst[i] = EOS; + locationDst[i] = CHAR_SPACE; + locationDst[i] = EOS; } } -void sub_81D2F78(struct UnknownStruct_81D1ED4 *arg0, u8 *sheen, u16 boxId, u16 monId, u16 arg5, u16 id, u16 arg7, bool8 arg8) +void GetConditionMenuMonConditions(struct ConditionGraph *graph, u8 *sheen, u16 boxId, u16 monId, u16 partyId, u16 id, u16 numMons, bool8 excludesCancel) { u16 i; - if (!arg8) - arg7--; + if (!excludesCancel) + numMons--; - if (arg5 != arg7) + if (partyId != numMons) { - arg0->unk0[id][0] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_COOL, NULL); - arg0->unk0[id][1] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_TOUGH, NULL); - arg0->unk0[id][2] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SMART, NULL); - arg0->unk0[id][3] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_CUTE, NULL); - arg0->unk0[id][4] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_BEAUTY, NULL); + graph->unk0[id][0] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_COOL, NULL); + graph->unk0[id][1] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_TOUGH, NULL); + graph->unk0[id][2] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SMART, NULL); + graph->unk0[id][3] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_CUTE, NULL); + graph->unk0[id][4] = GetBoxOrPartyMonData(boxId, monId, MON_DATA_BEAUTY, NULL); sheen[id] = (GetBoxOrPartyMonData(boxId, monId, MON_DATA_SHEEN, NULL) != 0xFF) ? GetBoxOrPartyMonData(boxId, monId, MON_DATA_SHEEN, NULL) / 29u : 9; - sub_81D2754(arg0->unk0[id], arg0->unk14[id]); + sub_81D2754(graph->unk0[id], graph->unk14[id]); } else { - for (i = 0; i < 5; i++) + for (i = 0; i < FLAVOR_COUNT; i++) { - arg0->unk0[id][i] = 0; - arg0->unk14[id][i].unk0 = 155; - arg0->unk14[id][i].unk2 = 91; + graph->unk0[id][i] = 0; + graph->unk14[id][i].unk0 = 155; + graph->unk14[id][i].unk2 = 91; } } } -void sub_81D3094(void *tilesDst, void *palDst, u16 boxId, u16 monId, u16 arg5, u16 arg6, bool8 arg7) +void GetConditionMenuMonGfx(void *tilesDst, void *palDst, u16 boxId, u16 monId, u16 partyId, u16 numMons, bool8 excludesCancel) { - if (!arg7) - arg6--; + if (!excludesCancel) + numMons--; - if (arg5 != arg6) + if (partyId != numMons) { u16 species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES2, NULL); u32 trainerId = GetBoxOrPartyMonData(boxId, monId, MON_DATA_OT_ID, NULL); @@ -1062,46 +1068,46 @@ void sub_81D3094(void *tilesDst, void *palDst, u16 boxId, u16 monId, u16 arg5, u } } -bool8 sub_81D312C(s16 *var) +bool8 MoveConditionMonOnscreen(s16 *x) { - *var += 24; - if (*var > 0) - *var = 0; + *x += 24; + if (*x > 0) + *x = 0; - return (*var != 0); + return (*x != 0); } -bool8 sub_81D3150(s16 *var) +bool8 MoveConditionMonOffscreen(s16 *x) { - *var -= 24; - if (*var < -80) - *var = -80; + *x -= 24; + if (*x < -80) + *x = -80; - return (*var != -80); + return (*x != -80); } -bool8 sub_81D3178(struct UnknownStruct_81D1ED4 *arg0, s16 *arg1) +bool8 TryUpdateConditionMonTransitionOn(struct ConditionGraph *graph, s16 *x) { - bool8 var1 = sub_81D2074(arg0); - bool8 var2 = sub_81D312C(arg1); + bool8 graphUpdating = TransitionConditionGraph(graph); + bool8 monUpdating = MoveConditionMonOnscreen(x); - return ((var1 != 0) || (var2 != 0)); + return (graphUpdating || monUpdating); } -bool8 sub_81D31A4(struct UnknownStruct_81D1ED4 *arg0, s16 *arg1) +bool8 TryUpdateConditionMonTransitionOff(struct ConditionGraph *graph, s16 *x) { - bool8 var1 = sub_81D2074(arg0); - bool8 var2 = sub_81D3150(arg1); + bool8 graphUpdating = TransitionConditionGraph(graph); + bool8 monUpdating = MoveConditionMonOffscreen(x); - return ((var1 != 0) || (var2 != 0)); + return (graphUpdating || monUpdating); } -static const u32 gUnknown_08625560[] = INCBIN_U32("graphics/pokenav/pokeball.4bpp"); -static const u32 gUnknown_08625660[] = INCBIN_U32("graphics/pokenav/pokeball_placeholder.4bpp"); -static const u16 gUnknown_08625680[] = INCBIN_U16("graphics/pokenav/sparkle.gbapal"); -static const u32 gUnknown_086256A0[] = INCBIN_U32("graphics/pokenav/sparkle.4bpp"); +static const u32 sConditionPokeball_Gfx[] = INCBIN_U32("graphics/pokenav/condition/pokeball.4bpp"); +static const u32 sConditionPokeballPlaceholder_Gfx[] = INCBIN_U32("graphics/pokenav/condition/pokeball_placeholder.4bpp"); +static const u16 sConditionSparkle_Gfx[] = INCBIN_U16("graphics/pokenav/condition/sparkle.gbapal"); +static const u32 sConditionSparkle_Pal[] = INCBIN_U32("graphics/pokenav/condition/sparkle.4bpp"); -static const struct OamData sOamData_8625A20 = +static const struct OamData sOam_ConditionMonPic = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1118,7 +1124,7 @@ static const struct OamData sOamData_8625A20 = .affineParam = 0 }; -static const struct OamData sOamData_8625A28 = +static const struct OamData sOam_ConditionSelectionIcon = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1135,71 +1141,73 @@ static const struct OamData sOamData_8625A28 = .affineParam = 0 }; -static const union AnimCmd sSpriteAnim_8625A30[] = +static const union AnimCmd sAnim_ConditionSelectionIcon_Selected[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8625A38[] = +static const union AnimCmd sAnim_ConditionSelectionIcon_Unselected[] = { ANIMCMD_FRAME(4, 5), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_8625A40[] = +static const union AnimCmd *const sAnims_ConditionSelectionIcon[] = { - sSpriteAnim_8625A30, - sSpriteAnim_8625A38 + sAnim_ConditionSelectionIcon_Selected, + sAnim_ConditionSelectionIcon_Unselected }; -void sub_81D31D0(struct SpriteSheet *sheet, struct SpriteTemplate *template, struct SpritePalette *pal) +// Just loads the generic data, up to the caller to load the actual sheet/pal for the specific mon +void LoadConditionMonPicTemplate(struct SpriteSheet *sheet, struct SpriteTemplate *template, struct SpritePalette *pal) { - struct SpriteSheet dataSheet = {NULL, 0x800, 100}; + struct SpriteSheet dataSheet = {NULL, 0x800, TAG_CONDITION_MON}; struct SpriteTemplate dataTemplate = { - .tileTag = 100, - .paletteTag = 100, - .oam = &sOamData_8625A20, + .tileTag = TAG_CONDITION_MON, + .paletteTag = TAG_CONDITION_MON, + .oam = &sOam_ConditionMonPic, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; - struct SpritePalette dataPal = {NULL, 100}; + struct SpritePalette dataPal = {NULL, TAG_CONDITION_MON}; *sheet = dataSheet; *template = dataTemplate; *pal = dataPal; } -void sub_81D321C(struct SpriteSheet *sheets, struct SpriteTemplate * template, struct SpritePalette *pals) +void LoadConditionSelectionIcons(struct SpriteSheet *sheets, struct SpriteTemplate * template, struct SpritePalette *pals) { u8 i; struct SpriteSheet dataSheets[] = { - {gUnknown_08625560, 0x100, 101}, - {gUnknown_08625660, 0x20, 103}, - {gPokenavConditionCancel_Gfx, 0x100, 102}, + {sConditionPokeball_Gfx, 0x100, TAG_CONDITION_BALL}, + {sConditionPokeballPlaceholder_Gfx, 0x20, TAG_CONDITION_BALL_PLACEHOLDER}, + {gPokenavConditionCancel_Gfx, 0x100, TAG_CONDITION_CANCEL}, {}, }; struct SpritePalette dataPals[] = { - {gPokenavConditionCancel_Pal, 101}, - {gPokenavConditionCancel_Pal + 16, 102}, + {gPokenavConditionCancel_Pal, TAG_CONDITION_BALL}, + {gPokenavConditionCancel_Pal + 16, TAG_CONDITION_CANCEL}, {}, }; + // Tag is overwritten for the other selection icons struct SpriteTemplate dataTemplate = { - .tileTag = 101, - .paletteTag = 101, - .oam = &sOamData_8625A28, - .anims = sSpriteAnimTable_8625A40, + .tileTag = TAG_CONDITION_BALL, + .paletteTag = TAG_CONDITION_BALL, + .oam = &sOam_ConditionSelectionIcon, + .anims = sAnims_ConditionSelectionIcon, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -1214,34 +1222,41 @@ void sub_81D321C(struct SpriteSheet *sheets, struct SpriteTemplate * template, s *(pals++) = dataPals[i]; } -void sub_81D32B0(struct SpriteSheet *sheet, struct SpritePalette *pal) +#define sSparkleId data[0] +#define sDelayTimer data[1] +#define sNumExtraSparkles data[2] +#define sCurSparkleId data[3] +#define sMonSpriteId data[4] +#define sNextSparkleSpriteId data[5] + +void LoadConditionSparkle(struct SpriteSheet *sheet, struct SpritePalette *pal) { - struct SpriteSheet dataSheet = {gUnknown_086256A0, 0x380, 104}; - struct SpritePalette dataPal = {gUnknown_08625680, 104}; + struct SpriteSheet dataSheet = {sConditionSparkle_Pal, 0x380, TAG_CONDITION_SPARKLE}; + struct SpritePalette dataPal = {sConditionSparkle_Gfx, TAG_CONDITION_SPARKLE}; *sheet = dataSheet; *pal = dataPal; } -static void sub_81D32D4(struct Sprite *sprite) +static void SpriteCB_ConditionSparkle_DoNextAfterDelay(struct Sprite *sprite) { - if (++sprite->data[1] > 60) + if (++sprite->sDelayTimer > 60) { - sprite->data[1] = 0; - sub_81D3408(sprite); + sprite->sDelayTimer = 0; + SetNextConditionSparkle(sprite); } } -static void sub_81D32F4(struct Sprite *sprite) +static void SpriteCB_ConditionSparkle_WaitForAllAnim(struct Sprite *sprite) { if (sprite->animEnded) { - sprite->data[1] = 0; - sprite->callback = sub_81D32D4; + sprite->sDelayTimer = 0; + sprite->callback = SpriteCB_ConditionSparkle_DoNextAfterDelay; } } -static const struct OamData sOamData_8625AD0 = +static const struct OamData sOam_ConditionSparkle = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1253,7 +1268,7 @@ static const struct OamData sOamData_8625AD0 = .priority = 0, }; -static const union AnimCmd sSpriteAnim_8625AD8[] = +static const union AnimCmd sAnim_ConditionSparkle[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_FRAME(4, 5), @@ -1265,133 +1280,120 @@ static const union AnimCmd sSpriteAnim_8625AD8[] = ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_8625AF8[] = +static const union AnimCmd *const sAnims_ConditionSparkle[] = { - sSpriteAnim_8625AD8, - sSpriteAnim_8625AD8 + 2, + &sAnim_ConditionSparkle[0], // Only this entry is used + &sAnim_ConditionSparkle[2], + &sAnim_ConditionSparkle[4], + &sAnim_ConditionSparkle[6], + &sAnim_ConditionSparkle[8], // Here below OOB, will crash if used + &sAnim_ConditionSparkle[10], + &sAnim_ConditionSparkle[12], }; -// unused -static const union AnimCmd *const sSpriteAnimTable_8625B00[] = +static const struct SpriteTemplate sSpriteTemplate_ConditionSparkle = { - sSpriteAnim_8625AD8 + 4, - sSpriteAnim_8625AD8 + 6, -}; - -// unused -static const union AnimCmd *const sSpriteAnimTable_8625B08[] = -{ - sSpriteAnim_8625AD8 + 8, - sSpriteAnim_8625AD8 + 10, -}; - -// unused -static const union AnimCmd *const *const sUnknown_08625B10 = sSpriteAnimTable_8625B08; - -const struct SpriteTemplate gUnknown_08625B14 = -{ - .tileTag = 104, - .paletteTag = 104, - .oam = &sOamData_8625AD0, - .anims = sSpriteAnimTable_8625AF8, + .tileTag = TAG_CONDITION_SPARKLE, + .paletteTag = TAG_CONDITION_SPARKLE, + .oam = &sOam_ConditionSparkle, + .anims = sAnims_ConditionSparkle, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_81D3564, + .callback = SpriteCB_ConditionSparkle, }; -static const s16 gUnknown_08625B2C[][2] = +static const s16 sConditionSparkleCoords[MAX_CONDITION_SPARKLES][2] = { - {0, -35}, - {20, -28}, - {33, -10}, - {33, 10}, - {20, 28}, - {0, 35}, - {-20, 28}, - {-33, 10}, - {-33, -10}, - {-20, -28}, + { 0, -35}, + { 20, -28}, + { 33, -10}, + { 33, 10}, + { 20, 28}, + { 0, 35}, + {-20, 28}, + {-33, 10}, + {-33, -10}, + {-20, -28}, }; -void sub_81D3314(struct Sprite *sprite) +static void SetConditionSparklePosition(struct Sprite *sprite) { - struct Sprite *sprite2 = &gSprites[sprite->data[4]]; + struct Sprite *mon = &gSprites[sprite->sMonSpriteId]; - if (sprite2 != NULL) + if (mon != NULL) { - sprite->pos1.x = sprite2->pos1.x + sprite2->pos2.x + gUnknown_08625B2C[sprite->data[0]][0]; - sprite->pos1.y = sprite2->pos1.y + sprite2->pos2.y + gUnknown_08625B2C[sprite->data[0]][1]; + sprite->pos1.x = mon->pos1.x + mon->pos2.x + sConditionSparkleCoords[sprite->sSparkleId][0]; + sprite->pos1.y = mon->pos1.y + mon->pos2.y + sConditionSparkleCoords[sprite->sSparkleId][1]; } else { - sprite->pos1.x = gUnknown_08625B2C[sprite->data[0]][0] + 40; - sprite->pos1.y = gUnknown_08625B2C[sprite->data[0]][1] + 104; + sprite->pos1.x = sConditionSparkleCoords[sprite->sSparkleId][0] + 40; + sprite->pos1.y = sConditionSparkleCoords[sprite->sSparkleId][1] + 104; } } -void sub_81D338C(u8 arg0, u8 arg1, struct Sprite **sprites) +static void InitConditionSparkles(u8 count, bool8 allowFirstShowAll, struct Sprite **sprites) { u16 i; - for (i = 0; i < 10; i++) + for (i = 0; i < MAX_CONDITION_SPARKLES; i++) { if (sprites[i] != NULL) { - sprites[i]->data[0] = i; - sprites[i]->data[1] = (i * 16) + 1; - sprites[i]->data[2] = arg0; - sprites[i]->data[3] = i; - if (arg1 == 0 || arg0 != 9) + sprites[i]->sSparkleId = i; + sprites[i]->sDelayTimer = (i * 16) + 1; + sprites[i]->sNumExtraSparkles = count; + sprites[i]->sCurSparkleId = i; + if (!allowFirstShowAll || count != MAX_CONDITION_SPARKLES - 1) { - sprites[i]->callback = sub_81D3564; + sprites[i]->callback = SpriteCB_ConditionSparkle; } else { - sub_81D3314(sprites[i]); - sub_81D35E8(sprites[i]); - sprites[i]->callback = sub_81D32F4; + SetConditionSparklePosition(sprites[i]); + ShowAllConditionSparkles(sprites[i]); + sprites[i]->callback = SpriteCB_ConditionSparkle_WaitForAllAnim; sprites[i]->invisible = FALSE; } } } } -static void sub_81D3408(struct Sprite *sprite) +static void SetNextConditionSparkle(struct Sprite *sprite) { u16 i; - u8 id = sprite->data[5]; - - for (i = 0; i < sprite->data[2] + 1; i++) + u8 id = sprite->sNextSparkleSpriteId; + for (i = 0; i < sprite->sNumExtraSparkles + 1; i++) { - gSprites[id].data[1] = (gSprites[id].data[0] * 16) + 1; - gSprites[id].callback = sub_81D3564; - id = gSprites[id].data[5]; + gSprites[id].sDelayTimer = (gSprites[id].sSparkleId * 16) + 1; + gSprites[id].callback = SpriteCB_ConditionSparkle; + id = gSprites[id].sNextSparkleSpriteId; } } -void sub_81D3464(struct Sprite **sprites) +void ResetConditionSparkleSprites(struct Sprite **sprites) { u8 i; - for (i = 0; i < 10; i++) + for (i = 0; i < MAX_CONDITION_SPARKLES; i++) sprites[i] = NULL; } -void sub_81D3480(struct Sprite **sprites, u8 arg1, u8 arg2) +void CreateConditionSparkleSprites(struct Sprite **sprites, u8 monSpriteId, u8 _count) { u16 i, spriteId, firstSpriteId = 0; - u8 count = arg2; + u8 count = _count; for (i = 0; i < count + 1; i++) { - spriteId = CreateSprite(&gUnknown_08625B14, 0, 0, 0); + spriteId = CreateSprite(&sSpriteTemplate_ConditionSparkle, 0, 0, 0); if (spriteId != MAX_SPRITES) { sprites[i] = &gSprites[spriteId]; sprites[i]->invisible = TRUE; - sprites[i]->data[4] = arg1; + sprites[i]->sMonSpriteId = monSpriteId; if (i != 0) - sprites[i - 1]->data[5] = spriteId; + sprites[i - 1]->sNextSparkleSpriteId = spriteId; else firstSpriteId = spriteId; } @@ -1401,15 +1403,15 @@ void sub_81D3480(struct Sprite **sprites, u8 arg1, u8 arg2) } } - sprites[count]->data[5] = firstSpriteId; - sub_81D338C(count, 1, sprites); + sprites[count]->sNextSparkleSpriteId = firstSpriteId; + InitConditionSparkles(count, TRUE, sprites); } -void sub_81D3520(struct Sprite **sprites) +void DestroyConditionSparkleSprites(struct Sprite **sprites) { u16 i; - for (i = 0; i < 10; i++) + for (i = 0; i < MAX_CONDITION_SPARKLES; i++) { if (sprites[i] != NULL) { @@ -1423,38 +1425,41 @@ void sub_81D3520(struct Sprite **sprites) } } -void sub_81D354C(struct Sprite **sprites) +void FreeConditionSparkles(struct Sprite **sprites) { - sub_81D3520(sprites); - FreeSpriteTilesByTag(104); - FreeSpritePaletteByTag(104); + DestroyConditionSparkleSprites(sprites); + FreeSpriteTilesByTag(TAG_CONDITION_SPARKLE); + FreeSpritePaletteByTag(TAG_CONDITION_SPARKLE); } -static void sub_81D3564(struct Sprite *sprite) +static void SpriteCB_ConditionSparkle(struct Sprite *sprite) { - if (sprite->data[1] != 0) + // Delay, then do sparkle anim + if (sprite->sDelayTimer != 0) { - if (--sprite->data[1] != 0) + if (--sprite->sDelayTimer != 0) return; SeekSpriteAnim(sprite, 0); sprite->invisible = FALSE; } - sub_81D3314(sprite); + SetConditionSparklePosition(sprite); + + // Set up next sparkle if (sprite->animEnded) { sprite->invisible = TRUE; - if (sprite->data[3] == sprite->data[2]) + if (sprite->sCurSparkleId == sprite->sNumExtraSparkles) { - if (sprite->data[3] == 9) + if (sprite->sCurSparkleId == MAX_CONDITION_SPARKLES - 1) { - sub_81D35E8(sprite); - sprite->callback = sub_81D32F4; + ShowAllConditionSparkles(sprite); + sprite->callback = SpriteCB_ConditionSparkle_WaitForAllAnim; } else { - sprite->callback = sub_81D32D4; + sprite->callback = SpriteCB_ConditionSparkle_DoNextAfterDelay; } } else @@ -1464,18 +1469,25 @@ static void sub_81D3564(struct Sprite *sprite) } } -static void sub_81D35E8(struct Sprite *sprite) +static void ShowAllConditionSparkles(struct Sprite *sprite) { - u8 i, id = sprite->data[5]; + u8 i, id = sprite->sNextSparkleSpriteId; - for (i = 0; i < sprite->data[2] + 1; i++) + for (i = 0; i < sprite->sNumExtraSparkles + 1; i++) { SeekSpriteAnim(&gSprites[id], 0); gSprites[id].invisible = FALSE; - id = gSprites[id].data[5]; + id = gSprites[id].sNextSparkleSpriteId; } } +#undef sSparkleId +#undef sDelayTimer +#undef sNumExtraSparkles +#undef sCurSparkleId +#undef sMonSpriteId +#undef sNextSparkleSpriteId + static const u8 *const sLvlUpStatStrings[NUM_STATS] = { gText_MaxHP, diff --git a/src/pokenav_conditions_1.c b/src/pokenav_conditions_1.c index 7184271ea..1c7573a44 100644 --- a/src/pokenav_conditions_1.c +++ b/src/pokenav_conditions_1.c @@ -25,7 +25,7 @@ struct PokenavSub11 u8 fill2[0x6320 - 0x6308]; u8 unk6320[3][24]; u8 unk6368[3][64]; - struct UnknownStruct_81D1ED4 unk6428; + struct ConditionGraph unk6428; u8 unk6780[3]; u8 unk6783[3]; s8 unk6786; @@ -546,7 +546,7 @@ u16 sub_81CDC60(void) return unkPtr->unk2; } -struct UnknownStruct_81D1ED4 *sub_81CDC70(void) +struct ConditionGraph *sub_81CDC70(void) { struct PokenavSub11 *structPtr = GetSubstructPtr(11); return &structPtr->unk6428; diff --git a/src/pokenav_conditions_2.c b/src/pokenav_conditions_2.c index 32e673aa4..7c536cd6a 100644 --- a/src/pokenav_conditions_2.c +++ b/src/pokenav_conditions_2.c @@ -24,8 +24,8 @@ u32 sub_81CE700(s32); BSS_DATA u8 gUnknown_030012BC; -const u16 gUnknown_086231E8[] = INCBIN_U16("graphics/pokenav/86231E8.gbapal"); -const u16 gUnknown_08623208[] = INCBIN_U16("graphics/pokenav/8623208.gbapal"); +const u16 gConditionGraphData_Pal[] = INCBIN_U16("graphics/pokenav/condition/graph_data.gbapal"); +const u16 gConditionText_Pal[] = INCBIN_U16("graphics/pokenav/condition/text.gbapal"); const u32 gUnknown_08623228[] = INCBIN_U32("graphics/pokenav/8623228.4bpp.lz"); const u32 gUnknown_0862323C[] = INCBIN_U32("graphics/pokenav/862323C.bin.lz"); const u16 gUnknown_08623338[] = INCBIN_U16("graphics/pokenav/8623338.gbapal"); @@ -134,7 +134,7 @@ struct Pokenav7Struct u8 unk1823; struct PokemonMarkMenu monMarks; struct Sprite *unk28dc; - struct Sprite *unk28e0[10]; + struct Sprite *unk28e0[MAX_CONDITION_SPARKLES]; u8 unk2908; u8 filler2[0x38ac - 0x2909]; }; @@ -226,7 +226,7 @@ u32 sub_81CDE94(s32 state) CopyBgTilemapBufferToVram(3); CopyPaletteIntoBufferUnfaded(gPokenavCondition_Pal, 0x10, 0x20); - CopyPaletteIntoBufferUnfaded(gUnknown_08623208, 0xF0, 0x20); + CopyPaletteIntoBufferUnfaded(gConditionText_Pal, 0xF0, 0x20); structPtr->unk1814 = -80; return LT_INC_AND_PAUSE; case 4: @@ -236,7 +236,7 @@ u32 sub_81CDE94(s32 state) LZ77UnCompVram(gUnknown_0862323C, structPtr->tilemapBuffers[2]); SetBgTilemapBuffer(2, structPtr->tilemapBuffers[2]); CopyBgTilemapBufferToVram(2); - CopyPaletteIntoBufferUnfaded(gUnknown_086231E8, 0x30, 0x20); + CopyPaletteIntoBufferUnfaded(gConditionGraphData_Pal, 0x30, 0x20); sub_81D21DC(2); return LT_INC_AND_PAUSE; case 5: @@ -323,11 +323,11 @@ u32 sub_81CDE94(s32 state) sub_81CEE74(TRUE); return LT_INC_AND_PAUSE; case 20: - if (!sub_81D3178(sub_81CDC70(), &structPtr->unk1814)) + if (!TryUpdateConditionMonTransitionOn(sub_81CDC70(), &structPtr->unk1814)) { - sub_81D3464(structPtr->unk28e0); + ResetConditionSparkleSprites(structPtr->unk28e0); if (sub_81CDD5C() == TRUE || sub_81CDC60() != sub_81CDC50()) - sub_81D3480(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); + CreateConditionSparkleSprites(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); return LT_FINISH; } @@ -345,10 +345,10 @@ u32 sub_81CE2D0(s32 state) { case 0: sub_81CEEC8(); - sub_81D3520(structPtr->unk28e0); + DestroyConditionSparkleSprites(structPtr->unk28e0); return 1; case 1: - if (sub_81D31A4(sub_81CDC70(), &structPtr->unk1814)) + if (TryUpdateConditionMonTransitionOff(sub_81CDC70(), &structPtr->unk1814)) return 2; sub_81CEE74(FALSE); return 1; @@ -360,7 +360,7 @@ u32 sub_81CE2D0(s32 state) case 3: if (IsPaletteFadeActive() || MainMenuLoopedTaskIsBusy()) return 2; - sub_81D354C(structPtr->unk28e0); + FreeConditionSparkles(structPtr->unk28e0); HideBg(1); HideBg(2); HideBg(3); @@ -373,7 +373,7 @@ u32 sub_81CE2D0(s32 state) u32 sub_81CE37C(s32 state) { struct Pokenav7Struct *structPtr = GetSubstructPtr(0xC); - struct UnknownStruct_81D1ED4 *unkPtr = sub_81CDC70(); + struct ConditionGraph *unkPtr = sub_81CDC70(); switch (state) { @@ -385,13 +385,13 @@ u32 sub_81CE37C(s32 state) return 1; case 2: sub_81CD548(2); - sub_81D3520(structPtr->unk28e0); + DestroyConditionSparkleSprites(structPtr->unk28e0); return 1; case 3: - sub_81D2074(unkPtr); + TransitionConditionGraph(unkPtr); return 1; case 4: - if (!sub_81D3150(&structPtr->unk1814)) + if (!MoveConditionMonOffscreen(&structPtr->unk1814)) { sub_81CED30(sub_81CDC84()); return 1; @@ -412,13 +412,13 @@ u32 sub_81CE37C(s32 state) return 2; case 9: unkPtr = sub_81CDC70(); - if (!sub_81D3178(unkPtr, &structPtr->unk1814)) + if (!TryUpdateConditionMonTransitionOn(unkPtr, &structPtr->unk1814)) { - sub_81D3464(structPtr->unk28e0); + ResetConditionSparkleSprites(structPtr->unk28e0); if (sub_81CDD5C() != TRUE && sub_81CDC60() == sub_81CDC50()) return 1; - sub_81D3480(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); + CreateConditionSparkleSprites(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); return 1; } return 2; @@ -459,10 +459,10 @@ u32 sub_81CE4D8(s32 state) return 1; return 2; case 8: - if (!sub_81D3178(sub_81CDC70(), &structPtr->unk1814)) + if (!TryUpdateConditionMonTransitionOn(sub_81CDC70(), &structPtr->unk1814)) { - sub_81D3464(structPtr->unk28e0); - sub_81D3480(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); + ResetConditionSparkleSprites(structPtr->unk28e0); + CreateConditionSparkleSprites(structPtr->unk28e0, structPtr->unk1816, sub_81CDDB0()); return 1; } return 2; @@ -485,10 +485,10 @@ u32 sub_81CE5E4(s32 state) return 1; case 2: sub_81CD548(2); - sub_81D3520(structPtr->unk28e0); + DestroyConditionSparkleSprites(structPtr->unk28e0); return 1; case 3: - if (!sub_81D31A4(sub_81CDC70(), &structPtr->unk1814)) + if (!TryUpdateConditionMonTransitionOff(sub_81CDC70(), &structPtr->unk1814)) return 1; return 2; case 4: @@ -663,7 +663,7 @@ void sub_81CE9E4(void) u16 i, spriteId; struct Pokenav7Struct *structPtr = GetSubstructPtr(0xC); - sub_81D321C(sprSheets, &sprTemplate, sprPals); + LoadConditionSelectionIcons(sprSheets, &sprTemplate, sprPals); if (sub_81CDD5C() == TRUE) { structPtr->monMarks.baseTileTag = 0x6A; @@ -728,7 +728,7 @@ void sub_81CE9E4(void) } } - sub_81D32B0(&sprSheet, &sprPals[0]); + LoadConditionSparkle(&sprSheet, &sprPals[0]); LoadSpriteSheet(&sprSheet); sprPals[1].data = NULL; Pokenav_AllocAndLoadPalettes(sprPals); @@ -804,7 +804,7 @@ void sub_81CED30(u8 var) if (structPtr->unk1816 == 0xFF) { - sub_81D31D0(&sprSheet, &sprTemplate, &sprPal); + LoadConditionMonPicTemplate(&sprSheet, &sprTemplate, &sprPal); sprSheet.data = sub_81CDCB4(var); sprPal.data = sub_81CDCD4(var); structPtr->unk1818 = LoadSpritePalette(&sprPal); @@ -834,7 +834,7 @@ void sub_81CED30(u8 var) void sub_81CEE44(void) { - struct UnknownStruct_81D1ED4 *unk = sub_81CDC70(); + struct ConditionGraph *unk = sub_81CDC70(); LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); @@ -857,17 +857,17 @@ void sub_81CEE74(bool8 showBg) void sub_81CEE90(void) { - struct UnknownStruct_81D1ED4 *unk = sub_81CDC70(); + struct ConditionGraph *unk = sub_81CDC70(); u8 id = sub_81CDC84(); gUnknown_030012BC = id; sub_81D1F84(unk, unk->unk14[3], unk->unk14[id]); - sub_81D2074(unk); + TransitionConditionGraph(unk); } void sub_81CEEC8(void) { - struct UnknownStruct_81D1ED4 *unk = sub_81CDC70(); + struct ConditionGraph *unk = sub_81CDC70(); if (sub_81CDD5C() || sub_81CDC60() != sub_81CDC50() - 1) sub_81D1F84(unk, unk->unk14[sub_81CDC84()], unk->unk14[3]); diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index 5079edb37..ebb237d54 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -24,143 +24,160 @@ #include "pokemon_summary_screen.h" #include "item_menu.h" -struct UsePokeblockSubStruct -{ - /*0x00*/ void (*field_0)(void); - /*0x04*/ void (*callback)(void); - /*0x08*/ struct Pokeblock *pokeblock; - /*0x0C*/ struct Pokemon *mon; - /*0x10*/ u8 stringBuffer[0x40]; - /*0x50*/ u8 field_50; - /*0x51*/ u8 field_51; - /*0x52*/ u8 field_52; - /*0x53*/ u8 field_53; - /*0x54*/ u8 field_54; - /*0x55*/ u8 field_55; - /*0x56*/ u8 field_56; - /*0x57*/ u8 field_57[5]; - /*0x5C*/ u8 field_5c[5]; - /*0x61*/ u8 field_61[5]; - /*0x66*/ s16 field_66[5]; - /*0x70*/ u8 field_70; - /*0x71*/ u8 field_71; - /*0x74*/ u8 (*unk74)(void); - /*0x78*/ u8 unk78; - /*0x79*/ u8 filler79[0x1]; - /*0x7A*/ u8 field_7A[0x22]; +/* + This file handles the screen where the player chooses + which pokemon to give a pokeblock to. The subsequent scene + of feeding the pokeblock to the pokemon is handled by + pokeblock_feed.c, and the rest of the pokeblock menu (and + other pokeblock-related functions) are in pokeblock.c +*/ + +enum { + WIN_NAME, + WIN_NATURE, + WIN_TEXT, + WIN_COUNT }; -struct Unk7FB8 +#define TAG_UP_DOWN 0 +#define TAG_CONDITION 1 + +// At any one time, the currently selected mon and its two adjacent neighbors can be loaded +// IDs to refer to one of these 3 are called "load id" in this file +#define NUM_SELECTIONS_LOADED 3 + +struct UsePokeblockSession { - u8 unk0; - u8 unk1; - u16 unk2; + void (*callback)(void); + void (*exitCallback)(void); + struct Pokeblock *pokeblock; + struct Pokemon *mon; + u8 stringBuffer[64]; + u8 mainState; + u8 unused1; + u8 timer; + u8 statId; + u8 numEnhancements; + u8 unused2; + bool8 monInTopHalf; + u8 conditionsBeforeBlock[FLAVOR_COUNT]; + u8 conditionsAfterBlock[FLAVOR_COUNT]; + u8 enhancements[FLAVOR_COUNT]; + s16 pokeblockStatBoosts[FLAVOR_COUNT]; + u8 numSelections; // num in party + 1 (for Cancel) + u8 curSelection; + bool8 (*loadNewSelection)(void); + u8 helperState; + u8 unused3; + u8 natureText[34]; }; -struct UsePokeblockStruct +// This struct is identical to PokenavMonList, the struct used for managing lists of pokemon in the pokenav +// Given that this screen is essentially duplicated in the poknav, this struct was probably the same one with +// a more general name/purpose +// TODO: Once the pokenav conditions screens are documented, resolve the above +struct UsePokeblockMenuPokemon { - /*0x0000*/ u8 filler0[4]; - /*0x0000*/ u16 field_4[6][0x40]; - /*0x0304*/ u8 field_304[3][0x2000]; - /*0x6304*/ u8 filler_6304[0x1000]; - /*0x7304*/ u8 tilemapBuffer[BG_SCREEN_SIZE + 2]; - /*0x7B06*/ u8 field_7B06[7]; - /*0x7B0E*/ s16 field_7B0E; - /*0x7B10*/ u8 field_7B10; - /*0x7B12*/ u16 field_7B12; - /*0x7B12*/ u16 field_7B14; - /*0x7B12*/ u8 *field_7B18; - /*0x7B1C*/ struct Sprite *field_7B1C[10]; - /*0x7B44*/ struct Sprite *field_7B44[2]; - /*0x7B4C*/ u8 field_7B4C; - /*0x7B4D*/ u8 field_7B4D[3][24]; - /*0x7B95*/ u8 field_7B95[3][64]; - /*0x7C58*/ struct UnknownStruct_81D1ED4 field_7C58; - /*0x7FB0*/ u8 unk7FB0[3]; - /*0x7FB3*/ s8 field_7FB3; - /*0x7FB4*/ s8 field_7FB4; - /*0x7FB5*/ s8 field_7FB5; - /*0x7FB6*/ s8 field_7FB6; - /*0x7FB8*/ struct Unk7FB8 field_7FB8[6]; - /*0x7FD0*/ struct UsePokeblockSubStruct info; + u8 boxId; // Because this screen is never used for the PC this is always set to TOTAL_BOXES_COUNT to refer to party + u8 monId; + u16 data; // never read }; -#define TAG_TILE_CONDITION_UP_DOWN 0 -#define TAG_PAL_CONDITION_UP_DOWN 0 -#define TAG_PAL_POKEBLOCK_CONDITION 1 +struct UsePokeblockMenu +{ + u32 unused; + u16 partyPalettes[PARTY_SIZE][0x40]; + u8 partySheets[NUM_SELECTIONS_LOADED][0x2000]; + u8 unusedBuffer[0x1000]; + u8 tilemapBuffer[BG_SCREEN_SIZE + 2]; + u8 selectionIconSpriteIds[PARTY_SIZE + 1]; + s16 curMonXOffset; + u8 curMonSpriteId; + u16 curMonPalette; + u16 curMonSheet; + u8 *curMonTileStart; + struct Sprite *sparkles[MAX_CONDITION_SPARKLES]; + struct Sprite *condition[2]; + u8 toLoadSelection; + u8 locationStrings[NUM_SELECTIONS_LOADED][24]; // Gets an "in party" or "in box #" string that never gets printed + u8 monNameStrings[NUM_SELECTIONS_LOADED][64]; + struct ConditionGraph graph; + u8 numSparkles[NUM_SELECTIONS_LOADED]; + s8 curLoadId; + s8 nextLoadId; + s8 prevLoadId; + s8 toLoadId; + struct UsePokeblockMenuPokemon party[PARTY_SIZE]; + struct UsePokeblockSession info; +}; -extern void sub_81D21DC(u8); +static void SetUsePokeblockCallback(void (*func)(void)); +static void LoadUsePokeblockMenu(void); +static void CB2_UsePokeblockMenu(void); +static void CB2_ReturnToUsePokeblockMenu(void); +static void ShowUsePokeblockMenu(void); +static void CB2_ShowUsePokeblockMenuForResults(void); +static void ShowUsePokeblockMenuForResults(void); +static void LoadPartyInfo(void); +static void LoadAndCreateSelectionIcons(void); +static u8 GetSelectionIdFromPartyId(u8); +static bool8 LoadConditionTitle(void); +static bool8 LoadUsePokeblockMenuGfx(void); +static void UpdateMonPic(u8); +static void UpdateMonInfoText(u16, bool8); +static void UsePokeblockMenu(void); +static void UpdateSelection(bool8); +static void CloseUsePokeblockMenu(void); +static void AskUsePokeblock(void); +static s8 HandleAskUsePokeblockInput(void); +static bool8 IsSheenMaxed(void); +static void PrintWontEatAnymore(void); +static void FeedPokeblockToMon(void); +static void EraseMenuWindow(void); +static u8 GetPartyIdFromSelectionId(u8); +static void ShowPokeblockResults(void); +static void CalculateConditionEnhancements(void); +static void LoadAndCreateUpDownSprites(void); +static void CalculateNumAdditionalSparkles(u8); +static void PrintFirstEnhancement(void); +static bool8 TryPrintNextEnhancement(void); +static void BufferEnhancedStatText(u8 *, u8, s16); +static void PrintMenuWindowText(const u8 *); +static void CalculatePokeblockEffectiveness(struct Pokeblock *, struct Pokemon *); +static void SpriteCB_UpDown(struct Sprite *); +static void LoadInitialMonInfo(void); +static void LoadMonInfo(s16, u8); +static bool8 LoadNewSelection_CancelToMon(void); +static bool8 LoadNewSelection_MonToCancel(void); +static bool8 LoadNewSelection_MonToMon(void); +static void SpriteCB_SelectionIconPokeball(struct Sprite *); +static void SpriteCB_SelectionIconCancel(struct Sprite *); +static void SpriteCB_MonPic(struct Sprite *); +static void SpriteCB_Condition(struct Sprite *); -// this file's functions -void sub_816636C(void (*func)(void)); -void sub_8166380(void); -void sub_816631C(void); -void sub_81662C0(void); -void sub_8166564(void); -void sub_8166304(void); -void sub_81668F8(void); -void sub_8167420(void); -void sub_8167760(void); -u8 sub_81672E4(u8 arg0); -static bool8 sub_8168328(void); -bool8 sub_8167930(void); -void sub_8167608(u8 arg0); -void sub_8167BA0(u16 arg0, u8 copyToVramMode); -void sub_8166634(void); -static void sub_8167CA0(bool8); -void sub_8166BEC(void); -void sub_8166D44(void); -s8 sub_8166DE4(void); -bool8 IsSheenMaxed(void); -void sub_8166F50(void); -void sub_816681C(void); -void sub_8166F94(void); -u8 sub_81672A4(u8 a0); -void sub_8166A34(void); -void sub_8167104(void); -void sub_8167338(void); -void sub_81681F4(u8); -void sub_8166E24(void); -bool8 sub_8166EDC(void); -void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 a2); -void Pokeblock_MenuWindowTextPrint(const u8 *message); -void sub_8167184(struct Pokeblock *, struct Pokemon *); -void sub_81673DC(struct Sprite *sprite); -void sub_81674BC(void); -void sub_816753C(s16, u8); -static u8 sub_8167EA4(void); -static u8 sub_8167FA4(void); -static u8 sub_8168048(void); -void sub_8168180(struct Sprite *sprite); -void sub_81681B4(struct Sprite *sprite); -void sub_8168168(struct Sprite *sprite); -void sub_8168374(struct Sprite *sprite); +extern const u16 gConditionGraphData_Pal[]; +extern const u16 gConditionText_Pal[]; -extern const u16 gUnknown_086231E8[]; -extern const u16 gUnknown_08623208[]; -extern const struct SpritePalette gSpritePalette_085DFDB8; -extern const struct SpriteTemplate gSpriteTemplate_085DFDA0; - -// ram variables -EWRAM_DATA struct UsePokeblockSubStruct *gUnknown_0203BC90 = NULL; -EWRAM_DATA void (*gUnknown_0203BC94)(void) = NULL; -EWRAM_DATA struct Pokeblock *gUnknown_0203BC98 = NULL; +// The below 3 are saved for returning to the screen after feeding a pokeblock to a mon +// so that the rest of the data can be freed +static EWRAM_DATA struct UsePokeblockSession *sInfo = NULL; +static EWRAM_DATA void (*sExitCallback)(void) = NULL; +static EWRAM_DATA struct Pokeblock *sPokeblock = NULL; EWRAM_DATA u8 gPokeblockMonId = 0; EWRAM_DATA s16 gPokeblockGain = 0; -EWRAM_DATA u8 *gUnknown_0203BCA0 = NULL; -EWRAM_DATA u8 *gUnknown_0203BCA4 = NULL; -EWRAM_DATA u8 *gUnknown_0203BCA8 = NULL; -EWRAM_DATA struct UsePokeblockStruct *gUnknown_0203BCAC = NULL; +static EWRAM_DATA u8 *sGraph_Tilemap = NULL; +static EWRAM_DATA u8 *sGraph_Gfx = NULL; +static EWRAM_DATA u8 *sMonFrame_TilemapPtr = NULL; +static EWRAM_DATA struct UsePokeblockMenu *sMenu = NULL; -// const rom data -// todo: make it static once the file is decompiled +static const u32 sMonFrame_Pal[] = INCBIN_U32("graphics/pokeblock/use_screen/mon_frame_pal.bin"); +static const u32 sMonFrame_Gfx[] = INCBIN_U32("graphics/pokeblock/use_screen/mon_frame.4bpp"); +static const u32 sMonFrame_Tilemap[] = INCBIN_U32("graphics/pokeblock/use_screen/mon_frame.bin"); +static const u32 sGraphData_Tilemap[] = INCBIN_U32("graphics/pokeblock/use_screen/graph_data.bin"); -const u32 gUnknown_085DFA60[] = INCBIN_U32("graphics/interface/85DFA60.bin"); -const u32 gUnknown_085DFA80[] = INCBIN_U32("graphics/interface/85DFA80.4bpp"); -const u32 gUnknown_085DFB60[] = INCBIN_U32("graphics/interface/85DFB60.bin"); -const u32 gUnknown_085DFC0C[] = INCBIN_U32("graphics/interface/85DFC0C.bin"); - -const u32 gUnknown_085DFCB0[] = +// The condition/flavors aren't listed in their normal order in this file, they're listed as shown on the graph going counter-clockwise +// Normally they would go Cool/Spicy, Beauty/Dry, Cute/Sweet, Smart/Bitter, Tough/Sour (also graph order, but clockwise) +static const u32 sMonDataConditions[FLAVOR_COUNT] = { MON_DATA_COOL, MON_DATA_TOUGH, @@ -169,13 +186,13 @@ const u32 gUnknown_085DFCB0[] = MON_DATA_BEAUTY }; -const u8 gUnknown_085DFCC4[] = +static const u8 sFlavors[FLAVOR_COUNT] = { - 0, // Spicy/Cool - 4, // Dry/Beauty - 3, // Sweet/Cute - 2, // Bitter/Smart - 1 // Sour/Tough + FLAVOR_SPICY, + FLAVOR_SOUR, + FLAVOR_BITTER, + FLAVOR_SWEET, + FLAVOR_DRY }; static const u8 sNatureTextColors[] = @@ -185,7 +202,7 @@ static const u8 sNatureTextColors[] = TEXT_COLOR_WHITE }; -const struct BgTemplate gUnknown_085DFCCC[4] = +static const struct BgTemplate sBgTemplates[4] = { { .bg = 0, @@ -225,50 +242,50 @@ const struct BgTemplate gUnknown_085DFCCC[4] = } }; -const struct WindowTemplate gUnknown_085DFCDC[] = +static const struct WindowTemplate sWindowTemplates[WIN_COUNT + 1] = { - { + [WIN_NAME] = { .bg = 0, - .tilemapLeft = 0xD, + .tilemapLeft = 13, .tilemapTop = 1, - .width = 0xD, + .width = 13, .height = 4, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 1 }, - { + [WIN_NATURE] = { .bg = 0, .tilemapLeft = 0, - .tilemapTop = 0xE, - .width = 0xB, + .tilemapTop = 14, + .width = 11, .height = 2, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x35 }, - { + [WIN_TEXT] = { .bg = 0, .tilemapLeft = 1, - .tilemapTop = 0x11, - .width = 0x1C, + .tilemapTop = 17, + .width = 28, .height = 2, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x4B }, DUMMY_WIN_TEMPLATE }; -const struct WindowTemplate sUsePokeblockYesNoWinTemplate = +static const struct WindowTemplate sUsePokeblockYesNoWinTemplate = { .bg = 0, - .tilemapLeft = 0x18, - .tilemapTop = 0xB, + .tilemapLeft = 24, + .tilemapTop = 11, .width = 5, .height = 4, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x83 }; -const u8 *const sContestStatNames[] = +static const u8 *const sContestStatNames[] = { gText_Coolness, gText_Toughness, @@ -277,26 +294,26 @@ const u8 *const sContestStatNames[] = gText_Beauty3 }; -const struct SpriteSheet gSpriteSheet_ConditionUpDown = +static const struct SpriteSheet sSpriteSheet_UpDown = { - gUsePokeblockUpDown_Gfx, 0x200, TAG_TILE_CONDITION_UP_DOWN + gUsePokeblockUpDown_Gfx, 0x200, TAG_UP_DOWN }; -const struct SpritePalette gSpritePalette_ConditionUpDown = +static const struct SpritePalette sSpritePalette_UpDown = { - gUsePokeblockUpDown_Pal, TAG_PAL_CONDITION_UP_DOWN + gUsePokeblockUpDown_Pal, TAG_UP_DOWN }; -const s16 gUnknown_085DFD28[][2] = +static const s16 sUpDownCoordsOnGraph[FLAVOR_COUNT][2] = { - {0x9C, 0x24}, - {0x75, 0x3B}, - {0x75, 0x76}, - {0xC5, 0x76}, - {0xC5, 0x3B} + {156, 36}, + {117, 59}, + {117, 118}, + {197, 118}, + {197, 59} }; -const struct OamData gOamData_085DFD3C = +static const struct OamData sOam_UpDown = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -310,36 +327,36 @@ const struct OamData gOamData_085DFD3C = .paletteNum = 0, }; -const union AnimCmd gSpriteAnim_085DFD44[] = +static const union AnimCmd sAnim_Up[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_085DFD4C[] = +static const union AnimCmd sAnim_Down[] = { ANIMCMD_FRAME(8, 5), ANIMCMD_END }; -const union AnimCmd *const gSpriteAnimTable_085DFD54[] = +static const union AnimCmd *const sAnims_UpDown[] = { - gSpriteAnim_085DFD44, - gSpriteAnim_085DFD4C + sAnim_Up, + sAnim_Down }; -const struct SpriteTemplate gSpriteTemplate_085DFD5C = +static const struct SpriteTemplate sSpriteTemplate_UpDown = { - .tileTag = 0, - .paletteTag = 0, - .oam = &gOamData_085DFD3C, - .anims = gSpriteAnimTable_085DFD54, + .tileTag = TAG_UP_DOWN, + .paletteTag = TAG_UP_DOWN, + .oam = &sOam_UpDown, + .anims = sAnims_UpDown, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -const struct OamData gOamData_085DFD74 = +static const struct OamData sOam_Condition = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -353,327 +370,341 @@ const struct OamData gOamData_085DFD74 = .paletteNum = 0, }; -const union AnimCmd gSpriteAnim_085DFD7C[] = +static const union AnimCmd sAnim_Condition_0[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_085DFD84[] = +static const union AnimCmd sAnim_Condition_1[] = { ANIMCMD_FRAME(32, 5), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_085DFD8C[] = +static const union AnimCmd sAnim_Condition_2[] = { ANIMCMD_FRAME(64, 5), ANIMCMD_END }; -const union AnimCmd *const gSpriteAnimTable_085DFD94[] = +static const union AnimCmd *const sAnims_Condition[] = { - gSpriteAnim_085DFD7C, - gSpriteAnim_085DFD84, - gSpriteAnim_085DFD8C + sAnim_Condition_0, + sAnim_Condition_1, + sAnim_Condition_2 }; -const struct SpriteTemplate gSpriteTemplate_085DFDA0 = +static const struct SpriteTemplate sSpriteTemplate_Condition = { - .tileTag = 1, - .paletteTag = 1, - .oam = &gOamData_085DFD74, - .anims = gSpriteAnimTable_085DFD94, + .tileTag = TAG_CONDITION, + .paletteTag = TAG_CONDITION, + .oam = &sOam_Condition, + .anims = sAnims_Condition, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_8168374, + .callback = SpriteCB_Condition, }; -const struct SpritePalette gSpritePalette_085DFDB8 = +static const struct SpritePalette sSpritePalette_Condition = { - gUsePokeblockCondition_Pal, TAG_PAL_POKEBLOCK_CONDITION + gUsePokeblockCondition_Pal, TAG_CONDITION }; -// code +// When first opening the selection screen void ChooseMonToGivePokeblock(struct Pokeblock *pokeblock, void (*callback)(void)) { - gUnknown_0203BCAC = AllocZeroed(sizeof(*gUnknown_0203BCAC)); - gUnknown_0203BC90 = &gUnknown_0203BCAC->info; - gUnknown_0203BC90->pokeblock = pokeblock; - gUnknown_0203BC90->callback = callback; - sub_816636C(sub_8166380); - SetMainCallback2(sub_816631C); + sMenu = AllocZeroed(sizeof(*sMenu)); + sInfo = &sMenu->info; + sInfo->pokeblock = pokeblock; + sInfo->exitCallback = callback; + SetUsePokeblockCallback(LoadUsePokeblockMenu); + SetMainCallback2(CB2_UsePokeblockMenu); } -void CB2_ReturnAndChooseMonToGivePokeblock(void) +// When returning to the selection screen after feeding a pokeblock to a mon +static void CB2_ReturnAndChooseMonToGivePokeblock(void) { - gUnknown_0203BCAC = AllocZeroed(sizeof(*gUnknown_0203BCAC)); - gUnknown_0203BC90 = &gUnknown_0203BCAC->info; - gUnknown_0203BC90->pokeblock = gUnknown_0203BC98; - gUnknown_0203BC90->callback = gUnknown_0203BC94; - gPokeblockMonId = sub_81672E4(gPokeblockMonId); - gUnknown_0203BC90->field_56 = gPokeblockMonId < 4 ? 0 : 1; - sub_816636C(sub_8166380); - SetMainCallback2(sub_81662C0); + sMenu = AllocZeroed(sizeof(*sMenu)); + sInfo = &sMenu->info; + sInfo->pokeblock = sPokeblock; + sInfo->exitCallback = sExitCallback; + gPokeblockMonId = GetSelectionIdFromPartyId(gPokeblockMonId); + sInfo->monInTopHalf = (gPokeblockMonId <= PARTY_SIZE / 2) ? FALSE : TRUE; + SetUsePokeblockCallback(LoadUsePokeblockMenu); + SetMainCallback2(CB2_ReturnToUsePokeblockMenu); } -void sub_81662C0(void) +static void CB2_ReturnToUsePokeblockMenu(void) { - gUnknown_0203BC90->field_0(); + sInfo->callback(); AnimateSprites(); BuildOamBuffer(); UpdatePaletteFade(); - if (gUnknown_0203BC90->field_0 == sub_8166564) + if (sInfo->callback == ShowUsePokeblockMenu) { - gUnknown_0203BC90->field_50 = 0; - SetMainCallback2(sub_8166304); + sInfo->mainState = 0; + SetMainCallback2(CB2_ShowUsePokeblockMenuForResults); } } -void sub_8166304(void) +static void CB2_ShowUsePokeblockMenuForResults(void) { - sub_81668F8(); + ShowUsePokeblockMenuForResults(); AnimateSprites(); BuildOamBuffer(); UpdatePaletteFade(); } -void sub_816631C(void) +static void CB2_UsePokeblockMenu(void) { - gUnknown_0203BC90->field_0(); + sInfo->callback(); AnimateSprites(); BuildOamBuffer(); RunTextPrinters(); UpdatePaletteFade(); } -void sub_8166340(void) +static void VBlankCB_UsePokeblockMenu(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); - sub_81D2108(&gUnknown_0203BCAC->field_7C58); + sub_81D2108(&sMenu->graph); ScanlineEffect_InitHBlankDmaTransfer(); } -void sub_816636C(void (*func)(void)) +static void SetUsePokeblockCallback(void (*func)(void)) { - gUnknown_0203BC90->field_0 = func; - gUnknown_0203BC90->field_50 = 0; + sInfo->callback = func; + sInfo->mainState = 0; } -void sub_8166380(void) +static void LoadUsePokeblockMenu(void) { - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: - gUnknown_0203BCAC->field_7B10 = 0xFF; - sub_81D1ED4(&gUnknown_0203BCAC->field_7C58); - gUnknown_0203BC90->field_50++; + sMenu->curMonSpriteId = 0xFF; + sub_81D1ED4(&sMenu->graph); + sInfo->mainState++; break; case 1: ResetSpriteData(); FreeAllSpritePalettes(); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 2: SetVBlankCallback(NULL); CpuFill32(0, (void*)(VRAM), VRAM_SIZE); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 3: ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_085DFCCC, ARRAY_COUNT(gUnknown_085DFCCC)); - InitWindows(gUnknown_085DFCDC); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); + InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); LoadUserWindowBorderGfx(0, 0x97, 0xE0); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 4: - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 5: - if (!sub_8168328()) - gUnknown_0203BC90->field_50++; + if (!LoadConditionTitle()) + sInfo->mainState++; break; case 6: gKeyRepeatStartDelay = 20; - sub_8167420(); - gUnknown_0203BC90->field_50++; + LoadPartyInfo(); + sInfo->mainState++; break; case 7: - if (!sub_8167930()) - gUnknown_0203BC90->field_50++; + if (!LoadUsePokeblockMenuGfx()) + sInfo->mainState++; break; case 8: - sub_8167608(0); - sub_8167760(); - gUnknown_0203BC90->field_50++; + UpdateMonPic(0); + LoadAndCreateSelectionIcons(); + sInfo->mainState++; break; case 9: - if (!sub_81D312C(&gUnknown_0203BCAC->field_7B0E)) - gUnknown_0203BC90->field_50++; + if (!MoveConditionMonOnscreen(&sMenu->curMonXOffset)) + sInfo->mainState++; break; case 10: - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 11: - sub_81D2754(gUnknown_0203BCAC->field_7C58.unk0[0], gUnknown_0203BCAC->field_7C58.unk14[0]); - sub_81D20AC(&gUnknown_0203BCAC->field_7C58); - gUnknown_0203BC90->field_50++; + sub_81D2754(sMenu->graph.unk0[0], sMenu->graph.unk14[0]); + sub_81D20AC(&sMenu->graph); + sInfo->mainState++; break; case 12: - if (!sub_81D20BC(&gUnknown_0203BCAC->field_7C58)) + if (!sub_81D20BC(&sMenu->graph)) { - sub_81D1F84(&gUnknown_0203BCAC->field_7C58, gUnknown_0203BCAC->field_7C58.unk14[0], gUnknown_0203BCAC->field_7C58.unk14[0]); - gUnknown_0203BC90->field_50++; + sub_81D1F84(&sMenu->graph, sMenu->graph.unk14[0], sMenu->graph.unk14[0]); + sInfo->mainState++; } break; case 13: - sub_81D2230(&gUnknown_0203BCAC->field_7C58); - gUnknown_0203BC90->field_50++; + sub_81D2230(&sMenu->graph); + sInfo->mainState++; break; case 14: - PutWindowTilemap(0); - PutWindowTilemap(1); - sub_8167BA0(0, 1); - gUnknown_0203BC90->field_50++; + PutWindowTilemap(WIN_NAME); + PutWindowTilemap(WIN_NATURE); + UpdateMonInfoText(0, TRUE); + sInfo->mainState++; break; case 15: - sub_816636C(sub_8166564); + SetUsePokeblockCallback(ShowUsePokeblockMenu); break; } } -void sub_8166564(void) +static void ShowUsePokeblockMenu(void) { - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); - SetVBlankCallback(sub_8166340); + SetVBlankCallback(VBlankCB_UsePokeblockMenu); ShowBg(0); ShowBg(1); ShowBg(3); ShowBg(2); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 1: if (!gPaletteFade.active) { - sub_81D3464(gUnknown_0203BCAC->field_7B1C); - if (gUnknown_0203BCAC->info.field_71 != gUnknown_0203BCAC->info.field_70 - 1) + ResetConditionSparkleSprites(sMenu->sparkles); + if (sMenu->info.curSelection != sMenu->info.numSelections - 1) { - u8 var0 = gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->field_7FB3]; - sub_81D3480(gUnknown_0203BCAC->field_7B1C, gUnknown_0203BCAC->field_7B10, var0); + u8 numSparkles = sMenu->numSparkles[sMenu->curLoadId]; + CreateConditionSparkleSprites(sMenu->sparkles, sMenu->curMonSpriteId, numSparkles); } - sub_816636C(sub_8166634); + SetUsePokeblockCallback(UsePokeblockMenu); } break; } } -void sub_8166634(void) -{ - u8 var; +enum { + STATE_HANDLE_INPUT, + STATE_UPDATE_SELECTION, + STATE_2, // unused state + STATE_CLOSE, + STATE_4, // unused state + STATE_CONFIRM_SELECTION, + STATE_HANDLE_CONFIRMATION, + STATE_WAIT_MSG, +}; - switch (gUnknown_0203BC90->field_50) +static void UsePokeblockMenu(void) +{ + bool8 loading; + + switch (sInfo->mainState) { - case 0: - if (gMain.heldKeys & DPAD_UP) + case STATE_HANDLE_INPUT: + if (JOY_HELD(DPAD_UP)) { PlaySE(SE_SELECT); - sub_8167CA0(TRUE); - sub_81D3520(gUnknown_0203BCAC->field_7B1C); - gUnknown_0203BC90->field_50 = 1; + UpdateSelection(TRUE); + DestroyConditionSparkleSprites(sMenu->sparkles); + sInfo->mainState = STATE_UPDATE_SELECTION; } - else if (gMain.heldKeys & DPAD_DOWN) + else if (JOY_HELD(DPAD_DOWN)) { PlaySE(SE_SELECT); - sub_8167CA0(FALSE); - sub_81D3520(gUnknown_0203BCAC->field_7B1C); - gUnknown_0203BC90->field_50 = 1; + UpdateSelection(FALSE); + DestroyConditionSparkleSprites(sMenu->sparkles); + sInfo->mainState = STATE_UPDATE_SELECTION; } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - gUnknown_0203BC90->field_50 = 3; + sInfo->mainState = STATE_CLOSE; } - else if (gMain.newKeys & A_BUTTON) + else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - if (gUnknown_0203BCAC->info.field_71 == gUnknown_0203BCAC->info.field_70 - 1) - gUnknown_0203BC90->field_50 = 3; + + // If last item, selected Cancel. Otherwise selected mon + if (sMenu->info.curSelection == sMenu->info.numSelections - 1) + sInfo->mainState = STATE_CLOSE; else - gUnknown_0203BC90->field_50 = 5; + sInfo->mainState = STATE_CONFIRM_SELECTION; } break; - case 1: - var = gUnknown_0203BCAC->info.unk74(); - if (!var) - gUnknown_0203BC90->field_50 = var; + case STATE_UPDATE_SELECTION: + loading = sMenu->info.loadNewSelection(); + if (!loading) + sInfo->mainState = STATE_HANDLE_INPUT; break; - case 2: + case STATE_2: break; - case 3: - sub_816636C(sub_8166BEC); + case STATE_CLOSE: + SetUsePokeblockCallback(CloseUsePokeblockMenu); break; - case 4: + case STATE_4: break; - case 5: - sub_8166D44(); - gUnknown_0203BC90->field_50++; + case STATE_CONFIRM_SELECTION: + AskUsePokeblock(); + sInfo->mainState++; break; - case 6: - switch (sub_8166DE4()) + case STATE_HANDLE_CONFIRMATION: + switch (HandleAskUsePokeblockInput()) { - case 1: - case -1: - gUnknown_0203BC90->field_50 = 0; + case 1: // NO + case MENU_B_PRESSED: + sInfo->mainState = STATE_HANDLE_INPUT; break; - case 0: + case 0: // YES if (IsSheenMaxed()) { - sub_8166F50(); - gUnknown_0203BC90->field_50 = 7; + PrintWontEatAnymore(); + sInfo->mainState = STATE_WAIT_MSG; } else { - sub_816636C(sub_816681C); + SetUsePokeblockCallback(FeedPokeblockToMon); } break; } break; - case 7: - if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + case STATE_WAIT_MSG: + if (JOY_NEW(A_BUTTON | B_BUTTON)) { - sub_8166F94(); - gUnknown_0203BC90->field_50 = 0; + EraseMenuWindow(); + sInfo->mainState = STATE_HANDLE_INPUT; } break; } } -void sub_816681C(void) +static void FeedPokeblockToMon(void) { - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: - gPokeblockMonId = sub_81672A4(gUnknown_0203BCAC->info.field_71); - gUnknown_0203BC94 = gUnknown_0203BC90->callback; - gUnknown_0203BC98 = gUnknown_0203BC90->pokeblock; + gPokeblockMonId = GetPartyIdFromSelectionId(sMenu->info.curSelection); + sExitCallback = sInfo->exitCallback; + sPokeblock = sInfo->pokeblock; BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 1: if (!gPaletteFade.active) { SetVBlankCallback(NULL); - FREE_AND_SET_NULL(gUnknown_0203BCA0); - FREE_AND_SET_NULL(gUnknown_0203BCA4); - FREE_AND_SET_NULL(gUnknown_0203BCA8); - FREE_AND_SET_NULL(gUnknown_0203BCAC); + FREE_AND_SET_NULL(sGraph_Tilemap); + FREE_AND_SET_NULL(sGraph_Gfx); + FREE_AND_SET_NULL(sMonFrame_TilemapPtr); + FREE_AND_SET_NULL(sMenu); FreeAllWindowBuffers(); gMain.savedCallback = CB2_ReturnAndChooseMonToGivePokeblock; CB2_PreparePokeblockFeedScene(); @@ -682,184 +713,184 @@ void sub_816681C(void) } } -void sub_81668F8(void) +static void ShowUsePokeblockMenuForResults(void) { - u16 var; + bool8 loading; - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: - if (gUnknown_0203BCAC->info.field_71 != gPokeblockMonId) + if (sMenu->info.curSelection != gPokeblockMonId) { - sub_8167CA0(gUnknown_0203BC90->field_56); - gUnknown_0203BC90->field_50++; + UpdateSelection(sInfo->monInTopHalf); + sInfo->mainState++; } else { - gUnknown_0203BC90->field_50 = 3; + sInfo->mainState = 3; } break; case 1: - var = gUnknown_0203BCAC->info.unk74(); - if (!var) - gUnknown_0203BC90->field_50 = var; + loading = sMenu->info.loadNewSelection(); + if (!loading) + sInfo->mainState = 0; break; case 2: break; case 3: BlendPalettes(0xFFFFFFFF, 16, RGB_BLACK); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 4: ShowBg(0); ShowBg(1); ShowBg(3); ShowBg(2); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 5: - SetVBlankCallback(sub_8166340); + SetVBlankCallback(VBlankCB_UsePokeblockMenu); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 6: if (!gPaletteFade.active) { - sub_81D3464(gUnknown_0203BCAC->field_7B1C); - sub_816636C(sub_8166A34); - SetMainCallback2(sub_816631C); + ResetConditionSparkleSprites(sMenu->sparkles); + SetUsePokeblockCallback(ShowPokeblockResults); + SetMainCallback2(CB2_UsePokeblockMenu); } break; } } -void sub_8166A34(void) +static void ShowPokeblockResults(void) { u8 var; - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: - gUnknown_0203BC90->mon = gPlayerParty; - gUnknown_0203BC90->mon += gUnknown_0203BCAC->field_7FB8[gUnknown_0203BCAC->info.field_71].unk1; - sub_81D3520(gUnknown_0203BCAC->field_7B1C); - gUnknown_0203BC90->field_50++; + sInfo->mon = gPlayerParty; + sInfo->mon += sMenu->party[sMenu->info.curSelection].monId; + DestroyConditionSparkleSprites(sMenu->sparkles); + sInfo->mainState++; break; case 1: - if (gMain.newKeys & (A_BUTTON | B_BUTTON)) - gUnknown_0203BC90->field_50++; + if (JOY_NEW(A_BUTTON | B_BUTTON)) + sInfo->mainState++; break; case 2: - sub_8167104(); - sub_81D2754(gUnknown_0203BC90->field_5c, gUnknown_0203BCAC->field_7C58.unk14[3]); - sub_81D1F84(&gUnknown_0203BCAC->field_7C58, gUnknown_0203BCAC->field_7C58.unk14[gUnknown_0203BCAC->field_7FB3], gUnknown_0203BCAC->field_7C58.unk14[3]); - sub_8167338(); - gUnknown_0203BC90->field_50++; + CalculateConditionEnhancements(); + sub_81D2754(sInfo->conditionsAfterBlock, sMenu->graph.unk14[3]); + sub_81D1F84(&sMenu->graph, sMenu->graph.unk14[sMenu->curLoadId], sMenu->graph.unk14[3]); + LoadAndCreateUpDownSprites(); + sInfo->mainState++; break; case 3: - var = sub_81D2074(&gUnknown_0203BCAC->field_7C58); + var = TransitionConditionGraph(&sMenu->graph); if (!var) { - sub_81681F4(sub_81672A4(gUnknown_0203BCAC->info.field_71)); - if (gUnknown_0203BCAC->info.field_71 != gUnknown_0203BCAC->info.field_70 - 1) + CalculateNumAdditionalSparkles(GetPartyIdFromSelectionId(sMenu->info.curSelection)); + if (sMenu->info.curSelection != sMenu->info.numSelections - 1) { - u8 var0 = gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->field_7FB3]; - sub_81D3480(gUnknown_0203BCAC->field_7B1C, gUnknown_0203BCAC->field_7B10, var0); + u8 numSparkles = sMenu->numSparkles[sMenu->curLoadId]; + CreateConditionSparkleSprites(sMenu->sparkles, sMenu->curMonSpriteId, numSparkles); } - gUnknown_0203BC90->field_52 = 0; - gUnknown_0203BC90->field_50++; + sInfo->timer = 0; + sInfo->mainState++; } break; case 4: - if (++gUnknown_0203BC90->field_52 > 16) + if (++sInfo->timer > 16) { - sub_8166E24(); - gUnknown_0203BC90->field_50++; + PrintFirstEnhancement(); + sInfo->mainState++; } break; case 5: - if (gMain.newKeys & (A_BUTTON | B_BUTTON) && !sub_8166EDC()) + if (JOY_NEW(A_BUTTON | B_BUTTON) && !TryPrintNextEnhancement()) { TryClearPokeblock((u8)gSpecialVar_ItemId); - sub_816636C(sub_8166BEC); + SetUsePokeblockCallback(CloseUsePokeblockMenu); } break; } } -void sub_8166BEC(void) +static void CloseUsePokeblockMenu(void) { - u8 i, var; + u8 i; - switch (gUnknown_0203BC90->field_50) + switch (sInfo->mainState) { case 0: BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 1: if (!gPaletteFade.active) - gUnknown_0203BC90->field_50 = 2; + sInfo->mainState = 2; break; case 2: gScanlineEffect.state = 3; ScanlineEffect_InitHBlankDmaTransfer(); - gUnknown_0203BC90->field_50++; + sInfo->mainState++; break; case 3: - SetMainCallback2(gUnknown_0203BC90->callback); - sub_81D354C(gUnknown_0203BCAC->field_7B1C); - for (i = 0; i < 7; i++) - DestroySprite(&gSprites[gUnknown_0203BCAC->field_7B06[i]]); + SetMainCallback2(sInfo->exitCallback); + FreeConditionSparkles(sMenu->sparkles); + for (i = 0; i < ARRAY_COUNT(sMenu->selectionIconSpriteIds); i++) + DestroySprite(&gSprites[sMenu->selectionIconSpriteIds[i]]); - FreeSpriteTilesByTag(0); - FreeSpriteTilesByTag(1); - FreeSpritePaletteByTag(0); - FreeSpritePaletteByTag(1); + FreeSpriteTilesByTag(TAG_UP_DOWN); + FreeSpriteTilesByTag(TAG_CONDITION); + FreeSpritePaletteByTag(TAG_UP_DOWN); + FreeSpritePaletteByTag(TAG_CONDITION); - for (i = 0; i < 2; i++) - DestroySprite(gUnknown_0203BCAC->field_7B44[i]); + for (i = 0; i < ARRAY_COUNT(sMenu->condition); i++) + DestroySprite(sMenu->condition[i]); - if (gUnknown_0203BCAC->field_7B10 != 0xFF) - DestroySprite(&gSprites[gUnknown_0203BCAC->field_7B10]); + if (sMenu->curMonSpriteId != 0xFF) + DestroySprite(&gSprites[sMenu->curMonSpriteId]); SetVBlankCallback(NULL); - FREE_AND_SET_NULL(gUnknown_0203BCA0); - FREE_AND_SET_NULL(gUnknown_0203BCA4); - FREE_AND_SET_NULL(gUnknown_0203BCA8); - FREE_AND_SET_NULL(gUnknown_0203BCAC); + FREE_AND_SET_NULL(sGraph_Tilemap); + FREE_AND_SET_NULL(sGraph_Gfx); + FREE_AND_SET_NULL(sMonFrame_TilemapPtr); + FREE_AND_SET_NULL(sMenu); FreeAllWindowBuffers(); break; } } -void sub_8166D44(void) +static void AskUsePokeblock(void) { u8 stringBuffer[0x40]; - GetMonData(&gPlayerParty[sub_81672A4(gUnknown_0203BCAC->info.field_71)], MON_DATA_NICKNAME, stringBuffer); + GetMonData(&gPlayerParty[GetPartyIdFromSelectionId(sMenu->info.curSelection)], MON_DATA_NICKNAME, stringBuffer); StringGetEnd10(stringBuffer); StringAppend(stringBuffer, gText_GetsAPokeBlockQuestion); StringCopy(gStringVar4, stringBuffer); - FillWindowPixelBuffer(2, 17); - DrawTextBorderOuter(2, 151, 14); - AddTextPrinterParameterized(2, 1, gStringVar4, 0, 1, 0, NULL); - PutWindowTilemap(2); - CopyWindowToVram(2, 3); + FillWindowPixelBuffer(WIN_TEXT, 17); + DrawTextBorderOuter(WIN_TEXT, 151, 14); + AddTextPrinterParameterized(WIN_TEXT, 1, gStringVar4, 0, 1, 0, NULL); + PutWindowTilemap(WIN_TEXT); + CopyWindowToVram(WIN_TEXT, 3); CreateYesNoMenu(&sUsePokeblockYesNoWinTemplate, 151, 14, 0); } -s8 sub_8166DE4(void) +static s8 HandleAskUsePokeblockInput(void) { s8 menuItem = Menu_ProcessInputNoWrapClearOnChoose(); switch (menuItem) { - case 0: + case 0: // YES break; case MENU_B_PRESSED: - case 1: + case 1: // NO PlaySE(SE_SELECT); rbox_fill_rectangle(2); ClearWindowTilemap(2); @@ -869,84 +900,84 @@ s8 sub_8166DE4(void) return menuItem; } -void sub_8166E24(void) +static void PrintFirstEnhancement(void) { - DrawTextBorderOuter(2, 151, 14); - FillWindowPixelBuffer(2, 17); + DrawTextBorderOuter(WIN_TEXT, 151, 14); + FillWindowPixelBuffer(WIN_TEXT, 17); - for (gUnknown_0203BC90->field_53 = 0; gUnknown_0203BC90->field_53 < 5; gUnknown_0203BC90->field_53++) + for (sInfo->statId = 0; sInfo->statId < FLAVOR_COUNT; sInfo->statId++) { - if (gUnknown_0203BC90->field_61[gUnknown_0203BC90->field_53] != 0) + if (sInfo->enhancements[sInfo->statId] != 0) break; } - if (gUnknown_0203BC90->field_53 < 5) - Pokeblock_BufferEnhancedStatText(gStringVar4, gUnknown_0203BC90->field_53, gUnknown_0203BC90->field_61[gUnknown_0203BC90->field_53]); + if (sInfo->statId < FLAVOR_COUNT) + BufferEnhancedStatText(gStringVar4, sInfo->statId, sInfo->enhancements[sInfo->statId]); else - Pokeblock_BufferEnhancedStatText(gStringVar4, gUnknown_0203BC90->field_53, 0); + BufferEnhancedStatText(gStringVar4, sInfo->statId, 0); - Pokeblock_MenuWindowTextPrint(gStringVar4); - PutWindowTilemap(2); - CopyWindowToVram(2, 3); + PrintMenuWindowText(gStringVar4); + PutWindowTilemap(WIN_TEXT); + CopyWindowToVram(WIN_TEXT, 3); } -bool8 sub_8166EDC(void) +static bool8 TryPrintNextEnhancement(void) { - FillWindowPixelBuffer(2, 17); + FillWindowPixelBuffer(WIN_TEXT, 17); while (1) { - gUnknown_0203BC90->field_53++; - if (gUnknown_0203BC90->field_53 < 5) + sInfo->statId++; + if (sInfo->statId < FLAVOR_COUNT) { - if (gUnknown_0203BC90->field_61[gUnknown_0203BC90->field_53] != 0) + if (sInfo->enhancements[sInfo->statId] != 0) break; } else { - gUnknown_0203BC90->field_53 = 5; + sInfo->statId = FLAVOR_COUNT; return FALSE; } } - Pokeblock_BufferEnhancedStatText(gStringVar4, gUnknown_0203BC90->field_53, gUnknown_0203BC90->field_61[gUnknown_0203BC90->field_53]); - Pokeblock_MenuWindowTextPrint(gStringVar4); - CopyWindowToVram(2, 2); + BufferEnhancedStatText(gStringVar4, sInfo->statId, sInfo->enhancements[sInfo->statId]); + PrintMenuWindowText(gStringVar4); + CopyWindowToVram(WIN_TEXT, 2); return TRUE; } -void sub_8166F50(void) +static void PrintWontEatAnymore(void) { - FillWindowPixelBuffer(2, 17); - DrawTextBorderOuter(2, 151, 14); - AddTextPrinterParameterized(2, 1, gText_WontEatAnymore, 0, 1, 0, NULL); - PutWindowTilemap(2); - CopyWindowToVram(2, 3); + FillWindowPixelBuffer(WIN_TEXT, 17); + DrawTextBorderOuter(WIN_TEXT, 151, 14); + AddTextPrinterParameterized(WIN_TEXT, 1, gText_WontEatAnymore, 0, 1, 0, NULL); + PutWindowTilemap(WIN_TEXT); + CopyWindowToVram(WIN_TEXT, 3); } -void sub_8166F94(void) +static void EraseMenuWindow(void) { - rbox_fill_rectangle(2); - ClearWindowTilemap(2); - CopyWindowToVram(2, 3); + rbox_fill_rectangle(WIN_TEXT); + ClearWindowTilemap(WIN_TEXT); + CopyWindowToVram(WIN_TEXT, 3); } -void Pokeblock_MenuWindowTextPrint(const u8 *message) +static void PrintMenuWindowText(const u8 *message) { - AddTextPrinterParameterized(2, 1, gStringVar4, 0, 1, 0, NULL); + AddTextPrinterParameterized(WIN_TEXT, 1, gStringVar4, 0, 1, 0, NULL); } -void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 a2) +static void BufferEnhancedStatText(u8 *dest, u8 statId, s16 enhancement) { - switch (a2) + switch (enhancement) { - case 1 ... 32767: - a2 = 0; + case 1 ... 32767: // if > 0 + enhancement = 0; // fallthrough - case -32768 ... -1: - if (a2) - dest[(u16)a2] += 0; // something you can't imagine + case -32768 ... -1: // if < 0 + if (enhancement) + dest[(u16)enhancement] += 0; // something you can't imagine StringCopy(dest, sContestStatNames[statId]); StringAppend(dest, gText_WasEnhanced); break; @@ -956,15 +987,15 @@ void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 a2) } } -void Pokeblock_GetMonContestStats(struct Pokemon *mon, u8 *data) +static void GetMonConditions(struct Pokemon *mon, u8 *data) { u16 i; - for (i = 0; i < 5; i++) - data[i] = GetMonData(mon, gUnknown_085DFCB0[i]); + for (i = 0; i < FLAVOR_COUNT; i++) + data[i] = GetMonData(mon, sMonDataConditions[i]); } -void sub_8167054(struct Pokeblock *pokeblock, struct Pokemon *mon) +static void AddPokeblockToConditions(struct Pokeblock *pokeblock, struct Pokemon *mon) { u16 i; s16 cstat; @@ -972,17 +1003,17 @@ void sub_8167054(struct Pokeblock *pokeblock, struct Pokemon *mon) if (GetMonData(mon, MON_DATA_SHEEN) != 255) { - sub_8167184(pokeblock, mon); - for (i = 0; i < 5; i++) + CalculatePokeblockEffectiveness(pokeblock, mon); + for (i = 0; i < FLAVOR_COUNT; i++) { - data = GetMonData(mon, gUnknown_085DFCB0[i]); - cstat = data + gUnknown_0203BC90->field_66[i]; + data = GetMonData(mon, sMonDataConditions[i]); + cstat = data + sInfo->pokeblockStatBoosts[i]; if (cstat < 0) cstat = 0; if (cstat > 255) cstat = 255; data = cstat; - SetMonData(mon, gUnknown_085DFCB0[i], &data); + SetMonData(mon, sMonDataConditions[i], &data); } cstat = (u8)(GetMonData(mon, MON_DATA_SHEEN)) + pokeblock->feel; @@ -994,28 +1025,28 @@ void sub_8167054(struct Pokeblock *pokeblock, struct Pokemon *mon) } } -void sub_8167104(void) +static void CalculateConditionEnhancements(void) { u16 i; struct Pokemon *mon = gPlayerParty; - mon += gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->info.field_71 * 4 + 9]; + mon += sMenu->party[sMenu->info.curSelection].monId; - Pokeblock_GetMonContestStats(mon, gUnknown_0203BC90->field_57); - sub_8167054(gUnknown_0203BC90->pokeblock, mon); - Pokeblock_GetMonContestStats(mon, gUnknown_0203BC90->field_5c); - for (i = 0; i < 5; i++) - gUnknown_0203BC90->field_61[i] = gUnknown_0203BC90->field_5c[i] - gUnknown_0203BC90->field_57[i]; + GetMonConditions(mon, sInfo->conditionsBeforeBlock); + AddPokeblockToConditions(sInfo->pokeblock, mon); + GetMonConditions(mon, sInfo->conditionsAfterBlock); + for (i = 0; i < FLAVOR_COUNT; i++) + sInfo->enhancements[i] = sInfo->conditionsAfterBlock[i] - sInfo->conditionsBeforeBlock[i]; } -void sub_8167184(struct Pokeblock *pokeblock, struct Pokemon *mon) +static void CalculatePokeblockEffectiveness(struct Pokeblock *pokeblock, struct Pokemon *mon) { s8 i, direction, taste; - gUnknown_0203BC90->field_66[0] = pokeblock->spicy; - gUnknown_0203BC90->field_66[1] = pokeblock->sour; - gUnknown_0203BC90->field_66[2] = pokeblock->bitter; - gUnknown_0203BC90->field_66[3] = pokeblock->sweet; - gUnknown_0203BC90->field_66[4] = pokeblock->dry; + sInfo->pokeblockStatBoosts[0] = pokeblock->spicy; + sInfo->pokeblockStatBoosts[1] = pokeblock->sour; + sInfo->pokeblockStatBoosts[2] = pokeblock->bitter; + sInfo->pokeblockStatBoosts[3] = pokeblock->sweet; + sInfo->pokeblockStatBoosts[4] = pokeblock->dry; if (gPokeblockGain > 0) direction = 1; @@ -1024,24 +1055,24 @@ void sub_8167184(struct Pokeblock *pokeblock, struct Pokemon *mon) else return; - for (i = 0; i < 5; i++) + for (i = 0; i < FLAVOR_COUNT; i++) { - s16 amount = gUnknown_0203BC90->field_66[i]; + s16 amount = sInfo->pokeblockStatBoosts[i]; s8 boost = amount / 10; if (amount % 10 >= 5) // round to the nearest boost++; - taste = GetMonFlavorRelation(mon, gUnknown_085DFCC4[i]); + taste = GetMonFlavorRelation(mon, sFlavors[i]); if (taste == direction) - gUnknown_0203BC90->field_66[i] += boost * taste; + sInfo->pokeblockStatBoosts[i] += boost * taste; } } -bool8 IsSheenMaxed(void) +static bool8 IsSheenMaxed(void) { - if (GetBoxOrPartyMonData(gUnknown_0203BCAC->field_7FB8[gUnknown_0203BCAC->info.field_71].unk0, - gUnknown_0203BCAC->field_7FB8[gUnknown_0203BCAC->info.field_71].unk1, + if (GetBoxOrPartyMonData(sMenu->party[sMenu->info.curSelection].boxId, + sMenu->party[sMenu->info.curSelection].monId, MON_DATA_SHEEN, NULL) == 255) return TRUE; @@ -1049,7 +1080,7 @@ bool8 IsSheenMaxed(void) return FALSE; } -u8 sub_81672A4(u8 a0) +static u8 GetPartyIdFromSelectionId(u8 selectionId) { u8 i; @@ -1057,58 +1088,58 @@ u8 sub_81672A4(u8 a0) { if (!GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { - if (a0 == 0) + if (selectionId == 0) return i; - a0--; + selectionId--; } } return 0; } -u8 sub_81672E4(u8 partyCount) +// Eggs are not viewable on the condition screen, so count how many are skipped over to reach the party id +static u8 GetSelectionIdFromPartyId(u8 partyId) { u8 i, numEggs; - - for (i = 0, numEggs = 0; i < partyCount; i++) + for (i = 0, numEggs = 0; i < partyId; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) numEggs++; } - return partyCount - numEggs; + return partyId - numEggs; } -u8 sub_8167324(u8 a0) +// Unused +static u8 GetPartyIdFromSelectionId_(u8 selectionId) { - return sub_81672A4(a0); + return GetPartyIdFromSelectionId(selectionId); } -void sub_8167338(void) +static void LoadAndCreateUpDownSprites(void) { u16 i, spriteId; - LoadSpriteSheet(&gSpriteSheet_ConditionUpDown); - LoadSpritePalette(&gSpritePalette_ConditionUpDown); - gUnknown_0203BC90->field_54 = 0; + LoadSpriteSheet(&sSpriteSheet_UpDown); + LoadSpritePalette(&sSpritePalette_UpDown); + sInfo->numEnhancements = 0; - for (i = 0; i < 5; i++) + for (i = 0; i < FLAVOR_COUNT; i++) { - if (gUnknown_0203BC90->field_61[i] != 0) + if (sInfo->enhancements[i] != 0) { - spriteId = CreateSprite(&gSpriteTemplate_085DFD5C, gUnknown_085DFD28[i][0], gUnknown_085DFD28[i][1], 0); + spriteId = CreateSprite(&sSpriteTemplate_UpDown, sUpDownCoordsOnGraph[i][0], sUpDownCoordsOnGraph[i][1], 0); if (spriteId != MAX_SPRITES) { - if (gUnknown_0203BC90->field_61[i] != 0) - gSprites[spriteId].callback = sub_81673DC; - - gUnknown_0203BC90->field_54++; + if (sInfo->enhancements[i] != 0) // Always true here + gSprites[spriteId].callback = SpriteCB_UpDown; + sInfo->numEnhancements++; } } } } -void sub_81673DC(struct Sprite *sprite) +static void SpriteCB_UpDown(struct Sprite *sprite) { if (sprite->data[0] < 6) sprite->pos2.y -= 2; @@ -1118,11 +1149,11 @@ void sub_81673DC(struct Sprite *sprite) if (++sprite->data[0] > 60) { DestroySprite(sprite); - gUnknown_0203BC90->field_54--; + sInfo->numEnhancements--; } } -void sub_8167420(void) +static void LoadPartyInfo(void) { u16 i; u16 numMons; @@ -1131,91 +1162,91 @@ void sub_8167420(void) { if (!GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { - gUnknown_0203BCAC->field_7FB8[numMons].unk0 = 14; - gUnknown_0203BCAC->field_7FB8[numMons].unk1 = i; - gUnknown_0203BCAC->field_7FB8[numMons].unk2 = 0; + sMenu->party[numMons].boxId = TOTAL_BOXES_COUNT; + sMenu->party[numMons].monId = i; + sMenu->party[numMons].data = 0; numMons++; } } - gUnknown_0203BCAC->info.field_71 = 0; - gUnknown_0203BCAC->info.field_70 = numMons + 1; - sub_81674BC(); + sMenu->info.curSelection = 0; + sMenu->info.numSelections = numMons + 1; + LoadInitialMonInfo(); } -void sub_81674BC(void) +static void LoadInitialMonInfo(void) { - s16 var, var2; + s16 nextSelection, prevSelection; - sub_816753C(gUnknown_0203BCAC->info.field_71, 0); - gUnknown_0203BCAC->field_7FB3 = 0; - gUnknown_0203BCAC->field_7FB4 = 1; - gUnknown_0203BCAC->field_7FB5 = 2; + LoadMonInfo(sMenu->info.curSelection, 0); + sMenu->curLoadId = 0; + sMenu->nextLoadId = 1; + sMenu->prevLoadId = 2; - var = gUnknown_0203BCAC->info.field_71 + 1; - if (var >= gUnknown_0203BCAC->info.field_70) - var = 0; + nextSelection = sMenu->info.curSelection + 1; + if (nextSelection >= sMenu->info.numSelections) + nextSelection = 0; - var2 = gUnknown_0203BCAC->info.field_71 - 1; - if (var2 < 0) - var2 = gUnknown_0203BCAC->info.field_70 - 1; + prevSelection = sMenu->info.curSelection - 1; + if (prevSelection < 0) + prevSelection = sMenu->info.numSelections - 1; - sub_816753C(var, 1); - sub_816753C(var2, 2); + LoadMonInfo(nextSelection, 1); + LoadMonInfo(prevSelection, 2); } -void sub_816753C(s16 id1, u8 id2) +static void LoadMonInfo(s16 partyId, u8 loadId) { - u8 boxId = gUnknown_0203BCAC->field_7FB8[id1].unk0; - u8 monId = gUnknown_0203BCAC->field_7FB8[id1].unk1; - u8 r6 = gUnknown_0203BCAC->info.field_70; - bool8 r8 = FALSE; + u8 boxId = sMenu->party[partyId].boxId; + u8 monId = sMenu->party[partyId].monId; + u8 numSelections = sMenu->info.numSelections; + bool8 excludesCancel = FALSE; // whether or not numSelections excludes Cancel from the count - sub_81D2ED4(gUnknown_0203BCAC->field_7B4D[id2], gUnknown_0203BCAC->field_7B95[id2], boxId, monId, id1, r6, r8); - sub_81D2F78(&gUnknown_0203BCAC->field_7C58, gUnknown_0203BCAC->unk7FB0, boxId, monId, id1, id2, r6, r8); - sub_81D3094(gUnknown_0203BCAC->field_304[id2], gUnknown_0203BCAC->field_4[id2], boxId, monId, id1, r6, r8); + GetConditionMenuMonNameAndLocString(sMenu->locationStrings[loadId], sMenu->monNameStrings[loadId], boxId, monId, partyId, numSelections, excludesCancel); + GetConditionMenuMonConditions(&sMenu->graph, sMenu->numSparkles, boxId, monId, partyId, loadId, numSelections, excludesCancel); + GetConditionMenuMonGfx(sMenu->partySheets[loadId], sMenu->partyPalettes[loadId], boxId, monId, partyId, numSelections, excludesCancel); } -void sub_8167608(u8 arg0) +static void UpdateMonPic(u8 loadId) { u8 spriteId; struct SpriteTemplate spriteTemplate; struct SpriteSheet spriteSheet; struct SpritePalette spritePal; - if (gUnknown_0203BCAC->field_7B10 == 0xFF) + if (sMenu->curMonSpriteId == 0xFF) { - sub_81D31D0(&spriteSheet, &spriteTemplate, &spritePal); - spriteSheet.data = gUnknown_0203BCAC->field_304[arg0]; - spritePal.data = gUnknown_0203BCAC->field_4[arg0]; - gUnknown_0203BCAC->field_7B12 = LoadSpritePalette(&spritePal); - gUnknown_0203BCAC->field_7B14 = LoadSpriteSheet(&spriteSheet); + LoadConditionMonPicTemplate(&spriteSheet, &spriteTemplate, &spritePal); + spriteSheet.data = sMenu->partySheets[loadId]; + spritePal.data = sMenu->partyPalettes[loadId]; + sMenu->curMonPalette = LoadSpritePalette(&spritePal); + sMenu->curMonSheet = LoadSpriteSheet(&spriteSheet); spriteId = CreateSprite(&spriteTemplate, 38, 104, 0); - gUnknown_0203BCAC->field_7B10 = spriteId; + sMenu->curMonSpriteId = spriteId; if (spriteId == MAX_SPRITES) { - FreeSpriteTilesByTag(100); - FreeSpritePaletteByTag(100); - gUnknown_0203BCAC->field_7B10 = 0xFF; + FreeSpriteTilesByTag(TAG_CONDITION_MON); + FreeSpritePaletteByTag(TAG_CONDITION_MON); + sMenu->curMonSpriteId = 0xFF; } else { - gUnknown_0203BCAC->field_7B10 = spriteId; - gSprites[gUnknown_0203BCAC->field_7B10].callback = sub_8168168; - gSprites[gUnknown_0203BCAC->field_7B10].pos2.y -= 34; - gUnknown_0203BCAC->field_7B18 = (void*)(OBJ_VRAM0 + (gUnknown_0203BCAC->field_7B14 * 32)); - gUnknown_0203BCAC->field_7B12 = (gUnknown_0203BCAC->field_7B12 * 16) + 0x100; + sMenu->curMonSpriteId = spriteId; + gSprites[sMenu->curMonSpriteId].callback = SpriteCB_MonPic; + gSprites[sMenu->curMonSpriteId].pos2.y -= 34; + sMenu->curMonTileStart = (void*)(OBJ_VRAM0 + (sMenu->curMonSheet * 32)); + sMenu->curMonPalette = (sMenu->curMonPalette * 16) + 0x100; } } else { - do {} while(0); // Surprised to see something like this? It's a very neat trick for generating the same assembly. It has no practical purpose, feel free to remove it. - DmaCopy16Defvars(3, gUnknown_0203BCAC->field_304[arg0], gUnknown_0203BCAC->field_7B18, 0x800); - LoadPalette(gUnknown_0203BCAC->field_4[arg0], gUnknown_0203BCAC->field_7B12, 32); + do {} while(0); // Only needed to match, feel free to remove. + DmaCopy16Defvars(3, sMenu->partySheets[loadId], sMenu->curMonTileStart, 0x800); + LoadPalette(sMenu->partyPalettes[loadId], sMenu->curMonPalette, 32); } } -void sub_8167760(void) +static void LoadAndCreateSelectionIcons(void) { u16 i, spriteId; struct SpriteSheet spriteSheets[4]; @@ -1224,62 +1255,65 @@ void sub_8167760(void) struct SpriteSheet spriteSheet2; struct SpritePalette spritePal2; - sub_81D321C(spriteSheets, &spriteTemplate, spritePals); + LoadConditionSelectionIcons(spriteSheets, &spriteTemplate, spritePals); LoadSpriteSheets(spriteSheets); LoadSpritePalettes(spritePals); - for (i = 0; i < gUnknown_0203BCAC->info.field_70 - 1; i++) + // Fill pokeball selection icons up to number in party + for (i = 0; i < sMenu->info.numSelections - 1; i++) { spriteId = CreateSprite(&spriteTemplate, 226, (i * 20) + 8, 0); if (spriteId != MAX_SPRITES) { - gUnknown_0203BCAC->field_7B06[i] = spriteId; + sMenu->selectionIconSpriteIds[i] = spriteId; gSprites[spriteId].data[0] = i; - gSprites[spriteId].callback = sub_8168180; + gSprites[spriteId].callback = SpriteCB_SelectionIconPokeball; } else { - gUnknown_0203BCAC->field_7B06[i] = -1; + sMenu->selectionIconSpriteIds[i] = -1; } } - spriteTemplate.tileTag = 103; - for (; i < 6; i++) + // Fill placeholder icons for remaining (empty) party slots + spriteTemplate.tileTag = TAG_CONDITION_BALL_PLACEHOLDER; + for (; i < PARTY_SIZE; i++) { spriteId = CreateSprite(&spriteTemplate, 230, (i * 20) + 8, 0); if (spriteId != MAX_SPRITES) { - gUnknown_0203BCAC->field_7B06[i] = spriteId; + sMenu->selectionIconSpriteIds[i] = spriteId; gSprites[spriteId].oam.size = 0; } else { - gUnknown_0203BCAC->field_7B06[i] = -1; + sMenu->selectionIconSpriteIds[i] = -1; } } - spriteTemplate.tileTag = 102; - spriteTemplate.callback = sub_81681B4; + // Add cancel selection icon at bottom + spriteTemplate.tileTag = TAG_CONDITION_CANCEL; + spriteTemplate.callback = SpriteCB_SelectionIconCancel; spriteId = CreateSprite(&spriteTemplate, 222, (i * 20) + 8, 0); if (spriteId != MAX_SPRITES) { - gUnknown_0203BCAC->field_7B06[i] = spriteId; + sMenu->selectionIconSpriteIds[i] = spriteId; gSprites[spriteId].oam.shape = SPRITE_SHAPE(32x16); gSprites[spriteId].oam.size = SPRITE_SIZE(32x16); } else { - gUnknown_0203BCAC->field_7B06[i] = -1; + sMenu->selectionIconSpriteIds[i] = -1; } - sub_81D32B0(&spriteSheet2, &spritePal2); + LoadConditionSparkle(&spriteSheet2, &spritePal2); LoadSpriteSheet(&spriteSheet2); LoadSpritePalette(&spritePal2); } -bool8 sub_8167930(void) +static bool8 LoadUsePokeblockMenuGfx(void) { - switch (gUnknown_0203BCAC->info.unk78) + switch (sMenu->info.helperState) { case 0: ChangeBgX(0, 0, 0); @@ -1290,296 +1324,308 @@ bool8 sub_8167930(void) ChangeBgY(2, 0, 0); ChangeBgX(3, 0, 0); ChangeBgY(3, 136 << 6, 0); - SetGpuReg(REG_OFFSET_DISPCNT, 28736); - SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG2|BLDCNT_EFFECT_BLEND|BLDCNT_TGT2_BG1); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON | DISPCNT_WIN0_ON | DISPCNT_WIN1_ON); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(11, 4)); break; case 1: - gUnknown_0203BCA4 = Alloc(6656); - gUnknown_0203BCA0 = Alloc(1280); - gUnknown_0203BCA8 = Alloc(1280); + sGraph_Gfx = Alloc(6656); + sGraph_Tilemap = Alloc(1280); + sMonFrame_TilemapPtr = Alloc(1280); break; case 2: - LZ77UnCompVram(gUnknown_085DFB60, gUnknown_0203BCA8); + LZ77UnCompVram(sMonFrame_Tilemap, sMonFrame_TilemapPtr); break; case 3: - LoadBgTiles(3, gUnknown_085DFA80, 224, 0); + LoadBgTiles(3, sMonFrame_Gfx, 224, 0); break; case 4: - LoadBgTilemap(3, gUnknown_0203BCA8, 1280, 0); + LoadBgTilemap(3, sMonFrame_TilemapPtr, 1280, 0); break; case 5: - LoadPalette(gUnknown_085DFA60, 208, 32); - gUnknown_0203BCAC->field_7B0E = 0xFFB0; + LoadPalette(sMonFrame_Pal, 208, 32); + sMenu->curMonXOffset = -80; break; case 6: - LZ77UnCompVram(gUsePokeblockGraph_Gfx, gUnknown_0203BCA4); + LZ77UnCompVram(gUsePokeblockGraph_Gfx, sGraph_Gfx); break; case 7: - LZ77UnCompVram(gUsePokeblockGraph_Tilemap, gUnknown_0203BCA0); + LZ77UnCompVram(gUsePokeblockGraph_Tilemap, sGraph_Tilemap); LoadPalette(gUsePokeblockGraph_Pal, 32, 32); break; case 8: - LoadBgTiles(1, gUnknown_0203BCA4, 6656, 160 << 2); + LoadBgTiles(1, sGraph_Gfx, 6656, 160 << 2); break; case 9: - SetBgTilemapBuffer(1, gUnknown_0203BCA0); + SetBgTilemapBuffer(1, sGraph_Tilemap); CopyToBgTilemapBufferRect(1, gUsePokeblockNatureWin_Pal, 0, 13, 12, 4); CopyBgTilemapBufferToVram(1); break; case 10: - LZ77UnCompVram(gUnknown_085DFC0C, gUnknown_0203BCAC->tilemapBuffer); + LZ77UnCompVram(sGraphData_Tilemap, sMenu->tilemapBuffer); break; case 11: - LoadBgTilemap(2, gUnknown_0203BCAC->tilemapBuffer, 1280, 0); - LoadPalette(gUnknown_086231E8, 48, 32); - LoadPalette(gUnknown_08623208, 240, 32); + LoadBgTilemap(2, sMenu->tilemapBuffer, 1280, 0); + LoadPalette(gConditionGraphData_Pal, 48, 32); + LoadPalette(gConditionText_Pal, 240, 32); sub_81D21DC(2); break; default: - gUnknown_0203BCAC->info.unk78 = 0; + sMenu->info.helperState = 0; return FALSE; } - gUnknown_0203BCAC->info.unk78++; + sMenu->info.helperState++; return TRUE; } -void sub_8167BA0(u16 arg0, u8 copyToVramMode) +static void UpdateMonInfoText(u16 loadId, bool8 firstPrint) { u8 partyIndex; u8 nature; u8 *str; - FillWindowPixelBuffer(0, PIXEL_FILL(0)); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - if (gUnknown_0203BCAC->info.field_71 != gUnknown_0203BCAC->info.field_70 - 1) + FillWindowPixelBuffer(WIN_NAME, PIXEL_FILL(0)); + FillWindowPixelBuffer(WIN_NATURE, PIXEL_FILL(0)); + if (sMenu->info.curSelection != sMenu->info.numSelections - 1) { - AddTextPrinterParameterized(0, 1, gUnknown_0203BCAC->field_7B95[arg0], 0, 1, 0, NULL); - partyIndex = sub_81672A4(gUnknown_0203BCAC->info.field_71); + AddTextPrinterParameterized(WIN_NAME, 1, sMenu->monNameStrings[loadId], 0, 1, 0, NULL); + partyIndex = GetPartyIdFromSelectionId(sMenu->info.curSelection); nature = GetNature(&gPlayerParty[partyIndex]); - str = StringCopy(gUnknown_0203BCAC->info.field_7A, gText_NatureSlash); + str = StringCopy(sMenu->info.natureText, gText_NatureSlash); str = StringCopy(str, gNatureNamePointers[nature]); - AddTextPrinterParameterized3(1, 1, 2, 1, sNatureTextColors, 0, gUnknown_0203BCAC->info.field_7A); + AddTextPrinterParameterized3(WIN_NATURE, 1, 2, 1, sNatureTextColors, 0, sMenu->info.natureText); } - if (copyToVramMode) + if (firstPrint) { - CopyWindowToVram(0, 3); - CopyWindowToVram(1, 3); + CopyWindowToVram(WIN_NAME, 3); + CopyWindowToVram(WIN_NATURE, 3); } else { - CopyWindowToVram(0, 2); - CopyWindowToVram(1, 2); + CopyWindowToVram(WIN_NAME, 2); + CopyWindowToVram(WIN_NATURE, 2); } } -static void sub_8167CA0(bool8 arg0) +static void UpdateSelection(bool8 up) { - u16 var0; - bool32 r8, r4; + u16 newLoadId; + bool32 startedOnMon, endedOnMon; - if (arg0) - var0 = gUnknown_0203BCAC->field_7FB5; + if (up) + newLoadId = sMenu->prevLoadId; else - var0 = gUnknown_0203BCAC->field_7FB4; + newLoadId = sMenu->nextLoadId; - sub_81D1F84( - &gUnknown_0203BCAC->field_7C58, - gUnknown_0203BCAC->field_7C58.unk14[gUnknown_0203BCAC->field_7FB3], - gUnknown_0203BCAC->field_7C58.unk14[var0]); + sub_81D1F84(&sMenu->graph, sMenu->graph.unk14[sMenu->curLoadId], sMenu->graph.unk14[newLoadId]); - r8 = (gUnknown_0203BCAC->info.field_71 ^ (gUnknown_0203BCAC->info.field_70 - 1)) ? 1 : 0; - if (arg0) + if (sMenu->info.curSelection == sMenu->info.numSelections - 1) + startedOnMon = FALSE; // moving off of Cancel + else + startedOnMon = TRUE; + + if (up) { - gUnknown_0203BCAC->field_7FB5 = gUnknown_0203BCAC->field_7FB4; - gUnknown_0203BCAC->field_7FB4 = gUnknown_0203BCAC->field_7FB3; - gUnknown_0203BCAC->field_7FB3 = var0; - gUnknown_0203BCAC->field_7FB6 = gUnknown_0203BCAC->field_7FB5; + sMenu->prevLoadId = sMenu->nextLoadId; // temporarily store nextLoadId, prevLoadId no longer needed + sMenu->nextLoadId = sMenu->curLoadId; + sMenu->curLoadId = newLoadId; + sMenu->toLoadId = sMenu->prevLoadId; // next load will be the mon that's one up from new selection - gUnknown_0203BCAC->info.field_71 = (gUnknown_0203BCAC->info.field_71 == 0) - ? gUnknown_0203BCAC->info.field_70 - 1 - : gUnknown_0203BCAC->info.field_71 - 1; + // Check for wrap to bottom of list + sMenu->info.curSelection = (sMenu->info.curSelection == 0) + ? sMenu->info.numSelections - 1 + : sMenu->info.curSelection - 1; - gUnknown_0203BCAC->field_7B4C = (gUnknown_0203BCAC->info.field_71 == 0) - ? gUnknown_0203BCAC->info.field_70 - 1 - : gUnknown_0203BCAC->info.field_71 - 1; + sMenu->toLoadSelection = (sMenu->info.curSelection == 0) + ? sMenu->info.numSelections - 1 + : sMenu->info.curSelection - 1; } else { - gUnknown_0203BCAC->field_7FB4 = gUnknown_0203BCAC->field_7FB5; - gUnknown_0203BCAC->field_7FB5 = gUnknown_0203BCAC->field_7FB3; - gUnknown_0203BCAC->field_7FB3 = var0; - gUnknown_0203BCAC->field_7FB6 = gUnknown_0203BCAC->field_7FB4; + sMenu->nextLoadId = sMenu->prevLoadId; // temporarily store prevLoadId, nextLoadId no longer needed + sMenu->prevLoadId = sMenu->curLoadId; + sMenu->curLoadId = newLoadId; + sMenu->toLoadId = sMenu->nextLoadId; // next load will be the mon that's one down from new selection - gUnknown_0203BCAC->info.field_71 = (gUnknown_0203BCAC->info.field_71 < gUnknown_0203BCAC->info.field_70 - 1) - ? gUnknown_0203BCAC->info.field_71 + 1 + // Check for wrap to top of list + sMenu->info.curSelection = (sMenu->info.curSelection < sMenu->info.numSelections - 1) + ? sMenu->info.curSelection + 1 : 0; - gUnknown_0203BCAC->field_7B4C = (gUnknown_0203BCAC->info.field_71 < gUnknown_0203BCAC->info.field_70 - 1) - ? gUnknown_0203BCAC->info.field_71 + 1 + sMenu->toLoadSelection = (sMenu->info.curSelection < sMenu->info.numSelections - 1) + ? sMenu->info.curSelection + 1 : 0; } - r4 = (gUnknown_0203BCAC->info.field_71 ^ (gUnknown_0203BCAC->info.field_70 - 1)) ? 1 : 0; - sub_81D3520(gUnknown_0203BCAC->field_7B1C); - - if (!r8) - gUnknown_0203BCAC->info.unk74 = sub_8167EA4; - else if (!r4) - gUnknown_0203BCAC->info.unk74 = sub_8167FA4; + if (sMenu->info.curSelection == sMenu->info.numSelections - 1) + endedOnMon = FALSE; // moving onto Cancel else - gUnknown_0203BCAC->info.unk74 = sub_8168048; + endedOnMon = TRUE; + + DestroyConditionSparkleSprites(sMenu->sparkles); + + if (!startedOnMon) + sMenu->info.loadNewSelection = LoadNewSelection_CancelToMon; + else if (!endedOnMon) + sMenu->info.loadNewSelection = LoadNewSelection_MonToCancel; + else + sMenu->info.loadNewSelection = LoadNewSelection_MonToMon; } -static u8 sub_8167EA4(void) +static bool8 LoadNewSelection_CancelToMon(void) { - switch (gUnknown_0203BCAC->info.unk78) + switch (sMenu->info.helperState) { case 0: - sub_8167608(gUnknown_0203BCAC->field_7FB3); - gUnknown_0203BCAC->info.unk78++; + UpdateMonPic(sMenu->curLoadId); + sMenu->info.helperState++; break; case 1: - sub_8167BA0(gUnknown_0203BCAC->field_7FB3, 0); - gUnknown_0203BCAC->info.unk78++; + UpdateMonInfoText(sMenu->curLoadId, FALSE); + sMenu->info.helperState++; break; case 2: - if (!sub_81D3178(&gUnknown_0203BCAC->field_7C58, &gUnknown_0203BCAC->field_7B0E)) + if (!TryUpdateConditionMonTransitionOn(&sMenu->graph, &sMenu->curMonXOffset)) { - sub_816753C(gUnknown_0203BCAC->field_7B4C, gUnknown_0203BCAC->field_7FB6); - gUnknown_0203BCAC->info.unk78++; + // Load the new adjacent pokemon (not the one being shown) + LoadMonInfo(sMenu->toLoadSelection, sMenu->toLoadId); + sMenu->info.helperState++; } break; case 3: - sub_81D3464(gUnknown_0203BCAC->field_7B1C); - if (gUnknown_0203BCAC->info.field_71 != gUnknown_0203BCAC->info.field_70 - 1) + ResetConditionSparkleSprites(sMenu->sparkles); + if (sMenu->info.curSelection != sMenu->info.numSelections - 1) { - u8 var0 = gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->field_7FB3]; - sub_81D3480(gUnknown_0203BCAC->field_7B1C, gUnknown_0203BCAC->field_7B10, var0); + u8 numSparkles = sMenu->numSparkles[sMenu->curLoadId]; + CreateConditionSparkleSprites(sMenu->sparkles, sMenu->curMonSpriteId, numSparkles); } - gUnknown_0203BCAC->info.unk78 = 0; + sMenu->info.helperState = 0; return FALSE; } return TRUE; } -static u8 sub_8167FA4(void) +static bool8 LoadNewSelection_MonToCancel(void) { - switch (gUnknown_0203BCAC->info.unk78) + switch (sMenu->info.helperState) { case 0: - if (!sub_81D31A4(&gUnknown_0203BCAC->field_7C58, &gUnknown_0203BCAC->field_7B0E)) - gUnknown_0203BCAC->info.unk78++; + if (!TryUpdateConditionMonTransitionOff(&sMenu->graph, &sMenu->curMonXOffset)) + sMenu->info.helperState++; break; case 1: - sub_8167BA0(gUnknown_0203BCAC->field_7FB3, 0); - gUnknown_0203BCAC->info.unk78++; + UpdateMonInfoText(sMenu->curLoadId, FALSE); + sMenu->info.helperState++; break; case 2: - sub_816753C(gUnknown_0203BCAC->field_7B4C, gUnknown_0203BCAC->field_7FB6); - gUnknown_0203BCAC->info.unk78++; + LoadMonInfo(sMenu->toLoadSelection, sMenu->toLoadId); + sMenu->info.helperState++; break; case 3: - gUnknown_0203BCAC->info.unk78 = 0; + sMenu->info.helperState = 0; return FALSE; } return TRUE; } -static u8 sub_8168048(void) +static bool8 LoadNewSelection_MonToMon(void) { - switch (gUnknown_0203BCAC->info.unk78) + switch (sMenu->info.helperState) { case 0: - sub_81D2074(&gUnknown_0203BCAC->field_7C58); - if (!sub_81D3150(&gUnknown_0203BCAC->field_7B0E)) + TransitionConditionGraph(&sMenu->graph); + if (!MoveConditionMonOffscreen(&sMenu->curMonXOffset)) { - sub_8167608(gUnknown_0203BCAC->field_7FB3); - gUnknown_0203BCAC->info.unk78++; + UpdateMonPic(sMenu->curLoadId); + sMenu->info.helperState++; } break; case 1: - sub_8167BA0(gUnknown_0203BCAC->field_7FB3, 0); - gUnknown_0203BCAC->info.unk78++; + UpdateMonInfoText(sMenu->curLoadId, FALSE); + sMenu->info.helperState++; break; case 2: - if (!sub_81D3178(&gUnknown_0203BCAC->field_7C58, &gUnknown_0203BCAC->field_7B0E)) + if (!TryUpdateConditionMonTransitionOn(&sMenu->graph, &sMenu->curMonXOffset)) { - sub_816753C(gUnknown_0203BCAC->field_7B4C, gUnknown_0203BCAC->field_7FB6); - gUnknown_0203BCAC->info.unk78++; + // Load the new adjacent pokemon (not the one being shown) + LoadMonInfo(sMenu->toLoadSelection, sMenu->toLoadId); + sMenu->info.helperState++; } break; case 3: - sub_81D3464(gUnknown_0203BCAC->field_7B1C); - if (gUnknown_0203BCAC->info.field_71 != gUnknown_0203BCAC->info.field_70 - 1) + ResetConditionSparkleSprites(sMenu->sparkles); + if (sMenu->info.curSelection != sMenu->info.numSelections - 1) { - u8 var0 = gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->field_7FB3]; - sub_81D3480(gUnknown_0203BCAC->field_7B1C, gUnknown_0203BCAC->field_7B10, var0); + u8 numSparkles = sMenu->numSparkles[sMenu->curLoadId]; + CreateConditionSparkleSprites(sMenu->sparkles, sMenu->curMonSpriteId, numSparkles); } - gUnknown_0203BCAC->info.unk78 = 0; + sMenu->info.helperState = 0; return FALSE; } return TRUE; } -void sub_8168168(struct Sprite *sprite) +static void SpriteCB_MonPic(struct Sprite *sprite) { - sprite->pos1.x = gUnknown_0203BCAC->field_7B0E + 38; + sprite->pos1.x = sMenu->curMonXOffset + 38; } -void sub_8168180(struct Sprite *sprite) +static void SpriteCB_SelectionIconPokeball(struct Sprite *sprite) { - if (sprite->data[0] == gUnknown_0203BCAC->info.field_71) + if (sprite->data[0] == sMenu->info.curSelection) StartSpriteAnim(sprite, 0); else StartSpriteAnim(sprite, 1); } -void sub_81681B4(struct Sprite *sprite) +static void SpriteCB_SelectionIconCancel(struct Sprite *sprite) { - if (gUnknown_0203BCAC->info.field_71 == gUnknown_0203BCAC->info.field_70 - 1) - sprite->oam.paletteNum = IndexOfSpritePaletteTag(101); + if (sMenu->info.curSelection == sMenu->info.numSelections - 1) + sprite->oam.paletteNum = IndexOfSpritePaletteTag(TAG_CONDITION_BALL); else - sprite->oam.paletteNum = IndexOfSpritePaletteTag(102); + sprite->oam.paletteNum = IndexOfSpritePaletteTag(TAG_CONDITION_CANCEL); } -void sub_81681F4(u8 monIndex) +// Calculate the max id for sparkles/stars that appear around the pokemon on the condition screen +// All pokemon start with 1 sparkle (added by CreateConditionSparkleSprites), so the number here +1 +// is the total number of sparkles that appear +static void CalculateNumAdditionalSparkles(u8 monIndex) { u8 sheen = GetMonData(&gPlayerParty[monIndex], MON_DATA_SHEEN); - gUnknown_0203BCAC->unk7FB0[gUnknown_0203BCAC->field_7FB3] = (sheen != 255) - ? sheen / 29 - : 9; + sMenu->numSparkles[sMenu->curLoadId] = (sheen != 255) + ? sheen / (255 / (MAX_CONDITION_SPARKLES - 1) + 1) + : MAX_CONDITION_SPARKLES - 1; } -static void sub_8168248(void) +static void LoadConditionGfx(void) { struct CompressedSpriteSheet spriteSheet; struct SpritePalette spritePalette; - spritePalette = gSpritePalette_085DFDB8; + spritePalette = sSpritePalette_Condition; spriteSheet.data = gUsePokeblockCondition_Gfx; spriteSheet.size = 0x800; - spriteSheet.tag = 1; + spriteSheet.tag = TAG_CONDITION; LoadCompressedSpriteSheet(&spriteSheet); LoadSpritePalette(&spritePalette); } -static void sub_8168294(void) +static void CreateConditionSprite(void) { u16 i; s16 xDiff, xStart; int yStart = 17; int var = 8; - struct Sprite **sprites = gUnknown_0203BCAC->field_7B44; - const struct SpriteTemplate *template = &gSpriteTemplate_085DFDA0; + struct Sprite **sprites = sMenu->condition; + const struct SpriteTemplate *template = &sSpriteTemplate_Condition; for (i = 0, xDiff = 64, xStart = -96; i < 2; i++) { @@ -1595,24 +1641,25 @@ static void sub_8168294(void) } } -static bool8 sub_8168328(void) +static bool8 LoadConditionTitle(void) { - switch (gUnknown_0203BCAC->info.unk78) + switch (sMenu->info.helperState) { case 0: - sub_8168248(); - gUnknown_0203BCAC->info.unk78++; + LoadConditionGfx(); + sMenu->info.helperState++; return TRUE; case 1: - sub_8168294(); - gUnknown_0203BCAC->info.unk78 = 0; + CreateConditionSprite(); + sMenu->info.helperState = 0; return FALSE; } return FALSE; } -void sub_8168374(struct Sprite *sprite) +// Literally the word "Condition", the title block that appears over the mon icon +static void SpriteCB_Condition(struct Sprite *sprite) { s16 prevX = sprite->pos1.x;