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 const SPAWN_DEBUGLEVEL_5
endc endc
DEF NUM_SPAWNS EQU const_value 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) ; Flypoints indexes (see data/maps/flypoints.asm)
const_def const_def

View File

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

View File

@ -119,4 +119,5 @@ DEF NUM_NAME_TYPES EQU const_value
const BOARDMENUITEM_PACK const BOARDMENUITEM_PACK
const BOARDMENUITEM_POKEGEAR const BOARDMENUITEM_POKEGEAR
const BOARDMENUITEM_EXIT 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) ; board events (tracked by hCurBoardEvent)
const_def 1 const_def 1
const BOARDEVENT_DISPLAY_MENU ; 1 const BOARDEVENT_DISPLAY_MENU ; 1
const BOARDEVENT_HANDLE_BOARD ; 2 const BOARDEVENT_HANDLE_BOARD ; 2
const BOARDEVENT_END_TURN ; 3 const BOARDEVENT_END_TURN ; 3
const BOARDEVENT_VIEW_MAP_MODE ; 4
const BOARDEVENT_REDISPLAY_MENU ; 5
DEF NUM_BOARD_EVENTS EQU const_value - 1 DEF NUM_BOARD_EVENTS EQU const_value - 1
; exitoverworld arguments ; exitoverworld arguments

View File

@ -14,6 +14,7 @@ MapSetupScripts:
dw MapSetupScript_BadWarp dw MapSetupScript_BadWarp
dw MapSetupScript_Fly dw MapSetupScript_Fly
dw MapSetupScript_EnterLevel dw MapSetupScript_EnterLevel
dw MapSetupScript_ExitViewMap
assert_table_length NUM_MAPSETUP_SCRIPTS assert_table_length NUM_MAPSETUP_SCRIPTS
; valid commands are listed in MapSetupCommands (see data/maps/setup_script_pointers.asm) ; valid commands are listed in MapSetupCommands (see data/maps/setup_script_pointers.asm)
@ -166,6 +167,28 @@ MapSetupScript_ReloadMap:
mapsetup LoadWildMonData mapsetup LoadWildMonData
db -1 ; end 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: MapSetupScript_LinkReturn:
mapsetup FadeMapMusicAndPalettes mapsetup FadeMapMusicAndPalettes
mapsetup DisableLCD mapsetup DisableLCD

View File

@ -8,10 +8,15 @@ BoardMenuScript::
ifequal BOARDMENUITEM_PACK, .Pack ifequal BOARDMENUITEM_PACK, .Pack
ifequal BOARDMENUITEM_POKEGEAR, .Pokegear ifequal BOARDMENUITEM_POKEGEAR, .Pokegear
ifequal BOARDMENUITEM_EXIT, .Exit ifequal BOARDMENUITEM_EXIT, .Exit
ifequal BOARDMENUITEM_VIEWMAP, .ViewMap
closetext closetext
end end
.Upkeep: .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 after opentext to reanchor map first
; save before processing variables like wCurTurn due to BoardMenuScript reentry after game reset ; save before processing variables like wCurTurn due to BoardMenuScript reentry after game reset
farcall AutoSaveGameInOverworld farcall AutoSaveGameInOverworld
@ -68,6 +73,34 @@ BoardMenuScript::
text "" text ""
done 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: .SubmenuCallback:
; if submenu has requested a callback through wMenuReturn, ; if submenu has requested a callback through wMenuReturn,
; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr. ; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr.
@ -163,6 +196,8 @@ GetBoardMenuSelection:
call GetMenuJoypad call GetMenuJoypad
bit A_BUTTON_F, a bit A_BUTTON_F, a
jr nz, .a_button jr nz, .a_button
bit SELECT_F, a
jr nz, .select_button
bit D_RIGHT_F, a bit D_RIGHT_F, a
jr nz, .d_right jr nz, .d_right
bit D_LEFT_F, a bit D_LEFT_F, a
@ -176,6 +211,14 @@ GetBoardMenuSelection:
scf scf
ret ret
.select_button
ld a, BOARDMENUITEM_VIEWMAP
ld [wBoardMenuCursorPosition], a
call PlayClickSFX
call WaitSFX
scf
ret
.d_right .d_right
call PlayClickSFX call PlayClickSFX
ld a, [wBoardMenuCursorPosition] ld a, [wBoardMenuCursorPosition]

View File

@ -331,9 +331,11 @@ CheckBoardEvent:
.Jumptable: .Jumptable:
table_width 2, .Jumptable table_width 2, .Jumptable
dw .none dw .none
dw .menu ; BOARDEVENT_DISPLAY_MENU dw .menu ; BOARDEVENT_DISPLAY_MENU
dw .board ; BOARDEVENT_HANDLE_BOARD dw .board ; BOARDEVENT_HANDLE_BOARD
dw .none ; BOARDEVENT_END_TURN dw .none ; BOARDEVENT_END_TURN
dw .mapview ; BOARDEVENT_VIEW_MAP_MODE
dw .menu ; BOARDEVENT_REDISPLAY_MENU
assert_table_length NUM_BOARD_EVENTS + 1 assert_table_length NUM_BOARD_EVENTS + 1
.none .none
@ -369,6 +371,25 @@ CheckBoardEvent:
scf scf
ret 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 .no_space_effect
; continue moving in board ; continue moving in board
xor a xor a
@ -389,6 +410,10 @@ CheckBoardEvent:
assert_table_length NUM_COLL_SPACES assert_table_length NUM_COLL_SPACES
CheckTrainerEvent: CheckTrainerEvent:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckTrainerBattle call CheckTrainerBattle
jr nc, .nope jr nc, .nope
@ -409,10 +434,18 @@ CheckTileEvent:
farcall CheckMovingOffEdgeOfMap farcall CheckMovingOffEdgeOfMap
jr c, .map_connection jr c, .map_connection
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckWarpTile call CheckWarpTile
jr c, .warp_tile jr c, .warp_tile
.connections_disabled .connections_disabled
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
call CheckCoordEventScriptFlag call CheckCoordEventScriptFlag
jr z, .coord_events_disabled jr z, .coord_events_disabled
@ -488,6 +521,10 @@ SetMinTwoStepWildEncounterCooldown: ; unreferenced
ret ret
RunSceneScript: RunSceneScript:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
ld a, [wCurMapSceneScriptCount] ld a, [wCurMapSceneScriptCount]
and a and a
jr z, .nope jr z, .nope
@ -536,6 +573,10 @@ endr
ret ret
CheckTimeEvents: CheckTimeEvents:
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
ld a, [wLinkMode] ld a, [wLinkMode]
and a and a
jr nz, .nothing jr nz, .nothing
@ -572,10 +613,12 @@ OWPlayerInput:
and a and a
jr nz, .NoAction 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] ld a, [hCurBoardEvent]
cp BOARDEVENT_HANDLE_BOARD cp BOARDEVENT_HANDLE_BOARD
jr z, .NoAction jr z, .NoAction
cp BOARDEVENT_VIEW_MAP_MODE
jr z, .NoAction
; Can't perform button actions while sliding on ice. ; Can't perform button actions while sliding on ice.
farcall CheckStandingOnIce farcall CheckStandingOnIce
@ -1121,6 +1164,9 @@ WarpToSpawnPoint::
ret ret
RunMemScript:: RunMemScript::
ld a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE
ret z
; If there is no script here, we don't need to be here. ; If there is no script here, we don't need to be here.
ld a, [wMapReentryScriptQueueFlag] ld a, [wMapReentryScriptQueueFlag]
and a and a

View File

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

View File

@ -235,6 +235,7 @@ ScriptCommandTable:
dw Script_wait ; a8 dw Script_wait ; a8
dw Script_checksave ; a9 dw Script_checksave ; a9
dw Script_exitoverworld ; aa dw Script_exitoverworld ; aa
dw Script_reloadmapafterviewmapmode ; db
assert_table_length NUM_EVENT_COMMANDS assert_table_length NUM_EVENT_COMMANDS
StartScript: StartScript:
@ -1203,6 +1204,22 @@ Script_reloadmapafterbattle:
.done .done
jp Script_reloadmap 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: Script_reloadmap:
xor a xor a
ld [wBattleScriptFlags], a ld [wBattleScriptFlags], a

View File

@ -7,6 +7,8 @@ EnterMapSpawnPoint:
ld a, [wDefaultSpawnpoint] ld a, [wDefaultSpawnpoint]
cp SPAWN_N_A cp SPAWN_N_A
jr z, .spawn_n_a jr z, .spawn_n_a
cp SPAWN_FROM_RAM
jr z, .spawn_from_ram
ld l, a ld l, a
ld h, 0 ld h, 0
add hl, hl add hl, hl
@ -21,6 +23,20 @@ EnterMapSpawnPoint:
ld [wXCoord], a ld [wXCoord], a
ld a, [hli] ld a, [hli]
ld [wYCoord], a 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 .spawn_n_a
pop de pop de
pop hl pop hl

View File

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

View File

@ -1682,6 +1682,16 @@ wTempSpaceStruct:: space_struct wTempSpace
wTempSpaceStructEnd:: wTempSpaceStructEnd::
wTempSpaceBranchStruct:: ds NUM_DIRECTIONS * 2 wTempSpaceBranchStruct:: ds NUM_DIRECTIONS * 2
wTempSpaceBranchStructEnd:: 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 ENDU
wBattleMenuCursorPosition:: wBattleMenuCursorPosition::