diff --git a/constants/map_data_constants.asm b/constants/map_data_constants.asm index 237b99cef..a61c8222e 100644 --- a/constants/map_data_constants.asm +++ b/constants/map_data_constants.asm @@ -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 diff --git a/constants/map_setup_constants.asm b/constants/map_setup_constants.asm index ab2e54e22..d91c86d28 100644 --- a/constants/map_setup_constants.asm +++ b/constants/map_setup_constants.asm @@ -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 diff --git a/constants/menu_constants.asm b/constants/menu_constants.asm index 9924faf6d..8075cb949 100644 --- a/constants/menu_constants.asm +++ b/constants/menu_constants.asm @@ -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 diff --git a/constants/script_constants.asm b/constants/script_constants.asm index 57354855c..fea20491e 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -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 diff --git a/data/maps/setup_scripts.asm b/data/maps/setup_scripts.asm index e3be5e1ea..e93321cac 100644 --- a/data/maps/setup_scripts.asm +++ b/data/maps/setup_scripts.asm @@ -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 diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 3d442e122..0ce1af2b8 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -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] diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index b274f94fa..c16c2d670 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -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 diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm index 75f4512f2..8321c41f2 100644 --- a/engine/overworld/player_step.asm +++ b/engine/overworld/player_step.asm @@ -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: diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index bcb76f90f..30c0f3e72 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -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 diff --git a/engine/overworld/spawn_points.asm b/engine/overworld/spawn_points.asm index 33e4c96b3..48713957d 100644 --- a/engine/overworld/spawn_points.asm +++ b/engine/overworld/spawn_points.asm @@ -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 diff --git a/macros/scripts/events.asm b/macros/scripts/events.asm index c72744b7c..71f52e94f 100644 --- a/macros/scripts/events.asm +++ b/macros/scripts/events.asm @@ -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 diff --git a/ram/wram.asm b/ram/wram.asm index 70aa47cc8..be3ec1d6e 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -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::