mapgen: The player now spawns in a random spot
authorLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 12:29:47 +0000 (14:29 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 25 Aug 2025 12:29:47 +0000 (14:29 +0200)
src/mapgen.s

index 1ea33ab6c9d3869c3b5fc2846843ef98208854dc..4d661ab479fe3213f9f5ad3a5d6bd477c937a34f 100644 (file)
@@ -614,16 +614,27 @@ mapgen_select_player_spawn:
                call map_get_tile
                cp a, 0x00 ; we want no flags here
                pop bc
-       jr z, @try_placement_again REL
+               jr nz, @try_placement_again REL
+
+               push bc
+               ; test if a unit is here 
+               call unit_find_at
+               ld a, h
+               or a, l
+               pop bc
+               jp nz, @try_placement_again REL
 
        ; otherwise write position
        ld hl, player_unit
        ld de, act_pos_y
        add hl, de
        ld a, b
-       ;ld [hl+], a ; write y
+       ld [hl+], a ; write y
 
        ld a, c
-       ;ld [hl], a ; write x
+       ld [hl], a ; write x
+       
+       ld de, player_unit
+       call unit_scroll_center
 
        ret