Move consts to top of file
This commit is contained in:
parent
b62df4c79d
commit
aa0b600ec8
34
src/rooms.rs
34
src/rooms.rs
|
@ -26,6 +26,23 @@ use rand::Rng;
|
||||||
|
|
||||||
use crate::game::{DungeonTile, LEVEL_SIZE};
|
use crate::game::{DungeonTile, LEVEL_SIZE};
|
||||||
|
|
||||||
|
/// The possible sizes of a room, on both the x and y axes.
|
||||||
|
const ROOM_SIZE_LIMITS: Range<usize> = 4..8;
|
||||||
|
|
||||||
|
/// The minimum distance between the interiors of 2 rooms. Should be
|
||||||
|
/// at least 1 to ensure that walls generate.
|
||||||
|
const ROOM_MIN_DISTANCE: usize = 4;
|
||||||
|
|
||||||
|
/// Factor to encourage routes to travel through existing rooms rather
|
||||||
|
/// than cutting new hallways. 0.0 very strongly encourages traveling
|
||||||
|
/// through rooms, 1.0 is indifferent to the existence of rooms, and
|
||||||
|
/// higher values discourage traveling through rooms (hallways will
|
||||||
|
/// wrap around rooms rather than enter them).
|
||||||
|
const ROOM_WEIGHT: f64 = 0.5;
|
||||||
|
|
||||||
|
/// Randomness factor to avoid straight lines in hallways.
|
||||||
|
const HALLWAY_RANDOMNESS: f64 = 0.6;
|
||||||
|
|
||||||
/// Generates a grid of the given size containing rooms connected by
|
/// Generates a grid of the given size containing rooms connected by
|
||||||
/// passages.
|
/// passages.
|
||||||
pub fn generate(n_rooms: usize, size: (usize, usize), rng: &mut impl Rng) -> Grid<DungeonTile> {
|
pub fn generate(n_rooms: usize, size: (usize, usize), rng: &mut impl Rng) -> Grid<DungeonTile> {
|
||||||
|
@ -67,13 +84,6 @@ pub fn generate_level(
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The possible sizes of a room, on both the x and y axes.
|
|
||||||
const ROOM_SIZE_LIMITS: Range<usize> = 4..8;
|
|
||||||
|
|
||||||
/// The minimum distance between the interiors of 2 rooms. Should be
|
|
||||||
/// at least 1 to ensure that walls generate.
|
|
||||||
const ROOM_MIN_DISTANCE: usize = 4;
|
|
||||||
|
|
||||||
/// The bounding box of a room.
|
/// The bounding box of a room.
|
||||||
struct RoomBounds {
|
struct RoomBounds {
|
||||||
ul_corner: (usize, usize),
|
ul_corner: (usize, usize),
|
||||||
|
@ -157,16 +167,6 @@ impl RoomBounds {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Factor to encourage routes to travel through existing rooms rather
|
|
||||||
/// than cutting new hallways. 0.0 very strongly encourages traveling
|
|
||||||
/// through rooms, 1.0 is indifferent to the existence of rooms, and
|
|
||||||
/// higher values discourage traveling through rooms (hallways will
|
|
||||||
/// wrap around rooms rather than enter them).
|
|
||||||
const ROOM_WEIGHT: f64 = 0.5;
|
|
||||||
|
|
||||||
/// Randomness factor to avoid straight lines in hallways.
|
|
||||||
const HALLWAY_RANDOMNESS: f64 = 0.6;
|
|
||||||
|
|
||||||
/// Adds a set of hallways connecting the given rooms to a dungeon.
|
/// Adds a set of hallways connecting the given rooms to a dungeon.
|
||||||
fn cut_hallways(grid: &mut Grid<DungeonTile>, rooms: &[RoomBounds], rng: &mut impl Rng) {
|
fn cut_hallways(grid: &mut Grid<DungeonTile>, rooms: &[RoomBounds], rng: &mut impl Rng) {
|
||||||
// How hard we try to avoid traveling through stone at a pair of
|
// How hard we try to avoid traveling through stone at a pair of
|
||||||
|
|
Loading…
Reference in a new issue