- ; updates a unit table
; runs state for each unit
; does not update if actor is ACT_T_NULL
; inputs:
push bc
call unit_demo_1_draw
pop bc
+
ret
; inputs
inc a
ld [hl], a
- ret
-
+ ret
+
; consumes a move
; sets UI redraw flag
; fails (z flag set) if no moves left
cp a, 0
push_all
- call z, unit_next
+ call z, unit_next_request
pop_all
ret z
ld c, a
ld a, [hl]
ld b, a
-
; bc = next active state
ret
+
+ ; forces a unit into an active state
+ ; inputs:
+ ; de: unit
+unit_wake_up:
+ push de
+ call unit_switch_to_active
+ ; bc = active state
+ push bc
+ pop de ; de = new state
+ pop hl ; unit ptr
+ ld bc, st_size
+ call memcpy
+ ret
; switches the current unit to idle
; sets moves to 0
ld b, a
ret
+ ; forces a unit to go into idle state
+ ; inputs:
+ ; de: unit
+unit_sleep:
+ push de
+ call unit_switch_to_idle
+ ; bc = active state
+ push bc
+ pop de ; de = new state
+ pop hl ; unit ptr
+ ld bc, st_size
+ call memcpy
+ ret
+
+ ; requests unit next
+ ; to be executed
+ ; inputs:
+ ; de: current unit
+unit_next_request:
+ ld a, [gameplay_flags]
+ or a, GPF_UNIT_NEXT
+ ld [gameplay_flags], a
+
+ ld a, e
+ ld [gameplay_unit_current], a
+ ld a, d
+ ld [gameplay_unit_current+1], a
+
+ ret
+
; finds a unit with a higher initiative value
; than the current one that has moves > 0 set
; if all unts have have 0 moves, set moves to
; initial value and try again
; skips any ACT_T_NULL types
; inputs:
- ; de: current unit
+ ; gameplay_unit_current: unit that requested a change
; uses:
; unit_next_best_init: as a temporary buffer
unit_next:
-
+ ; unset flag
+ ld a, [gameplay_flags]
+ xor a, GPF_UNIT_NEXT
+ ld [gameplay_flags], a
+
+ ; load requestor unit
+ ld a, [gameplay_unit_current]
+ ld e, a
+ ld a, [gameplay_unit_current+1]
+ ld d, a
+
+ push de
+ call unit_sleep
+ pop de
; set moves of current unit to 0
ld hl, act_moves
add hl, de
ld d, a
push de
- call unit_switch_to_active
+ call unit_wake_up
pop de
call ui_unit_need_draw
ret
unit_demo_2:
st_def 0x00, unit_demo_1_init, st_unit_demo_1_idle
- act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 7, 3, 3, 0
+ act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 3, 3, 0
act_st_def NULL, NULL, st_unit_demo_1_update, st_unit_demo_1_idle
st_unit_demo_1_update: