pokecrystal-board/engine/overworld/npc_movement.asm

575 lines
7.0 KiB
NASM
Raw Normal View History

CanObjectMoveInDirection: ; 6ec1
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_PALETTE
add hl, bc
2018-05-23 16:10:15 -07:00
bit SWIMMING_F, [hl]
jr z, .not_swimming
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_FLAGS1
add hl, bc
bit NOCLIP_TILES_F, [hl] ; lost, uncomment next line to fix
; jr nz, .noclip_tiles
2015-12-09 15:25:44 -08:00
push hl
push bc
call WillObjectBumpIntoLand
2015-12-09 15:25:44 -08:00
pop bc
pop hl
ret c
jr .continue
2015-12-09 15:25:44 -08:00
2018-05-23 16:10:15 -07:00
.not_swimming
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_FLAGS1
add hl, bc
bit NOCLIP_TILES_F, [hl]
jr nz, .noclip_tiles
2015-12-09 15:25:44 -08:00
push hl
push bc
call WillObjectBumpIntoWater
2015-12-09 15:25:44 -08:00
pop bc
pop hl
ret c
.noclip_tiles
.continue
bit NOCLIP_OBJS_F, [hl]
jr nz, .noclip_objs
2015-12-09 15:25:44 -08:00
push hl
push bc
call WillObjectBumpIntoSomeoneElse
2015-12-09 15:25:44 -08:00
pop bc
pop hl
ret c
.noclip_objs
bit MOVE_ANYWHERE_F, [hl]
jr nz, .move_anywhere
2015-12-09 15:25:44 -08:00
push hl
call HasObjectReachedMovementLimit
2015-12-09 15:25:44 -08:00
pop hl
ret c
push hl
call IsObjectMovingOffEdgeOfScreen
2015-12-09 15:25:44 -08:00
pop hl
ret c
.move_anywhere
2015-12-09 15:25:44 -08:00
and a
ret
; 6f07
WillObjectBumpIntoWater: ; 6f07
2015-12-09 15:25:44 -08:00
call Function6f5f
ret c
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
ld hl, OBJECT_PALETTE
add hl, bc
2018-01-11 09:00:01 -08:00
bit OAM_PRIORITY, [hl]
2015-12-09 15:25:44 -08:00
jp nz, Function6fa1
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
ld d, a
call GetTileCollision
2018-01-11 09:00:01 -08:00
and a ; LANDTILE
jr z, WillObjectBumpIntoTile
2015-12-09 15:25:44 -08:00
scf
ret
; 6f2c
WillObjectBumpIntoLand: ; 6f2c
2015-12-09 15:25:44 -08:00
call Function6f5f
ret c
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call GetTileCollision
cp WATERTILE
jr z, WillObjectBumpIntoTile
2015-12-09 15:25:44 -08:00
scf
ret
; 6f3e
WillObjectBumpIntoTile: ; 6f3e
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
2018-01-16 14:27:50 -08:00
maskbits NUM_DIRECTIONS
2015-12-09 15:25:44 -08:00
ld e, a
ld d, 0
ld hl, .data_6f5b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f5b
.data_6f5b
db DOWN_MASK, UP_MASK, RIGHT_MASK, LEFT_MASK
2015-12-09 15:25:44 -08:00
; 6f5f
Function6f5f: ; 6f5f
ld hl, OBJECT_STANDING_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
2018-01-16 14:27:50 -08:00
maskbits NUM_DIRECTIONS
2015-12-09 15:25:44 -08:00
ld e, a
ld d, 0
ld hl, .data_6f7b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f7b
.data_6f7b
db UP_MASK, DOWN_MASK, LEFT_MASK, RIGHT_MASK
2015-12-09 15:25:44 -08:00
; 6f7f
Function6f7f: ; 6f7f
ld d, a
and $f0
cp $b0
jr z, .done
cp $c0
jr z, .done
xor a
ret
.done
ld a, d
and 7
ld e, a
ld d, 0
ld hl, .data_6f99
add hl, de
ld a, [hl]
scf
ret
; 6f99
.data_6f99
db 8, 4, 1, 2
db 10, 6, 9, 5
; 6fa1
Function6fa1: ; 6fa1
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
2018-01-16 14:27:50 -08:00
maskbits NUM_DIRECTIONS
2018-01-11 09:00:01 -08:00
jr z, .down
2015-12-09 15:25:44 -08:00
dec a
2018-01-11 09:00:01 -08:00
jr z, .up
2015-12-09 15:25:44 -08:00
dec a
2018-01-11 09:00:01 -08:00
jr z, .left
jr .right
2015-12-09 15:25:44 -08:00
2018-01-11 09:00:01 -08:00
.down
2015-12-09 15:25:44 -08:00
inc e
push de
inc d
2018-01-11 09:00:01 -08:00
jr .continue
2015-12-09 15:25:44 -08:00
2018-01-11 09:00:01 -08:00
.up
2015-12-09 15:25:44 -08:00
push de
inc d
2018-01-11 09:00:01 -08:00
jr .continue
2015-12-09 15:25:44 -08:00
2018-01-11 09:00:01 -08:00
.left
2015-12-09 15:25:44 -08:00
push de
inc e
2018-01-11 09:00:01 -08:00
jr .continue
2015-12-09 15:25:44 -08:00
2018-01-11 09:00:01 -08:00
.right
2015-12-09 15:25:44 -08:00
inc d
push de
inc e
2018-01-11 09:00:01 -08:00
.continue
2015-12-09 15:25:44 -08:00
call GetCoordTile
call GetTileCollision
pop de
2018-01-11 09:00:01 -08:00
and a ; LANDTILE
jr nz, .not_land
2015-12-09 15:25:44 -08:00
call GetCoordTile
call GetTileCollision
2018-01-11 09:00:01 -08:00
and a ; LANDTILE
jr nz, .not_land
2015-12-09 15:25:44 -08:00
xor a
ret
2018-01-11 09:00:01 -08:00
.not_land
2015-12-09 15:25:44 -08:00
scf
ret
; 6fd9
CheckFacingObject:: ; 6fd9
call GetFacingTileCoord
; Double the distance for counter tiles.
call CheckCounterTile
jr nz, .asm_6ff1
2018-01-23 14:39:09 -08:00
ld a, [wPlayerStandingMapX]
2015-12-09 15:25:44 -08:00
sub d
cpl
inc a
add d
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wPlayerStandingMapY]
2015-12-09 15:25:44 -08:00
sub e
cpl
inc a
add e
ld e, a
.asm_6ff1
2018-01-23 14:39:09 -08:00
ld bc, wObjectStructs ; redundant
2015-12-09 15:25:44 -08:00
ld a, 0
ld [hMapObjectIndexBuffer], a
call IsNPCAtCoord
ret nc
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
cp STANDING
jr z, .standing
xor a
ret
.standing
scf
ret
; 7009
WillObjectBumpIntoSomeoneElse: ; 7009
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
jr IsNPCAtCoord
; 7015
2018-01-02 07:04:21 -08:00
Unreferenced_Function7015:
2015-12-09 15:25:44 -08:00
ld a, [hMapObjectIndexBuffer]
call GetObjectStruct
call .CheckWillBeFacingNPC
call IsNPCAtCoord
ret
.CheckWillBeFacingNPC: ; 7021
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
call GetSpriteDirection
and a
jr z, .down
cp OW_UP
jr z, .up
cp OW_LEFT
jr z, .left
inc d
ret
.down
inc e
ret
.up
dec e
ret
.left
dec d
ret
; 7041
IsNPCAtCoord: ; 7041
2018-01-23 14:39:09 -08:00
ld bc, wObjectStructs
2015-12-09 15:25:44 -08:00
xor a
.loop
ld [hObjectStructIndexBuffer], a
2016-05-04 19:34:09 -07:00
call DoesObjectHaveASprite
2015-12-09 15:25:44 -08:00
jr z, .next
ld hl, OBJECT_FLAGS1
add hl, bc
bit 7, [hl]
jr nz, .next
ld hl, OBJECT_PALETTE
add hl, bc
bit BIG_OBJECT_F, [hl]
2015-12-09 15:25:44 -08:00
jr z, .got
call Function7171
jr nc, .ok
jr .ok2
.got
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .ok
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .ok
.ok2
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.ok
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
and a
ret
.setcarry
scf
ret
; 70a4
HasObjectReachedMovementLimit: ; 70a4
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
and a
jr z, .nope
and $f
jr z, .check_y
ld e, a
ld d, a
ld hl, OBJECT_INIT_X
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.check_y
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
swap a
and $f
jr z, .nope
ld e, a
ld d, a
ld hl, OBJECT_INIT_Y
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.nope
xor a
ret
.yes
scf
ret
; 70ed
IsObjectMovingOffEdgeOfScreen: ; 70ed
2015-12-09 15:25:44 -08:00
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
2018-01-23 14:39:09 -08:00
ld a, [wXCoord]
2015-12-09 15:25:44 -08:00
cp [hl]
jr z, .check_y
jr nc, .yes
add $9
cp [hl]
jr c, .yes
.check_y
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
2018-01-23 14:39:09 -08:00
ld a, [wYCoord]
2015-12-09 15:25:44 -08:00
cp [hl]
jr z, .nope
jr nc, .yes
add $8
cp [hl]
jr c, .yes
.nope
and a
ret
.yes
scf
ret
; 7113
2018-01-02 07:04:21 -08:00
Unreferenced_Function7113:
2018-01-23 14:39:09 -08:00
ld a, [wPlayerStandingMapX]
2015-12-09 15:25:44 -08:00
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wPlayerStandingMapY]
2015-12-09 15:25:44 -08:00
ld e, a
2018-01-23 14:39:09 -08:00
ld bc, wObjectStructs
2015-12-09 15:25:44 -08:00
xor a
.loop
ld [hObjectStructIndexBuffer], a
2016-05-04 19:34:09 -07:00
call DoesObjectHaveASprite
2015-12-09 15:25:44 -08:00
jr z, .next
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
ld a, [hl]
cp SPRITEMOVEDATA_BIGDOLLSYM
2015-12-09 15:25:44 -08:00
jr nz, .not_snorlax
call Function7171
jr c, .yes
jr .next
.not_snorlax
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .check_current_coords
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .check_current_coords
ld a, [hObjectStructIndexBuffer]
cp $0
jr z, .next
jr .yes
.check_current_coords
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next
jr .yes
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
xor a
ret
.yes
scf
ret
; 7171
Function7171: ; 7171
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, d
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, e
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
scf
ret
.nope
and a
ret
; 718d