sub a, d ; max - current
ld e, a ; e = moves max counter
+ ld hl, SCRN1+1
+
; draw to screen
+ ld a, d
+ cp a, 0
+ jr z, @skip_loop_current REL
+
ld a, UI_TILE_MOVE
- ld hl, SCRN1+1
@loop_current:
ld [hl+], a
dec d
jr nz, @loop_current REL
+@skip_loop_current:
+
; draw used moves
ld a, e ; check if e is already 0
cp a, 0
; actor initiative based on tile flags
; actor position
unit_try_move_up:
+ call unit_use_move
+ ret z
+
ld hl, act_pos_y
add hl, de
; hl = actor y
ret
unit_try_move_down:
+ call unit_use_move
+ ret z
+
ld hl, act_pos_y
add hl, de
; hl = actor y
ret
unit_try_move_left:
+ call unit_use_move
+ ret z
+
ld hl, act_pos_x
add hl, de
; hl = actor x
ret
unit_try_move_right:
+ call unit_use_move
+ ret z
+
ld hl, act_pos_x
add hl, de
; hl = actor x
inc a
ld [hl], a
ret
+
+ ; consumes a move
+ ; sets UI redraw flag
+ ; fails (z flag set) if no moves left
+ ; inputs:
+ ; de: unit
+unit_use_move:
+ push de
+
+ ld hl, act_moves
+ add hl, de
+ pop de ; hl = act_moves
+
+ ld a, [hl] ; current
+ cp a, 0
+ ret z
+ dec a
+ ld [hl], a
+ call ui_unit_need_draw
+ ret
; centers the current scroll on the selected unit
; snaps to corners of the map