Tweak door behavior, completing section 4.18

This commit is contained in:
Timothy Warren 2021-12-17 14:31:39 -05:00
parent 1e969db5b0
commit 6af7476c51
2 changed files with 21 additions and 2 deletions

View File

@ -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 {

View File

@ -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;