Add ability to spawn items and enemies in corridors

This commit is contained in:
Timothy Warren 2021-12-17 11:29:16 -05:00
parent 132d1dac62
commit 75d9af0562
2 changed files with 32 additions and 0 deletions

View File

@ -13,6 +13,7 @@ mod room_based_spawner;
mod room_based_stairs;
mod room_based_starting_position;
mod room_corner_rounding;
mod room_corridor_spawner;
mod room_draw;
mod room_exploder;
mod room_sorter;
@ -40,6 +41,7 @@ use room_based_spawner::RoomBasedSpawner;
use room_based_stairs::RoomBasedStairs;
use room_based_starting_position::RoomBasedStartingPosition;
use room_corner_rounding::RoomCornerRounder;
use room_corridor_spawner::CorridorSpawner;
use room_draw::RoomDrawer;
use room_exploder::RoomExploder;
use room_sorter::{RoomSort, RoomSorter};

View File

@ -0,0 +1,30 @@
use rltk::RandomNumberGenerator;
use super::{BuilderMap, MetaMapBuilder};
use crate::spawner;
pub struct CorridorSpawner {}
impl MetaMapBuilder for CorridorSpawner {
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
self.build(rng, build_data);
}
}
impl CorridorSpawner {
#[allow(dead_code)]
pub fn new() -> Box<CorridorSpawner> {
Box::new(CorridorSpawner {})
}
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
if let Some(corridors) = &build_data.corridors {
for c in corridors.iter() {
let depth = build_data.map.depth;
spawner::spawn_region(&build_data.map, rng, &c, depth, &mut build_data.spawn_list);
}
} else {
panic!("Corridor Based Spawning only works after corridors have been created.");
}
}
}