From d1d543548772cbdf087c5ccc1e0b19980aa9ad87 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Thu, 30 Oct 2025 01:34:03 +0000 Subject: [PATCH] Improve undefined map assembler messages (#2196) --- asm/macros/event.inc | 16 ++++++++++++++++ asm/macros/map.inc | 4 ++++ data/event_scripts.s | 4 ++-- data/maps/LilycoveCity_Harbor/scripts.inc | 4 ++-- data/maps/LittlerootTown/scripts.inc | 2 +- data/maps/SlateportCity_Harbor/scripts.inc | 2 +- data/scripts/cable_club.inc | 12 ++++++------ include/constants/maps.h | 11 +++++++---- tools/mapjson/mapjson.cpp | 10 +++++++--- 9 files changed, 46 insertions(+), 19 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 797d549dc9..7075481750 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -667,6 +667,14 @@ map \map .endm + @ Set the player object's invisibility to FALSE. + .macro showplayer + .byte SCR_OP_SHOWOBJECTAT + .2byte LOCALID_PLAYER + .byte 0 @ map group + .byte 0 @ map num + .endm + @ Sets the specified object's invisibility to TRUE. .macro hideobjectat localId:req, map:req .byte SCR_OP_HIDEOBJECTAT @@ -674,6 +682,14 @@ map \map .endm + @ Set the player object's invisibility to TRUE. + .macro hideplayer + .byte SCR_OP_HIDEOBJECTAT + .2byte LOCALID_PLAYER + .byte 0 @ map group + .byte 0 @ map num + .endm + @ Turns the currently selected object (if there is one) to face the player. .macro faceplayer .byte SCR_OP_FACEPLAYER diff --git a/asm/macros/map.inc b/asm/macros/map.inc index 21445138de..acbcd532dd 100644 --- a/asm/macros/map.inc +++ b/asm/macros/map.inc @@ -2,8 +2,12 @@ @ Takes a MAP constant and outputs the map group and map number as separate bytes .macro map map_id:req + .ifdef \map_id .byte \map_id >> 8 @ map group .byte \map_id & 0xFF @ map num + .else + .error "undefined map (check for typos)" + .endif .endm @ Defines a map script. 'type' is any MAP_SCRIPT_* constant (see include/constants/map_scripts.h) diff --git a/data/event_scripts.s b/data/event_scripts.s index 0cc95940f8..33fc318957 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -787,7 +787,7 @@ EventScript_UnusedBoardFerry:: delay 30 applymovement LOCALID_PLAYER, Common_Movement_WalkInPlaceFasterUp waitmovement 0 - showobjectat LOCALID_PLAYER, 0 + showplayer delay 30 applymovement LOCALID_PLAYER, Movement_UnusedBoardFerry waitmovement 0 @@ -802,7 +802,7 @@ Common_EventScript_FerryDepartIsland:: call_if_eq VAR_FACING, DIR_SOUTH, Ferry_EventScript_DepartIslandSouth call_if_eq VAR_FACING, DIR_WEST, Ferry_EventScript_DepartIslandWest delay 30 - hideobjectat LOCALID_PLAYER, 0 + hideplayer call Common_EventScript_FerryDepart return diff --git a/data/maps/LilycoveCity_Harbor/scripts.inc b/data/maps/LilycoveCity_Harbor/scripts.inc index 9388609ab5..89bbb0714c 100644 --- a/data/maps/LilycoveCity_Harbor/scripts.inc +++ b/data/maps/LilycoveCity_Harbor/scripts.inc @@ -333,7 +333,7 @@ LilycoveCity_Harbor_EventScript_BoardFerryWithSailor:: call_if_eq VAR_FACING, DIR_NORTH, LilycoveCity_Harbor_EventScript_PlayerBoardFerryNorth call_if_eq VAR_FACING, DIR_EAST, LilycoveCity_Harbor_EventScript_PlayerBoardFerryEast delay 30 - hideobjectat LOCALID_PLAYER, 0 + hideplayer setvar VAR_0x8004, LOCALID_LILYCOVE_HARBOR_SS_TIDAL call Common_EventScript_FerryDepart return @@ -393,7 +393,7 @@ LilycoveCity_Harbor_EventScript_BoardFerry:: call_if_eq VAR_FACING, DIR_NORTH, LilycoveCity_Harbor_EventScript_PlayerBoardFerryNorth call_if_eq VAR_FACING, DIR_EAST, LilycoveCity_Harbor_EventScript_PlayerBoardFerryEast delay 30 - hideobjectat LOCALID_PLAYER, 0 + hideplayer setvar VAR_0x8004, LOCALID_LILYCOVE_HARBOR_SS_TIDAL call Common_EventScript_FerryDepart return diff --git a/data/maps/LittlerootTown/scripts.inc b/data/maps/LittlerootTown/scripts.inc index fd1d970b13..6a2c6af41b 100644 --- a/data/maps/LittlerootTown/scripts.inc +++ b/data/maps/LittlerootTown/scripts.inc @@ -156,7 +156,7 @@ LittlerootTown_EventScript_GoInsideWithMom:: waitmovement 0 setflag FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE setvar VAR_LITTLEROOT_INTRO_STATE, 3 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor VAR_0x8004, VAR_0x8005 waitdooranim clearflag FLAG_HIDE_LITTLEROOT_TOWN_FAT_MAN diff --git a/data/maps/SlateportCity_Harbor/scripts.inc b/data/maps/SlateportCity_Harbor/scripts.inc index ebcd40ab0c..52fd04ec65 100644 --- a/data/maps/SlateportCity_Harbor/scripts.inc +++ b/data/maps/SlateportCity_Harbor/scripts.inc @@ -228,7 +228,7 @@ SlateportCity_Harbor_EventScript_BoardFerry:: call_if_eq VAR_FACING, DIR_NORTH, SlateportCity_Harbor_EventScript_BoardFerryNorth call_if_eq VAR_FACING, DIR_EAST, SlateportCity_Harbor_EventScript_BoardFerryEast delay 30 - hideobjectat LOCALID_PLAYER, 0 + hideplayer setvar VAR_0x8004, LOCALID_SLATEPORT_HARBOR_SS_TIDAL call Common_EventScript_FerryDepart return diff --git a/data/scripts/cable_club.inc b/data/scripts/cable_club.inc index 68d619097f..a6a13fe940 100644 --- a/data/scripts/cable_club.inc +++ b/data/scripts/cable_club.inc @@ -356,7 +356,7 @@ CableClub_EventScript_EnterColosseum:: waitdooranim applymovement LOCALID_PLAYER, Movement_PlayerEnterLinkRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor 9, 1 waitdooranim release @@ -450,7 +450,7 @@ CableClub_EventScript_EnterTradeCenter:: waitdooranim applymovement LOCALID_PLAYER, Movement_PlayerEnterLinkRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor 9, 1 waitdooranim release @@ -515,7 +515,7 @@ CableClub_EventScript_EnterRecordCorner:: waitdooranim applymovement LOCALID_PLAYER, Movement_PlayerEnterLinkRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor 9, 1 waitdooranim release @@ -902,7 +902,7 @@ CableClub_EventScript_EnterUnionRoom:: waitdooranim applymovement LOCALID_PLAYER, Movement_PlayerEnterLinkRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor 5, 1 waitdooranim special Script_ResetUnionRoomTrade @@ -1202,7 +1202,7 @@ CableClub_EventScript_EnterWirelessLinkRoom:: waitdooranim applymovement LOCALID_PLAYER, Movement_PlayerEnterLinkRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer closedoor 9, 1 waitdooranim release @@ -1380,7 +1380,7 @@ MossdeepCity_GameCorner_1F_EventScript_EnterMinigameRoom:: closemessage applymovement LOCALID_PLAYER, Movement_PlayerEnterMinigameRoom waitmovement 0 - hideobjectat LOCALID_PLAYER, 0 + hideplayer release waitstate end diff --git a/include/constants/maps.h b/include/constants/maps.h index d41f03c683..36e27d78b7 100644 --- a/include/constants/maps.h +++ b/include/constants/maps.h @@ -3,11 +3,14 @@ #include "map_groups.h" -// Warps using this map will instead use the warp data stored in gSaveBlock1Ptr->dynamicWarp. -// Used for warps that need to change destinations, e.g. when stepping off an elevator. -#define MAP_DYNAMIC (0x7F | (0x7F << 8)) +enum +{ + // Warps using this map will instead use the warp data stored in gSaveBlock1Ptr->dynamicWarp. + // Used for warps that need to change destinations, e.g. when stepping off an elevator. + MAP_DYNAMIC = (0x7F | (0x7F << 8)), -#define MAP_UNDEFINED (0xFF | (0xFF << 8)) + MAP_UNDEFINED = (0xFF | (0xFF << 8)), +}; #define MAP_GROUP(map) (map >> 8) #define MAP_NUM(map) (map & 0xFF) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 8d8ec4e4e6..5ceac10393 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -526,11 +526,13 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { ostringstream text; text << get_include_guard_start(guard_name) << get_generated_warning("data/maps/map_groups.json", false); + text << "enum\n{\n"; + int group_num = 0; for (auto &group : groups_data["group_order"].array_items()) { string groupName = json_to_string(group); - text << "// " << groupName << "\n"; + text << " // " << groupName << "\n"; vector map_ids; size_t max_length = 0; @@ -548,14 +550,16 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { int map_id_num = 0; for (string map_id : map_ids) { - text << "#define " << map_id << string((max_length - map_id.length() + 1), ' ') - << "(" << map_id_num++ << " | (" << group_num << " << 8))\n"; + text << " " << map_id << string(max_length - map_id.length(), ' ') + << " = (" << map_id_num++ << " | (" << group_num << " << 8)),\n"; } text << "\n"; group_num++; } + text << "};\n\n"; + text << "#define MAP_GROUPS_COUNT " << group_num << "\n\n"; text << get_include_guard_end(guard_name);