call mapgen_seed
call mapgen_make_doors
call mapgen_select_player_spawn
- call mapgen
ret
; selects a room pattern table
; selects a random room that has an exit and
; sets the map cursor
; then places the player on a tile without flags
+ ; calls mapgen after player is placed to make the map
mapgen_select_player_spawn:
call rand
and a, FLOOR_MAP_COUNT-1
; write selected room
ld a, e
ld [player_map_cursor], a
-
- ; TODO: move player position
+ call mapgen
+
+@try_placement_again:
+ call rand
+ and a, MAP_H-1
+ ld b, a ; y pos
+ call rand
+ and a, MAP_W-1
+ ld c, a ; x pos
+
+ ; get tile data
+ push bc
+ call map_get_tile
+ cp a, 0x00 ; we want no flags here
+ pop bc
+ jr z, @try_placement_again REL
+
+ ; otherwise write position
+ ld hl, player_unit
+ ld de, act_pos_y
+ add hl, de
+ ld a, b
+ ;ld [hl+], a ; write y
+
+ ld a, c
+ ;ld [hl], a ; write x
ret