From 112a8fa86629e8fedced5c63f00248e341d6b61e Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 24 Aug 2025 19:21:26 +0200 Subject: [PATCH] mapgen: player spawn map is now selected randomly --- src/mapgen.s | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/mapgen.s b/src/mapgen.s index ec7bbc4..bc13838 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -8,6 +8,7 @@ mapgen_init: call act_save_init call mapgen_seed call mapgen_make_doors + call mapgen_select_player_spawn call mapgen ret @@ -576,4 +577,29 @@ mapgent_unit_randomize_or_reaload_position: 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 -- 2.30.2