diff --git a/include/code_80A26CC.h b/include/code_80A26CC.h index 6f0dcae56..48293736b 100644 --- a/include/code_80A26CC.h +++ b/include/code_80A26CC.h @@ -18,17 +18,16 @@ typedef struct DungeonInfo } DungeonInfo; const DungeonInfo *GetDungeonInfo_80A2608(s32 index); -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 IsRescueDungeonAvailable(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_item_action.h b/include/dungeon_item_action.h index 5031c0e83..8c63b4548 100644 --- a/include/dungeon_item_action.h +++ b/include/dungeon_item_action.h @@ -4,10 +4,10 @@ #include "structs/str_items.h" #include "structs/dungeon_entity.h" -void sub_80479B8(char param_1, char param_2, u8 param_3, Entity *pokemon, Entity *target, Item *item); +void sub_80479B8(bool8 param_1, bool8 param_2, u8 param_3, Entity *pokemon, Entity *target, Item *item); bool8 sub_8048950(Entity *param_1,Item *item); bool8 sub_8048A68(Entity *param_1,Item *item); -bool8 sub_8048B9C(Entity *entity, Item *item); +bool8 HandleLinkBoxAction(Entity *entity, Item *item); bool8 sub_8048D50(Entity *pokemon, Item *item); #endif // GUARD_DUNGEON_ITEM_ACTION_H diff --git a/include/dungeon_list_menu.h b/include/dungeon_list_menu.h new file mode 100644 index 000000000..a0fed805a --- /dev/null +++ b/include/dungeon_list_menu.h @@ -0,0 +1,13 @@ +#ifndef GUARD_DUNGEON_LIST_MENU_H +#define GUARD_DUNGEON_LIST_MENU_H + +#include "structs/str_position.h" + +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 HasZeroAvailableDungeons(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_8072F3C.c b/src/code_8072F3C.c deleted file mode 100644 index 935b171d6..000000000 --- a/src/code_8072F3C.c +++ /dev/null @@ -1,292 +0,0 @@ -#include "global.h" -#include "globaldata.h" -#include "constants/input.h" -#include "text_3.h" -#include "music_util.h" -#include "code_80958E8.h" -#include "code_80A26CC.h" -#include "rescue_scenario.h" -#include "input.h" -#include "memory.h" -#include "menu_input.h" -#include "text_1.h" -#include "text_2.h" - -struct unkStruct_203B314 -{ - // size: 0x15C - s16 unk0[2]; - u8 fill4[0x5C - 0x4]; - u8 unk5C[2]; - u8 fill5E[0x8A - 0x5E]; - u8 unk8A[2]; - u8 unk8C[0xB8 - 0x8C]; - u8 unkB8; - u8 unkB9; - u8 unkBA; - u8 unkBB; - struct MenuHeaderWindow sBC; -}; - -EWRAM_INIT struct unkStruct_203B314 *gUnknown_203B314 = {NULL}; - -const WindowTemplate gUnknown_80E06FC = { - 0x00, - 0x03, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - NULL -}; - -const WindowTemplate gUnknown_80E0714 = { - 0x00, - 0x06, - 0x02, 0x02, - 0x0E, 0x0E, - 0x0E, 0x00, - NULL -}; -const WindowTemplate gUnknown_80E072C = { - 0x00, - 0x06, - 0x02, 0x02, - 0x10, 0x10, - 0x10, 0x00, - NULL -}; - -ALIGNED(4) const u8 gUnknown_80E0744[] = "Dungeons"; -ALIGNED(4) const u8 gUnknown_80E0750[] = {0x83, 0xC2}; -ALIGNED(4) const u8 gUnknown_80E0754[] = {0x83, 0xC0}; - -void sub_802F9C0(void); -void sub_802FA50(void); -extern bool8 sub_802FCF0(void); -s32 sub_802FBF4(void); - -u32 sub_802F73C(u32 r0, DungeonPos *r1, u32 r2, u8 r3) -{ - if (sub_802FCF0()) - return 0; - - if (gUnknown_203B314 == NULL) - gUnknown_203B314 = MemoryAlloc(sizeof(struct unkStruct_203B314), 8); - - gUnknown_203B314->unkB8 = r3; - gUnknown_203B314->sBC.m.menuWinId = r0; - gUnknown_203B314->sBC.m.menuWindow = &gUnknown_203B314->sBC.m.windows.id[gUnknown_203B314->sBC.m.menuWinId]; - RestoreSavedWindows(&gUnknown_203B314->sBC.m.windows); - - if (r3 != 0) - gUnknown_203B314->sBC.m.windows.id[gUnknown_203B314->sBC.m.menuWinId] = gUnknown_80E072C; - else - gUnknown_203B314->sBC.m.windows.id[gUnknown_203B314->sBC.m.menuWinId] = gUnknown_80E0714; - - gUnknown_203B314->sBC.m.menuWindow->header = &gUnknown_203B314->sBC.header; - - if (r1 != 0) - gUnknown_203B314->sBC.m.windows.id[gUnknown_203B314->sBC.m.menuWinId].pos = *r1; - - sub_8012D08(gUnknown_203B314->sBC.m.menuWindow, r2); - ResetUnusedInputStruct(); - ShowWindows(&gUnknown_203B314->sBC.m.windows, TRUE, TRUE); - CreateMenuOnWindow(&gUnknown_203B314->sBC.m.input, sub_802FBF4(), r2, r0); - sub_802F9C0(); - sub_802FA50(); - return 1; -} - -u32 sub_802F848(s16 param_1) -{ - int index; - s32 param_1_32; - - param_1_32 = param_1; // cast needed - - for( index = 0; index < gUnknown_203B314->sBC.m.input.totalEntriesCount; index++ ) { - if (gUnknown_203B314->unk0[index] == param_1_32) { - MoveMenuToEntryId(&gUnknown_203B314->sBC.m.input,index); - sub_802F9C0(); - sub_802FA50(); - return 1; - } - } - MoveMenuToEntryId(&gUnknown_203B314->sBC.m.input,0); - return 0; -} - -u32 sub_802F8A0(u8 r0) -{ - if(r0 == 0) - { - sub_8013660(&gUnknown_203B314->sBC.m.input); - return 0; - } - else - { - switch(GetKeyPress(&gUnknown_203B314->sBC.m.input)) - { - case INPUT_B_BUTTON: - PlayMenuSoundEffect(1); - return 2; - case INPUT_A_BUTTON: - PlayMenuSoundEffect(0); - return 3; - default: - if(MenuCursorUpdate(&gUnknown_203B314->sBC.m.input, 1) != 0) - { - sub_802F9C0(); - sub_802FA50(); - return 1; - } - else - { - return 0; - } - } - } -} - -s16 sub_802F90C(void) -{ - return gUnknown_203B314->unk0[GET_CURRENT_MENU_ENTRY(gUnknown_203B314->sBC.m.input)]; -} - -void sub_802F938(u8 r0) -{ - gUnknown_203B314->sBC.m.input.totalEntriesCount = sub_802FBF4(); - MenuUpdatePagesData(&gUnknown_203B314->sBC.m.input); - sub_802F9C0(); - sub_802FA50(); - - if(r0 != 0) - AddMenuCursorSprite(&gUnknown_203B314->sBC.m.input); -} - -void sub_802F974(void) -{ - if(gUnknown_203B314 != NULL) - { - gUnknown_203B314->sBC.m.windows.id[gUnknown_203B314->sBC.m.menuWinId] = gUnknown_80E06FC; - ResetUnusedInputStruct(); - ShowWindows(&gUnknown_203B314->sBC.m.windows, TRUE, TRUE); - MemoryFree(gUnknown_203B314); - gUnknown_203B314 = NULL; - } -} - -void sub_802F9C0(void) -{ - gUnknown_203B314->sBC.header.count = 1; - gUnknown_203B314->sBC.header.currId = 0; - gUnknown_203B314->sBC.header.width = 8; - gUnknown_203B314->sBC.header.f3 = 0; - - UPDATE_MENU_WINDOW_HEIGHT(gUnknown_203B314->sBC.m); -} - -void sub_802FA50(void) -{ - s32 sVar1; - const u8 *text; - u32 y; - u32 y2; - int index; - int counter; - - CallPrepareTextbox_8008C54(gUnknown_203B314->sBC.m.menuWinId); - sub_80073B8(gUnknown_203B314->sBC.m.menuWinId); - PrintStringOnWindow(10,0,gUnknown_80E0744,gUnknown_203B314->sBC.m.menuWinId,0); - PrintNumOnWindow(gUnknown_203B314->sBC.header.width * 8 + 4,0,gUnknown_203B314->sBC.m.input.currPage + 1,2,7,gUnknown_203B314->sBC.m.menuWinId); - if (gUnknown_203B314->unkB8 != 0) { - for(counter = 0; counter < gUnknown_203B314->sBC.m.input.currPageEntries; counter++) - { - y = GetMenuEntryYCoord(&gUnknown_203B314->sBC.m.input,counter); - index = gUnknown_203B314->sBC.m.input.currPage * gUnknown_203B314->sBC.m.input.entriesPerPage + counter; - sVar1 = gUnknown_203B314->unk0[index]; - if (gUnknown_203B314->unk5C[index] != 0) { - PrintStringOnWindow(10,y,gUnknown_80E0750,gUnknown_203B314->sBC.m.menuWinId,0); - } - else if (gUnknown_203B314->unk8A[index] != 0) { - PrintStringOnWindow(10,y,gUnknown_80E0754,gUnknown_203B314->sBC.m.menuWinId,0); - } - PrintStringOnWindow(0x18,y,sub_80974A0(sVar1),gUnknown_203B314->sBC.m.menuWinId,0); - } - } - else { - for(counter = 0; counter < gUnknown_203B314->sBC.m.input.currPageEntries; counter++) - { - y2 = GetMenuEntryYCoord(&gUnknown_203B314->sBC.m.input,counter); - text = sub_80974A0(gUnknown_203B314->unk0[gUnknown_203B314->sBC.m.input.currPage * gUnknown_203B314->sBC.m.input.entriesPerPage + counter]); - PrintStringOnWindow(8,y2,text,gUnknown_203B314->sBC.m.menuWinId,0); - } - } - sub_80073E0(gUnknown_203B314->sBC.m.menuWinId); -} - -static inline void sub_802FBF4_sub(u8 *test, s32 counter) -{ - test[counter] = 0; -} - -s32 sub_802FBF4(void) -{ - bool8 bVar1; - u32 dungeonIndex; - s32 iVar6; - s32 counter; - s32 index; - - counter = 0; - for(index = 0; index < 0x2E; index++) - { - iVar6 = iVar6 = (s16)index; // NOTE: LOLOL - if (((sub_80A27CC(index) != 0) && (iVar6 != 0x13)) && (iVar6 != 0x1d)) { - gUnknown_203B314->unk0[counter] = iVar6; - sub_802FBF4_sub(gUnknown_203B314->unk5C, counter); - sub_802FBF4_sub(gUnknown_203B314->unk8A, counter); - if ((gUnknown_203B314->unkB8 != 0) && (iVar6 != 0xd)) { - dungeonIndex = sub_80A270C(index); - bVar1 = FALSE; - if (0x1e >= iVar6) - { - if (sub_8097384(iVar6) == 0) { - if (iVar6 == 6) { - if (sub_8097384(0x13) != 0) { - gUnknown_203B314->unk0[counter] = 0x13; - bVar1 = TRUE; - } - } - else if ((iVar6 == 10) && (sub_8097384(0x1d) != 0)) { - gUnknown_203B314->unk0[counter] = 0x1d; - bVar1 = TRUE; - } - } - else { - bVar1 = TRUE; - } - } - gUnknown_203B314->unk5C[counter] = bVar1; - if ((!bVar1) && (0 < CountJobsinDungeon(dungeonIndex))) { - gUnknown_203B314->unk8A[counter] = 1; - } - } - counter++; - } - } - return counter; -} - -bool8 sub_802FCF0(void) -{ - s32 i; - - for (i = 0; i < 0x2E; i++) { - if (sub_80A27CC(i)) - return FALSE; - } - - return TRUE; -} - diff --git a/src/code_80A26CC.c b/src/code_80A26CC.c index 718f07b87..828261598 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) @@ -1152,9 +1153,9 @@ const DungeonInfo *GetDungeonInfo_80A2608(s32 _index) return &gUnknown_81168A8[index]; } -const DungeonInfo *sub_80A2620(s16 index) +static const DungeonInfo *GetRescueDungeonInfo(s16 rescueDungeonId) { - return &gUnknown_81168A8[sub_80A26B8(index)]; + return &gUnknown_81168A8[RescueDungeonToScriptDungeonId(rescueDungeonId)]; } 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 IsRescueDungeonAvailable(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 (GetRescueDungeonInfo(_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,8 +1304,8 @@ bool8 sub_80A2824(u8 index) return FALSE; if (sub_80023E4(1)) { - for (i = 0; i < 46; i++) { - temp = sub_80A2620(i); + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + temp = GetRescueDungeonInfo(i); if (temp->unk11 != 0) { if (temp->dungeonIndex == index) { @@ -1324,8 +1318,8 @@ bool8 sub_80A2824(u8 index) } } else { - for (i = 0; i < 46; i++) { - temp = sub_80A2620(i); + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + temp = GetRescueDungeonInfo(i); if (temp->unk11 != 0) if (temp->dungeonIndex == index) @@ -1341,7 +1335,7 @@ UNUSED static bool8 sub_80A28B4(s16 r0) { const DungeonInfo *temp; - temp = sub_80A2620(r0); + temp = GetRescueDungeonInfo(r0); if (temp->unk0 != -1) { if (!sub_8097384(r0) && !RescueScenarioConquered(r0)) @@ -1359,7 +1353,7 @@ bool8 sub_80A28F0(u8 index) const DungeonInfo *temp; for (counter = 0; counter < 0x2E; counter++) { - temp = sub_80A2620(counter); + temp = GetRescueDungeonInfo(counter); if (temp->unk11 != 0) { if (temp->dungeonIndex == index) { @@ -1393,8 +1387,8 @@ UNUSED static s32 sub_80A293C(u8 *param_1) } while ((int)pcVar2 >= (int)local_68); - for (index = 0; index < 46; index++) { - iVar3 = sub_80A2620(index); + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { + iVar3 = GetRescueDungeonInfo(index); if (iVar3->unk11 != 0 && sub_8097384((s16) index)) local_68[iVar3->dungeonIndex] = 1; } @@ -1437,8 +1431,8 @@ s32 sub_80A29B0(u8 *param_1) if (sub_80023E4(1)) { - for (index = 0; index < 46; index++) { - iVar3 = sub_80A2620(index); + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { + iVar3 = GetRescueDungeonInfo(index); if (iVar3->unk11 != 0 && RescueScenarioConquered((s16) index)) local_68[iVar3->dungeonIndex] = 1; @@ -1479,16 +1473,16 @@ UNUSED static s32 sub_80A2A5C(u8 *param_1) } while ((s32)pcVar2 >= (s32)local_58); if (sub_80023E4(1)) { - for (index = 0; index < 46; index++) { - iVar3 = sub_80A2620(index); + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { + iVar3 = GetRescueDungeonInfo(index); if (iVar3->unk11 != 0 && (sub_8097384((s16) index) || RescueScenarioConquered((s16) index))) local_58[iVar3->dungeonIndex] = 1; } } else { - for (index = 0; index < 46; index++) { - iVar3 = sub_80A2620(index); + for (index = 0; index < RESCUE_DUNGEON_COUNT; index++) { + iVar3 = GetRescueDungeonInfo(index); if (iVar3->unk11 != 0 && sub_8097384((s16) index)) local_58[iVar3->dungeonIndex] = 1; 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/dungeon_item_action.c b/src/dungeon_item_action.c index f26f05c61..03d72fdc1 100644 --- a/src/dungeon_item_action.c +++ b/src/dungeon_item_action.c @@ -81,285 +81,284 @@ static void BlinkerSeedItemAction(Entity *, Entity *); static void DoomSeedItemAction(Entity *, Entity *); static void sub_80482FC(Entity *, Entity *, u32, u8); -void sub_80479B8(char param_1, char param_2, u8 param_3, Entity *pokemon, Entity *target, Item *item) +void sub_80479B8(bool8 param_1, bool8 param_2, u8 param_3, Entity *pokemon, Entity *target, Item *item) { - EntityInfo *info; - u32 flag; - u8 uStack_24; - u8 uStack_23; - u8 auStack_22; + if (param_1) { + if (!param_2) { + bool8 flag = FALSE; + EntityInfo *info = GetEntInfo(target); + if (info->isNotTeamMember) { + if (GetItemCategory(item->id) != CATEGORY_THROWN_LINE && GetItemCategory(item->id) != CATEGORY_BERRIES_SEEDS_VITAMINS) { + flag = (GetItemCategory(item->id) != CATEGORY_THROWN_ARC); + } + } + else { + if (GetItemCategory(item->id) != CATEGORY_BERRIES_SEEDS_VITAMINS) { + flag = IQSkillIsEnabled(target, IQ_ITEM_CATCHER); + } + } - if (param_1 != '\0') { - if (param_2 == '\0') { - flag = FALSE; - info = GetEntInfo(target); - if (info->isNotTeamMember) { - if ((GetItemCategory(item->id) != CATEGORY_THROWN_LINE) && (GetItemCategory(item->id) != CATEGORY_BERRIES_SEEDS_VITAMINS)) { - flag = GetItemCategory(item->id) == CATEGORY_THROWN_ARC ? FALSE : TRUE; + if (CheckVariousConditions(target)) { + flag = FALSE; + } + + if (flag && !ItemExists(&info->heldItem)) { + if (info->shopkeeper == TRUE) { + SpawnDroppedItemWrapper(pokemon,&target->pos,item); + } + else { + PlaySoundEffect(0x14d); + sub_8045BF8(gFormatBuffer_Items[0],item); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FDBB8); // $m0 caught the $i0 + info->heldItem = *item; + sub_806A6E8(target); + } + return; + } } - } - else { - if (GetItemCategory(item->id) != CATEGORY_BERRIES_SEEDS_VITAMINS) { - flag = IQSkillIsEnabled(target, IQ_ITEM_CATCHER); - } - } - if (CheckVariousConditions(target)) { - flag = FALSE; - } - if (flag && ((info->heldItem.flags & ITEM_FLAG_EXISTS) == 0)) { - if (info->shopkeeper == TRUE) { - SpawnDroppedItemWrapper(pokemon,&target->pos,item); - return; - } - PlaySoundEffect(0x14d); + } + + if (param_1) { + sub_8042390(target,item); + SetShopkeeperAggression(pokemon,target); + } + + if (item->flags & ITEM_FLAG_STICKY) { sub_8045BF8(gFormatBuffer_Items[0],item); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FDBB8); // $m0 caught the $i0 - info->heldItem = *item; - sub_806A6E8(target); - return; - } - } - if (param_1 != '\0') { - sub_8042390(target,item); - SetShopkeeperAggression(pokemon,target); - } - } - if ((item->flags & ITEM_FLAG_STICKY)) { - sub_8045BF8(gFormatBuffer_Items[0],item); - TryDisplayDungeonLoggableMessage3(pokemon,target,gItemStickyDoesntWorkText); - if (param_1 != '\0') { - sub_806F370(pokemon,target,gUnknown_80F4FAE,1,&uStack_24,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); - EnemyEvolution(pokemon); - return; - } - else goto _jump; - } - else { - if (param_1 == 0) -_jump: - sub_804245C(target,item); - } - if (GetItemCategory(item->id) == CATEGORY_BERRIES_SEEDS_VITAMINS) { - sub_8078B5C(pokemon,target,5,0,0); - } - if ((GetItemCategory(item->id) == CATEGORY_TMS_HMS) || (GetItemCategory(item->id) == CATEGORY_LINK_BOX)) { - if (param_1 != '\0') { - sub_806F370(pokemon,target,gUnknown_80F4FAC,1,&uStack_23,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); - goto _080482B4; - } - else - { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FE458); - goto _080482B4; - } - } - switch(item->id) { - case ITEM_STICK: - sub_80482FC(pokemon,target,gStickPPValue,ITEM_STICK); - break; - case ITEM_IRON_THORN: - sub_80482FC(pokemon,target,gIronThornPPValue,ITEM_IRON_THORN); - break; - case ITEM_SILVER_SPIKE: - sub_80482FC(pokemon,target,gSilverSpikePPValue,ITEM_SILVER_SPIKE); - break; - case ITEM_GOLD_FANG: - sub_80482FC(pokemon,target,gGoldFangPPValue,ITEM_GOLD_FANG); - break; - case ITEM_CACNEA_SPIKE: - sub_80482FC(pokemon,target,gCacneaSpikePPValue,ITEM_CACNEA_SPIKE); - break; - case ITEM_CORSOLA_TWIG: - sub_80482FC(pokemon,target,gCorsolaTwigPPValue,ITEM_CORSOLA_TWIG); - break; - case ITEM_GEO_PEBBLE: - sub_8048340(pokemon,target,gGeoPebbleThrownDmgValue); - break; - case ITEM_GRAVELEROCK: - sub_8048340(pokemon,target,gGravelerockThrownDmgValue); - break; - case ITEM_HEAL_SEED: - HealSeedItemAction(pokemon,target,param_3); - break; - case ITEM_ORAN_BERRY: - OranBerryItemAction(pokemon,target); - break; - case ITEM_SITRUS_BERRY: - SitrusBerryItemAction(pokemon,target); - break; - case ITEM_LIFE_SEED: - LifeSeedItemAction(pokemon,target); - break; - case ITEM_BLINKER_SEED: - BlinkerSeedItemAction(pokemon,target); - break; - case ITEM_ALLURE_SEED: - AllureSeedItemAction(pokemon,target); - break; - case ITEM_QUICK_SEED: - QuickSeedItemAction(pokemon,target); - break; - case ITEM_EYEDROP_SEED: - EyedropSeedItemAction(pokemon,target); - break; - case ITEM_TOTTER_SEED: - TotterSeedItemAction(pokemon,target); - break; - case ITEM_CHERI_BERRY: - CheriBerryItemAction(pokemon,target); - break; - case ITEM_PECHA_BERRY: - PechaBerryItemAction(pokemon,target); - break; - case ITEM_WARP_SEED: - WarpSeedItemAction(pokemon,target); - break; - case ITEM_SLEEP_SEED: - SleepSeedItemAction(pokemon,target); - break; - case ITEM_CHESTO_BERRY: - ChestoBerryItemAction(pokemon,target); - break; - case ITEM_JOY_SEED: - JoySeedItemAction(pokemon,target); - break; - case ITEM_DOOM_SEED: - DoomSeedItemAction(pokemon,target); - break; - case ITEM_STUN_SEED: - StunSeedItemAction(pokemon,target); - break; - case ITEM_PLAIN_SEED: - PlainSeedItemAction(pokemon,target); - break; - case ITEM_RAWST_BERRY: - RawstBerryItemAction(pokemon,target); - break; - case ITEM_HUNGER_SEED: - HungerSeedItemAction(pokemon,target); - break; - case ITEM_GINSENG: - GinsengItemAction(pokemon,target); - break; - case ITEM_BLAST_SEED: - BlastSeedItemAction(pokemon,target,param_1); - break; - case ITEM_MAX_ELIXIR: - MaxElixirAction(pokemon,target); - break; - case ITEM_PROTEIN: - ProteinItemAction(pokemon,target); - break; - case ITEM_CALCIUM: - CalciumItemAction(pokemon,target); - break; - case ITEM_IRON: - IronItemAction(pokemon,target); - break; - case ITEM_ZINC: - ZincItemAction(pokemon,target); - break; - case 0xe9: - nullsub_94(pokemon,target,param_1); - break; - case ITEM_BIG_APPLE: - sub_80487CC(pokemon,target,100,10); - break; - case ITEM_HUGE_APPLE: - sub_80487CC(pokemon,target,999,10); - break; - case ITEM_GRIMY_FOOD: - GrimyFoodItemAction(pokemon,target); - break; - case ITEM_WHITE_GUMMI: - HandleGummiItemAction(pokemon,target,1); - break; - case ITEM_RED_GUMMI: - HandleGummiItemAction(pokemon,target,2); - break; - case ITEM_BLUE_GUMMI: - HandleGummiItemAction(pokemon,target,3); - break; - case ITEM_GRASS_GUMMI: - HandleGummiItemAction(pokemon,target,4); - break; - case ITEM_YELLOW_GUMMI: - HandleGummiItemAction(pokemon,target,5); - break; - case ITEM_CLEAR_GUMMI: - HandleGummiItemAction(pokemon,target,6); - break; - case ITEM_ORANGE_GUMMI: - HandleGummiItemAction(pokemon,target,7); - break; - case ITEM_PINK_GUMMI: - HandleGummiItemAction(pokemon,target,8); - break; - case ITEM_BROWN_GUMMI: - HandleGummiItemAction(pokemon,target,9); - break; - case ITEM_SKY_GUMMI: - HandleGummiItemAction(pokemon,target,10); - break; - case ITEM_GOLD_GUMMI: - HandleGummiItemAction(pokemon,target,0xb); - break; - case ITEM_GREEN_GUMMI: - HandleGummiItemAction(pokemon,target,0xc); - break; - case ITEM_GRAY_GUMMI: - HandleGummiItemAction(pokemon,target,0xd); - break; - case ITEM_PURPLE_GUMMI: - HandleGummiItemAction(pokemon,target,0xe); - break; - case ITEM_ROYAL_GUMMI: - HandleGummiItemAction(pokemon,target,0xf); - break; - case ITEM_BLACK_GUMMI: - HandleGummiItemAction(pokemon,target,0x10); - break; - case ITEM_SILVER_GUMMI: - HandleGummiItemAction(pokemon,target,0x11); - break; - case ITEM_APPLE: - case ITEM_BANANA: - sub_80487CC(pokemon,target,0x32,5); - break; - case ITEM_CHESTNUT: - sub_80487CC(pokemon,target,10,0); - break; - case ITEM_KEY: - KeyItemAction(pokemon,target,param_1); - break; - case ITEM_ICE_PART: - IcePartItemAction(pokemon,target,param_1); - break; - case ITEM_ROCK_PART: - RockPartItemAction(pokemon,target,param_1); - break; - case ITEM_STEEL_PART: - SteelPartItemAction(pokemon,target,param_1); - break; - case ITEM_WISH_STONE: - WishStoneItemAction(pokemon,target,param_1); - break; - case ITEM_MUSIC_BOX: - MusicBoxItemAction(pokemon,target,param_1); - break; - default: - if (param_1 != '\0') { - sub_806F370(pokemon,target,gUnknown_80F4FAC,1,&auStack_22,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); + TryDisplayDungeonLoggableMessage3(pokemon,target,gItemStickyDoesntWorkText); + if (param_1) { + u8 uStack_24; + sub_806F370(pokemon,target,gUnknown_80F4FAE,1,&uStack_24,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); + EnemyEvolution(pokemon); + return; } - else - { + } + + if (!param_1) + sub_804245C(target,item); + + if (GetItemCategory(item->id) == CATEGORY_BERRIES_SEEDS_VITAMINS) { + sub_8078B5C(pokemon,target,5,0,0); + } + + if (GetItemCategory(item->id) == CATEGORY_TMS_HMS || GetItemCategory(item->id) == CATEGORY_LINK_BOX) { + if (param_1) { + u8 uStack_23; + sub_806F370(pokemon,target,gUnknown_80F4FAC,1,&uStack_23,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); + } + else { TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FE458); } - break; - } -_080482B4: - EnemyEvolution(pokemon); + } + else { + switch (item->id) { + case ITEM_STICK: + sub_80482FC(pokemon,target,gStickPPValue,ITEM_STICK); + break; + case ITEM_IRON_THORN: + sub_80482FC(pokemon,target,gIronThornPPValue,ITEM_IRON_THORN); + break; + case ITEM_SILVER_SPIKE: + sub_80482FC(pokemon,target,gSilverSpikePPValue,ITEM_SILVER_SPIKE); + break; + case ITEM_GOLD_FANG: + sub_80482FC(pokemon,target,gGoldFangPPValue,ITEM_GOLD_FANG); + break; + case ITEM_CACNEA_SPIKE: + sub_80482FC(pokemon,target,gCacneaSpikePPValue,ITEM_CACNEA_SPIKE); + break; + case ITEM_CORSOLA_TWIG: + sub_80482FC(pokemon,target,gCorsolaTwigPPValue,ITEM_CORSOLA_TWIG); + break; + case ITEM_GEO_PEBBLE: + sub_8048340(pokemon,target,gGeoPebbleThrownDmgValue); + break; + case ITEM_GRAVELEROCK: + sub_8048340(pokemon,target,gGravelerockThrownDmgValue); + break; + case ITEM_HEAL_SEED: + HealSeedItemAction(pokemon,target,param_3); + break; + case ITEM_ORAN_BERRY: + OranBerryItemAction(pokemon,target); + break; + case ITEM_SITRUS_BERRY: + SitrusBerryItemAction(pokemon,target); + break; + case ITEM_LIFE_SEED: + LifeSeedItemAction(pokemon,target); + break; + case ITEM_BLINKER_SEED: + BlinkerSeedItemAction(pokemon,target); + break; + case ITEM_ALLURE_SEED: + AllureSeedItemAction(pokemon,target); + break; + case ITEM_QUICK_SEED: + QuickSeedItemAction(pokemon,target); + break; + case ITEM_EYEDROP_SEED: + EyedropSeedItemAction(pokemon,target); + break; + case ITEM_TOTTER_SEED: + TotterSeedItemAction(pokemon,target); + break; + case ITEM_CHERI_BERRY: + CheriBerryItemAction(pokemon,target); + break; + case ITEM_PECHA_BERRY: + PechaBerryItemAction(pokemon,target); + break; + case ITEM_WARP_SEED: + WarpSeedItemAction(pokemon,target); + break; + case ITEM_SLEEP_SEED: + SleepSeedItemAction(pokemon,target); + break; + case ITEM_CHESTO_BERRY: + ChestoBerryItemAction(pokemon,target); + break; + case ITEM_JOY_SEED: + JoySeedItemAction(pokemon,target); + break; + case ITEM_DOOM_SEED: + DoomSeedItemAction(pokemon,target); + break; + case ITEM_STUN_SEED: + StunSeedItemAction(pokemon,target); + break; + case ITEM_PLAIN_SEED: + PlainSeedItemAction(pokemon,target); + break; + case ITEM_RAWST_BERRY: + RawstBerryItemAction(pokemon,target); + break; + case ITEM_HUNGER_SEED: + HungerSeedItemAction(pokemon,target); + break; + case ITEM_GINSENG: + GinsengItemAction(pokemon,target); + break; + case ITEM_BLAST_SEED: + BlastSeedItemAction(pokemon,target,param_1); + break; + case ITEM_MAX_ELIXIR: + MaxElixirAction(pokemon,target); + break; + case ITEM_PROTEIN: + ProteinItemAction(pokemon,target); + break; + case ITEM_CALCIUM: + CalciumItemAction(pokemon,target); + break; + case ITEM_IRON: + IronItemAction(pokemon,target); + break; + case ITEM_ZINC: + ZincItemAction(pokemon,target); + break; + case ITEM_SWITCH_BOX: + nullsub_94(pokemon,target,param_1); + break; + case ITEM_BIG_APPLE: + sub_80487CC(pokemon,target,100,10); + break; + case ITEM_HUGE_APPLE: + sub_80487CC(pokemon,target,999,10); + break; + case ITEM_GRIMY_FOOD: + GrimyFoodItemAction(pokemon,target); + break; + case ITEM_WHITE_GUMMI: + HandleGummiItemAction(pokemon,target,1); + break; + case ITEM_RED_GUMMI: + HandleGummiItemAction(pokemon,target,2); + break; + case ITEM_BLUE_GUMMI: + HandleGummiItemAction(pokemon,target,3); + break; + case ITEM_GRASS_GUMMI: + HandleGummiItemAction(pokemon,target,4); + break; + case ITEM_YELLOW_GUMMI: + HandleGummiItemAction(pokemon,target,5); + break; + case ITEM_CLEAR_GUMMI: + HandleGummiItemAction(pokemon,target,6); + break; + case ITEM_ORANGE_GUMMI: + HandleGummiItemAction(pokemon,target,7); + break; + case ITEM_PINK_GUMMI: + HandleGummiItemAction(pokemon,target,8); + break; + case ITEM_BROWN_GUMMI: + HandleGummiItemAction(pokemon,target,9); + break; + case ITEM_SKY_GUMMI: + HandleGummiItemAction(pokemon,target,10); + break; + case ITEM_GOLD_GUMMI: + HandleGummiItemAction(pokemon,target,0xb); + break; + case ITEM_GREEN_GUMMI: + HandleGummiItemAction(pokemon,target,0xc); + break; + case ITEM_GRAY_GUMMI: + HandleGummiItemAction(pokemon,target,0xd); + break; + case ITEM_PURPLE_GUMMI: + HandleGummiItemAction(pokemon,target,0xe); + break; + case ITEM_ROYAL_GUMMI: + HandleGummiItemAction(pokemon,target,0xf); + break; + case ITEM_BLACK_GUMMI: + HandleGummiItemAction(pokemon,target,0x10); + break; + case ITEM_SILVER_GUMMI: + HandleGummiItemAction(pokemon,target,0x11); + break; + case ITEM_APPLE: + case ITEM_BANANA: + sub_80487CC(pokemon,target,0x32,5); + break; + case ITEM_CHESTNUT: + sub_80487CC(pokemon,target,10,0); + break; + case ITEM_KEY: + KeyItemAction(pokemon,target,param_1); + break; + case ITEM_ICE_PART: + IcePartItemAction(pokemon,target,param_1); + break; + case ITEM_ROCK_PART: + RockPartItemAction(pokemon,target,param_1); + break; + case ITEM_STEEL_PART: + SteelPartItemAction(pokemon,target,param_1); + break; + case ITEM_WISH_STONE: + WishStoneItemAction(pokemon,target,param_1); + break; + case ITEM_MUSIC_BOX: + MusicBoxItemAction(pokemon,target,param_1); + break; + default: + if (param_1) { + u8 auStack_22; + sub_806F370(pokemon,target,gUnknown_80F4FAC,1,&auStack_22,0,DUNGEON_EXIT_FELLED_BY_THROWN_ITEM,RESIDUAL_DAMAGE_REGULAR,0,0); + } + else { + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FE458); + } + break; + } + } + + EnemyEvolution(pokemon); } UNUSED static void nullsub_205(void) { } @@ -806,8 +805,10 @@ bool8 sub_8048A68(Entity *param_1,Item *item) return FALSE; } -bool8 sub_8048B9C(Entity *entity, Item *item) +bool8 HandleLinkBoxAction(Entity *entity, Item *item) { + s32 i; + Entity *entity2; bool8 ret = FALSE; ActionContainer *entityActionPtr = &GetEntInfo(entity)->action; ActionContainer originalAction; @@ -816,79 +817,71 @@ bool8 sub_8048B9C(Entity *entity, Item *item) DisplayDungeonMessage(0,gItemStickyDoesntWorkText,1); return FALSE; } - else - { - s32 i; - Entity *entity2; - for (i = 0; i < MAX_TEAM_MEMBERS; i++) { - Entity *teamMon = gDungeon->teamPokemon[i]; - if (EntityIsValid(teamMon)) { - EntityInfo *teamMonInfo = GetEntInfo(teamMon); - bool8 flag = TRUE; - if (CheckVariousStatuses2(teamMon, FALSE)){ - flag = FALSE; - } - if (teamMonInfo->monsterBehavior == BEHAVIOR_RESCUE_TARGET) { - flag = FALSE; - } - if (IsExperienceLocked(teamMonInfo->joinedAt.id)) { - flag = FALSE; - } - teamMonInfo->unk157 = flag; + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + Entity *teamMon = gDungeon->teamPokemon[i]; + if (EntityIsValid(teamMon)) { + EntityInfo *teamMonInfo = GetEntInfo(teamMon); + bool8 flag = TRUE; + if (CheckVariousStatuses2(teamMon, FALSE)){ + flag = FALSE; } + if (teamMonInfo->monsterBehavior == BEHAVIOR_RESCUE_TARGET) { + flag = FALSE; + } + if (IsExperienceLocked(teamMonInfo->joinedAt.id)) { + flag = FALSE; + } + teamMonInfo->unk157 = flag; + } + } + + entity2 = ShowDungeonToWhichMonMenu(NULL,WHICH_MENU_MOVES); + if (!EntityIsValid(entity2)) { + return FALSE; + } + + originalAction = *entityActionPtr; + while (1) { + ClearMonsterActionFields(entityActionPtr); + if (ShowDungeonMovesMenu(entity2,1,0,0,1)) { + if (!ret) + break; + if (DisplayDungeonYesNoMessage(0,gUnknown_80FECA0,1) == 1) + break; } - entity2 = ShowDungeonToWhichMonMenu(NULL,WHICH_MENU_MOVES); - if (!EntityIsValid(entity2)) { - return FALSE; + if (entityActionPtr->action == ACTION_MOVE_INFO) { + ActionShowMoveInfo(entityActionPtr); } - - originalAction = *entityActionPtr; - goto LOOP_MIDDLE; // Needed to match - while (1) { - if (entityActionPtr->action == ACTION_MOVE_INFO) { - ActionShowMoveInfo(entityActionPtr); - } - else if (entityActionPtr->action == ACTION_LINK_MOVES) { - sub_803EAF0(0, NULL); - ActionLinkMoves(entityActionPtr); - SetLeaderActionToNothing(TRUE); - ret = TRUE; - } - else if (entityActionPtr->action == ACTION_DELINK_MOVES) { - sub_803EAF0(0, NULL); - ActionDelinkMoves(entityActionPtr,0); - SetLeaderActionToNothing(TRUE); - } - else if ((entityActionPtr->action == ACTION_SET_MOVE) || (entityActionPtr->action == ACTION_UNSET_MOVE)) { - sub_803EAF0(0, NULL); - ActionSetOrUnsetMove(entityActionPtr, FALSE); - } - else if (entityActionPtr->action == ACTION_SWITCH_AI_MOVE) { - sub_803EAF0(0, NULL); - ActionToggleMoveUsableForAi(entityActionPtr); - } - - LOOP_MIDDLE: - ClearMonsterActionFields(entityActionPtr); - if (ShowDungeonMovesMenu(entity2,1,0,0,1) != 0) { - if (ret) { - ASM_MATCH_TRICK(ret); - if (DisplayDungeonYesNoMessage(0,gUnknown_80FECA0,1) == 1) { - *entityActionPtr = originalAction; - sub_8044DF0(entity,0,0x6e); - SetMonsterActionFields(entityActionPtr,0x2c); - break; - } - } - else - { - SetLeaderActionToNothing(TRUE); - break; - } - } + else if (entityActionPtr->action == ACTION_LINK_MOVES) { + sub_803EAF0(0, NULL); + ActionLinkMoves(entityActionPtr); + SetLeaderActionToNothing(TRUE); + ret = TRUE; } + else if (entityActionPtr->action == ACTION_DELINK_MOVES) { + sub_803EAF0(0, NULL); + ActionDelinkMoves(entityActionPtr,0); + SetLeaderActionToNothing(TRUE); + } + else if ((entityActionPtr->action == ACTION_SET_MOVE) || (entityActionPtr->action == ACTION_UNSET_MOVE)) { + sub_803EAF0(0, NULL); + ActionSetOrUnsetMove(entityActionPtr, FALSE); + } + else if (entityActionPtr->action == ACTION_SWITCH_AI_MOVE) { + sub_803EAF0(0, NULL); + ActionToggleMoveUsableForAi(entityActionPtr); + } + } + + if (ret) { + *entityActionPtr = originalAction; + sub_8044DF0(entity,0,0x6e); + SetMonsterActionFields(entityActionPtr,ACTION_USE_LINK_BOX); + } + else { + SetLeaderActionToNothing(TRUE); } return ret; diff --git a/src/dungeon_list_menu.c b/src/dungeon_list_menu.c new file mode 100644 index 000000000..ba61ffc82 --- /dev/null +++ b/src/dungeon_list_menu.c @@ -0,0 +1,256 @@ +#include "global.h" +#include "globaldata.h" +#include "dungeon_list_menu.h" +#include "constants/input.h" +#include "text_3.h" +#include "music_util.h" +#include "code_80958E8.h" +#include "code_80A26CC.h" +#include "rescue_scenario.h" +#include "input.h" +#include "memory.h" +#include "menu_input.h" +#include "text_1.h" +#include "text_2.h" +#include "constants/rescue_dungeon_id.h" + +struct DungeonListMenu { + // size: 0x15C + s16 rescueDungeonIds[RESCUE_DUNGEON_COUNT]; + bool8 goIcon[RESCUE_DUNGEON_COUNT]; + bool8 jobInDungeon[RESCUE_DUNGEON_COUNT]; + bool8 showIcons; + struct MenuHeaderWindow m; +}; + +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, + .pos = {2, 2}, + .width = 14, + .height = 14, + .unk10 = 14, + .unk12 = 0, + .header = NULL, +}; + +static const WindowTemplate sWinTemplateWide = { + .unk0 = 0, + .type = WINDOW_TYPE_WITH_HEADER, + .pos = {2, 2}, + .width = 16, + .height = 16, + .unk10 = 16, + .unk12 = 0, + .header = NULL, +}; + +static void ShowWindowWithHeader(void); +static void PrintCurrentPage(void); +static s32 CountAvailableDungeons(void); + +bool8 DungeonListMenu_Init(u32 windowId, DungeonPos *winPos, s32 perPageCount, bool8 showIcons) +{ + if (HasZeroAvailableDungeons()) + return FALSE; + + if (sDungeonListMenu == NULL) + sDungeonListMenu = MemoryAlloc(sizeof(struct DungeonListMenu), 8); + + sDungeonListMenu->showIcons = showIcons; + sDungeonListMenu->m.m.menuWinId = windowId; + sDungeonListMenu->m.m.menuWindow = &sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId]; + RestoreSavedWindows(&sDungeonListMenu->m.m.windows); + + if (showIcons) + sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId] = sWinTemplateWide; + else + sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId] = sWinTemplateNarrow; + + sDungeonListMenu->m.m.menuWindow->header = &sDungeonListMenu->m.header; + + if (winPos != NULL) + sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId].pos = *winPos; + + sub_8012D08(sDungeonListMenu->m.m.menuWindow, perPageCount); + ResetUnusedInputStruct(); + ShowWindows(&sDungeonListMenu->m.m.windows, TRUE, TRUE); + CreateMenuOnWindow(&sDungeonListMenu->m.m.input, CountAvailableDungeons(), perPageCount, windowId); + ShowWindowWithHeader(); + PrintCurrentPage(); + return TRUE; +} + +bool8 DungeonListMenu_MoveMenuTo(s32 _rescueDungeonId) +{ + s32 i; + s32 rescueDungeonId = (s16) _rescueDungeonId; // cast needed + + for (i = 0; i < sDungeonListMenu->m.m.input.totalEntriesCount; i++) { + if (sDungeonListMenu->rescueDungeonIds[i] == rescueDungeonId) { + MoveMenuToEntryId(&sDungeonListMenu->m.m.input,i); + ShowWindowWithHeader(); + PrintCurrentPage(); + return TRUE; + } + } + MoveMenuToEntryId(&sDungeonListMenu->m.m.input,0); + return FALSE; +} + +u32 DungeonListMenu_GetInput(u8 arrowType) +{ + if (arrowType == 0) { + sub_8013660(&sDungeonListMenu->m.m.input); + return MENU_INPUT_NOTHING; + } + else { + switch (GetKeyPress(&sDungeonListMenu->m.m.input)) { + case INPUT_B_BUTTON: + PlayMenuSoundEffect(1); + return MENU_INPUT_B_PRESS; + case INPUT_A_BUTTON: + PlayMenuSoundEffect(0); + return MENU_INPUT_A_PRESS; + default: + if (MenuCursorUpdate(&sDungeonListMenu->m.m.input, TRUE)) { + ShowWindowWithHeader(); + PrintCurrentPage(); + return MENU_INPUT_DPAD; + } + return MENU_INPUT_NOTHING; + } + } +} + +s16 DungeonListMenu_GetCurrentRescueDungeonId(void) +{ + return sDungeonListMenu->rescueDungeonIds[GET_CURRENT_MENU_ENTRY(sDungeonListMenu->m.m.input)]; +} + +UNUSED static void DungeonListMenu_UpdateShowWindow(u8 arrowType) +{ + sDungeonListMenu->m.m.input.totalEntriesCount = CountAvailableDungeons(); + MenuUpdatePagesData(&sDungeonListMenu->m.m.input); + ShowWindowWithHeader(); + PrintCurrentPage(); + + if (arrowType != 0) + AddMenuCursorSprite(&sDungeonListMenu->m.m.input); +} + +void DungeonListMenu_Free(void) +{ + if (sDungeonListMenu != NULL) { + sDungeonListMenu->m.m.windows.id[sDungeonListMenu->m.m.menuWinId] = sWinTemplateDummy; + ResetUnusedInputStruct(); + ShowWindows(&sDungeonListMenu->m.m.windows, TRUE, TRUE); + FREE_AND_SET_NULL(sDungeonListMenu); + } +} + +static void ShowWindowWithHeader(void) +{ + sDungeonListMenu->m.header.count = 1; + sDungeonListMenu->m.header.currId = 0; + sDungeonListMenu->m.header.width = 8; + sDungeonListMenu->m.header.f3 = 0; + + UPDATE_MENU_WINDOW_HEIGHT(sDungeonListMenu->m.m); +} + +static void PrintCurrentPage(void) +{ + s32 counter; + + CallPrepareTextbox_8008C54(sDungeonListMenu->m.m.menuWinId); + sub_80073B8(sDungeonListMenu->m.m.menuWinId); + PrintStringOnWindow(10,0,_("Dungeons"),sDungeonListMenu->m.m.menuWinId,0); + PrintNumOnWindow(sDungeonListMenu->m.header.width * 8 + 4,0,sDungeonListMenu->m.m.input.currPage + 1,2,7,sDungeonListMenu->m.m.menuWinId); + if (sDungeonListMenu->showIcons) { + for (counter = 0; counter < sDungeonListMenu->m.m.input.currPageEntries; counter++) { + 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->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,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 = 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 s32 CountAvailableDungeons(void) +{ + s32 rescueDungeonId; + s32 counter; + s32 i; + bool8 icons = FALSE; // Variable needed to match. + + counter = 0; + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + rescueDungeonId = rescueDungeonId = (s16)i; // NOTE: weirdness needed for matching s16 memes + if (IsRescueDungeonAvailable(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 (rescueDungeonId == RESCUE_DUNGEON_MT_FREEZE) { + if (sub_8097384(RESCUE_DUNGEON_MT_FREEZE_2)) { + sDungeonListMenu->rescueDungeonIds[counter] = RESCUE_DUNGEON_MT_FREEZE_2; + goIcon = TRUE; + } + } + } + else { + goIcon = TRUE; + } + } + sDungeonListMenu->goIcon[counter] = goIcon; + if (!goIcon && CountJobsinDungeon(dungeonIndex) > 0) { + sDungeonListMenu->jobInDungeon[counter] = TRUE; + } + } + counter++; + } + } + + return counter; +} + +bool8 HasZeroAvailableDungeons(void) +{ + s32 i; + for (i = 0; i < RESCUE_DUNGEON_COUNT; i++) { + if (IsRescueDungeonAvailable(i)) + return FALSE; + } + + return TRUE; +} diff --git a/src/dungeon_main.c b/src/dungeon_main.c index 1a7f34c9d..0f385a466 100644 --- a/src/dungeon_main.c +++ b/src/dungeon_main.c @@ -1197,7 +1197,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) } else if (action == ACTION_USE_LINK_BOX) { item = sub_8044D90(GetLeader(), 0, 15); - if (!sub_8048B9C(GetLeader(), item)) { + if (!HandleLinkBoxAction(GetLeader(), item)) { SetLeaderActionToNothing(TRUE); } } @@ -1409,7 +1409,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) } else if (action == ACTION_USE_LINK_BOX) { item = sub_8044D90(GetLeader(), 0, 0x13); - if (!sub_8048B9C(GetLeader(), item)) { + if (!HandleLinkBoxAction(GetLeader(), item)) { SetLeaderActionToNothing(TRUE); } } diff --git a/src/friend_area_action_menu.c b/src/friend_area_action_menu.c index 560418b15..606f0db88 100644 --- a/src/friend_area_action_menu.c +++ b/src/friend_area_action_menu.c @@ -24,6 +24,7 @@ #include "text_1.h" #include "text_2.h" #include "unk_ds_only_feature.h" +#include "music_util.h" static EWRAM_INIT struct unkStruct_203B2BC *sUnknown_203B2BC = {NULL}; @@ -48,8 +49,6 @@ extern void CreateFriendActionMenu(); extern void sub_80276A8(); bool8 sub_8027D9C(Pokemon *pokeStruct); extern u8 sub_8027DCC(Pokemon *); -extern void SetFriendAreaActionMenuState(u32); -extern void PlaySound(u32); u32 sub_8027E18(Pokemon *); u8 sub_8027E4C(Pokemon *r0); diff --git a/src/ground_script.c b/src/ground_script.c index 2ef43f74f..096cb8a6a 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 (!HasZeroAvailableDungeons() && 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/text_1.c b/src/text_1.c index 9f0a2d3ee..902857bb9 100644 --- a/src/text_1.c +++ b/src/text_1.c @@ -222,8 +222,10 @@ void SetCharacterMask(s32 a0) { u32 retval; if (a0 == 0) { - UNUSED u32 unusedVal = sUnknown_20274B0; - retval = 0x88888888; + if (sUnknown_20274B0 == 0) + retval = 0x88888888; + else + retval = 0x88888888; } else { retval = (a0 & 0xF) | ((a0 & 0xF) << 4); // Must be one line for matching diff --git a/src/textbox.c b/src/textbox.c index 679c94229..07cee1211 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 (HasZeroAvailableDungeons()) { 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,1)) { + 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"