diff --git a/include/constants/party_menu.h b/include/constants/party_menu.h index 0c958ccc5..1321a4ced 100644 --- a/include/constants/party_menu.h +++ b/include/constants/party_menu.h @@ -55,8 +55,8 @@ #define PARTY_MENU_TYPE_FIELD 0 #define PARTY_MENU_TYPE_IN_BATTLE 1 #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_CHOOSE_SINGLE_MON 3 +#define PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS 4 // multi battles, eReader battles, and some battle facilities #define PARTY_MENU_TYPE_MULTI_SHOWCASE 5 #define PARTY_MENU_TYPE_DAYCARE 6 #define PARTY_MENU_TYPE_MOVE_RELEARNER 7 @@ -128,4 +128,11 @@ #define SELECTWINDOW_MAIL 2 #define SELECTWINDOW_MOVES 3 +enum +{ + CHOOSE_MONS_FOR_CABLE_CLUB_BATTLE, + CHOOSE_MONS_FOR_BATTLE_TOWER, + CHOOSE_MONS_FOR_UNION_ROOM_BATTLE, +}; + #endif // GUARD_CONSTANTS_PARTY_MENU_H diff --git a/include/party_menu.h b/include/party_menu.h index 5d329d246..97379910f 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -11,13 +11,12 @@ struct PartyMenu TaskFunc task; u8 menuType:4; u8 layout:2; - u8 unk_8_6:2; + u8 chooseMonsBattleType:2; s8 slotId; s8 slotId2; u8 action; u16 bagItem; - s16 data1; // used variously as a moveId, counter, moveSlotId, or cursorPos - s16 learnMoveState; + s16 data[2]; }; extern struct PartyMenu gPartyMenu; @@ -53,7 +52,7 @@ void SetUsedFlyQuestLogEvent(const u8 *healLocCtrlData); void CB2_ShowPartyMenuForItemUse(void); void ItemUseCB_Medicine(u8 taskId, TaskFunc func); void ItemUseCB_MedicineStep(u8 taskId, TaskFunc func); -void ItemUseCB_PPRecovery(u8 taskId, TaskFunc func); +void ItemUseCB_TryRestorePP(u8 taskId, TaskFunc func); void ItemUseCB_PPUp(u8 taskId, TaskFunc func); u16 ItemIdToBattleMoveId(u16 item); bool8 IsMoveHm(u16 move); @@ -66,7 +65,7 @@ u8 GetItemEffectType(u16 item); void CB2_PartyMenuFromStartMenu(void); void CB2_ChooseMonToGiveItem(void); void ChooseMonToGiveMailFromMailbox(void); -void InitChooseHalfPartyForBattle(u8 a1); +void InitChooseMonsForBattle(u8 chooseMonsBattleType); void ClearSelectedPartyOrder(void); void ChooseMonForTradingBoard(u8 menuType, MainCallback callback); void ChooseMonForMoveTutor(void); diff --git a/src/data/party_menu.h b/src/data/party_menu.h index 6c17d080e..de330200a 100644 --- a/src/data/party_menu.h +++ b/src/data/party_menu.h @@ -48,7 +48,7 @@ static const struct PartyMenuBoxInfoRects sPartyBoxInfoRects[] = 38, 36, 24, 8, // HP 53, 36, 24, 8, // Max HP 24, 35, 48, 3 // HP bar - }, + }, 12, 34, 64, 16 // Description text (e.g. NO USE) }, [PARTY_BOX_RIGHT_COLUMN] = @@ -71,6 +71,7 @@ static const u8 sPartyMenuSpriteCoords[PARTY_LAYOUT_COUNT][PARTY_SIZE][4 * 2] = { [PARTY_LAYOUT_SINGLE] = { + // pokemon coords, held item coords, status coords, pokeball coords { 16, 40, 20, 50, 56, 52, 16, 34}, {104, 18, 108, 28, 144, 27, 102, 25}, {104, 42, 108, 52, 144, 51, 102, 49}, @@ -537,7 +538,7 @@ static const struct WindowTemplate sWindowTemplate_FirstBattleOakVoiceover = .baseBlock = 0x1DF, }; -static const struct WindowTemplate gUnknown_845A178 = +static const struct WindowTemplate sFieldMoveDescriptionWindowTemplate = { .bg = 2, .tilemapLeft = 0, @@ -572,32 +573,23 @@ static const u8 sMainSlotTileNums_Egg[] = static const u8 sOtherSlotsTileNums[] = { - 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 45, 49, 33, - 33, 33, 33, 33, 33, 33, 33, 52, 53, 51, - 51, 51, 51, 51, 51, 54, 55, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 57, + 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, + 49, 33, 33, 33, 33, 33, 33, 33, 33, 52, 53, 51, 51, 51, 51, 51, 51, 54, + 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 57, }; static const u8 sOtherSlotsTileNums_Egg[] = { - 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 45, 49, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 50, 55, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 57, + 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, + 49, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 50, + 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 57, }; static const u8 sEmptySlotTileNums[] = { - 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 23, 30, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 31, 37, 38, 38, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 38, 38, 38, 39, + 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, + 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, + 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, }; static const u8 sGenderPalOffsets[] = {11, 12}; @@ -687,20 +679,20 @@ static const u8 *const sDescriptionStringTable[] = [PARTYBOX_DESC_LEARNED] = gText_Learned, }; -static const u8 *const sHMDescriptionTable[] = +static const u8 *const sFieldMoveDescriptionTable[] = { - gText_LightUpDarkness, - gText_CutATreeOrGrass, - gText_FlyToAKnownTown, - gText_MoveHeavyBoulders, - gText_TravelOnWater, - gText_ShatterACrackedRock, - gText_ClimbAWaterfall, - gText_ReturnToAHealingSpot, - gText_EscapeFromHere, - gText_ShareHp, - gText_ShareHp, - gText_LureWildPokemon, + [FIELD_MOVE_FLASH] = gText_LightUpDarkness, + [FIELD_MOVE_CUT] = gText_CutATreeOrGrass, + [FIELD_MOVE_FLY] = gText_FlyToAKnownTown, + [FIELD_MOVE_STRENGTH] = gText_MoveHeavyBoulders, + [FIELD_MOVE_SURF] = gText_TravelOnWater, + [FIELD_MOVE_ROCK_SMASH] = gText_ShatterACrackedRock, + [FIELD_MOVE_WATERFALL] = gText_ClimbAWaterfall, + [FIELD_MOVE_TELEPORT] = gText_ReturnToAHealingSpot, + [FIELD_MOVE_DIG] = gText_EscapeFromHere, + [FIELD_MOVE_MILK_DRINK] = gText_ShareHp, + [FIELD_MOVE_SOFT_BOILED] = gText_ShareHp, + [FIELD_MOVE_SWEET_SCENT] = gText_LureWildPokemon, }; static const u32 sHeldItemGfx[] = INCBIN_U32("graphics/interface/hold_icons.4bpp"); @@ -1073,25 +1065,25 @@ static const u16 sTMHMMoves_Duplicate[] = enum { - MENU_SUMMARY, - MENU_SWITCH, - MENU_CANCEL1, - MENU_ITEM, - MENU_GIVE, - MENU_TAKE_ITEM, - MENU_MAIL, - MENU_TAKE_MAIL, - MENU_READ, - MENU_CANCEL2, - MENU_SHIFT, - MENU_SEND_OUT, - MENU_ENTER, - MENU_NO_ENTRY, - MENU_STORE, - MENU_REGISTER, - MENU_TRADE1, - MENU_TRADE2, - MENU_FIELD_MOVES, + CURSOR_OPTION_SUMMARY, + CURSOR_OPTION_SWITCH, + CURSOR_OPTION_CANCEL1, + CURSOR_OPTION_ITEM, + CURSOR_OPTION_GIVE, + CURSOR_OPTION_TAKE_ITEM, + CURSOR_OPTION_MAIL, + CURSOR_OPTION_TAKE_MAIL, + CURSOR_OPTION_READ, + CURSOR_OPTION_CANCEL2, + CURSOR_OPTION_SHIFT, + CURSOR_OPTION_SEND_OUT, + CURSOR_OPTION_ENTER, + CURSOR_OPTION_NO_ENTRY, + CURSOR_OPTION_STORE, + CURSOR_OPTION_REGISTER, + CURSOR_OPTION_TRADE1, + CURSOR_OPTION_TRADE2, + CURSOR_OPTION_FIELD_MOVES, }; static struct @@ -1100,50 +1092,50 @@ static struct TaskFunc func; } const sCursorOptions[] = { - [MENU_SUMMARY] = {gText_Summary5, CursorCB_Summary}, - [MENU_SWITCH] = {gText_Switch2, CursorCB_Switch}, - [MENU_CANCEL1] = {gFameCheckerText_Cancel, CursorCB_Cancel1}, - [MENU_ITEM] = {gText_Item, CursorCB_Item}, - [MENU_GIVE] = {gOtherText_Give, CursorCB_Give}, - [MENU_TAKE_ITEM] = {gText_Take, CursorCB_TakeItem}, - [MENU_MAIL] = {gText_Mail, CursorCB_Mail}, - [MENU_TAKE_MAIL] = {gText_Take2, CursorCB_TakeMail}, - [MENU_READ] = {gText_Read2, CursorCB_Read}, - [MENU_CANCEL2] = {gFameCheckerText_Cancel, CursorCB_Cancel2}, - [MENU_SHIFT] = {gText_Shift, CursorCB_SendMon}, - [MENU_SEND_OUT] = {gText_SendOut, CursorCB_SendMon}, - [MENU_ENTER] = {gText_Enter, CursorCB_Enter}, - [MENU_NO_ENTRY] = {gText_NoEntry, CursorCB_NoEntry}, - [MENU_STORE] = {gText_Store, CursorCB_Store}, - [MENU_REGISTER] = {gText_Register, CursorCB_Register}, - [MENU_TRADE1] = {gText_Trade4, CursorCB_Trade1}, - [MENU_TRADE2] = {gText_Trade4, CursorCB_Trade2}, - [MENU_FIELD_MOVES + FIELD_MOVE_FLASH] = {gMoveNames[MOVE_FLASH], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_CUT] = {gMoveNames[MOVE_CUT], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_FLY] = {gMoveNames[MOVE_FLY], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_STRENGTH] = {gMoveNames[MOVE_STRENGTH], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_SURF] = {gMoveNames[MOVE_SURF], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_ROCK_SMASH] = {gMoveNames[MOVE_ROCK_SMASH], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_WATERFALL] = {gMoveNames[MOVE_WATERFALL], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_TELEPORT] = {gMoveNames[MOVE_TELEPORT], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_DIG] = {gMoveNames[MOVE_DIG], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_MILK_DRINK] = {gMoveNames[MOVE_MILK_DRINK], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_SOFT_BOILED] = {gMoveNames[MOVE_SOFT_BOILED], CursorCB_FieldMove}, - [MENU_FIELD_MOVES + FIELD_MOVE_SWEET_SCENT] = {gMoveNames[MOVE_SWEET_SCENT], CursorCB_FieldMove}, + [CURSOR_OPTION_SUMMARY] = {gText_Summary5, CursorCB_Summary }, + [CURSOR_OPTION_SWITCH] = {gText_Switch2, CursorCB_Switch }, + [CURSOR_OPTION_CANCEL1] = {gFameCheckerText_Cancel, CursorCB_Cancel1 }, + [CURSOR_OPTION_ITEM] = {gText_Item, CursorCB_Item }, + [CURSOR_OPTION_GIVE] = {gOtherText_Give, CursorCB_Give }, + [CURSOR_OPTION_TAKE_ITEM] = {gText_Take, CursorCB_TakeItem }, + [CURSOR_OPTION_MAIL] = {gText_Mail, CursorCB_Mail }, + [CURSOR_OPTION_TAKE_MAIL] = {gText_Take2, CursorCB_TakeMail }, + [CURSOR_OPTION_READ] = {gText_Read2, CursorCB_Read }, + [CURSOR_OPTION_CANCEL2] = {gFameCheckerText_Cancel, CursorCB_Cancel2 }, + [CURSOR_OPTION_SHIFT] = {gText_Shift, CursorCB_SendMon }, + [CURSOR_OPTION_SEND_OUT] = {gText_SendOut, CursorCB_SendMon }, + [CURSOR_OPTION_ENTER] = {gText_Enter, CursorCB_Enter }, + [CURSOR_OPTION_NO_ENTRY] = {gText_NoEntry, CursorCB_NoEntry }, + [CURSOR_OPTION_STORE] = {gText_Store, CursorCB_Store }, + [CURSOR_OPTION_REGISTER] = {gText_Register, CursorCB_Register }, + [CURSOR_OPTION_TRADE1] = {gText_Trade4, CursorCB_Trade1 }, + [CURSOR_OPTION_TRADE2] = {gText_Trade4, CursorCB_Trade2 }, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_FLASH] = {gMoveNames[MOVE_FLASH], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_CUT] = {gMoveNames[MOVE_CUT], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_FLY] = {gMoveNames[MOVE_FLY], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_STRENGTH] = {gMoveNames[MOVE_STRENGTH], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_SURF] = {gMoveNames[MOVE_SURF], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_ROCK_SMASH] = {gMoveNames[MOVE_ROCK_SMASH], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_WATERFALL] = {gMoveNames[MOVE_WATERFALL], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_TELEPORT] = {gMoveNames[MOVE_TELEPORT], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_DIG] = {gMoveNames[MOVE_DIG], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_MILK_DRINK] = {gMoveNames[MOVE_MILK_DRINK], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_SOFT_BOILED] = {gMoveNames[MOVE_SOFT_BOILED], CursorCB_FieldMove}, + [CURSOR_OPTION_FIELD_MOVES + FIELD_MOVE_SWEET_SCENT] = {gMoveNames[MOVE_SWEET_SCENT], CursorCB_FieldMove}, }; -static const u8 sPartyMenuAction_SummarySwitchCancel[] = {MENU_SUMMARY, MENU_SWITCH, MENU_CANCEL1}; -static const u8 sPartyMenuAction_ShiftSummaryCancel[] = {MENU_SHIFT, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_SendOutSummaryCancel[] = {MENU_SEND_OUT, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_SummaryCancel[] = {MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_EnterSummaryCancel[] = {MENU_ENTER, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_NoEntrySummaryCancel[] = {MENU_NO_ENTRY, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_StoreSummaryCancel[] = {MENU_STORE, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_GiveTakeItemCancel[] = {MENU_GIVE, MENU_TAKE_ITEM, MENU_CANCEL2}; -static const u8 sPartyMenuAction_ReadTakeMailCancel[] = {MENU_READ, MENU_TAKE_MAIL, MENU_CANCEL2}; -static const u8 sPartyMenuAction_RegisterSummaryCancel[] = {MENU_REGISTER, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_TradeSummaryCancel1[] = {MENU_TRADE1, MENU_SUMMARY, MENU_CANCEL1}; -static const u8 sPartyMenuAction_TradeSummaryCancel2[] = {MENU_TRADE2, MENU_SUMMARY, MENU_CANCEL1}; +static const u8 sPartyMenuAction_SummarySwitchCancel[] = {CURSOR_OPTION_SUMMARY, CURSOR_OPTION_SWITCH, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_ShiftSummaryCancel[] = {CURSOR_OPTION_SHIFT, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_SendOutSummaryCancel[] = {CURSOR_OPTION_SEND_OUT, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_SummaryCancel[] = {CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_EnterSummaryCancel[] = {CURSOR_OPTION_ENTER, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_NoEntrySummaryCancel[] = {CURSOR_OPTION_NO_ENTRY, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_StoreSummaryCancel[] = {CURSOR_OPTION_STORE, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_GiveTakeItemCancel[] = {CURSOR_OPTION_GIVE, CURSOR_OPTION_TAKE_ITEM, CURSOR_OPTION_CANCEL2}; +static const u8 sPartyMenuAction_ReadTakeMailCancel[] = {CURSOR_OPTION_READ, CURSOR_OPTION_TAKE_MAIL, CURSOR_OPTION_CANCEL2}; +static const u8 sPartyMenuAction_RegisterSummaryCancel[] = {CURSOR_OPTION_REGISTER, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_TradeSummaryCancel1[] = {CURSOR_OPTION_TRADE1, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; +static const u8 sPartyMenuAction_TradeSummaryCancel2[] = {CURSOR_OPTION_TRADE2, CURSOR_OPTION_SUMMARY, CURSOR_OPTION_CANCEL1}; // IDs for the action lists that appear when a party mon is selected enum diff --git a/src/item_use.c b/src/item_use.c index 1b9d0146a..a7a22665f 100644 --- a/src/item_use.c +++ b/src/item_use.c @@ -413,7 +413,7 @@ void FieldUseFunc_Medicine(u8 taskId) void FieldUseFunc_Ether(u8 taskId) { - gItemUseCB = ItemUseCB_PPRecovery; + gItemUseCB = ItemUseCB_TryRestorePP; sub_80A16D0(taskId); } @@ -816,7 +816,7 @@ static void sub_80A1FD8(u8 taskId) void BattleUseFunc_Ether(u8 taskId) { - gItemUseCB = ItemUseCB_PPRecovery; + gItemUseCB = ItemUseCB_TryRestorePP; ItemUse_SwitchToPartyMenuInBattle(taskId); } diff --git a/src/party_menu.c b/src/party_menu.c index 912c5184e..33293ed9c 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -83,6 +83,9 @@ #define MENU_DIR_RIGHT 2 #define MENU_DIR_LEFT -2 +#define SLOT_CONFIRM (PARTY_SIZE) +#define SLOT_CANCEL (PARTY_SIZE + 1) + enum { CAN_LEARN_MOVE, @@ -91,6 +94,20 @@ enum CANNOT_LEARN_MOVE_IS_EGG }; +enum +{ + LEARN_VIA_TMHM, + LEARN_VIA_LEVEL_UP, + LEARN_VIA_TUTOR, +}; + +enum +{ + DRAW_TEXT_ONLY, + DRAW_MENU_BOX_AND_TEXT, + DRAW_MENU_BOX_ONLY, +}; + struct PartyMenuBoxInfoRects { void (*blitFunc)(u8 windowId, u8 x, u8 y, u8 width, u8 height, bool8 isEgg); @@ -105,7 +122,7 @@ struct PartyMenuInternal { TaskFunc task; MainCallback exitCallback; - u32 chooseHalf:1; + u32 chooseMultiple:1; u32 lastSelectedSlot:3; // Used to return to same slot when going left/right bewtween columns u32 spriteIdConfirmPokeball:7; u32 spriteIdCancelPokeball:7; @@ -165,29 +182,29 @@ static void LoadPartyMenuPokeballGfx(void); static void LoadPartyMenuAilmentGfx(void); static bool8 RenderPartyMenuBoxes(void); static void CreateCancelConfirmPokeballSprites(void); -static void CreateCancelConfirmWindows(bool8 chooseHalf); +static void CreateCancelConfirmWindows(bool8 chooseMultiple); static void Task_ExitPartyMenu(u8 taskId); static void FreePartyPointers(void); static void PartyPaletteBufferCopy(u8 offset); static void DisplayPartyPokemonDataForMultiBattle(u8 slot); -static void DisplayPartyPokemonDataForChooseHalf(u8 slot); +static void DisplayPartyPokemonDataForChooseMultiple(u8 slot); static bool8 DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(u8 slot); static void DisplayPartyPokemonData(u8 slot); static void DisplayPartyPokemonDataForWirelessMinigame(u8 slot); static void LoadPartyBoxPalette(struct PartyMenuBox *menuBox, u8 palFlags); static void DrawEmptySlot(u8 windowId); -static void DisplayPartyPokemonNickname(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c); -static void DisplayPartyPokemonLevelCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c); -static void DisplayPartyPokemonGenderNidoranCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c); -static void DisplayPartyPokemonHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c); -static void DisplayPartyPokemonMaxHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c); +static void DisplayPartyPokemonNickname(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); +static void DisplayPartyPokemonLevelCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); +static void DisplayPartyPokemonGenderNidoranCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); +static void DisplayPartyPokemonHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); +static void DisplayPartyPokemonMaxHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); static void DisplayPartyPokemonHPBarCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox); -static void DisplayPartyPokemonDescriptionText(u8 stringId, struct PartyMenuBox *menuBox, u8 c); +static void DisplayPartyPokemonDescriptionText(u8 stringId, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText); static bool8 GetBattleEntryEligibility(struct Pokemon *mon); static bool8 IsMonAllowedInMinigame(u8 slot); static void DisplayPartyPokemonDataToTeachMove(u8 slot, u16 item, u8 tutor); static u8 CanMonLearnTMTutor(struct Pokemon *mon, u16 item, u8 tutor); -static void DisplayPartyPokemonBarDetail(u8 windowId, const u8 *str, u8 color, const u8 *align); +static void DisplayPartyPokemonBarDetail(u8 windowId, const u8 *str, u8 color, const u8 *dimensions); static void DisplayPartyPokemonLevel(u8 level, struct PartyMenuBox *menuBox); static void DisplayPartyPokemonGender(u8 gender, u16 species, u8 *nickname, struct PartyMenuBox *menuBox); static void DisplayPartyPokemonHP(u16 hp, struct PartyMenuBox *menuBox); @@ -222,7 +239,7 @@ static void SwitchSelectedMons(u8 taskId); static void TryEnterMonForMinigame(u8 taskId, u8 slot); static void Task_TryCreateSelectionWindow(u8 taskId); static void TryGiveItemOrMailToSelectedMon(u8 taskId); -static void PartyMenuRemoveWindow(u8 *ptr); +static void PartyMenuRemoveWindow(u8 *windowId); static void CB2_SetUpExitToBattleScreen(void); static void Task_ClosePartyMenuAfterText(u8 taskId); static void FinishTwoMonAction(u8 taskId); @@ -299,7 +316,7 @@ static u8 GetPartyIdFromBattleSlot(u8 slot); static void Task_DisplayHPRestoredMessage(u8 taskId); static void SetSelectedMoveForPPItem(u8 taskId); static void ReturnToUseOnWhichMon(u8 taskId); -static void TryUsePPItem(u8 taskId); +static void TryUsePPItemInBattle(u8 taskId); static void ItemUseCB_LearnedMove(u8 taskId, TaskFunc func); static void Task_LearnedMove(u8 taskId); static void Task_ReplaceMoveYesNo(u8 taskId); @@ -343,9 +360,9 @@ static void CB2_ReturnToPartyOrBagMenuFromWritingMail(void); static bool8 ReturnGiveItemToBagOrPC(u16 item); static void Task_DisplayGaveMailFromBagMessage(u8 taskId); static void Task_HandleSwitchItemsFromBagYesNoInput(u8 taskId); -static void Task_ValidateChosenHalfParty(u8 taskId); +static void Task_ValidateChosenMonsForBattle(u8 taskId); static bool8 HasPartySlotAlreadyBeenSelected(u8 slot); -static void Task_ContinueChoosingHalfParty(u8 taskId); +static void Task_ContinueChoosingMonsForBattle(u8 taskId); static void BufferBattlePartyOrder(u8 *partyBattleOrder, u8 flankId); static void BufferBattlePartyOrderBySide(u8 *partyBattleOrder, u8 flankId, u8 battlerId); static void Task_InitMultiPartnerPartySlideIn(u8 taskId); @@ -373,13 +390,13 @@ static u8 FirstBattleEnterParty_CreateWindowAndMsg1Printer(void); static void FirstBattleEnterParty_DestroyVoiceoverWindow(u8 windowId); static void SetSwitchedPartyOrderQuestLogEvent(void); static void SetUsedFieldMoveQuestLogEvent(struct Pokemon *mon, u8 fieldMove); -static void sub_8124DE0(void); -static void sub_8124E48(void); -static void sub_812580C(u8 taskId); -static void sub_8125898(u8 taskId, TaskFunc func); -static void sub_8125F4C(u8 taskId, TaskFunc func); -static void sub_8125F5C(u8 taskId); -static void sub_8126BD4(void); +static void CB2_DoUseItemAnim(void); +static void CB2_UseItem(void); +static void TryUsePPItemOutsideBattle(u8 taskId); +static void ItemUseCB_RestorePP(u8 taskId, TaskFunc func); +static void ItemUseCB_ReplaceMoveWithTMHM(u8 taskId, TaskFunc func); +static void Task_ReplaceMoveWithTMHM(u8 taskId); +static void CB2_UseEvolutionStone(void); static bool8 MonCanEvolve(void); static EWRAM_DATA struct PartyMenuInternal *sPartyMenuInternal = NULL; @@ -409,9 +426,7 @@ void InitPartyMenu(u8 menuType, u8 layout, u8 partyAction, bool8 keepCursorPos, ResetPartyMenu(); sPartyMenuInternal = Alloc(sizeof(struct PartyMenuInternal)); if (sPartyMenuInternal == NULL) - { SetMainCallback2(callback); - } else { gPartyMenu.menuType = menuType; @@ -421,16 +436,16 @@ void InitPartyMenu(u8 menuType, u8 layout, u8 partyAction, bool8 keepCursorPos, sPartyMenuInternal->task = task; sPartyMenuInternal->exitCallback = NULL; sPartyMenuInternal->lastSelectedSlot = 0; - if (menuType == PARTY_MENU_TYPE_CHOOSE_HALF) - sPartyMenuInternal->chooseHalf = TRUE; + if (menuType == PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS) + sPartyMenuInternal->chooseMultiple = TRUE; else - sPartyMenuInternal->chooseHalf = FALSE; + sPartyMenuInternal->chooseMultiple = FALSE; if (layout != KEEP_PARTY_LAYOUT) gPartyMenu.layout = layout; - for (i = 0; i < NELEMS(sPartyMenuInternal->data); ++i) + for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->data); ++i) sPartyMenuInternal->data[i] = 0; - for (i = 0; i < NELEMS(sPartyMenuInternal->windowId); ++i) - sPartyMenuInternal->windowId[i] = 0xFF; + for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->windowId); ++i) + sPartyMenuInternal->windowId[i] = WINDOW_NONE; if (!keepCursorPos) gPartyMenu.slotId = 0; else if (gPartyMenu.slotId > PARTY_SIZE - 1 || GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES) == SPECIES_NONE) @@ -562,7 +577,7 @@ static bool8 ShowPartyMenu(void) ++gMain.state; break; case 18: - CreateCancelConfirmWindows(sPartyMenuInternal->chooseHalf); + CreateCancelConfirmWindows(sPartyMenuInternal->chooseMultiple); ++gMain.state; break; case 19: @@ -625,7 +640,7 @@ static bool8 AllocPartyMenuBg(void) return FALSE; memset(sPartyBgTilemapBuffer, 0, 0x800); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sPartyMenuBgTemplates, NELEMS(sPartyMenuBgTemplates)); + InitBgsFromTemplates(0, sPartyMenuBgTemplates, ARRAY_COUNT(sPartyMenuBgTemplates)); SetBgTilemapBuffer(1, sPartyBgTilemapBuffer); ScheduleBgCopyTilemapToVram(1); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); @@ -743,8 +758,8 @@ static void RenderPartyMenuBox(u8 slot) } else { - if (gPartyMenu.menuType == PARTY_MENU_TYPE_CHOOSE_HALF) - DisplayPartyPokemonDataForChooseHalf(slot); + if (gPartyMenu.menuType == PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS) + DisplayPartyPokemonDataForChooseMultiple(slot); else if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) DisplayPartyPokemonDataForWirelessMinigame(slot); else if (!DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(slot)) @@ -766,16 +781,16 @@ static void DisplayPartyPokemonData(u8 slot) if (GetMonData(&gPlayerParty[slot], MON_DATA_IS_EGG)) { sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, TRUE); - DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); + DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); } else { sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, FALSE); - DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); - DisplayPartyPokemonLevelCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); - DisplayPartyPokemonGenderNidoranCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); - DisplayPartyPokemonHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); - DisplayPartyPokemonMaxHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0); + DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); + DisplayPartyPokemonLevelCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); + DisplayPartyPokemonGenderNidoranCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); + DisplayPartyPokemonHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); + DisplayPartyPokemonMaxHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); DisplayPartyPokemonHPBarCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot]); } } @@ -785,16 +800,16 @@ static void DisplayPartyPokemonDescriptionData(u8 slot, u8 stringId) struct Pokemon *mon = &gPlayerParty[slot]; sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, TRUE); - DisplayPartyPokemonNickname(mon, &sPartyMenuBoxes[slot], 0); + DisplayPartyPokemonNickname(mon, &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); if (!GetMonData(mon, MON_DATA_IS_EGG)) { - DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[slot], 0); - DisplayPartyPokemonGenderNidoranCheck(mon, &sPartyMenuBoxes[slot], 0); + DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); + DisplayPartyPokemonGenderNidoranCheck(mon, &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); } - DisplayPartyPokemonDescriptionText(stringId, &sPartyMenuBoxes[slot], 0); + DisplayPartyPokemonDescriptionText(stringId, &sPartyMenuBoxes[slot], DRAW_TEXT_ONLY); } -static void DisplayPartyPokemonDataForChooseHalf(u8 slot) +static void DisplayPartyPokemonDataForChooseMultiple(u8 slot) { u8 i; struct Pokemon *mon = &gPlayerParty[slot]; @@ -802,12 +817,10 @@ static void DisplayPartyPokemonDataForChooseHalf(u8 slot) u8 maxBattlers; if (!GetBattleEntryEligibility(mon)) - { DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NOT_ABLE); - } else { - if (gPartyMenu.unk_8_6 == 2) + if (gPartyMenu.chooseMonsBattleType == CHOOSE_MONS_FOR_UNION_ROOM_BATTLE) maxBattlers = 2; else maxBattlers = 3; @@ -888,9 +901,7 @@ static void DisplayPartyPokemonDataForMultiBattle(u8 slot) u8 actualSlot = slot - (3); if (gMultiPartnerParty[actualSlot].species == SPECIES_NONE) - { DrawEmptySlot(menuBox->windowId); - } else { menuBox->infoRects->blitFunc(menuBox->windowId, 0, 0, 0, 0, FALSE); @@ -969,16 +980,15 @@ static void CreateCancelConfirmPokeballSprites(void) } else { - if (sPartyMenuInternal->chooseHalf) + if (sPartyMenuInternal->chooseMultiple) { sPartyMenuInternal->spriteIdConfirmPokeball = CreateSmallPokeballButtonSprite(0xBF, 0x88); DrawCancelConfirmButtons(); sPartyMenuInternal->spriteIdCancelPokeball = CreateSmallPokeballButtonSprite(0xBF, 0x98); } else - { sPartyMenuInternal->spriteIdCancelPokeball = CreatePokeballButtonSprite(198, 148); - } + AnimatePartySlot(gPartyMenu.slotId, 1); } } @@ -997,29 +1007,28 @@ void AnimatePartySlot(u8 slot, u8 animNum) PartyMenuStartSpriteAnim(sPartyMenuBoxes[slot].pokeballSpriteId, animNum); } return; - case PARTY_SIZE: // Confirm + case SLOT_CONFIRM: if (animNum == 0) SetBgTilemapPalette(1, 23, 16, 7, 2, 1); else SetBgTilemapPalette(1, 23, 16, 7, 2, 2); spriteId = sPartyMenuInternal->spriteIdConfirmPokeball; break; - case PARTY_SIZE + 1: // Cancel + case SLOT_CANCEL: // The position of the Cancel button changes if Confirm is present - if (!sPartyMenuInternal->chooseHalf) + if (!sPartyMenuInternal->chooseMultiple) { if (animNum == 0) SetBgTilemapPalette(1, 23, 17, 7, 2, 1); else SetBgTilemapPalette(1, 23, 17, 7, 2, 2); } - else if (animNum == 0) - { - SetBgTilemapPalette(1, 23, 18, 7, 2, 1); - } else { - SetBgTilemapPalette(1, 23, 18, 7, 2, 2); + if (animNum == 0) + SetBgTilemapPalette(1, 23, 18, 7, 2, 1); + else + SetBgTilemapPalette(1, 23, 18, 7, 2, 2); } spriteId = sPartyMenuInternal->spriteIdCancelPokeball; break; @@ -1115,14 +1124,14 @@ void Task_HandleChooseMonInput(u8 taskId) switch (PartyMenuButtonHandler(slotPtr)) { - case 1: // Selected mon + case A_BUTTON: HandleChooseMonSelection(taskId, slotPtr); break; - case 2: // Selected Cancel + case B_BUTTON: // also handles pressing A_BUTTON on Cancel HandleChooseMonCancel(taskId, slotPtr); break; - case 8: // Start button - if (sPartyMenuInternal->chooseHalf) + case START_BUTTON: + if (sPartyMenuInternal->chooseMultiple) { PlaySE(SE_SELECT); MoveCursorToConfirm(); @@ -1142,10 +1151,8 @@ static s8 *GetCurrentPartySlotPtr(void) static void HandleChooseMonSelection(u8 taskId, s8 *slotPtr) { - if (*slotPtr == PARTY_SIZE) - { - gPartyMenu.task(taskId); - } + if (*slotPtr == SLOT_CONFIRM) + gPartyMenu.task(taskId); // task here is always Task_ValidateChosenMonsForBattle else { switch (gPartyMenu.action) @@ -1237,16 +1244,14 @@ static void HandleChooseMonCancel(u8 taskId, s8 *slotPtr) break; default: PlaySE(SE_SELECT); - if (gPartyMenu.menuType == PARTY_MENU_TYPE_CHOOSE_HALF) - { + if (gPartyMenu.menuType == PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS) DisplayCancelChooseMonYesNo(taskId); - } else { if (!MenuHelpers_LinkSomething()) - gSpecialVar_0x8004 = PARTY_SIZE + 1; + gSpecialVar_0x8004 = SLOT_CANCEL; gPartyMenuUseExitCallback = FALSE; - *slotPtr = PARTY_SIZE + 1; + *slotPtr = SLOT_CANCEL; Task_ClosePartyMenu(taskId); } break; @@ -1276,7 +1281,7 @@ static void Task_HandleCancelChooseMonYesNoInput(u8 taskId) { case 0: gPartyMenuUseExitCallback = FALSE; - gPartyMenu.slotId = PARTY_SIZE + 1; + gPartyMenu.slotId = SLOT_CANCEL; ClearSelectedPartyOrder(); Task_ClosePartyMenu(taskId); break; @@ -1323,15 +1328,14 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) break; } if (JOY_NEW(START_BUTTON)) - return 8; + return START_BUTTON; if (movementDir) { UpdateCurrentPartySelection(slotPtr, movementDir); return 0; } - // Pressed Cancel - if (JOY_NEW(A_BUTTON) && *slotPtr == PARTY_SIZE + 1) - return 2; + if (JOY_NEW(A_BUTTON) && *slotPtr == SLOT_CANCEL) + return B_BUTTON; return JOY_NEW(A_BUTTON | B_BUTTON); } @@ -1354,49 +1358,35 @@ static void UpdateCurrentPartySelection(s8 *slotPtr, s8 movementDir) static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) { - // PARTY_SIZE + 1 is Cancel, PARTY_SIZE is Confirm switch (movementDir) { case MENU_DIR_UP: if (*slotPtr == 0) - { - *slotPtr = PARTY_SIZE + 1; - } - else if (*slotPtr == PARTY_SIZE) - { + *slotPtr = SLOT_CANCEL; + else if (*slotPtr == SLOT_CONFIRM) *slotPtr = gPlayerPartyCount - 1; - } - else if (*slotPtr == PARTY_SIZE + 1) + else if (*slotPtr == SLOT_CANCEL) { - if (sPartyMenuInternal->chooseHalf) - *slotPtr = PARTY_SIZE; + if (sPartyMenuInternal->chooseMultiple) + *slotPtr = SLOT_CONFIRM; else *slotPtr = gPlayerPartyCount - 1; } else - { --*slotPtr; - } break; case MENU_DIR_DOWN: - if (*slotPtr == PARTY_SIZE + 1) - { + if (*slotPtr == SLOT_CANCEL) *slotPtr = 0; + else if (*slotPtr == gPlayerPartyCount - 1) + { + if (sPartyMenuInternal->chooseMultiple) + *slotPtr = SLOT_CONFIRM; + else + *slotPtr = SLOT_CANCEL; } else - { - if (*slotPtr == gPlayerPartyCount - 1) - { - if (sPartyMenuInternal->chooseHalf) - *slotPtr = PARTY_SIZE; - else - *slotPtr = PARTY_SIZE + 1; - } - else - { - ++*slotPtr; - } - } + ++*slotPtr; break; case MENU_DIR_RIGHT: if (gPlayerPartyCount != 1 && *slotPtr == 0) @@ -1408,7 +1398,7 @@ static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) } break; case MENU_DIR_LEFT: - if (*slotPtr != 0 && *slotPtr != PARTY_SIZE && *slotPtr != PARTY_SIZE + 1) + if (*slotPtr != 0 && *slotPtr != SLOT_CONFIRM && *slotPtr != SLOT_CANCEL) { sPartyMenuInternal->lastSelectedSlot = *slotPtr; *slotPtr = 0; @@ -1419,7 +1409,6 @@ static void UpdatePartySelectionSingleLayout(s8 *slotPtr, s8 movementDir) static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) { - // PARTY_SIZE + 1 is Cancel, PARTY_SIZE is Confirm // newSlot is used temporarily as a movement direction during its later assignment s8 newSlot = movementDir; @@ -1428,19 +1417,19 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) case MENU_DIR_UP: if (*slotPtr == 0) { - *slotPtr = PARTY_SIZE + 1; + *slotPtr = SLOT_CANCEL; break; } - else if (*slotPtr == PARTY_SIZE) + else if (*slotPtr == SLOT_CONFIRM) { *slotPtr = gPlayerPartyCount - 1; break; } - else if (*slotPtr == PARTY_SIZE + 1) + else if (*slotPtr == SLOT_CANCEL) { - if (sPartyMenuInternal->chooseHalf) + if (sPartyMenuInternal->chooseMultiple) { - *slotPtr = PARTY_SIZE; + *slotPtr = SLOT_CONFIRM; break; } --*slotPtr; @@ -1450,28 +1439,22 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) *slotPtr = newSlot; break; case MENU_DIR_DOWN: - if (*slotPtr == PARTY_SIZE) - { - *slotPtr = PARTY_SIZE + 1; - } - else if (*slotPtr == PARTY_SIZE + 1) - { + if (*slotPtr == SLOT_CONFIRM) + *slotPtr = SLOT_CANCEL; + else if (*slotPtr == SLOT_CANCEL) *slotPtr = 0; - } else { newSlot = GetNewSlotDoubleLayout(*slotPtr, MENU_DIR_DOWN); if (newSlot == -1) { - if (sPartyMenuInternal->chooseHalf) - *slotPtr = PARTY_SIZE; + if (sPartyMenuInternal->chooseMultiple) + *slotPtr = SLOT_CONFIRM; else - *slotPtr = PARTY_SIZE + 1; + *slotPtr = SLOT_CANCEL; } else - { *slotPtr = newSlot; - } } break; case MENU_DIR_RIGHT: @@ -1483,9 +1466,8 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) *slotPtr = 3; } else if (GetMonData(&gPlayerParty[2], MON_DATA_SPECIES) != SPECIES_NONE) - { *slotPtr = 2; - } + } else if (*slotPtr == 1) { @@ -1495,9 +1477,8 @@ static void UpdatePartySelectionDoubleLayout(s8 *slotPtr, s8 movementDir) *slotPtr = 5; } else if (GetMonData(&gPlayerParty[4], MON_DATA_SPECIES) != SPECIES_NONE) - { *slotPtr = 4; - } + } break; case MENU_DIR_LEFT: @@ -1520,7 +1501,7 @@ static s8 GetNewSlotDoubleLayout(s8 slotId, s8 movementDir) while (TRUE) { slotId += movementDir; - if ((u8)slotId >= PARTY_SIZE) + if ((u8)slotId >= SLOT_CONFIRM) return -1; if (GetMonData(&gPlayerParty[slotId], MON_DATA_SPECIES) != SPECIES_NONE) return slotId; @@ -1697,7 +1678,7 @@ static void Task_PartyMenuModifyHP(u8 taskId) tHP += tHPIncrement; --tHPToAdd; SetMonData(&gPlayerParty[tPartyId], MON_DATA_HP, &tHP); - DisplayPartyPokemonHPCheck(&gPlayerParty[tPartyId], &sPartyMenuBoxes[tPartyId], 1); + DisplayPartyPokemonHPCheck(&gPlayerParty[tPartyId], &sPartyMenuBoxes[tPartyId], DRAW_MENU_BOX_AND_TEXT); DisplayPartyPokemonHPBarCheck(&gPlayerParty[tPartyId], &sPartyMenuBoxes[tPartyId]); if (tHPToAdd == 0 || tHP == 0 || tHP == tMaxHP) { @@ -1788,25 +1769,24 @@ u8 GetMonAilment(struct Pokemon *mon) return AILMENT_NONE; } +#define minigameBitflag data[0] + static void SetPartyMonsAllowedInMinigame(void) { - u16 *ptr; - if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { u8 i; - - ptr = &gPartyMenu.data1; - gPartyMenu.data1 = 0; + s16 *data = gPartyMenu.data; + minigameBitflag = 0; if (gSpecialVar_0x8005 == 0) { for (i = 0; i < gPlayerPartyCount; ++i) - *ptr += IsMonAllowedInPokemonJump(&gPlayerParty[i]) << i; + minigameBitflag += IsMonAllowedInPokemonJump(&gPlayerParty[i]) << i; } else { for (i = 0; i < gPlayerPartyCount; ++i) - *ptr += IsMonAllowedInDodrioBerryPicking(&gPlayerParty[i]) << i; + minigameBitflag += IsMonAllowedInDodrioBerryPicking(&gPlayerParty[i]) << i; } } } @@ -1818,7 +1798,6 @@ static bool16 IsMonAllowedInPokemonJump(struct Pokemon *mon) return FALSE; } - static bool16 IsMonAllowedInDodrioBerryPicking(struct Pokemon *mon) { if (GetMonData(mon, MON_DATA_IS_EGG) != TRUE && GetMonData(mon, MON_DATA_SPECIES) == SPECIES_DODRIO) @@ -1828,11 +1807,13 @@ static bool16 IsMonAllowedInDodrioBerryPicking(struct Pokemon *mon) static bool8 IsMonAllowedInMinigame(u8 slot) { - if (!((gPartyMenu.data1 >> slot) & 1)) + if (!((gPartyMenu.minigameBitflag >> slot) & 1)) return FALSE; return TRUE; } +#undef minigameBitflag + static void TryEnterMonForMinigame(u8 taskId, u8 slot) { if (IsMonAllowedInMinigame(slot) == TRUE) @@ -1871,7 +1852,7 @@ static void Task_HandleCancelParticipationYesNoInput(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case 0: - gSpecialVar_0x8004 = PARTY_SIZE + 1; + gSpecialVar_0x8004 = SLOT_CANCEL; Task_ClosePartyMenu(taskId); break; case MENU_B_PRESSED: @@ -1892,22 +1873,16 @@ static u8 CanMonLearnTMTutor(struct Pokemon *mon, u16 item, u8 tutor) if (item >= ITEM_TM01_FOCUS_PUNCH) { - if (CanMonLearnTMHM(mon, item - ITEM_TM01_FOCUS_PUNCH)) - move = ItemIdToBattleMoveId(item); - else + if (!CanMonLearnTMHM(mon, item - ITEM_TM01_FOCUS_PUNCH)) return CANNOT_LEARN_MOVE; - do - { - } while (0); + else + move = ItemIdToBattleMoveId(item); } else if (CanLearnTutorMove(GetMonData(mon, MON_DATA_SPECIES), tutor) == FALSE) - { return CANNOT_LEARN_MOVE; - } else - { move = GetTutorMove(tutor); - } + if (MonKnowsMove(mon, move) == TRUE) return ALREADY_KNOWS_MOVE; else @@ -2148,7 +2123,7 @@ static void InitPartyMenuWindows(u8 layout) LoadPalette(stdpal_get(0), 0xE0, 0x20); } -static void CreateCancelConfirmWindows(bool8 chooseHalf) +static void CreateCancelConfirmWindows(bool8 chooseMultiple) { u8 confirmWindowId; u8 cancelWindowId; @@ -2156,7 +2131,7 @@ static void CreateCancelConfirmWindows(bool8 chooseHalf) if (gPartyMenu.menuType != PARTY_MENU_TYPE_MULTI_SHOWCASE) { - if (chooseHalf == TRUE) + if (chooseMultiple == TRUE) { confirmWindowId = AddWindow(&sConfirmButtonWindowTemplate); FillWindowPixelBuffer(confirmWindowId, PIXEL_FILL(0)); @@ -2194,7 +2169,7 @@ static u16 *GetPartyMenuPalBufferPtr(u8 paletteId) return &sPartyMenuInternal->palBuffer[paletteId]; } -static void BlitBitmapToPartyWindow(u8 windowId, const u8 *b, u8 c, u8 x, u8 y, u8 width, u8 height) +static void BlitBitmapToPartyWindow(u8 windowId, const u8 *tileNums, u8 menuBoxWidth, u8 x, u8 y, u8 width, u8 height) { u8 *pixels = AllocZeroed(height * width * 32); u8 i, j; @@ -2203,7 +2178,7 @@ static void BlitBitmapToPartyWindow(u8 windowId, const u8 *b, u8 c, u8 x, u8 y, { for (i = 0; i < height; ++i) for (j = 0; j < width; ++j) - CpuCopy16(GetPartyMenuBgTile(b[x + j + ((y + i) * c)]), &pixels[(i * width + j) * 32], 32); + CpuCopy16(GetPartyMenuBgTile(tileNums[x + j + ((y + i) * menuBoxWidth)]), &pixels[(i * width + j) * 32], 32); BlitBitmapToWindow(windowId, pixels, x * 8, y * 8, width * 8, height * 8); Free(pixels); } @@ -2320,25 +2295,25 @@ static void LoadPartyBoxPalette(struct PartyMenuBox *menuBox, u8 palFlags) } } -static void DisplayPartyPokemonBarDetail(u8 windowId, const u8 *str, u8 color, const u8 *align) +static void DisplayPartyPokemonBarDetail(u8 windowId, const u8 *str, u8 color, const u8 *dimensions) { - AddTextPrinterParameterized3(windowId, FONT_0, align[0], align[1], sFontColorTable[color], 0, str); + AddTextPrinterParameterized3(windowId, FONT_0, dimensions[0], dimensions[1], sFontColorTable[color], 0, str); } -static void DisplayPartyPokemonNickname(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonNickname(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { u8 nickname[POKEMON_NAME_LENGTH + 1]; if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { - if (c == 1) - menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[0] >> 3, menuBox->infoRects->dimensions[1] >> 3, menuBox->infoRects->dimensions[2] >> 3, menuBox->infoRects->dimensions[3] >> 3, FALSE); + if (drawMenuBoxOrText == DRAW_MENU_BOX_AND_TEXT) + menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[0] / 8, menuBox->infoRects->dimensions[1] / 8, menuBox->infoRects->dimensions[2] / 8, menuBox->infoRects->dimensions[3] / 8, FALSE); GetMonNickname(mon, nickname); DisplayPartyPokemonBarDetail(menuBox->windowId, nickname, 0, menuBox->infoRects->dimensions); } } -static void DisplayPartyPokemonLevelCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonLevelCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { @@ -2346,9 +2321,9 @@ static void DisplayPartyPokemonLevelCheck(struct Pokemon *mon, struct PartyMenuB if (ailment == AILMENT_NONE || ailment == AILMENT_PKRS) { - if (c != 0) - menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[4] >> 3, (menuBox->infoRects->dimensions[5] >> 3) + 1, menuBox->infoRects->dimensions[6] >> 3, menuBox->infoRects->dimensions[7] >> 3, FALSE); - if (c != 2) + if (drawMenuBoxOrText != DRAW_TEXT_ONLY) + menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[4] / 8, (menuBox->infoRects->dimensions[5] / 8) + 1, menuBox->infoRects->dimensions[6] / 8, menuBox->infoRects->dimensions[7] / 8, FALSE); + if (drawMenuBoxOrText != DRAW_MENU_BOX_ONLY) DisplayPartyPokemonLevel(GetMonData(mon, MON_DATA_LEVEL), menuBox); } } @@ -2362,12 +2337,12 @@ static void DisplayPartyPokemonLevel(u8 level, struct PartyMenuBox *menuBox) DisplayPartyPokemonBarDetail(menuBox->windowId, gStringVar1, 0, &menuBox->infoRects->dimensions[4]); } -static void DisplayPartyPokemonGenderNidoranCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonGenderNidoranCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { u8 nickname[POKEMON_NAME_LENGTH + 1]; - if (c == 1) - menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[8] >> 3, (menuBox->infoRects->dimensions[9] >> 3) + 1, menuBox->infoRects->dimensions[10] >> 3, menuBox->infoRects->dimensions[11] >> 3, FALSE); + if (drawMenuBoxOrText == DRAW_MENU_BOX_AND_TEXT) + menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[8] / 8, (menuBox->infoRects->dimensions[9] / 8) + 1, menuBox->infoRects->dimensions[10] / 8, menuBox->infoRects->dimensions[11] / 8, FALSE); GetMonNickname(mon, nickname); DisplayPartyPokemonGender(GetMonGender(mon), GetMonData(mon, MON_DATA_SPECIES), nickname, menuBox); } @@ -2395,13 +2370,13 @@ static void DisplayPartyPokemonGender(u8 gender, u16 species, u8 *nickname, stru } } -static void DisplayPartyPokemonHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { - if (c != 0) - menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[12] >> 3, (menuBox->infoRects->dimensions[13] >> 3) + 1, menuBox->infoRects->dimensions[14] >> 3, menuBox->infoRects->dimensions[15] >> 3, FALSE); - if (c != 2) + if (drawMenuBoxOrText != DRAW_TEXT_ONLY) + menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->dimensions[12] / 8, (menuBox->infoRects->dimensions[13] / 8) + 1, menuBox->infoRects->dimensions[14] / 8, menuBox->infoRects->dimensions[15] / 8, FALSE); + if (drawMenuBoxOrText != DRAW_MENU_BOX_ONLY) DisplayPartyPokemonHP(GetMonData(mon, MON_DATA_HP), menuBox); } } @@ -2415,13 +2390,13 @@ static void DisplayPartyPokemonHP(u16 hp, struct PartyMenuBox *menuBox) DisplayPartyPokemonBarDetail(menuBox->windowId, gStringVar1, 0, &menuBox->infoRects->dimensions[12]); } -static void DisplayPartyPokemonMaxHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonMaxHPCheck(struct Pokemon *mon, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { if (GetMonData(mon, MON_DATA_SPECIES) != SPECIES_NONE) { - if (c != 0) - menuBox->infoRects->blitFunc(menuBox->windowId, (menuBox->infoRects->dimensions[16] >> 3) + 1, (menuBox->infoRects->dimensions[17] >> 3) + 1, menuBox->infoRects->dimensions[18] >> 3, menuBox->infoRects->dimensions[19] >> 3, FALSE); - if (c != 2) + if (drawMenuBoxOrText != DRAW_TEXT_ONLY) + menuBox->infoRects->blitFunc(menuBox->windowId, (menuBox->infoRects->dimensions[16] / 8) + 1, (menuBox->infoRects->dimensions[17] / 8) + 1, menuBox->infoRects->dimensions[18] / 8, menuBox->infoRects->dimensions[19] / 8, FALSE); + if (drawMenuBoxOrText != DRAW_MENU_BOX_ONLY) DisplayPartyPokemonMaxHP(GetMonData(mon, MON_DATA_MAX_HP), menuBox); } } @@ -2473,21 +2448,21 @@ static void DisplayPartyPokemonHPBar(u16 hp, u16 maxhp, struct PartyMenuBox *men CopyWindowToVram(menuBox->windowId, COPYWIN_GFX); } -static void DisplayPartyPokemonDescriptionText(u8 stringId, struct PartyMenuBox *menuBox, u8 c) +static void DisplayPartyPokemonDescriptionText(u8 stringId, struct PartyMenuBox *menuBox, u8 drawMenuBoxOrText) { - if (c != 0) - menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->descTextLeft >> 3, menuBox->infoRects->descTextTop >> 3, menuBox->infoRects->descTextWidth >> 3, menuBox->infoRects->descTextHeight >> 3, TRUE); - if (c != 2) + if (drawMenuBoxOrText != DRAW_TEXT_ONLY) + menuBox->infoRects->blitFunc(menuBox->windowId, menuBox->infoRects->descTextLeft / 8, menuBox->infoRects->descTextTop / 8, menuBox->infoRects->descTextWidth / 8, menuBox->infoRects->descTextHeight / 8, TRUE); + if (drawMenuBoxOrText != DRAW_MENU_BOX_ONLY) AddTextPrinterParameterized3(menuBox->windowId, FONT_1, menuBox->infoRects->descTextLeft, menuBox->infoRects->descTextTop, sFontColorTable[0], 0, sDescriptionStringTable[stringId]); } -static void PartyMenuRemoveWindow(u8 *ptr) +static void PartyMenuRemoveWindow(u8 *windowId) { - if (*ptr != 0xFF) + if (*windowId != WINDOW_NONE) { - ClearStdWindowAndFrameToTransparent(*ptr, FALSE); - RemoveWindow(*ptr); - *ptr = 0xFF; + ClearStdWindowAndFrameToTransparent(*windowId, FALSE); + RemoveWindow(*windowId); + *windowId = WINDOW_NONE; ScheduleBgCopyTilemapToVram(2); } } @@ -2496,7 +2471,7 @@ void DisplayPartyMenuStdMessage(u32 stringId) { u8 *windowPtr = &sPartyMenuInternal->windowId[1]; - if (*windowPtr != 0xFF) + if (*windowPtr != WINDOW_NONE) PartyMenuRemoveWindow(windowPtr); if (stringId != PARTY_MSG_NONE) @@ -2523,7 +2498,7 @@ void DisplayPartyMenuStdMessage(u32 stringId) if (stringId == PARTY_MSG_CHOOSE_MON) { - if (sPartyMenuInternal->chooseHalf) + if (sPartyMenuInternal->chooseMultiple) stringId = PARTY_MSG_CHOOSE_MON_AND_CONFIRM; else if (!ShouldUseChooseMonText()) stringId = PARTY_MSG_CHOOSE_MON_OR_CANCEL; @@ -2583,7 +2558,7 @@ static u8 DisplaySelectionWindow(u8 windowType) fontAttribute = GetFontAttribute(FONT_2, FONTATTR_LETTER_SPACING); for (i = 0; i < sPartyMenuInternal->numActions; ++i) { - u8 fontColorsId = (sPartyMenuInternal->actions[i] >= MENU_FIELD_MOVES) ? 4 : 3; + u8 fontColorsId = (sPartyMenuInternal->actions[i] >= CURSOR_OPTION_FIELD_MOVES) ? 4 : 3; AddTextPrinterParameterized4(sPartyMenuInternal->windowId[0], FONT_2, cursorDimension, (i * 16) + 2, fontAttribute, 0, sFontColorTable[fontColorsId], 0, sCursorOptions[sPartyMenuInternal->actions[i]].text); } @@ -2642,28 +2617,28 @@ static void FirstBattleEnterParty_DestroyVoiceoverWindow(u8 windowId) ScheduleBgCopyTilemapToVram(2); } -static void sub_8122138(u8 action) +static void ToggleFieldMoveDescriptionWindow(u8 action) { - u8 attr; + u8 letterSpacing; struct PartyMenuInternal *ptr = sPartyMenuInternal; - if (action <= 17) + if (action < CURSOR_OPTION_FIELD_MOVES) { - if (ptr->windowId[2] != 0xFF) + if (ptr->windowId[2] != WINDOW_NONE) { ClearWindowTilemap(ptr->windowId[2]); RemoveWindow(ptr->windowId[2]); - ptr->windowId[2] = 0xFF; + ptr->windowId[2] = WINDOW_NONE; ScheduleBgCopyTilemapToVram(2); } } else { - if (ptr->windowId[2] == 0xFF) - ptr->windowId[2] = AddWindow(&gUnknown_845A178); + if (ptr->windowId[2] == WINDOW_NONE) + ptr->windowId[2] = AddWindow(&sFieldMoveDescriptionWindowTemplate); sub_8112F18(ptr->windowId[2]); - attr = GetFontAttribute(FONT_2, FONTATTR_LETTER_SPACING); - AddTextPrinterParameterized4(ptr->windowId[2], FONT_2, 3, 6, attr, 0, sFontColorTable[5], 0, sHMDescriptionTable[action - MENU_FIELD_MOVES]); + letterSpacing = GetFontAttribute(FONT_2, FONTATTR_LETTER_SPACING); + AddTextPrinterParameterized4(ptr->windowId[2], FONT_2, 3, 6, letterSpacing, 0, sFontColorTable[5], 0, sFieldMoveDescriptionTable[action - CURSOR_OPTION_FIELD_MOVES]); PutWindowTilemap(ptr->windowId[2]); ScheduleBgCopyTilemapToVram(2); } @@ -2990,7 +2965,7 @@ static void SetPartyMonFieldSelectionActions(struct Pokemon *mons, u8 slotId) u8 i, j; sPartyMenuInternal->numActions = 0; - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, MENU_SUMMARY); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, CURSOR_OPTION_SUMMARY); // Add field moves to action list for (i = 0; i < MAX_MON_MOVES; ++i) { @@ -2998,18 +2973,18 @@ static void SetPartyMonFieldSelectionActions(struct Pokemon *mons, u8 slotId) { if (GetMonData(&mons[slotId], i + MON_DATA_MOVE1) == sFieldMoves[j]) { - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, j + MENU_FIELD_MOVES); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, j + CURSOR_OPTION_FIELD_MOVES); break; } } } if (GetMonData(&mons[1], MON_DATA_SPECIES) != SPECIES_NONE) - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, MENU_SWITCH); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, CURSOR_OPTION_SWITCH); if (ItemIsMail(GetMonData(&mons[slotId], MON_DATA_HELD_ITEM))) - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, MENU_MAIL); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, CURSOR_OPTION_MAIL); else - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, MENU_ITEM); - AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, MENU_CANCEL1); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, CURSOR_OPTION_ITEM); + AppendToList(sPartyMenuInternal->actions, &sPartyMenuInternal->numActions, CURSOR_OPTION_CANCEL1); } static u8 GetPartyMenuActionsType(struct Pokemon *mon) @@ -3027,7 +3002,7 @@ static u8 GetPartyMenuActionsType(struct Pokemon *mon) case PARTY_MENU_TYPE_IN_BATTLE: actionType = GetPartyMenuActionsTypeInBattle(mon); break; - case PARTY_MENU_TYPE_CHOOSE_HALF: + case PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS: switch (GetPartySlotEntryStatus(gPartyMenu.slotId)) { default: // Not eligible @@ -3055,7 +3030,7 @@ static u8 GetPartyMenuActionsType(struct Pokemon *mon) break; // 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_CHOOSE_SINGLE_MON // PARTY_MENU_TYPE_MULTI_SHOWCASE // PARTY_MENU_TYPE_MOVE_RELEARNER // PARTY_MENU_TYPE_MINIGAME @@ -3080,7 +3055,7 @@ static void CreateSelectionWindow(void) static void Task_TryCreateSelectionWindow(u8 taskId) { CreateSelectionWindow(); - gTasks[taskId].data[0] = 0xFF; + gTasks[taskId].data[0] = (u8)MENU_B_PRESSED; gTasks[taskId].func = Task_HandleSelectionMenuInput; } @@ -3095,8 +3070,10 @@ static void Task_HandleSelectionMenuInput(u8 taskId) input = Menu_ProcessInputNoWrapAround_other(); else input = Menu_ProcessInput_other(); + if (data[0] != Menu_GetCursorPos()) - sub_8122138(sPartyMenuInternal->actions[Menu_GetCursorPos()]); + ToggleFieldMoveDescriptionWindow(sPartyMenuInternal->actions[Menu_GetCursorPos()]); + data[0] = Menu_GetCursorPos(); switch (input) { @@ -3431,7 +3408,7 @@ static void CursorCB_Item(u8 taskId) SetPartyMonSelectionActions(gPlayerParty, gPartyMenu.slotId, ACTIONS_ITEM); DisplaySelectionWindow(SELECTWINDOW_ITEM); DisplayPartyMenuStdMessage(PARTY_MSG_DO_WHAT_WITH_ITEM); - gTasks[taskId].data[0] = 0xFF; + gTasks[taskId].data[0] = (u8)MENU_B_PRESSED; gTasks[taskId].func = Task_HandleSelectionMenuInput; } @@ -3644,7 +3621,7 @@ static void CursorCB_Mail(u8 taskId) SetPartyMonSelectionActions(gPlayerParty, gPartyMenu.slotId, ACTIONS_MAIL); DisplaySelectionWindow(SELECTWINDOW_MAIL); DisplayPartyMenuStdMessage(PARTY_MSG_DO_WHAT_WITH_MAIL); - gTasks[taskId].data[0] = 0xFF; + gTasks[taskId].data[0] = (u8)MENU_B_PRESSED; gTasks[taskId].func = Task_HandleSelectionMenuInput; } @@ -3759,7 +3736,7 @@ static void CursorCB_Cancel2(u8 taskId) SetPartyMonSelectionActions(gPlayerParty, gPartyMenu.slotId, GetPartyMenuActionsType(mon)); DisplaySelectionWindow(SELECTWINDOW_ACTIONS); DisplayPartyMenuStdMessage(PARTY_MSG_DO_WHAT_WITH_MON); - gTasks[taskId].data[0] = 0xFF; + gTasks[taskId].data[0] = (u8)MENU_B_PRESSED; gTasks[taskId].func = Task_HandleSelectionMenuInput; } @@ -3786,7 +3763,7 @@ static void CursorCB_Enter(u8 taskId) u8 i; const u8 *str; - if (gPartyMenu.unk_8_6 == 2) + if (gPartyMenu.chooseMonsBattleType == CHOOSE_MONS_FOR_UNION_ROOM_BATTLE) { maxBattlers = 2; str = gText_NoMoreThanTwoMayEnter; @@ -3820,7 +3797,7 @@ static void CursorCB_Enter(u8 taskId) static void MoveCursorToConfirm(void) { AnimatePartySlot(gPartyMenu.slotId, 0); - gPartyMenu.slotId = PARTY_SIZE; + gPartyMenu.slotId = SLOT_CONFIRM; AnimatePartySlot(gPartyMenu.slotId, 1); } @@ -3851,11 +3828,11 @@ static void CursorCB_NoEntry(u8 taskId) break; } } - DisplayPartyPokemonDescriptionText(PARTYBOX_DESC_ABLE_3, &sPartyMenuBoxes[gPartyMenu.slotId], 1); + DisplayPartyPokemonDescriptionText(PARTYBOX_DESC_ABLE_3, &sPartyMenuBoxes[gPartyMenu.slotId], DRAW_MENU_BOX_AND_TEXT); if (gSelectedOrderFromParty[0] != 0) - DisplayPartyPokemonDescriptionText(PARTYBOX_DESC_FIRST, &sPartyMenuBoxes[gSelectedOrderFromParty[0] - 1], 1); + DisplayPartyPokemonDescriptionText(PARTYBOX_DESC_FIRST, &sPartyMenuBoxes[gSelectedOrderFromParty[0] - 1], DRAW_MENU_BOX_AND_TEXT); if (gSelectedOrderFromParty[1] != 0) - DisplayPartyPokemonDescriptionText(1 + PARTYBOX_DESC_FIRST, &sPartyMenuBoxes[gSelectedOrderFromParty[1] - 1], 1); + DisplayPartyPokemonDescriptionText(PARTYBOX_DESC_SECOND, &sPartyMenuBoxes[gSelectedOrderFromParty[1] - 1], DRAW_MENU_BOX_AND_TEXT); DisplayPartyMenuStdMessage(PARTY_MSG_CHOOSE_MON); gTasks[taskId].func = Task_HandleChooseMonInput; } @@ -3927,7 +3904,7 @@ static void CursorCB_Trade2(u8 taskId) static void CursorCB_FieldMove(u8 taskId) { - u8 fieldMove = sPartyMenuInternal->actions[Menu_GetCursorPos()] - MENU_FIELD_MOVES; + u8 fieldMove = sPartyMenuInternal->actions[Menu_GetCursorPos()] - CURSOR_OPTION_FIELD_MOVES; const struct MapHeader *mapHeader; PlaySE(SE_SELECT); @@ -4023,7 +4000,7 @@ static void Task_HandleFieldMoveExitAreaYesNoInput(u8 taskId) { switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes gPartyMenu.exitCallback = CB2_ReturnToField; SetUsedFieldMoveQuestLogEvent(&gPlayerParty[GetCursorSelectionMonId()], sPartyMenuInternal->data[0]); Task_ClosePartyMenu(taskId); @@ -4031,7 +4008,7 @@ static void Task_HandleFieldMoveExitAreaYesNoInput(u8 taskId) case MENU_B_PRESSED: PlaySE(SE_SELECT); // fallthrough - case 1: + case 1: // No gFieldCallback2 = NULL; gPostMenuFieldCallback = NULL; Task_ReturnToChooseMonAfterText(taskId); @@ -4289,31 +4266,28 @@ static void CB2_ReturnToBerryPouchMenu(void) InitBerryPouch(BERRYPOUCH_NA, NULL, 0xFF); } -static void sub_8124DC0(u8 taskId) +static void Task_DoUseItemAnim(u8 taskId) { - sPartyMenuInternal->exitCallback = sub_8124DE0; + sPartyMenuInternal->exitCallback = CB2_DoUseItemAnim; Task_ClosePartyMenu(taskId); } -static void sub_8124DE0(void) +static void CB2_DoUseItemAnim(void) { if (CheckIfItemIsTMHMOrEvolutionStone(gSpecialVar_ItemId) == 2) // Evolution stone { if (MonCanEvolve() == TRUE) - StartUseItemAnim_Normal(gPartyMenu.slotId, gSpecialVar_ItemId, sub_8126BD4); + StartUseItemAnim_Normal(gPartyMenu.slotId, gSpecialVar_ItemId, CB2_UseEvolutionStone); else StartUseItemAnim_CantEvolve(gPartyMenu.slotId, gSpecialVar_ItemId, gPartyMenu.exitCallback); } else - { - StartUseItemAnim_Normal(gPartyMenu.slotId, gSpecialVar_ItemId, sub_8124E48); - } + StartUseItemAnim_Normal(gPartyMenu.slotId, gSpecialVar_ItemId, CB2_UseItem); } -static void sub_8124E48(void) +static void CB2_UseItem(void) { - if (ItemId_GetPocket(gSpecialVar_ItemId) == POCKET_TM_CASE - && PSA_IsCancelDisabled() == TRUE) + if (ItemId_GetPocket(gSpecialVar_ItemId) == POCKET_TM_CASE && PSA_IsCancelDisabled() == TRUE) { GiveMoveToMon(&gPlayerParty[gPartyMenu.slotId], ItemIdToBattleMoveId(gSpecialVar_ItemId)); AdjustFriendship(&gPlayerParty[gPartyMenu.slotId], FRIENDSHIP_EVENT_LEARN_TMHM); @@ -4322,12 +4296,10 @@ static void sub_8124E48(void) SetMainCallback2(gPartyMenu.exitCallback); } else - { InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, PARTY_ACTION_CHOOSE_MON, gPartyMenu.slotId, PARTY_MSG_NONE, Task_SetSacredAshCB, gPartyMenu.exitCallback); - } } -static void sub_8124EFC(void) +static void CB2_UseTMHMAfterForgettingMove(void) { if (PSA_IsCancelDisabled() == TRUE) { @@ -4344,9 +4316,7 @@ static void sub_8124EFC(void) SetMainCallback2(gPartyMenu.exitCallback); } else - { InitPartyMenu(gPartyMenu.menuType, KEEP_PARTY_LAYOUT, gPartyMenu.action, gPartyMenu.slotId, PARTY_MSG_NONE, Task_SetSacredAshCB, gPartyMenu.exitCallback); - } } static void Task_SetSacredAshCB(u8 taskId) @@ -4492,7 +4462,7 @@ void ItemUseCB_Medicine(u8 taskId, TaskFunc func) else { ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, mon, item, 0xFFFF); - sub_8124DC0(taskId); + Task_DoUseItemAnim(taskId); gItemUseCB = ItemUseCB_MedicineStep; } } @@ -4503,8 +4473,11 @@ void ItemUseCB_MedicineStep(u8 taskId, TaskFunc func) struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; u16 item = gSpecialVar_ItemId; bool8 canHeal; + bool8 cannotHeal; - if (NotUsingHPEVItemOnShedinja(mon, item)) + if (NotUsingHPEVItemOnShedinja(mon, item) == FALSE) + cannotHeal = TRUE; + else { canHeal = IsHPRecoveryItem(item); if (canHeal == TRUE) @@ -4513,51 +4486,49 @@ void ItemUseCB_MedicineStep(u8 taskId, TaskFunc func) if (hp == GetMonData(mon, MON_DATA_MAX_HP)) canHeal = FALSE; } - if (ExecuteTableBasedItemEffect_(gPartyMenu.slotId, item, 0)) - { - WONT_HAVE_EFFECT: - gPartyMenuUseExitCallback = FALSE; - PlaySE(SE_SELECT); - DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); - ScheduleBgCopyTilemapToVram(2); - gTasks[taskId].func = func; - return; - } + + cannotHeal = ExecuteTableBasedItemEffect_(gPartyMenu.slotId, item, 0); } - else + + if (cannotHeal != FALSE) { - goto WONT_HAVE_EFFECT; // even loop wrap won't work - } - gPartyMenuUseExitCallback = TRUE; - if (!IsItemFlute(item)) - { - PlaySE(SE_USE_ITEM); - if (gPartyMenu.action != PARTY_ACTION_REUSABLE_ITEM) - RemoveBagItem(item, 1); - } - else - { - PlaySE(SE_GLASS_FLUTE); - } - SetPartyMonAilmentGfx(mon, &sPartyMenuBoxes[gPartyMenu.slotId]); - if (gSprites[sPartyMenuBoxes[gPartyMenu.slotId].statusSpriteId].invisible) - DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[gPartyMenu.slotId], 1); - if (canHeal == TRUE) - { - if (hp == 0) - AnimatePartySlot(gPartyMenu.slotId, 1); - PartyMenuModifyHP(taskId, gPartyMenu.slotId, 1, GetMonData(mon, MON_DATA_HP) - hp, Task_DisplayHPRestoredMessage); - ResetHPTaskData(taskId, 0, hp); - return; - } - else - { - GetMonNickname(mon, gStringVar1); - GetMedicineItemEffectMessage(item); - DisplayPartyMenuMessage(gStringVar4, TRUE); + gPartyMenuUseExitCallback = FALSE; + PlaySE(SE_SELECT); + DisplayPartyMenuMessage(gText_WontHaveEffect, TRUE); ScheduleBgCopyTilemapToVram(2); gTasks[taskId].func = func; } + else + { + gPartyMenuUseExitCallback = TRUE; + if (!IsItemFlute(item)) + { + PlaySE(SE_USE_ITEM); + if (gPartyMenu.action != PARTY_ACTION_REUSABLE_ITEM) + RemoveBagItem(item, 1); + } + else + PlaySE(SE_GLASS_FLUTE); + + SetPartyMonAilmentGfx(mon, &sPartyMenuBoxes[gPartyMenu.slotId]); + if (gSprites[sPartyMenuBoxes[gPartyMenu.slotId].statusSpriteId].invisible) + DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[gPartyMenu.slotId], 1); + if (canHeal == TRUE) + { + if (hp == 0) + AnimatePartySlot(gPartyMenu.slotId, 1); + PartyMenuModifyHP(taskId, gPartyMenu.slotId, 1, GetMonData(mon, MON_DATA_HP) - hp, Task_DisplayHPRestoredMessage); + ResetHPTaskData(taskId, 0, hp); + } + else + { + GetMonNickname(mon, gStringVar1); + GetMedicineItemEffectMessage(item); + DisplayPartyMenuMessage(gStringVar4, TRUE); + ScheduleBgCopyTilemapToVram(2); + gTasks[taskId].func = func; + } + } } static void Task_DisplayHPRestoredMessage(u8 taskId) @@ -4605,7 +4576,7 @@ static void ShowMoveSelectWindow(u8 slot) ScheduleBgCopyTilemapToVram(2); } -static void Task_HandleWhichMoveInput(u8 taskId) +static void Task_HandleRestoreWhichMoveInput(u8 taskId) { s8 input = Menu_ProcessInput(); @@ -4617,13 +4588,13 @@ static void Task_HandleWhichMoveInput(u8 taskId) ReturnToUseOnWhichMon(taskId); } else - { SetSelectedMoveForPPItem(taskId); - } } } -void ItemUseCB_PPRecovery(u8 taskId, TaskFunc func) +#define ppMoveSlot data[0] + +void ItemUseCB_TryRestorePP(u8 taskId, TaskFunc func) { const u8 *effect; u16 item = gSpecialVar_ItemId; @@ -4635,29 +4606,29 @@ void ItemUseCB_PPRecovery(u8 taskId, TaskFunc func) if (!(effect[4] & ITEM4_HEAL_PP_ONE)) { - gPartyMenu.data1 = 0; + gPartyMenu.ppMoveSlot = 0; if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_BATTLE) - TryUsePPItem(taskId); + TryUsePPItemInBattle(taskId); else - sub_812580C(taskId); + TryUsePPItemOutsideBattle(taskId); } else { PlaySE(SE_SELECT); DisplayPartyMenuStdMessage(PARTY_MSG_RESTORE_WHICH_MOVE); ShowMoveSelectWindow(gPartyMenu.slotId); - gTasks[taskId].func = Task_HandleWhichMoveInput; + gTasks[taskId].func = Task_HandleRestoreWhichMoveInput; } } static void SetSelectedMoveForPPItem(u8 taskId) { PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[0]); - gPartyMenu.data1 = Menu_GetCursorPos(); + gPartyMenu.ppMoveSlot = Menu_GetCursorPos(); if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_BATTLE) - TryUsePPItem(taskId); + TryUsePPItemInBattle(taskId); else - sub_812580C(taskId); + TryUsePPItemOutsideBattle(taskId); } static void ReturnToUseOnWhichMon(u8 taskId) @@ -4668,12 +4639,12 @@ static void ReturnToUseOnWhichMon(u8 taskId) DisplayPartyMenuStdMessage(PARTY_MSG_USE_ON_WHICH_MON); } -static void sub_812580C(u8 taskId) +static void TryUsePPItemOutsideBattle(u8 taskId) { bool8 noEffect = PokemonItemUseNoEffect(&gPlayerParty[gPartyMenu.slotId], gSpecialVar_ItemId, gPartyMenu.slotId, - gPartyMenu.data1); + gPartyMenu.ppMoveSlot); PlaySE(SE_SELECT); if (noEffect) { @@ -4684,22 +4655,22 @@ static void sub_812580C(u8 taskId) } else { - sub_8124DC0(taskId); - gItemUseCB = sub_8125898; + Task_DoUseItemAnim(taskId); + gItemUseCB = ItemUseCB_RestorePP; } } -static void sub_8125898(u8 taskId, TaskFunc func) +static void ItemUseCB_RestorePP(u8 taskId, TaskFunc func) { u16 move; struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - ExecuteTableBasedItemEffect_(gPartyMenu.slotId, gSpecialVar_ItemId, (u8)gPartyMenu.data1); + ExecuteTableBasedItemEffect_(gPartyMenu.slotId, gSpecialVar_ItemId, (u8)gPartyMenu.ppMoveSlot); gPartyMenuUseExitCallback = TRUE; ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, mon, gSpecialVar_ItemId, 0xFFFF); PlaySE(SE_USE_ITEM); RemoveBagItem(gSpecialVar_ItemId, 1); - move = GetMonData(mon, gPartyMenu.data1 + MON_DATA_MOVE1); + move = GetMonData(mon, gPartyMenu.ppMoveSlot + MON_DATA_MOVE1); StringCopy(gStringVar1, gMoveNames[move]); GetMedicineItemEffectMessage(gSpecialVar_ItemId); DisplayPartyMenuMessage(gStringVar4, 1); @@ -4707,10 +4678,10 @@ static void sub_8125898(u8 taskId, TaskFunc func) gTasks[taskId].func = Task_ClosePartyMenuAfterText; } -static void TryUsePPItem(u8 taskId) +static void TryUsePPItemInBattle(u8 taskId) { u16 move = MOVE_NONE; - s16 *moveSlot = &gPartyMenu.data1; + s16 *moveSlot = &gPartyMenu.ppMoveSlot; u16 item = gSpecialVar_ItemId; struct PartyMenu *ptr = &gPartyMenu; struct Pokemon *mon; @@ -4739,12 +4710,14 @@ static void TryUsePPItem(u8 taskId) } } +#undef ppMoveSlot + void ItemUseCB_PPUp(u8 taskId, TaskFunc func) { PlaySE(SE_SELECT); DisplayPartyMenuStdMessage(PARTY_MSG_BOOST_PP_WHICH_MOVE); ShowMoveSelectWindow(gPartyMenu.slotId); - gTasks[taskId].func = Task_HandleWhichMoveInput; + gTasks[taskId].func = Task_HandleRestoreWhichMoveInput; } u16 ItemIdToBattleMoveId(u16 item) @@ -4789,20 +4762,23 @@ static void DisplayLearnMoveMessageAndClose(u8 taskId, const u8 *str) gTasks[taskId].func = Task_ClosePartyMenuAfterText; } +#define learnMoveId data[0] +#define learnMoveMethod data[1] + void ItemUseCB_TMHM(u8 taskId, TaskFunc func) { struct Pokemon *mon; - s16 *move; + s16 *data; u16 item; PlaySE(SE_SELECT); mon = &gPlayerParty[gPartyMenu.slotId]; - move = &gPartyMenu.data1; + data = gPartyMenu.data; item = gSpecialVar_ItemId; GetMonNickname(mon, gStringVar1); - move[0] = ItemIdToBattleMoveId(item); - StringCopy(gStringVar2, gMoveNames[move[0]]); - move[1] = 0; + learnMoveId = ItemIdToBattleMoveId(item); + StringCopy(gStringVar2, gMoveNames[learnMoveId]); + learnMoveMethod = LEARN_VIA_TMHM; switch (CanMonLearnTMTutor(mon, item, 0)) { case CANNOT_LEARN_MOVE: @@ -4812,10 +4788,10 @@ void ItemUseCB_TMHM(u8 taskId, TaskFunc func) DisplayLearnMoveMessageAndClose(taskId, gText_PkmnAlreadyKnows); return; } - if (GiveMoveToMon(mon, move[0]) != MON_HAS_MAX_MOVES) + if (GiveMoveToMon(mon, learnMoveId) != MON_HAS_MAX_MOVES) { ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, mon, item, 0xFFFF); - sub_8124DC0(taskId); + Task_DoUseItemAnim(taskId); gItemUseCB = ItemUseCB_LearnedMove; } else @@ -4833,17 +4809,17 @@ static void ItemUseCB_LearnedMove(u8 taskId, TaskFunc func) static void Task_LearnedMove(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - s16 *move = &gPartyMenu.data1; + s16 *data = gPartyMenu.data; u16 item = gSpecialVar_ItemId; - if (move[1] == 0) + if (learnMoveMethod == LEARN_VIA_TMHM) { AdjustFriendship(mon, FRIENDSHIP_EVENT_LEARN_TMHM); - if (item < ITEM_HM01_CUT) + if (item <= ITEM_TM50) RemoveBagItem(item, 1); } GetMonNickname(mon, gStringVar1); - StringCopy(gStringVar2, gMoveNames[move[0]]); + StringCopy(gStringVar2, gMoveNames[learnMoveId]); StringExpandPlaceholders(gStringVar4, gText_PkmnLearnedMove3); DisplayPartyMenuMessage(gStringVar4, TRUE); ScheduleBgCopyTilemapToVram(2); @@ -4863,11 +4839,11 @@ static void Task_LearnNextMoveOrClosePartyMenu(u8 taskId) { if (IsFanfareTaskInactive() && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { - if (gPartyMenu.learnMoveState == 1) + if (gPartyMenu.learnMoveMethod == LEARN_VIA_LEVEL_UP) Task_TryLearningNextMove(taskId); else { - if (gPartyMenu.learnMoveState == 2) // never occurs + if (gPartyMenu.learnMoveMethod == LEARN_VIA_TUTOR) gSpecialVar_Result = TRUE; Task_ClosePartyMenu(taskId); } @@ -4887,14 +4863,14 @@ static void Task_HandleReplaceMoveYesNoInput(u8 taskId) { switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes DisplayPartyMenuMessage(gText_WhichMoveToForget, TRUE); gTasks[taskId].func = Task_ShowSummaryScreenToForgetMove; break; case MENU_B_PRESSED: PlaySE(SE_SELECT); // fallthrough - case 1: + case 1: // No StopLearningMovePrompt(taskId); break; } @@ -4911,26 +4887,24 @@ static void Task_ShowSummaryScreenToForgetMove(u8 taskId) static void CB2_ShowSummaryScreenToForgetMove(void) { - ShowSelectMovePokemonSummaryScreen(gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuWhileLearningMove, gPartyMenu.data1); + ShowSelectMovePokemonSummaryScreen(gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuWhileLearningMove, gPartyMenu.learnMoveId); } static void CB2_ReturnToPartyMenuWhileLearningMove(void) { u8 moveIdx = GetMoveSlotToReplace(); u16 move; - s32 learnMoveState = gPartyMenu.learnMoveState; + s32 learnMethod = gPartyMenu.learnMoveMethod; - if (learnMoveState == 0 && moveIdx != MAX_MON_MOVES) + if (learnMethod == LEARN_VIA_TMHM && moveIdx != MAX_MON_MOVES) { move = GetMonData(&gPlayerParty[gPartyMenu.slotId], moveIdx + MON_DATA_MOVE1); - StartUseItemAnim_ForgetMoveAndLearnTMorHM(gPartyMenu.slotId, gSpecialVar_ItemId, move, sub_8124EFC); - gItemUseCB = sub_8125F4C; - gPartyMenu.action = learnMoveState; + StartUseItemAnim_ForgetMoveAndLearnTMorHM(gPartyMenu.slotId, gSpecialVar_ItemId, move, CB2_UseTMHMAfterForgettingMove); + gItemUseCB = ItemUseCB_ReplaceMoveWithTMHM; + gPartyMenu.action = PARTY_ACTION_CHOOSE_MON; } else - { InitPartyMenu(PARTY_MENU_TYPE_FIELD, PARTY_LAYOUT_SINGLE, PARTY_ACTION_CHOOSE_MON, TRUE, PARTY_MSG_NONE, Task_ReturnToPartyMenuWhileLearningMove, gPartyMenu.exitCallback); - } } static void Task_ReturnToPartyMenuWhileLearningMove(u8 taskId) @@ -4944,12 +4918,12 @@ static void Task_ReturnToPartyMenuWhileLearningMove(u8 taskId) } } -static void sub_8125F4C(u8 taskId, TaskFunc func) +static void ItemUseCB_ReplaceMoveWithTMHM(u8 taskId, TaskFunc func) { - sub_8125F5C(taskId); + Task_ReplaceMoveWithTMHM(taskId); } -static void sub_8125F5C(u8 taskId) +static void Task_ReplaceMoveWithTMHM(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; u8 moveIdx = GetMoveSlotToReplace(); @@ -4959,7 +4933,7 @@ static void sub_8125F5C(u8 taskId) GetMonNickname(mon, gStringVar1); StringCopy(gStringVar2, gMoveNames[move]); RemoveMonPPBonus(mon, moveIdx); - SetMonMoveSlot(mon, gPartyMenu.data1, moveIdx); + SetMonMoveSlot(mon, gPartyMenu.learnMoveId, moveIdx); Task_LearnedMove(taskId); } @@ -4983,7 +4957,7 @@ static void Task_PartyMenuReplaceMove(u8 taskId) { mon = &gPlayerParty[gPartyMenu.slotId]; RemoveMonPPBonus(mon, GetMoveSlotToReplace()); - move = gPartyMenu.data1; + move = gPartyMenu.learnMoveId; SetMonMoveSlot(mon, move, GetMoveSlotToReplace()); Task_LearnedMove(taskId); } @@ -4991,7 +4965,7 @@ static void Task_PartyMenuReplaceMove(u8 taskId) static void StopLearningMovePrompt(u8 taskId) { - StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.learnMoveId]); StringExpandPlaceholders(gStringVar4, gText_StopLearningMove2); DisplayPartyMenuMessage(gStringVar4, TRUE); ScheduleBgCopyTilemapToVram(2); @@ -5013,18 +4987,18 @@ static void Task_HandleStopLearningMoveYesNoInput(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: + case 0: // Yes GetMonNickname(mon, gStringVar1); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.learnMoveId]); StringExpandPlaceholders(gStringVar4, gText_MoveNotLearned); DisplayPartyMenuMessage(gStringVar4, TRUE); - if (gPartyMenu.learnMoveState == 1) + if (gPartyMenu.learnMoveMethod == LEARN_VIA_LEVEL_UP) { gTasks[taskId].func = Task_TryLearningNextMoveAfterText; } else { - if (gPartyMenu.learnMoveState == 2) // never occurs + if (gPartyMenu.learnMoveMethod == LEARN_VIA_TUTOR) gSpecialVar_Result = FALSE; gTasks[taskId].func = Task_ClosePartyMenuAfterText; } @@ -5032,9 +5006,9 @@ static void Task_HandleStopLearningMoveYesNoInput(u8 taskId) case MENU_B_PRESSED: PlaySE(SE_SELECT); // fallthrough - case 1: + case 1: // No GetMonNickname(mon, gStringVar1); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.learnMoveId]); DisplayLearnMoveMessage(gText_PkmnNeedsToReplaceMove); gTasks[taskId].func = Task_ReplaceMoveYesNo; break; @@ -5067,7 +5041,7 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc func) } else { - sub_8124DC0(taskId); + Task_DoUseItemAnim(taskId); gItemUseCB = ItemUseCB_RareCandyStep; } } @@ -5100,9 +5074,9 @@ static void UpdateMonDisplayInfoAfterRareCandy(u8 slot, struct Pokemon *mon) { SetPartyMonAilmentGfx(mon, &sPartyMenuBoxes[slot]); if (gSprites[sPartyMenuBoxes[slot].statusSpriteId].invisible) - DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[slot], 1); - DisplayPartyPokemonHPCheck(mon, &sPartyMenuBoxes[slot], 1); - DisplayPartyPokemonMaxHPCheck(mon, &sPartyMenuBoxes[slot], 1); + DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[slot], DRAW_MENU_BOX_AND_TEXT); + DisplayPartyPokemonHPCheck(mon, &sPartyMenuBoxes[slot], DRAW_MENU_BOX_AND_TEXT); + DisplayPartyPokemonMaxHPCheck(mon, &sPartyMenuBoxes[slot], DRAW_MENU_BOX_AND_TEXT); DisplayPartyPokemonHPBarCheck(mon, &sPartyMenuBoxes[slot]); UpdatePartyMonHPBar(sPartyMenuBoxes[slot].monSpriteId, mon); AnimatePartySlot(slot, 1); @@ -5152,14 +5126,14 @@ static void Task_TryLearnNewMoves(u8 taskId) { u16 learnMove; - if (WaitFanfare(0) && (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON))) + if (WaitFanfare(FALSE) && (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON))) { RemoveLevelUpStatsWindow(); learnMove = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], TRUE); - gPartyMenu.learnMoveState = 1; + gPartyMenu.learnMoveMethod = LEARN_VIA_LEVEL_UP; switch (learnMove) { - case 0: // No moves to learn + case MOVE_NONE: // No moves to learn PartyMenuTryEvolution(taskId); break; case MON_HAS_MAX_MOVES: @@ -5181,7 +5155,7 @@ static void Task_TryLearningNextMove(u8 taskId) switch (result) { - case 0: // No moves to learn + case MOVE_NONE: // No moves to learn PartyMenuTryEvolution(taskId); break; case MON_HAS_MAX_MOVES: @@ -5198,19 +5172,17 @@ static void Task_TryLearningNextMove(u8 taskId) static void PartyMenuTryEvolution(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, 0); + u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE); if (targetSpecies != SPECIES_NONE) { FreePartyPointers(); gCB2_AfterEvolution = gPartyMenu.exitCallback; - BeginEvolutionScene(mon, targetSpecies, 1, gPartyMenu.slotId); + BeginEvolutionScene(mon, targetSpecies, TRUE, gPartyMenu.slotId); DestroyTask(taskId); } else - { gTasks[taskId].func = Task_ClosePartyMenuAfterText; - } } static void DisplayMonNeedsToReplaceMove(u8 taskId) @@ -5220,7 +5192,7 @@ static void DisplayMonNeedsToReplaceMove(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_PkmnNeedsToReplaceMove); DisplayPartyMenuMessage(gStringVar4, TRUE); ScheduleBgCopyTilemapToVram(2); - gPartyMenu.data1 = gMoveToLearn; + gPartyMenu.learnMoveId = gMoveToLearn; gTasks[taskId].func = Task_ReplaceMoveYesNo; } @@ -5231,7 +5203,7 @@ static void DisplayMonLearnedMove(u8 taskId, u16 move) StringExpandPlaceholders(gStringVar4, gText_PkmnLearnedMove3); DisplayPartyMenuMessage(gStringVar4, TRUE); ScheduleBgCopyTilemapToVram(2); - gPartyMenu.data1 = move; + gPartyMenu.learnMoveId = move; gTasks[taskId].func = Task_DoLearnedMoveFanfareAfterText; } @@ -5268,7 +5240,7 @@ static void UseSacredAsh(u8 taskId) sSacredAshQuestLogMonBackup = mon; SetPartyMonAilmentGfx(mon, &sPartyMenuBoxes[gPartyMenu.slotId]); if (gSprites[sPartyMenuBoxes[gPartyMenu.slotId].statusSpriteId].invisible) - DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[gPartyMenu.slotId], 1); + DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[gPartyMenu.slotId], DRAW_MENU_BOX_AND_TEXT); AnimatePartySlot(sPartyMenuInternal->tLastSlotUsed, 0); AnimatePartySlot(gPartyMenu.slotId, 1); PartyMenuModifyHP(taskId, gPartyMenu.slotId, 1, GetMonData(mon, MON_DATA_HP) - hp, Task_SacredAshDisplayHPRestored); @@ -5338,12 +5310,10 @@ void ItemUseCB_EvolutionStone(u8 taskId, TaskFunc func) gTasks[taskId].func = func; } else - { - sub_8124DC0(taskId); - } + Task_DoUseItemAnim(taskId); } -static void sub_8126BD4(void) +static void CB2_UseEvolutionStone(void) { gCB2_AfterEvolution = gPartyMenu.exitCallback; ExecuteTableBasedItemEffect_(gPartyMenu.slotId, gSpecialVar_ItemId, 0); @@ -5427,16 +5397,16 @@ u8 GetItemEffectType(u16 item) static void TryTutorSelectedMon(u8 taskId) { struct Pokemon *mon; - s16 *move; + s16 *data; if (!gPaletteFade.active) { mon = &gPlayerParty[gPartyMenu.slotId]; - move = &gPartyMenu.data1; + data = gPartyMenu.data; GetMonNickname(mon, gStringVar1); - gPartyMenu.data1 = GetTutorMove(gSpecialVar_0x8005); - StringCopy(gStringVar2, gMoveNames[gPartyMenu.data1]); - move[1] = 2; + gPartyMenu.learnMoveId = GetTutorMove(gSpecialVar_0x8005); + StringCopy(gStringVar2, gMoveNames[gPartyMenu.learnMoveId]); + learnMoveMethod = LEARN_VIA_TUTOR; switch (CanMonLearnTMTutor(mon, 0, gSpecialVar_0x8005)) { case CANNOT_LEARN_MOVE: @@ -5446,7 +5416,7 @@ static void TryTutorSelectedMon(u8 taskId) DisplayLearnMoveMessageAndClose(taskId, gText_PkmnAlreadyKnows); return; default: - if (GiveMoveToMon(mon, gPartyMenu.data1) != MON_HAS_MAX_MOVES) + if (GiveMoveToMon(mon, gPartyMenu.learnMoveId) != MON_HAS_MAX_MOVES) { Task_LearnedMove(taskId); return; @@ -5458,6 +5428,9 @@ static void TryTutorSelectedMon(u8 taskId) } } +#undef learnMoveId +#undef learnMoveMethod + void CB2_PartyMenuFromStartMenu(void) { InitPartyMenu(PARTY_MENU_TYPE_FIELD, PARTY_LAYOUT_SINGLE, PARTY_ACTION_CHOOSE_MON, FALSE, PARTY_MSG_CHOOSE_MON, Task_HandleChooseMonInput, CB2_ReturnToFieldWithOpenMenu); @@ -5681,12 +5654,12 @@ static void TryGiveMailToSelectedMon(u8 taskId) gTasks[taskId].func = Task_UpdateHeldItemSpriteAndClosePartyMenu; } -void InitChooseHalfPartyForBattle(u8 a1) +void InitChooseMonsForBattle(u8 chooseMonsBattleType) { ClearSelectedPartyOrder(); - InitPartyMenu(PARTY_MENU_TYPE_CHOOSE_HALF, PARTY_LAYOUT_SINGLE, PARTY_ACTION_CHOOSE_MON, FALSE, PARTY_MSG_CHOOSE_MON, Task_HandleChooseMonInput, gMain.savedCallback); - gPartyMenu.unk_8_6 = a1; - gPartyMenu.task = Task_ValidateChosenHalfParty; + InitPartyMenu(PARTY_MENU_TYPE_CHOOSE_MULTIPLE_MONS, PARTY_LAYOUT_SINGLE, PARTY_ACTION_CHOOSE_MON, FALSE, PARTY_MSG_CHOOSE_MON, Task_HandleChooseMonInput, gMain.savedCallback); + gPartyMenu.chooseMonsBattleType = chooseMonsBattleType; + gPartyMenu.task = Task_ValidateChosenMonsForBattle; } void ClearSelectedPartyOrder(void) @@ -5697,10 +5670,11 @@ void ClearSelectedPartyOrder(void) static u8 GetPartySlotEntryStatus(s8 slot) { if (GetBattleEntryEligibility(&gPlayerParty[slot]) == FALSE) - return 2; - if (HasPartySlotAlreadyBeenSelected(slot + 1) == TRUE) - return 1; - return 0; + return 2; // Not eligible + else if (HasPartySlotAlreadyBeenSelected(slot + 1) == TRUE) + return 1; // Already selected + else + return 0; // Eligible, not selected } static bool8 GetBattleEntryEligibility(struct Pokemon *mon) @@ -5710,17 +5684,17 @@ static bool8 GetBattleEntryEligibility(struct Pokemon *mon) if (GetMonData(mon, MON_DATA_IS_EGG)) return FALSE; - switch (gPartyMenu.unk_8_6) + switch (gPartyMenu.chooseMonsBattleType) { default: if (GetMonData(mon, MON_DATA_LEVEL) > 30) return FALSE; break; - case 0: + case CHOOSE_MONS_FOR_CABLE_CLUB_BATTLE: if (GetMonData(mon, MON_DATA_HP) == 0) return FALSE; break; - case 1: + case CHOOSE_MONS_FOR_BATTLE_TOWER: if (gSaveBlock2Ptr->battleTower.battleTowerLevelType == 0 // level 50 && GetMonData(mon, MON_DATA_LEVEL) > 50) return FALSE; @@ -5739,9 +5713,9 @@ static u8 CheckBattleEntriesAndGetMessage(void) struct Pokemon *party = gPlayerParty; u8 *order = gSelectedOrderFromParty; - switch (gPartyMenu.unk_8_6) + switch (gPartyMenu.chooseMonsBattleType) { - case 1: + case CHOOSE_MONS_FOR_BATTLE_TOWER: if (order[2] == 0) return PARTY_MSG_THREE_MONS_ARE_NEEDED; for (i = 0; i < 2; ++i) @@ -5757,7 +5731,7 @@ static u8 CheckBattleEntriesAndGetMessage(void) } } break; - case 2: + case CHOOSE_MONS_FOR_UNION_ROOM_BATTLE: if (order[1] == 0) return PARTY_MSG_TWO_MONS_ARE_NEEDED; break; @@ -5775,7 +5749,7 @@ static bool8 HasPartySlotAlreadyBeenSelected(u8 slot) return FALSE; } -static void Task_ValidateChosenHalfParty(u8 taskId) +static void Task_ValidateChosenMonsForBattle(u8 taskId) { u8 msgId = CheckBattleEntriesAndGetMessage(); @@ -5783,7 +5757,7 @@ static void Task_ValidateChosenHalfParty(u8 taskId) { PlaySE(SE_FAILURE); DisplayPartyMenuStdMessage(msgId); - gTasks[taskId].func = Task_ContinueChoosingHalfParty; + gTasks[taskId].func = Task_ContinueChoosingMonsForBattle; } else { @@ -5796,12 +5770,12 @@ static void Task_ValidateChosenHalfParty(u8 taskId) { PlaySE(SE_FAILURE); DisplayPartyMenuStdMessage(PARTY_MSG_NO_MON_FOR_BATTLE); - gTasks[taskId].func = Task_ContinueChoosingHalfParty; + gTasks[taskId].func = Task_ContinueChoosingMonsForBattle; } } } -static void Task_ContinueChoosingHalfParty(u8 taskId) +static void Task_ContinueChoosingMonsForBattle(u8 taskId) { if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) { diff --git a/src/party_menu_specials.c b/src/party_menu_specials.c index 23934773c..9b17a73ed 100644 --- a/src/party_menu_specials.c +++ b/src/party_menu_specials.c @@ -17,7 +17,7 @@ void ChoosePartyMon(void) LockPlayerFieldControls(); taskId = CreateTask(sub_80BF97C, 10); - gTasks[taskId].data[0] = PARTY_MENU_TYPE_CHOOSE_MON; + gTasks[taskId].data[0] = PARTY_MENU_TYPE_CHOOSE_SINGLE_MON; BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); } diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index 561621c1f..4bd5c9f22 100644 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -153,7 +153,7 @@ void ChooseHalfPartyForBattle(void) { gMain.savedCallback = CB2_ReturnFromChooseHalfParty; // VarSet(VAR_FRONTIER_FACILITY, FACILITY_MULTI_OR_EREADER); - InitChooseHalfPartyForBattle(0); + InitChooseMonsForBattle(CHOOSE_MONS_FOR_CABLE_CLUB_BATTLE); } static void CB2_ReturnFromChooseHalfParty(void) @@ -174,7 +174,7 @@ static void CB2_ReturnFromChooseHalfParty(void) void ChooseBattleTowerPlayerParty(void) { gMain.savedCallback = CB2_ReturnFromChooseBattleTowerParty; - InitChooseHalfPartyForBattle(1); + InitChooseMonsForBattle(CHOOSE_MONS_FOR_BATTLE_TOWER); } static void CB2_ReturnFromChooseBattleTowerParty(void) diff --git a/src/union_room.c b/src/union_room.c index c93360fea..68c210781 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -1929,7 +1929,7 @@ static void Task_StartActivity(u8 taskId) case ACTIVITY_ACCEPT | IN_UNION_ROOM: CleanupOverworldWindowsAndTilemaps(); gMain.savedCallback = CB2_UnionRoomBattle; - InitChooseHalfPartyForBattle(2); + InitChooseMonsForBattle(CHOOSE_MONS_FOR_UNION_ROOM_BATTLE); break; case ACTIVITY_BATTLE: CleanupOverworldWindowsAndTilemaps();