--- /dev/null
+
+ ; calculates the distance between 2
+ ; numbers:
+ ; inputs:
+ ; a: n1
+ ; b: n2
+ ; returns:
+ ; a: absolute distance between a and b
+ ; c: 1 if b > a
+ ; c: 0 otherwise
+distance:
+ cp a, b
+ ; if b > a jp
+ jr c, @b_gt_a REL
+
+ ; otherwise a simple sub will do
+ sub a, b
+ ld c, 0
+ ret
+@b_gt_a:
+ ; exchange a and b and sub
+ ld c, a
+ ld a, b
+ ld b, c
+ sub a, b
+ ld c, 1
+ ret
+ ; handles cpu inputs
+ ; inputs:
+ ; de: actor
+ ; returns:
+ ; bc: next state
unit_handle_cpu_inputs:
+ call distance
+ call unit_cpu_random_move
+ ld bc, st_unit_delay_to_active
+ ret
+
+
+ ; moves actor into a random direction
+ ; inputs:
+ ; de: actor
unit_cpu_random_move:
; pick where to go
call roll_d16
cp a, 3
call z, unit_try_move_down
- ld bc, st_unit_delay_to_active
ret