MACRO map_id ;\1: map id db GROUP_\1, MAP_\1 ENDM MACRO object_const_def const_def NUM_RESERVED_OBJECTS ENDM MACRO npc_id db \1 - NUM_RESERVED_OBJECTS ENDM MACRO map_attributes ;\1: map name ;\2: map id REDEF CURRENT_MAP_NAME EQUS "\1" REDEF CURRENT_MAP_ID EQUS "\2" DEF CURRENT_MAP_WIDTH = \2_WIDTH DEF CURRENT_MAP_HEIGHT = \2_HEIGHT \1_MapAttributes:: db CURRENT_MAP_HEIGHT, CURRENT_MAP_WIDTH dw \1_Blocks dw \1_TextPointers dw \1_ScriptLoader dw \1_MapEvents db MAP_CONNECTIONS_\2 ; Define `MAP_CONNECTIONS_\2` after `db`ing it so that the `db`ed value ; gets updated when subsequent `connection`s modify `MAP_CONNECTIONS_\2`. DEF MAP_CONNECTIONS_\2 = 0 ENDM ; Gen 1 equivalent of map_attributes MACRO old_map_header ;\1: map name ;\2: map id ;\3: tileset REDEF CURRENT_MAP_ID EQUS "\2" DEF CURRENT_MAP_WIDTH = \2_WIDTH DEF CURRENT_MAP_HEIGHT = \2_HEIGHT \1_MapAttributes:: db TILESET_\3 db CURRENT_MAP_HEIGHT, CURRENT_MAP_WIDTH dw \1_Blocks dw \1_TextPointers dw \1_ScriptLoader db MAP_CONNECTIONS_\2 dw \1_MapEvents ; Define `MAP_CONNECTIONS_\2` after `db`ing it so that the `db`ed value ; gets updated when subsequent `connection`s modify `MAP_CONNECTIONS_\2`. DEF MAP_CONNECTIONS_\2 = 0 ENDM ; Connections go in order: north, south, west, east MACRO connection ;\1: direction ;\2: map name ;\3: map id ;\4: offset of the target map relative to the current map ; (x offset for east/west, y offset for north/south) ; Calculate tile offsets for source (current) and target maps DEF _src = 0 DEF _tgt = (\4) + 3 if _tgt < 0 DEF _src = -_tgt DEF _tgt = 0 endc if "\1" === "north" if MAP_CONNECTIONS_{CURRENT_MAP_ID} & (NORTH | SOUTH | WEST | EAST) fail "Invalid order for 'connection' (must be north, south, west, east)" endc DEF MAP_CONNECTIONS_{CURRENT_MAP_ID} |= NORTH DEF _blk = \3_WIDTH * (\3_HEIGHT - 3) + _src DEF _map = _tgt DEF _win = (\3_WIDTH + 6) * \3_HEIGHT + 1 DEF _y = \3_HEIGHT * 2 - 1 DEF _x = (\4) * -2 DEF _len = CURRENT_MAP_WIDTH + 3 - (\4) if _len > \3_WIDTH DEF _len = \3_WIDTH endc elif "\1" === "south" if MAP_CONNECTIONS_{CURRENT_MAP_ID} & (SOUTH | WEST | EAST) fail "Invalid order for 'connection' (must be north, south, west, east)" endc DEF MAP_CONNECTIONS_{CURRENT_MAP_ID} |= SOUTH DEF _blk = _src DEF _map = (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _tgt DEF _win = \3_WIDTH + 7 DEF _y = 0 DEF _x = (\4) * -2 DEF _len = CURRENT_MAP_WIDTH + 3 - (\4) if _len > \3_WIDTH DEF _len = \3_WIDTH endc elif "\1" === "west" if MAP_CONNECTIONS_{CURRENT_MAP_ID} & (WEST | EAST) fail "Invalid order for 'connection' (must be north, south, west, east)" endc DEF MAP_CONNECTIONS_{CURRENT_MAP_ID} |= WEST DEF _blk = (\3_WIDTH * _src) + \3_WIDTH - 3 DEF _map = (CURRENT_MAP_WIDTH + 6) * _tgt DEF _win = (\3_WIDTH + 6) * 2 - 6 DEF _y = (\4) * -2 DEF _x = \3_WIDTH * 2 - 1 DEF _len = CURRENT_MAP_HEIGHT + 3 - (\4) if _len > \3_HEIGHT DEF _len = \3_HEIGHT endc elif "\1" === "east" if MAP_CONNECTIONS_{CURRENT_MAP_ID} & EAST fail "Invalid order for 'connection' (must be north, south, west, east)" endc DEF MAP_CONNECTIONS_{CURRENT_MAP_ID} |= EAST DEF _blk = (\3_WIDTH * _src) DEF _map = (CURRENT_MAP_WIDTH + 6) * _tgt + CURRENT_MAP_WIDTH + 3 DEF _win = \3_WIDTH + 7 DEF _y = (\4) * -2 DEF _x = 0 DEF _len = CURRENT_MAP_HEIGHT + 3 - (\4) if _len > \3_HEIGHT DEF _len = \3_HEIGHT endc else fail "Invalid direction for 'connection'." endc map_id \3 dw \2_Blocks + _blk dw wOverworldMapBlocks + _map db _len - _src db \3_WIDTH db _y, _x dw wOverworldMapBlocks + _win ENDM MACRO def_warp_events REDEF _NUM_WARP_EVENTS EQUS "_NUM_WARP_EVENTS_\@" db {_NUM_WARP_EVENTS} DEF {_NUM_WARP_EVENTS} = 0 ENDM MACRO warp_event ;\1: x: left to right, starts at 0 ;\2: y: top to bottom, starts at 0 ;\3: map id: from constants/map_constants.asm ;\4: warp destination: starts at 1 ;\5: wOverworldMapBlocks offset (unused) db \2, \1, \4 map_id \3 dw wOverworldMapBlocks + \5 DEF {_NUM_WARP_EVENTS} += 1 ENDM MACRO def_bg_events REDEF _NUM_BG_EVENTS EQUS "_NUM_BG_EVENTS_\@" db {_NUM_BG_EVENTS} DEF {_NUM_BG_EVENTS} = 0 ENDM MACRO bg_event ;\1: x: left to right, starts at 0 ;\2: y: top to bottom, starts at 0 ;\3: text index db \2, \1, 0, \3 DEF {_NUM_BG_EVENTS} += 1 ENDM MACRO def_object_events REDEF _NUM_OBJECT_EVENTS EQUS "_NUM_OBJECT_EVENTS_\@" db {_NUM_OBJECT_EVENTS} DEF {_NUM_OBJECT_EVENTS} = 0 ENDM MACRO object_event ;\1: x: left to right, starts at 0 ;\2: y: top to bottom, starts at 0 ;\3: sprite: a SPRITE_* constant ;\4: movement function: a SPRITEMOVEDATA_* constant ;\5, \6: movement radius: x, y ;\7, \8: hour limits: h1, h2 (0-23) ; * if h1 < h2, the object_event will only appear from h1 to h2 ; * if h1 > h2, the object_event will not appear from h2 to h1 ; * if h1 == h2, the object_event will always appear ; * if h1 == -1, h2 is treated as a time-of-day value: ; a combo of MORN, DAY, and/or NITE, or -1 to always appear ;\9: object type function ;\<10>: unknown 1 ;\<11>: unknown 2 ;\<12>: sight range ;\<13>: unknown 3 ;\<14>: unknown 4 db \3, \2 + 4, \1 + 4, \4 dn \5, \6 db \7, \8, \9, \<10>, \<11>, \<12>, \<13>, \<14> if DEF(_NUM_OBJECT_EVENTS) DEF {_NUM_OBJECT_EVENTS} += 1 endc ENDM MACRO def_script_pointers const_def ENDM MACRO script_pointer dw \1, \2 const \3 EXPORT \3 ENDM MACRO map_generic_scriptloader {CURRENT_MAP_NAME}_ScriptLoader:: ld hl, {CURRENT_MAP_NAME}ScriptPointers call RunMapScript call WriteBackMapScriptNumber ret ENDM ; For maps that don't have any scenes. MACRO map_generic_script_pointers {CURRENT_MAP_NAME}ScriptPointers:: def_script_pointers script_pointer {CURRENT_MAP_NAME}Script, {CURRENT_MAP_NAME}NPCIDs, SCENE_{CURRENT_MAP_ID}_DEFAULT ENDM MACRO map_generic_script {CURRENT_MAP_NAME}Script:: ld hl, {CURRENT_MAP_NAME}NPCIDs ld de, {CURRENT_MAP_NAME}SignPointers call CallMapTextSubroutine ret ENDM MACRO map_generic_npc_ids {CURRENT_MAP_NAME}NPCIDs:: for x, {_NUM_OBJECT_EVENTS} db x endr db -1 ENDM MACRO map_dummy_text_pointers {CURRENT_MAP_NAME}_ScriptLoader:: ret {CURRENT_MAP_NAME}_TextPointers:: rept 13 dw MapDefaultText endr ENDM MACRO map_dummy_text_pointers_old {CURRENT_MAP_NAME}_ScriptLoader:: ret {CURRENT_MAP_NAME}_TextPointers:: rept 9 dw GameFreakText endr ENDM ; Bank $27 already redirects the text pointers to a dummy file. MACRO map_dummy_script_bank27 {CURRENT_MAP_NAME}_ScriptLoader:: ret db "@" ENDM