diff --git a/constants/map_object_constants.asm b/constants/map_object_constants.asm index f98fae56e..adce3e52d 100644 --- a/constants/map_object_constants.asm +++ b/constants/map_object_constants.asm @@ -124,6 +124,12 @@ DEF PLAYER_OBJECT EQU 0 DEF MAPOBJECT_PALETTE_MASK EQU %11110000 DEF MAPOBJECT_TYPE_MASK EQU %00001111 +; number of entries in MapObjectsBackups. +; this sets a limit to the maximum number of different maps that can be reentered during a level. +; map groups with more than NUM_MAP_OBJECTS_BACKUPS maps are only ok if no more than +; NUM_MAP_OBJECTS_BACKUPS can be possibly accesed during the same level play. +DEF NUM_MAP_OBJECTS_BACKUPS EQU 10 + ; SpriteMovementData struct members (see data/sprites/map_objects.asm) rsreset DEF SPRITEMOVEATTR_MOVEMENT rb ; 0 diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index d7b9c16d5..5b5f461c9 100644 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -225,7 +225,7 @@ CopyMapObjectToObjectStruct: ret InitializeVisibleSprites: - ld bc, wMap1Object + ld bc, wMapObject1 ld a, 1 .loop ldh [hMapObjectIndex], a @@ -312,7 +312,7 @@ CheckObjectEnteringVisibleRange:: ld d, a ld a, [wXCoord] ld e, a - ld bc, wMap1Object + ld bc, wMapObject1 ld a, 1 .loop_v ldh [hMapObjectIndex], a @@ -368,7 +368,7 @@ CheckObjectEnteringVisibleRange:: ld e, a ld a, [wYCoord] ld d, a - ld bc, wMap1Object + ld bc, wMapObject1 ld a, 1 .loop_h ldh [hMapObjectIndex], a @@ -861,7 +861,7 @@ MockPlayerObject:: farcall RefreshPlayerCoords ; copy default sprite object to the last object struct ld hl, .DefaultPlayerObject - ld de, wMap{d:LAST_OBJECT}Object + ld de, wMapObject{d:LAST_OBJECT} ld bc, OBJECT_EVENT_SIZE + 1 call CopyBytes @@ -878,9 +878,9 @@ MockPlayerObject:: jr nz, .next2 ; found a match ld a, [hli] ; sprite - ld [wMap{d:LAST_OBJECT}ObjectSprite], a + ld [wMapObject{d:LAST_OBJECT}Sprite], a ld a, [hl] ; palette | objecttype - ld [wMap{d:LAST_OBJECT}ObjectPalette], a ; also wMap{d:LAST_OBJECT}ObjectType + ld [wMapObject{d:LAST_OBJECT}Palette], a ; also wMapObject{d:LAST_OBJECT}Type jr .copy_player_coords .next1 inc hl @@ -894,12 +894,12 @@ MockPlayerObject:: .copy_player_coords ; copy player's coordinates ld hl, wPlayerObjectYCoord - ld de, wMap{d:LAST_OBJECT}ObjectYCoord + ld de, wMapObject{d:LAST_OBJECT}YCoord ld a, [hli] ld [de], a inc de ld a, [hl] ; wPlayerObjectXCoord - ld [de], a ; wMap{d:LAST_OBJECT}ObjectXCoord + ld [de], a ; wMapObject{d:LAST_OBJECT}XCoord ; set facing direction ld a, [wPlayerDirection] srl a @@ -907,7 +907,7 @@ MockPlayerObject:: maskbits NUM_DIRECTIONS ld b, SPRITEMOVEDATA_STANDING_DOWN add b - ld [wMap{d:LAST_OBJECT}ObjectMovement], a + ld [wMapObject{d:LAST_OBJECT}Movement], a ; display mocked player object ; it will go to the last wMapObjects slot and to whichever wObjectStructs slot diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index 1c8a5f19d..7b21f4dcd 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -1246,7 +1246,7 @@ Script_reloadmapafterviewmapmode: set SECONDARYSPRITES_BRANCH_ARROWS_F, [hl] ld hl, wPlayerSpriteSetupFlags ; get the facing direction from the mocked object's facing direction - ld a, [wMap{d:LAST_OBJECT}ObjectMovement] + ld a, [wMapObject{d:LAST_OBJECT}Movement] sub SPRITEMOVEDATA_STANDING_DOWN ld [hl], a set PLAYERSPRITESETUP_CUSTOM_FACING_F, [hl] diff --git a/home/map.asm b/home/map.asm index f37c87d30..1ad7b22c8 100644 --- a/home/map.asm +++ b/home/map.asm @@ -571,7 +571,7 @@ ReadObjectEvents:: push hl call ClearNonPlayerObjectStructs pop de - ld hl, wMap1Object + ld hl, wMapObject1 ld a, [de] inc de ld [wCurMapObjectEventCount], a diff --git a/home/trainers.asm b/home/trainers.asm index 536444cdc..e45cbd988 100644 --- a/home/trainers.asm +++ b/home/trainers.asm @@ -15,7 +15,7 @@ _CheckTrainerBattleOrTalkerPrompt:: ; Skip the player object. ld a, 1 - ld de, wMap1Object + ld de, wMapObject1 .loop diff --git a/layout.link b/layout.link index f80fcbbc6..481a2a0b3 100644 --- a/layout.link +++ b/layout.link @@ -263,6 +263,8 @@ WRAMX 1 "Party" WRAMX 2 "Pic Animations" +WRAMX 3 + "Map Objects Backups" WRAMX 5 align 8 "GBC Video" @@ -291,6 +293,8 @@ SRAM $02 "Boxes 1-7" SRAM $03 "Boxes 8-14" +SRAM $04 + "SRAM Map Objects Backups" HRAM "OAM DMA" "HRAM" diff --git a/macros/ram.asm b/macros/ram.asm index 40ba19a9c..77be356e1 100644 --- a/macros/ram.asm +++ b/macros/ram.asm @@ -330,20 +330,20 @@ MACRO object_struct ENDM MACRO map_object -\1ObjectStructID:: db -\1ObjectSprite:: db -\1ObjectYCoord:: db -\1ObjectXCoord:: db -\1ObjectMovement:: db -\1ObjectRadius:: db -\1ObjectHour1:: db -\1ObjectHour2:: -\1ObjectTimeOfDay:: db -\1ObjectPalette:: -\1ObjectType:: db -\1ObjectSightRange:: db -\1ObjectScript:: dw -\1ObjectEventFlag:: dw +\1StructID:: db +\1Sprite:: db +\1YCoord:: db +\1XCoord:: db +\1Movement:: db +\1Radius:: db +\1Hour1:: db +\1Hour2:: +\1TimeOfDay:: db +\1Palette:: +\1Type:: db +\1SightRange:: db +\1Script:: dw +\1EventFlag:: dw ds 2 ENDM diff --git a/ram/sram.asm b/ram/sram.asm index e1ae60a46..1624edb4c 100644 --- a/ram/sram.asm +++ b/ram/sram.asm @@ -135,3 +135,8 @@ SECTION "Boxes 8-14", SRAM ; All 14 boxes fit exactly within 2 SRAM banks assert box_n == NUM_BOXES, \ "boxes: Expected {d:NUM_BOXES} total boxes, got {d:box_n}" + + +SECTION "SRAM Map Objects Backups", SRAM + +sMapObjectsBackups:: ds wMapObjectsBackupsEnd - wMapObjectsBackups diff --git a/ram/wram.asm b/ram/wram.asm index 6e574cc3d..f44165742 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -133,8 +133,6 @@ wPrinterConnectionOpen:: db wPrinterOpcode:: db wPrevDexEntry:: db wDisableTextAcceleration:: db -wPrevLandmark:: db -wCurLandmark:: db wLinkMode:: ; a LINK_* value for the link type @@ -2340,10 +2338,10 @@ endr wCmdQueue:: ds CMDQUEUE_CAPACITY * CMDQUEUE_ENTRY_SIZE wMapObjects:: -wPlayerObject:: map_object wPlayer ; player is map object 0 -; wMap1Object - wMap15Object +wPlayerObject:: map_object wPlayerObject ; player is map object 0 +; wMapObject1 - wMapObject15 for n, 1, NUM_OBJECTS -wMap{d:n}Object:: map_object wMap{d:n} +wMapObject{d:n}:: map_object wMapObject{d:n} endr wObjectMasks:: ds NUM_OBJECTS @@ -2689,6 +2687,22 @@ wPokeAnimBitmaskBuffer:: ds 7 wPokeAnimStructEnd:: +SECTION "Map Objects Backups", WRAMX + +wMapObjectsBackups:: +; wMap1ObjectsBackup* - wMap10ObjectsBackup* +; ds (2 + MAPOBJECT_LENGTH * (NUM_OBJECTS - 1)) * NUM_MAP_OBJECTS_BACKUPS +for n, 1, NUM_MAP_OBJECTS_BACKUPS + wMap{d:n}ObjectsBackupMapGroup:: db + wMap{d:n}ObjectsBackupMapNumber:: db + wMap{d:n}ObjectsBackupData:: + for m, 1, NUM_OBJECTS + wMap{d:n}ObjectsBackupObject{d:m}:: map_object wMap{d:n}ObjectsBackupObject{d:m} + endr +endr +wMapObjectsBackupsEnd:: db ; list terminator + + SECTION "GBC Video", WRAMX, ALIGN[8] ; eight 4-color palettes each