ld a, [hl+] ; hl = first room entry
ld b, a ; b = max length of room table
+ ; c = previous room selection
+ ld a, [mapgen_last_room]
+ ld c, a
+
+@duplicate_room:
; select a room randomly from the table
push hl
call rand
pop hl
- and a, b
+ and a, b
+ cp a, c
+ jr z, @duplicate_room REL
+
+ ; store for next iteration
+ ld [mapgen_last_room], a
+
ld b, 0
ld c, a
add hl, bc ; base + random offset
mapgen_depth: .adv 1
; counts how many rooms we have generated already
mapgen_total: .adv 1
+ ; store the previous room
+ ; to avoid multiple same room types in a row
+mapgen_last_room: .adv 1