diff --git a/graphics/interface/unknown_6157E0.bin b/graphics/interface/party_menu_cancel_button.bin similarity index 100% rename from graphics/interface/unknown_6157E0.bin rename to graphics/interface/party_menu_cancel_button.bin diff --git a/graphics/interface/unknown_6157C4.bin b/graphics/interface/party_menu_confirm_button.bin similarity index 100% rename from graphics/interface/unknown_6157C4.bin rename to graphics/interface/party_menu_confirm_button.bin diff --git a/include/battle_main.h b/include/battle_main.h index 5dd1aed444..fe88204bf7 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -77,7 +77,7 @@ void sub_803B3AC(void); // unused void sub_803B598(void); // unused void BattleTurnPassed(void); u8 IsRunningFromBattleImpossible(void); -void sub_803BDA0(u8 battlerId); +void SwitchPartyOrder(u8 battlerId); void SwapTurnOrder(u8 id1, u8 id2); u8 GetWhoStrikesFirst(u8 battlerId1, u8 battlerId2, bool8 ignoreChosenMoves); void RunBattleScriptCommands_PopCallbacksStack(void); diff --git a/include/battle_util2.h b/include/battle_util2.h index 336698ea32..fe767ea4bf 100644 --- a/include/battle_util2.h +++ b/include/battle_util2.h @@ -4,7 +4,7 @@ void AllocateBattleResources(void); void FreeBattleResources(void); void AdjustFriendshipOnBattleFaint(u8 battler); -void sub_80571DC(u8 battler, u8 arg1); +void SwitchPartyOrderInGameMulti(u8 battler, u8 arg1); u32 sub_805725C(u8 battler); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/constants/party_menu.h b/include/constants/party_menu.h index a15280afb0..7953967ed7 100644 --- a/include/constants/party_menu.h +++ b/include/constants/party_menu.h @@ -54,7 +54,7 @@ #define PARTY_MENU_TYPE_CONTEST 2 #define PARTY_MENU_TYPE_CHOOSE_MON 3 #define PARTY_MENU_TYPE_CHOOSE_HALF 4 // multi battles, eReader battles, and some battle facilities -#define PARTY_MENU_TYPE_IN_MULTI_BATTLE 5 // TODO: investigate +#define PARTY_MENU_TYPE_MULTI_SHOWCASE 5 #define PARTY_MENU_TYPE_DAYCARE 6 #define PARTY_MENU_TYPE_MOVE_RELEARNER 7 #define PARTY_MENU_TYPE_UNION_ROOM_REGISTER 8 // trading board diff --git a/include/menu.h b/include/menu.h index 14f4c130d6..c5cef202ce 100644 --- a/include/menu.h +++ b/include/menu.h @@ -86,7 +86,7 @@ void RemoveMapNamePopUpWindow(void); u8 GetMapNamePopUpWindowId(void); u8 AddMapNamePopUpWindow(void); void AddTextPrinterParameterized5(u8 windowId, u8 fontId, const u8 *str, u8 left, u8 top, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16), u8 letterSpacing, u8 lineSpacing); -void sub_8199C30(u8 bgId, u8 left, u8 top, u8 width, u8 height, u8 palette); +void SetBgTilemapPalette(u8 bgId, u8 left, u8 top, u8 width, u8 height, u8 palette); void sub_8199D3C(void *ptr, int delta, int width, int height, bool32 is8BPP); void sub_8198204(const u8 *string, const u8 *string2, u8 a3, u8 a4, bool8 copyToVram); void sub_8197AE8(bool8 copyToVram); diff --git a/include/party_menu.h b/include/party_menu.h index c9c62febec..c8926c0b95 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -4,6 +4,8 @@ #include "main.h" #include "task.h" +// seems like the last two fields may have been left as all-purpose vars +// and the second of the two just happens to only be used in one case struct PartyMenu { MainCallback exitCallback; @@ -15,13 +17,13 @@ struct PartyMenu s8 slotId2; u8 action; u16 bagItem; - s16 unkE; // used as both a moveId and a move slot/cursor position - s16 learnMoveState; + s16 data1; // used variously as a moveId, counter, moveSlotId, or cursorPos + s16 learnMoveState; // data2, used only as a learn move state }; extern struct PartyMenu gPartyMenu; -extern bool8 gUnknown_0203CEE8; -extern u8 gUnknown_0203CEE9; +extern bool8 gPartyMenuUseExitCallback; +extern u8 gSelectedMonPartyId; extern MainCallback gPostMenuFieldCallback; extern u8 gSelectedOrderFromParty[4]; extern u8 gBattlePartyCurrentOrder[3]; @@ -71,9 +73,9 @@ void OpenPartyMenuInBattle(u8 arg); void ChooseMonForInBattleItem(void); void sub_81B8C68(void); void sub_81B8D64(u8 battlerId, u8 multiplayerFlag); -void sub_81B8E80(u8 battlerId, u8 unk, u8 arrayIndex); +void SwitchPartyOrderLinkMulti(u8 battlerId, u8 slot, u8 arrayIndex); void SwitchPartyMonSlots(u8 slot, u8 slot2); -u8 GetBattlerPartyId(u8 slot); +u8 GetPartyIdFromBattlePartyId(u8 slot); void ShowPartyMenuToShowcaseMultiBattleParty(void); void ChooseMonForDaycare(void); bool8 CB2_FadeFromPartyMenu(void); diff --git a/include/pokemon_icon.h b/include/pokemon_icon.h index 5018de37c9..4fb9903026 100644 --- a/include/pokemon_icon.h +++ b/include/pokemon_icon.h @@ -21,7 +21,7 @@ u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u u8 UpdateMonIconFrame(struct Sprite *sprite); void LoadMonIconPalette(u16 species); void sub_80D328C(struct Sprite *sprite); -void UpdateTradeMonIconFrame(struct Sprite *sprite); +void MonIconSpriteCallback(struct Sprite *sprite); void SetPartyHPBarSprite(struct Sprite *sprite, u8 animNum); u8 GetMonIconPaletteIndexFromSpecies(u16 species); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 840ba6e629..57239bca6b 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1342,8 +1342,8 @@ static void WaitForMonSelection(void) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { - if (gUnknown_0203CEE8 == TRUE) - BtlController_EmitChosenMonReturnValue(1, gUnknown_0203CEE9, gBattlePartyCurrentOrder); + if (gPartyMenuUseExitCallback == TRUE) + BtlController_EmitChosenMonReturnValue(1, gSelectedMonPartyId, gBattlePartyCurrentOrder); else BtlController_EmitChosenMonReturnValue(1, PARTY_SIZE, NULL); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 236b0bb5e4..29540f3a94 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1311,14 +1311,14 @@ void BtlController_EmitTwoReturnValues(u8 bufferId, u8 arg1, u16 arg2) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 partyId, u8 *c) +void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 partyId, u8 *battlePartyOrder) { s32 i; sBattleBuffersTransferData[0] = CONTROLLER_CHOSENMONRETURNVALUE; sBattleBuffersTransferData[1] = partyId; - for (i = 0; i < 3; i++) - sBattleBuffersTransferData[2 + i] = c[i]; + for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) + sBattleBuffersTransferData[2 + i] = battlePartyOrder[i]; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 5); } diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index a70a9c34b4..c29bf7526e 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -1061,8 +1061,8 @@ void HandleBattleLowHpMusicChange(void) { u8 playerBattler1 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); u8 playerBattler2 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - u8 battler1PartyId = GetBattlerPartyId(gBattlerPartyIndexes[playerBattler1]); - u8 battler2PartyId = GetBattlerPartyId(gBattlerPartyIndexes[playerBattler2]); + u8 battler1PartyId = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[playerBattler1]); + u8 battler2PartyId = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[playerBattler2]); if (GetMonData(&gPlayerParty[battler1PartyId], MON_DATA_HP) != 0) HandleLowHpMusicChange(&gPlayerParty[battler1PartyId], playerBattler1); diff --git a/src/battle_main.c b/src/battle_main.c index 863fabef82..7ae8d5c468 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4122,20 +4122,20 @@ u8 IsRunningFromBattleImpossible(void) return 0; } -void sub_803BDA0(u8 battler) +void SwitchPartyOrder(u8 battler) { s32 i; - u8 r4; - u8 r1; + u8 partyId1; + u8 partyId2; // gBattleStruct->field_60[battler][i] for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) gBattlePartyCurrentOrder[i] = *(battler * 3 + i + (u8*)(gBattleStruct->field_60)); - r4 = GetBattlerPartyId(gBattlerPartyIndexes[battler]); - r1 = GetBattlerPartyId(*(gBattleStruct->monToSwitchIntoId + battler)); - SwitchPartyMonSlots(r4, r1); + partyId1 = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battler]); + partyId2 = GetPartyIdFromBattlePartyId(*(gBattleStruct->monToSwitchIntoId + battler)); + SwitchPartyMonSlots(partyId1, partyId2); if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { @@ -4590,7 +4590,7 @@ static void HandleTurnActionSelectionState(void) for (i = 0; i < gBattlersCount; i++) { if (gChosenActionByBattler[i] == B_ACTION_SWITCH) - sub_80571DC(i, *(gBattleStruct->monToSwitchIntoId + i)); + SwitchPartyOrderInGameMulti(i, *(gBattleStruct->monToSwitchIntoId + i)); } } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a9903b3d1d..82461be32e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5434,7 +5434,7 @@ static void atk51_switchhandleorder(void) break; case 1: if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - sub_803BDA0(gActiveBattler); + SwitchPartyOrder(gActiveBattler); break; case 2: if (!(gBattleStruct->field_93 & gBitTable[gActiveBattler])) @@ -5459,11 +5459,11 @@ static void atk51_switchhandleorder(void) } else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - sub_80571DC(gActiveBattler, *(gBattleStruct->monToSwitchIntoId + gActiveBattler)); + SwitchPartyOrderInGameMulti(gActiveBattler, *(gBattleStruct->monToSwitchIntoId + gActiveBattler)); } else { - sub_803BDA0(gActiveBattler); + SwitchPartyOrder(gActiveBattler); } PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].species) @@ -7567,19 +7567,19 @@ static void atk8F_forcerandomswitch(void) *(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i; if (!IsMultiBattle()) - sub_803BDA0(gBattlerTarget); + SwitchPartyOrder(gBattlerTarget); if ((gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) || (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) || (gBattleTypeFlags & BATTLE_TYPE_x2000000 && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) || (gBattleTypeFlags & BATTLE_TYPE_x2000000 && gBattleTypeFlags & BATTLE_TYPE_MULTI)) { - sub_81B8E80(gBattlerTarget, i, 0); - sub_81B8E80(gBattlerTarget ^ BIT_FLANK, i, 1); + SwitchPartyOrderLinkMulti(gBattlerTarget, i, 0); + SwitchPartyOrderLinkMulti(gBattlerTarget ^ BIT_FLANK, i, 1); } if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) - sub_80571DC(gBattlerTarget, i); + SwitchPartyOrderInGameMulti(gBattlerTarget, i); } } else diff --git a/src/battle_util2.c b/src/battle_util2.c index 2c8e8c8f2e..fd0dda76b9 100644 --- a/src/battle_util2.c +++ b/src/battle_util2.c @@ -102,7 +102,7 @@ void AdjustFriendshipOnBattleFaint(u8 battlerId) } } -void sub_80571DC(u8 battlerId, u8 arg1) +void SwitchPartyOrderInGameMulti(u8 battlerId, u8 arg1) { if (GetBattlerSide(battlerId) != B_SIDE_OPPONENT) { @@ -113,7 +113,7 @@ void sub_80571DC(u8 battlerId, u8 arg1) for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) gBattlePartyCurrentOrder[i] = *(0 * 3 + i + (u8*)(gBattleStruct->field_60)); - SwitchPartyMonSlots(GetBattlerPartyId(gBattlerPartyIndexes[battlerId]), GetBattlerPartyId(arg1)); + SwitchPartyMonSlots(GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battlerId]), GetPartyIdFromBattlePartyId(arg1)); for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++) *(0 * 3 + i + (u8*)(gBattleStruct->field_60)) = gBattlePartyCurrentOrder[i]; diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 18faf0e60d..3fbeec6e34 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1124,7 +1124,7 @@ static void sub_80B0318(u8 taskId) SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(12, 7)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_BG3 | WINOUT_WIN01_OBJ); - sub_8199C30(0, 0, 0, 0x1E, 0x14, 0xF); + SetBgTilemapPalette(0, 0, 0, 0x1E, 0x14, 0xF); schedule_bg_copy_tilemap_to_vram(0); SetFlash2ScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], data[2], data[3], 1); CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480); diff --git a/src/menu.c b/src/menu.c index 0950e6305b..056fc6a9df 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1868,7 +1868,7 @@ u16 copy_decompressed_tile_data_to_vram(u8 bgId, const void *src, u16 size, u16 } } -void sub_8199C30(u8 bgId, u8 left, u8 top, u8 width, u8 height, u8 palette) +void SetBgTilemapPalette(u8 bgId, u8 left, u8 top, u8 width, u8 height, u8 palette) { u8 i; u8 j; diff --git a/src/party_menu.c b/src/party_menu.c index 7de8ceee2d..07042774be 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -87,6 +87,11 @@ #define PARTY_PAL_NO_MON (1 << 6) #define PARTY_PAL_UNUSED (1 << 7) +#define MENU_DIR_DOWN 1 +#define MENU_DIR_UP -1 +#define MENU_DIR_RIGHT 2 +#define MENU_DIR_LEFT -2 + enum { CAN_LEARN_MOVE, @@ -110,7 +115,7 @@ struct PartyMenuInternal TaskFunc task; MainCallback exitCallback; u32 chooseHalf:1; - u32 unk8_1:3; + u32 lastSelectedSlot:3; // Used to return to same slot when going left/right bewtween columns u32 spriteIdConfirmPokeball:7; u32 spriteIdCancelPokeball:7; u32 messageId:14; @@ -142,8 +147,8 @@ EWRAM_DATA struct PartyMenu gPartyMenu = {0}; static EWRAM_DATA struct PartyMenuBox *sPartyMenuBoxes = NULL; static EWRAM_DATA u8 *sPartyBgGfxTilemap = NULL; static EWRAM_DATA u8 *sPartyBgTilemapBuffer = NULL; -EWRAM_DATA bool8 gUnknown_0203CEE8 = 0; // executed party action -ish -EWRAM_DATA u8 gUnknown_0203CEE9 = 0; // party id for something +EWRAM_DATA bool8 gPartyMenuUseExitCallback = 0; +EWRAM_DATA u8 gSelectedMonPartyId = 0; // only used for switching mons, oddly EWRAM_DATA MainCallback gPostMenuFieldCallback = NULL; static EWRAM_DATA u16 *sSlot1TilemapBuffer = 0; // for switching party slots static EWRAM_DATA u16 *sSlot2TilemapBuffer = 0; // @@ -166,10 +171,10 @@ static void InitPartyMenuWindows(u8); static void InitPartyMenuBoxes(u8); static void LoadPartyMenuPokeballGfx(void); static void LoadPartyMenuAilmentGfx(void); -static bool8 party_menu_add_per_mon_objects(void); +static bool8 CreatePartyMonSpritesLoop(void); static bool8 RenderPartyMenuBoxes(void); static void CreateCancelConfirmPokeballSprites(void); -static void sub_81B2428(u8); +static void CreateCancelConfirmWindows(u8); static void Task_ExitPartyMenu(u8); static void FreePartyPointers(void); static void PartyPaletteBufferCopy(u8); @@ -199,17 +204,19 @@ static void DisplayPartyPokemonGender(u8, u16, u8*, struct PartyMenuBox *); static void DisplayPartyPokemonHP(u16, struct PartyMenuBox *); static void DisplayPartyPokemonMaxHP(u16, struct PartyMenuBox *); static void DisplayPartyPokemonHPBar(u16, u16, struct PartyMenuBox *); -static void party_menu_link_mon_icon_anim(u16, u32, struct PartyMenuBox *, u8, u32); -static void party_menu_link_mon_held_item_object(u16, u16, struct PartyMenuBox *); -static void party_menu_link_mon_pokeball_object(u16, struct PartyMenuBox *); -static void party_menu_link_mon_status_condition_object(u16, u8, struct PartyMenuBox *); -static void party_menu_held_item_object(struct Pokemon *, struct PartyMenuBox *); -static void party_menu_pokeball_object(struct Pokemon *, struct PartyMenuBox *); -static void party_menu_icon_anim(struct Pokemon *, struct PartyMenuBox *, u32); -static void party_menu_status_condition_object(struct Pokemon *, struct PartyMenuBox *); -static u8 CreateMenuPokeballSprite(u8, u8); -static void sub_81B120C(void); -static u8 CreateCancelPokeballSprite(u8, u8); +static void CreatePartyMonIconSpriteParameterized(u16, u32, struct PartyMenuBox *, u8, u32); +static void CreatePartyMonHeldItemSpriteParameterized(u16, u16, struct PartyMenuBox *); +static void CreatePartyMonPokeballSpriteParameterized(u16, struct PartyMenuBox *); +static void CreatePartyMonStatusSpriteParameterized(u16, u8, struct PartyMenuBox *); +// These next 4 functions are essentially redundant with the above 4 +// The only difference is that rather than receive the data directly they retrieve it from the mon struct +static void CreatePartyMonHeldItemSprite(struct Pokemon *, struct PartyMenuBox *); +static void CreatePartyMonPokeballSprite(struct Pokemon *, struct PartyMenuBox *); +static void CreatePartyMonIconSprite(struct Pokemon *, struct PartyMenuBox *, u32); +static void CreatePartyMonStatusSprite(struct Pokemon *, struct PartyMenuBox *); +static u8 CreateSmallPokeballButtonSprite(u8, u8); +static void DrawCancelConfirmButtons(void); +static u8 CreatePokeballButtonSprite(u8, u8); static void AnimateSelectedPartyIcon(u8, u8); static void PartyMenuStartSpriteAnim(u8, u8); static u8 GetPartyBoxPaletteFlags(u8, u8); @@ -217,7 +224,7 @@ static bool8 PartyBoxPal_ParnterOrDisqualifiedInArena(u8); static u8 GetPartyIdFromBattleSlot(u8); static void Task_ClosePartyMenuAndSetCB2(u8); static void UpdatePartyToFieldOrder(void); -static void sub_81B4F88(void); +static void MoveCursorToConfirm(void); static void HandleChooseMonCancel(u8, s8*); static void HandleChooseMonSelection(u8, s8*); static u16 PartyMenuButtonHandler(s8*); @@ -228,7 +235,7 @@ static void CB2_SetUpExitToBattleScreen(void); static void Task_ClosePartyMenuAfterText(u8); static void TryTutorSelectedMon(u8); static void TryGiveMailToSelectedMon(u8); -static void TryGiveItemToSelectedMon(u8); +static void TryGiveItemOrMailToSelectedMon(u8); static void SwitchSelectedMons(u8); static void TryEnterMonForMinigame(u8, u8); static void Task_TryCreateSelectionWindow(u8); @@ -243,7 +250,7 @@ static void Task_ReturnToChooseMonAfterText(u8); static void UpdateCurrentPartySelection(s8*, s8); static void UpdatePartySelectionSingleLayout(s8*, s8); static void UpdatePartySelectionDoubleLayout(s8*, s8); -static s8 sub_81B1B00(s8, s8); +static s8 GetNewSlotDoubleLayout(s8, s8); static void PartyMenuPrintText(const u8*); static void Task_PrintAndWaitForText(u8); static bool16 IsMonAllowedInPokemonJump(struct Pokemon*); @@ -252,7 +259,7 @@ static void Task_CancelParticipationYesNo(u8); static void Task_HandleCancelParticipationYesNoInput(u8); static bool8 CanLearnTutorMove(u16, u8); static u16 GetTutorMove(u8); -static bool8 sub_81B314C(void); +static bool8 ShouldUseChooseMonText(void); static void SetPartyMonFieldSelectionActions(struct Pokemon*, u8); static u8 GetPartyMenuActionsTypeInBattle(struct Pokemon*); static u8 GetPartySlotEntryStatus(s8); @@ -274,17 +281,17 @@ static void Task_SwitchItemsYesNo(u8); static void Task_HandleSwitchItemsYesNoInput(u8); static void Task_WriteMailToGiveMonAfterText(u8); static void CB2_ReturnToPartyMenuFromWritingMail(void); -static void sub_81B4624(u8); +static void Task_DisplayGaveMailFromPartyMessage(u8); static void UpdatePartyMonHeldItemSprite(struct Pokemon*, struct PartyMenuBox*); static void Task_TossHeldItemYesNo(u8 taskId); static void Task_HandleTossHeldItemYesNoInput(u8); static void Task_TossHeldItem(u8); -static void sub_81B4A98(void); -static void sub_81B4AE0(void); -static void sub_81B4B6C(u8); -static void sub_81B4BA0(u8); -static void sub_81B4C60(u8); -static void sub_81B4C94(u8); +static void CB2_ReadHeldMail(void); +static void CB2_ReturnToPartyMenuFromReadingMail(void); +static void Task_SendMailToPCYesNo(u8); +static void Task_HandleSendMailToPCYesNoInput(u8); +static void Task_LoseMailMessageYesNo(u8); +static void Task_HandleLoseMailMessageYesNoInput(u8); static bool8 TrySwitchInPokemon(void); static void Task_SpinTradeYesNo(u8); static void Task_HandleSpinTradeYesNoInput(u8); @@ -297,15 +304,15 @@ static void Task_HandleFieldMoveExitAreaYesNoInput(u8); static void Task_FieldMoveWaitForFade(u8); static u16 GetFieldMoveMonSpecies(void); static void UpdatePartyMonHPBar(u8, struct Pokemon*); -static void UpdatePartyMonIconFrame(struct Sprite*); -static void UpdatePartyMonIconFrameAndBounce(struct Sprite*); +static void SpriteCB_UpdatePartyMonIcon(struct Sprite*); +static void SpriteCB_BouncePartyMonIcon(struct Sprite*); static void ShowOrHideHeldItemSprite(u16, struct PartyMenuBox*); static void CreateHeldItemSpriteForTrade(u8, bool8); static void SpriteCB_HeldItem(struct Sprite*); static void SetPartyMonAilmentGfx(struct Pokemon*, struct PartyMenuBox*); static void UpdatePartyMonAilmentGfx(u8, struct PartyMenuBox*); static u8 GetPartyLayoutFromBattleType(void); -static void sub_81B6280(u8); +static void Task_SetSacredAshCB(u8); static void CB2_ReturnToBagMenu(void); static void Task_DisplayHPRestoredMessage(u8); static u16 ItemEffectToMonEv(struct Pokemon*, u8); @@ -339,20 +346,20 @@ static void Task_TryLearnNewMoves(u8); static void PartyMenuTryEvolution(u8); static void DisplayMonNeedsToReplaceMove(u8); static void DisplayMonLearnedMove(u8, u16); -static void sub_81B7A28(u8); -static void task_sacred_ash_party_loop(u8); +static void UseSacredAsh(u8); +static void Task_SacredAshLoop(u8); static void Task_SacredAshDisplayHPRestored(u8); -static void GiveItemToSelectedMon(u8); -static void sub_81B83B8(u8); -static void sub_81B82A0(u8); +static void GiveItemOrMailToSelectedMon(u8); +static void DisplayItemMustBeRemovedFirstMessage(u8); +static void Task_SwitchItemsFromBagYesNo(u8); static void RemoveItemToGiveFromBag(u16); static void CB2_WriteMailToGiveMonFromBag(void); -static void sub_81B8088(u8); +static void GiveItemToSelectedMon(u8); static void Task_UpdateHeldItemSpriteAndClosePartyMenu(u8); static void CB2_ReturnToPartyOrBagMenuFromWritingMail(void); -static bool8 sub_81B841C(u16); -static void sub_81B8230(u8); -static void sub_81B82D4(u8); +static bool8 ReturnGiveItemToBagOrPC(u16); +static void Task_DisplayGaveMailFromBagMessage(u8); +static void Task_HandleSwitchItemsFromBagYesNoInput(u8); static void Task_ValidateChosenHalfParty(u8); static bool8 GetBattleEntryEligibility(struct Pokemon*); static bool8 HasPartySlotAlreadyBeenSelected(u8); @@ -474,498 +481,501 @@ static const struct PartyMenuBoxInfoRects sPartyBoxInfoRects[] = }; -// Each layout array has the sprite coords for each of the party mons in the following order +// Each layout array has an array for each of the 6 party slots +// The array for each slot has the sprite coords of its various sprites in the following order // Pokemon icon (x, y), held item (x, y), status condition (x, y), menu pokeball (x, y) static const u8 sPartyMenuSpriteCoords[PARTY_LAYOUT_COUNT][PARTY_SIZE][4 * 2] = { [PARTY_LAYOUT_SINGLE] = { { 16, 40, 20, 50, 50, 52, 16, 34}, - {104, 18, 108, 28, 136, 27, 102, 25}, - {104, 42, 108, 52, 136, 51, 102, 49}, - {104, 66, 108, 76, 136, 75, 102, 73}, - {104, 90, 108, 100, 136, 99, 102, 97}, - {104, 114, 108, 124, 136, 123, 102, 121}, - }, + {104, 18, 108, 28, 136, 27, 102, 25}, + {104, 42, 108, 52, 136, 51, 102, 49}, + {104, 66, 108, 76, 136, 75, 102, 73}, + {104, 90, 108, 100, 136, 99, 102, 97}, + {104, 114, 108, 124, 136, 123, 102, 121}, + }, [PARTY_LAYOUT_DOUBLE] = - { - {16, 24, 20, 34, 50, 36, 16, 18}, - {16, 80, 20, 90, 50, 92, 16, 74}, - {104, 18, 108, 28, 136, 27, 102, 25}, - {104, 50, 108, 60, 136, 59, 102, 57}, - {104, 82, 108, 92, 136, 91, 102, 89}, - {104, 114, 108, 124, 136, 123, 102, 121}, - }, + { + {16, 24, 20, 34, 50, 36, 16, 18}, + {16, 80, 20, 90, 50, 92, 16, 74}, + {104, 18, 108, 28, 136, 27, 102, 25}, + {104, 50, 108, 60, 136, 59, 102, 57}, + {104, 82, 108, 92, 136, 91, 102, 89}, + {104, 114, 108, 124, 136, 123, 102, 121}, + }, [PARTY_LAYOUT_MULTI] = - { - {16, 24, 20, 34, 50, 36, 16, 18}, - {16, 80, 20, 90, 50, 92, 16, 74}, - {104, 26, 106, 36, 136, 35, 102, 33}, - {104, 50, 106, 60, 136, 59, 102, 57}, - {104, 82, 106, 92, 136, 91, 102, 89}, - {104, 106, 106, 116, 136, 115, 102, 113}, - }, + { + {16, 24, 20, 34, 50, 36, 16, 18}, + {16, 80, 20, 90, 50, 92, 16, 74}, + {104, 26, 106, 36, 136, 35, 102, 33}, + {104, 50, 106, 60, 136, 59, 102, 57}, + {104, 82, 106, 92, 136, 91, 102, 89}, + {104, 106, 106, 116, 136, 115, 102, 113}, + }, [PARTY_LAYOUT_MULTI_SHOWCASE] = - { - {16, 32, 20, 42, 50, 44, 16, 26}, - {104, 34, 106, 44, 136, 43, 102, 41}, - {104, 58, 106, 68, 136, 67, 102, 65}, - {16, 104, 20, 114, 50, 116, 16, 98}, - {104, 106, 106, 116, 136, 115, 102, 113}, - {104, 130, 106, 140, 136, 139, 102, 137}, - }, + { + {16, 32, 20, 42, 50, 44, 16, 26}, + {104, 34, 106, 44, 136, 43, 102, 41}, + {104, 58, 106, 68, 136, 67, 102, 65}, + {16, 104, 20, 114, 50, 116, 16, 98}, + {104, 106, 106, 116, 136, 115, 102, 113}, + {104, 130, 106, 140, 136, 139, 102, 137}, + }, }; -static const u32 sConfirmButtonPokeball_Tilemap[] = INCBIN_U32("graphics/interface/unknown_6157C4.bin"); -static const u32 sCancelButtonPokeball_Tilemap[] = INCBIN_U32("graphics/interface/unknown_6157E0.bin"); +// Used only when both Cancel and Confirm are present +static const u32 sConfirmButton_Tilemap[] = INCBIN_U32("graphics/interface/party_menu_confirm_button.bin"); +static const u32 sCancelButton_Tilemap[] = INCBIN_U32("graphics/interface/party_menu_cancel_button.bin"); +// Text colors for BG, FG, and Shadow in that order static const u8 sFontColorTable[][3] = { - {0, 3, 2}, - {0, 1, 6}, - {0, 11, 12}, - {1, 2, 3}, - {1, 8, 9}, - {0, 1, 2}, + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GREY, TEXT_COLOR_DARK_GREY}, // Default + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_GREEN}, // Unused + {TEXT_COLOR_TRANSPARENT, TEXT_DYNAMIC_COLOR_2, TEXT_DYNAMIC_COLOR_3}, // Gender symbol + {TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY}, // Selection actions + {TEXT_COLOR_WHITE, TEXT_COLOR_BLUE, TEXT_COLOR_LIGHT_BLUE}, // Field moves + {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY}, // Unused }; static const struct WindowTemplate sSinglePartyMenuWindowTemplate[] = { - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 3, - .width = 10, - .height = 7, - .paletteNum = 3, - .baseBlock = 0x63, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 1, - .width = 18, - .height = 3, - .paletteNum = 4, - .baseBlock = 0xA9, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 4, - .width = 18, - .height = 3, - .paletteNum = 5, - .baseBlock = 0xDF, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 7, - .width = 18, - .height = 3, - .paletteNum = 6, - .baseBlock = 0x115, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 10, - .width = 18, - .height = 3, - .paletteNum = 7, - .baseBlock = 0x14B, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 13, - .width = 18, - .height = 3, - .paletteNum = 8, - .baseBlock = 0x181, - }, - { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 15, - .width = 28, - .height = 4, - .paletteNum = 14, - .baseBlock = 0x1DF, - }, - DUMMY_WIN_TEMPLATE + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 3, + .width = 10, + .height = 7, + .paletteNum = 3, + .baseBlock = 0x63, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 1, + .width = 18, + .height = 3, + .paletteNum = 4, + .baseBlock = 0xA9, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 4, + .width = 18, + .height = 3, + .paletteNum = 5, + .baseBlock = 0xDF, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 7, + .width = 18, + .height = 3, + .paletteNum = 6, + .baseBlock = 0x115, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 10, + .width = 18, + .height = 3, + .paletteNum = 7, + .baseBlock = 0x14B, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 13, + .width = 18, + .height = 3, + .paletteNum = 8, + .baseBlock = 0x181, + }, + { + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 15, + .width = 28, + .height = 4, + .paletteNum = 14, + .baseBlock = 0x1DF, + }, + DUMMY_WIN_TEMPLATE }; static const struct WindowTemplate sDoublePartyMenuWindowTemplate[] = { - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 1, - .width = 10, - .height = 7, - .paletteNum = 3, - .baseBlock = 0x63, - }, - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 8, - .width = 10, - .height = 7, - .paletteNum = 4, - .baseBlock = 0xA9, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 1, - .width = 18, - .height = 3, - .paletteNum = 5, - .baseBlock = 0xEF, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 5, - .width = 18, - .height = 3, - .paletteNum = 6, - .baseBlock = 0x125, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 9, - .width = 18, - .height = 3, - .paletteNum = 7, - .baseBlock = 0x15B, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 13, - .width = 18, - .height = 3, - .paletteNum = 8, - .baseBlock = 0x191, - }, - { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 15, - .width = 28, - .height = 4, - .paletteNum = 14, - .baseBlock = 0x1DF, - }, - DUMMY_WIN_TEMPLATE + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 10, + .height = 7, + .paletteNum = 3, + .baseBlock = 0x63, + }, + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 8, + .width = 10, + .height = 7, + .paletteNum = 4, + .baseBlock = 0xA9, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 1, + .width = 18, + .height = 3, + .paletteNum = 5, + .baseBlock = 0xEF, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 5, + .width = 18, + .height = 3, + .paletteNum = 6, + .baseBlock = 0x125, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 9, + .width = 18, + .height = 3, + .paletteNum = 7, + .baseBlock = 0x15B, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 13, + .width = 18, + .height = 3, + .paletteNum = 8, + .baseBlock = 0x191, + }, + { + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 15, + .width = 28, + .height = 4, + .paletteNum = 14, + .baseBlock = 0x1DF, + }, + DUMMY_WIN_TEMPLATE }; static const struct WindowTemplate sMultiPartyMenuWindowTemplate[] = { - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 1, - .width = 10, - .height = 7, - .paletteNum = 3, - .baseBlock = 0x63, - }, - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 8, - .width = 10, - .height = 7, - .paletteNum = 4, - .baseBlock = 0xA9, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 2, - .width = 18, - .height = 3, - .paletteNum = 5, - .baseBlock = 0xEF, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 5, - .width = 18, - .height = 3, - .paletteNum = 6, - .baseBlock = 0x125, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 9, - .width = 18, - .height = 3, - .paletteNum = 7, - .baseBlock = 0x15B, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 12, - .width = 18, - .height = 3, - .paletteNum = 8, - .baseBlock = 0x191, - }, - { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 15, - .width = 28, - .height = 4, - .paletteNum = 14, - .baseBlock = 0x1DF, - }, - DUMMY_WIN_TEMPLATE + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 10, + .height = 7, + .paletteNum = 3, + .baseBlock = 0x63, + }, + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 8, + .width = 10, + .height = 7, + .paletteNum = 4, + .baseBlock = 0xA9, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 2, + .width = 18, + .height = 3, + .paletteNum = 5, + .baseBlock = 0xEF, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 5, + .width = 18, + .height = 3, + .paletteNum = 6, + .baseBlock = 0x125, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 9, + .width = 18, + .height = 3, + .paletteNum = 7, + .baseBlock = 0x15B, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 12, + .width = 18, + .height = 3, + .paletteNum = 8, + .baseBlock = 0x191, + }, + { + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 15, + .width = 28, + .height = 4, + .paletteNum = 14, + .baseBlock = 0x1DF, + }, + DUMMY_WIN_TEMPLATE }; static const struct WindowTemplate sShowcaseMultiPartyMenuWindowTemplate[] = { - { - .bg = 0, - .tilemapLeft = 1, - .tilemapTop = 2, - .width = 10, - .height = 7, - .paletteNum = 3, - .baseBlock = 0x63, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 3, - .width = 18, - .height = 3, - .paletteNum = 5, - .baseBlock = 0xA9, - }, - { - .bg = 0, - .tilemapLeft = 12, - .tilemapTop = 6, - .width = 18, - .height = 3, - .paletteNum = 6, - .baseBlock = 0xDF, - }, - { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 11, - .width = 10, - .height = 7, - .paletteNum = 4, - .baseBlock = 0x115, - }, - { - .bg = 2, - .tilemapLeft = 12, - .tilemapTop = 12, - .width = 18, - .height = 3, - .paletteNum = 7, - .baseBlock = 0x16B, - }, - { - .bg = 2, - .tilemapLeft = 12, - .tilemapTop = 15, - .width = 18, - .height = 3, - .paletteNum = 8, - .baseBlock = 0x1A1, - }, - DUMMY_WIN_TEMPLATE + { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 2, + .width = 10, + .height = 7, + .paletteNum = 3, + .baseBlock = 0x63, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 3, + .width = 18, + .height = 3, + .paletteNum = 5, + .baseBlock = 0xA9, + }, + { + .bg = 0, + .tilemapLeft = 12, + .tilemapTop = 6, + .width = 18, + .height = 3, + .paletteNum = 6, + .baseBlock = 0xDF, + }, + { + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 11, + .width = 10, + .height = 7, + .paletteNum = 4, + .baseBlock = 0x115, + }, + { + .bg = 2, + .tilemapLeft = 12, + .tilemapTop = 12, + .width = 18, + .height = 3, + .paletteNum = 7, + .baseBlock = 0x16B, + }, + { + .bg = 2, + .tilemapLeft = 12, + .tilemapTop = 15, + .width = 18, + .height = 3, + .paletteNum = 8, + .baseBlock = 0x1A1, + }, + DUMMY_WIN_TEMPLATE }; -static const struct WindowTemplate gUnknown_08615908 = +static const struct WindowTemplate sCancelButtonWindowTemplate = { - .bg = 0, - .tilemapLeft = 24, - .tilemapTop = 17, - .width = 6, - .height = 2, - .paletteNum = 3, - .baseBlock = 0x1C7, + .bg = 0, + .tilemapLeft = 24, + .tilemapTop = 17, + .width = 6, + .height = 2, + .paletteNum = 3, + .baseBlock = 0x1C7, }; -static const struct WindowTemplate gUnknown_08615910 = +static const struct WindowTemplate sMultiCancelButtonWindowTemplate = { - .bg = 0, - .tilemapLeft = 24, - .tilemapTop = 18, - .width = 6, - .height = 2, - .paletteNum = 3, - .baseBlock = 0x1C7, + .bg = 0, + .tilemapLeft = 24, + .tilemapTop = 18, + .width = 6, + .height = 2, + .paletteNum = 3, + .baseBlock = 0x1C7, }; -static const struct WindowTemplate gUnknown_08615918 = +static const struct WindowTemplate sConfirmButtonWindowTemplate = { - .bg = 0, - .tilemapLeft = 24, - .tilemapTop = 16, - .width = 6, - .height = 2, - .paletteNum = 3, - .baseBlock = 0x1D3, + .bg = 0, + .tilemapLeft = 24, + .tilemapTop = 16, + .width = 6, + .height = 2, + .paletteNum = 3, + .baseBlock = 0x1D3, }; static const struct WindowTemplate sDefaultPartyMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 17, - .width = 21, - .height = 2, - .paletteNum = 15, - .baseBlock = 0x24F, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 17, + .width = 21, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x24F, }; static const struct WindowTemplate sDoWhatWithMonMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 17, - .width = 16, - .height = 2, - .paletteNum = 15, - .baseBlock = 0x279, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 17, + .width = 16, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x279, }; static const struct WindowTemplate sDoWhatWithItemMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 17, - .width = 20, - .height = 2, - .paletteNum = 15, - .baseBlock = 0x299, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 17, + .width = 20, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x299, }; static const struct WindowTemplate sDoWhatWithMailMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 17, - .width = 18, - .height = 2, - .paletteNum = 15, - .baseBlock = 0x299, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 17, + .width = 18, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x299, }; static const struct WindowTemplate sWhichMoveMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 17, - .width = 16, - .height = 2, - .paletteNum = 15, - .baseBlock = 0x299, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 17, + .width = 16, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x299, }; static const struct WindowTemplate sAlreadyHoldingOneMsgWindowTemplate = { - .bg = 2, - .tilemapLeft = 1, - .tilemapTop = 15, - .width = 20, - .height = 4, - .paletteNum = 15, - .baseBlock = 0x299, + .bg = 2, + .tilemapLeft = 1, + .tilemapTop = 15, + .width = 20, + .height = 4, + .paletteNum = 15, + .baseBlock = 0x299, }; static const struct WindowTemplate sItemGiveTakeWindowTemplate = { - .bg = 2, - .tilemapLeft = 23, - .tilemapTop = 13, - .width = 6, - .height = 6, - .paletteNum = 14, - .baseBlock = 0x39D, + .bg = 2, + .tilemapLeft = 23, + .tilemapTop = 13, + .width = 6, + .height = 6, + .paletteNum = 14, + .baseBlock = 0x39D, }; static const struct WindowTemplate sMailReadTakeWindowTemplate = { - .bg = 2, - .tilemapLeft = 21, - .tilemapTop = 13, - .width = 8, - .height = 6, - .paletteNum = 14, - .baseBlock = 0x39D, + .bg = 2, + .tilemapLeft = 21, + .tilemapTop = 13, + .width = 8, + .height = 6, + .paletteNum = 14, + .baseBlock = 0x39D, }; static const struct WindowTemplate sMoveSelectWindowTemplate = { - .bg = 2, - .tilemapLeft = 19, - .tilemapTop = 11, - .width = 10, - .height = 8, - .paletteNum = 14, - .baseBlock = 0x2E9, + .bg = 2, + .tilemapLeft = 19, + .tilemapTop = 11, + .width = 10, + .height = 8, + .paletteNum = 14, + .baseBlock = 0x2E9, }; static const struct WindowTemplate sPartyMenuYesNoWindowTemplate = { - .bg = 2, - .tilemapLeft = 21, - .tilemapTop = 9, - .width = 5, - .height = 4, - .paletteNum = 14, - .baseBlock = 0x2E9, + .bg = 2, + .tilemapLeft = 21, + .tilemapTop = 9, + .width = 5, + .height = 4, + .paletteNum = 14, + .baseBlock = 0x2E9, }; static const struct WindowTemplate sLevelUpStatsWindowTemplate = { - .bg = 2, - .tilemapLeft = 19, - .tilemapTop = 1, - .width = 10, - .height = 11, - .paletteNum = 14, - .baseBlock = 0x2E9, + .bg = 2, + .tilemapLeft = 19, + .tilemapTop = 1, + .width = 10, + .height = 11, + .paletteNum = 14, + .baseBlock = 0x2E9, }; static const struct WindowTemplate sUnusedWindowTemplate_08615978 = { - .bg = 2, - .tilemapLeft = 2, - .tilemapTop = 15, - .width = 27, - .height = 4, - .paletteNum = 14, - .baseBlock = 0x1DF, + .bg = 2, + .tilemapLeft = 2, + .tilemapTop = 15, + .width = 27, + .height = 4, + .paletteNum = 14, + .baseBlock = 0x1DF, }; static const struct WindowTemplate sUnusedWindowTemplate_08615980 = { - .bg = 2, - .tilemapLeft = 0, - .tilemapTop = 13, - .width = 18, - .height = 3, - .paletteNum = 12, - .baseBlock = 0x39D, + .bg = 2, + .tilemapLeft = 0, + .tilemapTop = 13, + .width = 18, + .height = 3, + .paletteNum = 12, + .baseBlock = 0x39D, }; // Tile nums @@ -1024,36 +1034,35 @@ static const u8 sPartyBoxCurrSelectionPalIds2[] = {97, 103, 104}; static const u8 sPartyBoxSelectedForActionPalIds2[] = {161, 167, 168}; static const u8 sPartyBoxNoMonPalIds[] = {17, 27, 28}; -//TOOD: IDs? static const u8 *const sActionStringTable[] = { - gText_ChoosePokemon, - gText_ChoosePokemonCancel, - gText_ChoosePokemonConfirm, - gText_MoveToWhere, - gText_TeachWhichPokemon, - gText_UseOnWhichPokemon, - gText_GiveToWhichPokemon, - gText_NothingToCut, - gText_CantSurfHere, - gText_AlreadySurfing, - gText_CurrentIsTooFast, - gText_EnjoyCycling, - gText_InUseAlready_PM, - gText_CantUseHere, - gText_NoPokemonForBattle, - gText_ChoosePokemon2, - gText_NotEnoughHp, - gText_PokemonAreNeeded, - gText_PokemonCantBeSame, - gText_NoIdenticalHoldItems, - gText_EmptyString2, - gText_DoWhatWithPokemon, - gText_RestoreWhichMove, - gText_BoostPp, - gText_DoWhatWithItem, - gText_DoWhatWithMail, - gText_AlreadyHoldingOne, + [PARTY_MSG_CHOOSE_MON] = gText_ChoosePokemon, + [PARTY_MSG_CHOOSE_MON_OR_CANCEL] = gText_ChoosePokemonCancel, + [PARTY_MSG_CHOOSE_MON_AND_CONFIRM] = gText_ChoosePokemonConfirm, + [PARTY_MSG_MOVE_TO_WHERE] = gText_MoveToWhere, + [PARTY_MSG_TEACH_WHICH_MON] = gText_TeachWhichPokemon, + [PARTY_MSG_USE_ON_WHICH_MON] = gText_UseOnWhichPokemon, + [PARTY_MSG_GIVE_TO_WHICH_MON] = gText_GiveToWhichPokemon, + [PARTY_MSG_NOTHING_TO_CUT] = gText_NothingToCut, + [PARTY_MSG_CANT_SURF_HERE] = gText_CantSurfHere, + [PARTY_MSG_ALREADY_SURFING] = gText_AlreadySurfing, + [PARTY_MSG_CURRENT_TOO_FAST] = gText_CurrentIsTooFast, + [PARTY_MSG_ENJOY_CYCLING] = gText_EnjoyCycling, + [PARTY_MSG_ALREADY_IN_USE] = gText_InUseAlready_PM, + [PARTY_MSG_CANT_USE_HERE] = gText_CantUseHere, + [PARTY_MSG_NO_MON_FOR_BATTLE] = gText_NoPokemonForBattle, + [PARTY_MSG_CHOOSE_MON_2] = gText_ChoosePokemon2, + [PARTY_MSG_NOT_ENOUGH_HP] = gText_NotEnoughHp, + [PARTY_MSG_X_MONS_ARE_NEEDED] = gText_PokemonAreNeeded, + [PARTY_MSG_MONS_CANT_BE_SAME] = gText_PokemonCantBeSame, + [PARTY_MSG_NO_SAME_HOLD_ITEMS] = gText_NoIdenticalHoldItems, + [PARTY_MSG_UNUSED] = gText_EmptyString2, + [PARTY_MSG_DO_WHAT_WITH_MON] = gText_DoWhatWithPokemon, + [PARTY_MSG_RESTORE_WHICH_MOVE] = gText_RestoreWhichMove, + [PARTY_MSG_BOOST_PP_WHICH_MOVE] = gText_BoostPp, + [PARTY_MSG_DO_WHAT_WITH_ITEM] = gText_DoWhatWithItem, + [PARTY_MSG_DO_WHAT_WITH_MAIL] = gText_DoWhatWithMail, + [PARTY_MSG_ALREADY_HOLDING_ONE] = gText_AlreadyHoldingOne, }; static const u8 *const sDescriptionStringTable[] = @@ -1365,7 +1374,7 @@ static const union AnimCmd sPokeballAnim_Open[] = ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_Pokeball[] = +static const union AnimCmd *const sSpriteAnimTable_MenuPokeball[] = { sPokeballAnim_Closed, sPokeballAnim_Open @@ -1381,19 +1390,19 @@ static const struct CompressedSpritePalette sSpritePalette_MenuPokeball = gPartyMenuPokeball_Pal, 0x04b0 }; -// TODO: menu pokeball is vague, these are mon menu pokeballs, but not confirm/cancel pokeballs +// Used for the pokeball sprite on each party slot / Cancel button static const struct SpriteTemplate sSpriteTemplate_MenuPokeball = { .tileTag = 0x04b0, .paletteTag = 0x04b0, .oam = &sOamData_MenuPokeball, - .anims = sSpriteAnimTable_Pokeball, + .anims = sSpriteAnimTable_MenuPokeball, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -static const struct OamData sOamData_8615F20 = +static const struct OamData sOamData_MenuPokeballSmall = { .y = 0, .affineMode = 0, @@ -1410,50 +1419,51 @@ static const struct OamData sOamData_8615F20 = .affineParam = 0 }; -static const union AnimCmd sSpriteAnim_8615F28[] = +static const union AnimCmd sSmallPokeballAnim_Closed[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8615F30[] = +static const union AnimCmd sSmallPokeballAnim_Open[] = { ANIMCMD_FRAME(4, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8615F38[] = +static const union AnimCmd sSmallPokeballAnim_Blank1[] = { ANIMCMD_FRAME(8, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8615F40[] = +static const union AnimCmd sSmallPokeballAnim_Blank2[] = { ANIMCMD_FRAME(12, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8615F48[] = +static const union AnimCmd sSmallPokeballAnim_Blank3[] = { ANIMCMD_FRAME(16, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8615F50[] = +static const union AnimCmd sSmallPokeballAnim_Blank4[] = { ANIMCMD_FRAME(20, 0), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_8615F58[] = +// The blanks below are never used +static const union AnimCmd *const sSpriteAnimTable_MenuPokeballSmall[] = { - sSpriteAnim_8615F28, - sSpriteAnim_8615F30, - sSpriteAnim_8615F38, - sSpriteAnim_8615F40, - sSpriteAnim_8615F48, - sSpriteAnim_8615F50 + sSmallPokeballAnim_Closed, + sSmallPokeballAnim_Open, + sSmallPokeballAnim_Blank1, + sSmallPokeballAnim_Blank2, + sSmallPokeballAnim_Blank3, + sSmallPokeballAnim_Blank4 }; static const struct CompressedSpriteSheet sSpriteSheet_MenuPokeballSmall = @@ -1461,12 +1471,13 @@ static const struct CompressedSpriteSheet sSpriteSheet_MenuPokeballSmall = gPartyMenuPokeballSmall_Gfx, 0x0300, 0x04b1 }; -static const struct SpriteTemplate gSpriteTemplate_8615F78 = +// Used for the pokeball sprite next to Cancel and Confirm when both are present, otherwise sSpriteTemplate_MenuPokeball is used +static const struct SpriteTemplate sSpriteTemplate_MenuPokeballSmall = { .tileTag = 1201, .paletteTag = 1200, - .oam = &sOamData_8615F20, - .anims = sSpriteAnimTable_8615F58, + .oam = &sOamData_MenuPokeballSmall, + .anims = sSpriteAnimTable_MenuPokeballSmall, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -1572,7 +1583,7 @@ static const struct SpriteTemplate sSpriteTemplate_StatusIcons = // Mask for the partners party in a multi battle // TRUE if in the partners party, FALSE otherwise -// The last two slots after the 6 party members are Confirm/Cancel TODO: this doesnt make sense, if confirm/cancel are present the partners party isnt either +// The 7th slot is Cancel, and the 8th slot is unreachable static const bool8 sMultiBattlePartnersPartyMask[PARTY_SIZE + 2] = { FALSE, @@ -1581,7 +1592,6 @@ static const bool8 sMultiBattlePartnersPartyMask[PARTY_SIZE + 2] = FALSE, TRUE, TRUE, - FALSE, FALSE }; @@ -1676,7 +1686,7 @@ static void InitPartyMenu(u8 menuType, u8 layout, u8 partyAction, bool8 keepCurs sPartyMenuInternal->messageId = messageId; sPartyMenuInternal->task = task; sPartyMenuInternal->exitCallback = NULL; - sPartyMenuInternal->unk8_1 = 0; + sPartyMenuInternal->lastSelectedSlot = 0; sPartyMenuInternal->spriteIdConfirmPokeball = 0x7F; sPartyMenuInternal->spriteIdCancelPokeball = 0x7F; @@ -1724,7 +1734,7 @@ static void CB2_InitPartyMenu(void) { while (TRUE) { - if (sub_81221EC() == TRUE || ShowPartyMenu() == TRUE || sub_81221AC() == TRUE) + if (sub_81221EC() == TRUE || ShowPartyMenu() == TRUE || sub_81221AC() == TRUE) //SKP break; } } @@ -1757,7 +1767,7 @@ static bool8 ShowPartyMenu(void) gMain.state++; break; case 5: - if (!sub_81221AC()) + if (!sub_81221AC()) //SKP ResetTasks(); gMain.state++; break; @@ -1807,7 +1817,7 @@ static bool8 ShowPartyMenu(void) gMain.state++; break; case 15: - if (party_menu_add_per_mon_objects()) + if (CreatePartyMonSpritesLoop()) { sPartyMenuInternal->data[0] = 0; gMain.state++; @@ -1825,7 +1835,7 @@ static bool8 ShowPartyMenu(void) gMain.state++; break; case 18: - sub_81B2428(sPartyMenuInternal->chooseHalf); + CreateCancelConfirmWindows(sPartyMenuInternal->chooseHalf); gMain.state++; break; case 19: @@ -1995,7 +2005,7 @@ static void InitPartyMenuBoxes(u8 layout) static void RenderPartyMenuBox(u8 slot) { - if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_MULTI_BATTLE && slot > 2) + if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE && slot > 2) { DisplayPartyPokemonDataForMultiBattle(slot); if (gMultiPartnerParty[slot - 3].species == SPECIES_NONE) @@ -2029,7 +2039,7 @@ static void RenderPartyMenuBox(u8 slot) else if (!DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(slot)) DisplayPartyPokemonData(slot); - if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_MULTI_BATTLE) + if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE) AnimatePartySlot(slot, 0); else if (gPartyMenu.slotId == slot) AnimatePartySlot(slot, 1); @@ -2189,7 +2199,6 @@ static void DisplayPartyPokemonDataToTeachMove(u8 slot, u16 item, u8 tutor) } } -// TODO: sort out unknowns static void DisplayPartyPokemonDataForMultiBattle(u8 slot) { struct PartyMenuBox *menuBox = &sPartyMenuBoxes[slot]; @@ -2204,7 +2213,7 @@ static void DisplayPartyPokemonDataForMultiBattle(u8 slot) menuBox->infoRects->blitFunc(menuBox->windowId, 0, 0, 0, 0, FALSE); StringCopy(gStringVar1, gMultiPartnerParty[actualSlot].nickname); StringGetEnd10(gStringVar1); - sub_81DB52C(gStringVar1); + sub_81DB52C(gStringVar1); //SKP DisplayPartyPokemonBarDetail(menuBox->windowId, gStringVar1, 0, menuBox->infoRects->dimensions); DisplayPartyPokemonLevel(gMultiPartnerParty[actualSlot].level, menuBox); DisplayPartyPokemonGender(gMultiPartnerParty[actualSlot].gender, gMultiPartnerParty[actualSlot].species, gMultiPartnerParty[actualSlot].nickname, menuBox); @@ -2228,64 +2237,63 @@ static u8* GetPartyMenuBgTile(u16 tileId) return &sPartyBgGfxTilemap[tileId << 5]; } -//TODO: rename and all related functions -static void party_menu_add_per_mon_objects_internal(u8 slot) +static void CreatePartyMonSprites(u8 slot) { u8 actualSlot; - if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_MULTI_BATTLE && slot > 2) + if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE && slot > 2) { u8 status; actualSlot = slot - 3; if (gMultiPartnerParty[actualSlot].species != SPECIES_NONE) { - party_menu_link_mon_icon_anim(gMultiPartnerParty[actualSlot].species, gMultiPartnerParty[actualSlot].personality, &sPartyMenuBoxes[slot], 0, 0); - party_menu_link_mon_held_item_object(gMultiPartnerParty[actualSlot].species, gMultiPartnerParty[actualSlot].heldItem, &sPartyMenuBoxes[slot]); - party_menu_link_mon_pokeball_object(gMultiPartnerParty[actualSlot].species, &sPartyMenuBoxes[slot]); + CreatePartyMonIconSpriteParameterized(gMultiPartnerParty[actualSlot].species, gMultiPartnerParty[actualSlot].personality, &sPartyMenuBoxes[slot], 0, FALSE); + CreatePartyMonHeldItemSpriteParameterized(gMultiPartnerParty[actualSlot].species, gMultiPartnerParty[actualSlot].heldItem, &sPartyMenuBoxes[slot]); + CreatePartyMonPokeballSpriteParameterized(gMultiPartnerParty[actualSlot].species, &sPartyMenuBoxes[slot]); if (gMultiPartnerParty[actualSlot].hp == 0) status = AILMENT_FNT; else status = GetAilmentFromStatus(gMultiPartnerParty[actualSlot].status); - party_menu_link_mon_status_condition_object(gMultiPartnerParty[actualSlot].species, status, &sPartyMenuBoxes[slot]); + CreatePartyMonStatusSpriteParameterized(gMultiPartnerParty[actualSlot].species, status, &sPartyMenuBoxes[slot]); } } else if (GetMonData(&gPlayerParty[slot], MON_DATA_SPECIES) != SPECIES_NONE) { - party_menu_icon_anim(&gPlayerParty[slot], &sPartyMenuBoxes[slot], slot); - party_menu_held_item_object(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); - party_menu_pokeball_object(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); - party_menu_status_condition_object(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); + CreatePartyMonIconSprite(&gPlayerParty[slot], &sPartyMenuBoxes[slot], slot); + CreatePartyMonHeldItemSprite(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); + CreatePartyMonPokeballSprite(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); + CreatePartyMonStatusSprite(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); } } -static bool8 party_menu_add_per_mon_objects(void) +static bool8 CreatePartyMonSpritesLoop(void) { - party_menu_add_per_mon_objects_internal(sPartyMenuInternal->data[0]); + CreatePartyMonSprites(sPartyMenuInternal->data[0]); if (++sPartyMenuInternal->data[0] == PARTY_SIZE) return TRUE; else return FALSE; } -// TODO Fix name, first if doesnt do that static void CreateCancelConfirmPokeballSprites(void) { - if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_MULTI_BATTLE) + if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE) { + // The showcase has no Cancel/Confirm buttons FillBgTilemapBufferRect(1, 14, 23, 17, 7, 2, 1); } else { if (sPartyMenuInternal->chooseHalf) { - sPartyMenuInternal->spriteIdConfirmPokeball = CreateMenuPokeballSprite(0xBF, 0x88); - sub_81B120C(); - sPartyMenuInternal->spriteIdCancelPokeball = CreateMenuPokeballSprite(0xBF, 0x98); + sPartyMenuInternal->spriteIdConfirmPokeball = CreateSmallPokeballButtonSprite(0xBF, 0x88); + DrawCancelConfirmButtons(); + sPartyMenuInternal->spriteIdCancelPokeball = CreateSmallPokeballButtonSprite(0xBF, 0x98); } else { - sPartyMenuInternal->spriteIdCancelPokeball = CreateCancelPokeballSprite(198, 148); + sPartyMenuInternal->spriteIdCancelPokeball = CreatePokeballButtonSprite(198, 148); } AnimatePartySlot(gPartyMenu.slotId, 1); } @@ -2305,28 +2313,29 @@ void AnimatePartySlot(u8 slot, u8 animNum) PartyMenuStartSpriteAnim(sPartyMenuBoxes[slot].pokeballSpriteId, animNum); } return; - case PARTY_SIZE: + case PARTY_SIZE: // Confirm if (animNum == 0) - sub_8199C30(1, 23, 16, 7, 2, 1); + SetBgTilemapPalette(1, 23, 16, 7, 2, 1); else - sub_8199C30(1, 23, 16, 7, 2, 2); + SetBgTilemapPalette(1, 23, 16, 7, 2, 2); spriteId = sPartyMenuInternal->spriteIdConfirmPokeball; break; case PARTY_SIZE + 1: // Cancel + // The position of the Cancel button changes if Confirm is present if (!sPartyMenuInternal->chooseHalf) { if (animNum == 0) - sub_8199C30(1, 23, 17, 7, 2, 1); + SetBgTilemapPalette(1, 23, 17, 7, 2, 1); else - sub_8199C30(1, 23, 17, 7, 2, 2); + SetBgTilemapPalette(1, 23, 17, 7, 2, 2); } else if (animNum == 0) { - sub_8199C30(1, 23, 18, 7, 2, 1); + SetBgTilemapPalette(1, 23, 18, 7, 2, 1); } else { - sub_8199C30(1, 23, 18, 7, 2, 2); + SetBgTilemapPalette(1, 23, 18, 7, 2, 2); } spriteId = sPartyMenuInternal->spriteIdCancelPokeball; break; @@ -2369,11 +2378,10 @@ static bool8 PartyBoxPal_ParnterOrDisqualifiedInArena(u8 slot) return FALSE; } -//TODO: tilemaps for confirm/cancel buttons in choose 3, double check -static void sub_81B120C(void) +static void DrawCancelConfirmButtons(void) { - CopyToBgTilemapBufferRect_ChangePalette(1, sConfirmButtonPokeball_Tilemap, 23, 16, 7, 2, 17); - CopyToBgTilemapBufferRect_ChangePalette(1, sCancelButtonPokeball_Tilemap, 23, 18, 7, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sConfirmButton_Tilemap, 23, 16, 7, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sCancelButton_Tilemap, 23, 18, 7, 2, 17); schedule_bg_copy_tilemap_to_vram(1); } @@ -2409,7 +2417,7 @@ static void Task_ClosePartyMenuAndSetCB2(u8 taskId) if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_BATTLE) UpdatePartyToFieldOrder(); - if (sPartyMenuInternal->exitCallback != NULL) + if (sPartyMenuInternal->exitCallback != NULL) SetMainCallback2(sPartyMenuInternal->exitCallback); else SetMainCallback2(gPartyMenu.exitCallback); @@ -2432,7 +2440,7 @@ u8 GetPartyMenuType(void) void Task_HandleChooseMonInput(u8 taskId) { - if (!gPaletteFade.active && sub_81221EC() != TRUE) + if (!gPaletteFade.active && sub_81221EC() != TRUE) //SKP { s8 *slotPtr = GetCurrentPartySlotPtr(); @@ -2448,7 +2456,7 @@ void Task_HandleChooseMonInput(u8 taskId) if (sPartyMenuInternal->chooseHalf) { PlaySE(SE_SELECT); - sub_81B4F88(); + MoveCursorToConfirm(); } break; } @@ -2512,7 +2520,7 @@ static void HandleChooseMonSelection(u8 taskId, s8 *slotPtr) { PlaySE(SE_SELECT); PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[1]); - TryGiveItemToSelectedMon(taskId); + TryGiveItemOrMailToSelectedMon(taskId); } break; case PARTY_ACTION_SWITCH - 3: @@ -2569,9 +2577,9 @@ static void HandleChooseMonCancel(u8 taskId, s8 *slotPtr) PlaySE(SE_SELECT); if (DisplayCancelChooseMonYesNo(taskId) != TRUE) { - if (!sub_81221AC()) + if (!sub_81221AC()) //SKP gSpecialVar_0x8004 = PARTY_SIZE + 1; - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; *slotPtr = PARTY_SIZE + 1; Task_ClosePartyMenu(taskId); } @@ -2612,7 +2620,7 @@ static void Task_HandleCancelChooseMonYesNoInput(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case 0: - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; gPartyMenu.slotId = PARTY_SIZE + 1; ClearSelectedPartyOrder(); Task_ClosePartyMenu(taskId); @@ -2633,25 +2641,25 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) switch (gMain.newAndRepeatedKeys) { case DPAD_UP: - movementDir = -1; + movementDir = MENU_DIR_UP; break; case DPAD_DOWN: - movementDir = 1; + movementDir = MENU_DIR_DOWN; break; case DPAD_LEFT: - movementDir = -2; + movementDir = MENU_DIR_LEFT; break; case DPAD_RIGHT: - movementDir = 2; + movementDir = MENU_DIR_RIGHT; break; default: switch (GetLRKeysPressedAndHeld()) { case MENU_L_PRESSED: - movementDir = -1; + movementDir = MENU_DIR_UP; break; case MENU_R_PRESSED: - movementDir = 1; + movementDir = MENU_DIR_DOWN; break; default: movementDir = 0; @@ -2683,7 +2691,7 @@ static void UpdateCurrentPartySelection(s8 *slotPtr, s8 movementDir) if (layout == PARTY_LAYOUT_SINGLE) UpdatePartySelectionSingleLayout(slotPtr, movementDir); - else // remaining double/multi layouts handle movement the same way + else UpdatePartySelectionDoubleLayout(slotPtr, movementDir); if (*slotPtr != newSlotId) @@ -2694,13 +2702,12 @@ static void UpdateCurrentPartySelection(s8 *slotPtr, s8 movementDir) } } -// TODO: clean up static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) { - // PARTY_SIZE + 1 is Cancel, the 7th party menu selection + // PARTY_SIZE + 1 is Cancel, PARTY_SIZE is Confirm (when choosing half only) switch (movementDir) { - case -1: + case MENU_DIR_UP: if (*slotPtr == 0) { *slotPtr = PARTY_SIZE + 1; @@ -2721,7 +2728,7 @@ static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) (*slotPtr)--; } break; - case 1: + case MENU_DIR_DOWN: if (*slotPtr == PARTY_SIZE + 1) { *slotPtr = 0; @@ -2741,34 +2748,34 @@ static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) } } break; - case 2: + case MENU_DIR_RIGHT: if (gPlayerPartyCount != 1 && *slotPtr == 0) { - if (sPartyMenuInternal->unk8_1 == 0) + if (sPartyMenuInternal->lastSelectedSlot == 0) *slotPtr = 1; else - *slotPtr = sPartyMenuInternal->unk8_1; + *slotPtr = sPartyMenuInternal->lastSelectedSlot; } break; - case -2: + case MENU_DIR_LEFT: if (*slotPtr != 0 && *slotPtr != PARTY_SIZE && *slotPtr != PARTY_SIZE + 1) { - sPartyMenuInternal->unk8_1 = *slotPtr; + sPartyMenuInternal->lastSelectedSlot = *slotPtr; *slotPtr = 0; } break; } } -// TODO: clean up static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) { - // PARTY_SIZE + 1 is Cancel, the 7th party menu selection - s8 unk2 = movementDir; + // PARTY_SIZE + 1 is Cancel, PARTY_SIZE is Confirm (when choosing half only) + // newSlot is used temporarily as a movement direction during its later assignment + s8 newSlot = movementDir; switch (movementDir) { - case -1: + case MENU_DIR_UP: if (*slotPtr == 0) { *slotPtr = PARTY_SIZE + 1; @@ -2788,11 +2795,11 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) } (*slotPtr)--; } - unk2 = sub_81B1B00(*slotPtr, unk2); - if (unk2 != -1) - *slotPtr = unk2; + newSlot = GetNewSlotDoubleLayout(*slotPtr, newSlot); + if (newSlot != -1) + *slotPtr = newSlot; break; - case 1: + case MENU_DIR_DOWN: if (*slotPtr == PARTY_SIZE) { *slotPtr = PARTY_SIZE + 1; @@ -2803,8 +2810,8 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) } else { - unk2 = sub_81B1B00(*slotPtr, 1); - if (unk2 == -1) + newSlot = GetNewSlotDoubleLayout(*slotPtr, MENU_DIR_DOWN); + if (newSlot == -1) { if (sPartyMenuInternal->chooseHalf) *slotPtr = PARTY_SIZE; @@ -2813,14 +2820,14 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) } else { - *slotPtr = unk2; + *slotPtr = newSlot; } } break; - case 2: + case MENU_DIR_RIGHT: if (*slotPtr == 0) { - if (sPartyMenuInternal->unk8_1 == 3) + if (sPartyMenuInternal->lastSelectedSlot == 3) { if (GetMonData(&gPlayerParty[3], MON_DATA_SPECIES) != SPECIES_NONE) *slotPtr = 3; @@ -2832,7 +2839,7 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) } else if (*slotPtr == 1) { - if (sPartyMenuInternal->unk8_1 == 5) + if (sPartyMenuInternal->lastSelectedSlot == 5) { if (GetMonData(&gPlayerParty[5], MON_DATA_SPECIES) != SPECIES_NONE) *slotPtr = 5; @@ -2843,26 +2850,26 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) } } break; - case -2: + case MENU_DIR_LEFT: if (*slotPtr == 2 || *slotPtr == 3) { - sPartyMenuInternal->unk8_1 = *slotPtr; + sPartyMenuInternal->lastSelectedSlot = *slotPtr; *slotPtr = 0; } else if (*slotPtr == 4 || *slotPtr == 5) { - sPartyMenuInternal->unk8_1 = *slotPtr; + sPartyMenuInternal->lastSelectedSlot = *slotPtr; *slotPtr = 1; } break; } } -static s8 sub_81B1B00(s8 slotId, s8 b) +static s8 GetNewSlotDoubleLayout(s8 slotId, s8 movementDir) { while (TRUE) { - slotId += b; + slotId += movementDir; if ((u8)slotId >= PARTY_SIZE) return -1; if (GetMonData(&gPlayerParty[slotId], MON_DATA_SPECIES) != SPECIES_NONE) @@ -2910,7 +2917,7 @@ bool8 IsPartyMenuTextPrinterActive(void) static void Task_WaitForLinkAndReturnToChooseMon(u8 taskId) { - if (sub_81221EC() != TRUE) + if (sub_81221EC() != TRUE) //SKP { DisplayPartyMenuStdMessage(PARTY_MSG_CHOOSE_MON); gTasks[taskId].func = Task_HandleChooseMonInput; @@ -2923,7 +2930,7 @@ static void Task_ReturnToChooseMonAfterText(u8 taskId) { ClearStdWindowAndFrameToTransparent(6, 0); ClearWindowTilemap(6); - if (sub_81221AC() == TRUE) + if (sub_81221AC() == TRUE) //SKP { gTasks[taskId].func = Task_WaitForLinkAndReturnToChooseMon; } @@ -3118,8 +3125,8 @@ static void SetPartyMonsAllowedInMinigame(void) { u8 i; - ptr = &gPartyMenu.unkE; - gPartyMenu.unkE = 0; + ptr = &gPartyMenu.data1; + gPartyMenu.data1 = 0; if (gSpecialVar_0x8005 == 0) { for (i = 0; i < gPlayerPartyCount; i++) @@ -3150,7 +3157,7 @@ static bool16 IsMonAllowedInDodrioBerryPicking(struct Pokemon *mon) static bool8 IsMonAllowedInMinigame(u8 slot) { - if (!((gPartyMenu.unkE >> slot) & 1)) + if (!((gPartyMenu.data1 >> slot) & 1)) return FALSE; return TRUE; } @@ -3275,46 +3282,46 @@ static void InitPartyMenuWindows(u8 layout) LoadPalette(gUnknown_0860F074, 0xF0, 0x20); } -// TODO -static void sub_81B2428(bool8 chooseHalf) +static void CreateCancelConfirmWindows(bool8 chooseHalf) { - u8 firstWindowId; - u8 windowId; + u8 confirmWindowId; + u8 cancelWindowId; u8 offset; u8 mainOffset; - if (gPartyMenu.menuType != PARTY_MENU_TYPE_IN_MULTI_BATTLE) + if (gPartyMenu.menuType != PARTY_MENU_TYPE_MULTI_SHOWCASE) { if (chooseHalf == TRUE) { - firstWindowId = AddWindow(&gUnknown_08615918); - FillWindowPixelBuffer(firstWindowId, PIXEL_FILL(0)); + confirmWindowId = AddWindow(&sConfirmButtonWindowTemplate); + FillWindowPixelBuffer(confirmWindowId, PIXEL_FILL(0)); mainOffset = GetStringCenterAlignXOffset(0, gMenuText_Confirm, 48); - AddTextPrinterParameterized4(firstWindowId, 0, mainOffset, 1, 0, 0, sFontColorTable[0], -1, gMenuText_Confirm); - PutWindowTilemap(firstWindowId); - CopyWindowToVram(firstWindowId, 2); - windowId = AddWindow(&gUnknown_08615910); + AddTextPrinterParameterized4(confirmWindowId, 0, mainOffset, 1, 0, 0, sFontColorTable[0], -1, gMenuText_Confirm); + PutWindowTilemap(confirmWindowId); + CopyWindowToVram(confirmWindowId, 2); + cancelWindowId = AddWindow(&sMultiCancelButtonWindowTemplate); offset = 0; } else { - windowId = AddWindow(&gUnknown_08615908); + cancelWindowId = AddWindow(&sCancelButtonWindowTemplate); offset = 3; } - FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); + FillWindowPixelBuffer(cancelWindowId, PIXEL_FILL(0)); + + // Branches are functionally identical. Second branch is never reached, Spin Trade wasnt fully implemented if (gPartyMenu.menuType != PARTY_MENU_TYPE_SPIN_TRADE) { mainOffset = GetStringCenterAlignXOffset(0, gText_Cancel, 48); - AddTextPrinterParameterized3(windowId, 0, mainOffset + offset, 1, sFontColorTable[0], -1, gText_Cancel); + AddTextPrinterParameterized3(cancelWindowId, 0, mainOffset + offset, 1, sFontColorTable[0], -1, gText_Cancel); } else { - // Identical to above, Spin Trade wasnt implemented mainOffset = GetStringCenterAlignXOffset(0, gText_Cancel2, 48); - AddTextPrinterParameterized3(windowId, 0, mainOffset + offset, 1, sFontColorTable[0], -1, gText_Cancel2); + AddTextPrinterParameterized3(cancelWindowId, 0, mainOffset + offset, 1, sFontColorTable[0], -1, gText_Cancel2); } - PutWindowTilemap(windowId); - CopyWindowToVram(windowId, 2); + PutWindowTilemap(cancelWindowId); + CopyWindowToVram(cancelWindowId, 2); schedule_bg_copy_tilemap_to_vram(0); } } @@ -3711,11 +3718,12 @@ void DisplayPartyMenuStdMessage(u32 stringID) *windowPtr = AddWindow(&sDefaultPartyMsgWindowTemplate); break; } + if (stringID == PARTY_MSG_CHOOSE_MON) { if (sPartyMenuInternal->chooseHalf) stringID = PARTY_MSG_CHOOSE_MON_AND_CONFIRM; - else if (sub_81B314C() == FALSE) + else if (!ShouldUseChooseMonText()) stringID = PARTY_MSG_CHOOSE_MON_OR_CANCEL; } DrawStdFrameWithCustomTileAndPalette(*windowPtr, FALSE, 0x4F, 0xD); @@ -3725,8 +3733,7 @@ void DisplayPartyMenuStdMessage(u32 stringID) } } -// TOOD: TRUE if should be forced to choose mon, but why when nummons > 1 -static bool8 sub_81B314C(void) +static bool8 ShouldUseChooseMonText(void) { struct Pokemon *party = gPlayerParty; u8 i; @@ -3770,15 +3777,15 @@ static u8 DisplaySelectionWindow(u8 windowType) sPartyMenuInternal->windowId[0] = AddWindow(&window); DrawStdFrameWithCustomTileAndPalette(sPartyMenuInternal->windowId[0], FALSE, 0x4F, 13); - if (windowType == 3) + if (windowType == SELECTWINDOW_MOVES) return sPartyMenuInternal->windowId[0]; cursorDimension = GetMenuCursorDimensionByFont(1, 0); fontAttribute = GetFontAttribute(1, 2); for (i = 0; i < sPartyMenuInternal->numActions; i++) { - u8 unk = (sPartyMenuInternal->actions[i] >= MENU_FIELD_MOVES) ? 4 : 3; - AddTextPrinterParameterized4(sPartyMenuInternal->windowId[0], 1, cursorDimension, (i * 16) + 1, fontAttribute, 0, sFontColorTable[unk], 0, sCursorOptions[sPartyMenuInternal->actions[i]].text); + u8 fontColorsId = (sPartyMenuInternal->actions[i] >= MENU_FIELD_MOVES) ? 4 : 3; + AddTextPrinterParameterized4(sPartyMenuInternal->windowId[0], 1, cursorDimension, (i * 16) + 1, fontAttribute, 0, sFontColorTable[fontColorsId], 0, sCursorOptions[sPartyMenuInternal->actions[i]].text); } InitMenuInUpperLeftCorner(sPartyMenuInternal->windowId[0], sPartyMenuInternal->numActions, 0, 1); @@ -3904,10 +3911,10 @@ static u8 GetPartyMenuActionsType(struct Pokemon *mon) case PARTY_MENU_TYPE_STORE_PYRAMID_HELD_ITEMS: actionType = ACTIONS_TAKEITEM_TOSS; break; - // The following have no selection actions because they exit immediately upon selection + // The following have no selection actions (i.e. they exit immediately upon selection) // PARTY_MENU_TYPE_CONTEST // PARTY_MENU_TYPE_CHOOSE_MON - // PARTY_MENU_TYPE_IN_MULTI_BATTLE ?? TODO + // PARTY_MENU_TYPE_MULTI_SHOWCASE // PARTY_MENU_TYPE_MOVE_RELEARNER // PARTY_MENU_TYPE_MINIGAME default: @@ -3963,7 +3970,7 @@ static void Task_TryCreateSelectionWindow(u8 taskId) static void Task_HandleSelectionMenuInput(u8 taskId) { - if (!gPaletteFade.active && sub_81221EC() != TRUE) + if (!gPaletteFade.active && sub_81221EC() != TRUE) //SKP { s8 input; s16 *data = gTasks[taskId].data; @@ -4436,10 +4443,10 @@ static void CB2_WriteMailToGiveMon(void) u8 mail = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_MAIL); DoEasyChatScreen( - EASY_CHAT_TYPE_MAIL, - gSaveBlock1Ptr->mail[mail].words, - CB2_ReturnToPartyMenuFromWritingMail, - EASY_CHAT_PERSON_DISPLAY_NONE); + EASY_CHAT_TYPE_MAIL, + gSaveBlock1Ptr->mail[mail].words, + CB2_ReturnToPartyMenuFromWritingMail, + EASY_CHAT_PERSON_DISPLAY_NONE); } static void CB2_ReturnToPartyMenuFromWritingMail(void) @@ -4447,6 +4454,7 @@ static void CB2_ReturnToPartyMenuFromWritingMail(void) struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; u16 item = GetMonData(mon, MON_DATA_HELD_ITEM); + // Canceled writing mail if (gSpecialVar_Result == FALSE) { TakeMailFromMon(mon); @@ -4455,13 +4463,15 @@ static void CB2_ReturnToPartyMenuFromWritingMail(void) AddBagItem(item, 1); InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_CHOOSE_MON, Task_TryCreateSelectionWindow, gPartyMenu.exitCallback); } + // Wrote mail else { - InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_NONE, sub_81B4624, gPartyMenu.exitCallback); + InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_NONE, Task_DisplayGaveMailFromPartyMessage, gPartyMenu.exitCallback); } } -static void sub_81B4624(u8 taskId) +// Nearly redundant with Task_DisplayGaveMailFromBagMessgae +static void Task_DisplayGaveMailFromPartyMessage(u8 taskId) { if (!gPaletteFade.active) { @@ -4602,16 +4612,16 @@ static void CursorCb_Mail(u8 taskId) static void CursorCb_Read(u8 taskId) { PlaySE(SE_SELECT); - sPartyMenuInternal->exitCallback = sub_81B4A98; + sPartyMenuInternal->exitCallback = CB2_ReadHeldMail; Task_ClosePartyMenu(taskId); } -static void sub_81B4A98(void) +static void CB2_ReadHeldMail(void) { - ReadMail(&gSaveBlock1Ptr->mail[GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_MAIL)], sub_81B4AE0, 1); + ReadMail(&gSaveBlock1Ptr->mail[GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_MAIL)], CB2_ReturnToPartyMenuFromReadingMail, 1); } -static void sub_81B4AE0(void) +static void CB2_ReturnToPartyMenuFromReadingMail(void) { gPaletteFade.bufferTransferDisabled = TRUE; InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_DO_WHAT_WITH_MON, Task_TryCreateSelectionWindow, gPartyMenu.exitCallback); @@ -4623,23 +4633,23 @@ static void CursorCb_TakeMail(u8 taskId) PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[1]); PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[0]); DisplayPartyMenuMessage(gText_SendMailToPC, TRUE); - gTasks[taskId].func = sub_81B4B6C; + gTasks[taskId].func = Task_SendMailToPCYesNo; } -static void sub_81B4B6C(u8 taskId) +static void Task_SendMailToPCYesNo(u8 taskId) { if (IsPartyMenuTextPrinterActive() != TRUE) { PartyMenuDisplayYesNoMenu(); - gTasks[taskId].func = sub_81B4BA0; + gTasks[taskId].func = Task_HandleSendMailToPCYesNoInput; } } -static void sub_81B4BA0(u8 taskId) +static void Task_HandleSendMailToPCYesNoInput(u8 taskId) { switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes, send to PC if (TakeMailFromMon2(&gPlayerParty[gPartyMenu.slotId]) != 0xFF) { DisplayPartyMenuMessage(gText_MailSentToPC, FALSE); @@ -4656,27 +4666,27 @@ static void sub_81B4BA0(u8 taskId) // fallthrough case 1: DisplayPartyMenuMessage(gText_MailMessageWillBeLost, TRUE); - gTasks[taskId].func = sub_81B4C60; + gTasks[taskId].func = Task_LoseMailMessageYesNo; break; } } -static void sub_81B4C60(u8 taskId) +static void Task_LoseMailMessageYesNo(u8 taskId) { if (IsPartyMenuTextPrinterActive() != TRUE) { PartyMenuDisplayYesNoMenu(); - gTasks[taskId].func = sub_81B4C94; + gTasks[taskId].func = Task_HandleLoseMailMessageYesNoInput; } } -static void sub_81B4C94(u8 taskId) +static void Task_HandleLoseMailMessageYesNoInput(u8 taskId) { u16 item; switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes, lose mail message item = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_HELD_ITEM); if (AddBagItem(item, 1) == TRUE) { @@ -4756,7 +4766,7 @@ static void CursorCb_Enter(u8 taskId) gSelectedOrderFromParty[i] = gPartyMenu.slotId + 1; DisplayPartyPokemonDescriptionText(i + PARTYBOX_DESC_FIRST, &sPartyMenuBoxes[gPartyMenu.slotId], 1); if (i == (maxBattlers - 1)) - sub_81B4F88(); + MoveCursorToConfirm(); DisplayPartyMenuStdMessage(PARTY_MSG_CHOOSE_MON); gTasks[taskId].func = Task_HandleChooseMonInput; return; @@ -4769,7 +4779,7 @@ static void CursorCb_Enter(u8 taskId) gTasks[taskId].func = Task_ReturnToChooseMonAfterText; } -static void sub_81B4F88(void) +static void MoveCursorToConfirm(void) { AnimatePartySlot(gPartyMenu.slotId, 0); gPartyMenu.slotId = PARTY_SIZE; @@ -4931,7 +4941,7 @@ static void CursorCb_FieldMove(u8 taskId) PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[0]); PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[1]); - if (sub_81221AC() == TRUE || InUnionRoom() == TRUE) + if (sub_81221AC() == TRUE || InUnionRoom() == TRUE) //SKP { if (fieldMove == FIELD_MOVE_MILK_DRINK || fieldMove == FIELD_MOVE_SOFT_BOILED) DisplayPartyMenuStdMessage(PARTY_MSG_CANT_USE_HERE); @@ -5146,23 +5156,25 @@ static bool8 SetUpFieldMove_Dive(void) return FALSE; } -static void party_menu_icon_anim(struct Pokemon *mon, struct PartyMenuBox *menuBox, u32 slot) +static void CreatePartyMonIconSprite(struct Pokemon *mon, struct PartyMenuBox *menuBox, u32 slot) { - bool32 bit = 1; + bool32 handleDeoxys = TRUE; u16 species2; + // If in a multi battle, show partners Deoxys icon as Normal forme if (IsMultiBattle() == TRUE && gMain.inBattle) - bit = (sMultiBattlePartnersPartyMask[slot] ^ bit) ? 1 : 0; + handleDeoxys = (sMultiBattlePartnersPartyMask[slot] ^ handleDeoxys) ? TRUE : FALSE; + species2 = GetMonData(mon, MON_DATA_SPECIES2); - party_menu_link_mon_icon_anim(species2, GetMonData(mon, MON_DATA_PERSONALITY), menuBox, 1, bit); + CreatePartyMonIconSpriteParameterized(species2, GetMonData(mon, MON_DATA_PERSONALITY), menuBox, 1, handleDeoxys); UpdatePartyMonHPBar(menuBox->monSpriteId, mon); } -static void party_menu_link_mon_icon_anim(u16 species, u32 pid, struct PartyMenuBox *menuBox, u8 priority, bool32 bit) +static void CreatePartyMonIconSpriteParameterized(u16 species, u32 pid, struct PartyMenuBox *menuBox, u8 priority, bool32 handleDeoxys) { if (species != SPECIES_NONE) { - menuBox->monSpriteId = CreateMonIcon(species, UpdateTradeMonIconFrame, menuBox->spriteCoords[0], menuBox->spriteCoords[1], 4, pid, bit); + menuBox->monSpriteId = CreateMonIcon(species, MonIconSpriteCallback, menuBox->spriteCoords[0], menuBox->spriteCoords[1], 4, pid, handleDeoxys); gSprites[menuBox->monSpriteId].oam.priority = priority; } } @@ -5209,35 +5221,35 @@ static void AnimateSelectedPartyIcon(u8 spriteId, u8 animNum) gSprites[spriteId].pos2.x = -4; gSprites[spriteId].pos2.y = 0; } - gSprites[spriteId].callback = UpdatePartyMonIconFrame; + gSprites[spriteId].callback = SpriteCB_UpdatePartyMonIcon; } else { gSprites[spriteId].pos2.x = 0; gSprites[spriteId].pos2.y = 0; - gSprites[spriteId].callback = UpdatePartyMonIconFrameAndBounce; + gSprites[spriteId].callback = SpriteCB_BouncePartyMonIcon; } } -static void UpdatePartyMonIconFrameAndBounce(struct Sprite *sprite) +static void SpriteCB_BouncePartyMonIcon(struct Sprite *sprite) { - u8 unk = UpdateMonIconFrame(sprite); + u8 animCmd = UpdateMonIconFrame(sprite); - if (unk != 0) + if (animCmd != 0) { - if (unk & 1) + if (animCmd & 1) // % 2 also matches sprite->pos2.y = -3; else sprite->pos2.y = 1; } } -static void UpdatePartyMonIconFrame(struct Sprite *sprite) +static void SpriteCB_UpdatePartyMonIcon(struct Sprite *sprite) { UpdateMonIconFrame(sprite); } -static void party_menu_held_item_object(struct Pokemon *mon, struct PartyMenuBox *menuBox) +static void CreatePartyMonHeldItemSprite(struct Pokemon *mon, struct PartyMenuBox *menuBox) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { @@ -5246,7 +5258,7 @@ static void party_menu_held_item_object(struct Pokemon *mon, struct PartyMenuBox } } -static void party_menu_link_mon_held_item_object(u16 species, u16 item, struct PartyMenuBox *menuBox) +static void CreatePartyMonHeldItemSpriteParameterized(u16 species, u16 item, struct PartyMenuBox *menuBox) { if (species != SPECIES_NONE) { @@ -5338,13 +5350,13 @@ static void SpriteCB_HeldItem(struct Sprite *sprite) } } -static void party_menu_pokeball_object(struct Pokemon *mon, struct PartyMenuBox *menuBox) +static void CreatePartyMonPokeballSprite(struct Pokemon *mon, struct PartyMenuBox *menuBox) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) menuBox->pokeballSpriteId = CreateSprite(&sSpriteTemplate_MenuPokeball, menuBox->spriteCoords[6], menuBox->spriteCoords[7], 8); } -static void party_menu_link_mon_pokeball_object(u16 species, struct PartyMenuBox *menuBox) +static void CreatePartyMonPokeballSpriteParameterized(u16 species, struct PartyMenuBox *menuBox) { if (species != SPECIES_NONE) { @@ -5353,7 +5365,8 @@ static void party_menu_link_mon_pokeball_object(u16 species, struct PartyMenuBox } } -static u8 CreateCancelPokeballSprite(u8 x, u8 y) +// For Cancel when Confirm isnt present +static u8 CreatePokeballButtonSprite(u8 x, u8 y) { u8 spriteId = CreateSprite(&sSpriteTemplate_MenuPokeball, x, y, 8); @@ -5361,10 +5374,10 @@ static u8 CreateCancelPokeballSprite(u8 x, u8 y) return spriteId; } -// For Confirm and Cancel in Choose 3 party menus -static u8 CreateMenuPokeballSprite(u8 x, u8 y) +// For Confirm and Cancel when both are present +static u8 CreateSmallPokeballButtonSprite(u8 x, u8 y) { - return CreateSprite(&gSpriteTemplate_8615F78, x, y, 8); + return CreateSprite(&sSpriteTemplate_MenuPokeballSmall, x, y, 8); } static void PartyMenuStartSpriteAnim(u8 spriteId, u8 animNum) @@ -5372,9 +5385,11 @@ static void PartyMenuStartSpriteAnim(u8 spriteId, u8 animNum) StartSpriteAnim(&gSprites[spriteId], animNum); } -static void sub_81B5FBC(u8 spriteId, u8 spriteId2, u8 a) +// Unused. Might explain the large blank section in gPartyMenuPokeballSmall_Gfx +// At the very least this is how the unused anim cmds for sSpriteAnimTable_MenuPokeballSmall were meant to be accessed +static void SpriteCB_BounceConfirmCancelButton(u8 spriteId, u8 spriteId2, u8 animNum) { - if (a == 0) + if (animNum == 0) { StartSpriteAnim(&gSprites[spriteId], 2); StartSpriteAnim(&gSprites[spriteId2], 4); @@ -5397,7 +5412,7 @@ static void LoadPartyMenuPokeballGfx(void) LoadCompressedSpritePalette(&sSpritePalette_MenuPokeball); } -static void party_menu_status_condition_object(struct Pokemon *mon, struct PartyMenuBox *menuBox) +static void CreatePartyMonStatusSprite(struct Pokemon *mon, struct PartyMenuBox *menuBox) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { @@ -5406,7 +5421,7 @@ static void party_menu_status_condition_object(struct Pokemon *mon, struct Party } } -static void party_menu_link_mon_status_condition_object(u16 species, u8 status, struct PartyMenuBox *menuBox) +static void CreatePartyMonStatusSpriteParameterized(u16 species, u8 status, struct PartyMenuBox *menuBox) { if (species != SPECIES_NONE) { @@ -5473,7 +5488,7 @@ void CB2_ShowPartyMenuForItemUse(void) break; } } - task = sub_81B6280; + task = Task_SetSacredAshCB; msgId = PARTY_MSG_NONE; } else @@ -5497,13 +5512,13 @@ static void CB2_ReturnToBagMenu(void) GoToBattlePyramidBagMenu(4, gPyramidBagCursorData.callback); } -static void sub_81B6280(u8 taskId) +static void Task_SetSacredAshCB(u8 taskId) { if (!gPaletteFade.active) { if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_BATTLE) sPartyMenuInternal->exitCallback = CB2_SetUpExitToBattleScreen; - gItemUseCB(taskId, Task_ClosePartyMenuAfterText); + gItemUseCB(taskId, Task_ClosePartyMenuAfterText); // ItemUseCB_SacredAsh in this case } } @@ -5628,7 +5643,7 @@ void ItemUseCB_Medicine(u8 taskId, TaskFunc task) if (ExecuteTableBasedItemEffect_(gPartyMenu.slotId, item, 0)) { iTriedHonestlyIDid: - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; PlaySE(SE_SELECT); DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); @@ -5640,7 +5655,7 @@ void ItemUseCB_Medicine(u8 taskId, TaskFunc task) { goto iTriedHonestlyIDid; //TODO: resolve this goto } - gUnknown_0203CEE8 = TRUE; + gPartyMenuUseExitCallback = TRUE; if (!IsItemFlute(item)) { PlaySE(SE_KAIFUKU); @@ -5686,7 +5701,7 @@ static void Task_ClosePartyMenuAfterText(u8 taskId) { if (IsPartyMenuTextPrinterActive() != TRUE) { - if (gUnknown_0203CEE8 == FALSE) + if (gPartyMenuUseExitCallback == FALSE) sPartyMenuInternal->exitCallback = NULL; Task_ClosePartyMenu(taskId); } @@ -5705,7 +5720,7 @@ void ItemUseCB_ReduceEV(u8 taskId, TaskFunc task) if (cannotUseEffect || (friendship == newFriendship && ev == newEv)) { - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; PlaySE(SE_SELECT); DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); @@ -5713,7 +5728,7 @@ void ItemUseCB_ReduceEV(u8 taskId, TaskFunc task) } else { - gUnknown_0203CEE8 = TRUE; + gPartyMenuUseExitCallback = TRUE; PlaySE(SE_KAIFUKU); RemoveBagItem(item, 1); GetMonNickname(mon, gStringVar1); @@ -5832,7 +5847,7 @@ void ItemUseCB_PPRecovery(u8 taskId, TaskFunc task) if (!(effect[4] & ITEM4_HEAL_PP_ONE)) { - gPartyMenu.unkE = 0; + gPartyMenu.data1 = 0; TryUsePPItem(taskId); } else @@ -5847,7 +5862,7 @@ void ItemUseCB_PPRecovery(u8 taskId, TaskFunc task) static void SetSelectedMoveForPPItem(u8 taskId) { PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[0]); - gPartyMenu.unkE = Menu_GetCursorPos(); + gPartyMenu.data1 = Menu_GetCursorPos(); TryUsePPItem(taskId); } @@ -5862,14 +5877,14 @@ static void ReturnToUseOnWhichMon(u8 taskId) static void TryUsePPItem(u8 taskId) { u16 move = MOVE_NONE; - s16 *moveSlot = &gPartyMenu.unkE; + s16 *moveSlot = &gPartyMenu.data1; u16 item = gSpecialVar_ItemId; struct PartyMenu *ptr = &gPartyMenu; struct Pokemon *mon; if (ExecuteTableBasedItemEffect_(ptr->slotId, item, *moveSlot)) { - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; PlaySE(SE_SELECT); DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); @@ -5877,7 +5892,7 @@ static void TryUsePPItem(u8 taskId) } else { - gUnknown_0203CEE8 = TRUE; + gPartyMenuUseExitCallback = TRUE; mon = &gPlayerParty[ptr->slotId]; PlaySE(SE_KAIFUKU); RemoveBagItem(item, 1); @@ -5951,7 +5966,7 @@ void ItemUseCB_TMHM(u8 taskId, TaskFunc task) PlaySE(SE_SELECT); mon = &gPlayerParty[gPartyMenu.slotId]; - move = &gPartyMenu.unkE; + move = &gPartyMenu.data1; item = gSpecialVar_ItemId; GetMonNickname(mon, gStringVar1); move[0] = ItemIdToBattleMoveId(item); @@ -5982,7 +5997,7 @@ void ItemUseCB_TMHM(u8 taskId, TaskFunc task) static void Task_LearnedMove(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - s16 *move = &gPartyMenu.unkE; + s16 *move = &gPartyMenu.data1; u16 item = gSpecialVar_ItemId; if (move[1] == 0) @@ -6060,7 +6075,7 @@ static void Task_ShowSummaryScreenToForgetMove(u8 taskId) static void CB2_ShowSummaryScreenToForgetMove(void) { - ShowSelectMovePokemonSummaryScreen(gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuWhileLearningMove, gPartyMenu.unkE); + ShowSelectMovePokemonSummaryScreen(gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuWhileLearningMove, gPartyMenu.data1); } static void CB2_ReturnToPartyMenuWhileLearningMove(void) @@ -6099,7 +6114,7 @@ static void Task_PartyMenuReplaceMove(u8 taskId) { mon = &gPlayerParty[gPartyMenu.slotId]; RemoveMonPPBonus(mon, GetMoveSlotToReplace()); - move = gPartyMenu.unkE; + move = gPartyMenu.data1; SetMonMoveSlot(mon, move, GetMoveSlotToReplace()); Task_LearnedMove(taskId); } @@ -6107,7 +6122,7 @@ static void Task_PartyMenuReplaceMove(u8 taskId) static void StopLearningMovePrompt(u8 taskId) { - StringCopy(gStringVar2, gMoveNames[gPartyMenu.unkE]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); StringExpandPlaceholders(gStringVar4, gText_StopLearningMove2); DisplayPartyMenuMessage(gStringVar4, TRUE); schedule_bg_copy_tilemap_to_vram(2); @@ -6131,7 +6146,7 @@ static void Task_HandleStopLearningMoveYesNoInput(u8 taskId) { case 0: GetMonNickname(mon, gStringVar1); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.unkE]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); StringExpandPlaceholders(gStringVar4, gText_MoveNotLearned); DisplayPartyMenuMessage(gStringVar4, TRUE); if (gPartyMenu.learnMoveState == 1) @@ -6150,7 +6165,7 @@ static void Task_HandleStopLearningMoveYesNoInput(u8 taskId) // fallthrough case 1: GetMonNickname(mon, gStringVar1); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.unkE]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); DisplayLearnMoveMessage(gText_PkmnNeedsToReplaceMove); gTasks[taskId].func = Task_ReplaceMoveYesNo; break; @@ -6175,7 +6190,7 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc task) { BufferMonStatsToTaskData(mon, arrayPtr); cannotUseEffect = ExecuteTableBasedItemEffect_(gPartyMenu.slotId, *itemPtr, 0); - BufferMonStatsToTaskData(mon, &ptr->data[6]); + BufferMonStatsToTaskData(mon, &ptr->data[NUM_STATS]); } else { @@ -6184,14 +6199,14 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc task) PlaySE(SE_SELECT); if (cannotUseEffect) { - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); gTasks[taskId].func = task; } else { - gUnknown_0203CEE8 = TRUE; + gPartyMenuUseExitCallback = TRUE; PlayFanfareByFanfareNum(0); UpdateMonDisplayInfoAfterRareCandy(gPartyMenu.slotId, mon); RemoveBagItem(gSpecialVar_ItemId, 1); @@ -6328,7 +6343,7 @@ static void DisplayMonNeedsToReplaceMove(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_PkmnNeedsToReplaceMove); DisplayPartyMenuMessage(gStringVar4, TRUE); schedule_bg_copy_tilemap_to_vram(2); - gPartyMenu.unkE = gMoveToLearn; + gPartyMenu.data1 = gMoveToLearn; gTasks[taskId].func = Task_ReplaceMoveYesNo; } @@ -6339,7 +6354,7 @@ static void DisplayMonLearnedMove(u8 taskId, u16 move) StringExpandPlaceholders(gStringVar4, gText_PkmnLearnedMove3); DisplayPartyMenuMessage(gStringVar4, TRUE); schedule_bg_copy_tilemap_to_vram(2); - gPartyMenu.unkE = move; + gPartyMenu.data1 = move; gTasks[taskId].func = Task_DoLearnedMoveFanfareAfterText; } @@ -6353,29 +6368,33 @@ static void BufferMonStatsToTaskData(struct Pokemon *mon, s16 *data) data[3] = GetMonData(mon, MON_DATA_SPEED); } +#define tUsedOnSlot data[0] +#define tHadEffect data[1] +#define tLastSlotUsed data[2] + void ItemUseCB_SacredAsh(u8 taskId, TaskFunc task) { - sPartyMenuInternal->data[0] = 0; - sPartyMenuInternal->data[1] = 0; - sPartyMenuInternal->data[2] = gPartyMenu.slotId; - sub_81B7A28(taskId); + sPartyMenuInternal->tUsedOnSlot = FALSE; + sPartyMenuInternal->tHadEffect = FALSE; + sPartyMenuInternal->tLastSlotUsed = gPartyMenu.slotId; + UseSacredAsh(taskId); } -static void sub_81B7A28(u8 taskId) +static void UseSacredAsh(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; u16 hp; if (GetMonData(mon, MON_DATA_SPECIES) == SPECIES_NONE) { - gTasks[taskId].func = task_sacred_ash_party_loop; + gTasks[taskId].func = Task_SacredAshLoop; return; } hp = GetMonData(mon, MON_DATA_HP); if (ExecuteTableBasedItemEffect_(gPartyMenu.slotId, gSpecialVar_ItemId, 0)) { - gTasks[taskId].func = task_sacred_ash_party_loop; + gTasks[taskId].func = Task_SacredAshLoop; return; } @@ -6383,34 +6402,34 @@ static void sub_81B7A28(u8 taskId) SetPartyMonAilmentGfx(mon, &sPartyMenuBoxes[gPartyMenu.slotId]); if (gSprites[sPartyMenuBoxes[gPartyMenu.slotId].statusSpriteId].invisible) DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[gPartyMenu.slotId], 1); - AnimatePartySlot(sPartyMenuInternal->data[2], 0); + AnimatePartySlot(sPartyMenuInternal->tLastSlotUsed, 0); AnimatePartySlot(gPartyMenu.slotId, 1); PartyMenuModifyHP(taskId, gPartyMenu.slotId, 1, GetMonData(mon, MON_DATA_HP) - hp, Task_SacredAshDisplayHPRestored); ResetHPTaskData(taskId, 0, hp); - sPartyMenuInternal->data[0] = 1; - sPartyMenuInternal->data[1] = 1; + sPartyMenuInternal->tUsedOnSlot = TRUE; + sPartyMenuInternal->tHadEffect = TRUE; } -static void task_sacred_ash_party_loop(u8 taskId) +static void Task_SacredAshLoop(u8 taskId) { if (IsPartyMenuTextPrinterActive() != TRUE) { - if (sPartyMenuInternal->data[0] == 1) + if (sPartyMenuInternal->tUsedOnSlot == TRUE) { - sPartyMenuInternal->data[0] = 0; - sPartyMenuInternal->data[2] = gPartyMenu.slotId; + sPartyMenuInternal->tUsedOnSlot = FALSE; + sPartyMenuInternal->tLastSlotUsed = gPartyMenu.slotId; } if (++(gPartyMenu.slotId) == PARTY_SIZE) { - if (sPartyMenuInternal->data[1] == 0) + if (sPartyMenuInternal->tHadEffect == FALSE) { - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); } else { - gUnknown_0203CEE8 = TRUE; + gPartyMenuUseExitCallback = TRUE; RemoveBagItem(gSpecialVar_ItemId, 1); } gTasks[taskId].func = Task_ClosePartyMenuAfterText; @@ -6418,7 +6437,7 @@ static void task_sacred_ash_party_loop(u8 taskId) } else { - sub_81B7A28(taskId); + UseSacredAsh(taskId); } } } @@ -6429,16 +6448,20 @@ static void Task_SacredAshDisplayHPRestored(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_PkmnHPRestoredByVar2); DisplayPartyMenuMessage(gStringVar4, FALSE); schedule_bg_copy_tilemap_to_vram(2); - gTasks[taskId].func = task_sacred_ash_party_loop; + gTasks[taskId].func = Task_SacredAshLoop; } +#undef tUsedOnSlot +#undef tHadEffect +#undef tLastSlotUsed + void ItemUseCB_EvolutionStone(u8 taskId, TaskFunc task) { PlaySE(SE_SELECT); gCB2_AfterEvolution = gPartyMenu.exitCallback; if (ExecuteTableBasedItemEffect_(gPartyMenu.slotId, gSpecialVar_ItemId, 0)) { - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); schedule_bg_copy_tilemap_to_vram(2); gTasks[taskId].func = task; @@ -6526,10 +6549,10 @@ static void TryTutorSelectedMon(u8 taskId) if (!gPaletteFade.active) { mon = &gPlayerParty[gPartyMenu.slotId]; - move = &gPartyMenu.unkE; + move = &gPartyMenu.data1; GetMonNickname(mon, gStringVar1); - gPartyMenu.unkE = GetTutorMove(gSpecialVar_0x8005); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.unkE]); + gPartyMenu.data1 = GetTutorMove(gSpecialVar_0x8005); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); move[1] = 2; switch (CanMonLearnTMTutor(mon, 0, gSpecialVar_0x8005)) { @@ -6540,7 +6563,7 @@ static void TryTutorSelectedMon(u8 taskId) DisplayLearnMoveMessageAndClose(taskId, gText_PkmnAlreadyKnows); return; default: - if (GiveMoveToMon(mon, gPartyMenu.unkE) != MON_HAS_MAX_MOVES) + if (GiveMoveToMon(mon, gPartyMenu.data1) != MON_HAS_MAX_MOVES) { Task_LearnedMove(taskId); return; @@ -6566,26 +6589,25 @@ void CB2_ChooseMonToGiveItem(void) gPartyMenu.bagItem = gSpecialVar_ItemId; } -//TODO next -static void TryGiveItemToSelectedMon(u8 taskId) +static void TryGiveItemOrMailToSelectedMon(u8 taskId) { sPartyMenuItemId = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_HELD_ITEM); if (sPartyMenuItemId == ITEM_NONE) { - GiveItemToSelectedMon(taskId); + GiveItemOrMailToSelectedMon(taskId); } else if (ItemIsMail(sPartyMenuItemId)) { - sub_81B83B8(taskId); + DisplayItemMustBeRemovedFirstMessage(taskId); } else { DisplayAlreadyHoldingItemSwitchMessage(&gPlayerParty[gPartyMenu.slotId], sPartyMenuItemId, TRUE); - gTasks[taskId].func = sub_81B82A0; + gTasks[taskId].func = Task_SwitchItemsFromBagYesNo; } } -static void GiveItemToSelectedMon(u8 taskId) +static void GiveItemOrMailToSelectedMon(u8 taskId) { if (ItemIsMail(gPartyMenu.bagItem)) { @@ -6595,11 +6617,11 @@ static void GiveItemToSelectedMon(u8 taskId) } else { - sub_81B8088(taskId); + GiveItemToSelectedMon(taskId); } } -static void sub_81B8088(u8 taskId) +static void GiveItemToSelectedMon(u8 taskId) { u16 item; @@ -6631,10 +6653,10 @@ static void CB2_WriteMailToGiveMonFromBag(void) GiveItemToMon(&gPlayerParty[gPartyMenu.slotId], gPartyMenu.bagItem); mail = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_MAIL); DoEasyChatScreen( - EASY_CHAT_TYPE_MAIL, - gSaveBlock1Ptr->mail[mail].words, - CB2_ReturnToPartyOrBagMenuFromWritingMail, - EASY_CHAT_PERSON_DISPLAY_NONE); + EASY_CHAT_TYPE_MAIL, + gSaveBlock1Ptr->mail[mail].words, + CB2_ReturnToPartyOrBagMenuFromWritingMail, + EASY_CHAT_PERSON_DISPLAY_NONE); } static void CB2_ReturnToPartyOrBagMenuFromWritingMail(void) @@ -6642,21 +6664,23 @@ static void CB2_ReturnToPartyOrBagMenuFromWritingMail(void) struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; u16 item = GetMonData(mon, MON_DATA_HELD_ITEM); + // Canceled writing mail if (gSpecialVar_Result == FALSE) { TakeMailFromMon(mon); SetMonData(mon, MON_DATA_HELD_ITEM, &sPartyMenuItemId); RemoveBagItem(sPartyMenuItemId, 1); - sub_81B841C(item); + ReturnGiveItemToBagOrPC(item); SetMainCallback2(gPartyMenu.exitCallback); } + // Wrote mail else { - InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_NONE, sub_81B8230, gPartyMenu.exitCallback); + InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, TRUE, PARTY_MSG_NONE, Task_DisplayGaveMailFromBagMessage, gPartyMenu.exitCallback); } } -static void sub_81B8230(u8 taskId) +static void Task_DisplayGaveMailFromBagMessage(u8 taskId) { if (!gPaletteFade.active) { @@ -6668,27 +6692,27 @@ static void sub_81B8230(u8 taskId) } } -static void sub_81B82A0(u8 taskId) +static void Task_SwitchItemsFromBagYesNo(u8 taskId) { if (IsPartyMenuTextPrinterActive() != TRUE) { PartyMenuDisplayYesNoMenu(); - gTasks[taskId].func = sub_81B82D4; + gTasks[taskId].func = Task_HandleSwitchItemsFromBagYesNoInput; } } -static void sub_81B82D4(u8 taskId) +static void Task_HandleSwitchItemsFromBagYesNoInput(u8 taskId) { u16 item; switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes, switch items item = gPartyMenu.bagItem; RemoveItemToGiveFromBag(item); if (AddBagItem(sPartyMenuItemId, 1) == FALSE) { - sub_81B841C(item); + ReturnGiveItemToBagOrPC(item); BufferBagFullCantTakeItemMessage(sPartyMenuItemId); DisplayPartyMenuMessage(gStringVar4, FALSE); gTasks[taskId].func = Task_UpdateHeldItemSpriteAndClosePartyMenu; @@ -6708,13 +6732,13 @@ static void sub_81B82D4(u8 taskId) case MENU_B_PRESSED: PlaySE(SE_SELECT); // fallthrough - case 1: + case 1: // No, dont switch items gTasks[taskId].func = Task_UpdateHeldItemSpriteAndClosePartyMenu; break; } } -static void sub_81B83B8(u8 taskId) +static void DisplayItemMustBeRemovedFirstMessage(u8 taskId) { DisplayPartyMenuMessage(gText_RemoveMailBeforeItem, TRUE); schedule_bg_copy_tilemap_to_vram(2); @@ -6729,7 +6753,9 @@ static void RemoveItemToGiveFromBag(u16 item) RemoveBagItem(item, 1); } -static bool8 sub_81B841C(u16 item) +// Returns FALSE if there was no space to return the item +// but there always should be, and the return is ignored in all uses +static bool8 ReturnGiveItemToBagOrPC(u16 item) { if (gPartyMenu.action == PARTY_ACTION_GIVE_ITEM) return AddBagItem(item, 1); @@ -6747,7 +6773,7 @@ static void TryGiveMailToSelectedMon(u8 taskId) struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; struct MailStruct *mail; - gUnknown_0203CEE8 = FALSE; + gPartyMenuUseExitCallback = FALSE; mail = &gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + 6 + playerPCItemPageInfo.cursorPos]; if (GetMonData(mon, MON_DATA_HELD_ITEM) != ITEM_NONE) { @@ -7044,18 +7070,19 @@ static bool8 TrySwitchInPokemon(void) if (gPartyMenu.action == PARTY_ACTION_CANT_SWITCH) { u8 currBattler = gBattlerInMenuId; - GetMonNickname(&gPlayerParty[GetBattlerPartyId(gBattlerPartyIndexes[currBattler])], gStringVar1); + GetMonNickname(&gPlayerParty[GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[currBattler])], gStringVar1); StringExpandPlaceholders(gStringVar4, gText_PkmnCantSwitchOut); return FALSE; } - gUnknown_0203CEE9 = GetPartyIdFromBattleSlot(slot); - gUnknown_0203CEE8 = TRUE; - newSlot = GetBattlerPartyId(gBattlerPartyIndexes[gBattlerInMenuId]); + gSelectedMonPartyId = GetPartyIdFromBattleSlot(slot); + gPartyMenuUseExitCallback = TRUE; + newSlot = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[gBattlerInMenuId]); SwitchPartyMonSlots(newSlot, slot); SwapPartyPokemon(&gPlayerParty[newSlot], &gPlayerParty[slot]); return TRUE; } +//TODO void sub_81B8C68(void) { sub_81B8C88(gBattlePartyCurrentOrder, sub_806D7EC()); @@ -7113,6 +7140,7 @@ static void sub_81B8C88(u8 *partyBattleOrder, bool8 multiplayerFlag) partyBattleOrder[i] = (partyIndexes[0 + (i * 2)] << 4) | partyIndexes[1 + (i * 2)]; } +//TODO void sub_81B8D64(u8 battlerId, u8 multiplayerFlag) { sub_81B8D88(gBattleStruct->field_60[battlerId], multiplayerFlag, battlerId); @@ -7184,10 +7212,11 @@ static void sub_81B8D88(u8 *ptr, bool8 multiplayerFlag, u8 battlerId) ptr[i] = (partyIndexes[0 + (i * 2)] << 4) | partyIndexes[1 + (i * 2)]; } -void sub_81B8E80(u8 battlerId, u8 unk, u8 arrayIndex) +//TODO clean up +void SwitchPartyOrderLinkMulti(u8 battlerId, u8 slot, u8 arrayIndex) { u8 possiblePartyIndexes[PARTY_SIZE]; - u8 unk2 = 0; + u8 slot2 = 0; int i, j; u8 *battleStructRelated; u8 possiblePartyIndexBuffer; @@ -7204,16 +7233,16 @@ void sub_81B8E80(u8 battlerId, u8 unk, u8 arrayIndex) possiblePartyIndexBuffer = possiblePartyIndexes[arrayIndex]; for (i = 0; i < PARTY_SIZE; i++) { - if (possiblePartyIndexes[i] == unk) + if (possiblePartyIndexes[i] == slot) { - unk2 = possiblePartyIndexes[i]; + slot2 = possiblePartyIndexes[i]; possiblePartyIndexes[i] = possiblePartyIndexBuffer; break; } } if (i != PARTY_SIZE) { - possiblePartyIndexes[arrayIndex] = unk2; + possiblePartyIndexes[arrayIndex] = slot2; battleStructRelated[0] = (possiblePartyIndexes[0] << 4) | possiblePartyIndexes[1]; battleStructRelated[1] = (possiblePartyIndexes[2] << 4) | possiblePartyIndexes[3]; battleStructRelated[2] = (possiblePartyIndexes[4] << 4) | possiblePartyIndexes[5]; @@ -7252,17 +7281,16 @@ void SwitchPartyMonSlots(u8 slot, u8 slot2) SetPartyIdAtBattleSlot(slot2, partyId); } -// TODO: rename? get party id from battle party id? -u8 GetBattlerPartyId(u8 slot) +u8 GetPartyIdFromBattlePartyId(u8 battlePartyId) { u8 i, j; for (j = i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); j++, i++) { - if ((gBattlePartyCurrentOrder[i] >> 4) != slot) + if ((gBattlePartyCurrentOrder[i] >> 4) != battlePartyId) { j++; - if ((gBattlePartyCurrentOrder[i] & 0xF) == slot) + if ((gBattlePartyCurrentOrder[i] & 0xF) == battlePartyId) return j; } else @@ -7280,7 +7308,7 @@ static void UpdatePartyToBattleOrder(void) memcpy(partyBuffer, gPlayerParty, sizeof(gPlayerParty)); for (i = 0; i < PARTY_SIZE; i++) - memcpy(&gPlayerParty[GetBattlerPartyId(i)], &partyBuffer[i], sizeof(struct Pokemon)); + memcpy(&gPlayerParty[GetPartyIdFromBattlePartyId(i)], &partyBuffer[i], sizeof(struct Pokemon)); Free(partyBuffer); } @@ -7322,7 +7350,7 @@ static void CB2_SetUpExitToBattleScreen(void) void ShowPartyMenuToShowcaseMultiBattleParty(void) { - InitPartyMenu(PARTY_MENU_TYPE_IN_MULTI_BATTLE, PARTY_LAYOUT_MULTI_SHOWCASE, PARTY_ACTION_CHOOSE_MON, FALSE, PARTY_MSG_NONE, Task_InitMultiPartnerPartySlideIn, gMain.savedCallback); + InitPartyMenu(PARTY_MENU_TYPE_MULTI_SHOWCASE, PARTY_LAYOUT_MULTI_SHOWCASE, PARTY_ACTION_CHOOSE_MON, FALSE, PARTY_MSG_NONE, Task_InitMultiPartnerPartySlideIn, gMain.savedCallback); } #define tXPos data[0] diff --git a/src/pokemon.c b/src/pokemon.c index 18d4fdb12a..ea8dcf0ccd 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4861,7 +4861,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if (battlerId != 4) { gAbsentBattlerFlags &= ~gBitTable[battlerId]; - CopyPlayerPartyMonToBattleData(battlerId, GetBattlerPartyId(gBattlerPartyIndexes[battlerId])); + CopyPlayerPartyMonToBattleData(battlerId, GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battlerId])); if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleResults.numRevivesUsed < 255) gBattleResults.numRevivesUsed++; } @@ -6440,11 +6440,11 @@ void SetMonPreventsSwitchingString(void) gBattleTextBuff1[4] = B_BUFF_EOS; if (GetBattlerSide(gBattleStruct->battlerPreventingSwitchout) == B_SIDE_PLAYER) - gBattleTextBuff1[3] = GetBattlerPartyId(gBattlerPartyIndexes[gBattleStruct->battlerPreventingSwitchout]); + gBattleTextBuff1[3] = GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[gBattleStruct->battlerPreventingSwitchout]); else gBattleTextBuff1[3] = gBattlerPartyIndexes[gBattleStruct->battlerPreventingSwitchout]; - PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff2, gBattlerInMenuId, GetBattlerPartyId(gBattlerPartyIndexes[gBattlerInMenuId])) + PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff2, gBattlerInMenuId, GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[gBattlerInMenuId])) BattleStringExpandPlaceholders(gText_PkmnsXPreventsSwitching, gStringVar4); } diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 7d7dadccb0..0a758f8eec 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -1029,13 +1029,13 @@ const u16 sSpriteImageSizes[3][4] = }, }; -u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, bool32 extra) +u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, bool32 handleDeoxys) { u8 spriteId; struct MonIconSpriteTemplate iconTemplate = { .oam = &sMonIconOamData, - .image = GetMonIconPtr(species, personality, extra), + .image = GetMonIconPtr(species, personality, handleDeoxys), .anims = sMonIconAnims, .affineAnims = sMonIconAffineAnims, .callback = callback, @@ -1125,9 +1125,9 @@ u16 sub_80D2E84(u16 species) } } -const u8 *GetMonIconPtr(u16 species, u32 personality, bool32 extra) +const u8 *GetMonIconPtr(u16 species, u32 personality, bool32 handleDeoxys) { - return GetMonIconTiles(GetIconSpecies(species, personality), extra); + return GetMonIconTiles(GetIconSpecies(species, personality), handleDeoxys); } void sub_80D2EF8(struct Sprite *sprite) @@ -1184,17 +1184,17 @@ void FreeMonIconPalette(u16 species) FreeSpritePaletteByTag(gMonIconPaletteTable[palIndex].tag); } -void UpdateTradeMonIconFrame(struct Sprite *sprite) +void MonIconSpriteCallback(struct Sprite *sprite) { UpdateMonIconFrame(sprite); } -const u8* GetMonIconTiles(u16 species, bool32 extra) +const u8* GetMonIconTiles(u16 species, bool32 handleDeoxys) { const u8* iconSprite = gMonIconTable[species]; - if (species == SPECIES_DEOXYS && extra == TRUE) + if (species == SPECIES_DEOXYS && handleDeoxys == TRUE) { - iconSprite = (const u8*)(0x400 + (u32)iconSprite); //WTF? + iconSprite = (const u8*)(0x400 + (u32)iconSprite); // use the specific Deoxys form icon (Speed in this case) } return iconSprite; } diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 5ab13b09e9..41c48d0087 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -2575,9 +2575,9 @@ static void DrawPokerusCuredSymbol(struct Pokemon *mon) // This checks if the mo static void SetDexNumberColor(bool8 isMonShiny) { if (!isMonShiny) - sub_8199C30(3, 1, 4, 8, 8, 0); + SetBgTilemapPalette(3, 1, 4, 8, 8, 0); else - sub_8199C30(3, 1, 4, 8, 8, 5); + SetBgTilemapPalette(3, 1, 4, 8, 8, 5); schedule_bg_copy_tilemap_to_vram(3); } diff --git a/src/trade.c b/src/trade.c index 6dbc60f1d6..004cffe713 100644 --- a/src/trade.c +++ b/src/trade.c @@ -481,7 +481,7 @@ static void CB2_CreateTradeMenu(void) { struct Pokemon *mon = &gPlayerParty[i]; sTradeMenuData->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2), - UpdateTradeMonIconFrame, + MonIconSpriteCallback, (sTradeMonSpriteCoords[i][0] * 8) + 14, (sTradeMonSpriteCoords[i][1] * 8) - 12, 1, @@ -493,7 +493,7 @@ static void CB2_CreateTradeMenu(void) { struct Pokemon *mon = &gEnemyParty[i]; sTradeMenuData->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL), - UpdateTradeMonIconFrame, + MonIconSpriteCallback, (sTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14, (sTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12, 1, @@ -668,7 +668,7 @@ static void CB2_ReturnToTradeMenu(void) { struct Pokemon *mon = &gPlayerParty[i]; sTradeMenuData->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL), - UpdateTradeMonIconFrame, + MonIconSpriteCallback, (sTradeMonSpriteCoords[i][0] * 8) + 14, (sTradeMonSpriteCoords[i][1] * 8) - 12, 1, @@ -680,7 +680,7 @@ static void CB2_ReturnToTradeMenu(void) { struct Pokemon *mon = &gEnemyParty[i]; sTradeMenuData->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL), - UpdateTradeMonIconFrame, + MonIconSpriteCallback, (sTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14, (sTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12, 1, @@ -1809,7 +1809,7 @@ static void DrawTradeMenuParty(u8 whichParty) gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[0] = 20; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[2] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[4] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12; - StoreSpriteCallbackInData6(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]], UpdateTradeMonIconFrame); + StoreSpriteCallbackInData6(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]], MonIconSpriteCallback); sTradeMenuData->drawPartyState[whichParty]++; TradeMenuBouncePartySprites(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]]); CopyToBgTilemapBufferRect_ChangePalette(1, sTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0); @@ -1820,7 +1820,7 @@ static void DrawTradeMenuParty(u8 whichParty) PrintNicknamesForTradeMenu(); break; case 2: - if (gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].callback == UpdateTradeMonIconFrame) + if (gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].callback == MonIconSpriteCallback) sTradeMenuData->drawPartyState[whichParty] = 3; break; case 3: