Adapt macro based on suggestions

This commit is contained in:
mid-kid 2018-11-11 00:32:05 +01:00
parent 375963349a
commit 814a720e9d

View File

@ -21,73 +21,77 @@ connection: MACRO
;\1: direction
;\2: map name
;\3: map id
;\4: x offset for east/west, y offset for north/south, of the target map
; relative to the current map.
;\4: offset of the target map relative to the current map
; (x offset for east/west, y offset for north/south)
; Figure out target and source offsets
; Target meaning the offset where the tiles will be placed
; Source meaning the offset where the tiles are fetched from
_s = 0
_t = (\4) + 3
if _t < 0
_s = -_t
_t = 0
endc
; Figure out whether we're using the width or the height as maximum size
_st = 0
_ss = 0
if ("\1" == "north") || ("\1" == "south")
_st = \3_WIDTH
_ss = CURRENT_MAP_WIDTH
elif ("\1" == "west") || ("\1" == "east")
_st = \3_HEIGHT
_ss = CURRENT_MAP_HEIGHT
endc
; Figure out the length of the strip to connect
if ((\4) + _st) > (_ss + 3)
_l = _ss + 3 - (\4) - _s
; LEGACY: Support for old connection macro
if _NARG == 6
connection \1, \2, \3, (\4) - (\5)
else
_l = _st - _s
; Calculate tile offsets for source (current) and target maps
_src = 0
_tgt = (\4) + 3
if _tgt < 0
_src = -_tgt
_tgt = 0
endc
if "\1" == "north"
map_id \3
dw \2_Blocks + \3_WIDTH * (\3_HEIGHT + -3) + _s
dw wOverworldMapBlocks + _t
db _l
db \3_WIDTH
db \3_HEIGHT * 2 - 1
db (\4) * -2
dw wOverworldMapBlocks + (\3_WIDTH + 6) * \3_HEIGHT + 1
_blk = \3_WIDTH * (\3_HEIGHT + -3) + _src
_map = _tgt
_win = (\3_WIDTH + 6) * \3_HEIGHT + 1
_y = \3_HEIGHT * 2 - 1
_x = (\4) * -2
_len = CURRENT_MAP_WIDTH + 3 - (\4)
if _len > \3_WIDTH
_len = \3_WIDTH
endc
elif "\1" == "south"
map_id \3
dw \2_Blocks + _s
dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _t
db _l
db \3_WIDTH
db 0
db (\4) * -2
dw wOverworldMapBlocks + \3_WIDTH + 7
_blk = _src
_map = (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _tgt
_win = \3_WIDTH + 7
_y = 0
_x = (\4) * -2
_len = CURRENT_MAP_WIDTH + 3 - (\4)
if _len > \3_WIDTH
_len = \3_WIDTH
endc
elif "\1" == "west"
map_id \3
dw \2_Blocks + (\3_WIDTH * _s) + \3_WIDTH + -3
dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * _t
db _l
db \3_WIDTH
db (\4) * -2
db \3_WIDTH * 2 - 1
dw wOverworldMapBlocks + (\3_WIDTH + 6) * 2 + -6
_blk = (\3_WIDTH * _src) + \3_WIDTH + -3
_map = (CURRENT_MAP_WIDTH + 6) * _tgt
_win = (\3_WIDTH + 6) * 2 + -6
_y = (\4) * -2
_x = \3_WIDTH * 2 - 1
_len = CURRENT_MAP_HEIGHT + 3 - (\4)
if _len > \3_HEIGHT
_len = \3_HEIGHT
endc
elif "\1" == "east"
_blk = (\3_WIDTH * _src)
_map = (CURRENT_MAP_WIDTH + 6) * _tgt + CURRENT_MAP_WIDTH + 3
_win = \3_WIDTH + 7
_y = (\4) * -2
_x = 0
_len = CURRENT_MAP_HEIGHT + 3 - (\4)
if _len > \3_HEIGHT
_len = \3_HEIGHT
endc
else
fail "Invalid direction for 'connection'."
endc
map_id \3
dw \2_Blocks + (\3_WIDTH * _s)
dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * _t + CURRENT_MAP_WIDTH + 3
db _l
dw \2_Blocks + _blk
dw wOverworldMapBlocks + _map
db _len - _src
db \3_WIDTH
db (\4) * -2
db 0
dw wOverworldMapBlocks + \3_WIDTH + 7
db _y, _x
dw wOverworldMapBlocks + _win
endc
ENDM