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, 0x0, 0x1, 0x0, 0x0, 0x0
+.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0
+.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0
+.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0
+.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0
+.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0
.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-
-#define ACT_FAR_Y 76
-#define ACT_FAR_X 80
-
-#define ACT_FURTHEST_Y 66
-#define ACT_FURTHEST_X 84
-
- ; vectors for each direction
- ; SOUTH, NORTH, WEST, EAST
- ; S: Sign bit
- ; y: y position
- ; x: x position
- ; bits:
- ; SYYYSXXX
-act_dir_vector:
-.db 0x10 ; SOUTH
-.db 0x90 ; NORTH
-.db 0x09 ; WEST
-.db 0x01 ; EAST
-
- ; reverse direction
-act_dir_reverse:
- .db NORTH ; SOUTH
- .db SOUTH ; NORTH
- .db EAST ; WEST
- .db WEST ; EAST
-
-
- ; tile flags to check if moving forward based on direction
-act_dir_forward:
- .db TF_SE ; SOUTH
- .db TF_NE ; NORTH
- .db TF_WE ; WEST
- .db TF_EE ; EAST
-
- ; tile flags to check if moving back based on direction
-act_dir_back:
- .db TF_NE ; SOUTH
- .db TF_SE ; NORTH
- .db TF_EE ; WEST
- .db TF_WE ; EAST
; loads an actor table into ram
; actors are loaded until the type byte of
add hl, de
ld [hl], a
- call act_move_forward
+ ; TODO: move
ret
call act_clear_tact
ret
-
-
- ; generic actor table call
- ; inputs:
- ; $1: far, near, furthest
-#macro _act_draw_n
- ld a, [de] ; type
- add a, a ; * 2 for offset
- ld hl, act_draw_$1_table
- ld b, 0
- ld c, a
- add hl, bc
-
- ; load routine ptr
- ld a, [hl+]
- ld h, [hl]
- ld l, a
- jp hl
-#endmacro
-
-act_draw_near_table:
- ; NULL
- dw act_r_nop
- ; PLAYER
- dw act_r_nop
- ; bat
- dw act_r_nop
-
- ; draws a near actor
- ; inputs:
- ; de: actor
-act_draw_near:
- _act_draw_n near
-
- ; draws a bat actor
- ; inputs:
- ; de: act ptr
-act_draw_far_bat:
- ld a, 4
- call oamalloc
-
- ld a, ACT_FAR_Y
- ld [hl+], a
- ld a, ACT_FAR_X
- ld [hl+], a
- ld a, 0x92
- ld [hl+], a
- xor a, a
- ld [hl+], a
-
- ld a, ACT_FAR_Y+8
- ld [hl+], a
- ld a, ACT_FAR_X
- ld [hl+], a
- ld a, 0xA2
- ld [hl+], a
- xor a, a
- ld [hl+], a
-
- ld a, ACT_FAR_Y
- ld [hl+], a
- ld a, ACT_FAR_X+8
- ld [hl+], a
- ld a, 0x93
- ld [hl+], a
- xor a, a
- ld [hl+], a
-
- ld a, ACT_FAR_Y+8
- ld [hl+], a
- ld a, ACT_FAR_X+8
- ld [hl+], a
- ld a, 0xA3
- ld [hl+], a
- xor a, a
- ld [hl+], a
- ret
-
-act_draw_far_table:
- ; NULL
- dw act_r_nop
- ; player
- dw act_r_nop
- ; bat
- dw act_draw_far_bat
-
- ; draws an actor if they are far
- ; usuall act_nearby or prop_nearby
- ; to the camera
- ; inputs:
- ; de: actor ptr
-act_draw_far:
- _act_draw_n far
-
- ; draw a bat actor
- ; inputs:
- ; de: actor ptr
-act_draw_furthest_bat:
- ld a, 2
- call oamalloc
-
- ld a, ACT_FURTHEST_Y
- ld [hl+], a
- ld a, ACT_FURTHEST_X
- ld [hl+], a
- ld a, 0x91
- ld [hl+], a
- xor a, a
- ld [hl+], a
-
- ld a, ACT_FURTHEST_Y+8
- ld [hl+], a
- ld a, ACT_FURTHEST_X
- ld [hl+], a
- ld a, 0xA1
- ld [hl+], a
- xor a, a
- ld [hl], a
- ret
-
-act_draw_furthest_table:
- ; NULLL
- dw act_r_nop
- ; player
- dw act_r_nop
- ; bat
- dw act_draw_furthest_bat
-
- ; draws an actor if they are furthest
- ; inputs:
- ; de: actor ptr
-act_draw_furthest:
- _act_draw_n furthest
-
- ret
; clears tact at the current actors position
; inputs:
ld a, e
ld [hl], a
ret
-
- ; checks if the selected actor can move forward
- ; inputs:
- ; de: actor
- ; hl: act_dir_forward or act_dir_back
- ; returns:
- ; zero flag: -> move not possible
- ; not zero flag: -> move possible
-act_can_move:
- push hl
-
- ld hl, act_pos_y
- add hl, de
-
- ld b, [hl]
- inc hl
- ld c, [hl]
-
- push de
- call map_get_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
- ld a, [hl]
- ld b, a ; b = tile flags
- pop de
-
- ld hl, act_dir
- add hl, de
- ld a, [hl]
- and a, ACT_DIR_MASK
- ; a = direction
-
- ld d, 0
- ld e, a ; de = direction offset
- pop hl ; hl = flags table
- add hl, de
- ld a, [hl] ; a = required flag
-
- and a, b
-
- ret
-
- ; applies a direction vector to the current actor
- ; inputs:
- ; de: actor
- ; b: direction vector (SYYYSXXX)
-act_apply_vec:
- ld hl, act_pos_y
- add hl, de
-
- ld a, b
- ; extract y direction
- and a, 0xF0
- swap a
-
- ; a = y direction
- push bc
- push hl
- call act_apply_pos
- pop hl
- pop bc
-
- inc hl ; hl = x pos
-
- ld a, b
- and a, 0x0F
- ; a = x direction
- call act_apply_pos
-
- ret
-
- ; applies a single position based on its
- ; sign bit
- ; inputs:
- ; hl: ptr to position
- ; a: 0000SNNN -> vector value
- ; preserves: de
- ; uses hl, bc, af
-act_apply_pos:
- ; check sign
- bit 3, a
- jr z, @nosign REL
-
- and a, 0b00000111
- ld b, a
- ld a, [hl]
-
- sub a, b
- ld [hl], a
-
- ret
-@nosign:
- and a, 0b00000111
- ld b, [hl]
-
- add a, b
- ld [hl], a
-
- ret
-
- ; creates a copy of the actors position
- ; in tmp_act_y and _x
- ; inputs:
- ; de: actor
- ; preverse:
- ; de
-_act_backup_pos:
- ld hl, act_pos_y
- add hl, de
- ld a, [hl+]
- ld [tmp_act_y], a
- ld a, [hl]
- ld [tmp_act_x], a
- ret
-
- ; restores actor position
- ; from tmp_act_y/x
- ; unsets act_just_moved
- ; inputs:
- ; de: actor
- ; preserves:
- ; de
-_act_restore_pos:
- ld hl, act_pos_y
- add hl, de
-
- ld a, [tmp_act_y]
- ld [hl+], a
- ld a, [tmp_act_x]
- ld [hl], a
-
- xor a, a
- ldh [act_just_moved], a
- ret
-
- ; tests if the new actor location contains
- ; an actor
- ; rolls back position to tmp_act_y/x if it does
- ; input:
- ; de: actor
- ; preserves:
- ; de
-_act_check_act_in_location:
- push de
- ld hl, act_pos_y
- add hl, de
- ld a, [hl+]
- ld b, a
- ld c, [hl]
- call map_get_tile
- ; hl = tile
- ld bc, t_act
- add hl, bc
-
- ld a, [hl+]
- or a, [hl]
- pop de
- call nz, _act_restore_pos
- ret
-
-
- ; moves the actor forward
- ; performs collision checks
- ; inputs:
- ; de: actor
- ; returns:
- ; act_just_moved: 1 -> moved
- ; act_just_moved: 0 -> not moved
-act_move_forward:
- xor a, a
- ldh [act_just_moved], a
- call _act_backup_pos
-
- push de
- ld hl, act_dir_forward
- call act_can_move
- pop de
- ret z ; bail on collision
-
- push de
- call act_clear_tact
- pop de
- push de
-
- ld hl, act_dir
- add hl, de ; hl = act_dir
- ld a, [hl]
- and a, ACT_DIR_MASK
- ld b, 0
- ld c, a ; bc = direction offset
-
- ld hl, act_dir_vector
- add hl, bc ; hl = direction vector
- ld b, [hl] ; b = direction
-
- call act_apply_vec
-
- ld a, 1
- ldh [act_just_moved], a
-
- ; check if player collides with actor
- ; at new location
- pop de
- call _act_check_act_in_location
- call act_set_tact
-
- ret
-
- ; moves the actor back
- ; performs collision checks
- ; inputs:
- ; de: actor
-act_move_back:
- xor a, a
- ldh [act_just_moved], a
- call _act_backup_pos
-
- push de
- ld hl, act_dir_back
- call act_can_move
- pop de
- ret z ; bail on collision
-
- push de
- call act_clear_tact
- pop de
- push de
-
- ld hl, act_dir
- add hl, de ; hl = act_dir
- ld a, [hl]
- and a, ACT_DIR_MASK
- ld b, 0
- ld c, a ; bc = direction offset
-
- ; get reverse direction
- ld hl, act_dir_reverse
- add hl, bc
- ld c, [hl] ; bc = reverse offset
-
-
- ld hl, act_dir_vector
- add hl, bc ; hl = direction vector
- ld b, [hl] ; b = direction
-
- call act_apply_vec
-
- ld a, 1
- ldh [act_just_moved], a
-
- pop de
- call _act_check_act_in_location
- call act_set_tact
- ret
; performs an attack
; depends on the weapon equipped,