Decompose bsp_dungeon builder into rooms, corridors, and sorting
This commit is contained in:
parent
23dfbeeeb9
commit
b0b154c8d7
@ -14,6 +14,8 @@ mod room_based_stairs;
|
|||||||
mod room_based_starting_position;
|
mod room_based_starting_position;
|
||||||
mod room_corner_rounding;
|
mod room_corner_rounding;
|
||||||
mod room_exploder;
|
mod room_exploder;
|
||||||
|
mod room_sorter;
|
||||||
|
mod rooms_corridors_bsp;
|
||||||
mod rooms_corridors_dogleg;
|
mod rooms_corridors_dogleg;
|
||||||
mod simple_map;
|
mod simple_map;
|
||||||
mod voronoi;
|
mod voronoi;
|
||||||
@ -36,6 +38,8 @@ use room_based_stairs::RoomBasedStairs;
|
|||||||
use room_based_starting_position::RoomBasedStartingPosition;
|
use room_based_starting_position::RoomBasedStartingPosition;
|
||||||
use room_corner_rounding::RoomCornerRounder;
|
use room_corner_rounding::RoomCornerRounder;
|
||||||
use room_exploder::RoomExploder;
|
use room_exploder::RoomExploder;
|
||||||
|
use room_sorter::RoomSorter;
|
||||||
|
use rooms_corridors_bsp::BspCorridors;
|
||||||
use rooms_corridors_dogleg::DoglegCorridors;
|
use rooms_corridors_dogleg::DoglegCorridors;
|
||||||
use simple_map::SimpleMapBuilder;
|
use simple_map::SimpleMapBuilder;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
@ -212,7 +216,8 @@ pub fn random_builder(new_depth: i32, rng: &mut RandomNumberGenerator) -> Builde
|
|||||||
|
|
||||||
builder
|
builder
|
||||||
.start_with(BspDungeonBuilder::new())
|
.start_with(BspDungeonBuilder::new())
|
||||||
.with(DoglegCorridors::new())
|
.with(RoomSorter::new())
|
||||||
|
.with(BspCorridors::new())
|
||||||
.with(AreaStartingPosition::new(XStart::Center, YStart::Center))
|
.with(AreaStartingPosition::new(XStart::Center, YStart::Center))
|
||||||
.with(CullUnreachable::new())
|
.with(CullUnreachable::new())
|
||||||
.with(VoronoiSpawning::new())
|
.with(VoronoiSpawning::new())
|
||||||
|
@ -51,24 +51,6 @@ impl BspDungeonBuilder {
|
|||||||
n_rooms += 1;
|
n_rooms += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we sort the rooms
|
|
||||||
rooms.sort_by(|a, b| a.x1.cmp(&b.x1));
|
|
||||||
|
|
||||||
// Now we want corridors
|
|
||||||
for i in 0..rooms.len() - 1 {
|
|
||||||
let room = rooms[i];
|
|
||||||
let next_room = rooms[i + 1];
|
|
||||||
let start_x = room.x1 + (rng.roll_dice(1, i32::abs(room.x1 - room.x2)) - 1);
|
|
||||||
let start_y = room.y1 + (rng.roll_dice(1, i32::abs(room.y1 - room.y2) - 1));
|
|
||||||
let end_x =
|
|
||||||
next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
|
||||||
let end_y =
|
|
||||||
next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
|
||||||
|
|
||||||
draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
|
||||||
build_data.take_snapshot();
|
|
||||||
}
|
|
||||||
|
|
||||||
build_data.rooms = Some(rooms);
|
build_data.rooms = Some(rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
src/map_builders/room_sorter.rs
Normal file
27
src/map_builders/room_sorter.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
|
|
||||||
|
pub struct RoomSorter {}
|
||||||
|
|
||||||
|
impl MetaMapBuilder for RoomSorter {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
self.sorter(rng, build_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomSorter {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new() -> Box<RoomSorter> {
|
||||||
|
Box::new(RoomSorter {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sorter(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
build_data
|
||||||
|
.rooms
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.sort_by(|a, b| a.x1.cmp(&b.x1));
|
||||||
|
}
|
||||||
|
}
|
44
src/map_builders/rooms_corridors_bsp.rs
Normal file
44
src/map_builders/rooms_corridors_bsp.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
|
use super::common::draw_corridor;
|
||||||
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::Rect;
|
||||||
|
|
||||||
|
pub struct BspCorridors {}
|
||||||
|
|
||||||
|
impl MetaMapBuilder for BspCorridors {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
self.corridors(rng, build_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BspCorridors {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new() -> Box<BspCorridors> {
|
||||||
|
Box::new(BspCorridors {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn corridors(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
let rooms: Vec<Rect>;
|
||||||
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
|
rooms = rooms_builder.clone();
|
||||||
|
} else {
|
||||||
|
panic!("BSP Corridors require a builder with room structures");
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..rooms.len() - 1 {
|
||||||
|
let room = rooms[i];
|
||||||
|
let next_room = rooms[i + 1];
|
||||||
|
let start_x = room.x1 + (rng.roll_dice(1, i32::abs(room.x1 - room.x2)) - 1);
|
||||||
|
let start_y = room.y1 + (rng.roll_dice(1, i32::abs(room.y1 - room.y2)) - 1);
|
||||||
|
let end_x =
|
||||||
|
next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
||||||
|
let end_y =
|
||||||
|
next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
||||||
|
|
||||||
|
draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
||||||
|
build_data.take_snapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user