#define TWALLD1 0x4A
#define TWALLL1 0x4C
+ ; count of all pointers in base room table
+#define BASE_ROOM_TABLE_LEN ((base_room_table_end - base_room_table) / 2)
+
; maps:
; a map is a collection of room structs
; basic mapgen setup
xor a, a
ld [mapgen_depth], a
+ ld [mapgen_total], a
ld d, ROOMS_TOTAL ; d = loop counter
ld hl, map0 ; hl = current room
; inputs:
; hl: current room
; de: previous room
- ; a: 0 == stop recursion
- ; a: 1 == continue recurions
map_gen_next:
push de ; save previous room
push hl ; save current room
inc a
ld [mapgen_depth], a
+ ld a, [mapgen_total]
+ inc a
+ ld [mapgen_total], a
+
; select a room
; and copy it to the current position
; linking back NULL on all exits initially
; load base room ptr
- ; TODO begin test
- ; TODO we are simply loading base_room_header every time
- ; TODO for now we are just copying room1 and room2 and linking them
+ ; select a room randomly from the table
+ call rand
ld hl, base_room_table
+ and a, BASE_ROOM_TABLE_LEN
+ ld b, 0
+ ld c, a
+ add hl, bc ; base + random offset
+
ld a, [hl+]
ld e, a
ld a, [hl]
; now we copy
call map_gen_copy_base_room
- ; hl = next room
+ ; hl = next room l
+
+ ; check if we're done generating
+ ld a, [mapgen_total]
+ cp a, ROOMS_TOTAL - 1
+ jp z, @gen_done
+
+ ; if not done link to next room
+
pop de ; de = previous room ptr
push de ; save it again
ld a, SOUTH ; link south for now
push hl
call map_gen_link_rooms
-
- ld hl, base_room_table
- ld b, 0
- ld c, 2 ; add 2 to load next base room
- add hl, bc
-
- ld a, [hl+]
- ld e, a
- ld a, [hl]
- ld d, a
+ ; hl = current room
pop hl
-
- call map_gen_copy_base_room
-
- ; TODO end test
+ pop de ; de = previous room
+ push de ; push again for later
+ call map_gen_next
; select a direction to walk into and call again
; and set up pointers
pop de
ret
+@gen_done:
+ ; clean up the stack
+ pop hl
+ pop hl
+ pop hl
+ pop hl
+ pop hl
+ ret
; lut for reverse direction
dw base_room2_header
base_room_table_end:
- ; count of all pointers in base room table
-#define BASE_ROOM_TABLE_LEN ((base_room_table_end - base_room_table) / 2)
; exit table for empty exits
room_empty_exits: