; 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
#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: