mapgen: fixed most issues with the current door placement implementation
authorLukas Krickl <lukas@krickl.dev>
Thu, 21 Aug 2025 16:17:55 +0000 (18:17 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 21 Aug 2025 16:17:55 +0000 (18:17 +0200)
src/map.s
src/mapgen.s

index 22afe0dfd2cfb2ef8e09c8f6893a63302dccf20f..903e464170fd6889ba2ce3dbbac37ba1bc6e69d6 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -76,6 +76,11 @@ map_draw_area_title:
   dec b
   jr nz, @loop REL
 
+       ; draw player map cursor number
+       ld a, [player_map_cursor]
+       add a, FONT_OFFSET+1
+       ld [de], a
+
   call ui_request_redraw
 
   ret
index 043bdfca3320fe8179b860825885a4398fdda3d0..ec7bbc4d7f798c51d9f7c8f2499f4fbeed542ff9 100644 (file)
@@ -146,22 +146,21 @@ mapgen:
        ; avoids placing doors at the edge.
        ; stops after plaving at least N  doors
 mapgen_make_doors:
-       ld b, 1 
-       ld c, 1 ; bc = y/x position
+       ld b, 0 
+       ld c, 0 ; bc = y/x position
        ; start current ptr at 1/1 as well
-       ld hl, map_doors_location + 1 + FLOOR_W 
+       ld hl, map_doors_location 
 
        ; set map cursor
-       ld a, 1 + FLOOR_W
+       ld a, 
        ld [player_map_cursor], a
-       BREAK
        
        ; select how many doors we want
        push bc
        push hl
        call rand
-       add a, 12 ; at least N doors
-       and a, (FLOOR_MAP_COUNT - 1) 
+       add a, 24 ; at least N doors
+       and a, (FLOOR_MAP_COUNT * 2) - 1 
 
        pop hl
        pop bc
@@ -180,15 +179,11 @@ mapgen_make_doors:
                pop hl
                
                call make_door
-               cp a, 0xFF
-               jp z, @loop ; try again
-               BREAK
                call make_opp_door
 
                pop af
                dec a
                jr nz, @loop REL
-       BREAK
        ret
        
        ; creates the counterpart to 
@@ -236,7 +231,6 @@ make_opp_door:
        ;               bc: current coordinate
        ;               hl: current ptr
        ;       returns:
-       ;               a: FF -> unable to place door
        ;               a: door direction -> door placed
        ;               [hl]: ors new door bit
        ;               bc: if door placed moves coordinates
@@ -257,9 +251,9 @@ make_door:
 
 @try_again:
        pop af
-       ; try again...
-       ld a, 0xFF
-       ret
+       inc a
+       and a, 3
+       jp make_door
 @left:
        
        ; can we even place it?
@@ -267,9 +261,14 @@ make_door:
        cp a, 0
        jp z, @try_again
 
+       ; is this door already set?
+       ; ld a, [hl]
+       ; and a, DIRLEFT
+       ; jp nz, @try_again
+
        ; we can!
        ld a, [hl]
-       or a, DIRRIGHT
+       or a, DIRLEFT
        ld [hl], a
 
        dec c ; x--
@@ -282,8 +281,12 @@ make_door:
        cp a, FLOOR_W-1
        jp z, @try_again
 
+       ; ld a, [hl]
+       ; and a, DIRRIGHT
+       ; jp nz, @try_again
+
        ld a, [hl]
-       or a, DIRLEFT
+       or a, DIRRIGHT
        ld [hl], a
        
        inc c ; x++
@@ -297,12 +300,16 @@ make_door:
        cp a, 0
        jp z, @try_again
 
+       ; ld a, [hl]
+       ; and a, DIRUP 
+       ; jp nz, @try_again
+
        ld a, [hl]
        or a, DIRUP
        ld [hl], a
 
        dec b ; y--
-       
+
        ; move hl up one row
 .rep i, FLOOR_W, 1, dec hl
 
@@ -314,6 +321,10 @@ make_door:
        cp a, FLOOR_H-1
        jp z, @try_again
 
+       ; ld a, [hl]
+       ; and a, DIRDOWN 
+       ; jp nz, @try_again
+
        ld a, [hl]
        or a, DIRDOWN
        ld [hl], a