map: mapgen now will not generate the same room twice in a row
authorLukas Krickl <lukas@krickl.dev>
Mon, 6 Jan 2025 06:37:05 +0000 (07:37 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 6 Jan 2025 06:37:05 +0000 (07:37 +0100)
This is simply done by calling rand again if the room is the same as the
previous room.

src/map.s
src/wram.s

index 623157e63b129dacaec6de08a5eafba5c181cd37..61df12e473ddf14103d60cd09ddd4656d752b9e2 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -546,11 +546,22 @@ map_gen_next:
   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 
index 5ae5ded4d0db3465a68178610c869b3917c591b6..d85cdf23d061554ba702c7b199acd4a8b42802ce 100644 (file)
@@ -284,3 +284,6 @@ ct_mask: .adv 1
 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