Add anchor points to support manual movement between spaces (#26)

This commit is contained in:
xCrystal 2023-11-16 17:20:13 +01:00
parent 8b9d731c5c
commit 6613cd5386
17 changed files with 164 additions and 18 deletions

View File

@ -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

View File

@ -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
DEF BRANCH_DIRECTION_UNAVAILABLE EQU -2

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -10,6 +10,8 @@ DebugLevel2_Map1_MapEvents:
def_warp_events
def_anchor_events
def_coord_events
def_bg_events

View File

@ -10,6 +10,8 @@ DebugLevel3_Map1_MapEvents:
def_warp_events
def_anchor_events
def_coord_events
def_bg_events

View File

@ -10,6 +10,8 @@ DebugLevel4_Map1_MapEvents:
def_warp_events
def_anchor_events
def_coord_events
def_bg_events

View File

@ -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

View File

@ -1 +1 @@
€Ã°Â<EFBFBD>°¡ÿ€~€°Ã¡±¡¡¡À€°€À<02>¡°Á€€€Â°Ã<C2B0>¡±¡¡
€Ã°Â<EFBFBD>°¡ÿ€~€°Ã¡±¡¡¡À€°€À<02>¡°Á€€€Â°Ã<C2B0>¡±¡¡

View File

@ -1 +0,0 @@
555$%

View File

@ -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

View File

@ -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