From 6af7476c51c9393227e147965b1f6975d6a62e35 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 17 Dec 2021 14:31:39 -0500 Subject: [PATCH] Tweak door behavior, completing section 4.18 --- src/map_builders.rs | 9 +++++++++ src/map_builders/door_placement.rs | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/map_builders.rs b/src/map_builders.rs index 4e6c844..840b826 100644 --- a/src/map_builders.rs +++ b/src/map_builders.rs @@ -299,6 +299,15 @@ pub fn random_builder(new_depth: i32, rng: &mut RandomNumberGenerator) -> Builde if rng.roll_dice(1, 3) == 1 { builder.with(WaveformCollapseBuilder::new()); + + // Now set the start to a random starting area + let (start_x, start_y) = random_start_position(rng); + builder.with(AreaStartingPosition::new(start_x, start_y)); + + // Setup an exit and spawn mobs + builder + .with(VoronoiSpawning::new()) + .with(DistantExit::new()); } if rng.roll_dice(1, 20) == 1 { diff --git a/src/map_builders/door_placement.rs b/src/map_builders/door_placement.rs index 68b8477..a61abcd 100644 --- a/src/map_builders/door_placement.rs +++ b/src/map_builders/door_placement.rs @@ -18,7 +18,7 @@ impl DoorPlacement { Box::new(DoorPlacement {}) } - fn doors(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) { + fn doors(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) { if let Some(halls_original) = &build_data.corridors { let halls = halls_original.clone(); for hall in halls.iter() { @@ -33,7 +33,10 @@ impl DoorPlacement { // There are no corridors - scan for possible places let tiles = build_data.map.tiles.clone(); for (i, tile) in tiles.iter().enumerate() { - if *tile == TileType::Floor && self.door_possible(build_data, i) { + if *tile == TileType::Floor + && self.door_possible(build_data, i) + && rng.roll_dice(1, 3) == 1 + { build_data.spawn_list.push((i, "Door".to_string())); } } @@ -41,6 +44,13 @@ impl DoorPlacement { } fn door_possible(&self, build_data: &mut BuilderMap, idx: usize) -> bool { + // Check that there isn't already something in this tile + for spawn in build_data.spawn_list.iter() { + if spawn.0 == idx { + return false; + } + } + let width = build_data.map.width as usize; let height = build_data.map.height as usize; let x = idx % width;