From: Lukas Krickl Date: Mon, 6 Jan 2025 06:37:05 +0000 (+0100) Subject: map: mapgen now will not generate the same room twice in a row X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=129d9c7a0e45a3d5276088da07475bd165297bc3;p=gbrg%2F.git map: mapgen now will not generate the same room twice in a row This is simply done by calling rand again if the room is the same as the previous room. --- diff --git a/src/map.s b/src/map.s index 623157e..61df12e 100644 --- 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 diff --git a/src/wram.s b/src/wram.s index 5ae5ded..d85cdf2 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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