Make map building random again, completes section 4.15
This commit is contained in:
parent
939996c71e
commit
2ef1f3e1c8
@ -159,69 +159,134 @@ pub trait MetaMapBuilder {
|
|||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap);
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_initial_builder(rng: &mut RandomNumberGenerator) -> (Box<dyn InitialMapBuilder>, bool) {
|
fn random_start_position(rng: &mut rltk::RandomNumberGenerator) -> (XStart, YStart) {
|
||||||
match rng.roll_dice(1, 17) {
|
let x = match rng.roll_dice(1, 3) {
|
||||||
1 => (BspDungeonBuilder::new(), true),
|
1 => XStart::Left,
|
||||||
2 => (BspInteriorBuilder::new(), true),
|
2 => XStart::Center,
|
||||||
3 => (CellularAutomataBuilder::new(), false),
|
_ => XStart::Right,
|
||||||
4 => (DrunkardsWalkBuilder::open_area(), false),
|
};
|
||||||
5 => (DrunkardsWalkBuilder::open_halls(), false),
|
|
||||||
6 => (DrunkardsWalkBuilder::winding_passages(), false),
|
let y = match rng.roll_dice(1, 3) {
|
||||||
7 => (DrunkardsWalkBuilder::fat_passages(), false),
|
1 => YStart::Bottom,
|
||||||
8 => (DrunkardsWalkBuilder::fearful_symmetry(), false),
|
2 => YStart::Center,
|
||||||
9 => (MazeBuilder::new(), false),
|
_ => YStart::Top,
|
||||||
10 => (DLABuilder::walk_inwards(), false),
|
};
|
||||||
11 => (DLABuilder::walk_outwards(), false),
|
|
||||||
12 => (DLABuilder::central_attractor(), false),
|
(x, y)
|
||||||
13 => (DLABuilder::insectoid(), false),
|
|
||||||
14 => (VoronoiCellBuilder::pythagoras(), false),
|
|
||||||
15 => (VoronoiCellBuilder::manhattan(), false),
|
|
||||||
16 => (
|
|
||||||
PrefabBuilder::constant(prefab_builder::prefab_levels::WFC_POPULATED),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
_ => (SimpleMapBuilder::new(), true),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderChain) {
|
||||||
|
let build_roll = rng.roll_dice(1, 3);
|
||||||
|
match build_roll {
|
||||||
|
1 => builder.start_with(SimpleMapBuilder::new()),
|
||||||
|
2 => builder.start_with(BspDungeonBuilder::new()),
|
||||||
|
_ => builder.start_with(BspInteriorBuilder::new()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// BSP Interior still makes holes in the walls
|
||||||
|
if build_roll != 3 {
|
||||||
|
// Sort by one of the 5 available algorithms
|
||||||
|
let room_sort = match rng.roll_dice(1, 5) {
|
||||||
|
1 => RoomSort::LeftMost,
|
||||||
|
2 => RoomSort::RightMost,
|
||||||
|
3 => RoomSort::TopMost,
|
||||||
|
4 => RoomSort::BottomMost,
|
||||||
|
_ => RoomSort::Central,
|
||||||
|
};
|
||||||
|
builder.with(RoomSorter::new(room_sort));
|
||||||
|
|
||||||
|
// Pick a corridor type
|
||||||
|
match rng.roll_dice(1, 2) {
|
||||||
|
1 => builder.with(DoglegCorridors::new()),
|
||||||
|
_ => builder.with(BspCorridors::new()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add additional modifier
|
||||||
|
match rng.roll_dice(1, 6) {
|
||||||
|
1 => {
|
||||||
|
builder.with(RoomExploder::new());
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
builder.with(RoomCornerRounder::new());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a starting position
|
||||||
|
match rng.roll_dice(1, 2) {
|
||||||
|
1 => builder.with(RoomBasedStartingPosition::new()),
|
||||||
|
_ => {
|
||||||
|
let (start_x, start_y) = random_start_position(rng);
|
||||||
|
builder.with(AreaStartingPosition::new(start_x, start_y))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find an exit
|
||||||
|
match rng.roll_dice(1, 2) {
|
||||||
|
1 => builder.with(RoomBasedStairs::new()),
|
||||||
|
_ => builder.with(DistantExit::new()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Spawn stuff
|
||||||
|
match rng.roll_dice(1, 2) {
|
||||||
|
1 => builder.with(RoomBasedSpawner::new()),
|
||||||
|
_ => builder.with(VoronoiSpawning::new()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_shape_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderChain) {
|
||||||
|
let first_builder: Box<dyn InitialMapBuilder> = match rng.roll_dice(1, 16) {
|
||||||
|
1 => CellularAutomataBuilder::new(),
|
||||||
|
2 => DrunkardsWalkBuilder::open_area(),
|
||||||
|
3 => DrunkardsWalkBuilder::open_halls(),
|
||||||
|
4 => DrunkardsWalkBuilder::winding_passages(),
|
||||||
|
5 => DrunkardsWalkBuilder::fat_passages(),
|
||||||
|
6 => DrunkardsWalkBuilder::fearful_symmetry(),
|
||||||
|
7 => MazeBuilder::new(),
|
||||||
|
8 => DLABuilder::walk_inwards(),
|
||||||
|
9 => DLABuilder::walk_outwards(),
|
||||||
|
10 => DLABuilder::central_attractor(),
|
||||||
|
11 => DLABuilder::insectoid(),
|
||||||
|
12 => VoronoiCellBuilder::pythagoras(),
|
||||||
|
13 => VoronoiCellBuilder::manhattan(),
|
||||||
|
_ => PrefabBuilder::constant(prefab_builder::prefab_levels::WFC_POPULATED),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the start to the center and cull
|
||||||
|
builder
|
||||||
|
.start_with(first_builder)
|
||||||
|
.with(AreaStartingPosition::new(XStart::Center, YStart::Center))
|
||||||
|
.with(CullUnreachable::new());
|
||||||
|
|
||||||
|
// Now set the start ot 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());
|
||||||
|
builder.with(DistantExit::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_builder(new_depth: i32, rng: &mut RandomNumberGenerator) -> BuilderChain {
|
pub fn random_builder(new_depth: i32, rng: &mut RandomNumberGenerator) -> BuilderChain {
|
||||||
let mut builder = BuilderChain::new(new_depth);
|
let mut builder = BuilderChain::new(new_depth);
|
||||||
// let (random_starter, has_rooms) = random_initial_builder(rng);
|
|
||||||
// builder.start_with(random_starter);
|
|
||||||
//
|
|
||||||
// if has_rooms {
|
|
||||||
// builder
|
|
||||||
// .with(RoomBasedSpawner::new())
|
|
||||||
// .with(RoomBasedStairs::new())
|
|
||||||
// .with(RoomBasedStartingPosition::new());
|
|
||||||
// } else {
|
|
||||||
// builder
|
|
||||||
// .with(AreaStartingPosition::new(XStart::Center, YStart::Center))
|
|
||||||
// .with(CullUnreachable::new())
|
|
||||||
// .with(VoronoiSpawning::new())
|
|
||||||
// .with(DistantExit::new());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if rng.roll_dice(1, 3) == 1 {
|
|
||||||
// builder.with(WaveformCollapseBuilder::new());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if rng.roll_dice(1, 20) == 1 {
|
|
||||||
// builder.with(PrefabBuilder::sectional(
|
|
||||||
// prefab_builder::prefab_sections::UNDERGROUND_FORT,
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// builder.with(PrefabBuilder::vaults());
|
|
||||||
|
|
||||||
builder
|
match rng.roll_dice(1, 2) {
|
||||||
.start_with(BspDungeonBuilder::new())
|
1 => random_room_builder(rng, &mut builder),
|
||||||
.with(RoomSorter::new(RoomSort::Central))
|
_ => random_shape_builder(rng, &mut builder),
|
||||||
.with(BspCorridors::new())
|
};
|
||||||
.with(AreaStartingPosition::new(XStart::Center, YStart::Center))
|
|
||||||
.with(CullUnreachable::new())
|
if rng.roll_dice(1, 3) == 1 {
|
||||||
.with(VoronoiSpawning::new())
|
builder.with(WaveformCollapseBuilder::new());
|
||||||
.with(DistantExit::new());
|
}
|
||||||
|
|
||||||
|
if rng.roll_dice(1, 20) == 1 {
|
||||||
|
builder.with(PrefabBuilder::sectional(
|
||||||
|
prefab_builder::prefab_sections::UNDERGROUND_FORT,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.with(PrefabBuilder::vaults());
|
||||||
|
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use rltk::RandomNumberGenerator;
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
use crate::map_builders::common::{apply_room_to_map, draw_corridor};
|
use crate::map_builders::common::apply_room_to_map;
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
use crate::{Map, Rect, TileType};
|
use crate::{Map, Rect, TileType};
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ impl DLABuilder {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn heavy_erosion() -> Box<DLABuilder> {
|
pub fn heavy_erosion() -> Box<DLABuilder> {
|
||||||
Box::new(DLABuilder {
|
Box::new(DLABuilder {
|
||||||
algorithm: DLAAlgorithm::WalkInwards,
|
algorithm: DLAAlgorithm::WalkInwards,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use rltk::RandomNumberGenerator;
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
use crate::map_builders::common::{
|
use crate::map_builders::common::apply_room_to_map;
|
||||||
apply_horizontal_tunnel, apply_room_to_map, apply_vertical_tunnel,
|
|
||||||
};
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user