shithub: pokecrystal

Download patch

ref: 212846af57d1878bb2c6964fbeababd9de03a195
parent: b17255fe3fe1466414fb69349345b956457441b0
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Jul 22 09:37:43 EDT 2020

Treat map setup commands like trade script commands

Fixes #736

--- a/data/maps/setup_script_pointers.asm
+++ b/data/maps/setup_script_pointers.asm
@@ -1,48 +1,52 @@
+add_mapsetup: MACRO
+\1_MapSetupCmd:
+	dba \1
+ENDM
+
 MapSetupCommands:
-; entries correspond to map_*_command constants (see macros/scripts/map_setup.asm)
-	dba EnableLCD ; 00
-	dba DisableLCD ; 01
-	dba InitSound ; 02
-	dba PlayMapMusic ; 03
-	dba RestartMapMusic ; 04
-	dba FadeToMapMusic ; 05
-	dba FadeMapMusicAndPalettes ; 06
-	dba PlayMapMusicBike ; 07
-	dba ForceMapMusic ; 08
-	dba FadeInToMusic ; 09
-	dba LoadBlockData ; 0a (callback 1)
-	dba LoadConnectionBlockData ; 0b
-	dba SaveScreen ; 0c
-	dba BufferScreen ; 0d
-	dba LoadMapGraphics ; 0e
-	dba LoadMapTileset ; 0f
-	dba LoadMapTimeOfDay ; 10
-	dba LoadMapPalettes ; 11
-	dba LoadWildMonData ; 12
-	dba RefreshMapSprites ; 13
-	dba HandleNewMap ; 14
-	dba HandleContinueMap ; 15
-	dba LoadMapObjects ; 16
-	dba EnterMapSpawnPoint ; 17
-	dba EnterMapConnection ; 18
-	dba EnterMapWarp ; 19
-	dba LoadMapAttributes ; 1a
-	dba LoadMapAttributes_SkipObjects ; 1b
-	dba ClearBGPalettes ; 1c
-	dba FadeOutPalettes ; 1d
-	dba FadeInPalettes ; 1e
-	dba GetMapScreenCoords ; 1f
-	dba GetWarpDestCoords ; 20
-	dba SpawnInFacingDown ; 21
-	dba SpawnPlayer ; 22
-	dba RefreshPlayerCoords ; 23
-	dba ResetPlayerObjectAction ; 24
-	dba SkipUpdateMapSprites ; 25
-	dba UpdateRoamMons ; 26
-	dba JumpRoamMons ; 27
-	dba FadeOutMapMusic ; 28
-	dba ActivateMapAnims ; 29
-	dba SuspendMapAnims ; 2a
-	dba ApplyMapPalettes ; 2b
-	dba EnableTextAcceleration ; 2c
-	dba InitMapNameSign ; 2d
+	add_mapsetup EnableLCD ; 00
+	add_mapsetup DisableLCD ; 01
+	add_mapsetup InitSound ; 02
+	add_mapsetup PlayMapMusic ; 03
+	add_mapsetup RestartMapMusic ; 04
+	add_mapsetup FadeToMapMusic ; 05
+	add_mapsetup FadeMapMusicAndPalettes ; 06
+	add_mapsetup PlayMapMusicBike ; 07
+	add_mapsetup ForceMapMusic ; 08
+	add_mapsetup FadeInToMusic ; 09
+	add_mapsetup LoadBlockData ; 0a (callback 1)
+	add_mapsetup LoadConnectionBlockData ; 0b
+	add_mapsetup SaveScreen ; 0c
+	add_mapsetup BufferScreen ; 0d
+	add_mapsetup LoadMapGraphics ; 0e
+	add_mapsetup LoadMapTileset ; 0f
+	add_mapsetup LoadMapTimeOfDay ; 10
+	add_mapsetup LoadMapPalettes ; 11
+	add_mapsetup LoadWildMonData ; 12
+	add_mapsetup RefreshMapSprites ; 13
+	add_mapsetup HandleNewMap ; 14
+	add_mapsetup HandleContinueMap ; 15
+	add_mapsetup LoadMapObjects ; 16
+	add_mapsetup EnterMapSpawnPoint ; 17
+	add_mapsetup EnterMapConnection ; 18
+	add_mapsetup EnterMapWarp ; 19
+	add_mapsetup LoadMapAttributes ; 1a
+	add_mapsetup LoadMapAttributes_SkipObjects ; 1b
+	add_mapsetup ClearBGPalettes ; 1c
+	add_mapsetup FadeOutPalettes ; 1d
+	add_mapsetup FadeInPalettes ; 1e
+	add_mapsetup GetMapScreenCoords ; 1f
+	add_mapsetup GetWarpDestCoords ; 20
+	add_mapsetup SpawnInFacingDown ; 21
+	add_mapsetup SpawnPlayer ; 22
+	add_mapsetup RefreshPlayerCoords ; 23
+	add_mapsetup ResetPlayerObjectAction ; 24
+	add_mapsetup SkipUpdateMapSprites ; 25
+	add_mapsetup UpdateRoamMons ; 26
+	add_mapsetup JumpRoamMons ; 27
+	add_mapsetup FadeOutMapMusic ; 28
+	add_mapsetup ActivateMapAnims ; 29
+	add_mapsetup SuspendMapAnims ; 2a
+	add_mapsetup ApplyMapPalettes ; 2b
+	add_mapsetup EnableTextAcceleration ; 2c
+	add_mapsetup InitMapNameSign ; 2d
--- a/data/maps/setup_scripts.asm
+++ b/data/maps/setup_scripts.asm
@@ -13,164 +13,169 @@
 	dw MapSetupScript_BadWarp
 	dw MapSetupScript_Fly
 
+; valid commands are listed in MapSetupCommands (see data/maps/setup_script_pointers.asm)
+mapsetup: MACRO
+	db (\1_MapSetupCmd - MapSetupCommands) / 3
+ENDM
+
 MapSetupScript_Teleport:
-	map_reset_player_object_action
+	mapsetup ResetPlayerObjectAction
 MapSetupScript_Fly:
-	map_fade_out_palettes
-	map_jump_roam_mons
+	mapsetup FadeOutPalettes
+	mapsetup JumpRoamMons
 MapSetupScript_Warp:
-	map_disable_lcd
-	map_init_sound
-	map_enter_spawn_point
-	map_load_attributes
-	map_handle_new
-	map_spawn_player
-	map_refresh_player_coords
-	map_get_screen_coords
-	map_load_block_data
-	map_buffer_screen
-	map_load_graphics
-	map_load_time_of_day
-	map_load_objects
-	map_enable_lcd
-	map_load_palettes
-	map_spawn_in_facing_down
-	map_refresh_sprites
-	map_play_music_bike
-	map_fade_in_to_music
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_end
+	mapsetup DisableLCD
+	mapsetup InitSound
+	mapsetup EnterMapSpawnPoint
+	mapsetup LoadMapAttributes
+	mapsetup HandleNewMap
+	mapsetup SpawnPlayer
+	mapsetup RefreshPlayerCoords
+	mapsetup GetMapScreenCoords
+	mapsetup LoadBlockData
+	mapsetup BufferScreen
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup LoadMapObjects
+	mapsetup EnableLCD
+	mapsetup LoadMapPalettes
+	mapsetup SpawnInFacingDown
+	mapsetup RefreshMapSprites
+	mapsetup PlayMapMusicBike
+	mapsetup FadeInToMusic
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	db -1 ; end
 
 MapSetupScript_BadWarp:
-	map_enter_spawn_point
-	map_load_attributes
-	map_handle_new
-	map_spawn_player
-	map_refresh_player_coords
-	map_get_screen_coords
-	map_load_block_data
-	map_buffer_screen
-	map_disable_lcd
-	map_load_graphics
-	map_load_time_of_day
-	map_fade_out_music
-	map_enable_lcd
-	map_load_objects
-	map_load_palettes
-	map_spawn_in_facing_down
-	map_refresh_sprites
-	map_fade_to_music
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_end
+	mapsetup EnterMapSpawnPoint
+	mapsetup LoadMapAttributes
+	mapsetup HandleNewMap
+	mapsetup SpawnPlayer
+	mapsetup RefreshPlayerCoords
+	mapsetup GetMapScreenCoords
+	mapsetup LoadBlockData
+	mapsetup BufferScreen
+	mapsetup DisableLCD
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup FadeOutMapMusic
+	mapsetup EnableLCD
+	mapsetup LoadMapObjects
+	mapsetup LoadMapPalettes
+	mapsetup SpawnInFacingDown
+	mapsetup RefreshMapSprites
+	mapsetup FadeToMapMusic
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	db -1 ; end
 
 MapSetupScript_Connection:
-	map_suspend_anims
-	map_enter_connection
-	map_load_attributes
-	map_handle_new
-	map_refresh_player_coords
-	map_load_block_data
-	map_load_tileset
-	map_save_screen
-	map_load_objects
-	map_fade_to_music
-	map_load_palettes
-	map_init_name_sign
-	map_apply_palettes
-	map_load_wild_mon_data
-	map_update_roam_mons
-	map_activate_anims
-	map_end
+	mapsetup SuspendMapAnims
+	mapsetup EnterMapConnection
+	mapsetup LoadMapAttributes
+	mapsetup HandleNewMap
+	mapsetup RefreshPlayerCoords
+	mapsetup LoadBlockData
+	mapsetup LoadMapTileset
+	mapsetup SaveScreen
+	mapsetup LoadMapObjects
+	mapsetup FadeToMapMusic
+	mapsetup LoadMapPalettes
+	mapsetup InitMapNameSign
+	mapsetup ApplyMapPalettes
+	mapsetup LoadWildMonData
+	mapsetup UpdateRoamMons
+	mapsetup ActivateMapAnims
+	db -1 ; end
 
 MapSetupScript_Fall:
-	map_reset_player_object_action
+	mapsetup ResetPlayerObjectAction
 MapSetupScript_Door:
-	map_fade_out_palettes
+	mapsetup FadeOutPalettes
 MapSetupScript_Train:
-	map_enter_warp
-	map_load_attributes
-	map_get_warp_dest_coords
-	map_handle_new
-	map_refresh_player_coords
-	map_load_block_data
-	map_buffer_screen
-	map_disable_lcd
-	map_load_graphics
-	map_load_time_of_day
-	map_fade_out_music
-	map_enable_lcd
-	map_load_objects
-	map_load_palettes
-	map_refresh_sprites
-	map_fade_to_music
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_update_roam_mons
-	map_end
+	mapsetup EnterMapWarp
+	mapsetup LoadMapAttributes
+	mapsetup GetWarpDestCoords
+	mapsetup HandleNewMap
+	mapsetup RefreshPlayerCoords
+	mapsetup LoadBlockData
+	mapsetup BufferScreen
+	mapsetup DisableLCD
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup FadeOutMapMusic
+	mapsetup EnableLCD
+	mapsetup LoadMapObjects
+	mapsetup LoadMapPalettes
+	mapsetup RefreshMapSprites
+	mapsetup FadeToMapMusic
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	mapsetup UpdateRoamMons
+	db -1 ; end
 
 MapSetupScript_ReloadMap:
-	map_fade_music_and_palettes
-	map_clear_bg_palettes
-	map_disable_lcd
-	map_init_sound
-	map_load_block_data
-	map_load_connection_block_data
-	map_load_graphics
-	map_load_time_of_day
-	map_enable_lcd
-	map_load_palettes
-	map_refresh_sprites
-	map_force_music
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_end
+	mapsetup FadeMapMusicAndPalettes
+	mapsetup ClearBGPalettes
+	mapsetup DisableLCD
+	mapsetup InitSound
+	mapsetup LoadBlockData
+	mapsetup LoadConnectionBlockData
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup EnableLCD
+	mapsetup LoadMapPalettes
+	mapsetup RefreshMapSprites
+	mapsetup ForceMapMusic
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	db -1 ; end
 
 MapSetupScript_LinkReturn:
-	map_fade_music_and_palettes
-	map_disable_lcd
-	map_init_sound
-	map_handle_new
-	map_load_block_data
-	map_buffer_screen
-	map_load_graphics
-	map_load_time_of_day
-	map_enable_lcd
-	map_load_palettes
-	map_refresh_sprites
-	map_play_music_bike
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_enable_text_acceleration
-	map_end
+	mapsetup FadeMapMusicAndPalettes
+	mapsetup DisableLCD
+	mapsetup InitSound
+	mapsetup HandleNewMap
+	mapsetup LoadBlockData
+	mapsetup BufferScreen
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup EnableLCD
+	mapsetup LoadMapPalettes
+	mapsetup RefreshMapSprites
+	mapsetup PlayMapMusicBike
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	mapsetup EnableTextAcceleration
+	db -1 ; end
 
 MapSetupScript_Continue:
-	map_disable_lcd
-	map_init_sound
-	map_load_attributes_no_objects
-	map_get_screen_coords
-	map_handle_continue
-	map_load_block_data
-	map_load_connection_block_data
-	map_buffer_screen
-	map_load_graphics
-	map_load_time_of_day
-	map_enable_lcd
-	map_load_palettes
-	map_refresh_sprites
-	map_play_music_bike
-	map_fade_in_palettes
-	map_activate_anims
-	map_load_wild_mon_data
-	map_end
+	mapsetup DisableLCD
+	mapsetup InitSound
+	mapsetup LoadMapAttributes_SkipObjects
+	mapsetup GetMapScreenCoords
+	mapsetup HandleContinueMap
+	mapsetup LoadBlockData
+	mapsetup LoadConnectionBlockData
+	mapsetup BufferScreen
+	mapsetup LoadMapGraphics
+	mapsetup LoadMapTimeOfDay
+	mapsetup EnableLCD
+	mapsetup LoadMapPalettes
+	mapsetup RefreshMapSprites
+	mapsetup PlayMapMusicBike
+	mapsetup FadeInPalettes
+	mapsetup ActivateMapAnims
+	mapsetup LoadWildMonData
+	db -1 ; end
 
 MapSetupScript_Submenu:
-	map_load_block_data
-	map_load_connection_block_data
-	map_end
+	mapsetup LoadBlockData
+	mapsetup LoadConnectionBlockData
+	db -1 ; end
--- a/engine/overworld/map_setup.asm
+++ b/engine/overworld/map_setup.asm
@@ -18,7 +18,7 @@
 ReadMapSetupScript:
 .loop
 	ld a, [hli]
-	cp map_end_command
+	cp -1 ; end?
 	ret z
 
 	push hl
--- a/macros.asm
+++ b/macros.asm
@@ -11,7 +11,6 @@
 INCLUDE "macros/scripts/events.asm"
 INCLUDE "macros/scripts/text.asm"
 INCLUDE "macros/scripts/movement.asm"
-INCLUDE "macros/scripts/map_setup.asm"
 INCLUDE "macros/scripts/battle_commands.asm"
 INCLUDE "macros/scripts/battle_anims.asm"
 INCLUDE "macros/scripts/gfx_anims.asm"
--- a/macros/scripts/map_setup.asm
+++ /dev/null
@@ -1,56 +1,0 @@
-setup_command: MACRO
-	const \1_command
-\1 EQUS "db \1_command"
-ENDM
-
-; MapSetupCommands indexes (see data/maps/setup_script_pointers.asm)
-	const_def
-	setup_command map_enable_lcd                 ; 00
-	setup_command map_disable_lcd                ; 01
-	setup_command map_init_sound                 ; 02
-	setup_command map_play_music                 ; 03
-	setup_command map_restart_music              ; 04
-	setup_command map_fade_to_music              ; 05
-	setup_command map_fade_music_and_palettes    ; 06
-	setup_command map_play_music_bike            ; 07
-	setup_command map_force_music                ; 08
-	setup_command map_fade_in_to_music           ; 09
-	setup_command map_load_block_data            ; 0a
-	setup_command map_load_connection_block_data ; 0b
-	setup_command map_save_screen                ; 0c
-	setup_command map_buffer_screen              ; 0d
-	setup_command map_load_graphics              ; 0e
-	setup_command map_load_tileset               ; 0f
-	setup_command map_load_time_of_day           ; 10
-	setup_command map_load_palettes              ; 11
-	setup_command map_load_wild_mon_data         ; 12
-	setup_command map_refresh_sprites            ; 13
-	setup_command map_handle_new                 ; 14
-	setup_command map_handle_continue            ; 15
-	setup_command map_load_objects               ; 16
-	setup_command map_enter_spawn_point          ; 17
-	setup_command map_enter_connection           ; 18
-	setup_command map_enter_warp                 ; 19
-	setup_command map_load_attributes            ; 1a
-	setup_command map_load_attributes_no_objects ; 1b
-	setup_command map_clear_bg_palettes          ; 1c
-	setup_command map_fade_out_palettes          ; 1d
-	setup_command map_fade_in_palettes           ; 1e
-	setup_command map_get_screen_coords          ; 1f
-	setup_command map_get_warp_dest_coords       ; 20
-	setup_command map_spawn_in_facing_down       ; 21
-	setup_command map_spawn_player               ; 22
-	setup_command map_refresh_player_coords      ; 23
-	setup_command map_reset_player_object_action ; 24
-	setup_command map_skip_update_sprites        ; 25
-	setup_command map_update_roam_mons           ; 26
-	setup_command map_jump_roam_mons             ; 27
-	setup_command map_fade_out_music             ; 28
-	setup_command map_activate_anims             ; 29
-	setup_command map_suspend_anims              ; 2a
-	setup_command map_apply_palettes             ; 2b
-	setup_command map_enable_text_acceleration   ; 2c
-	setup_command map_init_name_sign             ; 2d
-
-	const_def -1, -1
-	setup_command map_end                        ; ff