Implement View Map mode [commit 1] (#29)

This commit is contained in:
xCrystal 2023-10-31 20:25:56 +01:00
parent 85f9c258b5
commit 147c9f2add
12 changed files with 207 additions and 22 deletions

View File

@ -87,7 +87,8 @@ if DEF(_DEBUG)
const SPAWN_DEBUGLEVEL_5
endc
DEF NUM_SPAWNS EQU const_value
DEF SPAWN_N_A EQU -1
DEF SPAWN_FROM_RAM EQU -2
DEF SPAWN_N_A EQU -1
; Flypoints indexes (see data/maps/flypoints.asm)
const_def

View File

@ -1,19 +1,20 @@
; hMapEntryMethod values
; MapSetupScripts indexes (see data/maps/setup_scripts.asm)
const_def $f1
const MAPSETUP_WARP ; f1
const MAPSETUP_CONTINUE ; f2
const MAPSETUP_RELOADMAP ; f3
const MAPSETUP_TELEPORT ; f4
const MAPSETUP_DOOR ; f5
const MAPSETUP_FALL ; f6
const MAPSETUP_CONNECTION ; f7
const MAPSETUP_LINKRETURN ; f8
const MAPSETUP_TRAIN ; f9
const MAPSETUP_SUBMENU ; fa
const MAPSETUP_BADWARP ; fb
const MAPSETUP_FLY ; fc
const MAPSETUP_ENTERLEVEL ; fd
const MAPSETUP_WARP ; f1
const MAPSETUP_CONTINUE ; f2
const MAPSETUP_RELOADMAP ; f3
const MAPSETUP_TELEPORT ; f4
const MAPSETUP_DOOR ; f5
const MAPSETUP_FALL ; f6
const MAPSETUP_CONNECTION ; f7
const MAPSETUP_LINKRETURN ; f8
const MAPSETUP_TRAIN ; f9
const MAPSETUP_SUBMENU ; fa
const MAPSETUP_BADWARP ; fb
const MAPSETUP_FLY ; fc
const MAPSETUP_ENTERLEVEL ; fd
const MAPSETUP_EXITVIEWMAP ; fe
DEF NUM_MAPSETUP_SCRIPTS EQU const_value - $f1
; callback types

View File

@ -119,4 +119,5 @@ DEF NUM_NAME_TYPES EQU const_value
const BOARDMENUITEM_PACK
const BOARDMENUITEM_POKEGEAR
const BOARDMENUITEM_EXIT
DEF NUM_BOARD_MENU_ITEMS EQU const_value
const BOARDMENUITEM_VIEWMAP ; through select button
DEF NUM_BOARD_MENU_ITEMS EQU const_value - 1 ; don't count BOARDMENUITEM_VIEWMAP

View File

@ -326,9 +326,11 @@ DEF NUM_UNOWN_PUZZLES EQU const_value
; board events (tracked by hCurBoardEvent)
const_def 1
const BOARDEVENT_DISPLAY_MENU ; 1
const BOARDEVENT_HANDLE_BOARD ; 2
const BOARDEVENT_END_TURN ; 3
const BOARDEVENT_DISPLAY_MENU ; 1
const BOARDEVENT_HANDLE_BOARD ; 2
const BOARDEVENT_END_TURN ; 3
const BOARDEVENT_VIEW_MAP_MODE ; 4
const BOARDEVENT_REDISPLAY_MENU ; 5
DEF NUM_BOARD_EVENTS EQU const_value - 1
; exitoverworld arguments

View File

@ -14,6 +14,7 @@ MapSetupScripts:
dw MapSetupScript_BadWarp
dw MapSetupScript_Fly
dw MapSetupScript_EnterLevel
dw MapSetupScript_ExitViewMap
assert_table_length NUM_MAPSETUP_SCRIPTS
; valid commands are listed in MapSetupCommands (see data/maps/setup_script_pointers.asm)
@ -166,6 +167,28 @@ MapSetupScript_ReloadMap:
mapsetup LoadWildMonData
db -1 ; end
MapSetupScript_ExitViewMap:
mapsetup ClearBGPalettes
mapsetup DisableLCD
mapsetup EnterMapSpawnPoint
mapsetup LoadMapAttributes
mapsetup SpawnPlayer
mapsetup RefreshPlayerCoords
mapsetup GetMapScreenCoords
mapsetup LoadBlockData
mapsetup BufferScreen
mapsetup LoadMapGraphics
mapsetup LoadMapTimeOfDay
mapsetup EnableOverworldHUD
mapsetup LoadMapObjects
mapsetup EnableLCD
mapsetup LoadMapPalettes
mapsetup RefreshMapSprites
mapsetup FadeInPalettesFromWhite
mapsetup ActivateMapAnims
mapsetup LoadWildMonData
db -1 ; end
MapSetupScript_LinkReturn:
mapsetup FadeMapMusicAndPalettes
mapsetup DisableLCD

View File

@ -8,10 +8,15 @@ BoardMenuScript::
ifequal BOARDMENUITEM_PACK, .Pack
ifequal BOARDMENUITEM_POKEGEAR, .Pokegear
ifequal BOARDMENUITEM_EXIT, .Exit
ifequal BOARDMENUITEM_VIEWMAP, .ViewMap
closetext
end
.Upkeep:
; skip upkeep if we are re-entering after returning from View Map mode
ld a, [hCurBoardEvent]
cp BOARDEVENT_REDISPLAY_MENU
ret z
; save after opentext to reanchor map first
; save before processing variables like wCurTurn due to BoardMenuScript reentry after game reset
farcall AutoSaveGameInOverworld
@ -68,6 +73,34 @@ BoardMenuScript::
text ""
done
.ViewMap:
callasm .EnterViewMapMode
closetext
end
.EnterViewMapMode:
ld hl, wVramState
res 2, [hl]
ld a, BOARDEVENT_VIEW_MAP_MODE
ldh [hCurBoardEvent], a
ld a, TRUE
ld [wViewMapModeRange], a
ld a, [wMapGroup]
ld [wBeforeViewMapMapGroup], a
ld a, [wMapNumber]
ld [wBeforeViewMapMapNumber], a
ld a, [wXCoord]
ld [wBeforeViewMapXCoord], a
ld a, [wYCoord]
ld [wBeforeViewMapYCoord], a
xor a
ld [wViewMapModeDisplacementY], a
ld [wViewMapModeDisplacementX], a
call DisableOverworldHUD
ld hl, wPlayerFlags
set INVISIBLE_F, [hl]
ret
.SubmenuCallback:
; if submenu has requested a callback through wMenuReturn,
; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr.
@ -163,6 +196,8 @@ GetBoardMenuSelection:
call GetMenuJoypad
bit A_BUTTON_F, a
jr nz, .a_button
bit SELECT_F, a
jr nz, .select_button
bit D_RIGHT_F, a
jr nz, .d_right
bit D_LEFT_F, a
@ -176,6 +211,14 @@ GetBoardMenuSelection:
scf
ret
.select_button
ld a, BOARDMENUITEM_VIEWMAP
ld [wBoardMenuCursorPosition], a
call PlayClickSFX
call WaitSFX
scf
ret
.d_right
call PlayClickSFX
ld a, [wBoardMenuCursorPosition]

View File

@ -331,9 +331,11 @@ CheckBoardEvent:
.Jumptable:
table_width 2, .Jumptable
dw .none
dw .menu ; BOARDEVENT_DISPLAY_MENU
dw .board ; BOARDEVENT_HANDLE_BOARD
dw .none ; BOARDEVENT_END_TURN
dw .menu ; BOARDEVENT_DISPLAY_MENU
dw .board ; BOARDEVENT_HANDLE_BOARD
dw .none ; BOARDEVENT_END_TURN
dw .mapview ; BOARDEVENT_VIEW_MAP_MODE
dw .menu ; BOARDEVENT_REDISPLAY_MENU
assert_table_length NUM_BOARD_EVENTS + 1
.none
@ -369,6 +371,25 @@ CheckBoardEvent:
scf
ret
.mapview
; check if player pressed B and if so queue the script to exit View Map mode
ldh a, [hJoyDown]
and D_PAD
ret nz ; nc
ldh a, [hJoyPressed]
bit B_BUTTON_F, a
ret z ; nc
; B was pressed
ld a, BANK(.ExitMapViewModeScript)
ld hl, .ExitMapViewModeScript
call CallScript
scf
ret
.ExitMapViewModeScript:
reloadmapafterviewmapmode
end
.no_space_effect
; continue moving in board
xor a
@ -389,6 +410,10 @@ CheckBoardEvent:
assert_table_length NUM_COLL_SPACES
CheckTrainerEvent:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckTrainerBattle
jr nc, .nope
@ -409,10 +434,18 @@ CheckTileEvent:
farcall CheckMovingOffEdgeOfMap
jr c, .map_connection
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckWarpTile
jr c, .warp_tile
.connections_disabled
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckCoordEventScriptFlag
jr z, .coord_events_disabled
@ -488,6 +521,10 @@ SetMinTwoStepWildEncounterCooldown: ; unreferenced
ret
RunSceneScript:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
ld a, [wCurMapSceneScriptCount]
and a
jr z, .nope
@ -536,6 +573,10 @@ endr
ret
CheckTimeEvents:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
ld a, [wLinkMode]
and a
jr nz, .nothing
@ -572,10 +613,12 @@ OWPlayerInput:
and a
jr nz, .NoAction
; Can't perform button actions while in BOARDEVENT_HANDLE_BOARD
; Can't perform button actions while in BOARDEVENT_HANDLE_BOARD or BOARDEVENT_VIEW_MAP_MODE
ld a, [hCurBoardEvent]
cp BOARDEVENT_HANDLE_BOARD
jr z, .NoAction
cp BOARDEVENT_VIEW_MAP_MODE
jr z, .NoAction
; Can't perform button actions while sliding on ice.
farcall CheckStandingOnIce
@ -1121,6 +1164,9 @@ WarpToSpawnPoint::
ret
RunMemScript::
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
; If there is no script here, we don't need to be here.
ld a, [wMapReentryScriptQueueFlag]
and a

View File

@ -87,6 +87,11 @@ UpdatePlayerCoords:
jr nz, .check_step_down
ld hl, wYCoord
inc [hl]
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret nz
ld hl, wViewMapModeDisplacementY
inc [hl]
ret
.check_step_down
@ -94,6 +99,11 @@ UpdatePlayerCoords:
jr nz, .check_step_left
ld hl, wYCoord
dec [hl]
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret nz
ld hl, wViewMapModeDisplacementY
dec [hl]
ret
.check_step_left
@ -101,6 +111,11 @@ UpdatePlayerCoords:
jr nz, .check_step_right
ld hl, wXCoord
dec [hl]
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret nz
ld hl, wViewMapModeDisplacementX
dec [hl]
ret
.check_step_right
@ -108,6 +123,11 @@ UpdatePlayerCoords:
ret nz
ld hl, wXCoord
inc [hl]
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret nz
ld hl, wViewMapModeDisplacementX
inc [hl]
ret
UpdateOverworldMap:

View File

@ -235,6 +235,7 @@ ScriptCommandTable:
dw Script_wait ; a8
dw Script_checksave ; a9
dw Script_exitoverworld ; aa
dw Script_reloadmapafterviewmapmode ; db
assert_table_length NUM_EVENT_COMMANDS
StartScript:
@ -1203,6 +1204,22 @@ Script_reloadmapafterbattle:
.done
jp Script_reloadmap
Script_reloadmapafterviewmapmode:
xor a
ld [wBattleScriptFlags], a
ld a, MAPSETUP_EXITVIEWMAP
ldh [hMapEntryMethod], a
ld a, SPAWN_FROM_RAM
ld [wDefaultSpawnpoint], a
ld a, BOARDEVENT_REDISPLAY_MENU
ldh [hCurBoardEvent], a
ld a, MAPSTATUS_ENTER
call LoadMapStatus
ld hl, wPlayerFlags
res INVISIBLE_F, [hl]
call StopScript
ret
Script_reloadmap:
xor a
ld [wBattleScriptFlags], a

View File

@ -7,6 +7,8 @@ EnterMapSpawnPoint:
ld a, [wDefaultSpawnpoint]
cp SPAWN_N_A
jr z, .spawn_n_a
cp SPAWN_FROM_RAM
jr z, .spawn_from_ram
ld l, a
ld h, 0
add hl, hl
@ -21,6 +23,20 @@ EnterMapSpawnPoint:
ld [wXCoord], a
ld a, [hli]
ld [wYCoord], a
pop de
pop hl
ret
.spawn_from_ram
; exiting from View Map mode
ld a, [wBeforeViewMapMapGroup]
ld [wMapGroup], a
ld a, [wBeforeViewMapMapNumber]
ld [wMapNumber], a
ld a, [wBeforeViewMapXCoord]
ld [wXCoord], a
ld a, [wBeforeViewMapYCoord]
ld [wYCoord], a
.spawn_n_a
pop de
pop hl

View File

@ -1071,4 +1071,9 @@ MACRO exitoverworld
db \1 ; exit reason
ENDM
const reloadmapafterviewmapmode_command ; $ab
MACRO reloadmapafterviewmapmode
db reloadmapafterviewmapmode_command
ENDM
DEF NUM_EVENT_COMMANDS EQU const_value

View File

@ -1682,6 +1682,16 @@ wTempSpaceStruct:: space_struct wTempSpace
wTempSpaceStructEnd::
wTempSpaceBranchStruct:: ds NUM_DIRECTIONS * 2
wTempSpaceBranchStructEnd::
wViewMapModeRange:: db
; if either displacement (abs) equals the range, player can't move further in that direction
wViewMapModeDisplacementY:: db
wViewMapModeDisplacementX:: db
; coords and map backup to know where to spawn after returning from View Map mode
wBeforeViewMapYCoord:: db
wBeforeViewMapXCoord:: db
wBeforeViewMapMapGroup:: db
wBeforeViewMapMapNumber:: db
ENDU
wBattleMenuCursorPosition::