shithub: pokecrystal

Download patch

ref: 375963349aa9d9eaa254257e36613f4c410b20cf
parent: abb94543071f76d697f22988bf99b171f0af7ef4
author: mid-kid <esteve.varela@gmail.com>
date: Sat Nov 10 09:27:46 EST 2018

Finish new connection macro

Tried simplifying things a bit, although not nearly as much as I wanted.
Ideally, we'd either have one of two situations:
- A single set of calculations based on values depending on the
direction of the connection
- A bunch of "generic" calculations done before applying simple
modifiers to them in the final `if` block

Right now it's an icky mix of both and I'm not really sure what to make
of it.

--- a/data/maps/attributes.asm
+++ b/data/maps/attributes.asm
@@ -17,81 +17,78 @@
 ENDM
 
 ; Connections go in order: north, south, west, east
-_connection: MACRO
+connection: MACRO
 ;\1: direction
 ;\2: map name
 ;\3: map id
-;\4: x offset for east/west, y offset for north/south
-;\5: distance offset?
-;\6: strip length
+;\4: x offset for east/west, y offset for north/south, of the target map
+;    relative to the current map.
+
+; 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
+else
+_l = _st - _s
+endc
+
 if "\1" == "north"
 	map_id \3
-	dw \2_Blocks + \3_WIDTH * (\3_HEIGHT - 3) + \5
-	dw wOverworldMapBlocks + \4 + 3
-	db \6
+	dw \2_Blocks + \3_WIDTH * (\3_HEIGHT + -3) + _s
+	dw wOverworldMapBlocks + _t
+	db _l
 	db \3_WIDTH
 	db \3_HEIGHT * 2 - 1
-	db (\4 - \5) * -2
-	dw wOverworldMapBlocks + \3_HEIGHT * (\3_WIDTH + 6) + 1
+	db (\4) * -2
+	dw wOverworldMapBlocks + (\3_WIDTH + 6) * \3_HEIGHT + 1
 elif "\1" == "south"
 	map_id \3
-	dw \2_Blocks + \5
-	dw wOverworldMapBlocks + (CURRENT_MAP_HEIGHT + 3) * (CURRENT_MAP_WIDTH + 6) + \4 + 3
-	db \6
+	dw \2_Blocks + _s
+	dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _t
+	db _l
 	db \3_WIDTH
 	db 0
-	db (\4 - \5) * -2
+	db (\4) * -2
 	dw wOverworldMapBlocks + \3_WIDTH + 7
 elif "\1" == "west"
 	map_id \3
-	dw \2_Blocks + (\3_WIDTH * \5) + \3_WIDTH - 3
-	dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * (\4 + 3)
-	db \6
+	dw \2_Blocks + (\3_WIDTH * _s) + \3_WIDTH + -3
+	dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * _t
+	db _l
 	db \3_WIDTH
-	db (\4 - \5) * -2
+	db (\4) * -2
 	db \3_WIDTH * 2 - 1
-	dw wOverworldMapBlocks + \3_WIDTH * 2 + 6
+	dw wOverworldMapBlocks + (\3_WIDTH + 6) * 2 + -6
 elif "\1" == "east"
 	map_id \3
-	dw \2_Blocks + (\3_WIDTH * \5)
-	dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * (\4 + 3 + 1) - 3
-	db \6
+	dw \2_Blocks + (\3_WIDTH * _s)
+	dw wOverworldMapBlocks + (CURRENT_MAP_WIDTH + 6) * _t + CURRENT_MAP_WIDTH + 3
+	db _l
 	db \3_WIDTH
-	db (\4 - \5) * -2
+	db (\4) * -2
 	db 0
 	dw wOverworldMapBlocks + \3_WIDTH + 7
 endc
-ENDM
-
-connection: MACRO
-;\1: direction
-;\2: map name
-;\3: map id
-;\4: x offset for east/west, y offset for north/south
-
-if (\4) < -3
-_f = -3
-_s = -((\4) + 3)
-else
-_f = (\4)
-_s = 0
-endc
-
-if ("\1" == "north") || ("\1" == "south")
-if ((\4) + \3_WIDTH) > (CURRENT_MAP_WIDTH + 3)
-_l = CURRENT_MAP_WIDTH + 3 - (\4) - _s
-else
-_l = \3_WIDTH - _s
-endc
-elif ("\1" == "west") || ("\1" == "east")
-if ((\4) + \3_HEIGHT) > (CURRENT_MAP_HEIGHT + 3)
-_l = CURRENT_MAP_HEIGHT + 3 - (\4) - _s
-else
-_l = \3_HEIGHT - _s
-endc
-endc
-
-	_connection \1, \2, \3, _f, _s, _l
 ENDM
 
 
--- a/engine/overworld/warp_connection.asm
+++ b/engine/overworld/warp_connection.asm
@@ -18,7 +18,7 @@
 EnterMapConnection:
 ; Return carry if a connection has been entered.
 	ld a, [wPlayerStepDirection]
-	and a
+	and a ; DOWN
 	jp z, .south
 	cp UP
 	jp z, .north