From ce4ca8549453bdb95c3ae58efd88ebefc07029ac Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sun, 31 Dec 2023 15:05:07 +0100 Subject: [PATCH] Implement Flash technique through a map callback of type MAPCALLBACK_ENDMAPSETUP (#34) This callback type is executed in a new map setup command at the very end of every map setup script. Maps that should trigger the use of Flash automatically should use an instance of this callback with fixed functionality --- constants/map_setup_constants.asm | 1 + data/maps/maps.asm | 4 ++-- data/maps/setup_script_pointers.asm | 1 + data/maps/setup_scripts.asm | 9 +++++++++ engine/events/field_moves.asm | 17 +++++++++++++++++ engine/overworld/map_setup.asm | 3 +++ maps/DebugLevel2_Map1.asm | 5 +++++ 7 files changed, 38 insertions(+), 2 deletions(-) diff --git a/constants/map_setup_constants.asm b/constants/map_setup_constants.asm index d91c86d28..10a933820 100644 --- a/constants/map_setup_constants.asm +++ b/constants/map_setup_constants.asm @@ -24,3 +24,4 @@ DEF NUM_MAPSETUP_SCRIPTS EQU const_value - $f1 const MAPCALLBACK_CMDQUEUE const MAPCALLBACK_SPRITES const MAPCALLBACK_NEWMAP + const MAPCALLBACK_ENDMAPSETUP diff --git a/data/maps/maps.asm b/data/maps/maps.asm index cf54278f2..0cbe59185 100644 --- a/data/maps/maps.asm +++ b/data/maps/maps.asm @@ -49,8 +49,8 @@ MapGroup_DebugLevel1: MapGroup_DebugLevel2: table_width MAP_LENGTH, MapGroup_DebugLevel2 - map DebugLevel2_Map1, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE, 2 - map DebugLevel2_Map2, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE, 2 + map DebugLevel2_Map1, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE | IN_DARKNESS, FISHGROUP_SHORE, 2 + map DebugLevel2_Map2, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE | IN_DARKNESS, FISHGROUP_SHORE, 2 assert_table_length NUM_DEBUGLEVEL_2_MAPS MapGroup_DebugLevel3: diff --git a/data/maps/setup_script_pointers.asm b/data/maps/setup_script_pointers.asm index 975804f01..c257f054e 100644 --- a/data/maps/setup_script_pointers.asm +++ b/data/maps/setup_script_pointers.asm @@ -56,3 +56,4 @@ MapSetupCommands: add_mapsetup AnchorPointAfterWarp ; 31 add_mapsetup BackupMapObjects ; 32 add_mapsetup LoadDisabledSpaces ; 33 + add_mapsetup MapCallbackAtEndMapSetup ; 34 diff --git a/data/maps/setup_scripts.asm b/data/maps/setup_scripts.asm index 188a3c470..116328609 100644 --- a/data/maps/setup_scripts.asm +++ b/data/maps/setup_scripts.asm @@ -48,6 +48,7 @@ MapSetupScript_EnterLevel: mapsetup FadeInPalettesFromWhite mapsetup ActivateMapAnims mapsetup LoadWildMonData + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_Teleport: @@ -81,6 +82,7 @@ MapSetupScript_Warp: mapsetup ActivateMapAnims mapsetup LoadWildMonData mapsetup AnchorPointAfterWarp + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_BadWarp: @@ -108,6 +110,7 @@ MapSetupScript_BadWarp: mapsetup ActivateMapAnims mapsetup LoadWildMonData mapsetup AnchorPointAfterWarp + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_Connection: @@ -128,6 +131,7 @@ MapSetupScript_Connection: mapsetup LoadWildMonData mapsetup UpdateRoamMons mapsetup ActivateMapAnims + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_Fall: @@ -158,6 +162,7 @@ MapSetupScript_Train: mapsetup LoadWildMonData mapsetup UpdateRoamMons mapsetup AnchorPointAfterWarp + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_ReloadMap: @@ -178,6 +183,7 @@ MapSetupScript_ReloadMap: mapsetup FadeInPalettesFromWhite mapsetup ActivateMapAnims mapsetup LoadWildMonData + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_ExitViewMap: @@ -202,6 +208,7 @@ MapSetupScript_ExitViewMap: mapsetup FadeInPalettesFromWhite mapsetup ActivateMapAnims mapsetup LoadWildMonData + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_LinkReturn: @@ -222,6 +229,7 @@ MapSetupScript_LinkReturn: mapsetup ActivateMapAnims mapsetup LoadWildMonData mapsetup EnableTextAcceleration + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_Continue: @@ -244,6 +252,7 @@ MapSetupScript_Continue: mapsetup FadeInPalettesFromWhite mapsetup ActivateMapAnims mapsetup LoadWildMonData + mapsetup MapCallbackAtEndMapSetup db -1 ; end MapSetupScript_Submenu: diff --git a/engine/events/field_moves.asm b/engine/events/field_moves.asm index 825804b6d..155fede0e 100644 --- a/engine/events/field_moves.asm +++ b/engine/events/field_moves.asm @@ -9,6 +9,23 @@ PlayWhirlpoolSound: call WaitSFX ret +UseFlashAuto:: + ; ReplaceTimeOfDayPals in map setup command LoadMapTimeOfDay sets wTimeOfDayPalset to DARKNESS_PALSET + ; only if wStatusFlags[STATUSFLAGS_FLASH_F] has not been set. + ld a, [wTimeOfDayPalset] + cp DARKNESS_PALSET + ret nz + ld c, 30 ; 500 ms + call DelayFrames + call WaitSFX + ld de, SFX_FLASH + call PlaySFX + call BlindingFlash + ld c, 30 ; 500 ms + call DelayFrames + call WaitSFX + ret + BlindingFlash: farcall FadeOutPalettesToWhite ld hl, wStatusFlags diff --git a/engine/overworld/map_setup.asm b/engine/overworld/map_setup.asm index 7678b4436..9e759d397 100644 --- a/engine/overworld/map_setup.asm +++ b/engine/overworld/map_setup.asm @@ -202,3 +202,6 @@ ResetLevelScopedEventFlags: jr nz, .loop ret +MapCallbackAtEndMapSetup: + ld a, MAPCALLBACK_ENDMAPSETUP + jp RunMapCallback diff --git a/maps/DebugLevel2_Map1.asm b/maps/DebugLevel2_Map1.asm index 3bb82027f..55a73a0ee 100755 --- a/maps/DebugLevel2_Map1.asm +++ b/maps/DebugLevel2_Map1.asm @@ -4,6 +4,11 @@ DebugLevel2_Map1_MapScripts: def_scene_scripts def_callbacks + callback MAPCALLBACK_ENDMAPSETUP, .FlashAutoScript + +.FlashAutoScript: + callasm UseFlashAuto + endcallback DebugLevel2_Map1_MapEvents: db 0, 0 ; filler