Implement Surf technique, avoid facing-tile events when player has yet to STEP_TURN or while not in BOARDEVENT_HANDLE_BOARD [bugfix to previous two commits] (#34)

new tile permission SPACE_TILE added, which acts as WATER_TILE while on PLAYER_SURF or PLAYER_SURF_PIKA state, as LAND_TILE otherwise
This commit is contained in:
xCrystal 2023-12-30 00:27:50 +01:00
parent 303deca959
commit aa91909388
9 changed files with 96 additions and 38 deletions

View File

@ -1,6 +1,7 @@
; collision permissions (see data/collision/collision_permissions.asm) ; collision permissions (see data/collision/collision_permissions.asm)
DEF LAND_TILE EQU $00 DEF LAND_TILE EQU $00
DEF WATER_TILE EQU $01 DEF WATER_TILE EQU $01
DEF SPACE_TILE EQU $03 ; acts as WATER_TILE while on PLAYER_SURF or PLAYER_SURF_PIKA state, as LAND_TILE otherwise
DEF WALL_TILE EQU $0f DEF WALL_TILE EQU $0f
DEF TALK EQU $10 DEF TALK EQU $10

View File

@ -209,22 +209,22 @@ TileCollisionTable::
db WATER_TILE ; cd db WATER_TILE ; cd
db WATER_TILE ; ce db WATER_TILE ; ce
db WATER_TILE ; cf db WATER_TILE ; cf
db LAND_TILE ; COLL_BLUE_SPACE db SPACE_TILE ; COLL_BLUE_SPACE
db LAND_TILE ; COLL_RED_SPACE db SPACE_TILE ; COLL_RED_SPACE
db LAND_TILE ; COLL_GREEN_SPACE db SPACE_TILE ; COLL_GREEN_SPACE
db LAND_TILE ; COLL_ITEM_SPACE db SPACE_TILE ; COLL_ITEM_SPACE
db LAND_TILE ; COLL_POKEMON_SPACE db SPACE_TILE ; COLL_POKEMON_SPACE
db LAND_TILE ; COLL_MINIGAME_SPACE db SPACE_TILE ; COLL_MINIGAME_SPACE
db LAND_TILE ; COLL_END_SPACE db SPACE_TILE ; COLL_END_SPACE
db LAND_TILE ; COLL_GREY_SPACE db SPACE_TILE ; COLL_GREY_SPACE
db LAND_TILE ; COLL_BRANCH_SPACE db SPACE_TILE ; COLL_BRANCH_SPACE
db LAND_TILE ; COLL_UNION_SPACE db SPACE_TILE ; COLL_UNION_SPACE
db LAND_TILE ; da db SPACE_TILE ; da
db LAND_TILE ; db db SPACE_TILE ; db
db LAND_TILE ; dc db SPACE_TILE ; dc
db LAND_TILE ; dd db SPACE_TILE ; dd
db LAND_TILE ; de db SPACE_TILE ; de
db LAND_TILE ; df db SPACE_TILE ; df
db LAND_TILE ; e0 db LAND_TILE ; e0
db LAND_TILE ; e1 db LAND_TILE ; e1
db LAND_TILE ; e2 db LAND_TILE ; e2

View File

@ -144,10 +144,10 @@
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 8f tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 8f
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 90 tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 90
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 91 tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 91
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 92 tilecoll BLUE_SPACE, WATER, WATER, WATER ; 92
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 93 tilecoll BLUE_SPACE, WATER, WATER, WATER ; 93
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 94 tilecoll BLUE_SPACE, WATER, FLOOR, WATER ; 94
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 95 tilecoll BLUE_SPACE, WATER, FLOOR, WATER ; 95
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 96 tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 96
tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 97 tilecoll BLUE_SPACE, FLOOR, FLOOR, FLOOR ; 97
tilecoll POKEMON_SPACE, FLOOR, FLOOR, FLOOR ; 98 tilecoll POKEMON_SPACE, FLOOR, FLOOR, FLOOR ; 98
@ -176,10 +176,10 @@
tilecoll POKEMON_SPACE, FLOOR, FLOOR, FLOOR ; af tilecoll POKEMON_SPACE, FLOOR, FLOOR, FLOOR ; af
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b0 tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b0
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b1 tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b1
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b2 tilecoll RED_SPACE, WATER, WATER, WATER ; b2
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b3 tilecoll RED_SPACE, WATER, WATER, WATER ; b3
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b4 tilecoll RED_SPACE, WATER, FLOOR, WATER ; b4
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b5 tilecoll RED_SPACE, WATER, FLOOR, WATER ; b5
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b6 tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b6
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b7 tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b7
tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b8 tilecoll RED_SPACE, FLOOR, FLOOR, FLOOR ; b8
@ -205,13 +205,13 @@
tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; cc tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; cc
tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; cd tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; cd
tilecoll ITEM_SPACE, FLOOR, FLOOR, FLOOR ; ce tilecoll ITEM_SPACE, FLOOR, FLOOR, FLOOR ; ce
tilecoll FLOOR, FLOOR, FLOOR, FLOOR ; cf tilecoll MINIGAME_SPACE, FLOOR, FLOOR, FLOOR ; cf
tilecoll END_SPACE, FLOOR, FLOOR, FLOOR ; d0 tilecoll END_SPACE, FLOOR, FLOOR, FLOOR ; d0
tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; d1 tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; d1
tilecoll ITEM_SPACE, FLOOR, FLOOR, FLOOR ; d2 tilecoll ITEM_SPACE, WATER, WATER, WATER ; d2
tilecoll MINIGAME_SPACE, FLOOR, FLOOR, FLOOR ; d3 tilecoll MINIGAME_SPACE, WATER, WATER, WATER ; d3
tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; d4 tilecoll GREEN_SPACE, WATER, FLOOR, WATER ; d4
tilecoll GREEN_SPACE, FLOOR, FLOOR, FLOOR ; d5 tilecoll GREEN_SPACE, WATER, FLOOR, WATER ; d5
tilecoll ITEM_SPACE, FLOOR, FLOOR, FLOOR ; d6 tilecoll ITEM_SPACE, FLOOR, FLOOR, FLOOR ; d6
tilecoll MINIGAME_SPACE, FLOOR, FLOOR, FLOOR ; d7 tilecoll MINIGAME_SPACE, FLOOR, FLOOR, FLOOR ; d7
tilecoll END_SPACE, FLOOR, FLOOR, FLOOR ; d8 tilecoll END_SPACE, FLOOR, FLOOR, FLOOR ; d8
@ -240,10 +240,10 @@
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; ef tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; ef
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f0 tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f0
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f1 tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f1
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f2 tilecoll GREY_SPACE, WATER, WATER, WATER ; f2
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f3 tilecoll GREY_SPACE, WATER, WATER, WATER ; f3
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f4 tilecoll GREY_SPACE, WATER, FLOOR, WATER ; f4
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f5 tilecoll GREY_SPACE, WATER, FLOOR, WATER ; f5
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f6 tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f6
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f7 tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f7
tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f8 tilecoll GREY_SPACE, FLOOR, FLOOR, FLOOR ; f8

View File

@ -1,4 +1,4 @@
././././>?>?././././>?>?23XXBCXXXXXX1666AHHHAHHHQRRR6664HHHDHHHDRRRT+,,-;<<=;<<=KLLM@@@@@@@@ZZ@@YY@@@@ZZ@@YY@@@@@@@@&&&&&& ././././>?>?././././>?>?23XXBCXXXXXX1666AHHHAHHHQRRR6664HHHDHHHDRRRT+,,-;<<=;<<=KLLM@@@@@@@@ZZ@@YY@@@@ZZ@@YY@@@@@@@@&&&&&&
&& &&
789: 789:   789: 789:  
 789: &&#$789:&& <<<<嵗╯停眾貝物<<<<丰戍斯須洎悖ASSSQRRR"A<>PQRRSSSDRRRT<52>D%RRTU"A<>PQRR"A<>PQRR<52>D%RRTU<54>D%RRTUASSSQRRR<1A><><EFBFBD>㜭SSSRRRR'(<28>)*<2A>"A<>PQRR;'(;<3B>)*<2A>D%RRTU<54>=<3D><>=>?>?SSSSSSSSSSSSRRRR<52><52><EFBFBD><EFBFBD>>?>?1SSSASSS>?>?SSS4SSSDASSSQRRR<1A>'(<28>)*SSSDRRRT<52><54><1C><>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX號獄娧RR;<3B>'(;<3B>)*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX播噶RRRT<52>=<3D><>=>?>?>?>?ZZZZJYYYJJZZZZYYYYZZZZYYYJJJIIIIJJJJNO^_JJJJNO^_JJZZZZYYYYZZZZYYYYJJZZZZYYYYLL;;;;====;;;;====;;;KLLL===LLLM;;;KLLL===LLLM\LLL===LLL];;;LLLLLLLL====;;;;LL>?E>?>?>?>?>?>?>?>?>?E>?>?>?>?>?>?>?>?E>?>?>?>?>?>?>?>?>?E>?;;<<;;<<;;<<;;<<<<==<<==<<==<<==<+,,+;<<;;<<;;<<,,-<<<=-<<==<<==;;<<;;<<;KLLKLLL<<==<<==LLM=LLLM<<<<<<<<LL<<L;<<<<<<<<<<<<LL<<=L,,,,<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<LLLLLLLL<<<<<<<<FGLLVWLL;KL<4B>=LLLMLLLL789:NO^_MK6666HHHHHHHHRRRR擱NO倳^_<06><06><06><06><06><06><06><06><06><06><05><06><06>NO崷^_<06><06><06><06><06><06><06><06><06><06><06>霰NO婭^_恘NO睧^_  789: &&#$789:&& <<<<嵗╯停眾貝物<<<<丰戍斯須洎悖ASSSQRRR"A<>PQRRSSSDRRRT<52>D%RRTU"A<>PQRR"A<>PQRR<52>D%RRTU<54>D%RRTUASSSQRRR<1A><><EFBFBD>㜭SSSRRRR'(<28>)*<2A>"A<>PQRR;'(;<3B>)*<2A>D%RRTU<54>=<3D><>=>?>?SSSSSSSSSSSSRRRR<52><52><EFBFBD><EFBFBD>>?>?1SSSASSS>?>?SSS4SSSDASSSQRRR<1A>'(<28>)*SSSDRRRT<52><54><1C><>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX號獄娧RR;<3B>'(;<3B>)*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX播噶RRRT<52>=<3D><>=>?>?>?>?ZZZZJYYYJJZZZZYYYYZZZZYYYJJJIIIIJJJJNO^_JJJJNO^_JJZZZZYYYYZZZZYYYYJJZZZZYYYYLL;;;;====;;;;====;;;KLLL===LLLM;;;KLLL===LLLM\LLL===LLL];;;LLLLLLLL====;;;;LL>?E>?>?>?>?>?>?>?>?>?E>?>?>?>?>?>?>?>?E>?>?>?>?>?>?>?>?>?E>?;;<<;;<<;;<<;;<<<<==<<==<<==<<==<+,,+;<<;;<<;;<<,,-<<<=-<<==<<==;;<<;;<<;KLLKLLL<<==<<==LLM=LLLM<<<<<<<<LL<<L;<<<<<<<<<<<<LL<<=L,,,,<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<LLLLLLLL<<<<<<<<FGLLVWLL;KL<4B>=LLLMLLLL789:NO^_MK6666HHHHHHHHRRRR擱NO倳^_;倳;;;擱\L倳;;;擱;倳;;;<06><06><06><06><06><06><06><06><06><06><05><06><06>NO崷^_<06><06><06><06><06><06><06><06><06><06><06>;眑;;;藏\L眑;;;藏;眑;;;霰NO婭^_;窙;;;霰\L婭;;;霰;婭;;;恘NO睧^_;睧;;;恘\L睧;;;恘;睧;;;

View File

@ -408,6 +408,16 @@ SurfFunction:
ld a, $80 ld a, $80
ret ret
SurfAutoScript::
readmem wSurfingPlayerState
writevar VAR_MOVEMENT
special UpdatePlayerSprite
special PlayMapMusic
; step into the water (slow_step DIR, step_end)
special SurfStartStep
applymovement PLAYER, wMovementBuffer
end
SurfFromMenuScript: SurfFromMenuScript:
special UpdateTimePals special UpdateTimePals
@ -456,7 +466,7 @@ GetSurfType:
ld a, PLAYER_SURF ld a, PLAYER_SURF
ret ret
CheckDirection: CheckDirection::
; Return carry if a tile permission prevents you ; Return carry if a tile permission prevents you
; from moving in the direction you're facing. ; from moving in the direction you're facing.

View File

@ -641,9 +641,23 @@ SetMinTwoStepWildEncounterCooldown: ; unreferenced
ret ret
CheckFacingTileEvent: CheckFacingTileEvent:
; no tile events if not in BOARDEVENT_HANDLE_BOARD (e.g. after player lands in space)
ldh a, [hCurBoardEvent] ldh a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE cp BOARDEVENT_HANDLE_BOARD
jr nz, .NoAction
; no facing-tile events until player has turned to the walking direction.
; if the player has to perform a STEP_TURN first, the facing tile is not the right one.
ld a, [wWalkingDirection]
cp STANDING
jr z, .NoAction jr z, .NoAction
ld e, a
ld a, [wPlayerDirection]
rrca
rrca
maskbits NUM_DIRECTIONS
cp e
jr nz, .NoAction
call .TryObjectEvent call .TryObjectEvent
jr c, .Action jr c, .Action
@ -729,6 +743,33 @@ CheckFacingTileEvent:
ret ; c ret ; c
.TryTileCollisionEvent: .TryTileCollisionEvent:
call GetFacingTileCoord
ld [wFacingTileID], a
;; Surf
; Don't surf if already surfing.
ld a, [wPlayerState]
cp PLAYER_SURF_PIKA
jr z, .next_event_1
cp PLAYER_SURF
jr z, .next_event_1
; Must be facing water.
ld a, [wFacingTileID]
call GetTileCollision
cp WATER_TILE
jr nz, .next_event_1
ld a, PLAYER_SURF
ld [wSurfingPlayerState], a
ld a, BANK(SurfAutoScript)
ld hl, SurfAutoScript
call CallScript
ret ; c
.next_event_1
.no_event
xor a xor a
ret ; nc ret ; nc

View File

@ -929,6 +929,8 @@ ENDM
call GetTileCollision call GetTileCollision
and a ; LAND_TILE and a ; LAND_TILE
ret z ret z
cp SPACE_TILE
ret z
scf scf
ret ret
@ -939,6 +941,10 @@ ENDM
call GetTileCollision call GetTileCollision
cp WATER_TILE cp WATER_TILE
jr z, .Water jr z, .Water
; because this is called during PLAYER_SURF or PLAYER_SURF_PIKA state,
; SPACE_TILE is considered still water. Do not stop surfing on a space tile.
cp SPACE_TILE
jr z, .Water
; Can walk back onto land from water. ; Can walk back onto land from water.
and a ; LAND_TILE and a ; LAND_TILE

View File

@ -26,7 +26,7 @@ DebugLevel2_Map1_MapEvents:
def_bg_events def_bg_events
def_object_events def_object_events
object_event 6, 13, SPRITE_ROCK, SPRITEMOVEDATA_SMASHABLE_ROCK, 0, 0, -1, -1, 0, OBJECTTYPE_ROCK, 0, ObjectEvent, -1 object_event 4, 13, SPRITE_ROCK, SPRITEMOVEDATA_SMASHABLE_ROCK, 0, 0, -1, -1, 0, OBJECTTYPE_ROCK, 0, ObjectEvent, -1
object_event 5, 12, SPRITE_ROCK, SPRITEMOVEDATA_SMASHABLE_ROCK, 0, 0, -1, -1, 0, OBJECTTYPE_ROCK, 0, ObjectEvent, -1 object_event 5, 12, SPRITE_ROCK, SPRITEMOVEDATA_SMASHABLE_ROCK, 0, 0, -1, -1, 0, OBJECTTYPE_ROCK, 0, ObjectEvent, -1
DebugLevel2_Map1_MapSpaces: DebugLevel2_Map1_MapSpaces:

View File

@ -1 +1 @@
~Ä°Â<C2B0>°¡ÿ€~€°Ã¡±¡¡¡À€°€À<02>¡°Á€€€Â°Ã<EFBFBD>¡±¡¡ ~Ä°Â<C2B0>°¡ÿ€~€°Ã¡±¡¡¡À€°€À<02>¡´vvvUÁ•’’Ò³Ã<EFBFBD>¡±¡¡