diff --git a/include/code_80A26CC.h b/include/code_80A26CC.h index 6f0dcae56..c042837e9 100644 --- a/include/code_80A26CC.h +++ b/include/code_80A26CC.h @@ -22,13 +22,13 @@ const DungeonInfo *sub_80A2620(s16 index); s16 sub_80A2654(s16 index); s16 sub_80A2668(s16); s16 sub_80A2688(u8); -s16 sub_80A26B8(s16); +s16 RescueDungeonToScriptDungeonId(s16); s16 sub_80A26CC(s16); -u8 sub_80A270C(s16 index); +u8 RescueDungeonToDungeonId(s16 index); u8 sub_80A2728(s16 index); u8 ScriptDungeonIdToDungeonId(s16 index); s16 sub_80A2750(s16); -bool8 sub_80A27CC(s16); +bool8 IsRescueDungeonUnlocked(s16 _rescueDungeonId); bool8 sub_80A2824(u8 index); bool8 sub_80A28F0(u8 index); s32 sub_80A29B0(u8 *); diff --git a/include/constants/input.h b/include/constants/input.h index 4cf5ca76e..b483783c8 100644 --- a/include/constants/input.h +++ b/include/constants/input.h @@ -19,4 +19,10 @@ #define INPUT_R_DPAD_LEFT_BUTTONS 14 #define INPUT_R_DPAD_RIGHT_BUTTONS 15 -#endif // GUARD_CONSTANTS_INPUT_H \ No newline at end of file +// Used throughout menu functions +#define MENU_INPUT_NOTHING 0 +#define MENU_INPUT_DPAD 1 +#define MENU_INPUT_B_PRESS 2 +#define MENU_INPUT_A_PRESS 3 + +#endif // GUARD_CONSTANTS_INPUT_H diff --git a/include/constants/rescue_dungeon_id.h b/include/constants/rescue_dungeon_id.h new file mode 100644 index 000000000..b167089d3 --- /dev/null +++ b/include/constants/rescue_dungeon_id.h @@ -0,0 +1,55 @@ +#ifndef GUARD_CONSTANTS_RESCUE_DUNGEON_ID_H +#define GUARD_CONSTANTS_RESCUE_DUNGEON_ID_H + +enum RescueDungeonId +{ + RESCUE_DUNGEON_TINY_WOODS, + RESCUE_DUNGEON_THUNDERWAVE_CAVE, + RESCUE_DUNGEON_MT_STEEL, + RESCUE_DUNGEON_SINISTER_WOODS, + RESCUE_DUNGEON_SILENT_CHASM, + RESCUE_DUNGEON_MT_THUNDER, + RESCUE_DUNGEON_GREAT_CANYON, + RESCUE_DUNGEON_LAPIS_CAVE, + RESCUE_DUNGEON_MT_BLAZE, + RESCUE_DUNGEON_FROSTY_FOREST, + RESCUE_DUNGEON_MT_FREEZE, + RESCUE_DUNGEON_MAGMA_CAVERN, + RESCUE_DUNGEON_SKY_TOWER, + RESCUE_DUNGEON_DUMMY, + RESCUE_DUNGEON_UPROAR_FOREST, + RESCUE_DUNGEON_HOWLING_FOREST, + RESCUE_DUNGEON_STORMY_SEA, + RESCUE_DUNGEON_SILVER_TRENCH, + RESCUE_DUNGEON_METEOR_CAVE, + RESCUE_DUNGEON_GREAT_CANYON_2, + RESCUE_DUNGEON_FIERY_FIELD, + RESCUE_DUNGEON_LIGHTNING_FIELD, + RESCUE_DUNGEON_NORTHWIND_FIELD, + RESCUE_DUNGEON_MT_FARAWAY, + RESCUE_DUNGEON_WESTERN_CAVE, + RESCUE_DUNGEON_NORTHERN_RANGE, + RESCUE_DUNGEON_PITFALL_VALLEY, + RESCUE_DUNGEON_BURIED_RELIC, + RESCUE_DUNGEON_WISH_CAVE, + RESCUE_DUNGEON_MT_FREEZE_2, + RESCUE_DUNGEON_MURKY_CAVE, + RESCUE_DUNGEON_DESERT_REGION, + RESCUE_DUNGEON_SOUTHERN_CAVERN, + RESCUE_DUNGEON_WYVERN_HILL, + RESCUE_DUNGEON_SOLAR_CAVE, + RESCUE_DUNGEON_DARKNIGHT_RELIC, + RESCUE_DUNGEON_GRAND_SEA, + RESCUE_DUNGEON_WATERFALL_POND, + RESCUE_DUNGEON_UNOWN_RELIC, + RESCUE_DUNGEON_JOYOUS_TOWER, + RESCUE_DUNGEON_FAR_OFF_SEA, + RESCUE_DUNGEON_PURITY_FOREST, + RESCUE_DUNGEON_ODDITY_CAVE, + RESCUE_DUNGEON_REMAINS_ISLAND, + RESCUE_DUNGEON_MARVELOUS_SEA, + RESCUE_DUNGEON_FANTASY_STRAIT, + RESCUE_DUNGEON_COUNT, +}; + +#endif // GUARD_CONSTANTS_RESCUE_DUNGEON_ID_H diff --git a/include/debug_field_map_window.h b/include/debug_field_map_window.h index 702c00e55..1c02bc3e1 100644 --- a/include/debug_field_map_window.h +++ b/include/debug_field_map_window.h @@ -1,11 +1,6 @@ #ifndef GUARD_DEBUG_FIELD_MAP_WINDOW_H #define GUARD_DEBUG_FIELD_MAP_WINDOW_H -#define DEBUG_INPUT_NOTHING 0 -#define DEBUG_INPUT_DPAD 1 -#define DEBUG_INPUT_B_PRESS 2 -#define DEBUG_INPUT_A_PRESS 3 - bool8 DebugFieldMapWindow_Init(void); void DebugFieldMapWindow_MoveMenuTo(s16); u32 DebugFieldMapWindow_GetInput(void); diff --git a/include/dungeon_list_menu.h b/include/dungeon_list_menu.h index 73769bfc4..413a1d6a4 100644 --- a/include/dungeon_list_menu.h +++ b/include/dungeon_list_menu.h @@ -3,6 +3,11 @@ #include "structs/str_position.h" -bool8 sub_802F73C(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 showIcons); +bool8 DungeonListMenu_Init(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 showIcons); +bool8 DungeonListMenu_MoveMenuTo(s32 _rescueDungeonId); +u32 DungeonListMenu_GetInput(u8 arrowType); +s16 DungeonListMenu_GetCurrentRescueDungeonId(void); +void DungeonListMenu_Free(void); +bool8 HasZeroUnlockedDungeons(void); #endif diff --git a/include/rescue_scenario.h b/include/rescue_scenario.h index 3bf3dc55d..df71f2175 100644 --- a/include/rescue_scenario.h +++ b/include/rescue_scenario.h @@ -11,7 +11,7 @@ bool8 sub_8097384(s32 param_1); void sub_80973A8(s32 param_1, u32 param_2); bool8 RescueScenarioConquered(s32 param_1); void sub_8097418(s32 index, bool32); -const u8 *sub_80974A0(s16 index); +const u8 *GetRescueDungeonName(s16 rescueDungeonId); const u8 *GetCurrentMissionText(s16 index); #endif // GUARD_RESCUE_SCENARIO_H diff --git a/ld_script.ld b/ld_script.ld index 8a3943d19..8a46ca858 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -158,7 +158,7 @@ SECTIONS { src/pelipper_board.o(.text); src/wonder_mail_3_mid.o(.text); src/mission_reward.o(.text); - src/code_8072F3C.o(.text); + src/dungeon_list_menu.o(.text); src/makuhita_dojo1.o(.text); src/makuhita_dojo2.o(.text); src/wonder_mail_4.o(.text); @@ -529,7 +529,7 @@ SECTIONS { src/pelipper_board.o(.rodata); src/wonder_mail_3_mid.o(.rodata); src/mission_reward.o(.rodata); - src/code_8072F3C.o(.rodata); + src/dungeon_list_menu.o(.rodata); src/makuhita_dojo1.o(.rodata); src/makuhita_dojo2.o(.rodata); src/wonder_mail_4.o(.rodata); diff --git a/src/code_80A26CC.c b/src/code_80A26CC.c index 718f07b87..205acfa8c 100644 --- a/src/code_80A26CC.c +++ b/src/code_80A26CC.c @@ -5,6 +5,7 @@ #include "event_flag.h" #include "constants/dungeon.h" #include "constants/script_dungeon_id.h" +#include "constants/rescue_dungeon_id.h" static const DungeonInfo gUnknown_81168A8[SCRIPT_DUNGEON_COUNT] = { [SCRIPT_DUNGEON_TINY_WOODS] = { @@ -1097,53 +1098,53 @@ static const s16 gUnknown_8116F24[] = { 0, 0, 0, 0 }; -static const s16 gUnknown_8116F9A[] = { - [0] = SCRIPT_DUNGEON_TINY_WOODS, - [1] = SCRIPT_DUNGEON_THUNDERWAVE_CAVE, - [2] = SCRIPT_DUNGEON_MT_STEEL, - [3] = SCRIPT_DUNGEON_SINISTER_WOODS, - [4] = SCRIPT_DUNGEON_SILENT_CHASM, - [5] = SCRIPT_DUNGEON_MT_THUNDER, - [6] = SCRIPT_DUNGEON_GREAT_CANYON, - [7] = SCRIPT_DUNGEON_LAPIS_CAVE, - [8] = SCRIPT_DUNGEON_MT_BLAZE, - [9] = SCRIPT_DUNGEON_FROSTY_FOREST, - [10] = SCRIPT_DUNGEON_MT_FREEZE, - [11] = SCRIPT_DUNGEON_MAGMA_CAVERN, - [12] = SCRIPT_DUNGEON_SKY_TOWER, - [13] = SCRIPT_DUNGEON_21, - [14] = SCRIPT_DUNGEON_UPROAR_FOREST, - [15] = SCRIPT_DUNGEON_HOWLING_FOREST, - [16] = SCRIPT_DUNGEON_STORMY_SEA, - [17] = SCRIPT_DUNGEON_SILVER_TRENCH, - [18] = SCRIPT_DUNGEON_METEOR_CAVE, - [19] = SCRIPT_DUNGEON_GREAT_CANYON_2, - [20] = SCRIPT_DUNGEON_FIERY_FIELD, - [21] = SCRIPT_DUNGEON_LIGHTNING_FIELD, - [22] = SCRIPT_DUNGEON_NORTHWIND_FIELD, - [23] = SCRIPT_DUNGEON_MT_FARAWAY, - [24] = SCRIPT_DUNGEON_WESTERN_CAVE, - [25] = SCRIPT_DUNGEON_NORTHERN_RANGE, - [26] = SCRIPT_DUNGEON_PITFALL_VALLEY, - [27] = SCRIPT_DUNGEON_BURIED_RELIC, - [28] = SCRIPT_DUNGEON_WISH_CAVE, - [29] = SCRIPT_DUNGEON_MT_FREEZE_2, - [30] = SCRIPT_DUNGEON_MURKY_CAVE, - [31] = SCRIPT_DUNGEON_DESERT_REGION, - [32] = SCRIPT_DUNGEON_SOUTHERN_CAVERN, - [33] = SCRIPT_DUNGEON_WYVERN_HILL, - [34] = SCRIPT_DUNGEON_SOLAR_CAVE, - [35] = SCRIPT_DUNGEON_DARKNIGHT_RELIC, - [36] = SCRIPT_DUNGEON_GRAND_SEA, - [37] = SCRIPT_DUNGEON_WATERFALL_POND, - [38] = SCRIPT_DUNGEON_UNOWN_RELIC, - [39] = SCRIPT_DUNGEON_JOYOUS_TOWER, - [40] = SCRIPT_DUNGEON_FAR_OFF_SEA, - [41] = SCRIPT_DUNGEON_PURITY_FOREST, - [42] = SCRIPT_DUNGEON_ODDITY_CAVE, - [43] = SCRIPT_DUNGEON_REMAINS_ISLAND, - [44] = SCRIPT_DUNGEON_MARVELOUS_SEA, - [45] = SCRIPT_DUNGEON_FANTASY_STRAIT, +static const s16 sRescueToScriptDungeonIdTable[RESCUE_DUNGEON_COUNT] = { + [RESCUE_DUNGEON_TINY_WOODS] = SCRIPT_DUNGEON_TINY_WOODS, + [RESCUE_DUNGEON_THUNDERWAVE_CAVE] = SCRIPT_DUNGEON_THUNDERWAVE_CAVE, + [RESCUE_DUNGEON_MT_STEEL] = SCRIPT_DUNGEON_MT_STEEL, + [RESCUE_DUNGEON_SINISTER_WOODS] = SCRIPT_DUNGEON_SINISTER_WOODS, + [RESCUE_DUNGEON_SILENT_CHASM] = SCRIPT_DUNGEON_SILENT_CHASM, + [RESCUE_DUNGEON_MT_THUNDER] = SCRIPT_DUNGEON_MT_THUNDER, + [RESCUE_DUNGEON_GREAT_CANYON] = SCRIPT_DUNGEON_GREAT_CANYON, + [RESCUE_DUNGEON_LAPIS_CAVE] = SCRIPT_DUNGEON_LAPIS_CAVE, + [RESCUE_DUNGEON_MT_BLAZE] = SCRIPT_DUNGEON_MT_BLAZE, + [RESCUE_DUNGEON_FROSTY_FOREST] = SCRIPT_DUNGEON_FROSTY_FOREST, + [RESCUE_DUNGEON_MT_FREEZE] = SCRIPT_DUNGEON_MT_FREEZE, + [RESCUE_DUNGEON_MAGMA_CAVERN] = SCRIPT_DUNGEON_MAGMA_CAVERN, + [RESCUE_DUNGEON_SKY_TOWER] = SCRIPT_DUNGEON_SKY_TOWER, + [RESCUE_DUNGEON_DUMMY] = SCRIPT_DUNGEON_21, + [RESCUE_DUNGEON_UPROAR_FOREST] = SCRIPT_DUNGEON_UPROAR_FOREST, + [RESCUE_DUNGEON_HOWLING_FOREST] = SCRIPT_DUNGEON_HOWLING_FOREST, + [RESCUE_DUNGEON_STORMY_SEA] = SCRIPT_DUNGEON_STORMY_SEA, + [RESCUE_DUNGEON_SILVER_TRENCH] = SCRIPT_DUNGEON_SILVER_TRENCH, + [RESCUE_DUNGEON_METEOR_CAVE] = SCRIPT_DUNGEON_METEOR_CAVE, + [RESCUE_DUNGEON_GREAT_CANYON_2] = SCRIPT_DUNGEON_GREAT_CANYON_2, + [RESCUE_DUNGEON_FIERY_FIELD] = SCRIPT_DUNGEON_FIERY_FIELD, + [RESCUE_DUNGEON_LIGHTNING_FIELD] = SCRIPT_DUNGEON_LIGHTNING_FIELD, + [RESCUE_DUNGEON_NORTHWIND_FIELD] = SCRIPT_DUNGEON_NORTHWIND_FIELD, + [RESCUE_DUNGEON_MT_FARAWAY] = SCRIPT_DUNGEON_MT_FARAWAY, + [RESCUE_DUNGEON_WESTERN_CAVE] = SCRIPT_DUNGEON_WESTERN_CAVE, + [RESCUE_DUNGEON_NORTHERN_RANGE] = SCRIPT_DUNGEON_NORTHERN_RANGE, + [RESCUE_DUNGEON_PITFALL_VALLEY] = SCRIPT_DUNGEON_PITFALL_VALLEY, + [RESCUE_DUNGEON_BURIED_RELIC] = SCRIPT_DUNGEON_BURIED_RELIC, + [RESCUE_DUNGEON_WISH_CAVE] = SCRIPT_DUNGEON_WISH_CAVE, + [RESCUE_DUNGEON_MT_FREEZE_2] = SCRIPT_DUNGEON_MT_FREEZE_2, + [RESCUE_DUNGEON_MURKY_CAVE] = SCRIPT_DUNGEON_MURKY_CAVE, + [RESCUE_DUNGEON_DESERT_REGION] = SCRIPT_DUNGEON_DESERT_REGION, + [RESCUE_DUNGEON_SOUTHERN_CAVERN] = SCRIPT_DUNGEON_SOUTHERN_CAVERN, + [RESCUE_DUNGEON_WYVERN_HILL] = SCRIPT_DUNGEON_WYVERN_HILL, + [RESCUE_DUNGEON_SOLAR_CAVE] = SCRIPT_DUNGEON_SOLAR_CAVE, + [RESCUE_DUNGEON_DARKNIGHT_RELIC] = SCRIPT_DUNGEON_DARKNIGHT_RELIC, + [RESCUE_DUNGEON_GRAND_SEA] = SCRIPT_DUNGEON_GRAND_SEA, + [RESCUE_DUNGEON_WATERFALL_POND] = SCRIPT_DUNGEON_WATERFALL_POND, + [RESCUE_DUNGEON_UNOWN_RELIC] = SCRIPT_DUNGEON_UNOWN_RELIC, + [RESCUE_DUNGEON_JOYOUS_TOWER] = SCRIPT_DUNGEON_JOYOUS_TOWER, + [RESCUE_DUNGEON_FAR_OFF_SEA] = SCRIPT_DUNGEON_FAR_OFF_SEA, + [RESCUE_DUNGEON_PURITY_FOREST] = SCRIPT_DUNGEON_PURITY_FOREST, + [RESCUE_DUNGEON_ODDITY_CAVE] = SCRIPT_DUNGEON_ODDITY_CAVE, + [RESCUE_DUNGEON_REMAINS_ISLAND] = SCRIPT_DUNGEON_REMAINS_ISLAND, + [RESCUE_DUNGEON_MARVELOUS_SEA] = SCRIPT_DUNGEON_MARVELOUS_SEA, + [RESCUE_DUNGEON_FANTASY_STRAIT] = SCRIPT_DUNGEON_FANTASY_STRAIT, }; const DungeonInfo *GetDungeonInfo_80A2608(s32 _index) @@ -1154,7 +1155,7 @@ const DungeonInfo *GetDungeonInfo_80A2608(s32 _index) const DungeonInfo *sub_80A2620(s16 index) { - return &gUnknown_81168A8[sub_80A26B8(index)]; + return &gUnknown_81168A8[RescueDungeonToScriptDungeonId(index)]; } UNUSED static s16 sub_80A2644(u32 index) @@ -1189,10 +1190,10 @@ s16 sub_80A2688(u8 r0) return -1; } -s16 sub_80A26B8(s16 a0_) +s16 RescueDungeonToScriptDungeonId(s16 _rescueDungId) { - s32 a0 = (s16) a0_; - return gUnknown_8116F9A[a0]; + s32 rescueDungId = (s16) _rescueDungId; + return sRescueToScriptDungeonIdTable[rescueDungId]; } s16 sub_80A26CC(s16 r0) @@ -1218,14 +1219,12 @@ UNUSED static s16 sub_80A26D8(u8 index) return -1; } -u8 sub_80A270C(s16 index) +u8 RescueDungeonToDungeonId(s16 _rescueDungeonId) { - const DungeonInfo *temp; - s32 index_s32; + s32 rescueDungeonId = _rescueDungeonId; // forcing a shift before addressing + const DungeonInfo *info = GetDungeonInfo_80A2608(sRescueToScriptDungeonIdTable[rescueDungeonId]); - index_s32 = index; // forcing a shift before addressing - temp = GetDungeonInfo_80A2608(gUnknown_8116F9A[index_s32]); - return temp->dungeonIndex; + return info->dungeonIndex; } u8 sub_80A2728(s16 index) @@ -1277,26 +1276,21 @@ s16 sub_80A2750(s16 r0) return 2; } -bool8 sub_80A27CC(s16 r0) +bool8 IsRescueDungeonUnlocked(s16 _rescueDungeonId) { - s32 temp; - s32 temp2; - const DungeonInfo *t; - // Same dumbness as above to get a match - temp2 = r0; - temp = temp2; + s32 _rescueDungeonIdMatch = _rescueDungeonId; + s32 rescueDungeonId = _rescueDungeonIdMatch; - t = sub_80A2620(r0); - if (t->unk0 == -1) + if (sub_80A2620(_rescueDungeonId)->unk0 == -1) return FALSE; if (sub_80023E4(5)) return FALSE; - if (sub_8097384(r0)) + if (sub_8097384(_rescueDungeonId)) return TRUE; if (!sub_80023E4(1)) return FALSE; - if (!RescueScenarioConquered((s16) temp)) + if (!RescueScenarioConquered((s16) rescueDungeonId)) return FALSE; return TRUE; } @@ -1310,7 +1304,7 @@ bool8 sub_80A2824(u8 index) return FALSE; if (sub_80023E4(1)) { - for (i = 0; i < 46; i++) { + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { temp = sub_80A2620(i); if (temp->unk11 != 0) { @@ -1324,7 +1318,7 @@ bool8 sub_80A2824(u8 index) } } else { - for (i = 0; i < 46; i++) { + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { temp = sub_80A2620(i); if (temp->unk11 != 0) @@ -1393,7 +1387,7 @@ UNUSED static s32 sub_80A293C(u8 *param_1) } while ((int)pcVar2 >= (int)local_68); - for (index = 0; index < 46; index++) { + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { iVar3 = sub_80A2620(index); if (iVar3->unk11 != 0 && sub_8097384((s16) index)) local_68[iVar3->dungeonIndex] = 1; @@ -1437,7 +1431,7 @@ s32 sub_80A29B0(u8 *param_1) if (sub_80023E4(1)) { - for (index = 0; index < 46; index++) { + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { iVar3 = sub_80A2620(index); if (iVar3->unk11 != 0 && RescueScenarioConquered((s16) index)) @@ -1479,7 +1473,7 @@ UNUSED static s32 sub_80A2A5C(u8 *param_1) } while ((s32)pcVar2 >= (s32)local_58); if (sub_80023E4(1)) { - for (index = 0; index < 46; index++) { + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { iVar3 = sub_80A2620(index); if (iVar3->unk11 != 0 && (sub_8097384((s16) index) || RescueScenarioConquered((s16) index))) @@ -1487,7 +1481,7 @@ UNUSED static s32 sub_80A2A5C(u8 *param_1) } } else { - for (index = 0; index < 46; index++) { + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { iVar3 = sub_80A2620(index); if (iVar3->unk11 != 0 && sub_8097384((s16) index)) diff --git a/src/debug_field_map.c b/src/debug_field_map.c index 72e42914a..849143b57 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -20,6 +20,7 @@ #include "code_809D148.h" #include "direction_util.h" #include "menu_input.h" +#include "constants/input.h" UNUSED static void DebugMapViewer(void) { @@ -50,10 +51,10 @@ UNUSED static void DebugMapViewer(void) sub_8005838(NULL, 0); sub_8012A18(0); switch (DebugFieldMapWindow_GetInput()) { - case DEBUG_INPUT_A_PRESS: + case MENU_INPUT_A_PRESS: mapId = DebugFieldMapWindow_GetCurrentIndex(); break; - case DEBUG_INPUT_B_PRESS: + case MENU_INPUT_B_PRESS: mapId = -1; break; default: diff --git a/src/debug_field_map_window.c b/src/debug_field_map_window.c index b584ba0c1..cf6f66bdc 100644 --- a/src/debug_field_map_window.c +++ b/src/debug_field_map_window.c @@ -62,16 +62,16 @@ u32 DebugFieldMapWindow_GetInput(void) switch (GetKeyPress(&sDebugWindow->m.input)) { case INPUT_B_BUTTON: PlayMenuSoundEffect(1); - return DEBUG_INPUT_B_PRESS; + return MENU_INPUT_B_PRESS; case INPUT_A_BUTTON: - return DEBUG_INPUT_A_PRESS; + return MENU_INPUT_A_PRESS; default: if (MenuCursorUpdate(&sDebugWindow->m.input, TRUE)) { ShowWindowsWithHeader(); PrintCurrentPageText(); - return DEBUG_INPUT_DPAD; + return MENU_INPUT_DPAD; } - return DEBUG_INPUT_NOTHING; + return MENU_INPUT_NOTHING; } } diff --git a/src/code_8072F3C.c b/src/dungeon_list_menu.c similarity index 66% rename from src/code_8072F3C.c rename to src/dungeon_list_menu.c index 97e9f68ec..979b3fc51 100644 --- a/src/code_8072F3C.c +++ b/src/dungeon_list_menu.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "dungeon_list_menu.h" #include "constants/input.h" #include "text_3.h" #include "music_util.h" @@ -11,14 +12,13 @@ #include "menu_input.h" #include "text_1.h" #include "text_2.h" - -#define MAX_SHOWN_DUNGEONS 46 +#include "constants/rescue_dungeon_id.h" struct DungeonListMenu { // size: 0x15C - s16 rescueDungeonIds[MAX_SHOWN_DUNGEONS]; - bool8 goButton[MAX_SHOWN_DUNGEONS]; - bool8 jobInDungeon[MAX_SHOWN_DUNGEONS]; + s16 rescueDungeonIds[RESCUE_DUNGEON_COUNT]; + bool8 goIcon[RESCUE_DUNGEON_COUNT]; + bool8 jobInDungeon[RESCUE_DUNGEON_COUNT]; bool8 showIcons; struct MenuHeaderWindow m; }; @@ -27,6 +27,7 @@ static EWRAM_INIT struct DungeonListMenu *sDungeonListMenu = {NULL}; static const WindowTemplate sWinTemplateDummy = WIN_TEMPLATE_DUMMY; +// Never used in-game. It's slightly narrower as it doesn't have space for go/envelope icons. static const WindowTemplate sWinTemplateNarrow = { .unk0 = 0, .type = WINDOW_TYPE_WITH_HEADER, @@ -53,11 +54,9 @@ static void ShowWindowWithHeader(void); static void PrintCurrentPage(void); static s32 CountAvailableDungeons(void); -extern bool8 sub_802FCF0(void); - -bool8 sub_802F73C(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 showIcons) +bool8 DungeonListMenu_Init(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 showIcons) { - if (sub_802FCF0()) + if (HasZeroUnlockedDungeons()) return FALSE; if (sDungeonListMenu == NULL) @@ -87,7 +86,7 @@ bool8 sub_802F73C(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 show return TRUE; } -bool8 sub_802F848(s32 _rescueDungeonId) +bool8 DungeonListMenu_MoveMenuTo(s32 _rescueDungeonId) { s32 i; s32 rescueDungeonId = (s16) _rescueDungeonId; // cast needed @@ -104,50 +103,48 @@ bool8 sub_802F848(s32 _rescueDungeonId) return FALSE; } -u32 sub_802F8A0(u8 r0) +u32 DungeonListMenu_GetInput(u8 arrowType) { - if (r0 == 0) { + if (arrowType == 0) { sub_8013660(&sDungeonListMenu->m.m.input); - return 0; + return MENU_INPUT_NOTHING; } else { switch (GetKeyPress(&sDungeonListMenu->m.m.input)) { case INPUT_B_BUTTON: PlayMenuSoundEffect(1); - return 2; + return MENU_INPUT_B_PRESS; case INPUT_A_BUTTON: PlayMenuSoundEffect(0); - return 3; + return MENU_INPUT_A_PRESS; default: - if (MenuCursorUpdate(&sDungeonListMenu->m.m.input, 1) != 0) { + if (MenuCursorUpdate(&sDungeonListMenu->m.m.input, TRUE)) { ShowWindowWithHeader(); PrintCurrentPage(); - return 1; - } - else { - return 0; + return MENU_INPUT_DPAD; } + return MENU_INPUT_NOTHING; } } } -s16 sub_802F90C(void) +s16 DungeonListMenu_GetCurrentRescueDungeonId(void) { return sDungeonListMenu->rescueDungeonIds[GET_CURRENT_MENU_ENTRY(sDungeonListMenu->m.m.input)]; } -void sub_802F938(u8 r0) +UNUSED static void DungeonListMenu_UpdateShowWindow(u8 arrowType) { sDungeonListMenu->m.m.input.totalEntriesCount = CountAvailableDungeons(); MenuUpdatePagesData(&sDungeonListMenu->m.m.input); ShowWindowWithHeader(); PrintCurrentPage(); - if (r0 != 0) + if (arrowType != 0) AddMenuCursorSprite(&sDungeonListMenu->m.m.input); } -void sub_802F974(void) +void DungeonListMenu_Free(void) { if (sDungeonListMenu != NULL) { sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId] = sWinTemplateDummy; @@ -180,70 +177,63 @@ static void PrintCurrentPage(void) s32 y = GetMenuEntryYCoord(&sDungeonListMenu->m.m.input,counter); s32 index = sDungeonListMenu->m.m.input.currPage * sDungeonListMenu->m.m.input.entriesPerPage + counter; s32 rescueDungId = sDungeonListMenu->rescueDungeonIds[index]; - if (sDungeonListMenu->goButton[index]) { + if (sDungeonListMenu->goIcon[index]) { PrintStringOnWindow(10,y,_("{ICON_GO}"),sDungeonListMenu->m.m.menuWinId,'\0'); } else if (sDungeonListMenu->jobInDungeon[index]) { PrintStringOnWindow(10,y,_("{ENVELOPE_OPEN}"),sDungeonListMenu->m.m.menuWinId,'\0'); } - PrintStringOnWindow(24,y,sub_80974A0(rescueDungId),sDungeonListMenu->m.m.menuWinId,'\0'); + PrintStringOnWindow(24,y,GetRescueDungeonName(rescueDungId),sDungeonListMenu->m.m.menuWinId,'\0'); } } else { for (counter = 0; counter < sDungeonListMenu->m.m.input.currPageEntries; counter++) { s32 y = GetMenuEntryYCoord(&sDungeonListMenu->m.m.input,counter); - const u8 *name = sub_80974A0(sDungeonListMenu->rescueDungeonIds[sDungeonListMenu->m.m.input.currPage * sDungeonListMenu->m.m.input.entriesPerPage + counter]); + const u8 *name = GetRescueDungeonName(sDungeonListMenu->rescueDungeonIds[sDungeonListMenu->m.m.input.currPage * sDungeonListMenu->m.m.input.entriesPerPage + counter]); PrintStringOnWindow(8,y,name,sDungeonListMenu->m.m.menuWinId,0); } } sub_80073E0(sDungeonListMenu->m.m.menuWinId); } -static inline void sub_802FBF4_sub(u8 *test, s32 counter) -{ - test[counter] = 0; -} - static s32 CountAvailableDungeons(void) { - bool8 bVar1; - u32 dungeonIndex; - s32 iVar6; + s32 rescueDungeonId; s32 counter; s32 i; + bool8 icons = FALSE; // Variable needed to match. counter = 0; - for (i = 0; i < MAX_SHOWN_DUNGEONS; i++) { - iVar6 = iVar6 = (s16)i; // NOTE: LOLOL - if (((sub_80A27CC(i) != 0) && (iVar6 != 0x13)) && (iVar6 != 0x1d)) { - bool8 a = 0; - bool8 b = 0; - sDungeonListMenu->rescueDungeonIds[counter] = iVar6; - sDungeonListMenu->jobInDungeon[counter] = a; - sDungeonListMenu->goButton[counter] = b; - if ((sDungeonListMenu->showIcons) && (iVar6 != 0xd)) { - dungeonIndex = sub_80A270C(i); - bVar1 = FALSE; - if (0x1e >= iVar6) - { - if (sub_8097384(iVar6) == 0) { - if (iVar6 == 6) { - if (sub_8097384(0x13) != 0) { - sDungeonListMenu->rescueDungeonIds[counter] = 0x13; - bVar1 = TRUE; + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + rescueDungeonId = rescueDungeonId = (s16)i; // NOTE: weirdness needing for matching s16 memes + if (IsRescueDungeonUnlocked(i) && rescueDungeonId != RESCUE_DUNGEON_GREAT_CANYON_2 && rescueDungeonId != RESCUE_DUNGEON_MT_FREEZE_2) { + sDungeonListMenu->rescueDungeonIds[counter] = rescueDungeonId; + sDungeonListMenu->goIcon[counter] = icons; + sDungeonListMenu->jobInDungeon[counter] = icons; + if (sDungeonListMenu->showIcons && rescueDungeonId != RESCUE_DUNGEON_DUMMY) { + s32 dungeonIndex = RescueDungeonToDungeonId(rescueDungeonId); + bool8 goIcon = FALSE; + if (rescueDungeonId < RESCUE_DUNGEON_DESERT_REGION) { + if (!sub_8097384(rescueDungeonId)) { + if (rescueDungeonId == RESCUE_DUNGEON_GREAT_CANYON) { + if (sub_8097384(RESCUE_DUNGEON_GREAT_CANYON_2)) { + sDungeonListMenu->rescueDungeonIds[counter] = RESCUE_DUNGEON_GREAT_CANYON_2; + goIcon = TRUE; } } - else if ((iVar6 == 10) && (sub_8097384(0x1d) != 0)) { - sDungeonListMenu->rescueDungeonIds[counter] = 0x1d; - bVar1 = TRUE; + else if (rescueDungeonId == RESCUE_DUNGEON_MT_FREEZE) { + if (sub_8097384(RESCUE_DUNGEON_MT_FREEZE_2)) { + sDungeonListMenu->rescueDungeonIds[counter] = RESCUE_DUNGEON_MT_FREEZE_2; + goIcon = TRUE; + } } } else { - bVar1 = TRUE; + goIcon = TRUE; } } - sDungeonListMenu->goButton[counter] = bVar1; - if ((!bVar1) && (0 < CountJobsinDungeon(dungeonIndex))) { + sDungeonListMenu->goIcon[counter] = goIcon; + if (!goIcon && CountJobsinDungeon(dungeonIndex) > 0) { sDungeonListMenu->jobInDungeon[counter] = 1; } } @@ -254,12 +244,11 @@ static s32 CountAvailableDungeons(void) return counter; } -bool8 sub_802FCF0(void) +bool8 HasZeroUnlockedDungeons(void) { s32 i; - - for (i = 0; i < MAX_SHOWN_DUNGEONS; i++) { - if (sub_80A27CC(i)) + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + if (IsRescueDungeonUnlocked(i)) return FALSE; } diff --git a/src/ground_script.c b/src/ground_script.c index 2ef43f74f..fafacb850 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -56,10 +56,10 @@ #include "ground_weather.h" #include "code_809D148.h" #include "training_maze.h" +#include "dungeon_list_menu.h" // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files -bool8 sub_802FCF0(void); bool8 sub_8099B94(void); bool8 sub_80961D8(void); void ResetMailbox(void); @@ -889,7 +889,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) break; } if (val >= 0) { - SetScriptVarValue(NULL, 18, sub_80A26B8(val)); + SetScriptVarValue(NULL, 18, RescueDungeonToScriptDungeonId(val)); action->scriptData.branchDiscriminant = 1; } else { action->scriptData.branchDiscriminant = -1; @@ -923,7 +923,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) break; } if (val >= 0) { - SetScriptVarValue(NULL, 19, action->scriptData.curScriptOp == 4 ? sub_80A26B8(val) : (s16)val); + SetScriptVarValue(NULL, 19, action->scriptData.curScriptOp == 4 ? RescueDungeonToScriptDungeonId(val) : (s16)val); disc = 1; } else { disc = -1; @@ -1347,7 +1347,7 @@ static s32 ExecuteScriptCommand(Action *action) } case 0x04: { if (curCmd.arg1 == -1) { - if (!(u8)sub_802FCF0() && sub_809B1C0(12,0,NULL)) { + if (!HasZeroUnlockedDungeons() && sub_809B1C0(12,0,NULL)) { sub_80A87AC(0, 11); action->scriptData.branchDiscriminant = 0; } else { @@ -1355,7 +1355,7 @@ static s32 ExecuteScriptCommand(Action *action) } return 2; // do action } else { - SetScriptVarValue(NULL, DUNGEON_SELECT, sub_80A26B8((s16)curCmd.arg1)); + SetScriptVarValue(NULL, DUNGEON_SELECT, RescueDungeonToScriptDungeonId((s16)curCmd.arg1)); action->scriptData.branchDiscriminant = 1; return 2; // do action } diff --git a/src/rescue_scenario.c b/src/rescue_scenario.c index 06bb24ce8..1746637d1 100644 --- a/src/rescue_scenario.c +++ b/src/rescue_scenario.c @@ -6,6 +6,7 @@ #include "exclusive_pokemon.h" #include "code_80958E8.h" #include "code_80A26CC.h" +#include "constants/rescue_dungeon_id.h" // size: 0x8 typedef struct MissionText @@ -107,7 +108,7 @@ bool8 sub_8097384(s32 param_1) { s32 param1 = (s16) param_1; - if (param1 == 13) { + if (param1 == RESCUE_DUNGEON_DUMMY) { return FALSE; } else { @@ -123,7 +124,7 @@ void sub_80973A8(s32 param_1, u32 param_2) if (param_1_s32 != 0xd) { if (param_2_u32 != 0) { - sVar1 = sub_80A26B8(param_1); + sVar1 = RescueDungeonToScriptDungeonId(param_1); SetScriptVarArrayValue(NULL,RESCUE_SCENARIO_ORDER_LIST,(u16)param_1_s32,0); if (sVar1 != -1) { SetScriptVarValue(NULL,DUNGEON_SELECT,sVar1); @@ -137,7 +138,7 @@ bool8 RescueScenarioConquered(s32 param_1) { s32 param1 = (s16) param_1; - if (param1 == 13) { + if (param1 == RESCUE_DUNGEON_DUMMY) { return FALSE; } else { @@ -167,27 +168,24 @@ void sub_8097418(s32 index, bool32 param_2) } } -UNUSED static const u8 *sub_809747C(s16 index) +// These two are literally the same +UNUSED static const u8 *UnusedGetRescueDungeonName(s16 index) { - if(index == 0xD) - { + if (index == RESCUE_DUNGEON_DUMMY) { return gDummyScenarioText; } - else - { - return GetDungeonName1(sub_80A270C(index)); + else { + return GetDungeonName1(RescueDungeonToDungeonId(index)); } } -const u8 *sub_80974A0(s16 index) +const u8 *GetRescueDungeonName(s16 rescueDungeonId) { - if(index == 0xD) - { + if (rescueDungeonId == RESCUE_DUNGEON_DUMMY) { return gDummyScenarioText; } - else - { - return GetDungeonName1(sub_80A270C(index)); + else { + return GetDungeonName1(RescueDungeonToDungeonId(rescueDungeonId)); } } diff --git a/src/textbox.c b/src/textbox.c index 559264731..8335f99d6 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -47,6 +47,7 @@ #include "wigglytuff_shop3.h" #include "wonder_mail.h" #include "naming_screen.h" +#include "dungeon_list_menu.h" #include "game_options.h" #include "script_item.h" #include "structs/menu.h" @@ -119,8 +120,6 @@ struct Textbox static IWRAM_INIT struct Textbox *sTextbox = { NULL }; -extern bool8 sub_802FCF0(void); - void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); bool8 sub_809B18C(s32 *sp); extern u8 sub_802B2D4(void); @@ -134,11 +133,6 @@ bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems); s32 sub_801516C(); void sub_80151A4(); s32 sub_8015198(); -u8 sub_802F73C(); -u8 sub_802F848(); -s32 sub_802F8A0(); -void sub_802F974(); -s16 sub_802F90C(); void sub_8011C28(u32); bool8 CreateHelperPelipperMenu(s16); u32 sub_802E90C(); @@ -878,7 +872,7 @@ bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, void *a3) break; case 0xC: sub_8001D88(); - if (sub_802FCF0()) { + if (HasZeroUnlockedDungeons()) { return FALSE; } break; @@ -1497,27 +1491,27 @@ static bool8 sub_809B648(void) if (sTextbox->unk420 == 1) { s32 var = sub_80A2654(GetScriptVarValue(0,0x12)); ResetTextbox(); - if (!sub_802F73C(3,0,10,TRUE)) { + if (!DungeonListMenu_Init(3,0,10,TRUE)) { sTextbox->unk430 = -1; return 0; } - if ((var != -1) && (!sub_802F848(var))) { + if ((var != -1) && (!DungeonListMenu_MoveMenuTo(var))) { SetScriptVarValue(0,0x12,-1); } PlayMenuSoundEffect(4); } else { - switch (sub_802F8A0(1)) { + switch (DungeonListMenu_GetInput(1)) { case 3: { - s32 var = sub_802F90C(); - SetScriptVarValue(0, 0x12, sub_80A26B8(var)); - sTextbox->unk430 = var; - sub_802F974(); + s32 rescueDungeonId = DungeonListMenu_GetCurrentRescueDungeonId(); + SetScriptVarValue(0, 0x12, RescueDungeonToScriptDungeonId(rescueDungeonId)); + sTextbox->unk430 = rescueDungeonId; + DungeonListMenu_Free(); return 0; } case 2: sTextbox->unk430 = -1; - sub_802F974(); + DungeonListMenu_Free(); return 0; } } diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index b059881b4..d44460fc4 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -82,7 +82,7 @@ .include "src/pelipper_board.o" .include "src/wonder_mail_3_mid.o" .include "src/mission_reward.o" -.include "src/code_8072F3C.o" +.include "src/dungeon_list_menu.o" .include "src/makuhita_dojo1.o" .include "src/makuhita_dojo2.o" .include "src/wonder_mail_4.o"