; generates a new set of seeds
; and places them into map_seeds
+ ; also places initial door locations
mapgen_seed:
ld hl, map_seeds
; 2 bytes per seed
dec b
jr nz, @loop REL
+ call mapgen_make_doors
+
ret
; places a rectangular room
; of size MAP_H * MAP_W
; de: the seed used
; map_header: the current map header
- ; returns:
- ; a == 0: room was unable to be placed
- ; a == 1: room was placed
- ; de: seed after generation has finished
; preserves:
; srand
mapgen:
call mapgen_bottom_right_room
call mapgen_place_special_room
+
+ call mapgen_draw_doors
call mapgen_place_actors
ld [srand], a
ret
+
+ ; generates door locations for each map
+mapgen_make_doors:
+ ld a, FLOOR_MAP_COUNT
+ ld hl, map_doors_location
+ ; TODO: fnor now just place all 4 doors
+@loop:
+ push af
+ ld a, DIRUP | DIRDOWN | DIRLEFT | DIRRIGHT
+ ld [hl+], a
+ pop af
+ dec a
+ jr nz, @loop REL
+ ret
+
+ ; loads the current player map cursor
+ ; and draws the required doors
+ ; inputs:
+ ; hl: [map]
+ ; preserves: hl
+mapgen_draw_doors:
+ push hl
+ ld hl, map_doors_location
+ ld a, [player_map_cursor]
+ ld e, a
+ ld d, 0
+ add hl, de ; hl = door entry
+
+ ld a, [hl] ; a = door pattern
+ pop hl ; hl = map
+ ld b, a ; b = door pattern backup
+
+ and a, DIRUP
+ jr z, @no_door_up REL
+ push hl
+ ld de, 7*c_size ; move over 7 tiles
+ add hl, de
+ ld a, DOOR_TILE_TOP
+ ld [hl+], a
+ ld a, CF_DOOR | CF_COLLISION
+ ld [hl], a
+ pop hl
+@no_door_up:
+
+ ld a, b
+ and a, DIRDOWN
+ jr z, @no_door_down REL
+ push hl
+ ld de, 7*c_size + MAP_W * (MAP_H - 1) * c_size
+ add hl, de
+ ld a, DOOR_TILE_BOTTOM
+ ld [hl+], a
+ ld a, CF_DOOR | CF_COLLISION
+ ld [hl], a
+ pop hl
+@no_door_down:
+
+ ld a, b
+ and a, DIRLEFT
+ jr z, @no_door_left REL
+ push hl
+ ld de, 7 * MAP_W * c_size
+ add hl, de
+ ld a, DOOR_TILE_LEFT
+ ld [hl+], a
+ ld a, CF_DOOR | CF_COLLISION
+ ld [hl], a
+ pop hl
+@no_door_left:
+
+ ld a, b
+ and a, DIRRIGHT
+ jr z, @no_door_right REL
+ push hl
+ ld de, 7 * MAP_W * c_size + (MAP_W - 1) * c_size
+ add hl, de
+ ld a, DOOR_TILE_RIGHT
+ ld [hl+], a
+ ld a, CF_DOOR | CF_COLLISION
+ ld [hl], a
+ pop hl
+@no_door_right:
+
+ ret
; selects a random room pattern
; inputs:
; special rooms are placed starting in the top left corner
; inputs:
; hl: [map]
+ ; preserves: hl
mapgen_place_special_room:
push hl
call rand
pop hl
ret z ; bail if no speical room is requested
+ push hl
+
; move to correct location on map
ld bc, MAP_W*c_size
add hl, bc
ld hl, room_pattern_special
call mapgen_select_pattern
pop hl
-
- call mapgen_draw_room_pattern
+ call mapgen_draw_room_pattern
+
+ pop hl
ret