ld [srand], a
; generate first room
- push hl
call mapgen_up_left_room
- pop hl
+ call mapgen_bottom_left_room
+ call mapgen_up_right_room
+ call mapgen_bottom_right_room
; restore seed
ret
+ ; selects a random room pattern
+ ; inputs:
+ ; hl: room pattern table
+ ; a: table size
+ ; returns:
+ ; bc: room pattern ptr
+mapgen_select_pattern:
+ push hl
+
+ ld b, a
+ call rand
+ and a, b ; cap rand to table size
+
+ pop hl
+
+ ld b, 0
+ ld c, a
+ add hl, bc
+
+
+ ; load table ptr
+ ld a, [hl+]
+ ld c, a
+ ld a, [hl]
+ ld b, a
+
+ ret
+
+ ; select room pattern 6x6
+ ; preserves: hl
+mapgen_select_pattern_6x6:
+ push hl
+ ld a, ROOM_PATTERN_6X6_SIZE
+ ld hl, room_pattern_6x6
+ call mapgen_select_pattern
+ pop hl
+ ret
+
; inputs:
; hl: [map]
+ ; preserves: hl
mapgen_up_left_room:
- ld bc, room_pattern_6by6
+ push hl
+
+ ; move to correct location on map
+ ld bc, MAP_W*c_size
+ add hl, bc
+ inc hl
+ inc hl
+
+ call mapgen_select_pattern_6x6
+
call mapgen_draw_room_pattern
+ pop hl
ret
+
+ ; inputs:
+ ; hl: [map]
+ ; preserves: hl
+mapgen_bottom_left_room:
+ push hl
+
+ ; move to correct location on map
+ ld bc, MAP_W*9*c_size
+ add hl, bc
+ inc hl
+ inc hl
+
+ call mapgen_select_pattern_6x6
+
+ call mapgen_draw_room_pattern
+ pop hl
+ ret
+
+ ; inputs:
+ ; hl: [map]
+ ; preserves: hl
+mapgen_up_right_room:
+ push hl
+
+ ; move to correct location on map
+ ld bc, (MAP_W/2)*c_size + MAP_W*c_size
+ add hl, bc
+ inc hl
+ inc hl
+
+ call mapgen_select_pattern_6x6
+
+ call mapgen_draw_room_pattern
+ pop hl
+ ret
+
+
+ ; inputs:
+ ; hl: [map]
+ ; preserves: hl
+mapgen_bottom_right_room:
+ push hl
+
+ ; move to correct location on map
+ ld bc, (MAP_W/2)*c_size + MAP_W*9*c_size
+ add hl, bc
+ inc hl
+ inc hl
+
+ call mapgen_select_pattern_6x6
+
+ call mapgen_draw_room_pattern
+ pop hl
+ ret
+
+
; draws a room pattern to the map
; inputs:
; hl: origin inside of map struct
pop hl
push bc
- ld bc, MAP_W
+ ld bc, MAP_W*c_size
add hl, bc ; next row
pop bc
; tile table first
mapgen_read_value_from_table room_pattern_tile_translation
-
; write to map
ld [hl+], a ; write tile
; door right
.de RPDR, 1
+room_pattern_empty:
+ rpheaderdef 0x66
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+ rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL
+
room_pattern1:
rpheaderdef 0x66
rprow RPUL, RPUW, RPUW, RPDU, RPUW, RPUR
; translation tables for tiles
room_pattern_tile_translation:
; walls
- .db 0x6b, 0x6b, 0x6b
- .db 0x6b, 0x6b, 0x6b
- .db 0x6b, 0x6b
+ .db 0x44, 0x44, 0x44
+ .db 0x44, 0x44, 0x44
+ .db 0x44, 0x44
.db 0x00 ; floor
; doors
.db 0x00, 0x00, 0x00, 0x00
.db CF_DOOR, CF_DOOR, CF_DOOR, CF_DOOR
; table of 6 by 6 room patterns
-room_pattern_6by6:
+room_pattern_6x6:
+ dw room_pattern_empty
dw room_pattern1
-room_pattern_6by6_end:
+room_pattern_6x6_end:
+
+#define ROOM_PATTERN_6X6_SIZE ((room_pattern_6x6_end - room_pattern_6x6) / 2)