map: MACRO
	rept _NARG
		db GROUP_\1, MAP_\1
		shift
	endr
ENDM

roam_map: MACRO
; A map and an arbitrary number of some more maps.

	map \1
	db  \2

	rept \2
	map \3
	shift
	endr

	db 0
ENDM

person_event: macro
person_event_narg = _NARG
	db \1 ; sprite
	db \2 + 4 ; y
	db \3 + 4 ; x
	db \4 ; movement function
	dn \5, \6 ; radius: y, x
	db \7 ; clock_hour
	db \8 ; clock_daytime
	shift
	dn \8, \9 ; color_function
	IF \9 == PERSONTYPE_JUMPSTD
		shift
		db \9 ; sight_range
		shift
		db \9 ; std
		IF person_event_narg == 14
			shift
			db \9
		ELSE
			db 0
		ENDC
	ELSE
		shift
		db \9 ; sight_range
		shift
		dw \9 ; pointer
	ENDC	
	shift
	dw \9 ; event flag
	endm

signpost: macro
boolean_or = 0
	db \1 ; y
	db \2 ; x
	db \3 ; function
	IF \3 == SIGNPOST_JUMPSTD
boolean_or = 1
	ELSE
		IF \3 == SIGNPOST_JUMPSTDNOSFX
boolean_or = 1
		ENDC
	ENDC
	IF boolean_or == 1
		db \4
		IF _NARG == 5
			db \5
		ELSE
			db 0
		ENDC
	ELSE
		dw \4 ; pointer
	ENDC
	endm

xy_trigger: macro
	db \1 ; number
	db \2 ; y
	db \3 ; x
	db \4 ; unknown1
	dw \5 ; script
	IF _NARG == 6
		dw \6 ; event
	ELSE
		db \6 ; unknown2
		db \7 ; unknown3
	ENDC
	endm

warp_def: macro
	db \1 ; y
	db \2 ; x
	db \3 ; warp_to
	map \4 ; map
	endm

dummy_warp: macro
	db \1 ; y
	db \2 ; x
	db 0, 0, 0
	endm

map_header: MACRO
	; label, tileset, permission, location, music, phone service flag, time of day, fishing group
\1_MapHeader:
	db BANK(\1_SecondMapHeader), \2, \3
	dw \1_SecondMapHeader
	db \4, \5
	dn \6, \7
	db \8
ENDM


map_header_2: MACRO
; label, map, border block, connections
\1_SecondMapHeader::
	db \3
	db \2_HEIGHT, \2_WIDTH
	db BANK(\1_BlockData)
	dw \1_BlockData
	db BANK(\1_MapScriptHeader)
	dw \1_MapScriptHeader
	dw \1_MapEventHeader
	db \4
ENDM

connection: MACRO
if "\1" == "north"
;\2: map id
;\3: map label (eventually will be rolled into map id)
;\4: x
;\5: offset?
;\6: strip length
;\7: this map id
	map \2
	dw wDecompressScratch + \2_WIDTH * (\2_HEIGHT - 3) + \5
	dw OverworldMap + \4 + 3
	db \6
	db \2_WIDTH
	db \2_HEIGHT * 2 - 1
	db (\4 - \5) * -2
	dw OverworldMap + \2_HEIGHT * (\2_WIDTH + 6) + 1
endc

if "\1" == "south"
;\2: map id
;\3: map label (eventually will be rolled into map id)
;\4: x
;\5: offset?
;\6: strip length
;\7: this map id
	map \2
	dw wDecompressScratch + \5
	dw OverworldMap + (\7_HEIGHT + 3) * (\7_WIDTH + 6) + \4 + 3
	db \6
	db \2_WIDTH
	db 0
	db (\4 - \5) * -2
	dw OverworldMap + \2_WIDTH + 7
endc

if "\1" == "west"
;\2: map id
;\3: map label (eventually will be rolled into map id)
;\4: y
;\5: offset?
;\6: strip length
;\7: this map id
	map \2
	dw wDecompressScratch + (\2_WIDTH * \5) + \2_WIDTH - 3
	dw OverworldMap + (\7_WIDTH + 6) * (\4 + 3)
	db \6
	db \2_WIDTH
	db (\4 - \5) * -2
	db \2_WIDTH * 2 - 1
	dw OverworldMap + \2_WIDTH * 2 + 6
endc

if "\1" == "east"
;\2: map id
;\3: map label (eventually will be rolled into map id)
;\4: y
;\5: offset?
;\6: strip length
;\7: this map id
	map \2
	dw wDecompressScratch + (\2_WIDTH * \5)
	dw OverworldMap + (\7_WIDTH + 6) * (\4 + 3 + 1) - 3
	db \6
	db \2_WIDTH
	db (\4 - \5) * -2
	db 0
	dw OverworldMap + \2_WIDTH + 7
endc

ENDM

mapgroup: MACRO
GROUP_\1 EQU const_value
	enum MAP_\1
\1_HEIGHT EQU \2
\1_WIDTH EQU \3
ENDM

newgroup: MACRO
const_value = const_value + 1
	enum_start 1
ENDM

elevfloor: MACRO
	db \1, \2
	map \3
ENDM

itemball: MACRO
if _NARG == 2
	db \1, \2
else
	db \1, 1
endc
endm

stonetable: MACRO
	db \1, \2
	dw \3
endm

maptrigger: MACRO
	dw \1, 0
endm

eventflagchangeblock: MACRO
	dw \1
	db \2, \3, \4
ENDM