Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map/object/event renaming #1076

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 58 additions & 58 deletions constants/map_object_constants.asm
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
; object_struct members (see macros/ram.asm)
rsreset
DEF OBJECT_SPRITE rb ; 00
DEF OBJECT_MAP_OBJECT_INDEX rb ; 01
DEF OBJECT_SPRITE_TILE rb ; 02
DEF OBJECT_MOVEMENT_TYPE rb ; 03
DEF OBJECT_FLAGS1 rb ; 04
DEF OBJECT_FLAGS2 rb ; 05
DEF OBJECT_PALETTE rb ; 06
DEF OBJECT_WALKING rb ; 07
DEF OBJECT_DIRECTION rb ; 08
DEF OBJECT_STEP_TYPE rb ; 09
DEF OBJECT_STEP_DURATION rb ; 0a
DEF OBJECT_ACTION rb ; 0b
DEF OBJECT_STEP_FRAME rb ; 0c
DEF OBJECT_FACING rb ; 0d
DEF OBJECT_TILE rb ; 0e
DEF OBJECT_LAST_TILE rb ; 0f
DEF OBJECT_MAP_X rb ; 10
DEF OBJECT_MAP_Y rb ; 11
DEF OBJECT_LAST_MAP_X rb ; 12
DEF OBJECT_LAST_MAP_Y rb ; 13
DEF OBJECT_INIT_X rb ; 14
DEF OBJECT_INIT_Y rb ; 15
DEF OBJECT_RADIUS rb ; 16
DEF OBJECT_SPRITE_X rb ; 17
DEF OBJECT_SPRITE_Y rb ; 18
DEF OBJECT_SPRITE_X_OFFSET rb ; 19
DEF OBJECT_SPRITE_Y_OFFSET rb ; 1a
DEF OBJECT_MOVEMENT_INDEX rb ; 1b
DEF OBJECT_STEP_INDEX rb ; 1c
DEF OBJECT_1D rb ; 1d
DEF OBJECT_1E rb ; 1e
DEF OBJECT_JUMP_HEIGHT rb ; 1f
DEF OBJECT_RANGE rb ; 20
rb_skip 7
DEF OBJECT_SPRITE rb ; 00
DEF OBJECT_OBJECT_EVENT_INDEX rb ; 01
DEF OBJECT_SPRITE_TILE rb ; 02
DEF OBJECT_MOVEMENT_TYPE rb ; 03
DEF OBJECT_FLAGS1 rb ; 04
DEF OBJECT_FLAGS2 rb ; 05
DEF OBJECT_PALETTE rb ; 06
DEF OBJECT_WALKING rb ; 07
DEF OBJECT_DIRECTION rb ; 08
DEF OBJECT_STEP_TYPE rb ; 09
DEF OBJECT_STEP_DURATION rb ; 0a
DEF OBJECT_ACTION rb ; 0b
DEF OBJECT_STEP_FRAME rb ; 0c
DEF OBJECT_FACING rb ; 0d
DEF OBJECT_TILE rb ; 0e
DEF OBJECT_LAST_TILE rb ; 0f
DEF OBJECT_MAP_X rb ; 10
DEF OBJECT_MAP_Y rb ; 11
DEF OBJECT_LAST_MAP_X rb ; 12
DEF OBJECT_LAST_MAP_Y rb ; 13
DEF OBJECT_INIT_X rb ; 14
DEF OBJECT_INIT_Y rb ; 15
DEF OBJECT_RADIUS rb ; 16
DEF OBJECT_SPRITE_X rb ; 17
DEF OBJECT_SPRITE_Y rb ; 18
DEF OBJECT_SPRITE_X_OFFSET rb ; 19
DEF OBJECT_SPRITE_Y_OFFSET rb ; 1a
DEF OBJECT_MOVEMENT_INDEX rb ; 1b
DEF OBJECT_STEP_INDEX rb ; 1c
DEF OBJECT_1D rb ; 1d
DEF OBJECT_1E rb ; 1e
DEF OBJECT_JUMP_HEIGHT rb ; 1f
DEF OBJECT_RANGE rb ; 20
rb_skip 7
DEF OBJECT_LENGTH EQU _RS
DEF NUM_OBJECT_STRUCTS EQU 13 ; see wObjectStructs
DEF NUM_OBJECTS EQU 13 ; see wObjects

; object_struct OBJECT_DIRECTION values
DEF OW_DOWN EQU DOWN << 2
Expand Down Expand Up @@ -96,32 +96,32 @@ DEF ABSOLUTE_TILE_ID_F EQU 2
DEF RELATIVE_ATTRIBUTES EQU 1 << RELATIVE_ATTRIBUTES_F
DEF ABSOLUTE_TILE_ID EQU 1 << ABSOLUTE_TILE_ID_F

; map_object struct members (see macros/ram.asm)
; object_event_struct members (see macros/ram.asm)
; struct initialized by object_event macro (see macros/scripts/maps.asm)
rsreset
DEF MAPOBJECT_OBJECT_STRUCT_ID rb ; 0
DEF MAPOBJECT_SPRITE rb ; 1
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_1 rb ; 6
DEF MAPOBJECT_HOUR_2 rb ; 7
rsset MAPOBJECT_HOUR_2
DEF MAPOBJECT_TIMEOFDAY rb ; 7
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
DEF OBJECT_EVENT_OBJECT_STRUCT_ID rb ; 0
DEF OBJECT_EVENT_SPRITE rb ; 1
DEF OBJECT_EVENT_Y_COORD rb ; 2
DEF OBJECT_EVENT_X_COORD rb ; 3
DEF OBJECT_EVENT_MOVEMENT rb ; 4
DEF OBJECT_EVENT_RADIUS rb ; 5
DEF OBJECT_EVENT_HOUR_1 rb ; 6
DEF OBJECT_EVENT_HOUR_2 rb ; 7
rsset OBJECT_EVENT_HOUR_2
DEF OBJECT_EVENT_TIMEOFDAY rb ; 7
DEF OBJECT_EVENT_PALETTE rb ; 8
rsset OBJECT_EVENT_PALETTE
DEF OBJECT_EVENT_TYPE rb ; 8
DEF OBJECT_EVENT_SIGHT_RANGE rb ; 9
DEF OBJECT_EVENT_SCRIPT_POINTER rw ; a
DEF OBJECT_EVENT_EVENT_FLAG rw ; c
rb_skip 2
DEF MAPOBJECT_LENGTH EQU _RS
DEF NUM_OBJECTS EQU 16
DEF OBJECT_EVENT_LENGTH EQU _RS
DEF NUM_OBJECT_EVENTS EQU 16
DEF PLAYER_OBJECT EQU 0

DEF MAPOBJECT_PALETTE_MASK EQU %11110000
DEF MAPOBJECT_TYPE_MASK EQU %00001111
DEF OBJECT_EVENT_PALETTE_MASK EQU %11110000
DEF OBJECT_EVENT_TYPE_MASK EQU %00001111

; SpriteMovementData struct members (see data/sprites/map_objects.asm)
rsreset
Expand All @@ -133,8 +133,8 @@ DEF SPRITEMOVEATTR_FLAGS2 rb ; 4
DEF SPRITEMOVEATTR_PALFLAGS rb ; 5
DEF NUM_SPRITEMOVEDATA_FIELDS EQU _RS

DEF MAPOBJECT_SCREEN_WIDTH EQU (SCREEN_WIDTH / 2) + 2
DEF MAPOBJECT_SCREEN_HEIGHT EQU (SCREEN_HEIGHT / 2) + 2
DEF OBJECT_EVENT_SCREEN_WIDTH EQU (SCREEN_WIDTH / 2) + 2
DEF OBJECT_EVENT_SCREEN_HEIGHT EQU (SCREEN_HEIGHT / 2) + 2

; SpriteMovementData indexes (see data/sprites/map_objects.asm)
const_def
Expand Down
4 changes: 2 additions & 2 deletions constants/script_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ DEF CALLBACK_SIZE EQU 3 ; callback
DEF WARP_EVENT_SIZE EQU 5 ; warp_event
DEF COORD_EVENT_SIZE EQU 8 ; coord_event
DEF BG_EVENT_SIZE EQU 5 ; bg_event
; An object_event is a map_object without its initial MAPOBJECT_OBJECT_STRUCT_ID or final padding
DEF OBJECT_EVENT_SIZE EQU MAPOBJECT_LENGTH - 3 ; 13
; An object_event is a map_object without its initial OBJECT_EVENT_OBJECT_STRUCT_ID or final padding
DEF OBJECT_EVENT_SIZE EQU OBJECT_EVENT_LENGTH - 3 ; 13

; A coord_event for scene -1 will always activate,
; regardless of the map's scene variable value.
Expand Down
10 changes: 5 additions & 5 deletions docs/bugs_and_glitches.md
Original file line number Diff line number Diff line change
Expand Up @@ -2638,21 +2638,21 @@ If `IsInArray` returns `nc`, data at `bc` will be executed as code.
**Fix:** Edit `ReadObjectEvents` in [home/map.asm](https://github.com/pret/pokecrystal/blob/master/home/map.asm):

```diff
-; get NUM_OBJECTS - [wCurMapObjectEventCount]
+; get NUM_OBJECTS - [wCurMapObjectEventCount] - 1
-; get NUM_OBJECT_EVENTS - [wCurMapObjectEventCount]
+; get NUM_OBJECT_EVENTS - [wCurMapObjectEventCount] - 1
-; BUG: ReadObjectEvents overflows into wObjectMasks (see docs/bugs_and_glitches.md)
ld a, [wCurMapObjectEventCount]
ld c, a
- ld a, NUM_OBJECTS
+ ld a, NUM_OBJECTS - 1
- ld a, NUM_OBJECT_EVENTS
+ ld a, NUM_OBJECT_EVENTS - 1
sub c
jr z, .skip
+ jr c, .skip

; could have done "inc hl" instead
ld bc, 1
add hl, bc
ld bc, MAPOBJECT_LENGTH
ld bc, OBJECT_EVENT_LENGTH
.loop
ld [hl], 0
inc hl
Expand Down
2 changes: 1 addition & 1 deletion engine/events/battle_tower/battle_tower.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ LoadOpponentTrainerAndPokemonWithOTSprite:
ld c, a
ld b, 0
ld d, 0
ld hl, wMapObjects
ld hl, wObjectEvents
add hl, bc
inc hl
ld a, [wBTTempOTSprite]
Expand Down
4 changes: 2 additions & 2 deletions engine/events/overworld.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,12 @@ GetFacingObject:

ldh a, [hObjectStructIndex]
call GetObjectStruct
ld hl, OBJECT_MAP_OBJECT_INDEX
ld hl, OBJECT_OBJECT_EVENT_INDEX
add hl, bc
ld a, [hl]
ldh [hLastTalked], a
call GetMapObject
ld hl, MAPOBJECT_MOVEMENT
ld hl, OBJECT_EVENT_MOVEMENT
add hl, bc
ld a, [hl]
ld d, a
Expand Down
6 changes: 3 additions & 3 deletions engine/overworld/cmd_queue.asm
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ CmdQueue_Type3:

.IsPlayerFacingDown:
push bc
ld bc, wPlayerStruct
ld bc, wPlayerObject
call GetSpriteDirection
and a
pop bc
ret

CmdQueue_StoneTable:
ld de, wPlayerStruct
ld a, NUM_OBJECT_STRUCTS
ld de, wPlayerObject
ld a, NUM_OBJECTS
.loop
push af

Expand Down
10 changes: 5 additions & 5 deletions engine/overworld/events.asm
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,17 @@ TryObjectEvent:
call PlayTalkObject
ldh a, [hObjectStructIndex]
call GetObjectStruct
ld hl, OBJECT_MAP_OBJECT_INDEX
ld hl, OBJECT_OBJECT_EVENT_INDEX
add hl, bc
ld a, [hl]
ldh [hLastTalked], a

ldh a, [hLastTalked]
call GetMapObject
ld hl, MAPOBJECT_TYPE
ld hl, OBJECT_EVENT_TYPE
add hl, bc
ld a, [hl]
and MAPOBJECT_TYPE_MASK
and OBJECT_EVENT_TYPE_MASK

; BUG: TryObjectEvent arbitrary code execution (see docs/bugs_and_glitches.md)
push bc
Expand Down Expand Up @@ -583,7 +583,7 @@ ObjectEventTypeArray:
db -1 ; end

.script
ld hl, MAPOBJECT_SCRIPT_POINTER
ld hl, OBJECT_EVENT_SCRIPT_POINTER
add hl, bc
ld a, [hli]
ld h, [hl]
Expand All @@ -593,7 +593,7 @@ ObjectEventTypeArray:
ret

.itemball
ld hl, MAPOBJECT_SCRIPT_POINTER
ld hl, OBJECT_EVENT_SCRIPT_POINTER
add hl, bc
ld a, [hli]
ld h, [hl]
Expand Down
Loading