; 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, 0
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
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
; 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
@try_again:
pop af
- ; try again...
- ld a, 0xFF
- ret
+ inc a
+ and a, 3
+ jp make_door
@left:
; can we even place it?
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--
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++
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
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