map: Maps can now swap room tables based on the current floor
authorLukas Krickl <lukas@krickl.dev>
Thu, 2 Jan 2025 21:50:21 +0000 (22:50 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 2 Jan 2025 21:50:21 +0000 (22:50 +0100)
src/map.s

index 5f1876912f35980b9e28dd997a5518a1a2c91280..d25d4771fae1b1bb954eb4c4610ff68bcc109eb4 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -533,10 +533,27 @@ map_gen_next:
 
   ; load base room ptr
 
+  ; select table based on level first
+  ld hl, room_tables
+  ld a, [floor] 
+  add a, a ; * 2 for offset in ptr table
+  ld b, 0
+  ld c, a
+  add hl, bc ; hl = room table ptr based on floor
+
+  ld a, [hl+]
+  ld b, a
+  ld a, [hl]
+  ld h, a
+  ld l, b ; hl = room table max length
+  ld a, [hl+] ; hl = first room entry 
+  ld b, a ; b = max length of room table
+
   ; select a room randomly from the table
+  push hl
   call rand
-  ld hl, base_room_table
-  and a, BASE_ROOM_TABLE_LEN 
+  pop hl
+  and a, b 
   ld b, 0
   ld c, a
   add hl, bc ; base + random offset 
@@ -1003,13 +1020,20 @@ map_gen_copy_base_room:
 #include "base_room.s"
 #include "base_room2.s"
 
+
+  ; the first byte of the table is the length of the table 
   ; a table of all base room ptrs
   ; length must be divisible by 2
 base_room_table:
+  .db BASE_ROOM_TABLE_LEN
   dw base_room_header
   dw base_room2_header
 base_room_table_end:
 
+  ; a table of all room tables 
+  ; to allow for room sets per level
+room_tables:
+  dw base_room_table
 
   ; exit table for empty exits 
 room_empty_exits: