diff --git a/constants/script_constants.asm b/constants/script_constants.asm index bb5f69ed6..227dd8b93 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -107,6 +107,7 @@ DEF NUM_PLAYER_MOVEMENTS EQU const_value DEF SCENE_SCRIPT_SIZE EQU 4 ; scene_script DEF CALLBACK_SIZE EQU 3 ; callback DEF WARP_EVENT_SIZE EQU 5 ; warp_event +DEF ANCHOR_EVENT_SIZE EQU 3 ; anchor_event DEF COORD_EVENT_SIZE EQU 8 ; coord_event DEF BG_EVENT_SIZE EQU 5 ; bg_event ; An object_event is a map_object without its initial MAPOBJECT_OBJECT_STRUCT_ID or final padding diff --git a/constants/space_constants.asm b/constants/space_constants.asm index fb110e9f2..6849ae7f2 100755 --- a/constants/space_constants.asm +++ b/constants/space_constants.asm @@ -3,6 +3,14 @@ DEF FIRST_SPACE_METATILE EQU $80 DEF FIRST_GREY_SPACE_METATILE EQU $e0 DEF UNIQUE_SPACE_METATILES_MASK EQU %11111 +; reserved next space values that signal movement towards anchor point rather than towards space + const_def -1, -1 + const GO_DOWN ; 255 + const GO_UP ; 254 + const GO_LEFT ; 253 + const GO_RIGHT ; 252 +DEF NEXT_SPACE_IS_ANCHOR_POINT EQU const_value + 1 + ; Branch Space special direction values DEF BRANCH_DIRECTION_INVALID EQU -1 -DEF BRANCH_DIRECTION_UNAVAILABLE EQU -2 \ No newline at end of file +DEF BRANCH_DIRECTION_UNAVAILABLE EQU -2 diff --git a/data/tilesets/board_debug_1_metatiles.bin b/data/tilesets/board_debug_1_metatiles.bin index e625f6a4f..cb6ea16b9 100755 Binary files a/data/tilesets/board_debug_1_metatiles.bin and b/data/tilesets/board_debug_1_metatiles.bin differ diff --git a/engine/board/movement.asm b/engine/board/movement.asm index 7a98231db..c096b481b 100755 --- a/engine/board/movement.asm +++ b/engine/board/movement.asm @@ -1,5 +1,7 @@ StepTowardsNextSpace:: ld a, [wCurSpaceNextSpace] + cp NEXT_SPACE_IS_ANCHOR_POINT + jr nc, .move_towards_anchor_point call LoadTempSpaceData ld a, [wTempSpaceXCoord] ld c, a @@ -27,3 +29,19 @@ StepTowardsNextSpace:: .done ld [wCurInput], a ret + +.move_towards_anchor_point + ld c, D_DOWN + cp GO_DOWN + jr z, .done2 + ld c, D_UP + cp GO_UP + jr z, .done2 + ld c, D_LEFT + cp GO_LEFT + jr z, .done2 + ld c, D_RIGHT +.done2 + ld a, c + ld [wCurInput], a + ret diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 776af85a4..63fd40f37 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -357,6 +357,32 @@ CheckBoardEvent: .board call CheckSpaceEffectsScriptFlag jr z, .no_space_effect + +; anchor point handler +; if wCurSpaceNextSpace is not an anchor point, override any anchor point we pass though + ld a, [wCurSpaceNextSpace] + cp NEXT_SPACE_IS_ANCHOR_POINT + jr c, .next + ld a, [wCurMapAnchorEventCount] + and a + jr z, .next +; if we have arrived to an anchor point, load its associated next space to wCurSpaceNextSpace right now. +; don't queue a script so that it happens transparently from the point of view of the player's movement. +; note that the next space of an anchor point could be another anchor point. + ld c, a + ld hl, wCurMapAnchorEventsPointer + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wXCoord] + ld d, a + ld a, [wYCoord] + ld e, a + call CheckAndApplyAnchorPoint + ret nc ; if we applied an anchor point, we're done here (we're not in a space) + +.next +; space handler ld a, [wPlayerTile] and $f0 cp HI_NYBBLE_SPACES diff --git a/home/map.asm b/home/map.asm index 860e7bfb6..5dc0f6871 100644 --- a/home/map.asm +++ b/home/map.asm @@ -244,12 +244,12 @@ GetDestinationWarpNumber:: ld a, [wPlayerMapX] sub 4 ld d, a - ld a, [wCurMapWarpCount] + ld a, [wCurMapWarpEventCount] and a ret z ld c, a - ld hl, wCurMapWarpsPointer + ld hl, wCurMapWarpEventsPointer ld a, [hli] ld h, [hl] ld l, a @@ -282,7 +282,7 @@ GetDestinationWarpNumber:: call .IncreaseHLTwice ret nc ; never encountered - ld a, [wCurMapWarpCount] + ld a, [wCurMapWarpEventCount] inc a sub c ld c, a @@ -309,7 +309,7 @@ CopyWarpData:: .CopyWarpData: push bc - ld hl, wCurMapWarpsPointer + ld hl, wCurMapWarpEventsPointer ld a, [hli] ld h, [hl] ld l, a @@ -390,7 +390,8 @@ ReadMapEvents:: ld l, a inc hl inc hl - call ReadWarps + call ReadWarpEvents + call ReadAnchorEvents call ReadCoordEvents call ReadBGEvents @@ -500,14 +501,14 @@ ReadMapCallbacks:: call AddNTimes ret -ReadWarps:: +ReadWarpEvents:: ld a, [hli] ld c, a - ld [wCurMapWarpCount], a + ld [wCurMapWarpEventCount], a ld a, l - ld [wCurMapWarpsPointer], a + ld [wCurMapWarpEventsPointer], a ld a, h - ld [wCurMapWarpsPointer + 1], a + ld [wCurMapWarpEventsPointer + 1], a ld a, c and a ret z @@ -515,6 +516,23 @@ ReadWarps:: call AddNTimes ret +ReadAnchorEvents:: + ld a, [hli] + ld c, a + ld [wCurMapAnchorEventCount], a + ld a, l + ld [wCurMapAnchorEventsPointer], a + ld a, h + ld [wCurMapAnchorEventsPointer + 1], a + + ld a, c + and a + ret z + + ld bc, ANCHOR_EVENT_SIZE + call AddNTimes + ret + ReadCoordEvents:: ld a, [hli] ld c, a @@ -1783,6 +1801,44 @@ GetBlockLocation:: add hl, bc ret +CheckAndApplyAnchorPoint:: +; c = [wCurMapAnchorEventCount] (non-0) +; d = [wXCoord] +; e = [wYCoord] +; hl = [wCurMapAnchorEventsPointer] +; if currently at coords of any anchor point, copy its next space byte to wCurSpaceNextSpace. +; return carry if anchor point matched, nc otherwise. + ldh a, [hROMBank] + push af + call SwitchToMapScriptsBank + +.loop + ld a, [hli] + cp d ; x + jr nz, .next1 + ld a, [hli] + cp e ; y + jr nz, .next2 + +; found anchor point in current player coords + ld a, [hl] + ld [wCurSpaceNextSpace], a + pop af + rst Bankswitch + xor a + ret + +.next1 + inc hl +.next2 + inc hl + dec c + jr nz, .loop + pop af + rst Bankswitch + scf + ret + CheckFacingBGEvent:: call GetFacingTileCoord ; Load facing into b. diff --git a/home/stone_queue.asm b/home/stone_queue.asm index cb4c652c6..81b4a13f7 100644 --- a/home/stone_queue.asm +++ b/home/stone_queue.asm @@ -56,11 +56,11 @@ HandleStoneQueue:: ret .check_on_warp - ld hl, wCurMapWarpsPointer + ld hl, wCurMapWarpEventsPointer ld a, [hli] ld h, [hl] ld l, a - ld a, [wCurMapWarpCount] + ld a, [wCurMapWarpEventCount] and a jr z, .nope2 @@ -94,7 +94,7 @@ HandleStoneQueue:: .found_warp pop af ld d, a - ld a, [wCurMapWarpCount] + ld a, [wCurMapWarpEventCount] sub d inc a scf diff --git a/macros/scripts/maps.asm b/macros/scripts/maps.asm index 251d92349..ecaa8349f 100644 --- a/macros/scripts/maps.asm +++ b/macros/scripts/maps.asm @@ -62,6 +62,21 @@ MACRO warp_event DEF {_NUM_WARP_EVENTS} += 1 ENDM +MACRO def_anchor_events + REDEF _NUM_ANCHOR_EVENTS EQUS "_NUM_ANCHOR_EVENTS_\@" + db {_NUM_ANCHOR_EVENTS} + DEF {_NUM_ANCHOR_EVENTS} = 0 +ENDM + +MACRO anchor_event +;\1: x coord +;\2: y coord +;\3: next space +; there is no \4. An anchor point can't act as an space with an effect (neither as a branch space) + db \1, \2, \3 + DEF {_NUM_ANCHOR_EVENTS} += 1 +ENDM + MACRO def_coord_events REDEF _NUM_COORD_EVENTS EQUS "_NUM_COORD_EVENTS_\@" db {_NUM_COORD_EVENTS} diff --git a/maps/DebugLevel1_Map1.asm b/maps/DebugLevel1_Map1.asm index c6ee138be..eec530a64 100755 --- a/maps/DebugLevel1_Map1.asm +++ b/maps/DebugLevel1_Map1.asm @@ -16,6 +16,8 @@ DebugLevel1_Map1_MapEvents: def_warp_events warp_event 7, 0, LEVEL_1_MAP_1, 1 + def_anchor_events + def_coord_events def_bg_events diff --git a/maps/DebugLevel2_Map1.asm b/maps/DebugLevel2_Map1.asm index eb4565511..c7e6aa262 100755 --- a/maps/DebugLevel2_Map1.asm +++ b/maps/DebugLevel2_Map1.asm @@ -10,6 +10,8 @@ DebugLevel2_Map1_MapEvents: def_warp_events + def_anchor_events + def_coord_events def_bg_events diff --git a/maps/DebugLevel3_Map1.asm b/maps/DebugLevel3_Map1.asm index c57d95049..eb2be9f4f 100755 --- a/maps/DebugLevel3_Map1.asm +++ b/maps/DebugLevel3_Map1.asm @@ -10,6 +10,8 @@ DebugLevel3_Map1_MapEvents: def_warp_events + def_anchor_events + def_coord_events def_bg_events diff --git a/maps/DebugLevel4_Map1.asm b/maps/DebugLevel4_Map1.asm index 667e08f65..10548e5f4 100755 --- a/maps/DebugLevel4_Map1.asm +++ b/maps/DebugLevel4_Map1.asm @@ -10,6 +10,8 @@ DebugLevel4_Map1_MapEvents: def_warp_events + def_anchor_events + def_coord_events def_bg_events diff --git a/maps/DebugLevel5_Map1.asm b/maps/DebugLevel5_Map1.asm index d32658937..4a1772da2 100755 --- a/maps/DebugLevel5_Map1.asm +++ b/maps/DebugLevel5_Map1.asm @@ -10,6 +10,10 @@ DebugLevel5_Map1_MapEvents: def_warp_events + def_anchor_events + anchor_event 10, 1, GO_RIGHT + anchor_event 12, 1, 39 + def_coord_events def_bg_events @@ -58,7 +62,7 @@ DebugLevel5_Map1_MapSpaces: space 6, 2, $0, 36 ; 35 space 6, 0, $0, 37 ; 36 space 8, 0, $0, 38 ; 37 - space 10, 0, $0, 39 ; 38 + space 10, 0, $0, GO_DOWN ; 38 space 12, 0, $0, 40 ; 39 space 14, 0, $0, 41 ; 40 space 16, 0, $0, 42 ; 41 diff --git a/maps/DebugLevel5_Map1.blk b/maps/DebugLevel5_Map1.blk index 515b789df..75022ec65 100755 --- a/maps/DebugLevel5_Map1.blk +++ b/maps/DebugLevel5_Map1.blk @@ -1 +1 @@ -À~€À°Á \ No newline at end of file +ā~€À°Á \ No newline at end of file diff --git a/maps/DebugLevel5_Map1.blk.bak b/maps/DebugLevel5_Map1.blk.bak deleted file mode 100755 index d4fb5113f..000000000 --- a/maps/DebugLevel5_Map1.blk.bak +++ /dev/null @@ -1 +0,0 @@ -555$% \ No newline at end of file diff --git a/maps/Level1_Map1.asm b/maps/Level1_Map1.asm index ddc19ce3a..7d43183c9 100755 --- a/maps/Level1_Map1.asm +++ b/maps/Level1_Map1.asm @@ -16,6 +16,8 @@ Level1_Map1_MapEvents: def_warp_events warp_event 7, 0, LEVEL_1_MAP_1, 1 + def_anchor_events + def_coord_events def_bg_events diff --git a/ram/wram.asm b/ram/wram.asm index 1bf106dac..002fd26c8 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1597,6 +1597,13 @@ wElevatorPointer:: dw wElevatorOriginFloor:: db wElevatorDataEnd:: +NEXTU +; anchor event data +wCurAnchorEvent:: +wCurAnchorEventXCoord:: db +wCurAnchorEventYCoord:: db +wCurAnchorEventNextSpace:: db + NEXTU ; coord event data wCurCoordEvent:: @@ -2434,8 +2441,10 @@ wBikeFlags:: wCurMapSceneScriptPointer:: dw wCurCaller:: dw -wCurMapWarpCount:: db -wCurMapWarpsPointer:: dw +wCurMapWarpEventCount:: db +wCurMapWarpEventsPointer:: dw +wCurMapAnchorEventCount:: db +wCurMapAnchorEventsPointer:: dw wCurMapCoordEventCount:: db wCurMapCoordEventsPointer:: dw wCurMapBGEventCount:: db