finishes decoupling map from camera
This commit is contained in:
parent
2ecfd25d95
commit
7f0465da73
13 changed files with 110 additions and 254 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use super::{Map, Rect, TileType};
|
||||
use std::cmp::{max, min};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn apply_room_to_map(map: &mut Map, room: &Rect) {
|
||||
for y in room.y1 + 1..=room.y2 {
|
||||
for x in room.x1 + 1..=room.x2 {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ pub struct BuilderMap {
|
|||
pub rooms: Option<Vec<Rect>>,
|
||||
pub corridors: Option<Vec<Vec<usize>>>,
|
||||
pub history: Vec<Map>,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
|
||||
impl BuilderMap {
|
||||
|
|
@ -86,17 +88,19 @@ pub struct BuilderChain {
|
|||
}
|
||||
|
||||
impl BuilderChain {
|
||||
pub fn new(new_depth: i32) -> BuilderChain {
|
||||
pub fn new(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||
BuilderChain {
|
||||
starter: None,
|
||||
builders: Vec::new(),
|
||||
build_data: BuilderMap {
|
||||
spawn_list: Vec::new(),
|
||||
map: Map::new(new_depth),
|
||||
map: Map::new(new_depth, width, height),
|
||||
starting_position: None,
|
||||
rooms: None,
|
||||
corridors: None,
|
||||
history: Vec::new(),
|
||||
width: width,
|
||||
height: height,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -166,7 +170,7 @@ fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Buil
|
|||
let build_roll = rng.roll_dice(1, 3);
|
||||
// Start with a room builder.
|
||||
match build_roll {
|
||||
1 => builder.start_with(SimpleMapBuilder::new()),
|
||||
1 => builder.start_with(SimpleMapBuilder::new(None)),
|
||||
2 => builder.start_with(BspDungeonBuilder::new()),
|
||||
_ => builder.start_with(BspInteriorBuilder::new()),
|
||||
}
|
||||
|
|
@ -271,8 +275,8 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui
|
|||
builder.with(DistantExit::new());
|
||||
}
|
||||
|
||||
pub fn random_builder(new_depth: i32, rng: &mut rltk::RandomNumberGenerator) -> BuilderChain {
|
||||
/*let mut builder = BuilderChain::new(new_depth);
|
||||
pub fn random_builder(new_depth: i32, rng: &mut rltk::RandomNumberGenerator, width: i32, height: i32) -> BuilderChain {
|
||||
let mut builder = BuilderChain::new(new_depth, width, height);
|
||||
let type_roll = rng.roll_dice(1, 2);
|
||||
match type_roll {
|
||||
1 => random_room_builder(rng, &mut builder),
|
||||
|
|
@ -298,14 +302,5 @@ pub fn random_builder(new_depth: i32, rng: &mut rltk::RandomNumberGenerator) ->
|
|||
builder.with(DoorPlacement::new());
|
||||
builder.with(PrefabBuilder::vaults());
|
||||
|
||||
builder*/
|
||||
|
||||
let mut builder = BuilderChain::new(new_depth);
|
||||
builder.start_with(BspInteriorBuilder::new());
|
||||
builder.with(DoorPlacement::new());
|
||||
builder.with(RoomBasedSpawner::new());
|
||||
builder.with(PrefabBuilder::vaults());
|
||||
builder.with(RoomBasedStairs::new());
|
||||
builder.with(RoomBasedStartingPosition::new());
|
||||
builder
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,11 @@ impl PrefabBuilder {
|
|||
build_data.spawn_list.push((idx, scroll_table(build_data.map.depth).roll(rng)));
|
||||
// Placeholder for scroll spawn
|
||||
}
|
||||
')' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, equipment_table(build_data.map.depth).roll(rng)));
|
||||
// Placeholder for scroll spawn
|
||||
}
|
||||
_ => {
|
||||
rltk::console::log(format!("Unknown glyph '{}' when loading prefab", (ch as u8) as char));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use super::{BuilderMap, MetaMapBuilder, Rect};
|
||||
use rltk::RandomNumberGenerator;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum RoomSort {
|
||||
LEFTMOST,
|
||||
RIGHTMOST,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use super::{apply_room_to_map, apply_vertical_tunnel, BuilderMap, InitialMapBuilder, Rect};
|
||||
use super::{BuilderMap, InitialMapBuilder, Rect};
|
||||
use rltk::RandomNumberGenerator;
|
||||
|
||||
pub struct SimpleMapBuilder {}
|
||||
pub struct SimpleMapBuilder {
|
||||
room_params: (i32, i32, i32),
|
||||
}
|
||||
|
||||
impl InitialMapBuilder for SimpleMapBuilder {
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -12,19 +14,28 @@ impl InitialMapBuilder for SimpleMapBuilder {
|
|||
|
||||
impl SimpleMapBuilder {
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Box<SimpleMapBuilder> {
|
||||
Box::new(SimpleMapBuilder {})
|
||||
pub fn new(room_params: Option<(i32, i32, i32)>) -> Box<SimpleMapBuilder> {
|
||||
const DEFAULT_MAX_ROOMS: i32 = 40;
|
||||
const DEFAULT_MIN_SIZE: i32 = 6;
|
||||
const DEFAULT_MAX_SIZE: i32 = 16;
|
||||
|
||||
let (max_rooms, min_size, max_size);
|
||||
|
||||
if let Some(room_params) = room_params {
|
||||
(max_rooms, min_size, max_size) = (room_params.0, room_params.1, room_params.2)
|
||||
} else {
|
||||
(max_rooms, min_size, max_size) = (DEFAULT_MAX_ROOMS, DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE)
|
||||
}
|
||||
|
||||
Box::new(SimpleMapBuilder { room_params: (max_rooms, min_size, max_size) })
|
||||
}
|
||||
|
||||
fn build_rooms(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
const MAX_ROOMS: i32 = 30;
|
||||
const MIN_SIZE: i32 = 6;
|
||||
const MAX_SIZE: i32 = 10;
|
||||
let mut rooms: Vec<Rect> = Vec::new();
|
||||
|
||||
for _i in 0..MAX_ROOMS {
|
||||
let w = rng.range(MIN_SIZE, MAX_SIZE);
|
||||
let h = rng.range(MIN_SIZE, MAX_SIZE);
|
||||
for _i in 0..self.room_params.0 {
|
||||
let w = rng.range(self.room_params.1, self.room_params.2);
|
||||
let h = rng.range(self.room_params.1, self.room_params.2);
|
||||
let x = rng.roll_dice(1, build_data.map.width - w - 1) - 1;
|
||||
let y = rng.roll_dice(1, build_data.map.height - h - 1) - 1;
|
||||
let new_room = Rect::new(x, y, w, h);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl WaveFunctionCollapseBuilder {
|
|||
let constraints = patterns_to_constraints(patterns, CHUNK_SIZE);
|
||||
self.render_tile_gallery(&constraints, CHUNK_SIZE, build_data);
|
||||
|
||||
build_data.map = Map::new(build_data.map.depth);
|
||||
build_data.map = Map::new(build_data.map.depth, build_data.map.width, build_data.map.height);
|
||||
loop {
|
||||
let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map);
|
||||
while !solver.iteration(&mut build_data.map, rng) {
|
||||
|
|
@ -46,7 +46,7 @@ impl WaveFunctionCollapseBuilder {
|
|||
}
|
||||
|
||||
fn render_tile_gallery(&mut self, constraints: &[MapChunk], chunk_size: i32, build_data: &mut BuilderMap) {
|
||||
build_data.map = Map::new(0);
|
||||
build_data.map = Map::new(0, build_data.width, build_data.height);
|
||||
let mut counter = 0;
|
||||
let mut x = 1;
|
||||
let mut y = 1;
|
||||
|
|
@ -62,7 +62,7 @@ impl WaveFunctionCollapseBuilder {
|
|||
if y + chunk_size > build_data.map.height {
|
||||
// Move to the next page
|
||||
build_data.take_snapshot();
|
||||
build_data.map = Map::new(0);
|
||||
build_data.map = Map::new(0, build_data.width, build_data.height);
|
||||
|
||||
x = 1;
|
||||
y = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue