summaryrefslogtreecommitdiff
path: root/dungeon/src
diff options
context:
space:
mode:
authoralf9310 <alf9310@rit.edu>2025-11-10 00:31:56 -0500
committeralf9310 <alf9310@rit.edu>2025-11-10 00:31:56 -0500
commit0d484d763a243e6b73e13d4968ccf6222b65eeca (patch)
treeeefc124a4bbe165710eac9faeb2426a8e2608747 /dungeon/src
parentdungeon_generation: added Hallway vs Room tiles (diff)
downloadDungeonCrawl-0d484d763a243e6b73e13d4968ccf6222b65eeca.tar.gz
DungeonCrawl-0d484d763a243e6b73e13d4968ccf6222b65eeca.tar.bz2
DungeonCrawl-0d484d763a243e6b73e13d4968ccf6222b65eeca.zip
Added many auto-gen test cases for maze connectivity
Diffstat (limited to 'dungeon/src')
-rw-r--r--dungeon/src/bsp.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/dungeon/src/bsp.rs b/dungeon/src/bsp.rs
index 8b5fa3b..aaafa10 100644
--- a/dungeon/src/bsp.rs
+++ b/dungeon/src/bsp.rs
@@ -228,15 +228,14 @@ impl Node {
}
/// Connect rooms of child nodes recursively and collect corridors to carve.
- ///
/// returns corridors: output vector of (Pos, Pos) pairs to connect
fn connect_children(&self, rng: &mut rand::rngs::StdRng) -> Vec<(Pos, Pos)> {
let mut corridors = Vec::new();
if let (Some(left), Some(right)) = (&self.left, &self.right) {
- // Get room centers for left and right children
- let left_point = left.room_center();
- let right_point = right.room_center();
+ // Get a random point in each child's room
+ let left_point = left.random_point_in_room(rng);
+ let right_point = right.random_point_in_room(rng);
corridors.push((left_point, right_point));
// Recursively connect children
@@ -265,6 +264,10 @@ fn carve_h_corridor(tiles: &mut [Tile; TILE_COUNT], x1: u16, x2: u16, y: u16) {
let (sx, ex) = if x1 <= x2 { (x1, x2) } else { (x2, x1) };
for x in sx..=ex {
let idx = x + y * MAP_SIZE;
+ // Don't carve if it's already a room
+ if tiles[idx as usize] == Tile::Room {
+ continue;
+ }
tiles[idx as usize] = Tile::Hallway;
}
}
@@ -274,6 +277,10 @@ fn carve_v_corridor(tiles: &mut [Tile; TILE_COUNT], y1: u16, y2: u16, x: u16) {
let (sy, ey) = if y1 <= y2 { (y1, y2) } else { (y2, y1) };
for y in sy..=ey {
let idx = x + y * MAP_SIZE;
+ // Don't carve if it's already a room
+ if tiles[idx as usize] == Tile::Room {
+ continue;
+ }
tiles[idx as usize] = Tile::Hallway;
}
}
@@ -374,8 +381,6 @@ pub fn generate(seed: u64) -> (Box<[Tile; TILE_COUNT]>, Pos) {
}
// Choose player start randomly in the center of one of the rooms (leaf nodes)
-
- // Choose a random leaf node (room) for the player start
let mut leaves = vec![];
root.collect_leaves(&mut leaves);
let player_room = leaves.choose(&mut rng).unwrap_or(&leaves[0]);
@@ -454,6 +459,7 @@ mod tests {
let mut node = Node::new(rect);
let mut rng = rand::rngs::StdRng::seed_from_u64(12345);
node.split(&mut rng);
+ node.create_room(&mut rng);
let corridors = node.connect_children(&mut rng);
assert!(!corridors.is_empty());
}