diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1aa83be..74c7e5c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -13,12 +13,12 @@
-
-
-
+
+
+
-
+
@@ -49,6 +49,9 @@
+
+
+
@@ -64,6 +67,7 @@
+
@@ -78,7 +82,7 @@
1643546643557
-
+
diff --git a/src/components.rs b/src/components.rs
index 3f7b416..cbdee50 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -13,18 +13,13 @@ pub struct Position {
impl Position {
pub fn new(x: i32, y: i32) -> Self {
- Self {
- x, y
- }
+ Self { x, y }
}
}
impl Default for Position {
fn default() -> Self {
- Self {
- x: 0,
- y: 0
- }
+ Self { x: 0, y: 0 }
}
}
diff --git a/src/map_builders/bsp/mod.rs b/src/map_builders/bsp/mod.rs
index cc33133..3d6dc3d 100644
--- a/src/map_builders/bsp/mod.rs
+++ b/src/map_builders/bsp/mod.rs
@@ -19,4 +19,4 @@ pub fn draw_corridor(map: &mut Map, x1: i32, y1: i32, x2: i32, y2: i32) {
let idx = map.xy_idx(x, y);
map.tiles[idx] = TileType::Floor;
}
-}
\ No newline at end of file
+}
diff --git a/src/map_builders/bsp_dungeon.rs b/src/map_builders/bsp_dungeon.rs
index 7ecf5bc..bad4326 100644
--- a/src/map_builders/bsp_dungeon.rs
+++ b/src/map_builders/bsp_dungeon.rs
@@ -186,7 +186,7 @@ impl MapBuilder for BspDungeonBuilder {
fn spawn_entities(&mut self, ecs: &mut World) {
for room in self.rooms.iter().skip(1) {
- spawner::spawn_room(ecs, room, self.depth, &self.map);
+ spawner::spawn_room(ecs, room, self.depth);
}
}
diff --git a/src/map_builders/bsp_interior.rs b/src/map_builders/bsp_interior.rs
index c2b77c6..102b783 100644
--- a/src/map_builders/bsp_interior.rs
+++ b/src/map_builders/bsp_interior.rs
@@ -1,10 +1,10 @@
-use rltk::RandomNumberGenerator;
-use crate::{Map, Position, SHOW_MAPGEN_VISUALIZER, spawner, TileType, World};
use crate::map_builders::common::reveal_all;
use crate::map_builders::{bsp, MapBuilder};
use crate::rect::Rect;
+use crate::{spawner, Map, Position, TileType, World, SHOW_MAPGEN_VISUALIZER};
+use rltk::RandomNumberGenerator;
-const MIN_ROOM_SIZE : i32 = 8;
+const MIN_ROOM_SIZE: i32 = 8;
pub struct BspInteriorBuilder {
map: Map,
@@ -16,18 +16,17 @@ pub struct BspInteriorBuilder {
}
impl BspInteriorBuilder {
- pub fn new(new_depth: i32) -> Self{
+ pub fn new(new_depth: i32) -> Self {
Self {
map: Map::new(new_depth),
rects: Vec::new(),
- history:Vec::new(),
+ history: Vec::new(),
depth: new_depth,
rooms: Vec::new(),
- starting_position: Position::default()
+ starting_position: Position::default(),
}
}
-
fn build(&mut self) {
let mut rng = RandomNumberGenerator::new();
@@ -54,8 +53,10 @@ impl BspInteriorBuilder {
let next_room = self.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);
+ 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);
self.draw_corridor(start_x, start_y, end_x, end_y);
self.take_snapshot();
}
@@ -63,7 +64,8 @@ impl BspInteriorBuilder {
fn place_rooms(&mut self, mut rng: &mut RandomNumberGenerator) {
self.rects.clear();
- self.rects.push(Rect::new(1, 1, self.map.width - 2, self.map.height - 2));
+ self.rects
+ .push(Rect::new(1, 1, self.map.width - 2, self.map.height - 2));
let first_room = self.rects[0];
self.add_subrects(first_room, &mut rng);
@@ -96,7 +98,7 @@ impl BspInteriorBuilder {
let split = rng.roll_dice(1, 4);
if split <= 2 {
- let h1 = Rect::new(rect.x1, rect.y1, half_width -1, height);
+ let h1 = Rect::new(rect.x1, rect.y1, half_width - 1, height);
self.rects.push(h1);
if half_width > MIN_ROOM_SIZE {
self.add_subrects(h1, rng);
@@ -106,13 +108,13 @@ impl BspInteriorBuilder {
if half_width > MIN_ROOM_SIZE {
self.add_subrects(h2, rng);
}
- }else {
- let v1 = Rect::new(rect.x1, rect.y1, width , half_height - 1);
+ } else {
+ let v1 = Rect::new(rect.x1, rect.y1, width, half_height - 1);
self.rects.push(v1);
if half_height > MIN_ROOM_SIZE {
self.add_subrects(v1, rng);
}
- let v2 = Rect::new(rect.x1 , rect.y1 + half_height, width, half_height);
+ let v2 = Rect::new(rect.x1, rect.y1 + half_height, width, half_height);
self.rects.push(v2);
if half_height > MIN_ROOM_SIZE {
self.add_subrects(v2, rng);
@@ -132,7 +134,7 @@ impl MapBuilder for BspInteriorBuilder {
fn spawn_entities(&mut self, ecs: &mut World) {
for room in self.rooms.iter().skip(1) {
- spawner::spawn_room(ecs, room, self.depth, &self.map);
+ spawner::spawn_room(ecs, room, self.depth);
}
}
@@ -154,4 +156,3 @@ impl MapBuilder for BspInteriorBuilder {
}
}
}
-
diff --git a/src/map_builders/cellular_automata.rs b/src/map_builders/cellular_automata.rs
new file mode 100644
index 0000000..364a481
--- /dev/null
+++ b/src/map_builders/cellular_automata.rs
@@ -0,0 +1,168 @@
+use std::collections::HashMap;
+use std::process::exit;
+use rltk::RandomNumberGenerator;
+use crate::map_builders::{common, MapBuilder};
+use crate::{Map, Position, World, SHOW_MAPGEN_VISUALIZER, TileType, spawner};
+
+const MIN_ROOM_SIZE: i32 = 8;
+
+pub struct CellularAutomataBuilder {
+ map: Map,
+ starting_position: Position,
+ depth: i32,
+ history: Vec