mapgen: actor spawning now checks if an actor already exists at the selected position
authorLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 17:24:42 +0000 (19:24 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 17:24:42 +0000 (19:24 +0200)
src/mapgen.s

index 4d661ab479fe3213f9f5ad3a5d6bd477c937a34f..f2f4667a1159f4e9f2b2262ae1cee552c3f7a3ba 100644 (file)
@@ -523,7 +523,7 @@ mapgen_place_actors:
 
                ; 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
@@ -533,8 +533,6 @@ mapgen_place_actors:
                dec b
        jp nz, @spawn_another 
 
-       ; TODO: reload flags and positions
-       
        ret
        
        ; randomizes (or reloads from sram)
@@ -542,7 +540,7 @@ mapgen_place_actors:
        ; 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
@@ -561,11 +559,22 @@ mapgent_unit_randomize_or_reaload_position:
        ; 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