call act_save_init
call mapgen_seed
call mapgen_make_doors
+ call mapgen_select_player_spawn
call mapgen
ret
pop_all
ret
+
+ ; selects player spawn room
+ ; selects a random room that has an exit and
+ ; sets the map cursor
+ ; then places the player on a tile without flags
+mapgen_select_player_spawn:
+ call rand
+ and a, FLOOR_MAP_COUNT-1
+ ld hl, map_doors_location
+ ld d, 0
+ ld e, a
+ add hl, de
+ ; check if the selected room has doors (is not 0)
+
+ ld a, [hl]
+ cp a, 0
+ jr z, mapgen_select_player_spawn REL
+
+ ; write selected room
+ ld a, e
+ ld [player_map_cursor], a
+ ; TODO: move player position
+
+
+ ret