diff --git a/data/data_8106A4C.s b/data/data_8106A4C.s index 002a4b90d..ac925c300 100644 --- a/data/data_8106A4C.s +++ b/data/data_8106A4C.s @@ -1,67 +1,10 @@ .section .rodata -@ sub_8048E04 - sub_805FC30 - .align 2,0 - .string "pksdir0\0" - - - .global gUnknown_8106A4C -gUnknown_8106A4C: @ 8106A4C - .4byte 0 - - .global gUnknown_8106A50 -gUnknown_8106A50: @ 8106A50 - .4byte 1 - - .global gUnknown_8106A54 -gUnknown_8106A54: @ 8106A54 -.byte 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 -.byte 0x80, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 -.byte 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 -.byte 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 - - .global gUnknown_8106A8C -gUnknown_8106A8C: @ 8106A8C -.byte 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 -.byte 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 - - .global gUnknown_8106AC8 -gUnknown_8106AC8: @ 8106AC8 -.byte 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00 -.byte 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 - - .global gUnknown_8106AE8 -gUnknown_8106AE8: @ 8106AE8 -.byte 0x00, 0x00, 0x01, 0x00 -.byte 0x12, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x13, 0x02, 0x00, 0x00 -.byte 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x01, 0x00, 0xff, 0xff, 0x13, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff -.byte 0x12, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x13, 0x02, 0x00, 0x00 -.byte 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00 -.byte 0xff, 0xff, 0x01, 0x00, 0x13, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00 - - .global gUnknown_8106B50 -gUnknown_8106B50: @ 8106B50 - .string "{COLOR}%c%s\0" - - @ CreateFieldItemMenu - sub_8062CA8 - .align 2,0 - .string "pksdir0\0" - .align 2,0 - .global gUnknown_8106B60 -gUnknown_8106B60: @ 8106B60 - .byte 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x50, 0x00, 0x01, 0x00, 0x00, 0x00 - .global gUnknown_8106B6C -gUnknown_8106B6C: @ 8106B6C -.byte 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x06, 0x00, 0x02, 0x00 -.byte 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 + .global gUnknown_8106B8C gUnknown_8106B8C: @ 8106B8C diff --git a/data/data_8106A4C_0.s b/data/data_8106A4C_0.s new file mode 100644 index 000000000..fba5034bd --- /dev/null +++ b/data/data_8106A4C_0.s @@ -0,0 +1,44 @@ + .section .rodata + +@ sub_8048E04 - sub_805FC30 + .align 2,0 + .string "pksdir0\0" + + + .global gUnknown_8106A4C +gUnknown_8106A4C: @ 8106A4C + .4byte 0 + + .global gUnknown_8106A50 +gUnknown_8106A50: @ 8106A50 + .4byte 1 + + .global gUnknown_8106A54 +gUnknown_8106A54: @ 8106A54 +.byte 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 +.byte 0x80, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 +.byte 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00 + +.align 2,0 +.string "pksdir0\0" +.align 2,0 + +.align 2,0 +.string "pksdir0\0" +.align 2,0 + + .global gUnknown_8106A8C +gUnknown_8106A8C: @ 8106A8C +.byte 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 +.byte 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 +.byte 0x69, 0x72, 0x30, 0x00 + +.align 2,0 +.string "pksdir0\0" +.align 2,0 + +.align 2,0 +.string "pksdir0\0" +.align 2,0 + + diff --git a/include/dungeon_main.h b/include/dungeon_main.h index 232533bdc..033a67d42 100644 --- a/include/dungeon_main.h +++ b/include/dungeon_main.h @@ -2,6 +2,14 @@ #define GUARD_DUNGEON_MAIN_H #include "structs/str_text.h" +#include "structs/dungeon_entity.h" + +struct UnkMenuBitsStruct { + u8 a0_8; + u8 a0_16; + u8 a0_24; + u8 a0_32; +}; void DungeonHandlePlayerInput(void); void sub_805E804(void); @@ -10,7 +18,7 @@ void sub_805EFB4(Entity *a0, bool8 a1); void sub_805F02C(void); ActionContainer *GetLeaderActionContainer(void); u16 GetLeaderActionId(void); -bool8 sub_805FBE8(u8 *a0); +bool8 DungeonGiveNameToRecruitedMon(u8 *a0); void CreateDungeonMenuSubWindow(Window *mainWindow, s32 subWindowX); #endif diff --git a/include/dungeon_submenu.h b/include/dungeon_submenu.h new file mode 100644 index 000000000..bdabc762f --- /dev/null +++ b/include/dungeon_submenu.h @@ -0,0 +1,8 @@ +#ifndef GUARD_DUNGEON_SUBMENU_H +#define GUARD_DUNGEON_SUBMENU_H + +#include "structs/str_text.h" + +void CreateDungeonMenuSubWindow(Window *mainWindow, s32 subWindowX); + +#endif diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index c5e73164e..a06ec3155 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -98,8 +98,8 @@ typedef struct UnkDungeonGlobal_unk181E8_sub u8 unk18218; // x30 u8 unk18219; // x31 u8 unk1821A; // x32 - u8 unk1821B; // x33 - u8 unk1821C; // x34 + u8 rotateModeDirection; // x33 + u8 prevRotateModeDirection; // x34 u8 fill1821D; // x35 s16 unk36; // x36 s16 unk38; // x38 diff --git a/ld_script.txt b/ld_script.txt index e3b4ce6b9..948551853 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -227,7 +227,9 @@ SECTIONS { src/status_actions.o(.text); src/move_checks.o(.text); src/dungeon_main.o(.text); + src/dungeon_submenu.o(.text); src/code_805D8C8_2.o(.text); + src/code_805D8C8_3.o(.text); asm/code_805D8C8.o(.text); src/code_8066D04.o(.text); src/code_805D8C8.o(.text); @@ -541,6 +543,11 @@ SECTIONS { data/data_80F59C8.o(.rodata); src/dungeon_message.o(.rodata); src/dungeon_move.o(.rodata); + data/data_8106A4C_0.o(.rodata); + src/dungeon_main.o(.rodata); + src/dungeon_submenu.o(.rodata); + src/code_805D8C8_2.o(.rodata); + src/code_805D8C8_3.o(.rodata); data/data_8106A4C.o(.rodata); src/code_8066D04.o(.rodata); data/data_8106A4C_2.o(.rodata); diff --git a/src/code_803E724.c b/src/code_803E724.c index 87a51c1f6..5d47fb436 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -698,8 +698,8 @@ void sub_803F27C(bool8 a0) strPtr->priority = 3; strPtr->unk1821A = 0; strPtr->unk18212 = 0; - strPtr->unk1821B = 0; - strPtr->unk1821C = 0; + strPtr->rotateModeDirection = 0; + strPtr->prevRotateModeDirection = 0; strPtr->unk18214 = 0; strPtr->unk18215 = 1; sub_803F38C(); diff --git a/src/code_805D8C8_2.c b/src/code_805D8C8_2.c index e2648ba2b..133e5f7fc 100644 --- a/src/code_805D8C8_2.c +++ b/src/code_805D8C8_2.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "structs/str_dungeon.h" #include "number_util.h" #include "input.h" @@ -50,13 +51,6 @@ #include "structs/struct_sub80095e4.h" #include "structs/str_text.h" -struct UnkMenuBitsStruct { - u8 a0_8; - u8 a0_16; - u8 a0_24; - u8 a0_32; -}; - extern void HandleSetItemAction(Entity *,bool8); extern void HandleUnsetItemAction(Entity *,bool8); extern bool8 sub_8048A68(Entity *param_1,Item *item); @@ -100,7 +94,6 @@ s32 GetTeamMemberEntityIndex(Entity *pokemon); bool8 sub_8070F80(Entity * pokemon, s32 direction); void PrintOnMainMenu(bool8 printAll); bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1); -bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0); void sub_8060D24(UNUSED ActionContainer *a0); bool8 ShowDungeonTeamMenu(Entity *a0); void sub_8062D8C(ActionContainer *a0); @@ -187,12 +180,29 @@ static EWRAM_DATA s32 sUnknown_202F240 = 0; static UNUSED EWRAM_DATA u8 sUnused2[4] = {0}; static EWRAM_DATA s16 sUnknown_202F248[8] = {0}; static EWRAM_DATA s32 sUnknown_202F258 = 0; -static UNUSED EWRAM_DATA u8 sUnused3[4] = {0}; -EWRAM_DATA s32 gTeamMenuChosenId = 0; -static UNUSED EWRAM_DATA u8 sUnused4[4] = {0}; static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, Windows *a4, WindowHeader *a5); +bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0) +{ + u16 action = GetLeaderActionId(); + + a0->a0_8 = 0; + a0->a0_16 = 0; + a0->a0_24 = 0; + a0->a0_32 = 0; + if (action == 0xA) { + a0->a0_8 = 1; + a0->a0_32 = 1; + } + if (action == 0x3E) { + a0->a0_8 = 1; + a0->a0_16 = 0; + a0->a0_32 = 1; + } + return a0->a0_8; +} + bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) { s32 i, i_r6; @@ -465,19 +475,25 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) return r9; } -extern const struct Window gUnknown_8106B6C; -extern const struct unkStruct_8090F58 gUnknown_8106B60; +static const struct unkStruct_8090F58 gUnknown_8106B60 = {1, 1, 0, 80, 1}; -static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, Windows *windows, WindowHeader *a5) +static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, bool8 a3, Windows *windows, WindowHeader *a5) { s32 i, x, y; s32 r10; UnkTextStruct1 *txtStrPtr; - Window var_94; + Window whichWindow = { + .type = WINDOW_TYPE_NORMAL, + .pos = {2, 4}, + .width = 6, + .height = 2, + .unk10 = 2, + .unk12 = 0, + .unk14 = NULL, + }; u8 txtBuff[80]; EntityInfo *a1Info; - var_94 = gUnknown_8106B6C; a1Info = GetEntInfo(a1); r10 = sub_8060800(a5, a0); gDungeonMenu.menuIndex = sUnknown_202F240; @@ -516,10 +532,10 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, Wind break; } - if (a2) { + if (showWhichWindow) { gDungeonMenu.unkC += 0x40; windows->id[0].pos.x = 0xA; - windows->id[1] = var_94; + windows->id[1] = whichWindow; } else { windows->id[0].pos.x = 2; @@ -612,7 +628,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, Wind gDungeonMenu.menuIndex = 0; } sub_80073E0(0); - if (a2) { + if (showWhichWindow) { sub_80073B8(1); PrintFormattedStringOnWindow(4, 2, gWhichTextPtr1, 1, 0); sub_80073E0(1); @@ -928,2064 +944,5 @@ s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4) return count; } -extern WindowHeader gUnknown_202F270; -struct UnkFieldTeamMenuStruct -{ - s32 unk0; - s32 unk4[MAX_TEAM_MEMBERS]; - u8 unk14[MAX_TEAM_MEMBERS]; -}; -void PrintOnDungeonTeamMenu(struct UnkFieldTeamMenuStruct *a0, Windows *a1, bool8 a2); -void sub_806145C(struct UnkFieldTeamMenuStruct *a0); -void sub_80615B4(ActionContainer *a0, struct UnkFieldTeamMenuStruct *a1); - -extern u8 gUnknown_202EE39; - -bool8 ShowDungeonTeamMenu(Entity *a0) -{ - s32 i; - bool32 r10, ret; - struct UnkFieldTeamMenuStruct sp; - Windows windows = { - .id = { - [0] = { - .type = WINDOW_TYPE_WITH_HEADER, - .pos = {2, 2}, - .width = 14, - .height = 16, - .unk10 = 16, - .unk12 = 0, - .unk14 = &gUnknown_202F270, - }, - [1] = WINDOW_DUMMY, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - Entity *teamMon = gDungeon->teamPokemon[i]; - if (EntityIsValid(teamMon)) { - GetEntInfo(teamMon)->unk157 = TRUE; - } - } - - if (!gDungeon->unk644.unk17) { - windows.id[0].type = WINDOW_TYPE_NORMAL; - windows.id[0].pos.y++; - } - - while (1) { - s32 id; - bool32 r4; - - ret = FALSE; - PrintOnDungeonTeamMenu(&sp, &windows, TRUE); - r10 = FALSE; - while (1) { - s32 id = sp.unk4[gDungeonMenu.menuIndex]; - if (id >= 0) { - Entity *teamMon = gDungeon->teamPokemon[id]; - sub_806A2BC(teamMon, 0); - ChangeDungeonCameraPos(&teamMon->pos, 0, 1, 1); - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.pressed & START_BUTTON) { - if (sp.unk14[gDungeonMenu.menuIndex] != 0) { - PlayDungeonStartButtonSE(); - r10 = TRUE; - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) - { - if (sp.unk14[gDungeonMenu.menuIndex] != 0) { - PlayDungeonConfirmationSE(); - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - ret = TRUE; - break; - } - } - - id = sp.unk4[gDungeonMenu.menuIndex]; - if (id >= 0) { - Entity *teamMon = gDungeon->teamPokemon[id]; - sub_806A2BC(teamMon, 0); - ChangeDungeonCameraPos(&teamMon->pos, 0, 1, 1); - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - sub_804AA60(); - if (ret) { - break; - } - - sp.unk0 = gDungeonMenu.menuIndex; - gTeamMenuChosenId = gDungeonMenu.menuIndex; - sub_806145C(&sp); - if (r10) { - EntityInfo *info = GetEntInfo(a0); - SetMonsterActionFields(&info->action, 0x1B); - info->action.actionParameters[0].actionUseIndex = sp.unk4[sp.unk0]; - ret = FALSE; - break; - } - - CreateDungeonMenuSubWindow(&windows.id[0], 0x12); - while (1) { - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { - sub_80615B4(&GetEntInfo(a0)->action, &sp); - PlayDungeonConfirmationSE(); - r4 = FALSE; - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - r4 = TRUE; - break; - } - } - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (r4 != TRUE) { - ret = FALSE; - break; - } - } - - if (ret) { - sub_806A2BC(GetLeader(), 0); - } - sub_803EAF0(0, NULL); - return ret; -} - -bool32 sub_8069D18(DungeonPos *a0, Entity *a1); - -extern const u8 gTeamFormat[]; -extern const u8 gHeartRedTiny[]; -extern const u8 gHeartRedSmall[]; -extern const u8 gHeartRedMedium[]; -extern const u8 gHeartRedLarge[]; -extern const u8 gHeartYellowTiny[]; -extern const u8 gHeartYellowSmall[]; -extern const u8 gHeartYellowMedium[]; -extern const u8 gHeartYellowLarge[]; -extern const u8 gUnknown_8106BD4[]; -extern const u8 gUnknown_8106BE0[]; -extern const u8 gUnknown_8106BEC[]; -extern const u8 gUnknown_8106BF4[]; - -extern void sub_8070968(u8 *buffer, EntityInfo *entityInfo, s32 colorNum); - -void PrintOnDungeonTeamMenu(struct UnkFieldTeamMenuStruct *a0, Windows *windows, bool8 a2) -{ - s32 r0; - DungeonPos pos; - s32 i; - - s32 count = 0; - bool8 r10 = (windows->id[0].type == WINDOW_TYPE_WITH_HEADER); - - sub_8069D18(&pos, GetLeader()); - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - EntityInfo *monInfo; - Entity *teamMon = gDungeon->teamPokemon[i]; - if (EntityIsValid(teamMon)) { - a0->unk4[count] = i; - monInfo = GetEntInfo(teamMon); - a0->unk14[count] = monInfo->unk157; - if (pos.x == teamMon->pos.x && pos.y == teamMon->pos.y && gTeamMenuChosenId < 0) { - gTeamMenuChosenId = count; - } - count++; - } - } - - if (gTeamMenuChosenId >= count) { - gTeamMenuChosenId = count - 1; - } - if (gTeamMenuChosenId < 0) { - gTeamMenuChosenId = 0; - } - - for (i = count; i < MAX_TEAM_MEMBERS; i++) { - a0->unk4[i] = -1; - a0->unk14[i] = 0; - } - - gUnknown_202F270.f0 = 1; - gUnknown_202F270.f1 = 0; - gUnknown_202F270.f3 = 0; - gDungeonMenu.menuIndex = gTeamMenuChosenId; - gDungeonMenu.unk1A = count; - gDungeonMenu.unk1C = count; - gDungeonMenu.unk1E = 0; - gDungeonMenu.unk20 = 0; - gDungeonMenu.unk4 = 0; - gDungeonMenu.firstEntryY = (r10 != FALSE) * 16; - gDungeonMenu.unkC = 0; - gDungeonMenu.unkE = 0; - gDungeonMenu.unk14.x = 0; - gDungeonMenu.unk0 = 0; - sub_801317C(&gDungeonMenu.unk28); - r0 = sub_80095E4(count, 0); - if (r10) { - r0 += 2; - } - windows->id[0].unk10 = r0; - windows->id[0].height = r0; - gUnknown_202F270.f2 = 8; - if (a2) { - windows->id[1] = windows->id[3]; - } - - DungeonShowWindows(windows, 1); - sub_80137B0(&gDungeonMenu, 0); - sub_80073B8(0); - if (r10) { - PrintFormattedStringOnWindow(0xC, 0, gTeamFormat, 0, 0); - } - - // Print hp/max hp - for (i = 0; i < count; i++) { - s32 y; - s32 id = a0->unk4[i]; - if (id >= 0) { - Entity *teamMon = gDungeon->teamPokemon[id]; - if (EntityIsValid(teamMon)) - { - EntityInfo *monInfo = GetEntInfo(teamMon); - s32 color = (a0->unk14[i] != 0) ? 6 : 2; - - sub_8070968(gFormatBuffer_Monsters[0], monInfo, color); - if (sub_806A538(gRecruitedPokemonRef->pokemon2[monInfo->teamIndex].unkA)) { - if (monInfo->HP <= monInfo->maxHPStat / 4) { - strcpy(gFormatBuffer_Monsters[1], gHeartRedTiny); - } - else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { - strcpy(gFormatBuffer_Monsters[1], gHeartRedSmall); - } - else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { - strcpy(gFormatBuffer_Monsters[1], gHeartRedMedium); - } - else { - strcpy(gFormatBuffer_Monsters[1], gHeartRedLarge); - } - } - else { - if (monInfo->HP <= monInfo->maxHPStat / 4) { - strcpy(gFormatBuffer_Monsters[1], gHeartYellowTiny); - } - else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { - strcpy(gFormatBuffer_Monsters[1], gHeartYellowSmall); - } - else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { - strcpy(gFormatBuffer_Monsters[1], gHeartYellowMedium); - } - else { - strcpy(gFormatBuffer_Monsters[1], gHeartYellowLarge); - } - } - - gFormatArgs[0] = monInfo->HP; - gFormatArgs[1] = monInfo->maxHPStat; - y = GetMenuEntryYCoord(&gDungeonMenu, i); - if (monInfo->isTeamLeader) { - PrintFormattedStringOnWindow(9, y, gUnknown_8106BD4, 0, 0); - } - else { - PrintFormattedStringOnWindow(9, y, gUnknown_8106BE0, 0, 0); - } - } - } - } - - sub_80073E0(0); -} - -extern bool8 CanLeaderSwitch(u8 dungeon); - -void sub_806145C(struct UnkFieldTeamMenuStruct *a0) -{ - Entity *teamMon; - EntityInfo *monInfo; - - gDungeonSubMenuItemsCount = 0; - teamMon = gDungeon->teamPokemon[a0->unk4[gDungeonMenu.menuIndex]]; - monInfo = GetEntInfo(teamMon); - sub_8044F5C(0x1B, 0); - sub_8044F5C(0x19, 0); - if (!monInfo->isTeamLeader) { - if (!gDungeon->unk644.unk19 && (monInfo->joinedAt.id != DUNGEON_JOIN_LOCATION_PARTNER || gDungeon->unk644.unk18)) { - sub_8044F5C(0x34, 0); - } - sub_8044F5C(0x1C, 0); - } - sub_8044F5C(0x30, 0); - if (!monInfo->isTeamLeader) { - sub_8044F5C(0x1A, 0); - } - if (!monInfo->isTeamLeader && gDungeon->unk644.unk18 && CanLeaderSwitch(gDungeon->unk644.dungeonLocation.id)) { - bool32 r5; - - sub_8044F5C(0x3B, 0); - r5 = TRUE; - if (monInfo->teamIndex >= MAX_TEAM_MEMBERS) { - r5 = FALSE; - } - else { - PokemonStruct2 *mon = &gRecruitedPokemonRef->pokemon2[monInfo->teamIndex]; - if (sub_806A538(mon->unkA)) { - r5 = FALSE; - } - } - - if (CheckVariousStatuses2(teamMon, FALSE)) { - r5 = FALSE; - } - if (!r5) { - sub_8044FF0(0x3B); - } - } - - if (IsExperienceLocked(monInfo->joinedAt.id)) { - sub_8044FF0(0x19); - sub_8044FF0(0x3B); - sub_8044FF0(0x1A); - sub_8044FF0(0x30); - sub_8044FF0(0x34); - } - - sub_8045064(); -} - -void sub_80615B4(ActionContainer *a0, struct UnkFieldTeamMenuStruct *a1) -{ - SetMonsterActionFields(a0, gUnknown_202EE44[gDungeonMenu.menuIndex].unk0); - a0->actionParameters[0].actionUseIndex = a1->unk4[a1->unk0]; -} - -void PrintMonTactics(s32 a0, u8 *tacticIds, EntityInfo *mon, s32 windowId); -void sub_80623B0(void); -void sub_8062D68(void); -void sub_8062230(void); -void sub_8062748(u8 a0); - -void ShowTacticsMenu(ActionContainer *a0) -{ - Windows windows = { - .id = { - [0] = { - .type = WINDOW_TYPE_WITH_HEADER, - .pos = {2, 2}, - .width = 18, - .height = 14, - .unk10 = 18, - .unk12 = 2, - .unk14 = &gUnknown_202F270, - }, - [1] = WINDOW_DUMMY, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - EntityInfo *monInfo; - u8 tacticIds[NUM_TACTICS]; - s32 scrollFirstId; - s32 menuIndex; - Entity *teamMon; - - teamMon = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; - monInfo = GetEntInfo(teamMon); - menuIndex = 0; - scrollFirstId = 0; - while (1) { - s32 i; - bool32 addCursor = TRUE; - bool32 loopBreak = FALSE; - - gUnknown_202F270.f0 = 1; - gUnknown_202F270.f1 = 0; - gUnknown_202F270.f2 = 10; - gUnknown_202F270.f3 = 0; - DungeonShowWindows(&windows, 1); - PrintMonTactics(scrollFirstId, tacticIds, monInfo, 0); - for (i = 0; i < 8; i++) { - if (tacticIds[i] == TACTIC_UNUSED) - break; - } - gDungeonMenu.unk1A = i; - gDungeonMenu.unk1C = 8; - gDungeonMenu.unk1E = 0; - gDungeonMenu.unk20 = 0; - gDungeonMenu.unk4 = 0; - gDungeonMenu.firstEntryY = 16; - gDungeonMenu.unkC = 0; - gDungeonMenu.unkE = 0; - gDungeonMenu.unk14.x = 0; - gDungeonMenu.unk0 = 0; - sub_801317C(&gDungeonMenu.unk28); - sub_80137B0(&gDungeonMenu, 0); - gDungeonMenu.menuIndex = menuIndex; - while (1) { - s32 i; - - AddMenuCursorSprite(&gDungeonMenu); - if (tacticIds[8] != TACTIC_UNUSED) { - sub_80623B0(); - } - if (scrollFirstId != 0) { - sub_8062230(); - } - DungeonRunFrameActions(0x3D); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - if (gDungeonMenu.menuIndex == 7) { - if (tacticIds[8] != TACTIC_UNUSED) { - for (i = 0; i < 6; i++) { - gIwramTextFunc1(0); - DungeonRunFrameActions(0x3D); - } - scrollFirstId++; - } - menuIndex = 7; - break; - } - MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - if (gDungeonMenu.menuIndex == 0) { - if (scrollFirstId != 0) { - for (i = 0; i < 6; i++) { - gIwramTextFunc2(0); - DungeonRunFrameActions(0x3D); - } - scrollFirstId--; - } - menuIndex = 0; - break; - } - MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); - } - if (gRealInputs.pressed & START_BUTTON) { - u32 tacticId = tacticIds[gDungeonMenu.menuIndex]; - menuIndex = gDungeonMenu.menuIndex; - PlayDungeonStartButtonSE(); - sub_8062748(tacticId); - loopBreak = FALSE; - break; - } - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - bool32 changed; - - u32 tacticId = tacticIds[gDungeonMenu.menuIndex]; - menuIndex = gDungeonMenu.menuIndex; - sub_8062D68(); - PlayDungeonConfirmationSE(); - gDungeonSubMenuItemsCount = 0; - sub_8044F5C(0x2F, 0); - sub_8044F5C(0xC, 0); - if (CheckVariousStatuses2(teamMon, TRUE)) { - sub_8044FF0(0x2F); - } - CreateDungeonMenuSubWindow(&windows.id[0], 0x16); - while (1) { - changed = FALSE; - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x3D); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { - changed = TRUE; - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - changed = FALSE; - break; - } - } - if (changed) { - PlayDungeonConfirmationSE(); - if (gDungeonMenu.menuIndex == 0) { - PlaySoundEffect(0x133); - monInfo->tactic = tacticId; - monInfo->aiTarget.aiObjective = 6; - monInfo->aiTarget.aiTarget = NULL; - monInfo->aiTarget.unkC = 0; - monInfo->aiTarget.aiTargetSpawnGenID = 0; - if (!monInfo->isTeamLeader) { - AIMovement(teamMon, TRUE); - } - } - else { - sub_8062748(tacticId); - addCursor = FALSE; - } - } - loopBreak = FALSE; - break; - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - loopBreak = TRUE; - break; - } - } - - if (addCursor) { - AddMenuCursorSprite(&gDungeonMenu); - } - DungeonRunFrameActions(0x3D); - if (loopBreak) - break; - } - sub_803EAF0(0, NULL); -} - -extern void GetAvailTacticsforLvl(u8 *tacticsBuffer, s32 pokeLevel); - -void PrintMonTactics(s32 firstId, u8 *tacticIds, EntityInfo *mon, s32 windowId) -{ - u8 tacticsBuffer[NUM_TACTICS]; - u32 tactic; - s32 y, i, j; - - firstId--; - sub_80073B8(windowId); - PrintStringOnWindow(0x10, 0, gUnknown_80FE954, windowId, 0); - y = 0x14; - for (j = 0; j < 9; j++) { - tacticIds[j] = TACTIC_UNUSED; - } - GetAvailTacticsforLvl(tacticsBuffer, GetLeaderInfo()->level); - for (i = -1; i < 10; i++, y += 12, firstId++) { - if (firstId < 0) - continue; - if (firstId >= NUM_TACTICS) - continue; - - tactic = tacticsBuffer[firstId]; - if (i >= 0 && i < 9) { - tacticIds[i] = tactic; - } - if (tactic == TACTIC_UNUSED) - break; - - CopyTacticsNameToBuffer(gFormatBuffer_Monsters[0], tactic); - if (mon->tactic == tactic) { - PrintFormattedStringOnWindow(0x10, y, gUnknown_8106BEC, windowId, 0); - } - else { - PrintFormattedStringOnWindow(0x10, y, gUnknown_8106BF4, windowId, 0); - } - } - - sub_80073E0(windowId); -} - -EWRAM_INIT u8 gUnknown_203B43C[4] = {2, 0, 0xD, 0}; // TODO: Move to a better file and figure out the array count. Apparently it's only written to. - -extern void sub_8069844(struct unkStruct_808FF20 *param_1, Entity *target); -extern u32 sub_8014140(s32 a0, const void *a1); -void sub_806285C(s32 a0); -void sub_806262C(u8 iqSkillId); - -extern const u8 gUnknown_8106B8C[]; - -void sub_8061A38(ActionContainer *a0, bool8 a1) -{ - s32 spArr[6]; - struct unkStruct_808FF20 unkMonStruct; - struct UnkInfoTabStruct unkInfoTabStruct; - Windows windows = { - .id = { - [0] = { - .type = WINDOW_TYPE_WITH_HEADER, - .pos = {2, 2}, - .width = 18, - .height = 14, - .unk10 = 18, - .unk12 = 2, - .unk14 = &gUnknown_202F270, - }, - [1] = WINDOW_DUMMY, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - s32 r8; - Entity *entity; - s32 var_3C; - s32 var_38; - EntityInfo *entityInfo; - - var_3C = 0; - r8 = 0; - entity = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; - entityInfo = GetEntInfo(entity); - - if (IsExperienceLocked(entityInfo->joinedAt.id)) { - spArr[0] = 1; - spArr[1] = 0; - spArr[2] = 0; - spArr[3] = 0; - spArr[4] = 0; - spArr[5] = 0; - var_38 = 1; - } - else if (a1) { - spArr[0] = 4; - spArr[1] = 0; - spArr[2] = 0; - spArr[3] = 0; - spArr[4] = 0; - spArr[5] = 0; - var_38 = 1; - } - else { - spArr[0] = 2; - spArr[1] = 1; - spArr[2] = 3; - spArr[3] = 5; - spArr[4] = 0; - spArr[5] = 0; - var_38 = 4; - } - - unkMonStruct.unk40 = 0; - unkMonStruct.unk56 = 0; - gDungeonMenu.menuIndex = 0; - - while (1) { - bool8 loopBreak = FALSE; - s32 var_30 = 0; - s32 var_2C = 0; - s32 var_28 = 1; - UnkTextStruct1 *unkTxtStr1Ptr = &gUnknown_2027370[0]; - - gUnknown_202F270.f0 = var_38; - gUnknown_202F270.f1 = var_3C; - gUnknown_202F270.f2 = 10; - gUnknown_202F270.f3 = 0; - DungeonShowWindows(&windows, TRUE); - sub_8069844(&unkMonStruct, entity); - CreatePokemonInfoTabScreen(spArr[var_3C], var_3C, &unkMonStruct, &unkInfoTabStruct, 0); - gDungeonMenu.unk1E = var_3C; - gDungeonMenu.unk20 = var_38; - gDungeonMenu.unkC = (unkTxtStr1Ptr->unk0 + 15) * 8; - gDungeonMenu.unkE = ((unkTxtStr1Ptr->unk2 + 1) * 8) - 2; - gDungeonMenu.unk14.x = 0; - gDungeonMenu.unk4 = 0; - gDungeonMenu.firstEntryY = 16; - gDungeonMenu.unk0 = 0; - sub_801317C(&gDungeonMenu.unk28); - gDungeonMenu.menuIndex = 0; - gDungeonMenu.unk1A = 0; - gDungeonMenu.unk1C = 0; - - if (spArr[var_3C] == 1) { - s32 i; - - for (i = 0; i < 8; i++) { - if (unkInfoTabStruct.unkC[i] == 0) { - break; - } - } - - if (i != 0) { - var_2C = 1; - gDungeonMenu.unk1A = i; - gDungeonMenu.unk1C = 8; - sub_80137B0(&gDungeonMenu, 0); - } - gDungeonMenu.menuIndex = r8; - } - else if (spArr[var_3C] == 4) { - s32 i; - - for (i = 0; i < 8; i++) { - if (unkInfoTabStruct.unk0[i] == 0) { - break; - } - } - - if (i != 0) { - var_30 = 1; - gDungeonMenu.unk1A = i; - gDungeonMenu.unk1C = 8; - sub_80137B0(&gDungeonMenu, 0); - } - gDungeonMenu.menuIndex = r8; - } - - while (1) { - s32 unkVar; - bool8 r5, r6; - - AddMenuCursorSprite(&gDungeonMenu); - unkVar = sub_8014140(0, gUnknown_8106B8C); - r5 = FALSE; - r6 = FALSE; - if (var_30) { - if (unkInfoTabStruct.unk0[8] != 0) { - r5 = TRUE; - sub_80623B0(); - } - if (unkMonStruct.unk40 != 0) { - r6 = TRUE; - sub_8062230(); - } - } - if (var_2C) { - if (unkInfoTabStruct.unkC[8] != 0) { - r5 = TRUE; - sub_80623B0(); - } - if (unkMonStruct.unk56 != 0) { - r6 = TRUE; - sub_8062230(); - } - } - - DungeonRunFrameActions(0x1C); - if (gUnknown_202F270.f0 > 1 && !sub_80048C8()) { - if ((gRealInputs.pressed & DPAD_RIGHT) || gDungeonMenu.unk28.dpad_right) { - PlayDungeonCursorSE(0); - var_3C++; - if (spArr[var_3C] == 0) { - var_3C = 0; - } - break; - } - if ((gRealInputs.pressed & DPAD_LEFT) || gDungeonMenu.unk28.dpad_left) { - PlayDungeonCursorSE(0); - var_3C--; - if (var_3C == -1) { - var_3C = 5; - while (spArr[var_3C] == 0) { - var_3C--; - } - } - break; - } - } - - if (var_2C) { - if (unkVar == 2 && r5) { - PlayDungeonCursorSE(0); - if (unkInfoTabStruct.unkC[8] != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc1(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk56++; - } - r8 = 7; - break; - } - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(0); - if (gDungeonMenu.menuIndex == 7) { - if (unkInfoTabStruct.unkC[8] != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc1(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk56++; - } - r8 = 7; - break; - } - else { - MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); - } - } - - if (unkVar == 1 && r6) { - if (unkMonStruct.unk56 != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc2(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk56--; - } - r8 = 0; - break; - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - if (gDungeonMenu.menuIndex == 0) { - if (unkMonStruct.unk56 != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc2(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk56--; - } - r8 = 0; - break; - } - else { - MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); - } - } - } - else if (var_30) { - if (unkVar == 2 && r5) { - if (unkInfoTabStruct.unk0[8] != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc1(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk40++; - } - r8 = 7; - break; - } - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - if (gDungeonMenu.menuIndex == 7) { - if (unkInfoTabStruct.unk0[8] != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc1(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk40++; - } - r8 = 7; - break; - } - else { - MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); - } - } - - if (unkVar == 1 && r6) { - if (unkMonStruct.unk40 != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc2(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk40--; - } - r8 = 0; - break; - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - if (gDungeonMenu.menuIndex == 0) { - if (unkMonStruct.unk40 != 0) { - s32 i; - for (i = 0; i < 6; i++) { - gIwramTextFunc2(0); - DungeonRunFrameActions(28); - } - unkMonStruct.unk40--; - } - r8 = 0; - break; - } - else { - MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); - } - } - } - - if (sub_80048C8()) - continue; - - if (gRealInputs.pressed & START_BUTTON) { - if (var_2C) { - s32 var = unkInfoTabStruct.unkC[gDungeonMenu.menuIndex]; - - r8 = gDungeonMenu.menuIndex; - PlayDungeonStartButtonSE(); - sub_806285C(var); - var_28 = 0; - loopBreak = FALSE; - break; - } - else if (var_30) { - s32 var = unkInfoTabStruct.unk0[gDungeonMenu.menuIndex]; - - r8 = gDungeonMenu.menuIndex; - PlayDungeonStartButtonSE(); - sub_806262C(var); - var_28 = 0; - loopBreak = FALSE; - break; - } - } - - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - if (var_2C) { - s32 var = unkInfoTabStruct.unkC[gDungeonMenu.menuIndex]; - - r8 = gDungeonMenu.menuIndex; - sub_8062D68(); - gDungeonSubMenuItemsCount = 0; - PlayDungeonConfirmationSE(); - sub_8044F5C(0xC, 0); - CreateDungeonMenuSubWindow(&windows.id[0], 0x16); - while (1) { - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1C); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - PlayDungeonConfirmationSE(); - sub_806285C(var); - var_28 = 0; - loopBreak = FALSE; - break; - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - loopBreak = FALSE; - break; - } - } - } - else if (var_30) { - bool8 aPress = FALSE; - s32 var = unkInfoTabStruct.unk0[gDungeonMenu.menuIndex]; - - r8 = gDungeonMenu.menuIndex; - sub_8062D68(); - gDungeonSubMenuItemsCount = var_2C; - PlayDungeonConfirmationSE(); - sub_8044F5C(0x28, 0); - sub_8044F5C(0xC, 0); - if (CheckVariousStatuses2(entity, TRUE)) { - sub_8044FF0(0x28); - } - CreateDungeonMenuSubWindow(&windows.id[0], 0x16); - while (1) { - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1C); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { - PlayDungeonConfirmationSE(); - aPress = TRUE; - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - loopBreak = FALSE; - aPress = FALSE; - break; - } - } - - if (aPress) { - if (gDungeonMenu.menuIndex == 0) { - PlaySoundEffect(0x133); - ToggleIQSkill(&entityInfo->IQSkillMenuFlags, var); - } - else { - sub_806262C(var); - var_28 = 0; - } - loopBreak = FALSE; - break; - } - } - else { - PlayDungeonConfirmationSE(); - loopBreak = TRUE; - } - break; - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - loopBreak = TRUE; - break; - } - } - - if (var_28) { - if (var_30 != 0 || var_2C != 0) { - AddMenuCursorSprite(&gDungeonMenu); - } - DungeonRunFrameActions(0x1C); - } - - if (loopBreak) { - break; - } - } - - sub_803EAF0(0, NULL); - LoadIQSkills(entity); -} - -extern s32 gUnknown_202EDCC; - -// The same as sub_8068344 -void sub_8062230(void) -{ - if ((gUnknown_202EDCC & 8) != 0) { - UnkTextStruct1 *txtStrPtr = &gUnknown_2027370[0]; - SpriteOAM sprite = {0}; - - SpriteSetAffine1(&sprite, 0); - SpriteSetAffine2(&sprite, 0); - SpriteSetObjMode(&sprite, 0); - SpriteSetMosaic(&sprite, 0); - SpriteSetBpp(&sprite, 0); - SpriteSetShape(&sprite, 1); - SpriteSetMatrixNum(&sprite, 16); - SpriteSetSize(&sprite, 0); - SpriteSetTileNum(&sprite, 0x3F0); - SpriteSetPriority(&sprite, 0); - SpriteSetPalNum(&sprite, 15); - SpriteSetY(&sprite, (txtStrPtr->unk2 * 8) + 0x8); - SpriteSetX(&sprite, (txtStrPtr->unk0 * 8) + 0x40); - - AddSprite(&sprite, 0x100, NULL, NULL); - } -} - -// The same as sub_80684C4 -void sub_80623B0(void) -{ - if ((gUnknown_202EDCC & 8) != 0) { - UnkTextStruct1 *ptr = &gUnknown_2027370[0]; - SpriteOAM sprite = {0}; - - SpriteSetAffine1(&sprite, 0); - SpriteSetAffine2(&sprite, 0); - SpriteSetObjMode(&sprite, 0); - SpriteSetMosaic(&sprite, 0); - SpriteSetBpp(&sprite, 0); - SpriteSetShape(&sprite, 1); - SpriteSetMatrixNum(&sprite, 0); - SpriteSetSize(&sprite, 0); - SpriteSetTileNum(&sprite, 0x3F0); - SpriteSetPriority(&sprite, 0); - SpriteSetPalNum(&sprite, 15); - SpriteSetY(&sprite, (ptr->unk2 * 8) + 0x70); - SpriteSetX(&sprite, (ptr->unk0 * 8) + 0x40); - AddSprite(&sprite,0x100,NULL,NULL); - } -} - -extern SpriteOAM gUnknown_202F268; - -void sub_8062500(void) -{ - if ((gUnknown_202EDCC & 8) != 0) { - UnkTextStruct1 *ptr = &gUnknown_2027370[0]; - - SpriteSetAffine1(&gUnknown_202F268, 0); - SpriteSetAffine2(&gUnknown_202F268, 0); - SpriteSetObjMode(&gUnknown_202F268, 0); - SpriteSetMosaic(&gUnknown_202F268, 0); - SpriteSetBpp(&gUnknown_202F268, 0); - SpriteSetShape(&gUnknown_202F268, 1); - SpriteSetMatrixNum(&gUnknown_202F268, 0); - SpriteSetSize(&gUnknown_202F268, 0); - SpriteSetTileNum(&gUnknown_202F268, 0x3F0); - SpriteSetPriority(&gUnknown_202F268, 0); - SpriteSetPalNum(&gUnknown_202F268, 15); - SpriteSetY(&gUnknown_202F268, (ptr->unk2 * 8) + 0x60); - SpriteSetX(&gUnknown_202F268, 0x70); - AddSprite(&gUnknown_202F268,0x100,NULL,NULL); - } -} - -void sub_80639E4(struct subStruct_203B240 *strings, MenuInputStructSub *menuSub); - -void sub_80625A4(s32 count, struct subStruct_203B240 **strings) -{ - s32 i; - MenuInputStructSub menuSub; - - sub_801317C(&menuSub); - for (i = 0; i < count; i++) { - sub_80639E4(strings[i], &menuSub); - while (1) { - if (i < count - 1) { - sub_8062500(); - } - nullsub_34(&menuSub, 0); - DungeonRunFrameActions(0x16); - if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { - PlayDungeonConfirmationSE(); - break; - } - if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { - PlayDungeonCancelSE(); - break; - } - } - } -} - -#include "code_8097DD0.h" -#include "move_util.h" -#include "move_util.h" - -extern const u8 *const gUnknown_80FE95C; -extern const u8 *const gUnknown_80FE960; -extern const u8 *const gUnknown_80FE964; -extern const u8 *const gUnknown_80FE978; -extern const u8 gUnknown_8106C90[]; -extern const u8 gUnknown_8106C98[]; -extern const u8 gUnknown_8106C9C[]; -extern const u8 *const gWhichTextPtr2; -extern char* sub_808E4FC(s32 a1); -extern char* sub_808E51C(s32 a1); -extern void sub_8062B74(Entity *entity); -extern void sub_8062CA8(Entity *entity); -extern void sub_8045C18(u8 *buffer, Item *item); - -void sub_806262C(u8 iqSkillId) -{ - MenuInputStructSub menuSub; - Windows windows; - WindowHeader header; - struct subStruct_203B240 *result[4]; - - while (1) { - s32 count; - bool8 bPress; - - sub_801317C(&menuSub); - sub_80140B4(&windows); - windows.id[0].unk14 = &header; - header.f0 = 1; - header.f1 = 0; - header.f2 = 16; - header.f3 = 0; - DungeonShowWindows(&windows, TRUE); - sub_80073B8(0); - - strcpy(gFormatBuffer_Items[0], GetIQSkillName(iqSkillId)); - PrintFormattedStringOnWindow(16, 0, gUnknown_80FE95C, 0, '\0'); - PrintFormattedStringOnWindow(8, 16, GetIQSkillDescription(iqSkillId), 0, '\0'); - sub_80073E0(0); - count = sub_8097DF0(GetIQSkillDescription(iqSkillId), result); - while (1) { - if (count != 0) { - sub_8062500(); - } - nullsub_34(&menuSub, 0); - DungeonRunFrameActions(0x16); - if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { - bPress = FALSE; - PlayDungeonConfirmationSE(); - break; - } - if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { - bPress = TRUE; - PlayDungeonCancelSE(); - break; - } - } - - if (bPress || count == 0) - break; - - sub_80625A4(count, result); - } - - sub_803E708(4, 0x3E); -} - -void sub_8062748(u8 tacticId) -{ - MenuInputStructSub menuSub; - Windows windows; - WindowHeader header; - struct subStruct_203B240 *result[4]; - - while (1) { - s32 count; - bool8 bPress; - - sub_801317C(&menuSub); - sub_80140B4(&windows); - windows.id[0].unk14 = &header; - header.f0 = 1; - header.f1 = 0; - header.f2 = 16; - header.f3 = 0; - DungeonShowWindows(&windows, TRUE); - sub_80073B8(0); - - CopyTacticsNameToBuffer(gFormatBuffer_Items[0], tacticId); - PrintFormattedStringOnWindow(16, 0, gUnknown_80FE960, 0, '\0'); - PrintFormattedStringOnWindow(8, 16, GetTacticsDescription(tacticId), 0, '\0'); - sub_80073E0(0); - count = sub_8097DF0(GetTacticsDescription(tacticId), result); - while (1) { - if (count != 0) { - sub_8062500(); - } - nullsub_34(&menuSub, 0); - DungeonRunFrameActions(62); - if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { - bPress = FALSE; - PlayDungeonConfirmationSE(); - break; - } - if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { - bPress = TRUE; - PlayDungeonCancelSE(); - break; - } - } - - if (bPress || count == 0) - break; - - sub_80625A4(count, result); - } - - sub_803E708(4, 0x3E); -} - -void sub_806285C(s32 a0) -{ - const u8 *str; - MenuInputStructSub menuSub; - WindowHeader header; - Windows windows = { - .id = { - [0] = { - .type = WINDOW_TYPE_WITH_HEADER, - .pos = {2, 2}, - .width = 26, - .height = 12, - .unk10 = 12, - .unk12 = 0, - .unk14 = &header, - }, - [1] = WINDOW_DUMMY, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - - sub_801317C(&menuSub); - header.f0 = 1; - header.f1 = 0; - header.f2 = 16; - header.f3 = 0; - DungeonShowWindows(&windows, TRUE); - sub_80073B8(0); - str = sub_808E4FC(a0); - strcpy(gFormatBuffer_Items[0], str); - PrintFormattedStringOnWindow(16, 0, gUnknown_80FE964, 0, '\0'); - PrintFormattedStringOnWindow(8, 16, sub_808E51C(a0), 0, '\0'); - sub_80073E0(0); - - while (1) { - nullsub_34(&menuSub, 0); - DungeonRunFrameActions(22); - if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { - PlayDungeonConfirmationSE(); - break; - } - if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { - PlayDungeonCancelSE(); - break; - } - } - - sub_803E708(4, 0x3E); -} - -extern const Windows gUnknown_8106C30; -extern const Window gUnknown_8106C00; -extern const Window gUnknown_8106C18; - -Entity *DrawFieldGiveItemMenu(s32 *teamId, s32 a1) -{ - struct UnkFieldTeamMenuStruct unkStruct; - Windows windows = gUnknown_8106C30; - bool8 bPress = FALSE; - s32 prevId, currId; - - if (teamId != NULL) { - *teamId = -1; - } - - if (a1 == 1) { - windows.id[2] = gUnknown_8106C00; - } - else if (a1 == 2) { - windows.id[2] = gUnknown_8106C18; - } - - PrintOnDungeonTeamMenu(&unkStruct, &windows, FALSE); - sub_80073B8(1); - PrintStringOnWindow(4, 3, gWhichTextPtr2, 1, '\0'); - sub_80073E0(1); - prevId = -985; // Magic number or does it actually mean anything? - - while (1) { - currId = unkStruct.unk4[gDungeonMenu.menuIndex]; - - if (currId >= 0) { - Entity *entity = gDungeon->teamPokemon[currId]; - - if (EntityIsValid(entity) && prevId != currId) { - if (a1 == 1) { - sub_8062B74(entity); - } - else if (a1 == 2) { - sub_8062CA8(entity); - } - } - prevId = currId; - sub_806A2BC(entity, 0); - ChangeDungeonCameraPos(&entity->pos, 0, 1, 1); - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - - if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { - if (unkStruct.unk14[gDungeonMenu.menuIndex] != 0) { - PlayDungeonConfirmationSE(); - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - bPress = TRUE; - break; - } - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - sub_804AA60(); - sub_806A2BC(GetLeader(), 0); - sub_803EAF0(0, 0); - sub_803E708(4, 0x3E); - if (bPress) { - return NULL; - } - currId = unkStruct.unk4[gDungeonMenu.menuIndex]; - if (teamId != NULL) { - *teamId = currId; - } - if (currId >= 0) { - return gDungeon->teamPokemon[currId]; - } - - return NULL; -} - -void sub_8062B74(Entity *entity) -{ - s32 x, y; - EntityInfo *entInfo = GetEntInfo(entity); - - CallPrepareTextbox_8008C54(2); - sub_80073B8(2); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); - PrintFormattedStringOnWindow(12, 0, gUnknown_80FE978, 2, '\0'); - y = 16; - - if (entInfo->monsterBehavior == 1 || IsExperienceLocked(entInfo->joinedAt.id)) { - PrintFormattedStringOnWindow(12, y, gUnknown_8106C90, 2, '\0'); - } - else { - s32 i; - - for (i = 0; i < MAX_MON_MOVES; i++) { - unkStruct_80928C0 movStruct = {0, 106, 0, 0}; - Move *move = &entInfo->moves.moves[i]; - - if (MoveFlagExists(move)) { - if (entInfo->isTeamLeader) { - movStruct.unk0 = 2; - } - else { - movStruct.unk0 = 4; - } - - movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE); - BufferMoveName(gFormatBuffer_Items[0], move, &movStruct); - - if (MoveFlagLinkChain(move)) { - x = 13; - } - else { - x = 8; - if (i != 0) { - sub_80078A4(2, 12, y - 2, 120, 7); - } - } - PrintFormattedStringOnWindow(x, y, gUnknown_8106C98, 2, '\0'); - y += 12; - } - } - } - - sub_80073E0(2); -} - -void sub_8062CA8(Entity *entity) -{ - s32 x, y; - EntityInfo *entInfo = GetEntInfo(entity); - - CallPrepareTextbox_8008C54(2); - sub_80073B8(2); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); - PrintFormattedStringOnWindow(12, 0, gUnknown_80FE940, 2, '\0'); - x = 8; - y = 18; - - if (entInfo->monsterBehavior == 1 || IsExperienceLocked(entInfo->joinedAt.id)) { - PrintFormattedStringOnWindow(8, y, gUnknown_8106C90, 2, '\0'); - } - else { - Item *item = &entInfo->heldItem; - if (!ItemExists(item)) { - PrintFormattedStringOnWindow(x, y, gUnknown_8106C9C, 2, '\0'); - } - else { - sub_8045C18(gFormatBuffer_Items[0], item); - PrintFormattedStringOnWindow(x, y, gUnknown_8106C98, 2, '\0'); - } - } - - sub_80073E0(2); -} - -void sub_8062D68(void) -{ - gDungeonMenu.unk1E = 0; - gDungeonMenu.unk20 = 0; - gDungeonMenu.unkC = 0; - gDungeonMenu.unkE = 0; - gDungeonMenu.unk14.x = 0; - sub_801317C(&gDungeonMenu.unk28); -} - -u32 sub_8062D88(void) -{ - return A_BUTTON; -} - -void sub_8062D8C(ActionContainer *a0) -{ - s32 id = a0->actionParameters[0].actionUseIndex; - Entity *entityOrg = gDungeon->teamPokemon[id]; - Entity *entityNew = entityOrg; - - while (1) { - s32 i, count, countUntilId; - - countUntilId = 0; - count = 0; - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - if (sub_8071A8C(gDungeon->teamPokemon[i])) { - if (i == id) { - countUntilId = count; - } - count++; - } - } - - sub_806A2BC(entityNew, 0); - ChangeDungeonCameraPos(&entityNew->pos, 0, 1, 1); - SetLeaderActionToNothing(1); - if (ShowDungeonMovesMenu(entityNew, 0, 1, countUntilId, count)) { - return; - } - - if (GetLeaderActionId() == 6) { - s32 idBefore = id; - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - if (++id >= MAX_TEAM_MEMBERS) { - id = 0; - } - entityNew = gDungeon->teamPokemon[id]; - if (sub_8071A8C(entityNew)) { - break; - } - } - - a0->actionParameters[0].actionUseIndex = id; - if (idBefore != id) { - PlayDungeonCursorSE(0); - } - SetLeaderActionToNothing(1); - } - // Everything is the same as in the above if except for add/sub difference. - else if (GetLeaderActionId() == 7) { - s32 idBefore = id; - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - if (--id < 0) { - id = MAX_TEAM_MEMBERS - 1; - } - entityNew = gDungeon->teamPokemon[id]; - if (sub_8071A8C(entityNew)) { - break; - } - } - - a0->actionParameters[0].actionUseIndex = id; - if (idBefore != id) { - PlayDungeonCursorSE(0); - } - SetLeaderActionToNothing(1); - } - else if (GetLeaderActionId() == 29) { - sub_80637E8(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); - } - else if (GetLeaderActionId() == 30) { - sub_803EAF0(0, NULL); - sub_8063A70(GetLeaderActionContainer(), TRUE); - SetLeaderActionToNothing(1); - } - else if (GetLeaderActionId() == 51) { - sub_803EAF0(0, NULL); - sub_8063A70(GetLeaderActionContainer(), FALSE); - SetLeaderActionToNothing(1); - } - else if (GetLeaderActionId() == 31) { - sub_803EAF0(0, NULL); - sub_8063B54(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); - } - else if (GetLeaderActionId() == 33) { - sub_803EAF0(0, NULL); - sub_8063CF0(GetLeaderActionContainer(), TRUE); - SetLeaderActionToNothing(1); - } - - if (GetLeaderActionId() != 0) - break; - } - - sub_806A2BC(entityOrg, 0); - ChangeDungeonCameraPos(&entityOrg->pos, 0, 1, 1); -} - -extern s32 gUnknown_202F2D8; -extern s32 sub_8044FB4(u16 param_1); - -void sub_80633E4(Entity *entity, EntityInfo *entInfo, u8 a2, Windows *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7); -void sub_8063698(Entity *entity, u8 a1, u8 a2); -void sub_80637BC(ActionContainer *a0, s32 a1, s32 a2); -void sub_80637A4(ActionContainer *a0, s32 a1); - -bool8 ShowDungeonMovesMenu(Entity * entity, u8 a1, u8 a2, s32 a3, s32 a4) -{ - s32 i; - bool8 ret; - EntityInfo *entInfo = GetEntInfo(entity); - bool8 unkBool = TRUE; - EntityInfo *leaderInfo = GetEntInfo(GetLeader()); - WindowHeader header; - Windows windows = { - .id = { - [0] = { - .type = WINDOW_TYPE_WITH_HEADER, - .pos = {2, 2}, - .width = 18, - .height = 16, - .unk10 = 16, - .unk12 = 0, - .unk14 = &header, - }, - [1] = WINDOW_DUMMY, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - u8 unk[4]; - bool8 r10; - s32 r5; - bool8 bPress; - - gUnknown_202F2D8 = 0; - for (i = 0; i < MAX_MON_MOVES; i++) { - Move *move = &entInfo->moves.moves[i]; - - if (MoveFlagExists(move) && move->moveFlags2 & 2) { - move->moveFlags2 &= ~(2); - gUnknown_202F2D8 = i; - } - } - - while (1) { - r5 = 0; - ret = FALSE; - r10 = FALSE; - sub_80633E4(entity, entInfo, a1, &windows, &header, unk, a3, a4); - while (1) { - AddMenuCursorSprite_(&gDungeonMenu, unk); - DungeonRunFrameActions(0x1E); - if (gRealInputs.repeated & DPAD_DOWN) { - bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; - s32 id = gDungeonMenu.menuIndex; - - if (rHeld) { - gUnknown_202F2D8 = unk_SetMoveToLastInLinkedSequence4(entInfo->moves.moves, id); - if (id != gUnknown_202F2D8) { - PlayDungeonCursorSE(0); - } - else { - PlayDungeonCancelSE(); - } - r10 = TRUE; - break; - } - else { - sub_8013780(&gDungeonMenu, unk_FindMoveEnabledForAIAfter4(entInfo->moves.moves, id)); - if (id != gDungeonMenu.menuIndex) { - PlayDungeonCursorSE(0); - } - } - } - if (gRealInputs.repeated & DPAD_UP) { - bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; - s32 id = gDungeonMenu.menuIndex; - - if (rHeld) { - gUnknown_202F2D8 = unk_SetMoveToFirstInLinkedSequence4(entInfo->moves.moves, id); - if (id != gUnknown_202F2D8) { - PlayDungeonCursorSE(0); - } - else { - PlayDungeonCancelSE(); - } - r10 = TRUE; - break; - } - else { - sub_8013780(&gDungeonMenu, sub_8092DB8(entInfo->moves.moves, id)); - if (id != gDungeonMenu.menuIndex) { - PlayDungeonCursorSE(0); - } - } - } - - if ((gRealInputs.repeated & DPAD_RIGHT) || gDungeonMenu.unk28.dpad_right) { - SetMonsterActionFields(&leaderInfo->action, 6); - break; - } - if ((gRealInputs.repeated & DPAD_LEFT) || gDungeonMenu.unk28.dpad_left) { - SetMonsterActionFields(&leaderInfo->action, 7); - break; - } - - if ((gRealInputs.pressed & sub_8062D88()) || gDungeonMenu.unk28.a_button) { - if (a1) { - bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; - if (rHeld) { - r5 = 3; - } - } - PlayDungeonConfirmationSE(); - break; - } - - if (gRealInputs.pressed & START_BUTTON) { - r5 = 1; - PlayDungeonStartButtonSE(); - break; - } - if (gRealInputs.pressed & SELECT_BUTTON) { - r5 = 2; - PlayDungeonStartButtonSE(); - break; - } - // Fixme: r0/r1 regswap... - { - u32 bPressed = B_BUTTON; - bPressed &= gRealInputs.pressed; - if ((bPressed) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - ret = TRUE; - break; - } - } - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1E); - if (leaderInfo->action.action == 6 || leaderInfo->action.action == 7) { - unkBool = FALSE; - break; - } - - if (r10) - continue; - if (ret) - break; - - gUnknown_202F2D8 = gDungeonMenu.menuIndex; - if (r5 == 1) { - SetMonsterActionFields(&leaderInfo->action, 0x1D); - leaderInfo->action.actionParameters[0].actionUseIndex = entity->unk24; - leaderInfo->action.actionParameters[1].actionUseIndex = gUnknown_202F2D8; - sub_803EAF0(0, NULL); - sub_803E708(8, 0x1B); - ret = FALSE; - break; - } - - sub_8063698(entity, a1, a2); - if (r5 == 3) { - s32 r6 = sub_8044FB4(0x20); - if (!CanSubMenuItemBeChosen(r6)) { - r6 = sub_8044FB4(0x21); - if (CanSubMenuItemBeChosen(r6)) { - sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); - break; - } - } - else { - sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); - break; - } - } - else if (r5 == 2) { - if (entInfo->isTeamLeader) { - s32 r6 = sub_8044FB4(0x1E); - if (!CanSubMenuItemBeChosen(r6)) { - r6 = sub_8044FB4(0x33); - if (CanSubMenuItemBeChosen(r6)) { - sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); - break; - } - } - else { - sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); - break; - } - } - else { - s32 r6 = sub_8044FB4(0x1F); - if (CanSubMenuItemBeChosen(r6)) { - sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); - break; - } - } - } - - sub_8009524(2); - CreateDungeonMenuSubWindow(&windows.id[0], 0x16); - while (1) { - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (gRealInputs.repeated & DPAD_DOWN) { - PlayDungeonCursorSE(1); - MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); - } - if (gRealInputs.repeated & DPAD_UP) { - PlayDungeonCursorSE(1); - MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); - } - - if ((gRealInputs.pressed & sub_8062D88()) || gDungeonMenu.unk28.a_button) { - if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { - sub_80637A4(&leaderInfo->action, GetTeamMemberEntityIndex(entity)); - if (leaderInfo->action.action != 20 && leaderInfo->action.action != 21) { - PlayDungeonConfirmationSE(); - } - bPress = FALSE; - break; - } - PlayDungeonCancelSE(); - } - if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { - PlayDungeonCancelSE(); - bPress = TRUE; - break; - } - } - - AddMenuCursorSprite(&gDungeonMenu); - DungeonRunFrameActions(0x1B); - if (bPress != TRUE) { - ret = 0; - break; - } - } - - if (unkBool) { - sub_803EAF0(0, NULL); - sub_803E708(8, 0x1E); - } - - return ret; -} - -extern const Window gUnknown_8106CAC; -void sub_8063578(s32 a0, Entity *entity, Moves *moves, s32 a3, u8 a4, s32 a5); -extern const u8 *const gUnknown_80FDFE8; - -void sub_80633E4(Entity *entity, EntityInfo *entInfo, u8 a2, Windows *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7) -{ - s32 i, movesCount; - Window windowNew = gUnknown_8106CAC; - - header->f0 = arg7; - header->f1 = arg6; - header->f3 = 0; - - movesCount = 0; - for (i = 0; i < MAX_MON_MOVES; i++) { - Move *move = &entInfo->moves.moves[i]; - if (MoveFlagExists(move)) { - movesCount++; - } - } - - gDungeonMenu.menuIndex = gUnknown_202F2D8; - gDungeonMenu.unk1A = movesCount; - gDungeonMenu.unk1C = 4; - gDungeonMenu.unk1E = arg6; - gDungeonMenu.unk20 = arg7; - gDungeonMenu.unk4 = 0; - gDungeonMenu.firstEntryY = 16; - gDungeonMenu.unk14.x = 0; - gDungeonMenu.unk0 = 0; - sub_801317C(&gDungeonMenu.unk28); - - windows->id[0].height = windows->id[0].unk10 = sub_80095E4(4, 0xC) + 2; - header->f2 = 13; - windows->id[0].pos.x = 2; - windows->id[1] = windows->id[3]; - windows->id[2] = windowNew; - DungeonShowWindows(windows, TRUE); - sub_80137B0(&gDungeonMenu, 0); - gDungeonMenu.unkC = (gUnknown_2027370[0].unk0 + 16) * 8; - gDungeonMenu.unkE = ((gUnknown_2027370[0].unk2 + 1) * 8) - 2; - SetMessageArgument_2(gFormatBuffer_Monsters[0], entInfo, 0); - for (i = 0; i < MAX_MON_MOVES; i++) { - Move *move = &entInfo->moves.moves[i]; - - arg5[i] = 0; - if (!MoveFlagExists(move)) { - if (gDungeonMenu.menuIndex == i) { - gDungeonMenu.menuIndex = 0; - } - } - else if (MoveFlagLinkChain(move)) { - arg5[i] = 1; - } - } - - sub_8063578(4, entity, &entInfo->moves, 0, a2, arg6); - sub_80073B8(2); - PrintFormattedStringOnWindow(4, 0, gUnknown_80FDFE8, 2, '\0'); - sub_80073E0(2); -} - -extern const u8 gUnknown_8106CC4[]; - -void sub_8063578(s32 count, Entity *entity, Moves *moves, s32 windowId, u8 a4, s32 a5) -{ - s32 i; - EntityInfo *entInfo = GetEntInfo(entity); - - sub_80073B8(windowId); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); - PrintFormattedStringOnWindow((a5 * 8) + 10, 0, gUnknown_80FE978, windowId, '\0'); - for (i = 0; i < count; i++) { - s32 x, y; - unkStruct_80928C0 movStruct = {0, 106, 0, a4}; - Move *move = &moves->moves[i]; - - if (MoveFlagExists(move)) { - if (entInfo->isTeamLeader) { - movStruct.unk0 = 2; - } - else { - movStruct.unk0 = 4; - } - - movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE); - BufferMoveName(gFormatBuffer_Items[0], move, &movStruct); - y = GetMenuEntryYCoord(&gDungeonMenu, i); - if (MoveFlagLinkChain(move)) { - x = 13; - } - else { - x = 8; - if (i != 0) { - sub_80078A4(windowId, 12, y - 2, 120, 7); - } - } - PrintFormattedStringOnWindow(x, y, gUnknown_8106CC4, windowId, '\0'); - } - } - - sub_80073E0(windowId); -} - -bool8 sub_8063C88(EntityInfo *entInfo, s32 a1); -bool8 sub_8063DD4(EntityInfo *entInfo, s32 a1); - -void sub_8063698(Entity *entity, u8 a1, u8 a2) -{ - EntityInfo *entInfo = GetEntInfo(entity); - Move *move = &entInfo->moves.moves[gUnknown_202F2D8]; - - gDungeonSubMenuItemsCount = 0; - if (entInfo->isTeamLeader) { - if (a2) { - sub_8044F5C(0x14, 0); - } - if (MoveFlagExists(move)) { - if (MoveFlagSet(move)) { - sub_8044F5C(0x33, 0); - } - else { - sub_8044F5C(0x1E, 0); - } - } - } - else { - sub_8044F5C(0x1F, 0); - } - - if (a1) { - sub_8044F5C(0x20, 0); - sub_8044F5C(0x21, 0); - } - sub_8044F5C(0x1D, 0); - if (!a1) { - sub_8044FF0(0x20); - } - else { - if (!sub_8063C88(entInfo, gUnknown_202F2D8)) { - sub_8044FF0(0x20); - } - if (!sub_8063DD4(entInfo, gUnknown_202F2D8)) { - sub_8044FF0(0x21); - } - } - - if (!sub_8063DD4(entInfo, gUnknown_202F2D8)) { - sub_8044FF0(0x21); - } - - if (a2) { - bool8 unkBool = FALSE; - if (gUnknown_202F2D8 < MAX_MON_MOVES) { - unkBool = CanAIUseMove(entity, gUnknown_202F2D8, TRUE) != FALSE; - } - if (!unkBool) { - sub_8044FF0(0x14); - } - } - - sub_8045064(); -} - -void sub_80637A4(ActionContainer *a0, s32 a1) -{ - sub_80637BC(a0, gDungeonMenu.menuIndex, a1); -} - -void sub_80637BC(ActionContainer *a0, s32 a1, s32 a2) -{ - SetMonsterActionFields(a0, gUnknown_202EE44[a1].unk0); - a0->actionParameters[0].actionUseIndex = a2; - a0->actionParameters[1].actionUseIndex = gUnknown_202F2D8; -} - -void sub_8063834(Move *moves, s32 a1, s32 a2); - -void sub_80637E8(ActionContainer *a0) -{ - Entity *mon = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; - EntityInfo *monInfo = GetEntInfo(mon); - - monInfo->moves.moves[a0->actionParameters[1].actionUseIndex].moveFlags2 |= 2; - sub_8063834(monInfo->moves.moves, a0->actionParameters[1].actionUseIndex, 4); -} - -// diff --git a/src/code_805D8C8_3.c b/src/code_805D8C8_3.c new file mode 100644 index 000000000..a5dfa4b40 --- /dev/null +++ b/src/code_805D8C8_3.c @@ -0,0 +1,2253 @@ +#include "global.h" +#include "globaldata.h" +#include "structs/str_dungeon.h" +#include "number_util.h" +#include "input.h" +#include "structs/map.h" +#include "dungeon_main.h" +#include "dungeon_message.h" +#include "dungeon_action.h" +#include "dungeon_ai_targeting.h" +#include "dungeon_pokemon_attributes.h" +#include "dungeon_random.h" +#include "dungeon_util.h" +#include "pokemon.h" +#include "moves.h" +#include "items.h" +#include "dungeon_music.h" +#include "dungeon_ai_movement.h" +#include "code_8045A00.h" +#include "string_format.h" +#include "code_803E46C.h" +#include "code_801602C.h" +#include "code_800D090.h" +#include "trap.h" +#include "charge_move.h" +#include "dungeon_map_access.h" +#include "status_checks_1.h" +#include "game_options.h" +#include "weather.h" +#include "dungeon_items.h" +#include "dungeon_leader.h" +#include "tile_types.h" +#include "dungeon_visibility.h" +#include "dungeon_movement.h" +#include "bg_control.h" +#include "menu_input.h" +#include "music.h" +#include "items.h" +#include "play_time.h" +#include "pokemon_3.h" +#include "text.h" +#include "code_806CD90.h" +#include "code_8044CC8.h" +#include "code_801B3C0.h" +#include "dungeon_capabilities.h" +#include "constants/dungeon.h" +#include "constants/status.h" +#include "constants/tactic.h" +#include "constants/iq_skill.h" +#include "constants/dungeon_action.h" +#include "structs/struct_sub80095e4.h" +#include "structs/str_text.h" + +extern void HandleSetItemAction(Entity *,bool8); +extern void HandleUnsetItemAction(Entity *,bool8); +extern bool8 sub_8048A68(Entity *param_1,Item *item); +extern bool8 sub_8048950(Entity *param_1,Item *item); +extern bool8 sub_8048B9C(Entity *param_1,Item *item); +extern Item *sub_8044D90(Entity *, s32, u32); +extern void PlayDungeonStartButtonSE(void); +extern void PlayDungeonCancelSE(void); +extern void PlayDungeonConfirmationSE(void); +extern void sub_806A6E8(Entity *); +extern bool8 sub_8047084(s32 itemFlag); +extern void HandleTrap(Entity *pokemon, DungeonPos *pos, int param_3, char param_4); +extern void sub_8045DB4(DungeonPos *, u32); +bool8 sub_807EF48(void); +void sub_806A2BC(Entity *a0, u8 a1); +bool8 sub_805E874(void); +bool8 sub_80701A4(Entity *a0); +void ShowDungeonStairsMenu(Entity *a0); +void sub_805E738(Entity *a0); +void sub_803E708(s32 a0, s32 a1); +void sub_8040A78(void); +void sub_805E804(void); +void ShowDungeonOthersMenu(void); +void sub_8075680(u32); +void sub_8094C88(void); +void sub_8040A84(void); +void sub_8047158(void); +void sub_806A914(u8 a0, u8 a1, u8 a2); +void SetLeaderActionToNothing(u8 a0); +u16 GetLeaderActionId(void); +void sub_80978C8(s16 a0); +bool8 sub_8094C48(void); +bool8 sub_805EC4C(Entity *a0, u8 a1); +void sub_803E724(s32 a0); +void HandleTalkFieldAction(Entity *); +bool8 sub_8044B28(void); +bool8 IsNotAttacking(Entity *param_1, bool8 param_2); +void ShowMainMenu(bool8 fromBPress, bool8 a1); +bool8 sub_805EF60(Entity *a0, EntityInfo *a1); +s32 GetTeamMemberEntityIndex(Entity *pokemon); +bool8 sub_8070F80(Entity * pokemon, s32 direction); +void PrintOnMainMenu(bool8 printAll); +bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1); +void sub_8060D24(UNUSED ActionContainer *a0); +bool8 ShowDungeonTeamMenu(Entity *a0); +void sub_8062D8C(ActionContainer *a0); +void sub_80637E8(ActionContainer *a0); +void sub_8063B54(ActionContainer *a0); +void sub_8063BB4(ActionContainer *a0); +void sub_806752C(ActionContainer *a0); +void sub_8061A38(ActionContainer *a0, bool8 a1); +void sub_8063A70(ActionContainer *a0, bool8 a1); +void sub_8063CF0(ActionContainer *a0, bool8 a1); +void sub_8067768(ActionContainer *a0); +void ShowTacticsMenu(ActionContainer *a0); +void ChangeDungeonCameraPos(DungeonPos *pos, s32 a1, u8 a2, u8 a3); +extern bool8 sub_8071A8C(Entity *pokemon); +extern void sub_80643AC(Entity *pokemon); +extern bool8 ShowDungeonMovesMenu(Entity * entity, u8 a1, u8 a2, s32 a3, s32 a4); + +extern u8 gUnknown_202EE00; +extern Entity *gLeaderPointer; + +extern const u8 *gUnknown_80F8A84; +extern const u8 *gUnknown_80F8A6C; +extern const u8 *gUnknown_80F8ADC; +extern const u8 *gUnknown_80F8AB0; +extern const u8 *gUnknown_80F8B0C; +extern const u8 *gUnknown_80FD4B0; +extern const u8 *gUnknown_80F8A4C; +extern const u8 *gUnknown_80F8A28; +extern const u8 *gUnknown_8100208; +extern const u8 *gUnknown_80F9BD8; +extern const u8 *gUnknown_80F9C08; +extern const u8 *gUnknown_80F9C2C; +extern const u8 *gUnknown_80F9BB0; +extern const u8 *gUnknown_80FDE18; +extern const u8 *gUnknown_80F8B24; +extern const u8 *gTeamToolboxAPtr; +extern const u8 *gTeamToolboxBPtr; +extern const u8 *gFieldItemMenuGroundTextPtr; +extern const u8 *gUnknown_80FE940; +extern const u8 *gWhichTextPtr1; +extern const u8 *const gFieldMenuMovesPtr; +extern const u8 *const gFieldMenuItemsPtr; +extern const u8 *const gFieldMenuTeamPtr; +extern const u8 *const gFieldMenuOthersPtr; +extern const u8 *const gFieldMenuGroundPtr; +extern const u8 *const gUnknown_80F9174; +extern const u8 *const gUnknown_80F9190; +extern const u8 *const gUnknown_80F91C8; +extern const u8 *const gUnknown_80F91E0; +extern const u8 *const gUnknown_80F91A8; +extern const u8 *const gUnknown_80FE954; + +extern bool8 sub_8070F14(Entity * pokemon, s32 direction); +bool8 sub_805EC2C(Entity *a0, s32 x, s32 y); +extern Entity *sub_80696A8(Entity *a0); +extern u8 sub_806A538(s32); +extern void sub_803EAF0(u32, u8 *); +extern void sub_803F508(Entity *); +extern void sub_8041AD0(Entity *pokemon); +extern void sub_8041AE0(Entity *pokemon); +extern void sub_807EC28(bool8); +extern void PlayDungeonCursorSE(u8 param_1); +extern u8 *GetDungeonSubMenuItemString(s32 param_1); +extern bool8 CanSubMenuItemBeChosen(s32 param_1); +extern s32 gDungeonSubMenuItemsCount; +extern const u8 gUnknown_8106B50[]; +extern void DungeonShowWindows(Windows *a0, u8 a1); +extern Item * sub_8044CC8(Entity *param_1, ActionParameter *param_2, UNUSED s32 a3); +extern void sub_8044F5C(u16 param_1, u8 param_2); +extern void sub_8044FF0(u16 param_1); +extern u16 sub_8044DC8(Item *param_1); +extern bool8 sub_8046F00(Item *item); +extern void sub_8045064(void); + +void PrintMonTactics(s32 a0, u8 *tacticIds, EntityInfo *mon, s32 windowId); +void sub_80623B0(void); +void sub_8062D68(void); +void sub_8062230(void); +void sub_8062748(u8 a0); + +extern MenuInputStruct gDungeonMenu; +extern WindowHeader gUnknown_202F270; + +s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4); + +void sub_8060890(DungeonPos *a0); +bool8 sub_8060860(s32 a0); +void sub_8060900(Entity *a0); +s32 sub_8060800(WindowHeader *a0, s32 a1); +void ChosenSubMenuToAction(ActionContainer *a0); +Entity *DrawFieldGiveItemMenu(s32 *teamId, s32 a1); + +static UNUSED EWRAM_DATA u8 sUnused3[4] = {0}; +EWRAM_DATA s32 gTeamMenuChosenId = 0; +static UNUSED EWRAM_DATA u8 sUnused4[4] = {0}; + +EWRAM_INIT u8 gUnknown_203B43C[4] = {2, 0, 0xD, 0}; // TODO: Move to a better file and figure out the array count. Apparently it's only written to. + +extern void sub_8069844(struct unkStruct_808FF20 *param_1, Entity *target); +extern u32 sub_8014140(s32 a0, const void *a1); +void sub_806285C(s32 a0); +void sub_806262C(u8 iqSkillId); + +extern const u8 gUnknown_8106B8C[]; + +extern WindowHeader gUnknown_202F270; + +struct UnkFieldTeamMenuStruct +{ + s32 unk0; + s32 unk4[MAX_TEAM_MEMBERS]; + u8 unk14[MAX_TEAM_MEMBERS]; +}; + +void PrintOnDungeonTeamMenu(struct UnkFieldTeamMenuStruct *a0, Windows *a1, bool8 a2); +void sub_806145C(struct UnkFieldTeamMenuStruct *a0); +void sub_80615B4(ActionContainer *a0, struct UnkFieldTeamMenuStruct *a1); + +extern u8 gUnknown_202EE39; + +bool8 ShowDungeonTeamMenu(Entity *a0) +{ + s32 i; + bool32 r10, ret; + struct UnkFieldTeamMenuStruct sp; + Windows windows = { + .id = { + [0] = { + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 14, + .height = 16, + .unk10 = 16, + .unk12 = 0, + .unk14 = &gUnknown_202F270, + }, + [1] = WINDOW_DUMMY, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + Entity *teamMon = gDungeon->teamPokemon[i]; + if (EntityIsValid(teamMon)) { + GetEntInfo(teamMon)->unk157 = TRUE; + } + } + + if (!gDungeon->unk644.unk17) { + windows.id[0].type = WINDOW_TYPE_NORMAL; + windows.id[0].pos.y++; + } + + while (1) { + s32 id; + bool32 r4; + + ret = FALSE; + PrintOnDungeonTeamMenu(&sp, &windows, TRUE); + r10 = FALSE; + while (1) { + s32 id = sp.unk4[gDungeonMenu.menuIndex]; + if (id >= 0) { + Entity *teamMon = gDungeon->teamPokemon[id]; + sub_806A2BC(teamMon, 0); + ChangeDungeonCameraPos(&teamMon->pos, 0, 1, 1); + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.pressed & START_BUTTON) { + if (sp.unk14[gDungeonMenu.menuIndex] != 0) { + PlayDungeonStartButtonSE(); + r10 = TRUE; + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) + { + if (sp.unk14[gDungeonMenu.menuIndex] != 0) { + PlayDungeonConfirmationSE(); + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + ret = TRUE; + break; + } + } + + id = sp.unk4[gDungeonMenu.menuIndex]; + if (id >= 0) { + Entity *teamMon = gDungeon->teamPokemon[id]; + sub_806A2BC(teamMon, 0); + ChangeDungeonCameraPos(&teamMon->pos, 0, 1, 1); + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + sub_804AA60(); + if (ret) { + break; + } + + sp.unk0 = gDungeonMenu.menuIndex; + gTeamMenuChosenId = gDungeonMenu.menuIndex; + sub_806145C(&sp); + if (r10) { + EntityInfo *info = GetEntInfo(a0); + SetMonsterActionFields(&info->action, 0x1B); + info->action.actionParameters[0].actionUseIndex = sp.unk4[sp.unk0]; + ret = FALSE; + break; + } + + CreateDungeonMenuSubWindow(&windows.id[0], 0x12); + while (1) { + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { + sub_80615B4(&GetEntInfo(a0)->action, &sp); + PlayDungeonConfirmationSE(); + r4 = FALSE; + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + r4 = TRUE; + break; + } + } + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (r4 != TRUE) { + ret = FALSE; + break; + } + } + + if (ret) { + sub_806A2BC(GetLeader(), 0); + } + sub_803EAF0(0, NULL); + return ret; +} + +bool32 sub_8069D18(DungeonPos *a0, Entity *a1); + +extern const u8 gTeamFormat[]; +extern const u8 gHeartRedTiny[]; +extern const u8 gHeartRedSmall[]; +extern const u8 gHeartRedMedium[]; +extern const u8 gHeartRedLarge[]; +extern const u8 gHeartYellowTiny[]; +extern const u8 gHeartYellowSmall[]; +extern const u8 gHeartYellowMedium[]; +extern const u8 gHeartYellowLarge[]; +extern const u8 gUnknown_8106BD4[]; +extern const u8 gUnknown_8106BE0[]; +extern const u8 gUnknown_8106BEC[]; +extern const u8 gUnknown_8106BF4[]; + +extern void sub_8070968(u8 *buffer, EntityInfo *entityInfo, s32 colorNum); + +void PrintOnDungeonTeamMenu(struct UnkFieldTeamMenuStruct *a0, Windows *windows, bool8 a2) +{ + s32 r0; + DungeonPos pos; + s32 i; + + s32 count = 0; + bool8 r10 = (windows->id[0].type == WINDOW_TYPE_WITH_HEADER); + + sub_8069D18(&pos, GetLeader()); + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + EntityInfo *monInfo; + Entity *teamMon = gDungeon->teamPokemon[i]; + if (EntityIsValid(teamMon)) { + a0->unk4[count] = i; + monInfo = GetEntInfo(teamMon); + a0->unk14[count] = monInfo->unk157; + if (pos.x == teamMon->pos.x && pos.y == teamMon->pos.y && gTeamMenuChosenId < 0) { + gTeamMenuChosenId = count; + } + count++; + } + } + + if (gTeamMenuChosenId >= count) { + gTeamMenuChosenId = count - 1; + } + if (gTeamMenuChosenId < 0) { + gTeamMenuChosenId = 0; + } + + for (i = count; i < MAX_TEAM_MEMBERS; i++) { + a0->unk4[i] = -1; + a0->unk14[i] = 0; + } + + gUnknown_202F270.f0 = 1; + gUnknown_202F270.f1 = 0; + gUnknown_202F270.f3 = 0; + gDungeonMenu.menuIndex = gTeamMenuChosenId; + gDungeonMenu.unk1A = count; + gDungeonMenu.unk1C = count; + gDungeonMenu.unk1E = 0; + gDungeonMenu.unk20 = 0; + gDungeonMenu.unk4 = 0; + gDungeonMenu.firstEntryY = (r10 != FALSE) * 16; + gDungeonMenu.unkC = 0; + gDungeonMenu.unkE = 0; + gDungeonMenu.unk14.x = 0; + gDungeonMenu.unk0 = 0; + sub_801317C(&gDungeonMenu.unk28); + r0 = sub_80095E4(count, 0); + if (r10) { + r0 += 2; + } + windows->id[0].unk10 = r0; + windows->id[0].height = r0; + gUnknown_202F270.f2 = 8; + if (a2) { + windows->id[1] = windows->id[3]; + } + + DungeonShowWindows(windows, 1); + sub_80137B0(&gDungeonMenu, 0); + sub_80073B8(0); + if (r10) { + PrintFormattedStringOnWindow(0xC, 0, gTeamFormat, 0, 0); + } + + // Print hp/max hp + for (i = 0; i < count; i++) { + s32 y; + s32 id = a0->unk4[i]; + if (id >= 0) { + Entity *teamMon = gDungeon->teamPokemon[id]; + if (EntityIsValid(teamMon)) + { + EntityInfo *monInfo = GetEntInfo(teamMon); + s32 color = (a0->unk14[i] != 0) ? 6 : 2; + + sub_8070968(gFormatBuffer_Monsters[0], monInfo, color); + if (sub_806A538(gRecruitedPokemonRef->pokemon2[monInfo->teamIndex].unkA)) { + if (monInfo->HP <= monInfo->maxHPStat / 4) { + strcpy(gFormatBuffer_Monsters[1], gHeartRedTiny); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { + strcpy(gFormatBuffer_Monsters[1], gHeartRedSmall); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { + strcpy(gFormatBuffer_Monsters[1], gHeartRedMedium); + } + else { + strcpy(gFormatBuffer_Monsters[1], gHeartRedLarge); + } + } + else { + if (monInfo->HP <= monInfo->maxHPStat / 4) { + strcpy(gFormatBuffer_Monsters[1], gHeartYellowTiny); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { + strcpy(gFormatBuffer_Monsters[1], gHeartYellowSmall); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { + strcpy(gFormatBuffer_Monsters[1], gHeartYellowMedium); + } + else { + strcpy(gFormatBuffer_Monsters[1], gHeartYellowLarge); + } + } + + gFormatArgs[0] = monInfo->HP; + gFormatArgs[1] = monInfo->maxHPStat; + y = GetMenuEntryYCoord(&gDungeonMenu, i); + if (monInfo->isTeamLeader) { + PrintFormattedStringOnWindow(9, y, gUnknown_8106BD4, 0, 0); + } + else { + PrintFormattedStringOnWindow(9, y, gUnknown_8106BE0, 0, 0); + } + } + } + } + + sub_80073E0(0); +} + +extern bool8 CanLeaderSwitch(u8 dungeon); + +void sub_806145C(struct UnkFieldTeamMenuStruct *a0) +{ + Entity *teamMon; + EntityInfo *monInfo; + + gDungeonSubMenuItemsCount = 0; + teamMon = gDungeon->teamPokemon[a0->unk4[gDungeonMenu.menuIndex]]; + monInfo = GetEntInfo(teamMon); + sub_8044F5C(0x1B, 0); + sub_8044F5C(0x19, 0); + if (!monInfo->isTeamLeader) { + if (!gDungeon->unk644.unk19 && (monInfo->joinedAt.id != DUNGEON_JOIN_LOCATION_PARTNER || gDungeon->unk644.unk18)) { + sub_8044F5C(0x34, 0); + } + sub_8044F5C(0x1C, 0); + } + sub_8044F5C(0x30, 0); + if (!monInfo->isTeamLeader) { + sub_8044F5C(0x1A, 0); + } + if (!monInfo->isTeamLeader && gDungeon->unk644.unk18 && CanLeaderSwitch(gDungeon->unk644.dungeonLocation.id)) { + bool32 r5; + + sub_8044F5C(0x3B, 0); + r5 = TRUE; + if (monInfo->teamIndex >= MAX_TEAM_MEMBERS) { + r5 = FALSE; + } + else { + PokemonStruct2 *mon = &gRecruitedPokemonRef->pokemon2[monInfo->teamIndex]; + if (sub_806A538(mon->unkA)) { + r5 = FALSE; + } + } + + if (CheckVariousStatuses2(teamMon, FALSE)) { + r5 = FALSE; + } + if (!r5) { + sub_8044FF0(0x3B); + } + } + + if (IsExperienceLocked(monInfo->joinedAt.id)) { + sub_8044FF0(0x19); + sub_8044FF0(0x3B); + sub_8044FF0(0x1A); + sub_8044FF0(0x30); + sub_8044FF0(0x34); + } + + sub_8045064(); +} + +void sub_80615B4(ActionContainer *a0, struct UnkFieldTeamMenuStruct *a1) +{ + SetMonsterActionFields(a0, gUnknown_202EE44[gDungeonMenu.menuIndex].unk0); + a0->actionParameters[0].actionUseIndex = a1->unk4[a1->unk0]; +} + +void PrintMonTactics(s32 a0, u8 *tacticIds, EntityInfo *mon, s32 windowId); +void sub_80623B0(void); +void sub_8062D68(void); +void sub_8062230(void); +void sub_8062748(u8 a0); + +void ShowTacticsMenu(ActionContainer *a0) +{ + Windows windows = { + .id = { + [0] = { + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 18, + .height = 14, + .unk10 = 18, + .unk12 = 2, + .unk14 = &gUnknown_202F270, + }, + [1] = WINDOW_DUMMY, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + EntityInfo *monInfo; + u8 tacticIds[NUM_TACTICS]; + s32 scrollFirstId; + s32 menuIndex; + Entity *teamMon; + + teamMon = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; + monInfo = GetEntInfo(teamMon); + menuIndex = 0; + scrollFirstId = 0; + while (1) { + s32 i; + bool32 addCursor = TRUE; + bool32 loopBreak = FALSE; + + gUnknown_202F270.f0 = 1; + gUnknown_202F270.f1 = 0; + gUnknown_202F270.f2 = 10; + gUnknown_202F270.f3 = 0; + DungeonShowWindows(&windows, 1); + PrintMonTactics(scrollFirstId, tacticIds, monInfo, 0); + for (i = 0; i < 8; i++) { + if (tacticIds[i] == TACTIC_UNUSED) + break; + } + gDungeonMenu.unk1A = i; + gDungeonMenu.unk1C = 8; + gDungeonMenu.unk1E = 0; + gDungeonMenu.unk20 = 0; + gDungeonMenu.unk4 = 0; + gDungeonMenu.firstEntryY = 16; + gDungeonMenu.unkC = 0; + gDungeonMenu.unkE = 0; + gDungeonMenu.unk14.x = 0; + gDungeonMenu.unk0 = 0; + sub_801317C(&gDungeonMenu.unk28); + sub_80137B0(&gDungeonMenu, 0); + gDungeonMenu.menuIndex = menuIndex; + while (1) { + s32 i; + + AddMenuCursorSprite(&gDungeonMenu); + if (tacticIds[8] != TACTIC_UNUSED) { + sub_80623B0(); + } + if (scrollFirstId != 0) { + sub_8062230(); + } + DungeonRunFrameActions(0x3D); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + if (gDungeonMenu.menuIndex == 7) { + if (tacticIds[8] != TACTIC_UNUSED) { + for (i = 0; i < 6; i++) { + gIwramTextFunc1(0); + DungeonRunFrameActions(0x3D); + } + scrollFirstId++; + } + menuIndex = 7; + break; + } + MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + if (gDungeonMenu.menuIndex == 0) { + if (scrollFirstId != 0) { + for (i = 0; i < 6; i++) { + gIwramTextFunc2(0); + DungeonRunFrameActions(0x3D); + } + scrollFirstId--; + } + menuIndex = 0; + break; + } + MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); + } + if (gRealInputs.pressed & START_BUTTON) { + u32 tacticId = tacticIds[gDungeonMenu.menuIndex]; + menuIndex = gDungeonMenu.menuIndex; + PlayDungeonStartButtonSE(); + sub_8062748(tacticId); + loopBreak = FALSE; + break; + } + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + bool32 changed; + + u32 tacticId = tacticIds[gDungeonMenu.menuIndex]; + menuIndex = gDungeonMenu.menuIndex; + sub_8062D68(); + PlayDungeonConfirmationSE(); + gDungeonSubMenuItemsCount = 0; + sub_8044F5C(0x2F, 0); + sub_8044F5C(0xC, 0); + if (CheckVariousStatuses2(teamMon, TRUE)) { + sub_8044FF0(0x2F); + } + CreateDungeonMenuSubWindow(&windows.id[0], 0x16); + while (1) { + changed = FALSE; + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x3D); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { + changed = TRUE; + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + changed = FALSE; + break; + } + } + if (changed) { + PlayDungeonConfirmationSE(); + if (gDungeonMenu.menuIndex == 0) { + PlaySoundEffect(0x133); + monInfo->tactic = tacticId; + monInfo->aiTarget.aiObjective = 6; + monInfo->aiTarget.aiTarget = NULL; + monInfo->aiTarget.unkC = 0; + monInfo->aiTarget.aiTargetSpawnGenID = 0; + if (!monInfo->isTeamLeader) { + AIMovement(teamMon, TRUE); + } + } + else { + sub_8062748(tacticId); + addCursor = FALSE; + } + } + loopBreak = FALSE; + break; + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + loopBreak = TRUE; + break; + } + } + + if (addCursor) { + AddMenuCursorSprite(&gDungeonMenu); + } + DungeonRunFrameActions(0x3D); + if (loopBreak) + break; + } + sub_803EAF0(0, NULL); +} + +extern void GetAvailTacticsforLvl(u8 *tacticsBuffer, s32 pokeLevel); + +void PrintMonTactics(s32 firstId, u8 *tacticIds, EntityInfo *mon, s32 windowId) +{ + u8 tacticsBuffer[NUM_TACTICS]; + u32 tactic; + s32 y, i, j; + + firstId--; + sub_80073B8(windowId); + PrintStringOnWindow(0x10, 0, gUnknown_80FE954, windowId, 0); + y = 0x14; + for (j = 0; j < 9; j++) { + tacticIds[j] = TACTIC_UNUSED; + } + GetAvailTacticsforLvl(tacticsBuffer, GetLeaderInfo()->level); + for (i = -1; i < 10; i++, y += 12, firstId++) { + if (firstId < 0) + continue; + if (firstId >= NUM_TACTICS) + continue; + + tactic = tacticsBuffer[firstId]; + if (i >= 0 && i < 9) { + tacticIds[i] = tactic; + } + if (tactic == TACTIC_UNUSED) + break; + + CopyTacticsNameToBuffer(gFormatBuffer_Monsters[0], tactic); + if (mon->tactic == tactic) { + PrintFormattedStringOnWindow(0x10, y, gUnknown_8106BEC, windowId, 0); + } + else { + PrintFormattedStringOnWindow(0x10, y, gUnknown_8106BF4, windowId, 0); + } + } + + sub_80073E0(windowId); +} + +void sub_8061A38(ActionContainer *a0, bool8 a1) +{ + s32 spArr[6]; + struct unkStruct_808FF20 unkMonStruct; + struct UnkInfoTabStruct unkInfoTabStruct; + Windows windows = { + .id = { + [0] = { + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 18, + .height = 14, + .unk10 = 18, + .unk12 = 2, + .unk14 = &gUnknown_202F270, + }, + [1] = WINDOW_DUMMY, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + s32 r8; + Entity *entity; + s32 var_3C; + s32 var_38; + EntityInfo *entityInfo; + + var_3C = 0; + r8 = 0; + entity = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; + entityInfo = GetEntInfo(entity); + + if (IsExperienceLocked(entityInfo->joinedAt.id)) { + spArr[0] = 1; + spArr[1] = 0; + spArr[2] = 0; + spArr[3] = 0; + spArr[4] = 0; + spArr[5] = 0; + var_38 = 1; + } + else if (a1) { + spArr[0] = 4; + spArr[1] = 0; + spArr[2] = 0; + spArr[3] = 0; + spArr[4] = 0; + spArr[5] = 0; + var_38 = 1; + } + else { + spArr[0] = 2; + spArr[1] = 1; + spArr[2] = 3; + spArr[3] = 5; + spArr[4] = 0; + spArr[5] = 0; + var_38 = 4; + } + + unkMonStruct.unk40 = 0; + unkMonStruct.unk56 = 0; + gDungeonMenu.menuIndex = 0; + + while (1) { + bool8 loopBreak = FALSE; + s32 var_30 = 0; + s32 var_2C = 0; + s32 var_28 = 1; + UnkTextStruct1 *unkTxtStr1Ptr = &gUnknown_2027370[0]; + + gUnknown_202F270.f0 = var_38; + gUnknown_202F270.f1 = var_3C; + gUnknown_202F270.f2 = 10; + gUnknown_202F270.f3 = 0; + DungeonShowWindows(&windows, TRUE); + sub_8069844(&unkMonStruct, entity); + CreatePokemonInfoTabScreen(spArr[var_3C], var_3C, &unkMonStruct, &unkInfoTabStruct, 0); + gDungeonMenu.unk1E = var_3C; + gDungeonMenu.unk20 = var_38; + gDungeonMenu.unkC = (unkTxtStr1Ptr->unk0 + 15) * 8; + gDungeonMenu.unkE = ((unkTxtStr1Ptr->unk2 + 1) * 8) - 2; + gDungeonMenu.unk14.x = 0; + gDungeonMenu.unk4 = 0; + gDungeonMenu.firstEntryY = 16; + gDungeonMenu.unk0 = 0; + sub_801317C(&gDungeonMenu.unk28); + gDungeonMenu.menuIndex = 0; + gDungeonMenu.unk1A = 0; + gDungeonMenu.unk1C = 0; + + if (spArr[var_3C] == 1) { + s32 i; + + for (i = 0; i < 8; i++) { + if (unkInfoTabStruct.unkC[i] == 0) { + break; + } + } + + if (i != 0) { + var_2C = 1; + gDungeonMenu.unk1A = i; + gDungeonMenu.unk1C = 8; + sub_80137B0(&gDungeonMenu, 0); + } + gDungeonMenu.menuIndex = r8; + } + else if (spArr[var_3C] == 4) { + s32 i; + + for (i = 0; i < 8; i++) { + if (unkInfoTabStruct.unk0[i] == 0) { + break; + } + } + + if (i != 0) { + var_30 = 1; + gDungeonMenu.unk1A = i; + gDungeonMenu.unk1C = 8; + sub_80137B0(&gDungeonMenu, 0); + } + gDungeonMenu.menuIndex = r8; + } + + while (1) { + s32 unkVar; + bool8 r5, r6; + + AddMenuCursorSprite(&gDungeonMenu); + unkVar = sub_8014140(0, gUnknown_8106B8C); + r5 = FALSE; + r6 = FALSE; + if (var_30) { + if (unkInfoTabStruct.unk0[8] != 0) { + r5 = TRUE; + sub_80623B0(); + } + if (unkMonStruct.unk40 != 0) { + r6 = TRUE; + sub_8062230(); + } + } + if (var_2C) { + if (unkInfoTabStruct.unkC[8] != 0) { + r5 = TRUE; + sub_80623B0(); + } + if (unkMonStruct.unk56 != 0) { + r6 = TRUE; + sub_8062230(); + } + } + + DungeonRunFrameActions(0x1C); + if (gUnknown_202F270.f0 > 1 && !sub_80048C8()) { + if ((gRealInputs.pressed & DPAD_RIGHT) || gDungeonMenu.unk28.dpad_right) { + PlayDungeonCursorSE(0); + var_3C++; + if (spArr[var_3C] == 0) { + var_3C = 0; + } + break; + } + if ((gRealInputs.pressed & DPAD_LEFT) || gDungeonMenu.unk28.dpad_left) { + PlayDungeonCursorSE(0); + var_3C--; + if (var_3C == -1) { + var_3C = 5; + while (spArr[var_3C] == 0) { + var_3C--; + } + } + break; + } + } + + if (var_2C) { + if (unkVar == 2 && r5) { + PlayDungeonCursorSE(0); + if (unkInfoTabStruct.unkC[8] != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc1(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk56++; + } + r8 = 7; + break; + } + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(0); + if (gDungeonMenu.menuIndex == 7) { + if (unkInfoTabStruct.unkC[8] != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc1(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk56++; + } + r8 = 7; + break; + } + else { + MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); + } + } + + if (unkVar == 1 && r6) { + if (unkMonStruct.unk56 != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc2(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk56--; + } + r8 = 0; + break; + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + if (gDungeonMenu.menuIndex == 0) { + if (unkMonStruct.unk56 != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc2(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk56--; + } + r8 = 0; + break; + } + else { + MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); + } + } + } + else if (var_30) { + if (unkVar == 2 && r5) { + if (unkInfoTabStruct.unk0[8] != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc1(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk40++; + } + r8 = 7; + break; + } + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + if (gDungeonMenu.menuIndex == 7) { + if (unkInfoTabStruct.unk0[8] != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc1(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk40++; + } + r8 = 7; + break; + } + else { + MoveMenuCursorDownWrapAround(&gDungeonMenu, 0); + } + } + + if (unkVar == 1 && r6) { + if (unkMonStruct.unk40 != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc2(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk40--; + } + r8 = 0; + break; + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + if (gDungeonMenu.menuIndex == 0) { + if (unkMonStruct.unk40 != 0) { + s32 i; + for (i = 0; i < 6; i++) { + gIwramTextFunc2(0); + DungeonRunFrameActions(28); + } + unkMonStruct.unk40--; + } + r8 = 0; + break; + } + else { + MoveMenuCursorUpWrapAround(&gDungeonMenu, 0); + } + } + } + + if (sub_80048C8()) + continue; + + if (gRealInputs.pressed & START_BUTTON) { + if (var_2C) { + s32 var = unkInfoTabStruct.unkC[gDungeonMenu.menuIndex]; + + r8 = gDungeonMenu.menuIndex; + PlayDungeonStartButtonSE(); + sub_806285C(var); + var_28 = 0; + loopBreak = FALSE; + break; + } + else if (var_30) { + s32 var = unkInfoTabStruct.unk0[gDungeonMenu.menuIndex]; + + r8 = gDungeonMenu.menuIndex; + PlayDungeonStartButtonSE(); + sub_806262C(var); + var_28 = 0; + loopBreak = FALSE; + break; + } + } + + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + if (var_2C) { + s32 var = unkInfoTabStruct.unkC[gDungeonMenu.menuIndex]; + + r8 = gDungeonMenu.menuIndex; + sub_8062D68(); + gDungeonSubMenuItemsCount = 0; + PlayDungeonConfirmationSE(); + sub_8044F5C(0xC, 0); + CreateDungeonMenuSubWindow(&windows.id[0], 0x16); + while (1) { + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1C); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + PlayDungeonConfirmationSE(); + sub_806285C(var); + var_28 = 0; + loopBreak = FALSE; + break; + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + loopBreak = FALSE; + break; + } + } + } + else if (var_30) { + bool8 aPress = FALSE; + s32 var = unkInfoTabStruct.unk0[gDungeonMenu.menuIndex]; + + r8 = gDungeonMenu.menuIndex; + sub_8062D68(); + gDungeonSubMenuItemsCount = var_2C; + PlayDungeonConfirmationSE(); + sub_8044F5C(0x28, 0); + sub_8044F5C(0xC, 0); + if (CheckVariousStatuses2(entity, TRUE)) { + sub_8044FF0(0x28); + } + CreateDungeonMenuSubWindow(&windows.id[0], 0x16); + while (1) { + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1C); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { + PlayDungeonConfirmationSE(); + aPress = TRUE; + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + loopBreak = FALSE; + aPress = FALSE; + break; + } + } + + if (aPress) { + if (gDungeonMenu.menuIndex == 0) { + PlaySoundEffect(0x133); + ToggleIQSkill(&entityInfo->IQSkillMenuFlags, var); + } + else { + sub_806262C(var); + var_28 = 0; + } + loopBreak = FALSE; + break; + } + } + else { + PlayDungeonConfirmationSE(); + loopBreak = TRUE; + } + break; + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + loopBreak = TRUE; + break; + } + } + + if (var_28) { + if (var_30 != 0 || var_2C != 0) { + AddMenuCursorSprite(&gDungeonMenu); + } + DungeonRunFrameActions(0x1C); + } + + if (loopBreak) { + break; + } + } + + sub_803EAF0(0, NULL); + LoadIQSkills(entity); +} + +extern s32 gUnknown_202EDCC; + +// The same as sub_8068344 +void sub_8062230(void) +{ + if ((gUnknown_202EDCC & 8) != 0) { + UnkTextStruct1 *txtStrPtr = &gUnknown_2027370[0]; + SpriteOAM sprite = {0}; + + SpriteSetAffine1(&sprite, 0); + SpriteSetAffine2(&sprite, 0); + SpriteSetObjMode(&sprite, 0); + SpriteSetMosaic(&sprite, 0); + SpriteSetBpp(&sprite, 0); + SpriteSetShape(&sprite, 1); + SpriteSetMatrixNum(&sprite, 16); + SpriteSetSize(&sprite, 0); + SpriteSetTileNum(&sprite, 0x3F0); + SpriteSetPriority(&sprite, 0); + SpriteSetPalNum(&sprite, 15); + SpriteSetY(&sprite, (txtStrPtr->unk2 * 8) + 0x8); + SpriteSetX(&sprite, (txtStrPtr->unk0 * 8) + 0x40); + + AddSprite(&sprite, 0x100, NULL, NULL); + } +} + +// The same as sub_80684C4 +void sub_80623B0(void) +{ + if ((gUnknown_202EDCC & 8) != 0) { + UnkTextStruct1 *ptr = &gUnknown_2027370[0]; + SpriteOAM sprite = {0}; + + SpriteSetAffine1(&sprite, 0); + SpriteSetAffine2(&sprite, 0); + SpriteSetObjMode(&sprite, 0); + SpriteSetMosaic(&sprite, 0); + SpriteSetBpp(&sprite, 0); + SpriteSetShape(&sprite, 1); + SpriteSetMatrixNum(&sprite, 0); + SpriteSetSize(&sprite, 0); + SpriteSetTileNum(&sprite, 0x3F0); + SpriteSetPriority(&sprite, 0); + SpriteSetPalNum(&sprite, 15); + SpriteSetY(&sprite, (ptr->unk2 * 8) + 0x70); + SpriteSetX(&sprite, (ptr->unk0 * 8) + 0x40); + AddSprite(&sprite,0x100,NULL,NULL); + } +} + +extern SpriteOAM gUnknown_202F268; + +void sub_8062500(void) +{ + if ((gUnknown_202EDCC & 8) != 0) { + UnkTextStruct1 *ptr = &gUnknown_2027370[0]; + + SpriteSetAffine1(&gUnknown_202F268, 0); + SpriteSetAffine2(&gUnknown_202F268, 0); + SpriteSetObjMode(&gUnknown_202F268, 0); + SpriteSetMosaic(&gUnknown_202F268, 0); + SpriteSetBpp(&gUnknown_202F268, 0); + SpriteSetShape(&gUnknown_202F268, 1); + SpriteSetMatrixNum(&gUnknown_202F268, 0); + SpriteSetSize(&gUnknown_202F268, 0); + SpriteSetTileNum(&gUnknown_202F268, 0x3F0); + SpriteSetPriority(&gUnknown_202F268, 0); + SpriteSetPalNum(&gUnknown_202F268, 15); + SpriteSetY(&gUnknown_202F268, (ptr->unk2 * 8) + 0x60); + SpriteSetX(&gUnknown_202F268, 0x70); + AddSprite(&gUnknown_202F268,0x100,NULL,NULL); + } +} + +void sub_80639E4(struct subStruct_203B240 *strings, MenuInputStructSub *menuSub); + +void sub_80625A4(s32 count, struct subStruct_203B240 **strings) +{ + s32 i; + MenuInputStructSub menuSub; + + sub_801317C(&menuSub); + for (i = 0; i < count; i++) { + sub_80639E4(strings[i], &menuSub); + while (1) { + if (i < count - 1) { + sub_8062500(); + } + nullsub_34(&menuSub, 0); + DungeonRunFrameActions(0x16); + if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { + PlayDungeonConfirmationSE(); + break; + } + if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { + PlayDungeonCancelSE(); + break; + } + } + } +} + +#include "code_8097DD0.h" +#include "move_util.h" +#include "move_util.h" + +extern const u8 *const gUnknown_80FE95C; +extern const u8 *const gUnknown_80FE960; +extern const u8 *const gUnknown_80FE964; +extern const u8 *const gUnknown_80FE978; +extern const u8 gUnknown_8106C90[]; +extern const u8 gUnknown_8106C98[]; +extern const u8 gUnknown_8106C9C[]; +extern const u8 *const gWhichTextPtr2; +extern char* sub_808E4FC(s32 a1); +extern char* sub_808E51C(s32 a1); +extern void sub_8062B74(Entity *entity); +extern void sub_8062CA8(Entity *entity); +extern void sub_8045C18(u8 *buffer, Item *item); + +void sub_806262C(u8 iqSkillId) +{ + MenuInputStructSub menuSub; + Windows windows; + WindowHeader header; + struct subStruct_203B240 *result[4]; + + while (1) { + s32 count; + bool8 bPress; + + sub_801317C(&menuSub); + sub_80140B4(&windows); + windows.id[0].unk14 = &header; + header.f0 = 1; + header.f1 = 0; + header.f2 = 16; + header.f3 = 0; + DungeonShowWindows(&windows, TRUE); + sub_80073B8(0); + + strcpy(gFormatBuffer_Items[0], GetIQSkillName(iqSkillId)); + PrintFormattedStringOnWindow(16, 0, gUnknown_80FE95C, 0, '\0'); + PrintFormattedStringOnWindow(8, 16, GetIQSkillDescription(iqSkillId), 0, '\0'); + sub_80073E0(0); + count = sub_8097DF0(GetIQSkillDescription(iqSkillId), result); + while (1) { + if (count != 0) { + sub_8062500(); + } + nullsub_34(&menuSub, 0); + DungeonRunFrameActions(0x16); + if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { + bPress = FALSE; + PlayDungeonConfirmationSE(); + break; + } + if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { + bPress = TRUE; + PlayDungeonCancelSE(); + break; + } + } + + if (bPress || count == 0) + break; + + sub_80625A4(count, result); + } + + sub_803E708(4, 0x3E); +} + +void sub_8062748(u8 tacticId) +{ + MenuInputStructSub menuSub; + Windows windows; + WindowHeader header; + struct subStruct_203B240 *result[4]; + + while (1) { + s32 count; + bool8 bPress; + + sub_801317C(&menuSub); + sub_80140B4(&windows); + windows.id[0].unk14 = &header; + header.f0 = 1; + header.f1 = 0; + header.f2 = 16; + header.f3 = 0; + DungeonShowWindows(&windows, TRUE); + sub_80073B8(0); + + CopyTacticsNameToBuffer(gFormatBuffer_Items[0], tacticId); + PrintFormattedStringOnWindow(16, 0, gUnknown_80FE960, 0, '\0'); + PrintFormattedStringOnWindow(8, 16, GetTacticsDescription(tacticId), 0, '\0'); + sub_80073E0(0); + count = sub_8097DF0(GetTacticsDescription(tacticId), result); + while (1) { + if (count != 0) { + sub_8062500(); + } + nullsub_34(&menuSub, 0); + DungeonRunFrameActions(62); + if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { + bPress = FALSE; + PlayDungeonConfirmationSE(); + break; + } + if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { + bPress = TRUE; + PlayDungeonCancelSE(); + break; + } + } + + if (bPress || count == 0) + break; + + sub_80625A4(count, result); + } + + sub_803E708(4, 0x3E); +} + +void sub_806285C(s32 a0) +{ + const u8 *str; + MenuInputStructSub menuSub; + WindowHeader header; + Windows windows = { + .id = { + [0] = { + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 26, + .height = 12, + .unk10 = 12, + .unk12 = 0, + .unk14 = &header, + }, + [1] = WINDOW_DUMMY, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + + sub_801317C(&menuSub); + header.f0 = 1; + header.f1 = 0; + header.f2 = 16; + header.f3 = 0; + DungeonShowWindows(&windows, TRUE); + sub_80073B8(0); + str = sub_808E4FC(a0); + strcpy(gFormatBuffer_Items[0], str); + PrintFormattedStringOnWindow(16, 0, gUnknown_80FE964, 0, '\0'); + PrintFormattedStringOnWindow(8, 16, sub_808E51C(a0), 0, '\0'); + sub_80073E0(0); + + while (1) { + nullsub_34(&menuSub, 0); + DungeonRunFrameActions(22); + if ((gRealInputs.pressed & A_BUTTON) || menuSub.a_button) { + PlayDungeonConfirmationSE(); + break; + } + if ((gRealInputs.pressed & B_BUTTON) || menuSub.b_button) { + PlayDungeonCancelSE(); + break; + } + } + + sub_803E708(4, 0x3E); +} + +extern const Windows gUnknown_8106C30; +extern const Window gUnknown_8106C00; +extern const Window gUnknown_8106C18; + +Entity *DrawFieldGiveItemMenu(s32 *teamId, s32 a1) +{ + struct UnkFieldTeamMenuStruct unkStruct; + Windows windows = gUnknown_8106C30; + bool8 bPress = FALSE; + s32 prevId, currId; + + if (teamId != NULL) { + *teamId = -1; + } + + if (a1 == 1) { + windows.id[2] = gUnknown_8106C00; + } + else if (a1 == 2) { + windows.id[2] = gUnknown_8106C18; + } + + PrintOnDungeonTeamMenu(&unkStruct, &windows, FALSE); + sub_80073B8(1); + PrintStringOnWindow(4, 3, gWhichTextPtr2, 1, '\0'); + sub_80073E0(1); + prevId = -985; // Magic number or does it actually mean anything? + + while (1) { + currId = unkStruct.unk4[gDungeonMenu.menuIndex]; + + if (currId >= 0) { + Entity *entity = gDungeon->teamPokemon[currId]; + + if (EntityIsValid(entity) && prevId != currId) { + if (a1 == 1) { + sub_8062B74(entity); + } + else if (a1 == 2) { + sub_8062CA8(entity); + } + } + prevId = currId; + sub_806A2BC(entity, 0); + ChangeDungeonCameraPos(&entity->pos, 0, 1, 1); + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + + if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { + if (unkStruct.unk14[gDungeonMenu.menuIndex] != 0) { + PlayDungeonConfirmationSE(); + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + bPress = TRUE; + break; + } + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + sub_804AA60(); + sub_806A2BC(GetLeader(), 0); + sub_803EAF0(0, 0); + sub_803E708(4, 0x3E); + if (bPress) { + return NULL; + } + currId = unkStruct.unk4[gDungeonMenu.menuIndex]; + if (teamId != NULL) { + *teamId = currId; + } + if (currId >= 0) { + return gDungeon->teamPokemon[currId]; + } + + return NULL; +} + +void sub_8062B74(Entity *entity) +{ + s32 x, y; + EntityInfo *entInfo = GetEntInfo(entity); + + CallPrepareTextbox_8008C54(2); + sub_80073B8(2); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); + PrintFormattedStringOnWindow(12, 0, gUnknown_80FE978, 2, '\0'); + y = 16; + + if (entInfo->monsterBehavior == 1 || IsExperienceLocked(entInfo->joinedAt.id)) { + PrintFormattedStringOnWindow(12, y, gUnknown_8106C90, 2, '\0'); + } + else { + s32 i; + + for (i = 0; i < MAX_MON_MOVES; i++) { + unkStruct_80928C0 movStruct = {0, 106, 0, 0}; + Move *move = &entInfo->moves.moves[i]; + + if (MoveFlagExists(move)) { + if (entInfo->isTeamLeader) { + movStruct.unk0 = 2; + } + else { + movStruct.unk0 = 4; + } + + movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE); + BufferMoveName(gFormatBuffer_Items[0], move, &movStruct); + + if (MoveFlagLinkChain(move)) { + x = 13; + } + else { + x = 8; + if (i != 0) { + sub_80078A4(2, 12, y - 2, 120, 7); + } + } + PrintFormattedStringOnWindow(x, y, gUnknown_8106C98, 2, '\0'); + y += 12; + } + } + } + + sub_80073E0(2); +} + +void sub_8062CA8(Entity *entity) +{ + s32 x, y; + EntityInfo *entInfo = GetEntInfo(entity); + + CallPrepareTextbox_8008C54(2); + sub_80073B8(2); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); + PrintFormattedStringOnWindow(12, 0, gUnknown_80FE940, 2, '\0'); + x = 8; + y = 18; + + if (entInfo->monsterBehavior == 1 || IsExperienceLocked(entInfo->joinedAt.id)) { + PrintFormattedStringOnWindow(8, y, gUnknown_8106C90, 2, '\0'); + } + else { + Item *item = &entInfo->heldItem; + if (!ItemExists(item)) { + PrintFormattedStringOnWindow(x, y, gUnknown_8106C9C, 2, '\0'); + } + else { + sub_8045C18(gFormatBuffer_Items[0], item); + PrintFormattedStringOnWindow(x, y, gUnknown_8106C98, 2, '\0'); + } + } + + sub_80073E0(2); +} + +void sub_8062D68(void) +{ + gDungeonMenu.unk1E = 0; + gDungeonMenu.unk20 = 0; + gDungeonMenu.unkC = 0; + gDungeonMenu.unkE = 0; + gDungeonMenu.unk14.x = 0; + sub_801317C(&gDungeonMenu.unk28); +} + +u32 sub_8062D88(void) +{ + return A_BUTTON; +} + +void sub_8062D8C(ActionContainer *a0) +{ + s32 id = a0->actionParameters[0].actionUseIndex; + Entity *entityOrg = gDungeon->teamPokemon[id]; + Entity *entityNew = entityOrg; + + while (1) { + s32 i, count, countUntilId; + + countUntilId = 0; + count = 0; + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + if (sub_8071A8C(gDungeon->teamPokemon[i])) { + if (i == id) { + countUntilId = count; + } + count++; + } + } + + sub_806A2BC(entityNew, 0); + ChangeDungeonCameraPos(&entityNew->pos, 0, 1, 1); + SetLeaderActionToNothing(1); + if (ShowDungeonMovesMenu(entityNew, 0, 1, countUntilId, count)) { + return; + } + + if (GetLeaderActionId() == 6) { + s32 idBefore = id; + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + if (++id >= MAX_TEAM_MEMBERS) { + id = 0; + } + entityNew = gDungeon->teamPokemon[id]; + if (sub_8071A8C(entityNew)) { + break; + } + } + + a0->actionParameters[0].actionUseIndex = id; + if (idBefore != id) { + PlayDungeonCursorSE(0); + } + SetLeaderActionToNothing(1); + } + // Everything is the same as in the above if except for add/sub difference. + else if (GetLeaderActionId() == 7) { + s32 idBefore = id; + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + if (--id < 0) { + id = MAX_TEAM_MEMBERS - 1; + } + entityNew = gDungeon->teamPokemon[id]; + if (sub_8071A8C(entityNew)) { + break; + } + } + + a0->actionParameters[0].actionUseIndex = id; + if (idBefore != id) { + PlayDungeonCursorSE(0); + } + SetLeaderActionToNothing(1); + } + else if (GetLeaderActionId() == 29) { + sub_80637E8(GetLeaderActionContainer()); + SetLeaderActionToNothing(1); + } + else if (GetLeaderActionId() == 30) { + sub_803EAF0(0, NULL); + sub_8063A70(GetLeaderActionContainer(), TRUE); + SetLeaderActionToNothing(1); + } + else if (GetLeaderActionId() == 51) { + sub_803EAF0(0, NULL); + sub_8063A70(GetLeaderActionContainer(), FALSE); + SetLeaderActionToNothing(1); + } + else if (GetLeaderActionId() == 31) { + sub_803EAF0(0, NULL); + sub_8063B54(GetLeaderActionContainer()); + SetLeaderActionToNothing(1); + } + else if (GetLeaderActionId() == 33) { + sub_803EAF0(0, NULL); + sub_8063CF0(GetLeaderActionContainer(), TRUE); + SetLeaderActionToNothing(1); + } + + if (GetLeaderActionId() != 0) + break; + } + + sub_806A2BC(entityOrg, 0); + ChangeDungeonCameraPos(&entityOrg->pos, 0, 1, 1); +} + +extern s32 gUnknown_202F2D8; +extern s32 sub_8044FB4(u16 param_1); + +void sub_80633E4(Entity *entity, EntityInfo *entInfo, u8 a2, Windows *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7); +void sub_8063698(Entity *entity, u8 a1, u8 a2); +void sub_80637BC(ActionContainer *a0, s32 a1, s32 a2); +void sub_80637A4(ActionContainer *a0, s32 a1); + +bool8 ShowDungeonMovesMenu(Entity * entity, u8 a1, u8 a2, s32 a3, s32 a4) +{ + s32 i; + bool8 ret; + EntityInfo *entInfo = GetEntInfo(entity); + bool8 unkBool = TRUE; + EntityInfo *leaderInfo = GetEntInfo(GetLeader()); + WindowHeader header; + Windows windows = { + .id = { + [0] = { + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 18, + .height = 16, + .unk10 = 16, + .unk12 = 0, + .unk14 = &header, + }, + [1] = WINDOW_DUMMY, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + u8 unk[4]; + bool8 r10; + s32 r5; + bool8 bPress; + + gUnknown_202F2D8 = 0; + for (i = 0; i < MAX_MON_MOVES; i++) { + Move *move = &entInfo->moves.moves[i]; + + if (MoveFlagExists(move) && move->moveFlags2 & 2) { + move->moveFlags2 &= ~(2); + gUnknown_202F2D8 = i; + } + } + + while (1) { + r5 = 0; + ret = FALSE; + r10 = FALSE; + sub_80633E4(entity, entInfo, a1, &windows, &header, unk, a3, a4); + while (1) { + AddMenuCursorSprite_(&gDungeonMenu, unk); + DungeonRunFrameActions(0x1E); + if (gRealInputs.repeated & DPAD_DOWN) { + bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; + s32 id = gDungeonMenu.menuIndex; + + if (rHeld) { + gUnknown_202F2D8 = unk_SetMoveToLastInLinkedSequence4(entInfo->moves.moves, id); + if (id != gUnknown_202F2D8) { + PlayDungeonCursorSE(0); + } + else { + PlayDungeonCancelSE(); + } + r10 = TRUE; + break; + } + else { + sub_8013780(&gDungeonMenu, unk_FindMoveEnabledForAIAfter4(entInfo->moves.moves, id)); + if (id != gDungeonMenu.menuIndex) { + PlayDungeonCursorSE(0); + } + } + } + if (gRealInputs.repeated & DPAD_UP) { + bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; + s32 id = gDungeonMenu.menuIndex; + + if (rHeld) { + gUnknown_202F2D8 = unk_SetMoveToFirstInLinkedSequence4(entInfo->moves.moves, id); + if (id != gUnknown_202F2D8) { + PlayDungeonCursorSE(0); + } + else { + PlayDungeonCancelSE(); + } + r10 = TRUE; + break; + } + else { + sub_8013780(&gDungeonMenu, sub_8092DB8(entInfo->moves.moves, id)); + if (id != gDungeonMenu.menuIndex) { + PlayDungeonCursorSE(0); + } + } + } + + if ((gRealInputs.repeated & DPAD_RIGHT) || gDungeonMenu.unk28.dpad_right) { + SetMonsterActionFields(&leaderInfo->action, 6); + break; + } + if ((gRealInputs.repeated & DPAD_LEFT) || gDungeonMenu.unk28.dpad_left) { + SetMonsterActionFields(&leaderInfo->action, 7); + break; + } + + if ((gRealInputs.pressed & sub_8062D88()) || gDungeonMenu.unk28.a_button) { + if (a1) { + bool8 rHeld = (gRealInputs.held & R_BUTTON) != 0; + if (rHeld) { + r5 = 3; + } + } + PlayDungeonConfirmationSE(); + break; + } + + if (gRealInputs.pressed & START_BUTTON) { + r5 = 1; + PlayDungeonStartButtonSE(); + break; + } + if (gRealInputs.pressed & SELECT_BUTTON) { + r5 = 2; + PlayDungeonStartButtonSE(); + break; + } + // Fixme: r0/r1 regswap... + { + u32 bPressed = B_BUTTON; + bPressed &= gRealInputs.pressed; + if ((bPressed) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + ret = TRUE; + break; + } + } + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1E); + if (leaderInfo->action.action == 6 || leaderInfo->action.action == 7) { + unkBool = FALSE; + break; + } + + if (r10) + continue; + if (ret) + break; + + gUnknown_202F2D8 = gDungeonMenu.menuIndex; + if (r5 == 1) { + SetMonsterActionFields(&leaderInfo->action, 0x1D); + leaderInfo->action.actionParameters[0].actionUseIndex = entity->unk24; + leaderInfo->action.actionParameters[1].actionUseIndex = gUnknown_202F2D8; + sub_803EAF0(0, NULL); + sub_803E708(8, 0x1B); + ret = FALSE; + break; + } + + sub_8063698(entity, a1, a2); + if (r5 == 3) { + s32 r6 = sub_8044FB4(0x20); + if (!CanSubMenuItemBeChosen(r6)) { + r6 = sub_8044FB4(0x21); + if (CanSubMenuItemBeChosen(r6)) { + sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); + break; + } + } + else { + sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); + break; + } + } + else if (r5 == 2) { + if (entInfo->isTeamLeader) { + s32 r6 = sub_8044FB4(0x1E); + if (!CanSubMenuItemBeChosen(r6)) { + r6 = sub_8044FB4(0x33); + if (CanSubMenuItemBeChosen(r6)) { + sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); + break; + } + } + else { + sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); + break; + } + } + else { + s32 r6 = sub_8044FB4(0x1F); + if (CanSubMenuItemBeChosen(r6)) { + sub_80637BC(&leaderInfo->action, r6, GetTeamMemberEntityIndex(entity)); + break; + } + } + } + + sub_8009524(2); + CreateDungeonMenuSubWindow(&windows.id[0], 0x16); + while (1) { + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (gRealInputs.repeated & DPAD_DOWN) { + PlayDungeonCursorSE(1); + MoveMenuCursorDownWrapAround(&gDungeonMenu, TRUE); + } + if (gRealInputs.repeated & DPAD_UP) { + PlayDungeonCursorSE(1); + MoveMenuCursorUpWrapAround(&gDungeonMenu, TRUE); + } + + if ((gRealInputs.pressed & sub_8062D88()) || gDungeonMenu.unk28.a_button) { + if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { + sub_80637A4(&leaderInfo->action, GetTeamMemberEntityIndex(entity)); + if (leaderInfo->action.action != 20 && leaderInfo->action.action != 21) { + PlayDungeonConfirmationSE(); + } + bPress = FALSE; + break; + } + PlayDungeonCancelSE(); + } + if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { + PlayDungeonCancelSE(); + bPress = TRUE; + break; + } + } + + AddMenuCursorSprite(&gDungeonMenu); + DungeonRunFrameActions(0x1B); + if (bPress != TRUE) { + ret = 0; + break; + } + } + + if (unkBool) { + sub_803EAF0(0, NULL); + sub_803E708(8, 0x1E); + } + + return ret; +} + +extern const Window gUnknown_8106CAC; +void sub_8063578(s32 a0, Entity *entity, Moves *moves, s32 a3, u8 a4, s32 a5); +extern const u8 *const gUnknown_80FDFE8; + +void sub_80633E4(Entity *entity, EntityInfo *entInfo, u8 a2, Windows *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7) +{ + s32 i, movesCount; + Window windowNew = gUnknown_8106CAC; + + header->f0 = arg7; + header->f1 = arg6; + header->f3 = 0; + + movesCount = 0; + for (i = 0; i < MAX_MON_MOVES; i++) { + Move *move = &entInfo->moves.moves[i]; + if (MoveFlagExists(move)) { + movesCount++; + } + } + + gDungeonMenu.menuIndex = gUnknown_202F2D8; + gDungeonMenu.unk1A = movesCount; + gDungeonMenu.unk1C = 4; + gDungeonMenu.unk1E = arg6; + gDungeonMenu.unk20 = arg7; + gDungeonMenu.unk4 = 0; + gDungeonMenu.firstEntryY = 16; + gDungeonMenu.unk14.x = 0; + gDungeonMenu.unk0 = 0; + sub_801317C(&gDungeonMenu.unk28); + + windows->id[0].height = windows->id[0].unk10 = sub_80095E4(4, 0xC) + 2; + header->f2 = 13; + windows->id[0].pos.x = 2; + windows->id[1] = windows->id[3]; + windows->id[2] = windowNew; + DungeonShowWindows(windows, TRUE); + sub_80137B0(&gDungeonMenu, 0); + gDungeonMenu.unkC = (gUnknown_2027370[0].unk0 + 16) * 8; + gDungeonMenu.unkE = ((gUnknown_2027370[0].unk2 + 1) * 8) - 2; + SetMessageArgument_2(gFormatBuffer_Monsters[0], entInfo, 0); + for (i = 0; i < MAX_MON_MOVES; i++) { + Move *move = &entInfo->moves.moves[i]; + + arg5[i] = 0; + if (!MoveFlagExists(move)) { + if (gDungeonMenu.menuIndex == i) { + gDungeonMenu.menuIndex = 0; + } + } + else if (MoveFlagLinkChain(move)) { + arg5[i] = 1; + } + } + + sub_8063578(4, entity, &entInfo->moves, 0, a2, arg6); + sub_80073B8(2); + PrintFormattedStringOnWindow(4, 0, gUnknown_80FDFE8, 2, '\0'); + sub_80073E0(2); +} + +extern const u8 gUnknown_8106CC4[]; + +void sub_8063578(s32 count, Entity *entity, Moves *moves, s32 windowId, u8 a4, s32 a5) +{ + s32 i; + EntityInfo *entInfo = GetEntInfo(entity); + + sub_80073B8(windowId); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], entity, 0); + PrintFormattedStringOnWindow((a5 * 8) + 10, 0, gUnknown_80FE978, windowId, '\0'); + for (i = 0; i < count; i++) { + s32 x, y; + unkStruct_80928C0 movStruct = {0, 106, 0, a4}; + Move *move = &moves->moves[i]; + + if (MoveFlagExists(move)) { + if (entInfo->isTeamLeader) { + movStruct.unk0 = 2; + } + else { + movStruct.unk0 = 4; + } + + movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE); + BufferMoveName(gFormatBuffer_Items[0], move, &movStruct); + y = GetMenuEntryYCoord(&gDungeonMenu, i); + if (MoveFlagLinkChain(move)) { + x = 13; + } + else { + x = 8; + if (i != 0) { + sub_80078A4(windowId, 12, y - 2, 120, 7); + } + } + PrintFormattedStringOnWindow(x, y, gUnknown_8106CC4, windowId, '\0'); + } + } + + sub_80073E0(windowId); +} + +bool8 sub_8063C88(EntityInfo *entInfo, s32 a1); +bool8 sub_8063DD4(EntityInfo *entInfo, s32 a1); + +void sub_8063698(Entity *entity, u8 a1, u8 a2) +{ + EntityInfo *entInfo = GetEntInfo(entity); + Move *move = &entInfo->moves.moves[gUnknown_202F2D8]; + + gDungeonSubMenuItemsCount = 0; + if (entInfo->isTeamLeader) { + if (a2) { + sub_8044F5C(0x14, 0); + } + if (MoveFlagExists(move)) { + if (MoveFlagSet(move)) { + sub_8044F5C(0x33, 0); + } + else { + sub_8044F5C(0x1E, 0); + } + } + } + else { + sub_8044F5C(0x1F, 0); + } + + if (a1) { + sub_8044F5C(0x20, 0); + sub_8044F5C(0x21, 0); + } + sub_8044F5C(0x1D, 0); + if (!a1) { + sub_8044FF0(0x20); + } + else { + if (!sub_8063C88(entInfo, gUnknown_202F2D8)) { + sub_8044FF0(0x20); + } + if (!sub_8063DD4(entInfo, gUnknown_202F2D8)) { + sub_8044FF0(0x21); + } + } + + if (!sub_8063DD4(entInfo, gUnknown_202F2D8)) { + sub_8044FF0(0x21); + } + + if (a2) { + bool8 unkBool = FALSE; + if (gUnknown_202F2D8 < MAX_MON_MOVES) { + unkBool = CanAIUseMove(entity, gUnknown_202F2D8, TRUE) != FALSE; + } + if (!unkBool) { + sub_8044FF0(0x14); + } + } + + sub_8045064(); +} + +void sub_80637A4(ActionContainer *a0, s32 a1) +{ + sub_80637BC(a0, gDungeonMenu.menuIndex, a1); +} + +void sub_80637BC(ActionContainer *a0, s32 a1, s32 a2) +{ + SetMonsterActionFields(a0, gUnknown_202EE44[a1].unk0); + a0->actionParameters[0].actionUseIndex = a2; + a0->actionParameters[1].actionUseIndex = gUnknown_202F2D8; +} + +void sub_8063834(Move *moves, s32 a1, s32 a2); + +void sub_80637E8(ActionContainer *a0) +{ + Entity *mon = gDungeon->teamPokemon[a0->actionParameters[0].actionUseIndex]; + EntityInfo *monInfo = GetEntInfo(mon); + + monInfo->moves.moves[a0->actionParameters[1].actionUseIndex].moveFlags2 |= 2; + sub_8063834(monInfo->moves.moves, a0->actionParameters[1].actionUseIndex, 4); +} + +// diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index 1df01e6f7..964cce8c9 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -40,7 +40,7 @@ extern u8 *gUnknown_80FA090[]; void sub_8068FE0(Entity *, u32, Entity *); u8 sub_806B8CC(); -bool8 sub_805FBE8(u8 *a0); +bool8 DungeonGiveNameToRecruitedMon(u8 *a0); void sub_8083D88(); u8 sub_808529C(s32); void nullsub_96(Entity *pokemon,Entity *target); @@ -450,7 +450,7 @@ bool8 sub_806FA5C(Entity *entity1, Entity *entity2, struct unkStruct_8069D4C *pa sub_8083D88(); sub_803E708(0xa0,0x46); if (DisplayDungeonYesNoMessage(0,*gUnknown_80FA090,1) == 1) { - while (sub_805FBE8(pokeStruct2->name) == 0) { + while (DungeonGiveNameToRecruitedMon(pokeStruct2->name) == 0) { DisplayDungeonMessage(0,*gUnknown_80FA0C8,1); } } @@ -583,7 +583,7 @@ bool8 sub_806FDF4(Entity *entity1,Entity *entity2,Entity **entityPtr) } else { if (DisplayDungeonYesNoMessage(0,*gUnknown_80FA090,1) == 1) { - while (!sub_805FBE8(buffer)) { + while (!DungeonGiveNameToRecruitedMon(buffer)) { DisplayDungeonMessage(0,*gUnknown_80FA0C8,1); } } diff --git a/src/dungeon_main.c b/src/dungeon_main.c index c775ce053..d40f0799b 100644 --- a/src/dungeon_main.c +++ b/src/dungeon_main.c @@ -1,9 +1,10 @@ #include "global.h" +#include "globaldata.h" +#include "dungeon_main.h" #include "structs/str_dungeon.h" #include "number_util.h" #include "input.h" #include "structs/map.h" -#include "dungeon_main.h" #include "dungeon_message.h" #include "dungeon_action.h" #include "dungeon_ai_targeting.h" @@ -50,13 +51,6 @@ #include "structs/struct_sub80095e4.h" #include "structs/str_text.h" -struct UnkMenuBitsStruct { - u8 a0_8; - u8 a0_16; - u8 a0_24; - u8 a0_32; -}; - extern void HandleSetItemAction(Entity *,bool8); extern void HandleUnsetItemAction(Entity *,bool8); extern bool8 sub_8048A68(Entity *param_1,Item *item); @@ -90,6 +84,7 @@ bool8 sub_8094C48(void); void sub_803E724(s32 a0); void HandleTalkFieldAction(Entity *); bool8 sub_8044B28(void); +bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0); bool8 IsNotAttacking(Entity *param_1, bool8 param_2); s32 GetTeamMemberEntityIndex(Entity *pokemon); bool8 sub_8070F80(Entity * pokemon, s32 direction); @@ -149,12 +144,6 @@ extern const u8 *const gUnknown_80FE954; const u8 *GetCurrentDungeonName(void); void GetWeatherName(u8 *dst, u8 weatherId); -extern u8 *GetDungeonSubMenuItemString(s32 param_1); -extern bool8 CanSubMenuItemBeChosen(s32 param_1); -extern s32 gDungeonSubMenuItemsCount; -extern const u8 gUnknown_8106B50[]; - -extern void DungeonShowWindows(Windows *a0, u8 a1); extern bool8 sub_8070F14(Entity * pokemon, s32 direction); extern Entity *sub_80696A8(Entity *a0); @@ -184,12 +173,11 @@ static bool8 sub_805EC4C(Entity *a0, u8 a1); static bool8 sub_805EF60(Entity *a0, EntityInfo *a1); static void ShowMainMenu(bool8 fromBPress, bool8 a1); static void PrintOnMainMenu(bool8 printAll); -static bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0); void DungeonHandlePlayerInput(void) { struct UnkMenuBitsStruct r6; - bool8 triggers[5]; // Always FALSE, if one of these is TRUE - they can open various menus or cause an item throw. Most likely used for debugging/testing. + bool8 triggers[5]; // Always FALSE, if one of these is TRUE - they can open various menus or cause an item throw. Used in Blue's touch screen. s32 frames; s32 var_38; UnkDungeonGlobal_unk181E8_sub *unkPtr; @@ -254,7 +242,7 @@ void DungeonHandlePlayerInput(void) while (r6.a0_8 == 0) { u32 dpadDiagonal, dpadSimple; bool32 highlightTiles, tryItemThrow; - bool32 bPress, rPress, unkBool; // Always FALSE, might've been used as debug variables. + bool32 bPress, rPress, unkBool; // Always FALSE, might've been used in Blue. s32 directionNew; sArrowsFrames++; @@ -432,8 +420,8 @@ void DungeonHandlePlayerInput(void) if (highlightTiles) { sub_805E738(leader); sInRotateMode = TRUE; - unkPtr->unk1821B = leaderInfo->action.direction; - unkPtr->unk1821C = 0xFF; + unkPtr->rotateModeDirection = leaderInfo->action.direction; + unkPtr->prevRotateModeDirection = 0xFF; ResetRepeatTimers(); } @@ -525,7 +513,7 @@ void DungeonHandlePlayerInput(void) bool32 directionChanged = (leaderInfo->action.direction != directionNew); leaderInfo->action.direction = directionNew & DIRECTION_MASK; if (sInRotateMode) { - unkPtr->unk1821B = directionNew; + unkPtr->rotateModeDirection = directionNew; sub_806CDD4(leader, sub_806CEBC(leader), directionNew); } else { @@ -638,27 +626,42 @@ void DungeonHandlePlayerInput(void) } } -struct UnkStruct_8106AC8 +struct DiagonalArrowInfo { - s16 unk0; - s16 unk2; - u8 unk4; - u8 unk5; + s16 x; + s16 y; + bool8 unk4; + bool8 unk5; }; -extern const struct UnkStruct_8106AC8 gUnknown_8106AC8[]; - -struct UnkStruct_8106AE8 +static const struct DiagonalArrowInfo sDiagonalArrowsInfo[] = { - s16 unk0; - s16 unk2; - u32 unk4; - u8 unk8; - u8 unk9; - u8 unkA; + {-1, -1, TRUE, FALSE}, + {-1, 1, TRUE, TRUE}, + {1, 1, FALSE, TRUE}, + {1, -1, FALSE, FALSE}, }; -extern const struct UnkStruct_8106AE8 gUnknown_8106AE8[]; +struct RotateArrowInfo +{ + s16 x; + s16 y; + u32 tilemapNum; + bool8 unk8; + bool8 unk9; +}; + +static const struct RotateArrowInfo sRotateArrowsInfo[] = +{ + {0, 1, 0x212, FALSE, TRUE}, + {1, 1, 0x213, FALSE, TRUE}, + {1, 0, 0x214, FALSE, FALSE}, + {1, -1, 0x213, FALSE, FALSE}, + {0, -1, 0x212, TRUE, FALSE}, + {-1, -1, 0x213, TRUE, FALSE}, + {-1, 0, 0x214, TRUE, TRUE}, + {-1, 1, 0x213, TRUE, TRUE}, +}; // Creates arrow sprites which are used when in rotate or diagonal modes. static void TryCreateModeArrows(Entity *leader) @@ -681,9 +684,9 @@ static void TryCreateModeArrows(Entity *leader) SpriteSetBpp(&sprite, 0); SpriteSetShape(&sprite, 0); - matrixNum = (gUnknown_8106AC8[i].unk4 != 0) ? 8 : 0; + matrixNum = (sDiagonalArrowsInfo[i].unk4) ? 8 : 0; - if (gUnknown_8106AC8[i].unk5) + if (sDiagonalArrowsInfo[i].unk5) matrixNum += 16; SpriteSetMatrixNum_UseLocalVar(&sprite, matrixNum); @@ -696,14 +699,14 @@ static void TryCreateModeArrows(Entity *leader) SpriteSetUnk6_0(&sprite, 0); SpriteSetUnk6_1(&sprite, 0); - xMul = gUnknown_8106AC8[i].unk0 * 10; + xMul = sDiagonalArrowsInfo[i].x * 10; x2 = (sArrowsFrames / 2) & 7; - x = (x2 * gUnknown_8106AC8[i].unk0) + xMul + 116; + x = (x2 * sDiagonalArrowsInfo[i].x) + xMul + 116; SpriteSetX(&sprite, x); - yMul = gUnknown_8106AC8[i].unk2 * 10; + yMul = sDiagonalArrowsInfo[i].y * 10; y2 = (sArrowsFrames / 2) & 7; - y = (y2 * gUnknown_8106AC8[i].unk2) + yMul + 82; + y = (y2 * sDiagonalArrowsInfo[i].y) + yMul + 82; SpriteSetY(&sprite, y); AddSprite(&sprite, 0x100, NULL, NULL); @@ -713,20 +716,20 @@ static void TryCreateModeArrows(Entity *leader) else if (unkPtr->unk1821A) { s32 i; SpriteOAM sprite; - s32 var_2C = unkPtr->unk1821B; + s32 direction = unkPtr->rotateModeDirection; - if (unkPtr->unk1821B < 8) { + if (unkPtr->rotateModeDirection < NUM_DIRECTIONS) { s32 x, xMul, x2; s32 y, yMul, y2; s32 to = (sShowThreeArrows2 != FALSE && sShowThreeArrows1 != FALSE) ? 3 : 1; - xMul = gUnknown_8106AE8[var_2C].unk0 * 10; + xMul = sRotateArrowsInfo[direction].x * 10; x2 = (sArrowsFrames / 2) & 7; - x = (gUnknown_8106AE8[var_2C].unk0 * x2) + xMul + 116; + x = (sRotateArrowsInfo[direction].x * x2) + xMul + 116; - yMul = gUnknown_8106AE8[var_2C].unk2 * 10; + yMul = sRotateArrowsInfo[direction].y * 10; y2 = (sArrowsFrames / 2) & 7; - y = (y2 * gUnknown_8106AE8[var_2C].unk2) + yMul + 82; + y = (y2 * sRotateArrowsInfo[direction].y) + yMul + 82; for (i = 0; i < to; i++) { u32 matrixNum; @@ -737,15 +740,15 @@ static void TryCreateModeArrows(Entity *leader) SpriteSetBpp(&sprite, 0); SpriteSetShape(&sprite, 0); - matrixNum = (gUnknown_8106AE8[var_2C].unk8 != 0) ? 8 : 0; + matrixNum = (sRotateArrowsInfo[direction].unk8 != 0) ? 8 : 0; - if (gUnknown_8106AE8[var_2C].unk9) + if (sRotateArrowsInfo[direction].unk9) matrixNum += 16; SpriteSetMatrixNum_UseLocalVar(&sprite, matrixNum); SpriteSetSize(&sprite, 0); - SpriteSetTileNum(&sprite, gUnknown_8106AE8[var_2C].unk4); + SpriteSetTileNum(&sprite, sRotateArrowsInfo[direction].tilemapNum); SpriteSetPriority(&sprite, 2); SpriteSetPalNum(&sprite, 0); @@ -756,15 +759,15 @@ static void TryCreateModeArrows(Entity *leader) SpriteSetY(&sprite, y); AddSprite(&sprite, 0x100, NULL, NULL); - x += gUnknown_8106AE8[var_2C].unk0 * 4; - y += gUnknown_8106AE8[var_2C].unk2 * 4; + x += sRotateArrowsInfo[direction].x * 4; + y += sRotateArrowsInfo[direction].y * 4; } } } - if (sInRotateMode && unkPtr->unk1821C != unkPtr->unk1821B) { - unkPtr->unk1821C = unkPtr->unk1821B; - ChangeDungeonCameraPos(&leader->pos, unkPtr->unk1821B, 0, sInRotateMode); + if (sInRotateMode && unkPtr->prevRotateModeDirection != unkPtr->rotateModeDirection) { + unkPtr->prevRotateModeDirection = unkPtr->rotateModeDirection; + ChangeDungeonCameraPos(&leader->pos, unkPtr->rotateModeDirection, 0, sInRotateMode); } } @@ -1654,7 +1657,7 @@ static void PrintOnMainMenu(bool8 printAll) } } -bool8 sub_805FBE8(u8 *a0) +bool8 DungeonGiveNameToRecruitedMon(u8 *a0) { s32 r4; sub_803EAF0(8, a0); @@ -1673,76 +1676,4 @@ bool8 sub_805FBE8(u8 *a0) return FALSE; } -void CreateDungeonMenuSubWindow(Window *mainWindow, s32 subWindowX) -{ - s32 i; - Windows windows = { - .id = { - [0] = WINDOW_DUMMY, - [1] = { - .type = WINDOW_TYPE_NORMAL, - .pos = {22, 4}, - .width = 6, - .height = 4, - .unk10 = 4, - }, - [2] = WINDOW_DUMMY, - [3] = WINDOW_DUMMY, - } - }; - windows.id[0] = *mainWindow; - windows.id[0].unk0 = 0x80; - - gDungeonMenu.menuIndex = 0; - gDungeonMenu.unk1C = gDungeonSubMenuItemsCount; - gDungeonMenu.unk1A = gDungeonSubMenuItemsCount; - gDungeonMenu.unk1E = 0; - gDungeonMenu.unk20 = 0; - gDungeonMenu.unk4 = 0; - gDungeonMenu.firstEntryY = 0; - gDungeonMenu.unk0 = 1; - gDungeonMenu.unkC = 0; - gDungeonMenu.unkE = 0; - gDungeonMenu.unk14 = gDungeonMenu.unk8; - - sub_801317C(&gDungeonMenu.unk28); - - windows.id[1].pos.x = subWindowX; - windows.id[1].width = 28 - subWindowX; - windows.id[1].height = windows.id[1].unk10 = sub_80095E4(gDungeonMenu.unk1C, 0); - DungeonShowWindows(&windows, FALSE); - sub_80137B0(&gDungeonMenu, windows.id[1].height * 8); - sub_80073B8(1); - - for (i = 0; i < gDungeonSubMenuItemsCount; i++) { - s32 colorId, y; - u8 text[20]; - - colorId = (CanSubMenuItemBeChosen(i) != FALSE) ? 7 : 2; - sprintfStatic(text, gUnknown_8106B50, colorId, GetDungeonSubMenuItemString(i)); - y = GetMenuEntryYCoord(&gDungeonMenu, i); - PrintStringOnWindow(8, y, text, 1, 0); - } - sub_80073E0(1); -} - -static bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0) -{ - u16 action = GetLeaderActionId(); - - a0->a0_8 = 0; - a0->a0_16 = 0; - a0->a0_24 = 0; - a0->a0_32 = 0; - if (action == 0xA) { - a0->a0_8 = 1; - a0->a0_32 = 1; - } - if (action == 0x3E) { - a0->a0_8 = 1; - a0->a0_16 = 0; - a0->a0_32 = 1; - } - return a0->a0_8; -} diff --git a/src/dungeon_submenu.c b/src/dungeon_submenu.c new file mode 100644 index 000000000..92a90afd6 --- /dev/null +++ b/src/dungeon_submenu.c @@ -0,0 +1,69 @@ +#include "global.h" +#include "globaldata.h" +#include "dungeon_submenu.h" +#include "menu_input.h" +#include "text.h" +#include "code_800D090.h" + +// The reason this short file(just 1 function) exists is because of the pksdir string which usually signifies the file's beginning. + +extern MenuInputStruct gDungeonMenu; +extern s32 gDungeonSubMenuItemsCount; + +extern u8 *GetDungeonSubMenuItemString(s32 param_1); +extern bool8 CanSubMenuItemBeChosen(s32 param_1); +extern void DungeonShowWindows(Windows *a0, u8 a1); + +void CreateDungeonMenuSubWindow(Window *mainWindow, s32 subWindowX) +{ + s32 i; + Windows windows = { + .id = { + [0] = WINDOW_DUMMY, + [1] = { + .type = WINDOW_TYPE_NORMAL, + .pos = {22, 4}, + .width = 6, + .height = 4, + .unk10 = 4, + }, + [2] = WINDOW_DUMMY, + [3] = WINDOW_DUMMY, + } + }; + + windows.id[0] = *mainWindow; + windows.id[0].unk0 = 0x80; + + gDungeonMenu.menuIndex = 0; + gDungeonMenu.unk1C = gDungeonSubMenuItemsCount; + gDungeonMenu.unk1A = gDungeonSubMenuItemsCount; + gDungeonMenu.unk1E = 0; + gDungeonMenu.unk20 = 0; + gDungeonMenu.unk4 = 0; + gDungeonMenu.firstEntryY = 0; + gDungeonMenu.unk0 = 1; + gDungeonMenu.unkC = 0; + gDungeonMenu.unkE = 0; + gDungeonMenu.unk14 = gDungeonMenu.unk8; + + sub_801317C(&gDungeonMenu.unk28); + + windows.id[1].pos.x = subWindowX; + windows.id[1].width = 28 - subWindowX; + windows.id[1].height = windows.id[1].unk10 = sub_80095E4(gDungeonMenu.unk1C, 0); + DungeonShowWindows(&windows, FALSE); + sub_80137B0(&gDungeonMenu, windows.id[1].height * 8); + sub_80073B8(1); + + for (i = 0; i < gDungeonSubMenuItemsCount; i++) { + s32 colorId, y; + u8 text[20]; + + colorId = (CanSubMenuItemBeChosen(i) != FALSE) ? 7 : 2; + sprintfStatic(text, _("{COLOR}%c%s"), colorId, GetDungeonSubMenuItemString(i)); + y = GetMenuEntryYCoord(&gDungeonMenu, i); + PrintStringOnWindow(8, y, text, 1, 0); + } + sub_80073E0(1); +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 18bb55d20..0e53d74a9 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -150,6 +150,7 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .include "src/dungeon_move.o" .include "src/dungeon_main.o" .include "src/code_805D8C8_2.o" + .include "src/code_805D8C8_3.o" gUnknown_202F268: /* 202F268 (sub_8062500) */ .space 0x8 diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index 4881ca4e9..50b3fe815 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -115,7 +115,7 @@ .include "src/dungeon_message.o" .include "src/dungeon_move.o" .include "src/dungeon_main.o" -.include "src/code_805D8C8_2.o" +.include "src/code_805D8C8_3.o" .include "src/dungeon_ai_items.o" .include "src/code_807CD9C.o" .include "src/dungeon_leader.o"