From c01409be5a9930d6f0687ce53c1c898e1855c884 Mon Sep 17 00:00:00 2001 From: vulcandth Date: Tue, 3 Jan 2023 21:16:08 -0600 Subject: [PATCH] Relabel some `map_object` struct fields (#1029) --- constants/map_object_constants.asm | 13 ++++++++++--- engine/overworld/events.asm | 4 ++-- engine/overworld/player_object.asm | 8 ++++---- home/map_objects.asm | 6 +++--- home/trainers.asm | 6 +++--- macros/ram.asm | 26 ++++++++++++++------------ macros/scripts/maps.asm | 2 +- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/constants/map_object_constants.asm b/constants/map_object_constants.asm index b1a88ae09..ada9a984f 100644 --- a/constants/map_object_constants.asm +++ b/constants/map_object_constants.asm @@ -104,10 +104,14 @@ DEF MAPOBJECT_Y_COORD rb ; 2 DEF MAPOBJECT_X_COORD rb ; 3 DEF MAPOBJECT_MOVEMENT rb ; 4 DEF MAPOBJECT_RADIUS rb ; 5 -DEF MAPOBJECT_HOUR rb ; 6 +DEF MAPOBJECT_HOUR_1 rb ; 6 +DEF MAPOBJECT_HOUR_2 rb ; 7 +rsset MAPOBJECT_HOUR_2 DEF MAPOBJECT_TIMEOFDAY rb ; 7 -DEF MAPOBJECT_COLOR rb ; 8 -DEF MAPOBJECT_RANGE rb ; 9 +DEF MAPOBJECT_PALETTE rb ; 8 +rsset MAPOBJECT_PALETTE +DEF MAPOBJECT_TYPE rb ; 8 +DEF MAPOBJECT_SIGHT_RANGE rb ; 9 DEF MAPOBJECT_SCRIPT_POINTER rw ; a DEF MAPOBJECT_EVENT_FLAG rw ; c rb_skip 2 @@ -115,6 +119,9 @@ DEF MAPOBJECT_LENGTH EQU _RS DEF NUM_OBJECTS EQU 16 DEF PLAYER_OBJECT EQU 0 +DEF MAPOBJECT_PALETTE_MASK EQU %11110000 +DEF MAPOBJECT_TYPE_MASK EQU %00001111 + ; SpriteMovementData struct members (see data/sprites/map_objects.asm) rsreset DEF SPRITEMOVEATTR_MOVEMENT rb ; 0 diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 20c63bda8..7b669e660 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -546,10 +546,10 @@ TryObjectEvent: ldh a, [hLastTalked] call GetMapObject - ld hl, MAPOBJECT_COLOR + ld hl, MAPOBJECT_TYPE add hl, bc ld a, [hl] - and %00001111 + and MAPOBJECT_TYPE_MASK ; BUG: TryObjectEvent arbitrary code execution (see docs/bugs_and_glitches.md) push bc diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index 5e9dd0504..dec66f6ad 100644 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -27,7 +27,7 @@ SpawnPlayer: call PlayerSpawn_ConvertCoords ld a, PLAYER_OBJECT call GetMapObject - ld hl, MAPOBJECT_COLOR + ld hl, MAPOBJECT_PALETTE add hl, bc ln e, PAL_NPC_RED, OBJECTTYPE_SCRIPT ld a, [wPlayerSpriteSetupFlags] @@ -188,10 +188,10 @@ CopyMapObjectToObjectStruct: call GetSpritePalette ld [wTempObjectCopyPalette], a - ld hl, MAPOBJECT_COLOR + ld hl, MAPOBJECT_PALETTE add hl, bc ld a, [hl] - and $f0 + and MAPOBJECT_PALETTE_MASK jr z, .skip_color_override swap a and PALETTE_MASK @@ -203,7 +203,7 @@ CopyMapObjectToObjectStruct: ld a, [hl] ld [wTempObjectCopyMovement], a - ld hl, MAPOBJECT_RANGE + ld hl, MAPOBJECT_SIGHT_RANGE add hl, bc ld a, [hl] ld [wTempObjectCopyRange], a diff --git a/home/map_objects.asm b/home/map_objects.asm index 2b92b4491..328556596 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -227,7 +227,7 @@ CheckObjectVisibility:: ret CheckObjectTime:: - ld hl, MAPOBJECT_HOUR + ld hl, MAPOBJECT_HOUR_1 add hl, bc ld a, [hl] cp -1 @@ -264,10 +264,10 @@ CheckObjectTime:: db NITE .check_hour - ld hl, MAPOBJECT_HOUR + ld hl, MAPOBJECT_HOUR_1 add hl, bc ld d, [hl] - ld hl, MAPOBJECT_TIMEOFDAY + ld hl, MAPOBJECT_HOUR_2 add hl, bc ld e, [hl] ld hl, hHours diff --git a/home/trainers.asm b/home/trainers.asm index 7085dc324..f271ef14e 100644 --- a/home/trainers.asm +++ b/home/trainers.asm @@ -31,10 +31,10 @@ _CheckTrainerBattle:: jr z, .next ; Is a trainer - ld hl, MAPOBJECT_COLOR + ld hl, MAPOBJECT_TYPE add hl, de ld a, [hl] - and $f + and MAPOBJECT_TYPE_MASK cp OBJECTTYPE_TRAINER jr nz, .next @@ -51,7 +51,7 @@ _CheckTrainerBattle:: jr nc, .next ; ...within their sight range - ld hl, MAPOBJECT_RANGE + ld hl, MAPOBJECT_SIGHT_RANGE add hl, de ld a, [hl] cp b diff --git a/macros/ram.asm b/macros/ram.asm index 652a21645..aa05d8325 100644 --- a/macros/ram.asm +++ b/macros/ram.asm @@ -330,18 +330,20 @@ MACRO object_struct ENDM MACRO map_object -\1ObjectStructID:: db -\1ObjectSprite:: db -\1ObjectYCoord:: db -\1ObjectXCoord:: db -\1ObjectMovement:: db -\1ObjectRadius:: db -\1ObjectHour:: db -\1ObjectTimeOfDay:: db -\1ObjectColor:: db -\1ObjectRange:: db -\1ObjectScript:: dw -\1ObjectEventFlag:: dw +\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 ds 2 ENDM diff --git a/macros/scripts/maps.asm b/macros/scripts/maps.asm index 8c57a884a..1181ba543 100644 --- a/macros/scripts/maps.asm +++ b/macros/scripts/maps.asm @@ -114,7 +114,7 @@ MACRO object_event ; * if h1 == h2, the object_event will always appear ; * if h1 == -1, h2 is treated as a time-of-day value: ; a combo of MORN, DAY, and/or NITE, or -1 to always appear -;\9: color: a PAL_NPC_* constant, or 0 for sprite default +;\9: palette: a PAL_NPC_* constant, or 0 for sprite default ;\<10>: function: a OBJECTTYPE_* constant ;\<11>: sight range: applies to OBJECTTYPE_TRAINER ;\<12>: script pointer