Add room_exploder and room_corner_rounder map filters
This commit is contained in:
parent
74fcc25b8c
commit
099f373ee8
@ -12,6 +12,8 @@ mod prefab_builder;
|
|||||||
mod room_based_spawner;
|
mod room_based_spawner;
|
||||||
mod room_based_stairs;
|
mod room_based_stairs;
|
||||||
mod room_based_starting_position;
|
mod room_based_starting_position;
|
||||||
|
mod room_corner_rounding;
|
||||||
|
mod room_exploder;
|
||||||
mod simple_map;
|
mod simple_map;
|
||||||
mod voronoi;
|
mod voronoi;
|
||||||
mod voronoi_spawning;
|
mod voronoi_spawning;
|
||||||
@ -31,6 +33,8 @@ use prefab_builder::PrefabBuilder;
|
|||||||
use room_based_spawner::RoomBasedSpawner;
|
use room_based_spawner::RoomBasedSpawner;
|
||||||
use room_based_stairs::RoomBasedStairs;
|
use room_based_stairs::RoomBasedStairs;
|
||||||
use room_based_starting_position::RoomBasedStartingPosition;
|
use room_based_starting_position::RoomBasedStartingPosition;
|
||||||
|
use room_corner_rounding::RoomCornerRounder;
|
||||||
|
use room_exploder::RoomExploder;
|
||||||
use simple_map::SimpleMapBuilder;
|
use simple_map::SimpleMapBuilder;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use voronoi::VoronoiCellBuilder;
|
use voronoi::VoronoiCellBuilder;
|
||||||
|
60
src/map_builders/room_corner_rounding.rs
Normal file
60
src/map_builders/room_corner_rounding.rs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::{Rect, TileType};
|
||||||
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
|
pub struct RoomCornerRounder {}
|
||||||
|
|
||||||
|
impl MetaMapBuilder for RoomCornerRounder {
|
||||||
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
self.build(rng, build_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomCornerRounder {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new() -> Box<RoomCornerRounder> {
|
||||||
|
Box::new(RoomCornerRounder {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_if_corner(&mut self, x: i32, y: i32, build_data: &mut BuilderMap) {
|
||||||
|
let w = build_data.map.width;
|
||||||
|
let h = build_data.map.height;
|
||||||
|
let idx = build_data.map.xy_idx(x, y);
|
||||||
|
let mut neighbor_walls = 0;
|
||||||
|
|
||||||
|
if x > 0 && build_data.map.tiles[idx - 1] == TileType::Wall {
|
||||||
|
neighbor_walls += 1;
|
||||||
|
}
|
||||||
|
if y > 0 && build_data.map.tiles[idx - w as usize] == TileType::Wall {
|
||||||
|
neighbor_walls += 1;
|
||||||
|
}
|
||||||
|
if x < w - 2 && build_data.map.tiles[idx + 1] == TileType::Wall {
|
||||||
|
neighbor_walls += 1;
|
||||||
|
}
|
||||||
|
if y < h - 2 && build_data.map.tiles[idx + w as usize] == TileType::Wall {
|
||||||
|
neighbor_walls += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if neighbor_walls == 2 {
|
||||||
|
build_data.map.tiles[idx] = TileType::Wall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build(&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!("Room Rounding requires a builder with room structures");
|
||||||
|
}
|
||||||
|
|
||||||
|
for room in rooms.iter() {
|
||||||
|
self.fill_if_corner(room.x1 + 1, room.y1 + 1, build_data);
|
||||||
|
self.fill_if_corner(room.x2, room.y1 + 1, build_data);
|
||||||
|
self.fill_if_corner(room.x1 + 1, room.y2, build_data);
|
||||||
|
self.fill_if_corner(room.x2, room.y2, build_data);
|
||||||
|
|
||||||
|
build_data.take_snapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
88
src/map_builders/room_exploder.rs
Normal file
88
src/map_builders/room_exploder.rs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
use crate::map_builders::common::{paint, Symmetry};
|
||||||
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::{Rect, TileType};
|
||||||
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
|
pub struct RoomExploder {}
|
||||||
|
|
||||||
|
impl MetaMapBuilder for RoomExploder {
|
||||||
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||||
|
self.build(rng, build_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomExploder {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn new() -> Box<RoomExploder> {
|
||||||
|
Box::new(RoomExploder {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build(&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!("Room Explosions require a builder with room structures");
|
||||||
|
}
|
||||||
|
|
||||||
|
for room in rooms.iter() {
|
||||||
|
let start = room.center();
|
||||||
|
let n_diggers = rng.roll_dice(1, 20) - 5;
|
||||||
|
|
||||||
|
if n_diggers > 0 {
|
||||||
|
for _i in 0..n_diggers {
|
||||||
|
let mut drunk_x = start.0;
|
||||||
|
let mut drunk_y = start.1;
|
||||||
|
|
||||||
|
let mut drunk_life = 20;
|
||||||
|
let mut did_something = false;
|
||||||
|
|
||||||
|
while drunk_life > 0 {
|
||||||
|
let drunk_idx = build_data.map.xy_idx(drunk_x, drunk_y);
|
||||||
|
if build_data.map.tiles[drunk_idx] == TileType::Wall {
|
||||||
|
did_something = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(&mut build_data.map, Symmetry::None, 1, drunk_x, drunk_y);
|
||||||
|
build_data.map.tiles[drunk_idx] = TileType::DownStairs;
|
||||||
|
|
||||||
|
match rng.roll_dice(1, 4) {
|
||||||
|
1 => {
|
||||||
|
if drunk_x > 2 {
|
||||||
|
drunk_x -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
if drunk_x < build_data.map.width - 2 {
|
||||||
|
drunk_x += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
if drunk_y > 2 {
|
||||||
|
drunk_y -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
if drunk_y < build_data.map.height - 2 {
|
||||||
|
drunk_y += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drunk_life -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if did_something {
|
||||||
|
build_data.take_snapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
for t in build_data.map.tiles.iter_mut() {
|
||||||
|
if *t == TileType::DownStairs {
|
||||||
|
*t = TileType::Floor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user