; move to next actor table entry
push hl
- call mapgent_unit_randomize_or_reaload_position
+ call mapgent_unit_randomize_position
ld hl, act_size
add hl, de
push hl
dec b
jp nz, @spawn_another
- ; TODO: reload flags and positions
-
ret
; randomizes (or reloads from sram)
; inputs:
; de: actor table entry
; preserves all registers
-mapgent_unit_randomize_or_reaload_position:
+mapgent_unit_randomize_position:
push_all
@retry:
ld hl, act_pos_y
; check if tile is OK to spawn on
push bc
call map_get_tile
- and a, CF_COLLISION
+ cp a, 0x00 ; check flags
pop bc
pop hl
; if collision flag is set try again
jr nz, @retry REL
+
+ push bc
+ push hl
+ ; check if this tile already had an actor
+ call unit_find_at
+ ld a, h
+ or a, l
+ pop bc
+ pop hl
+ cp a, 0
+ jr nz, @retry REL
; write y and x positions
ld a, b