From d2bb82bc3ca7270c688e5b2d105f9a8b399e50e9 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Nov 2023 11:48:12 +0100 Subject: [PATCH] Implement View Map mode [commit 2]: mock player object (#29) --- constants/map_object_constants.asm | 1 + engine/board/menu.asm | 1 + engine/overworld/events.asm | 12 ++++-- engine/overworld/scripting.asm | 66 +++++++++++++++++++++++++++++- macros/scripts/events.asm | 5 +++ 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/constants/map_object_constants.asm b/constants/map_object_constants.asm index e44c2825b..f98fae56e 100644 --- a/constants/map_object_constants.asm +++ b/constants/map_object_constants.asm @@ -118,6 +118,7 @@ DEF MAPOBJECT_EVENT_FLAG rw ; c rb_skip 2 DEF MAPOBJECT_LENGTH EQU _RS DEF NUM_OBJECTS EQU 16 +DEF LAST_OBJECT EQU NUM_OBJECTS - 1 DEF PLAYER_OBJECT EQU 0 DEF MAPOBJECT_PALETTE_MASK EQU %11110000 diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 0ce1af2b8..b46abac44 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -75,6 +75,7 @@ BoardMenuScript:: .ViewMap: callasm .EnterViewMapMode + appearplayermock closetext end diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index c16c2d670..541c26894 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -208,11 +208,15 @@ MapEvents: .no_events: ret -MaxOverworldDelay: - db 2 - +DEF MAX_OVERWORLD_DELAY EQU 2 +DEF VIEW_MAP_OVERWORLD_DELAY EQU 1 ResetOverworldDelay: - ld a, [MaxOverworldDelay] + ldh a, [hCurBoardEvent] + cp BOARDEVENT_VIEW_MAP_MODE + ld a, MAX_OVERWORLD_DELAY + jr nz, .set_delay + ld a, VIEW_MAP_OVERWORLD_DELAY +.set_delay ldh [hOverworldDelay], a ret diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index 30c0f3e72..9d76c9c26 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -235,7 +235,8 @@ ScriptCommandTable: dw Script_wait ; a8 dw Script_checksave ; a9 dw Script_exitoverworld ; aa - dw Script_reloadmapafterviewmapmode ; db + dw Script_reloadmapafterviewmapmode ; ab + dw Script_appearplayermock ; ac assert_table_length NUM_EVENT_COMMANDS StartScript: @@ -961,6 +962,69 @@ Script_variablesprite: ld [hl], a ret +Script_appearplayermock: + ld hl, .DefaultPlayerObject + ld de, wMap{d:LAST_OBJECT}Object + ld bc, OBJECT_EVENT_SIZE + 1 + call CopyBytes + +; adjust sprite id and palette number + ld hl, .PlayerObjectFields +.loop + ld a, [wPlayerGender] + cp [hl] + inc hl + jr nz, .next1 + ld a, [wPlayerState] + cp [hl] + inc hl + jr nz, .next2 +; found a match + ld a, [hli] ; sprite + ld [wMap{d:LAST_OBJECT}ObjectSprite], a + ld a, [hl] ; palette | objecttype + ld [wMap{d:LAST_OBJECT}ObjectPalette], a ; also wMap{d:LAST_OBJECT}ObjectType + jr .copy_player_coords +.next1 + inc hl +.next2 + inc hl + inc hl + ld a, [hl] + cp -1 + jr nz, .loop + +.copy_player_coords +; copy player's coordinates + ld hl, wPlayerObjectYCoord + ld de, wMap{d:LAST_OBJECT}ObjectYCoord + ld a, [hli] + ld [de], a + inc de + ld a, [hl] ; wPlayerObjectXCoord + ld [de], a ; wMap{d:LAST_OBJECT}ObjectXCoord + +; display mocked player object +; it will go to the last wMapObjects slot and to whichever wObjectStructs slot +; wObjectStructs[n][MAPOBJECT_OBJECT_STRUCT_ID] links both structs + ld a, NUM_OBJECTS - 1 + call UnmaskCopyMapObjectStruct + ret + +.DefaultPlayerObject: + db -1 ; MAPOBJECT_OBJECT_STRUCT_ID + object_event 0, 0, SPRITE_CHRIS, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, ObjectEvent, -1 + +.PlayerObjectFields: +; [wPlayerGender], [wPlayerState], sprite id, palette + db 0, PLAYER_NORMAL, SPRITE_CHRIS, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT + db 1 << PLAYERGENDER_FEMALE_F, PLAYER_NORMAL, SPRITE_KRIS, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT + db 0, PLAYER_SURF, SPRITE_SURF, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT + db 1 << PLAYERGENDER_FEMALE_F, PLAYER_SURF, SPRITE_SURF, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT + db 0, PLAYER_BIKE, SPRITE_CHRIS_BIKE, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT + db 1 << PLAYERGENDER_FEMALE_F, PLAYER_BIKE, SPRITE_KRIS_BIKE, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT + db -1 + Script_appear: call GetScriptByte call GetScriptObject diff --git a/macros/scripts/events.asm b/macros/scripts/events.asm index 71f52e94f..424cd2e23 100644 --- a/macros/scripts/events.asm +++ b/macros/scripts/events.asm @@ -1076,4 +1076,9 @@ MACRO reloadmapafterviewmapmode db reloadmapafterviewmapmode_command ENDM + const appearplayermock_command ; $ac +MACRO appearplayermock + db appearplayermock_command +ENDM + DEF NUM_EVENT_COMMANDS EQU const_value