Use new rng module instead of passing around a variable. Completes section 5.31
This commit is contained in:
parent
206f012729
commit
fd9f8e7463
@ -1,4 +1,3 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
@ -6,6 +5,7 @@ use crate::components::{
|
|||||||
};
|
};
|
||||||
use crate::effects::*;
|
use crate::effects::*;
|
||||||
use crate::raws::{self, SpawnType, RAWS};
|
use crate::raws::{self, SpawnType, RAWS};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, gamelog, Map, RunState};
|
use crate::{colors, gamelog, Map, RunState};
|
||||||
|
|
||||||
pub fn delete_the_dead(ecs: &mut World) {
|
pub fn delete_the_dead(ecs: &mut World) {
|
||||||
@ -49,7 +49,6 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
let mut carried = ecs.write_storage::<InBackpack>();
|
let mut carried = ecs.write_storage::<InBackpack>();
|
||||||
let mut positions = ecs.write_storage::<Position>();
|
let mut positions = ecs.write_storage::<Position>();
|
||||||
let loot_tables = ecs.read_storage::<LootTable>();
|
let loot_tables = ecs.read_storage::<LootTable>();
|
||||||
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
|
|
||||||
|
|
||||||
for victim in dead.iter() {
|
for victim in dead.iter() {
|
||||||
let pos = positions.get(*victim);
|
let pos = positions.get(*victim);
|
||||||
@ -72,7 +71,7 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
|
|
||||||
if let Some(table) = loot_tables.get(*victim) {
|
if let Some(table) = loot_tables.get(*victim) {
|
||||||
let drop_finder =
|
let drop_finder =
|
||||||
raws::get_item_drop(&crate::raws::RAWS.lock().unwrap(), &mut rng, &table.table);
|
raws::get_item_drop(&crate::raws::RAWS.lock().unwrap(), &table.table);
|
||||||
if let Some(tag) = drop_finder {
|
if let Some(tag) = drop_finder {
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
to_spawn.push((tag, *pos));
|
to_spawn.push((tag, *pos));
|
||||||
@ -108,9 +107,8 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
for victim in dead.iter() {
|
for victim in dead.iter() {
|
||||||
let death_effects = ecs.read_storage::<OnDeath>();
|
let death_effects = ecs.read_storage::<OnDeath>();
|
||||||
if let Some(death_effect) = death_effects.get(*victim) {
|
if let Some(death_effect) = death_effects.get(*victim) {
|
||||||
let mut rng = ecs.fetch_mut::<RandomNumberGenerator>();
|
|
||||||
for effect in death_effect.abilities.iter() {
|
for effect in death_effect.abilities.iter() {
|
||||||
if rng.roll_dice(1, 100) <= (effect.chance * 100.0) as i32 {
|
if roll_dice(1, 100) <= (effect.chance * 100.0) as i32 {
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
if let Some(pos) = ecs.read_storage::<Position>().get(*victim) {
|
if let Some(pos) = ecs.read_storage::<Position>().get(*victim) {
|
||||||
let spell_entity =
|
let spell_entity =
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::Point;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||||
|
|
||||||
@ -7,6 +7,7 @@ use crate::components::{
|
|||||||
Attributes, Confusion, DamageOverTime, Duration, Name, Player, Pools, SerializeMe, Skills, Slow,
|
Attributes, Confusion, DamageOverTime, Duration, Name, Player, Pools, SerializeMe, Skills, Slow,
|
||||||
};
|
};
|
||||||
use crate::gamesystem::{mana_at_level, player_hp_at_level};
|
use crate::gamesystem::{mana_at_level, player_hp_at_level};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, gamelog, EquipmentChanged, Map, StatusEffect};
|
use crate::{colors, gamelog, EquipmentChanged, Map, StatusEffect};
|
||||||
|
|
||||||
pub fn inflict_damage(ecs: &mut World, damage: &EffectSpawner, target: Entity) {
|
pub fn inflict_damage(ecs: &mut World, damage: &EffectSpawner, target: Entity) {
|
||||||
@ -90,8 +91,7 @@ pub fn death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
|
|||||||
.log();
|
.log();
|
||||||
|
|
||||||
// Improve a random attribute
|
// Improve a random attribute
|
||||||
let mut rng = ecs.fetch_mut::<RandomNumberGenerator>();
|
match roll_dice(1, 4) {
|
||||||
match rng.roll_dice(1, 4) {
|
|
||||||
1 => {
|
1 => {
|
||||||
player_attributes.might.base += 1;
|
player_attributes.might.base += 1;
|
||||||
gamelog::log_color_line(colors::GREEN, "You feel stronger!");
|
gamelog::log_color_line(colors::GREEN, "You feel stronger!");
|
||||||
|
@ -154,7 +154,7 @@ fn register_components(state: &mut State) {
|
|||||||
/// * Creates the [`Player`](crate::spawner::player)
|
/// * Creates the [`Player`](crate::spawner::player)
|
||||||
/// * Generates the first [`map`](crate::state::State::generate_world_map)
|
/// * Generates the first [`map`](crate::state::State::generate_world_map)
|
||||||
fn init_state() -> State {
|
fn init_state() -> State {
|
||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::Point;
|
||||||
use systems::particle_system::ParticleBuilder;
|
use systems::particle_system::ParticleBuilder;
|
||||||
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
@ -170,7 +170,6 @@ fn init_state() -> State {
|
|||||||
state.ecs.insert(MasterDungeonMap::new());
|
state.ecs.insert(MasterDungeonMap::new());
|
||||||
state.ecs.insert(Map::new(1, 64, 64, "New Map"));
|
state.ecs.insert(Map::new(1, 64, 64, "New Map"));
|
||||||
state.ecs.insert(Point::zero());
|
state.ecs.insert(Point::zero());
|
||||||
state.ecs.insert(RandomNumberGenerator::new());
|
|
||||||
|
|
||||||
let player_entity = spawner::player(&mut state.ecs, 0, 0);
|
let player_entity = spawner::player(&mut state.ecs, 0, 0);
|
||||||
state.ecs.insert(player_entity);
|
state.ecs.insert(player_entity);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Functionality that is common to all the currently generated maps.
|
//! Functionality that is common to all the currently generated maps.
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::Point;
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ use crate::components::{OtherLevelPosition, Position, Viewshed};
|
|||||||
use crate::map::{Map, TileType};
|
use crate::map::{Map, TileType};
|
||||||
use crate::map_builders::level_builder;
|
use crate::map_builders::level_builder;
|
||||||
use crate::raws;
|
use crate::raws;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct MasterDungeonMap {
|
pub struct MasterDungeonMap {
|
||||||
@ -27,16 +28,15 @@ impl MasterDungeonMap {
|
|||||||
potion_mappings: HashMap::new(),
|
potion_mappings: HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut rng = RandomNumberGenerator::new();
|
|
||||||
for scroll_tag in raws::get_scroll_tags().iter() {
|
for scroll_tag in raws::get_scroll_tags().iter() {
|
||||||
let masked_name = make_scroll_name(&mut rng);
|
let masked_name = make_scroll_name();
|
||||||
dm.scroll_mappings
|
dm.scroll_mappings
|
||||||
.insert(scroll_tag.to_string(), masked_name);
|
.insert(scroll_tag.to_string(), masked_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut used_potion_names = HashSet::new();
|
let mut used_potion_names = HashSet::new();
|
||||||
for potion_tag in raws::get_potion_tags().iter() {
|
for potion_tag in raws::get_potion_tags().iter() {
|
||||||
let masked_name = make_potion_name(&mut rng, &mut used_potion_names);
|
let masked_name = make_potion_name(&mut used_potion_names);
|
||||||
dm.potion_mappings
|
dm.potion_mappings
|
||||||
.insert(potion_tag.to_string(), masked_name);
|
.insert(potion_tag.to_string(), masked_name);
|
||||||
}
|
}
|
||||||
@ -57,13 +57,13 @@ impl MasterDungeonMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_scroll_name(rng: &mut rltk::RandomNumberGenerator) -> String {
|
fn make_scroll_name() -> String {
|
||||||
let length = 4 + rng.roll_dice(1, 4);
|
let length = 4 + roll_dice(1, 4);
|
||||||
let mut name = "Scroll of ".to_string();
|
let mut name = "Scroll of ".to_string();
|
||||||
|
|
||||||
for i in 0..length {
|
for i in 0..length {
|
||||||
if i % 2 == 0 {
|
if i % 2 == 0 {
|
||||||
name += match rng.roll_dice(1, 5) {
|
name += match roll_dice(1, 5) {
|
||||||
1 => "a",
|
1 => "a",
|
||||||
2 => "e",
|
2 => "e",
|
||||||
3 => "i",
|
3 => "i",
|
||||||
@ -71,7 +71,7 @@ fn make_scroll_name(rng: &mut rltk::RandomNumberGenerator) -> String {
|
|||||||
_ => "u",
|
_ => "u",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name += match rng.roll_dice(1, 21) {
|
name += match roll_dice(1, 21) {
|
||||||
1 => "b",
|
1 => "b",
|
||||||
2 => "c",
|
2 => "c",
|
||||||
3 => "d",
|
3 => "d",
|
||||||
@ -113,13 +113,12 @@ const POTION_ADJECTIVES: &[&str] = &[
|
|||||||
"Glowing",
|
"Glowing",
|
||||||
];
|
];
|
||||||
|
|
||||||
fn make_potion_name(rng: &mut RandomNumberGenerator, used_names: &mut HashSet<String>) -> String {
|
fn make_potion_name(used_names: &mut HashSet<String>) -> String {
|
||||||
loop {
|
loop {
|
||||||
let mut name = POTION_ADJECTIVES
|
let mut name = POTION_ADJECTIVES[roll_dice(1, POTION_ADJECTIVES.len() as i32) as usize - 1]
|
||||||
[rng.roll_dice(1, POTION_ADJECTIVES.len() as i32) as usize - 1]
|
|
||||||
.to_string();
|
.to_string();
|
||||||
name += " ";
|
name += " ";
|
||||||
name += POTION_COLORS[rng.roll_dice(1, POTION_COLORS.len() as i32) as usize - 1];
|
name += POTION_COLORS[roll_dice(1, POTION_COLORS.len() as i32) as usize - 1];
|
||||||
name += " Potion";
|
name += " Potion";
|
||||||
|
|
||||||
if !used_names.contains(&name) {
|
if !used_names.contains(&name) {
|
||||||
@ -148,9 +147,8 @@ pub fn level_transition(ecs: &mut World, new_depth: i32, offset: i32) -> Option<
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transition_to_new_map(ecs: &mut World, new_depth: i32) -> Vec<Map> {
|
fn transition_to_new_map(ecs: &mut World, new_depth: i32) -> Vec<Map> {
|
||||||
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
|
let mut builder = level_builder(new_depth, 80, 50);
|
||||||
let mut builder = level_builder(new_depth, &mut rng, 80, 50);
|
builder.build_map();
|
||||||
builder.build_map(&mut rng);
|
|
||||||
|
|
||||||
if new_depth > 1 {
|
if new_depth > 1 {
|
||||||
if let Some(pos) = &builder.build_data.starting_position {
|
if let Some(pos) = &builder.build_data.starting_position {
|
||||||
@ -168,7 +166,6 @@ fn transition_to_new_map(ecs: &mut World, new_depth: i32) -> Vec<Map> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn bad guys
|
// Spawn bad guys
|
||||||
std::mem::drop(rng);
|
|
||||||
builder.spawn_entities(ecs);
|
builder.spawn_entities(ecs);
|
||||||
|
|
||||||
// Place the player and update resources
|
// Place the player and update resources
|
||||||
|
@ -34,7 +34,6 @@ mod voronoi;
|
|||||||
mod voronoi_spawning;
|
mod voronoi_spawning;
|
||||||
mod waveform_collapse;
|
mod waveform_collapse;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
use area_ending_point::{AreaEndingPosition, XEnd, YEnd};
|
use area_ending_point::{AreaEndingPosition, XEnd, YEnd};
|
||||||
use area_starting_points::{AreaStartingPosition, XStart, YStart};
|
use area_starting_points::{AreaStartingPosition, XStart, YStart};
|
||||||
@ -72,6 +71,7 @@ use voronoi::VoronoiCellBuilder;
|
|||||||
use voronoi_spawning::VoronoiSpawning;
|
use voronoi_spawning::VoronoiSpawning;
|
||||||
use waveform_collapse::WaveformCollapseBuilder;
|
use waveform_collapse::WaveformCollapseBuilder;
|
||||||
|
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{spawner, Map, Position, Rect, SHOW_MAPGEN_VISUALIZER};
|
use crate::{spawner, Map, Position, Rect, SHOW_MAPGEN_VISUALIZER};
|
||||||
|
|
||||||
pub struct BuilderMap {
|
pub struct BuilderMap {
|
||||||
@ -140,18 +140,18 @@ impl BuilderChain {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_map(&mut self, rng: &mut RandomNumberGenerator) -> &mut Self {
|
pub fn build_map(&mut self) -> &mut Self {
|
||||||
match &mut self.starter {
|
match &mut self.starter {
|
||||||
None => panic!("Cannot run a map builder chain without starting a build system"),
|
None => panic!("Cannot run a map builder chain without starting a build system"),
|
||||||
Some(starter) => {
|
Some(starter) => {
|
||||||
// Build the starting map
|
// Build the starting map
|
||||||
starter.build_map(rng, &mut self.build_data);
|
starter.build_map(&mut self.build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build additional layers in turn
|
// Build additional layers in turn
|
||||||
for metabuilder in self.builders.iter_mut() {
|
for metabuilder in self.builders.iter_mut() {
|
||||||
metabuilder.build_map(rng, &mut self.build_data);
|
metabuilder.build_map(&mut self.build_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -183,21 +183,21 @@ impl BuilderChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait InitialMapBuilder {
|
pub trait InitialMapBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap);
|
fn build_map(&mut self, build_data: &mut BuilderMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MetaMapBuilder {
|
pub trait MetaMapBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap);
|
fn build_map(&mut self, build_data: &mut BuilderMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_start_position(rng: &mut rltk::RandomNumberGenerator) -> (XStart, YStart) {
|
pub fn random_start_position() -> (XStart, YStart) {
|
||||||
let x = match rng.roll_dice(1, 3) {
|
let x = match roll_dice(1, 3) {
|
||||||
1 => XStart::Left,
|
1 => XStart::Left,
|
||||||
2 => XStart::Center,
|
2 => XStart::Center,
|
||||||
_ => XStart::Right,
|
_ => XStart::Right,
|
||||||
};
|
};
|
||||||
|
|
||||||
let y = match rng.roll_dice(1, 3) {
|
let y = match roll_dice(1, 3) {
|
||||||
1 => YStart::Bottom,
|
1 => YStart::Bottom,
|
||||||
2 => YStart::Center,
|
2 => YStart::Center,
|
||||||
_ => YStart::Top,
|
_ => YStart::Top,
|
||||||
@ -206,8 +206,8 @@ pub fn random_start_position(rng: &mut rltk::RandomNumberGenerator) -> (XStart,
|
|||||||
(x, y)
|
(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderChain) {
|
fn random_room_builder(builder: &mut BuilderChain) {
|
||||||
let build_roll = rng.roll_dice(1, 3);
|
let build_roll = roll_dice(1, 3);
|
||||||
match build_roll {
|
match build_roll {
|
||||||
1 => builder.start_with(SimpleMapBuilder::new()),
|
1 => builder.start_with(SimpleMapBuilder::new()),
|
||||||
2 => builder.start_with(BspDungeonBuilder::new()),
|
2 => builder.start_with(BspDungeonBuilder::new()),
|
||||||
@ -217,7 +217,7 @@ fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCha
|
|||||||
// BSP Interior still makes holes in the walls
|
// BSP Interior still makes holes in the walls
|
||||||
if build_roll != 3 {
|
if build_roll != 3 {
|
||||||
// Sort by one of the 5 available algorithms
|
// Sort by one of the 5 available algorithms
|
||||||
let room_sort = match rng.roll_dice(1, 5) {
|
let room_sort = match roll_dice(1, 5) {
|
||||||
1 => RoomSort::LeftMost,
|
1 => RoomSort::LeftMost,
|
||||||
2 => RoomSort::RightMost,
|
2 => RoomSort::RightMost,
|
||||||
3 => RoomSort::TopMost,
|
3 => RoomSort::TopMost,
|
||||||
@ -229,7 +229,7 @@ fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCha
|
|||||||
builder.with(RoomDrawer::new());
|
builder.with(RoomDrawer::new());
|
||||||
|
|
||||||
// Pick a corridor type
|
// Pick a corridor type
|
||||||
match rng.roll_dice(1, 4) {
|
match roll_dice(1, 4) {
|
||||||
1 => builder.with(DoglegCorridors::new()),
|
1 => builder.with(DoglegCorridors::new()),
|
||||||
2 => builder.with(NearestCorridors::new()),
|
2 => builder.with(NearestCorridors::new()),
|
||||||
3 => builder.with(StraightLineCorridors::new()),
|
3 => builder.with(StraightLineCorridors::new()),
|
||||||
@ -237,12 +237,12 @@ fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCha
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Maybe spawn stuff in the corridor
|
// Maybe spawn stuff in the corridor
|
||||||
if rng.roll_dice(1, 2) == 1 {
|
if roll_dice(1, 2) == 1 {
|
||||||
builder.with(CorridorSpawner::new());
|
builder.with(CorridorSpawner::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add additional modifier
|
// Add additional modifier
|
||||||
match rng.roll_dice(1, 6) {
|
match roll_dice(1, 6) {
|
||||||
1 => {
|
1 => {
|
||||||
builder.with(RoomExploder::new());
|
builder.with(RoomExploder::new());
|
||||||
}
|
}
|
||||||
@ -254,29 +254,29 @@ fn random_room_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCha
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find a starting position
|
// Find a starting position
|
||||||
match rng.roll_dice(1, 2) {
|
match roll_dice(1, 2) {
|
||||||
1 => builder.with(RoomBasedStartingPosition::new()),
|
1 => builder.with(RoomBasedStartingPosition::new()),
|
||||||
_ => {
|
_ => {
|
||||||
let (start_x, start_y) = random_start_position(rng);
|
let (start_x, start_y) = random_start_position();
|
||||||
builder.with(AreaStartingPosition::new(start_x, start_y))
|
builder.with(AreaStartingPosition::new(start_x, start_y))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find an exit
|
// Find an exit
|
||||||
match rng.roll_dice(1, 2) {
|
match roll_dice(1, 2) {
|
||||||
1 => builder.with(RoomBasedStairs::new()),
|
1 => builder.with(RoomBasedStairs::new()),
|
||||||
_ => builder.with(DistantExit::new()),
|
_ => builder.with(DistantExit::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Spawn stuff
|
// Spawn stuff
|
||||||
match rng.roll_dice(1, 2) {
|
match roll_dice(1, 2) {
|
||||||
1 => builder.with(RoomBasedSpawner::new()),
|
1 => builder.with(RoomBasedSpawner::new()),
|
||||||
_ => builder.with(VoronoiSpawning::new()),
|
_ => builder.with(VoronoiSpawning::new()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_shape_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderChain) {
|
fn random_shape_builder(builder: &mut BuilderChain) {
|
||||||
let first_builder: Box<dyn InitialMapBuilder> = match rng.roll_dice(1, 16) {
|
let first_builder: Box<dyn InitialMapBuilder> = match roll_dice(1, 16) {
|
||||||
1 => CellularAutomataBuilder::new(),
|
1 => CellularAutomataBuilder::new(),
|
||||||
2 => DrunkardsWalkBuilder::open_area(),
|
2 => DrunkardsWalkBuilder::open_area(),
|
||||||
3 => DrunkardsWalkBuilder::open_halls(),
|
3 => DrunkardsWalkBuilder::open_halls(),
|
||||||
@ -300,7 +300,7 @@ fn random_shape_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCh
|
|||||||
.with(CullUnreachable::new());
|
.with(CullUnreachable::new());
|
||||||
|
|
||||||
// Now set the start ot a random starting area
|
// Now set the start ot a random starting area
|
||||||
let (start_x, start_y) = random_start_position(rng);
|
let (start_x, start_y) = random_start_position();
|
||||||
builder.with(AreaStartingPosition::new(start_x, start_y));
|
builder.with(AreaStartingPosition::new(start_x, start_y));
|
||||||
|
|
||||||
// Setup an exit and spawn mobs
|
// Setup an exit and spawn mobs
|
||||||
@ -308,24 +308,19 @@ fn random_shape_builder(rng: &mut RandomNumberGenerator, builder: &mut BuilderCh
|
|||||||
builder.with(DistantExit::new());
|
builder.with(DistantExit::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_builder(
|
pub fn random_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut builder = BuilderChain::new(new_depth, width, height, "New Map");
|
let mut builder = BuilderChain::new(new_depth, width, height, "New Map");
|
||||||
|
|
||||||
match rng.roll_dice(1, 2) {
|
match roll_dice(1, 2) {
|
||||||
1 => random_room_builder(rng, &mut builder),
|
1 => random_room_builder(&mut builder),
|
||||||
_ => random_shape_builder(rng, &mut builder),
|
_ => random_shape_builder(&mut builder),
|
||||||
};
|
};
|
||||||
|
|
||||||
if rng.roll_dice(1, 3) == 1 {
|
if roll_dice(1, 3) == 1 {
|
||||||
builder.with(WaveformCollapseBuilder::new());
|
builder.with(WaveformCollapseBuilder::new());
|
||||||
|
|
||||||
// Now set the start to a random starting area
|
// Now set the start to a random starting area
|
||||||
let (start_x, start_y) = random_start_position(rng);
|
let (start_x, start_y) = random_start_position();
|
||||||
builder.with(AreaStartingPosition::new(start_x, start_y));
|
builder.with(AreaStartingPosition::new(start_x, start_y));
|
||||||
|
|
||||||
// Setup an exit and spawn mobs
|
// Setup an exit and spawn mobs
|
||||||
@ -334,7 +329,7 @@ pub fn random_builder(
|
|||||||
.with(DistantExit::new());
|
.with(DistantExit::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
if rng.roll_dice(1, 20) == 1 {
|
if roll_dice(1, 20) == 1 {
|
||||||
builder.with(PrefabBuilder::sectional(
|
builder.with(PrefabBuilder::sectional(
|
||||||
prefab_builder::prefab_sections::UNDERGROUND_FORT,
|
prefab_builder::prefab_sections::UNDERGROUND_FORT,
|
||||||
));
|
));
|
||||||
@ -346,23 +341,18 @@ pub fn random_builder(
|
|||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn level_builder(
|
pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
rltk::console::log(format!("Depth: {}", new_depth));
|
rltk::console::log(format!("Depth: {}", new_depth));
|
||||||
match new_depth {
|
match new_depth {
|
||||||
1 => town_builder(new_depth, rng, width, height),
|
1 => town_builder(new_depth, width, height),
|
||||||
2 => forest_builder(new_depth, rng, width, height),
|
2 => forest_builder(new_depth, width, height),
|
||||||
3 => limestone_cavern_builder(new_depth, rng, width, height),
|
3 => limestone_cavern_builder(new_depth, width, height),
|
||||||
4 => limestone_deep_cavern_builder(new_depth, rng, width, height),
|
4 => limestone_deep_cavern_builder(new_depth, width, height),
|
||||||
5 => limestone_transition_builder(new_depth, rng, width, height),
|
5 => limestone_transition_builder(new_depth, width, height),
|
||||||
6 => dwarf_fort_builder(new_depth, rng, width, height),
|
6 => dwarf_fort_builder(new_depth, width, height),
|
||||||
7 => mushroom_entrance(new_depth, rng, width, height),
|
7 => mushroom_entrance(new_depth, width, height),
|
||||||
8 => mushroom_builder(new_depth, rng, width, height),
|
8 => mushroom_builder(new_depth, width, height),
|
||||||
9 => mushroom_exit(new_depth, rng, width, height),
|
9 => mushroom_exit(new_depth, width, height),
|
||||||
_ => random_builder(new_depth, rng, width, height),
|
_ => random_builder(new_depth, width, height),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ::rltk::{DistanceAlg, Point, RandomNumberGenerator};
|
use ::rltk::{DistanceAlg, Point};
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::{map, TileType};
|
use crate::{map, TileType};
|
||||||
@ -23,8 +23,8 @@ pub struct AreaEndingPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for AreaEndingPosition {
|
impl MetaMapBuilder for AreaEndingPosition {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ impl AreaEndingPosition {
|
|||||||
Box::new(AreaEndingPosition { x, y })
|
Box::new(AreaEndingPosition { x, y })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let seed_x = match self.x {
|
let seed_x = match self.x {
|
||||||
XEnd::Left => 1,
|
XEnd::Left => 1,
|
||||||
XEnd::Center => build_data.map.width / 2,
|
XEnd::Center => build_data.map.width / 2,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::{map, Position};
|
use crate::{map, Position};
|
||||||
|
|
||||||
@ -23,8 +21,8 @@ pub struct AreaStartingPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for AreaStartingPosition {
|
impl MetaMapBuilder for AreaStartingPosition {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +32,7 @@ impl AreaStartingPosition {
|
|||||||
Box::new(AreaStartingPosition { x, y })
|
Box::new(AreaStartingPosition { x, y })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let seed_x = match self.x {
|
let seed_x = match self.x {
|
||||||
XStart::Left => 1,
|
XStart::Left => 1,
|
||||||
XStart::Center => build_data.map.width / 2,
|
XStart::Center => build_data.map.width / 2,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
pub struct BspDungeonBuilder {
|
pub struct BspDungeonBuilder {
|
||||||
@ -9,8 +8,8 @@ pub struct BspDungeonBuilder {
|
|||||||
|
|
||||||
impl InitialMapBuilder for BspDungeonBuilder {
|
impl InitialMapBuilder for BspDungeonBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ impl BspDungeonBuilder {
|
|||||||
Box::new(BspDungeonBuilder { rects: Vec::new() })
|
Box::new(BspDungeonBuilder { rects: Vec::new() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let mut rooms: Vec<Rect> = Vec::new();
|
let mut rooms: Vec<Rect> = Vec::new();
|
||||||
self.rects.clear();
|
self.rects.clear();
|
||||||
|
|
||||||
@ -37,8 +36,8 @@ impl BspDungeonBuilder {
|
|||||||
// a room in there, we place it and add it to the rooms list.
|
// a room in there, we place it and add it to the rooms list.
|
||||||
let mut n_rooms = 0;
|
let mut n_rooms = 0;
|
||||||
while n_rooms < 240 {
|
while n_rooms < 240 {
|
||||||
let rect = self.get_random_rect(rng);
|
let rect = self.get_random_rect();
|
||||||
let candidate = self.get_random_sub_rect(rect, rng);
|
let candidate = self.get_random_sub_rect(rect);
|
||||||
|
|
||||||
if self.is_possible(candidate, build_data, &rooms) {
|
if self.is_possible(candidate, build_data, &rooms) {
|
||||||
rooms.push(candidate);
|
rooms.push(candidate);
|
||||||
@ -79,25 +78,25 @@ impl BspDungeonBuilder {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_random_rect(&mut self, rng: &mut RandomNumberGenerator) -> Rect {
|
fn get_random_rect(&mut self) -> Rect {
|
||||||
if self.rects.len() == 1 {
|
if self.rects.len() == 1 {
|
||||||
return self.rects[0];
|
return self.rects[0];
|
||||||
}
|
}
|
||||||
let idx = (rng.roll_dice(1, self.rects.len() as i32) - 1) as usize;
|
let idx = (roll_dice(1, self.rects.len() as i32) - 1) as usize;
|
||||||
|
|
||||||
self.rects[idx]
|
self.rects[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_random_sub_rect(&self, rect: Rect, rng: &mut RandomNumberGenerator) -> Rect {
|
fn get_random_sub_rect(&self, rect: Rect) -> Rect {
|
||||||
let mut result = rect;
|
let mut result = rect;
|
||||||
let rect_width = i32::abs(rect.x1 - rect.x2);
|
let rect_width = i32::abs(rect.x1 - rect.x2);
|
||||||
let rect_height = i32::abs(rect.y1 - rect.y2);
|
let rect_height = i32::abs(rect.y1 - rect.y2);
|
||||||
|
|
||||||
let w = i32::max(3, rng.roll_dice(1, i32::min(rect_width, 10)) - 1) + 1;
|
let w = i32::max(3, roll_dice(1, i32::min(rect_width, 10)) - 1) + 1;
|
||||||
let h = i32::max(3, rng.roll_dice(1, i32::min(rect_height, 10)) - 1) + 1;
|
let h = i32::max(3, roll_dice(1, i32::min(rect_height, 10)) - 1) + 1;
|
||||||
|
|
||||||
result.x1 += rng.roll_dice(1, 6) - 1;
|
result.x1 += roll_dice(1, 6) - 1;
|
||||||
result.y1 += rng.roll_dice(1, 6) - 1;
|
result.y1 += roll_dice(1, 6) - 1;
|
||||||
result.x2 = result.x1 + w;
|
result.x2 = result.x1 + w;
|
||||||
result.y2 = result.y1 + h;
|
result.y2 = result.y1 + h;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::common::draw_corridor;
|
use crate::map_builders::common::draw_corridor;
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
const MIN_ROOM_SIZE: i32 = 8;
|
const MIN_ROOM_SIZE: i32 = 8;
|
||||||
@ -12,8 +11,8 @@ pub struct BspInteriorBuilder {
|
|||||||
|
|
||||||
impl InitialMapBuilder for BspInteriorBuilder {
|
impl InitialMapBuilder for BspInteriorBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ impl BspInteriorBuilder {
|
|||||||
Box::new(BspInteriorBuilder { rects: Vec::new() })
|
Box::new(BspInteriorBuilder { rects: Vec::new() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let mut rooms: Vec<Rect> = Vec::new();
|
let mut rooms: Vec<Rect> = Vec::new();
|
||||||
self.rects.clear();
|
self.rects.clear();
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ impl BspInteriorBuilder {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let first_room = self.rects[0];
|
let first_room = self.rects[0];
|
||||||
self.add_subrects(first_room, rng); // Divide the first room
|
self.add_subrects(first_room); // Divide the first room
|
||||||
|
|
||||||
let rooms_copy = self.rects.clone();
|
let rooms_copy = self.rects.clone();
|
||||||
for r in rooms_copy.iter() {
|
for r in rooms_copy.iter() {
|
||||||
@ -60,12 +59,10 @@ impl BspInteriorBuilder {
|
|||||||
for i in 0..rooms.len() - 1 {
|
for i in 0..rooms.len() - 1 {
|
||||||
let room = rooms[i];
|
let room = rooms[i];
|
||||||
let next_room = rooms[i + 1];
|
let next_room = rooms[i + 1];
|
||||||
let start_x = room.x1 + (rng.roll_dice(1, i32::abs(room.x1 - room.x2)) - 1);
|
let start_x = room.x1 + (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 start_y = room.y1 + (roll_dice(1, i32::abs(room.y1 - room.y2) - 1));
|
||||||
let end_x =
|
let end_x = next_room.x1 + (roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
||||||
next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
let end_y = next_room.y1 + (roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
||||||
let end_y =
|
|
||||||
next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
|
||||||
|
|
||||||
draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
@ -74,7 +71,7 @@ impl BspInteriorBuilder {
|
|||||||
build_data.rooms = Some(rooms);
|
build_data.rooms = Some(rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_subrects(&mut self, rect: Rect, rng: &mut RandomNumberGenerator) {
|
fn add_subrects(&mut self, rect: Rect) {
|
||||||
// Remove the last rect from the list
|
// Remove the last rect from the list
|
||||||
if !self.rects.is_empty() {
|
if !self.rects.is_empty() {
|
||||||
self.rects.remove(self.rects.len() - 1);
|
self.rects.remove(self.rects.len() - 1);
|
||||||
@ -86,33 +83,33 @@ impl BspInteriorBuilder {
|
|||||||
let half_width = width / 2;
|
let half_width = width / 2;
|
||||||
let half_height = height / 2;
|
let half_height = height / 2;
|
||||||
|
|
||||||
let split = rng.roll_dice(1, 4);
|
let split = roll_dice(1, 4);
|
||||||
|
|
||||||
if split <= 2 {
|
if split <= 2 {
|
||||||
// Horizontal split
|
// Horizontal split
|
||||||
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);
|
self.rects.push(h1);
|
||||||
if half_width > MIN_ROOM_SIZE {
|
if half_width > MIN_ROOM_SIZE {
|
||||||
self.add_subrects(h1, rng);
|
self.add_subrects(h1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let h2 = Rect::new(rect.x1 + half_width, rect.y1, half_width, height);
|
let h2 = Rect::new(rect.x1 + half_width, rect.y1, half_width, height);
|
||||||
self.rects.push(h2);
|
self.rects.push(h2);
|
||||||
if half_width > MIN_ROOM_SIZE {
|
if half_width > MIN_ROOM_SIZE {
|
||||||
self.add_subrects(h2, rng);
|
self.add_subrects(h2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Vertical split
|
// Vertical split
|
||||||
let v1 = Rect::new(rect.x1, rect.y1, width, half_height - 1);
|
let v1 = Rect::new(rect.x1, rect.y1, width, half_height - 1);
|
||||||
self.rects.push(v1);
|
self.rects.push(v1);
|
||||||
if half_height > MIN_ROOM_SIZE {
|
if half_height > MIN_ROOM_SIZE {
|
||||||
self.add_subrects(v1, rng);
|
self.add_subrects(v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
self.rects.push(v2);
|
||||||
if half_height > MIN_ROOM_SIZE {
|
if half_height > MIN_ROOM_SIZE {
|
||||||
self.add_subrects(v2, rng);
|
self.add_subrects(v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
pub struct CellularAutomataBuilder {}
|
pub struct CellularAutomataBuilder {}
|
||||||
|
|
||||||
impl InitialMapBuilder for CellularAutomataBuilder {
|
impl InitialMapBuilder for CellularAutomataBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for CellularAutomataBuilder {
|
impl MetaMapBuilder for CellularAutomataBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.apply_iteration(build_data);
|
self.apply_iteration(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,11 +72,11 @@ impl CellularAutomataBuilder {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
// First we completely randomize the map, setting 55% of it to be floor.
|
// First we completely randomize the map, setting 55% of it to be floor.
|
||||||
for y in 1..build_data.map.height - 1 {
|
for y in 1..build_data.map.height - 1 {
|
||||||
for x in 1..build_data.map.width - 1 {
|
for x in 1..build_data.map.width - 1 {
|
||||||
let roll = rng.roll_dice(1, 100);
|
let roll = roll_dice(1, 100);
|
||||||
let idx = build_data.map.xy_idx(x, y);
|
let idx = build_data.map.xy_idx(x, y);
|
||||||
|
|
||||||
if roll > 55 {
|
if roll > 55 {
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
pub struct CullUnreachable {}
|
pub struct CullUnreachable {}
|
||||||
|
|
||||||
impl MetaMapBuilder for CullUnreachable {
|
impl MetaMapBuilder for CullUnreachable {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +15,7 @@ impl CullUnreachable {
|
|||||||
Box::new(CullUnreachable {})
|
Box::new(CullUnreachable {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
||||||
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
pub struct DistantExit {}
|
pub struct DistantExit {}
|
||||||
|
|
||||||
impl MetaMapBuilder for DistantExit {
|
impl MetaMapBuilder for DistantExit {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +15,7 @@ impl DistantExit {
|
|||||||
Box::new(DistantExit {})
|
Box::new(DistantExit {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
||||||
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::common::{paint, Symmetry};
|
use super::common::{paint, Symmetry};
|
||||||
use crate::components::Position;
|
use crate::components::Position;
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
@ -20,14 +19,14 @@ pub struct DLABuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InitialMapBuilder for DLABuilder {
|
impl InitialMapBuilder for DLABuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for DLABuilder {
|
impl MetaMapBuilder for DLABuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ impl DLABuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let starting_position = Position {
|
let starting_position = Position {
|
||||||
x: build_data.map.width / 2,
|
x: build_data.map.width / 2,
|
||||||
y: build_data.map.height / 2,
|
y: build_data.map.height / 2,
|
||||||
@ -113,8 +112,8 @@ impl DLABuilder {
|
|||||||
while floor_tile_count < desired_floor_tiles {
|
while floor_tile_count < desired_floor_tiles {
|
||||||
match self.algorithm {
|
match self.algorithm {
|
||||||
DLAAlgorithm::WalkInwards => {
|
DLAAlgorithm::WalkInwards => {
|
||||||
let mut digger_x = rng.roll_dice(1, build_data.map.width - 3) + 1;
|
let mut digger_x = roll_dice(1, build_data.map.width - 3) + 1;
|
||||||
let mut digger_y = rng.roll_dice(1, build_data.map.height - 3) + 1;
|
let mut digger_y = roll_dice(1, build_data.map.height - 3) + 1;
|
||||||
let mut prev_x = digger_x;
|
let mut prev_x = digger_x;
|
||||||
let mut prev_y = digger_y;
|
let mut prev_y = digger_y;
|
||||||
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
||||||
@ -123,7 +122,7 @@ impl DLABuilder {
|
|||||||
prev_x = digger_x;
|
prev_x = digger_x;
|
||||||
prev_y = digger_y;
|
prev_y = digger_y;
|
||||||
|
|
||||||
let stagger_direction = rng.roll_dice(1, 4);
|
let stagger_direction = roll_dice(1, 4);
|
||||||
match stagger_direction {
|
match stagger_direction {
|
||||||
1 => {
|
1 => {
|
||||||
if digger_x > 2 {
|
if digger_x > 2 {
|
||||||
@ -165,7 +164,7 @@ impl DLABuilder {
|
|||||||
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
||||||
|
|
||||||
while build_data.map.tiles[digger_idx] == TileType::Floor {
|
while build_data.map.tiles[digger_idx] == TileType::Floor {
|
||||||
let stagger_direction = rng.roll_dice(1, 4);
|
let stagger_direction = roll_dice(1, 4);
|
||||||
match stagger_direction {
|
match stagger_direction {
|
||||||
1 => {
|
1 => {
|
||||||
if digger_x > 2 {
|
if digger_x > 2 {
|
||||||
@ -202,8 +201,8 @@ impl DLABuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DLAAlgorithm::CentralAttractor => {
|
DLAAlgorithm::CentralAttractor => {
|
||||||
let mut digger_x = rng.roll_dice(1, build_data.map.width - 3) + 1;
|
let mut digger_x = roll_dice(1, build_data.map.width - 3) + 1;
|
||||||
let mut digger_y = rng.roll_dice(1, build_data.map.height - 3) + 1;
|
let mut digger_y = roll_dice(1, build_data.map.height - 3) + 1;
|
||||||
let mut prev_x = digger_x;
|
let mut prev_x = digger_x;
|
||||||
let mut prev_y = digger_y;
|
let mut prev_y = digger_y;
|
||||||
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
pub struct DoorPlacement {}
|
pub struct DoorPlacement {}
|
||||||
|
|
||||||
impl MetaMapBuilder for DoorPlacement {
|
impl MetaMapBuilder for DoorPlacement {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.doors(rng, build_data);
|
self.doors(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ impl DoorPlacement {
|
|||||||
Box::new(DoorPlacement {})
|
Box::new(DoorPlacement {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doors(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn doors(&mut self, build_data: &mut BuilderMap) {
|
||||||
if let Some(halls_original) = &build_data.corridors {
|
if let Some(halls_original) = &build_data.corridors {
|
||||||
let halls = halls_original.clone();
|
let halls = halls_original.clone();
|
||||||
for hall in halls.iter() {
|
for hall in halls.iter() {
|
||||||
@ -33,7 +32,7 @@ impl DoorPlacement {
|
|||||||
for (i, tile) in tiles.iter().enumerate() {
|
for (i, tile) in tiles.iter().enumerate() {
|
||||||
if *tile == TileType::Floor
|
if *tile == TileType::Floor
|
||||||
&& self.door_possible(build_data, i)
|
&& self.door_possible(build_data, i)
|
||||||
&& rng.roll_dice(1, 3) == 1
|
&& roll_dice(1, 3) == 1
|
||||||
{
|
{
|
||||||
build_data.spawn_list.push((i, "Door".to_string()));
|
build_data.spawn_list.push((i, "Door".to_string()));
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::common::{paint, Symmetry};
|
use super::common::{paint, Symmetry};
|
||||||
use crate::components::Position;
|
use crate::components::Position;
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
@ -24,15 +23,15 @@ pub struct DrunkardsWalkBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InitialMapBuilder for DrunkardsWalkBuilder {
|
impl InitialMapBuilder for DrunkardsWalkBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for DrunkardsWalkBuilder {
|
impl MetaMapBuilder for DrunkardsWalkBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ impl DrunkardsWalkBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
// Set a central starting point
|
// Set a central starting point
|
||||||
let starting_position = Position {
|
let starting_position = Position {
|
||||||
x: build_data.map.width / 2,
|
x: build_data.map.width / 2,
|
||||||
@ -127,8 +126,8 @@ impl DrunkardsWalkBuilder {
|
|||||||
drunk_x = starting_position.x;
|
drunk_x = starting_position.x;
|
||||||
drunk_y = starting_position.y;
|
drunk_y = starting_position.y;
|
||||||
} else {
|
} else {
|
||||||
drunk_x = rng.roll_dice(1, build_data.map.width - 3) + 1;
|
drunk_x = roll_dice(1, build_data.map.width - 3) + 1;
|
||||||
drunk_y = rng.roll_dice(1, build_data.map.height - 3) + 1;
|
drunk_y = roll_dice(1, build_data.map.height - 3) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +149,7 @@ impl DrunkardsWalkBuilder {
|
|||||||
);
|
);
|
||||||
build_data.map.tiles[drunk_idx] = TileType::DownStairs;
|
build_data.map.tiles[drunk_idx] = TileType::DownStairs;
|
||||||
|
|
||||||
let stagger_direction = rng.roll_dice(1, 4);
|
let stagger_direction = roll_dice(1, 4);
|
||||||
match stagger_direction {
|
match stagger_direction {
|
||||||
1 => {
|
1 => {
|
||||||
if drunk_x > 2 {
|
if drunk_x > 2 {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ::rltk::{DistanceAlg, Point, RandomNumberGenerator};
|
use ::rltk::{DistanceAlg, Point};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
AreaEndingPosition, AreaStartingPosition, BspCorridors, BspDungeonBuilder, BuilderChain,
|
AreaEndingPosition, AreaStartingPosition, BspCorridors, BspDungeonBuilder, BuilderChain,
|
||||||
@ -7,12 +7,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{tile_walkable, TileType};
|
use crate::{tile_walkable, TileType};
|
||||||
|
|
||||||
pub fn dwarf_fort_builder(
|
pub fn dwarf_fort_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Dwarven Fortress");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Dwarven Fortress");
|
||||||
chain
|
chain
|
||||||
.start_with(BspDungeonBuilder::new())
|
.start_with(BspDungeonBuilder::new())
|
||||||
@ -34,8 +29,8 @@ pub fn dwarf_fort_builder(
|
|||||||
pub struct DragonsLair {}
|
pub struct DragonsLair {}
|
||||||
|
|
||||||
impl MetaMapBuilder for DragonsLair {
|
impl MetaMapBuilder for DragonsLair {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +40,13 @@ impl DragonsLair {
|
|||||||
Box::new(DragonsLair {})
|
Box::new(DragonsLair {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
build_data.map.depth = 7;
|
build_data.map.depth = 7;
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
||||||
let mut builder = BuilderChain::new(6, build_data.width, build_data.height, "New Map");
|
let mut builder = BuilderChain::new(6, build_data.width, build_data.height, "New Map");
|
||||||
builder.start_with(DLABuilder::insectoid());
|
builder.start_with(DLABuilder::insectoid());
|
||||||
builder.build_map(rng);
|
builder.build_map();
|
||||||
|
|
||||||
// Add the history to our history
|
// Add the history to our history
|
||||||
for h in builder.build_data.history.iter() {
|
for h in builder.build_data.history.iter() {
|
||||||
@ -72,8 +67,8 @@ impl DragonsLair {
|
|||||||
pub struct DragonSpawner {}
|
pub struct DragonSpawner {}
|
||||||
|
|
||||||
impl MetaMapBuilder for DragonSpawner {
|
impl MetaMapBuilder for DragonSpawner {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +78,7 @@ impl DragonSpawner {
|
|||||||
Box::new(DragonSpawner {})
|
Box::new(DragonSpawner {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
// Find a central location that isn't occupied
|
// Find a central location that isn't occupied
|
||||||
let seed_x = build_data.map.width / 2;
|
let seed_x = build_data.map.width / 2;
|
||||||
let seed_y = build_data.map.height / 2;
|
let seed_y = build_data.map.height / 2;
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
AreaStartingPosition, BuilderChain, CellularAutomataBuilder, CullUnreachable, MetaMapBuilder,
|
AreaStartingPosition, BuilderChain, CellularAutomataBuilder, CullUnreachable, MetaMapBuilder,
|
||||||
VoronoiSpawning, XStart, YStart,
|
VoronoiSpawning, XStart, YStart,
|
||||||
};
|
};
|
||||||
use crate::map_builders::BuilderMap;
|
use crate::map_builders::BuilderMap;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{map, TileType};
|
use crate::{map, TileType};
|
||||||
|
|
||||||
pub fn forest_builder(
|
pub fn forest_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Woods");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Woods");
|
||||||
|
|
||||||
chain
|
chain
|
||||||
@ -29,8 +23,8 @@ pub fn forest_builder(
|
|||||||
pub struct YellowBrickRoad {}
|
pub struct YellowBrickRoad {}
|
||||||
|
|
||||||
impl MetaMapBuilder for YellowBrickRoad {
|
impl MetaMapBuilder for YellowBrickRoad {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +74,7 @@ impl YellowBrickRoad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
let starting_pos = *build_data.starting_position.as_ref().unwrap();
|
||||||
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
let start_idx = build_data.map.xy_idx(starting_pos.x, starting_pos.y);
|
||||||
|
|
||||||
@ -107,7 +101,7 @@ impl YellowBrickRoad {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
||||||
// Place exit
|
// Place exit
|
||||||
let exit_dir = rng.roll_dice(1, 2);
|
let exit_dir = roll_dice(1, 2);
|
||||||
let (seed_x, seed_y, stream_startx, stream_starty) = if exit_dir == 1 {
|
let (seed_x, seed_y, stream_startx, stream_starty) = if exit_dir == 1 {
|
||||||
(build_data.map.width - 1, 1, 0, build_data.height - 1)
|
(build_data.map.width - 1, 1, 0, build_data.height - 1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::prefab_builder::prefab_sections;
|
use super::prefab_builder::prefab_sections;
|
||||||
use super::{
|
use super::{
|
||||||
AreaEndingPosition, AreaStartingPosition, BspDungeonBuilder, BuilderChain, BuilderMap,
|
AreaEndingPosition, AreaStartingPosition, BspDungeonBuilder, BuilderChain, BuilderMap,
|
||||||
@ -8,13 +6,9 @@ use super::{
|
|||||||
RoomSort, RoomSorter, VoronoiSpawning, XEnd, XStart, YEnd, YStart,
|
RoomSort, RoomSorter, VoronoiSpawning, XEnd, XStart, YEnd, YStart,
|
||||||
};
|
};
|
||||||
use crate::map::TileType;
|
use crate::map::TileType;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
|
|
||||||
pub fn limestone_cavern_builder(
|
pub fn limestone_cavern_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Limestone Caverns");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Limestone Caverns");
|
||||||
chain
|
chain
|
||||||
.start_with(DrunkardsWalkBuilder::winding_passages())
|
.start_with(DrunkardsWalkBuilder::winding_passages())
|
||||||
@ -28,12 +22,7 @@ pub fn limestone_cavern_builder(
|
|||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn limestone_deep_cavern_builder(
|
pub fn limestone_deep_cavern_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Deep Limestone Caverns");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Deep Limestone Caverns");
|
||||||
chain
|
chain
|
||||||
.start_with(DLABuilder::central_attractor())
|
.start_with(DLABuilder::central_attractor())
|
||||||
@ -46,12 +35,7 @@ pub fn limestone_deep_cavern_builder(
|
|||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn limestone_transition_builder(
|
pub fn limestone_transition_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Dwarf Fort - Upper Reaches");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Dwarf Fort - Upper Reaches");
|
||||||
chain
|
chain
|
||||||
.start_with(CellularAutomataBuilder::new())
|
.start_with(CellularAutomataBuilder::new())
|
||||||
@ -71,8 +55,8 @@ pub fn limestone_transition_builder(
|
|||||||
pub struct CaveDecorator {}
|
pub struct CaveDecorator {}
|
||||||
|
|
||||||
impl MetaMapBuilder for CaveDecorator {
|
impl MetaMapBuilder for CaveDecorator {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,13 +66,13 @@ impl CaveDecorator {
|
|||||||
Box::new(CaveDecorator {})
|
Box::new(CaveDecorator {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let old_map = build_data.map.clone();
|
let old_map = build_data.map.clone();
|
||||||
for (idx, tt) in build_data.map.tiles.iter_mut().enumerate() {
|
for (idx, tt) in build_data.map.tiles.iter_mut().enumerate() {
|
||||||
// Gravel Spawning
|
// Gravel Spawning
|
||||||
if *tt == TileType::Floor && rng.roll_dice(1, 6) == 1 {
|
if *tt == TileType::Floor && roll_dice(1, 6) == 1 {
|
||||||
*tt = TileType::Gravel;
|
*tt = TileType::Gravel;
|
||||||
} else if *tt == TileType::Floor && rng.roll_dice(1, 10) == 1 {
|
} else if *tt == TileType::Floor && roll_dice(1, 10) == 1 {
|
||||||
// Spawn passable pools
|
// Spawn passable pools
|
||||||
*tt = TileType::ShallowWater;
|
*tt = TileType::ShallowWater;
|
||||||
} else if *tt == TileType::Wall {
|
} else if *tt == TileType::Wall {
|
||||||
@ -115,7 +99,7 @@ impl CaveDecorator {
|
|||||||
if neighbors == 2 {
|
if neighbors == 2 {
|
||||||
*tt = TileType::DeepWater;
|
*tt = TileType::DeepWater;
|
||||||
} else if neighbors == 1 {
|
} else if neighbors == 1 {
|
||||||
*tt = match rng.roll_dice(1, 4) {
|
*tt = match roll_dice(1, 4) {
|
||||||
1 => TileType::Stalactite,
|
1 => TileType::Stalactite,
|
||||||
2 => TileType::Stalagmite,
|
2 => TileType::Stalagmite,
|
||||||
_ => *tt,
|
_ => *tt,
|
||||||
@ -132,8 +116,8 @@ impl CaveDecorator {
|
|||||||
pub struct CaveTransition {}
|
pub struct CaveTransition {}
|
||||||
|
|
||||||
impl MetaMapBuilder for CaveTransition {
|
impl MetaMapBuilder for CaveTransition {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +127,7 @@ impl CaveTransition {
|
|||||||
Box::new(CaveTransition {})
|
Box::new(CaveTransition {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
build_data.map.depth = 5;
|
build_data.map.depth = 5;
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
||||||
@ -156,7 +140,7 @@ impl CaveTransition {
|
|||||||
.with(NearestCorridors::new())
|
.with(NearestCorridors::new())
|
||||||
.with(RoomExploder::new())
|
.with(RoomExploder::new())
|
||||||
.with(RoomBasedSpawner::new());
|
.with(RoomBasedSpawner::new());
|
||||||
builder.build_map(rng);
|
builder.build_map();
|
||||||
|
|
||||||
// Add the history to our history
|
// Add the history to our history
|
||||||
for h in builder.build_data.history.iter() {
|
for h in builder.build_data.history.iter() {
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Map, TileType};
|
use crate::{Map, TileType};
|
||||||
|
|
||||||
pub struct MazeBuilder {}
|
pub struct MazeBuilder {}
|
||||||
|
|
||||||
impl InitialMapBuilder for MazeBuilder {
|
impl InitialMapBuilder for MazeBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,12 +18,11 @@ impl MazeBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
// Maze gen
|
// Maze gen
|
||||||
let mut maze = Grid::new(
|
let mut maze = Grid::new(
|
||||||
(build_data.map.width / 2) - 2,
|
(build_data.map.width / 2) - 2,
|
||||||
(build_data.map.height / 2) - 2,
|
(build_data.map.height / 2) - 2,
|
||||||
rng,
|
|
||||||
);
|
);
|
||||||
maze.generate_maze(build_data);
|
maze.generate_maze(build_data);
|
||||||
}
|
}
|
||||||
@ -73,24 +71,22 @@ impl Cell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Grid<'a> {
|
struct Grid {
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
cells: Vec<Cell>,
|
cells: Vec<Cell>,
|
||||||
backtrace: Vec<usize>,
|
backtrace: Vec<usize>,
|
||||||
current: usize,
|
current: usize,
|
||||||
rng: &'a mut RandomNumberGenerator,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Grid<'a> {
|
impl Grid {
|
||||||
fn new(width: i32, height: i32, rng: &mut RandomNumberGenerator) -> Grid {
|
fn new(width: i32, height: i32) -> Grid {
|
||||||
let mut grid = Grid {
|
let mut grid = Grid {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
cells: Vec::new(),
|
cells: Vec::new(),
|
||||||
backtrace: Vec::new(),
|
backtrace: Vec::new(),
|
||||||
current: 0,
|
current: 0,
|
||||||
rng,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for row in 0..height {
|
for row in 0..height {
|
||||||
@ -138,7 +134,7 @@ impl<'a> Grid<'a> {
|
|||||||
return if neighbors.len() == 1 {
|
return if neighbors.len() == 1 {
|
||||||
Some(neighbors[0])
|
Some(neighbors[0])
|
||||||
} else {
|
} else {
|
||||||
Some(neighbors[(self.rng.roll_dice(1, neighbors.len() as i32) - 1) as usize])
|
Some(neighbors[(roll_dice(1, neighbors.len() as i32) - 1) as usize])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,7 @@ use super::{
|
|||||||
YStart,
|
YStart,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn mushroom_entrance(
|
pub fn mushroom_entrance(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut ::rltk::RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Mushroom Grove");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Mushroom Grove");
|
||||||
chain
|
chain
|
||||||
.start_with(CellularAutomataBuilder::new())
|
.start_with(CellularAutomataBuilder::new())
|
||||||
@ -25,12 +20,7 @@ pub fn mushroom_entrance(
|
|||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mushroom_builder(
|
pub fn mushroom_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut ::rltk::RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Mushroom Grove");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Into the Mushroom Grove");
|
||||||
chain
|
chain
|
||||||
.start_with(CellularAutomataBuilder::new())
|
.start_with(CellularAutomataBuilder::new())
|
||||||
@ -44,12 +34,7 @@ pub fn mushroom_builder(
|
|||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mushroom_exit(
|
pub fn mushroom_exit(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut rltk::RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "Into The Mushroom Grove");
|
let mut chain = BuilderChain::new(new_depth, width, height, "Into The Mushroom Grove");
|
||||||
chain
|
chain
|
||||||
.start_with(CellularAutomataBuilder::new())
|
.start_with(CellularAutomataBuilder::new())
|
||||||
|
@ -4,9 +4,8 @@ pub mod prefab_sections;
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Position, TileType};
|
use crate::{Position, TileType};
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
@ -30,14 +29,14 @@ pub struct PrefabBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaMapBuilder for PrefabBuilder {
|
impl MetaMapBuilder for PrefabBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InitialMapBuilder for PrefabBuilder {
|
impl InitialMapBuilder for PrefabBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +76,12 @@ impl PrefabBuilder {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
PrefabMode::RexLevel { template } => self.load_rex_map(template, build_data),
|
PrefabMode::RexLevel { template } => self.load_rex_map(template, build_data),
|
||||||
PrefabMode::Constant { level } => self.load_ascii_map(&level, build_data),
|
PrefabMode::Constant { level } => self.load_ascii_map(&level, build_data),
|
||||||
PrefabMode::Sectional { section } => self.apply_sectional(§ion, rng, build_data),
|
PrefabMode::Sectional { section } => self.apply_sectional(§ion, build_data),
|
||||||
PrefabMode::RoomVaults => self.apply_room_vaults(rng, build_data),
|
PrefabMode::RoomVaults => self.apply_room_vaults(build_data),
|
||||||
}
|
}
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
@ -189,12 +188,8 @@ impl PrefabBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_previous_iteration<F>(
|
fn apply_previous_iteration<F>(&mut self, mut filter: F, build_data: &mut BuilderMap)
|
||||||
&mut self,
|
where
|
||||||
mut filter: F,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
) where
|
|
||||||
F: FnMut(i32, i32) -> bool,
|
F: FnMut(i32, i32) -> bool,
|
||||||
{
|
{
|
||||||
let width = build_data.map.width;
|
let width = build_data.map.width;
|
||||||
@ -211,7 +206,7 @@ impl PrefabBuilder {
|
|||||||
fn apply_sectional(
|
fn apply_sectional(
|
||||||
&mut self,
|
&mut self,
|
||||||
section: &prefab_sections::PrefabSection,
|
section: &prefab_sections::PrefabSection,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
) {
|
) {
|
||||||
use prefab_sections::*;
|
use prefab_sections::*;
|
||||||
@ -239,7 +234,6 @@ impl PrefabBuilder {
|
|||||||
|| y < chunk_y
|
|| y < chunk_y
|
||||||
|| y > (chunk_y + section.height as i32)
|
|| y > (chunk_y + section.height as i32)
|
||||||
},
|
},
|
||||||
rng,
|
|
||||||
build_data,
|
build_data,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -262,14 +256,14 @@ impl PrefabBuilder {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_room_vaults(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn apply_room_vaults(&mut self, build_data: &mut BuilderMap) {
|
||||||
use prefab_rooms::*;
|
use prefab_rooms::*;
|
||||||
|
|
||||||
// Apply the previous builder, and keep all entities it spawns (for now)
|
// Apply the previous builder, and keep all entities it spawns (for now)
|
||||||
self.apply_previous_iteration(|_x, _y| true, rng, build_data);
|
self.apply_previous_iteration(|_x, _y| true, build_data);
|
||||||
|
|
||||||
// Do we want a vault at all?
|
// Do we want a vault at all?
|
||||||
let vault_roll = rng.roll_dice(1, 6) + build_data.map.depth;
|
let vault_roll = roll_dice(1, 6) + build_data.map.depth;
|
||||||
if vault_roll < 4 {
|
if vault_roll < 4 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -290,14 +284,14 @@ impl PrefabBuilder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let n_vaults = i32::min(rng.roll_dice(1, 3), possible_vaults.len() as i32);
|
let n_vaults = i32::min(roll_dice(1, 3), possible_vaults.len() as i32);
|
||||||
let mut used_tiles: HashSet<usize> = HashSet::new();
|
let mut used_tiles: HashSet<usize> = HashSet::new();
|
||||||
|
|
||||||
for _i in 0..n_vaults {
|
for _i in 0..n_vaults {
|
||||||
let vault_index = if possible_vaults.len() == 1 {
|
let vault_index = if possible_vaults.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
(rng.roll_dice(1, possible_vaults.len() as i32) - 1) as usize
|
(roll_dice(1, possible_vaults.len() as i32) - 1) as usize
|
||||||
};
|
};
|
||||||
let vault = possible_vaults[vault_index];
|
let vault = possible_vaults[vault_index];
|
||||||
|
|
||||||
@ -344,7 +338,7 @@ impl PrefabBuilder {
|
|||||||
let pos_idx = if vault_positions.len() == 1 {
|
let pos_idx = if vault_positions.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
(rng.roll_dice(1, vault_positions.len() as i32) - 1) as usize
|
(roll_dice(1, vault_positions.len() as i32) - 1) as usize
|
||||||
};
|
};
|
||||||
let pos = &vault_positions[pos_idx];
|
let pos = &vault_positions[pos_idx];
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{spawner, BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{spawner, BuilderMap, MetaMapBuilder};
|
||||||
|
|
||||||
pub struct RoomBasedSpawner {}
|
pub struct RoomBasedSpawner {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomBasedSpawner {
|
impl MetaMapBuilder for RoomBasedSpawner {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,12 +14,11 @@ impl RoomBasedSpawner {
|
|||||||
Box::new(RoomBasedSpawner {})
|
Box::new(RoomBasedSpawner {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
if let Some(rooms) = &build_data.rooms {
|
if let Some(rooms) = &build_data.rooms {
|
||||||
for room in rooms.iter().skip(1) {
|
for room in rooms.iter().skip(1) {
|
||||||
spawner::spawn_room(
|
spawner::spawn_room(
|
||||||
&build_data.map,
|
&build_data.map,
|
||||||
rng,
|
|
||||||
room,
|
room,
|
||||||
build_data.map.depth,
|
build_data.map.depth,
|
||||||
&mut build_data.spawn_list,
|
&mut build_data.spawn_list,
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
pub struct RoomBasedStairs {}
|
pub struct RoomBasedStairs {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomBasedStairs {
|
impl MetaMapBuilder for RoomBasedStairs {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +15,7 @@ impl RoomBasedStairs {
|
|||||||
Box::new(RoomBasedStairs {})
|
Box::new(RoomBasedStairs {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
if let Some(rooms) = &build_data.rooms {
|
if let Some(rooms) = &build_data.rooms {
|
||||||
let stairs_position = rooms[rooms.len() - 1].center();
|
let stairs_position = rooms[rooms.len() - 1].center();
|
||||||
let stairs_idx = build_data.map.xy_idx(stairs_position.0, stairs_position.1);
|
let stairs_idx = build_data.map.xy_idx(stairs_position.0, stairs_position.1);
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::Position;
|
use crate::Position;
|
||||||
|
|
||||||
pub struct RoomBasedStartingPosition {}
|
pub struct RoomBasedStartingPosition {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomBasedStartingPosition {
|
impl MetaMapBuilder for RoomBasedStartingPosition {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +15,7 @@ impl RoomBasedStartingPosition {
|
|||||||
Box::new(RoomBasedStartingPosition {})
|
Box::new(RoomBasedStartingPosition {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
if let Some(rooms) = &build_data.rooms {
|
if let Some(rooms) = &build_data.rooms {
|
||||||
let start_pos = rooms[0].center();
|
let start_pos = rooms[0].center();
|
||||||
build_data.starting_position = Some(Position {
|
build_data.starting_position = Some(Position {
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
pub struct RoomCornerRounder {}
|
pub struct RoomCornerRounder {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomCornerRounder {
|
impl MetaMapBuilder for RoomCornerRounder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ impl RoomCornerRounder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::spawner;
|
use crate::spawner;
|
||||||
|
|
||||||
pub struct CorridorSpawner {}
|
pub struct CorridorSpawner {}
|
||||||
|
|
||||||
impl MetaMapBuilder for CorridorSpawner {
|
impl MetaMapBuilder for CorridorSpawner {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,11 +15,11 @@ impl CorridorSpawner {
|
|||||||
Box::new(CorridorSpawner {})
|
Box::new(CorridorSpawner {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
if let Some(corridors) = &build_data.corridors {
|
if let Some(corridors) = &build_data.corridors {
|
||||||
for c in corridors.iter() {
|
for c in corridors.iter() {
|
||||||
let depth = build_data.map.depth;
|
let depth = build_data.map.depth;
|
||||||
spawner::spawn_region(&build_data.map, rng, c, depth, &mut build_data.spawn_list);
|
spawner::spawn_region(&build_data.map, c, depth, &mut build_data.spawn_list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("Corridor Based Spawning only works after corridors have been created.");
|
panic!("Corridor Based Spawning only works after corridors have been created.");
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
pub struct RoomDrawer {}
|
pub struct RoomDrawer {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomDrawer {
|
impl MetaMapBuilder for RoomDrawer {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ impl RoomDrawer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
@ -59,7 +58,7 @@ impl RoomDrawer {
|
|||||||
|
|
||||||
for room in rooms.iter() {
|
for room in rooms.iter() {
|
||||||
// Choose which shape of room to render
|
// Choose which shape of room to render
|
||||||
match rng.roll_dice(1, 4) {
|
match roll_dice(1, 4) {
|
||||||
1 => self.circle(build_data, room),
|
1 => self.circle(build_data, room),
|
||||||
_ => self.rectangle(build_data, room),
|
_ => self.rectangle(build_data, room),
|
||||||
};
|
};
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::common::{paint, Symmetry};
|
use crate::map_builders::common::{paint, Symmetry};
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
pub struct RoomExploder {}
|
pub struct RoomExploder {}
|
||||||
|
|
||||||
impl MetaMapBuilder for RoomExploder {
|
impl MetaMapBuilder for RoomExploder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ impl RoomExploder {
|
|||||||
Box::new(RoomExploder {})
|
Box::new(RoomExploder {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
@ -28,7 +27,7 @@ impl RoomExploder {
|
|||||||
|
|
||||||
for room in rooms.iter() {
|
for room in rooms.iter() {
|
||||||
let start = room.center();
|
let start = room.center();
|
||||||
let n_diggers = rng.roll_dice(1, 20) - 5;
|
let n_diggers = roll_dice(1, 20) - 5;
|
||||||
|
|
||||||
if n_diggers > 0 {
|
if n_diggers > 0 {
|
||||||
for _i in 0..n_diggers {
|
for _i in 0..n_diggers {
|
||||||
@ -47,7 +46,7 @@ impl RoomExploder {
|
|||||||
paint(&mut build_data.map, Symmetry::None, 1, drunk_x, drunk_y);
|
paint(&mut build_data.map, Symmetry::None, 1, drunk_x, drunk_y);
|
||||||
build_data.map.tiles[drunk_idx] = TileType::DownStairs;
|
build_data.map.tiles[drunk_idx] = TileType::DownStairs;
|
||||||
|
|
||||||
match rng.roll_dice(1, 4) {
|
match roll_dice(1, 4) {
|
||||||
1 => {
|
1 => {
|
||||||
if drunk_x > 2 {
|
if drunk_x > 2 {
|
||||||
drunk_x -= 1;
|
drunk_x -= 1;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
|
|
||||||
@ -17,8 +15,8 @@ pub struct RoomSorter {
|
|||||||
|
|
||||||
impl MetaMapBuilder for RoomSorter {
|
impl MetaMapBuilder for RoomSorter {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.sorter(rng, build_data);
|
self.sorter(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +26,7 @@ impl RoomSorter {
|
|||||||
Box::new(RoomSorter { sort_by })
|
Box::new(RoomSorter { sort_by })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sorter(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn sorter(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms = build_data.rooms.as_mut().unwrap();
|
let rooms = build_data.rooms.as_mut().unwrap();
|
||||||
|
|
||||||
match self.sort_by {
|
match self.sort_by {
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::common::draw_corridor;
|
use super::common::draw_corridor;
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
|
|
||||||
pub struct BspCorridors {}
|
pub struct BspCorridors {}
|
||||||
|
|
||||||
impl MetaMapBuilder for BspCorridors {
|
impl MetaMapBuilder for BspCorridors {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.corridors(rng, build_data);
|
self.corridors(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ impl BspCorridors {
|
|||||||
Box::new(BspCorridors {})
|
Box::new(BspCorridors {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn corridors(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn corridors(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
@ -31,12 +30,10 @@ impl BspCorridors {
|
|||||||
for i in 0..rooms.len() - 1 {
|
for i in 0..rooms.len() - 1 {
|
||||||
let room = rooms[i];
|
let room = rooms[i];
|
||||||
let next_room = rooms[i + 1];
|
let next_room = rooms[i + 1];
|
||||||
let start_x = room.x1 + (rng.roll_dice(1, i32::abs(room.x1 - room.x2)) - 1);
|
let start_x = room.x1 + (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 start_y = room.y1 + (roll_dice(1, i32::abs(room.y1 - room.y2)) - 1);
|
||||||
let end_x =
|
let end_x = next_room.x1 + (roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
||||||
next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1);
|
let end_y = next_room.y1 + (roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
||||||
let end_y =
|
|
||||||
next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1);
|
|
||||||
|
|
||||||
let corridor = draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
let corridor = draw_corridor(&mut build_data.map, start_x, start_y, end_x, end_y);
|
||||||
corridors.push(corridor);
|
corridors.push(corridor);
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::common::{apply_horizontal_tunnel, apply_vertical_tunnel};
|
use super::common::{apply_horizontal_tunnel, apply_vertical_tunnel};
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::range;
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
|
|
||||||
pub struct DoglegCorridors {}
|
pub struct DoglegCorridors {}
|
||||||
|
|
||||||
impl MetaMapBuilder for DoglegCorridors {
|
impl MetaMapBuilder for DoglegCorridors {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.corridors(rng, build_data);
|
self.corridors(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ impl DoglegCorridors {
|
|||||||
Box::new(DoglegCorridors {})
|
Box::new(DoglegCorridors {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn corridors(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn corridors(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
@ -33,7 +32,7 @@ impl DoglegCorridors {
|
|||||||
let (new_x, new_y) = room.center();
|
let (new_x, new_y) = room.center();
|
||||||
let (prev_x, prev_y) = rooms[i as usize - 1].center();
|
let (prev_x, prev_y) = rooms[i as usize - 1].center();
|
||||||
|
|
||||||
if rng.range(0, 2) == 1 {
|
if range(0, 2) == 1 {
|
||||||
let mut c1 =
|
let mut c1 =
|
||||||
apply_horizontal_tunnel(&mut build_data.map, prev_x, new_x, prev_y);
|
apply_horizontal_tunnel(&mut build_data.map, prev_x, new_x, prev_y);
|
||||||
let mut c2 = apply_vertical_tunnel(&mut build_data.map, prev_y, new_y, new_x);
|
let mut c2 = apply_vertical_tunnel(&mut build_data.map, prev_y, new_y, new_x);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::{Rect, TileType};
|
use crate::{Rect, TileType};
|
||||||
|
|
||||||
@ -9,8 +7,8 @@ pub struct StraightLineCorridors {}
|
|||||||
|
|
||||||
impl MetaMapBuilder for StraightLineCorridors {
|
impl MetaMapBuilder for StraightLineCorridors {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.corridors(rng, build_data);
|
self.corridors(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ impl StraightLineCorridors {
|
|||||||
Box::new(StraightLineCorridors {})
|
Box::new(StraightLineCorridors {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn corridors(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn corridors(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use super::common::draw_corridor;
|
use super::common::draw_corridor;
|
||||||
use super::{BuilderMap, MetaMapBuilder};
|
use super::{BuilderMap, MetaMapBuilder};
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
@ -10,8 +8,8 @@ pub struct NearestCorridors {}
|
|||||||
|
|
||||||
impl MetaMapBuilder for NearestCorridors {
|
impl MetaMapBuilder for NearestCorridors {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.corridors(rng, build_data);
|
self.corridors(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +19,7 @@ impl NearestCorridors {
|
|||||||
Box::new(NearestCorridors {})
|
Box::new(NearestCorridors {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn corridors(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn corridors(&mut self, build_data: &mut BuilderMap) {
|
||||||
let rooms: Vec<Rect>;
|
let rooms: Vec<Rect>;
|
||||||
if let Some(rooms_builder) = &build_data.rooms {
|
if let Some(rooms_builder) = &build_data.rooms {
|
||||||
rooms = rooms_builder.clone();
|
rooms = rooms_builder.clone();
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::{range, roll_dice};
|
||||||
use crate::Rect;
|
use crate::Rect;
|
||||||
|
|
||||||
pub struct SimpleMapBuilder {}
|
pub struct SimpleMapBuilder {}
|
||||||
|
|
||||||
impl InitialMapBuilder for SimpleMapBuilder {
|
impl InitialMapBuilder for SimpleMapBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build_rooms(rng, build_data);
|
self.build_rooms(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,17 +17,17 @@ impl SimpleMapBuilder {
|
|||||||
Box::new(SimpleMapBuilder {})
|
Box::new(SimpleMapBuilder {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_rooms(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_rooms(&mut self, build_data: &mut BuilderMap) {
|
||||||
const MAX_ROOMS: i32 = 30;
|
const MAX_ROOMS: i32 = 30;
|
||||||
const MIN_SIZE: i32 = 6;
|
const MIN_SIZE: i32 = 6;
|
||||||
const MAX_SIZE: i32 = 10;
|
const MAX_SIZE: i32 = 10;
|
||||||
let mut rooms: Vec<Rect> = Vec::new();
|
let mut rooms: Vec<Rect> = Vec::new();
|
||||||
|
|
||||||
for _ in 0..MAX_ROOMS {
|
for _ in 0..MAX_ROOMS {
|
||||||
let w = rng.range(MIN_SIZE, MAX_SIZE);
|
let w = range(MIN_SIZE, MAX_SIZE);
|
||||||
let h = rng.range(MIN_SIZE, MAX_SIZE);
|
let h = range(MIN_SIZE, MAX_SIZE);
|
||||||
let x = rng.roll_dice(1, build_data.map.width - w - 1) - 1;
|
let x = roll_dice(1, build_data.map.width - w - 1) - 1;
|
||||||
let y = rng.roll_dice(1, build_data.map.height - h - 1) - 1;
|
let y = roll_dice(1, build_data.map.height - h - 1) - 1;
|
||||||
|
|
||||||
let new_room = Rect::new(x, y, w, h);
|
let new_room = Rect::new(x, y, w, h);
|
||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::Point;
|
||||||
|
|
||||||
use super::{BuilderChain, BuilderMap, InitialMapBuilder};
|
use super::{BuilderChain, BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{Position, TileType};
|
use crate::{Position, TileType};
|
||||||
|
|
||||||
pub fn town_builder(
|
pub fn town_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
|
||||||
new_depth: i32,
|
|
||||||
_rng: &mut RandomNumberGenerator,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
) -> BuilderChain {
|
|
||||||
let mut chain = BuilderChain::new(new_depth, width, height, "The Town of Ion");
|
let mut chain = BuilderChain::new(new_depth, width, height, "The Town of Ion");
|
||||||
chain.start_with(TownBuilder::new());
|
chain.start_with(TownBuilder::new());
|
||||||
|
|
||||||
@ -21,8 +17,8 @@ pub struct TownBuilder {}
|
|||||||
|
|
||||||
impl InitialMapBuilder for TownBuilder {
|
impl InitialMapBuilder for TownBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build_rooms(rng, build_data);
|
self.build_rooms(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +40,13 @@ impl TownBuilder {
|
|||||||
Box::new(TownBuilder {})
|
Box::new(TownBuilder {})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_rooms(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
pub fn build_rooms(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.grass_layer(build_data);
|
self.grass_layer(build_data);
|
||||||
self.water_and_piers(rng, build_data);
|
self.water_and_piers(build_data);
|
||||||
|
|
||||||
let (mut available_building_tiles, wall_gap_y) = self.town_walls(rng, build_data);
|
let (mut available_building_tiles, wall_gap_y) = self.town_walls(build_data);
|
||||||
let mut buildings = self.buildings(rng, build_data, &mut available_building_tiles);
|
let mut buildings = self.buildings(build_data, &mut available_building_tiles);
|
||||||
let doors = self.add_doors(rng, build_data, &mut buildings, wall_gap_y);
|
let doors = self.add_doors(build_data, &mut buildings, wall_gap_y);
|
||||||
self.add_paths(build_data, &doors);
|
self.add_paths(build_data, &doors);
|
||||||
|
|
||||||
for y in wall_gap_y - 3..wall_gap_y + 4 {
|
for y in wall_gap_y - 3..wall_gap_y + 4 {
|
||||||
@ -59,10 +55,10 @@ impl TownBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let building_size = self.sort_buildings(&buildings);
|
let building_size = self.sort_buildings(&buildings);
|
||||||
self.building_factory(rng, build_data, &buildings, &building_size);
|
self.building_factory(build_data, &buildings, &building_size);
|
||||||
|
|
||||||
self.spawn_dockers(build_data, rng);
|
self.spawn_dockers(build_data);
|
||||||
self.spawn_townsfolk(build_data, rng, &mut available_building_tiles);
|
self.spawn_townsfolk(build_data, &mut available_building_tiles);
|
||||||
|
|
||||||
// Make visible for screenshot
|
// Make visible for screenshot
|
||||||
for t in build_data.map.visible_tiles.iter_mut() {
|
for t in build_data.map.visible_tiles.iter_mut() {
|
||||||
@ -79,12 +75,12 @@ impl TownBuilder {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn water_and_piers(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn water_and_piers(&mut self, build_data: &mut BuilderMap) {
|
||||||
let mut n = (rng.roll_dice(1, 65535) as f32) / 65535_f32;
|
let mut n = (roll_dice(1, 65535) as f32) / 65535_f32;
|
||||||
let mut water_width: Vec<i32> = Vec::new();
|
let mut water_width: Vec<i32> = Vec::new();
|
||||||
|
|
||||||
for y in 0..build_data.height {
|
for y in 0..build_data.height {
|
||||||
let n_water = (f32::sin(n) * 10.0) as i32 + 14 + rng.roll_dice(1, 6);
|
let n_water = (f32::sin(n) * 10.0) as i32 + 14 + roll_dice(1, 6);
|
||||||
water_width.push(n_water);
|
water_width.push(n_water);
|
||||||
n += 0.1;
|
n += 0.1;
|
||||||
|
|
||||||
@ -101,9 +97,9 @@ impl TownBuilder {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
||||||
// Add piers
|
// Add piers
|
||||||
for _i in 0..rng.roll_dice(1, 4) + 6 {
|
for _i in 0..roll_dice(1, 4) + 6 {
|
||||||
let y = rng.roll_dice(1, build_data.height) - 1;
|
let y = roll_dice(1, build_data.height) - 1;
|
||||||
for x in 2 + rng.roll_dice(1, 6)..water_width[y as usize] + 4 {
|
for x in 2 + roll_dice(1, 6)..water_width[y as usize] + 4 {
|
||||||
let idx = build_data.map.xy_idx(x, y);
|
let idx = build_data.map.xy_idx(x, y);
|
||||||
build_data.map.tiles[idx] = TileType::WoodFloor;
|
build_data.map.tiles[idx] = TileType::WoodFloor;
|
||||||
}
|
}
|
||||||
@ -111,13 +107,9 @@ impl TownBuilder {
|
|||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn town_walls(
|
fn town_walls(&mut self, build_data: &mut BuilderMap) -> (HashSet<usize>, i32) {
|
||||||
&mut self,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
) -> (HashSet<usize>, i32) {
|
|
||||||
let mut available_building_tiles: HashSet<usize> = HashSet::new();
|
let mut available_building_tiles: HashSet<usize> = HashSet::new();
|
||||||
let wall_gap_y = rng.roll_dice(1, build_data.height - 9) + 5;
|
let wall_gap_y = roll_dice(1, build_data.height - 9) + 5;
|
||||||
for y in 1..build_data.height - 2 {
|
for y in 1..build_data.height - 2 {
|
||||||
if !(y > wall_gap_y - 4 && y < wall_gap_y + 4) {
|
if !(y > wall_gap_y - 4 && y < wall_gap_y + 4) {
|
||||||
let idx = build_data.map.xy_idx(30, y);
|
let idx = build_data.map.xy_idx(30, y);
|
||||||
@ -156,7 +148,7 @@ impl TownBuilder {
|
|||||||
|
|
||||||
fn buildings(
|
fn buildings(
|
||||||
&mut self,
|
&mut self,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
available_building_tiles: &mut HashSet<usize>,
|
available_building_tiles: &mut HashSet<usize>,
|
||||||
) -> Vec<(i32, i32, i32, i32)> {
|
) -> Vec<(i32, i32, i32, i32)> {
|
||||||
@ -164,10 +156,10 @@ impl TownBuilder {
|
|||||||
let mut n_buildings = 0;
|
let mut n_buildings = 0;
|
||||||
|
|
||||||
while n_buildings < 12 {
|
while n_buildings < 12 {
|
||||||
let bx = rng.roll_dice(1, build_data.map.width - 32) + 30;
|
let bx = roll_dice(1, build_data.map.width - 32) + 30;
|
||||||
let by = rng.roll_dice(1, build_data.map.height) - 2;
|
let by = roll_dice(1, build_data.map.height) - 2;
|
||||||
let bw = rng.roll_dice(1, 8) + 4;
|
let bw = roll_dice(1, 8) + 4;
|
||||||
let bh = rng.roll_dice(1, 8) + 4;
|
let bh = roll_dice(1, 8) + 4;
|
||||||
let mut possible = true;
|
let mut possible = true;
|
||||||
|
|
||||||
for y in by..by + bh {
|
for y in by..by + bh {
|
||||||
@ -237,14 +229,14 @@ impl TownBuilder {
|
|||||||
|
|
||||||
fn add_doors(
|
fn add_doors(
|
||||||
&mut self,
|
&mut self,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
buildings: &mut Vec<(i32, i32, i32, i32)>,
|
buildings: &mut Vec<(i32, i32, i32, i32)>,
|
||||||
wall_gap_y: i32,
|
wall_gap_y: i32,
|
||||||
) -> Vec<usize> {
|
) -> Vec<usize> {
|
||||||
let mut doors = Vec::new();
|
let mut doors = Vec::new();
|
||||||
for building in buildings.iter() {
|
for building in buildings.iter() {
|
||||||
let door_x = building.0 + 1 + rng.roll_dice(1, building.2 - 3);
|
let door_x = building.0 + 1 + roll_dice(1, building.2 - 3);
|
||||||
let cy = building.1 + (building.3 / 2);
|
let cy = building.1 + (building.3 / 2);
|
||||||
let idx = if cy > wall_gap_y {
|
let idx = if cy > wall_gap_y {
|
||||||
// Door on the north wall
|
// Door on the north wall
|
||||||
@ -332,7 +324,7 @@ impl TownBuilder {
|
|||||||
|
|
||||||
fn building_factory(
|
fn building_factory(
|
||||||
&mut self,
|
&mut self,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
buildings: &[(i32, i32, i32, i32)],
|
buildings: &[(i32, i32, i32, i32)],
|
||||||
building_index: &[(usize, i32, BuildingTag)],
|
building_index: &[(usize, i32, BuildingTag)],
|
||||||
@ -340,14 +332,14 @@ impl TownBuilder {
|
|||||||
for (i, building) in buildings.iter().enumerate() {
|
for (i, building) in buildings.iter().enumerate() {
|
||||||
let build_type = &building_index[i].2;
|
let build_type = &building_index[i].2;
|
||||||
match build_type {
|
match build_type {
|
||||||
BuildingTag::Pub => self.build_pub(building, build_data, rng),
|
BuildingTag::Pub => self.build_pub(building, build_data),
|
||||||
BuildingTag::Temple => self.build_temple(building, build_data, rng),
|
BuildingTag::Temple => self.build_temple(building, build_data),
|
||||||
BuildingTag::Blacksmith => self.build_smith(building, build_data, rng),
|
BuildingTag::Blacksmith => self.build_smith(building, build_data),
|
||||||
BuildingTag::Clothier => self.build_clothier(building, build_data, rng),
|
BuildingTag::Clothier => self.build_clothier(building, build_data),
|
||||||
BuildingTag::Alchemist => self.build_alchemist(building, build_data, rng),
|
BuildingTag::Alchemist => self.build_alchemist(building, build_data),
|
||||||
BuildingTag::PlayerHouse => self.build_my_house(building, build_data, rng),
|
BuildingTag::PlayerHouse => self.build_my_house(building, build_data),
|
||||||
BuildingTag::Hovel => self.build_hovel(building, build_data, rng),
|
BuildingTag::Hovel => self.build_hovel(building, build_data),
|
||||||
BuildingTag::Abandoned => self.build_abandoned_house(building, build_data, rng),
|
BuildingTag::Abandoned => self.build_abandoned_house(building, build_data),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,7 +349,7 @@ impl TownBuilder {
|
|||||||
&mut self,
|
&mut self,
|
||||||
building: &(i32, i32, i32, i32),
|
building: &(i32, i32, i32, i32),
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
to_place: &mut Vec<&str>,
|
to_place: &mut Vec<&str>,
|
||||||
player_idx: usize,
|
player_idx: usize,
|
||||||
) {
|
) {
|
||||||
@ -366,7 +358,7 @@ impl TownBuilder {
|
|||||||
let idx = build_data.map.xy_idx(x, y);
|
let idx = build_data.map.xy_idx(x, y);
|
||||||
if build_data.map.tiles[idx] == TileType::WoodFloor
|
if build_data.map.tiles[idx] == TileType::WoodFloor
|
||||||
&& idx != player_idx
|
&& idx != player_idx
|
||||||
&& rng.roll_dice(1, 3) == 1
|
&& roll_dice(1, 3) == 1
|
||||||
&& !to_place.is_empty()
|
&& !to_place.is_empty()
|
||||||
{
|
{
|
||||||
let entity_tag = to_place[0];
|
let entity_tag = to_place[0];
|
||||||
@ -377,12 +369,7 @@ impl TownBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_pub(
|
fn build_pub(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place the player
|
// Place the player
|
||||||
build_data.starting_position = Some(Position {
|
build_data.starting_position = Some(Position {
|
||||||
x: building.0 + (building.2 / 2),
|
x: building.0 + (building.2 / 2),
|
||||||
@ -404,15 +391,10 @@ impl TownBuilder {
|
|||||||
"Table",
|
"Table",
|
||||||
"Chair",
|
"Chair",
|
||||||
];
|
];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, player_idx);
|
self.random_building_spawn(building, build_data, &mut to_place, player_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_temple(
|
fn build_temple(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> = vec![
|
let mut to_place: Vec<&str> = vec![
|
||||||
"Priest",
|
"Priest",
|
||||||
@ -424,15 +406,10 @@ impl TownBuilder {
|
|||||||
"Candle",
|
"Candle",
|
||||||
"Candle",
|
"Candle",
|
||||||
];
|
];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_smith(
|
fn build_smith(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> = vec![
|
let mut to_place: Vec<&str> = vec![
|
||||||
"Blacksmith",
|
"Blacksmith",
|
||||||
@ -441,66 +418,45 @@ impl TownBuilder {
|
|||||||
"Weapon Rack",
|
"Weapon Rack",
|
||||||
"Armor Stand",
|
"Armor Stand",
|
||||||
];
|
];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_clothier(
|
fn build_clothier(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> = vec!["Clothier", "Cabinet", "Table", "Loom", "Hide Rack"];
|
let mut to_place: Vec<&str> = vec!["Clothier", "Cabinet", "Table", "Loom", "Hide Rack"];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_alchemist(
|
fn build_alchemist(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> =
|
let mut to_place: Vec<&str> =
|
||||||
vec!["Alchemist", "Chemistry Set", "Dead Thing", "Chair", "Table"];
|
vec!["Alchemist", "Chemistry Set", "Dead Thing", "Chair", "Table"];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_my_house(
|
fn build_my_house(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> = vec!["Mom", "Bed", "Cabinet", "Chair", "Table"];
|
let mut to_place: Vec<&str> = vec!["Mom", "Bed", "Cabinet", "Chair", "Table"];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_hovel(
|
fn build_hovel(&mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap) {
|
||||||
&mut self,
|
|
||||||
building: &(i32, i32, i32, i32),
|
|
||||||
build_data: &mut BuilderMap,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
|
||||||
// Place items
|
// Place items
|
||||||
let mut to_place: Vec<&str> = vec!["Peasant", "Bed", "Chair", "Table"];
|
let mut to_place: Vec<&str> = vec!["Peasant", "Bed", "Chair", "Table"];
|
||||||
self.random_building_spawn(building, build_data, rng, &mut to_place, 0);
|
self.random_building_spawn(building, build_data, &mut to_place, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_abandoned_house(
|
fn build_abandoned_house(
|
||||||
&mut self,
|
&mut self,
|
||||||
building: &(i32, i32, i32, i32),
|
building: &(i32, i32, i32, i32),
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
) {
|
) {
|
||||||
for y in building.1..building.1 + building.3 {
|
for y in building.1..building.1 + building.3 {
|
||||||
for x in building.0..building.0 + building.2 {
|
for x in building.0..building.0 + building.2 {
|
||||||
let idx = build_data.map.xy_idx(x, y);
|
let idx = build_data.map.xy_idx(x, y);
|
||||||
if build_data.map.tiles[idx] == TileType::WoodFloor
|
if build_data.map.tiles[idx] == TileType::WoodFloor
|
||||||
&& idx != 0
|
&& idx != 0
|
||||||
&& rng.roll_dice(1, 2) == 1
|
&& roll_dice(1, 2) == 1
|
||||||
{
|
{
|
||||||
build_data.spawn_list.push((idx, "Rat".to_string()));
|
build_data.spawn_list.push((idx, "Rat".to_string()));
|
||||||
}
|
}
|
||||||
@ -508,10 +464,10 @@ impl TownBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_dockers(&mut self, build_data: &mut BuilderMap, rng: &mut RandomNumberGenerator) {
|
fn spawn_dockers(&mut self, build_data: &mut BuilderMap) {
|
||||||
for (idx, tt) in build_data.map.tiles.iter().enumerate() {
|
for (idx, tt) in build_data.map.tiles.iter().enumerate() {
|
||||||
if *tt == TileType::Bridge && rng.roll_dice(1, 6) == 1 {
|
if *tt == TileType::Bridge && roll_dice(1, 6) == 1 {
|
||||||
match rng.roll_dice(1, 3) {
|
match roll_dice(1, 3) {
|
||||||
1 => build_data.spawn_list.push((idx, "Dock Worker".to_string())),
|
1 => build_data.spawn_list.push((idx, "Dock Worker".to_string())),
|
||||||
2 => build_data
|
2 => build_data
|
||||||
.spawn_list
|
.spawn_list
|
||||||
@ -525,12 +481,12 @@ impl TownBuilder {
|
|||||||
fn spawn_townsfolk(
|
fn spawn_townsfolk(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_data: &mut BuilderMap,
|
build_data: &mut BuilderMap,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
available_building_tiles: &mut HashSet<usize>,
|
available_building_tiles: &mut HashSet<usize>,
|
||||||
) {
|
) {
|
||||||
for idx in available_building_tiles.iter() {
|
for idx in available_building_tiles.iter() {
|
||||||
if rng.roll_dice(1, 10) == 1 {
|
if roll_dice(1, 10) == 1 {
|
||||||
match rng.roll_dice(1, 4) {
|
match roll_dice(1, 4) {
|
||||||
1 => build_data.spawn_list.push((*idx, "Peasant".to_string())),
|
1 => build_data.spawn_list.push((*idx, "Peasant".to_string())),
|
||||||
2 => build_data.spawn_list.push((*idx, "Drunk".to_string())),
|
2 => build_data.spawn_list.push((*idx, "Drunk".to_string())),
|
||||||
3 => build_data
|
3 => build_data
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
use crate::map_builders::{BuilderMap, InitialMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::TileType;
|
use crate::TileType;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
@ -17,8 +16,8 @@ pub struct VoronoiCellBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InitialMapBuilder for VoronoiCellBuilder {
|
impl InitialMapBuilder for VoronoiCellBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +43,13 @@ impl VoronoiCellBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
// Make a Voronoi diagram. We'll do this the hard way to learn about the technique!
|
// Make a Voronoi diagram. We'll do this the hard way to learn about the technique!
|
||||||
let mut voronoi_seeds: Vec<(usize, rltk::Point)> = Vec::new();
|
let mut voronoi_seeds: Vec<(usize, rltk::Point)> = Vec::new();
|
||||||
|
|
||||||
while voronoi_seeds.len() < self.n_seeds {
|
while voronoi_seeds.len() < self.n_seeds {
|
||||||
let vx = rng.roll_dice(1, build_data.map.width - 1);
|
let vx = roll_dice(1, build_data.map.width - 1);
|
||||||
let vy = rng.roll_dice(1, build_data.map.height - 1);
|
let vy = roll_dice(1, build_data.map.height - 1);
|
||||||
let vidx = build_data.map.xy_idx(vx, vy);
|
let vidx = build_data.map.xy_idx(vx, vy);
|
||||||
let candidate = (vidx, rltk::Point::new(vx, vy));
|
let candidate = (vidx, rltk::Point::new(vx, vy));
|
||||||
if !voronoi_seeds.contains(&candidate) {
|
if !voronoi_seeds.contains(&candidate) {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
use ::rltk::{CellularDistanceFunction, FastNoise, NoiseType};
|
||||||
|
|
||||||
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
use crate::map_builders::{BuilderMap, MetaMapBuilder};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{spawner, TileType};
|
use crate::{spawner, TileType};
|
||||||
|
|
||||||
pub struct VoronoiSpawning {}
|
pub struct VoronoiSpawning {}
|
||||||
|
|
||||||
impl MetaMapBuilder for VoronoiSpawning {
|
impl MetaMapBuilder for VoronoiSpawning {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +21,12 @@ impl VoronoiSpawning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
let mut noise_areas: HashMap<i32, Vec<usize>> = HashMap::new();
|
let mut noise_areas: HashMap<i32, Vec<usize>> = HashMap::new();
|
||||||
let mut noise = rltk::FastNoise::seeded(rng.roll_dice(1, 65536) as u64);
|
let mut noise = FastNoise::seeded(roll_dice(1, 65536) as u64);
|
||||||
noise.set_noise_type(rltk::NoiseType::Cellular);
|
noise.set_noise_type(NoiseType::Cellular);
|
||||||
noise.set_frequency(0.08);
|
noise.set_frequency(0.08);
|
||||||
noise.set_cellular_distance_function(rltk::CellularDistanceFunction::Manhattan);
|
noise.set_cellular_distance_function(CellularDistanceFunction::Manhattan);
|
||||||
|
|
||||||
for y in 1..build_data.map.height - 1 {
|
for y in 1..build_data.map.height - 1 {
|
||||||
for x in 1..build_data.map.width - 1 {
|
for x in 1..build_data.map.width - 1 {
|
||||||
@ -47,7 +48,6 @@ impl VoronoiSpawning {
|
|||||||
for area in noise_areas.iter() {
|
for area in noise_areas.iter() {
|
||||||
spawner::spawn_region(
|
spawner::spawn_region(
|
||||||
&build_data.map,
|
&build_data.map,
|
||||||
rng,
|
|
||||||
area.1,
|
area.1,
|
||||||
build_data.map.depth,
|
build_data.map.depth,
|
||||||
&mut build_data.spawn_list,
|
&mut build_data.spawn_list,
|
||||||
|
@ -2,7 +2,6 @@ mod common;
|
|||||||
mod constraints;
|
mod constraints;
|
||||||
mod solver;
|
mod solver;
|
||||||
|
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use constraints::*;
|
use constraints::*;
|
||||||
use solver::*;
|
use solver::*;
|
||||||
@ -13,8 +12,8 @@ use crate::Map;
|
|||||||
pub struct WaveformCollapseBuilder {}
|
pub struct WaveformCollapseBuilder {}
|
||||||
|
|
||||||
impl MetaMapBuilder for WaveformCollapseBuilder {
|
impl MetaMapBuilder for WaveformCollapseBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build_map(&mut self, build_data: &mut BuilderMap) {
|
||||||
self.build(rng, build_data);
|
self.build(build_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ impl WaveformCollapseBuilder {
|
|||||||
Box::new(WaveformCollapseBuilder {})
|
Box::new(WaveformCollapseBuilder {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
fn build(&mut self, build_data: &mut BuilderMap) {
|
||||||
const CHUNK_SIZE: i32 = 8;
|
const CHUNK_SIZE: i32 = 8;
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ impl WaveformCollapseBuilder {
|
|||||||
let mut tries = 0;
|
let mut tries = 0;
|
||||||
loop {
|
loop {
|
||||||
let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map);
|
let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map);
|
||||||
while !solver.iteration(&mut build_data.map, rng) {
|
while !solver.iteration(&mut build_data.map) {
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
}
|
}
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use super::MapChunk;
|
use super::MapChunk;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::Map;
|
use crate::Map;
|
||||||
|
|
||||||
pub struct Solver {
|
pub struct Solver {
|
||||||
@ -71,7 +72,7 @@ impl Solver {
|
|||||||
neighbors
|
neighbors
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iteration(&mut self, map: &mut Map, rng: &mut rltk::RandomNumberGenerator) -> bool {
|
pub fn iteration(&mut self, map: &mut Map) -> bool {
|
||||||
if self.remaining.is_empty() {
|
if self.remaining.is_empty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ impl Solver {
|
|||||||
|
|
||||||
// Pick a random chunk we haven't dealt with yet and get its index, remove from remaining list
|
// Pick a random chunk we haven't dealt with yet and get its index, remove from remaining list
|
||||||
let remaining_index = if !neighbors_exist {
|
let remaining_index = if !neighbors_exist {
|
||||||
(rng.roll_dice(1, self.remaining.len() as i32) - 1) as usize
|
(roll_dice(1, self.remaining.len() as i32) - 1) as usize
|
||||||
} else {
|
} else {
|
||||||
0_usize
|
0_usize
|
||||||
};
|
};
|
||||||
@ -154,7 +155,7 @@ impl Solver {
|
|||||||
|
|
||||||
if neighbors == 0 {
|
if neighbors == 0 {
|
||||||
// There is nothing nearby, so we can have anything!
|
// There is nothing nearby, so we can have anything!
|
||||||
let new_chunk_idx = (rng.roll_dice(1, self.constraints.len() as i32) - 1) as usize;
|
let new_chunk_idx = (roll_dice(1, self.constraints.len() as i32) - 1) as usize;
|
||||||
self.chunks[chunk_index] = Some(new_chunk_idx);
|
self.chunks[chunk_index] = Some(new_chunk_idx);
|
||||||
let left_x = chunk_x as i32 * self.chunk_size;
|
let left_x = chunk_x as i32 * self.chunk_size;
|
||||||
let right_x = (chunk_x + 1) as i32 * self.chunk_size;
|
let right_x = (chunk_x + 1) as i32 * self.chunk_size;
|
||||||
@ -202,7 +203,7 @@ impl Solver {
|
|||||||
let new_chunk_idx = if possible_options.len() == 1 {
|
let new_chunk_idx = if possible_options.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
rng.roll_dice(1, possible_options.len() as i32) - 1
|
roll_dice(1, possible_options.len() as i32) - 1
|
||||||
};
|
};
|
||||||
self.chunks[chunk_index] = Some(new_chunk_idx as usize);
|
self.chunks[chunk_index] = Some(new_chunk_idx as usize);
|
||||||
let left_x = chunk_x as i32 * self.chunk_size;
|
let left_x = chunk_x as i32 * self.chunk_size;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Player-related functionality
|
//! Player-related functionality
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
use rltk::{DistanceAlg, Point, RandomNumberGenerator, Rltk, VirtualKeyCode};
|
use rltk::{DistanceAlg, Point, Rltk, VirtualKeyCode};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
@ -10,6 +10,7 @@ use crate::components::{
|
|||||||
WantsToMelee, WantsToPickupItem, WantsToShoot,
|
WantsToMelee, WantsToPickupItem, WantsToShoot,
|
||||||
};
|
};
|
||||||
use crate::raws::{self, Reaction, RAWS};
|
use crate::raws::{self, Reaction, RAWS};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{
|
use crate::{
|
||||||
colors, gamelog, spatial, Map, RunState, State, TileType, VendorMode, WantsToCastSpell, Weapon,
|
colors, gamelog, spatial, Map, RunState, State, TileType, VendorMode, WantsToCastSpell, Weapon,
|
||||||
};
|
};
|
||||||
@ -358,8 +359,7 @@ fn skip_turn(ecs: &mut World) -> RunState {
|
|||||||
let pools = health_components.get_mut(*player_entity).unwrap();
|
let pools = health_components.get_mut(*player_entity).unwrap();
|
||||||
pools.hit_points.current = i32::min(pools.hit_points.current + 1, pools.hit_points.max);
|
pools.hit_points.current = i32::min(pools.hit_points.current + 1, pools.hit_points.max);
|
||||||
|
|
||||||
let mut rng = ecs.fetch_mut::<RandomNumberGenerator>();
|
if roll_dice(1, 6) == 1 {
|
||||||
if rng.roll_dice(1, 6) == 1 {
|
|
||||||
pools.mana.current = i32::min(pools.mana.current + 1, pools.mana.max);
|
pools.mana.current = i32::min(pools.mana.current + 1, pools.mana.max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! Weighted random generation of entities
|
//! Weighted random generation of entities
|
||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
|
|
||||||
use crate::raws::{spawn_type_by_name, RawMaster, SpawnTableType};
|
use crate::raws::{spawn_type_by_name, RawMaster, SpawnTableType};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
|
|
||||||
pub struct RandomEntry {
|
pub struct RandomEntry {
|
||||||
name: String,
|
name: String,
|
||||||
@ -41,12 +40,11 @@ impl MasterTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn roll(&self, rng: &mut RandomNumberGenerator) -> String {
|
pub fn roll(&self) -> String {
|
||||||
let roll = rng.roll_dice(1, 4);
|
match roll_dice(1, 4) {
|
||||||
match roll {
|
1 => self.items.roll(),
|
||||||
1 => self.items.roll(rng),
|
2 => self.props.roll(),
|
||||||
2 => self.props.roll(rng),
|
3 => self.mobs.roll(),
|
||||||
3 => self.mobs.roll(rng),
|
|
||||||
_ => "None".to_string(),
|
_ => "None".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,12 +71,12 @@ impl RandomTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn roll(&self, rng: &mut RandomNumberGenerator) -> String {
|
pub fn roll(&self) -> String {
|
||||||
if self.total_weight == 0 {
|
if self.total_weight == 0 {
|
||||||
return "None".to_string();
|
return "None".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut roll = rng.roll_dice(1, self.total_weight) - 1;
|
let mut roll = roll_dice(1, self.total_weight) - 1;
|
||||||
let mut index: usize = 0;
|
let mut index: usize = 0;
|
||||||
|
|
||||||
while roll > 0 {
|
while roll > 0 {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use ::regex::Regex;
|
use ::regex::Regex;
|
||||||
use ::rltk::{console, RandomNumberGenerator, RGB};
|
use ::rltk::{console, RGB};
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ use crate::components::*;
|
|||||||
use crate::gamesystem::{mana_at_level, npc_hp};
|
use crate::gamesystem::{mana_at_level, npc_hp};
|
||||||
use crate::map::MasterDungeonMap;
|
use crate::map::MasterDungeonMap;
|
||||||
use crate::random_table::{MasterTable, RandomTable};
|
use crate::random_table::{MasterTable, RandomTable};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
|
|
||||||
pub fn parse_dice_string(dice: &str) -> (i32, i32, i32) {
|
pub fn parse_dice_string(dice: &str) -> (i32, i32, i32) {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -714,9 +715,8 @@ pub fn spawn_named_mob(
|
|||||||
total_weight: 0.,
|
total_weight: 0.,
|
||||||
total_initiative_penalty: 0.,
|
total_initiative_penalty: 0.,
|
||||||
gold: if let Some(gold) = &mob_template.gold {
|
gold: if let Some(gold) = &mob_template.gold {
|
||||||
let mut rng = RandomNumberGenerator::new();
|
|
||||||
let (n, d, b) = parse_dice_string(gold);
|
let (n, d, b) = parse_dice_string(gold);
|
||||||
(rng.roll_dice(n, d) + b) as f32
|
(roll_dice(n, d) + b) as f32
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
},
|
},
|
||||||
@ -975,11 +975,7 @@ pub fn get_spawn_table_for_depth(raws: &RawMaster, depth: i32) -> MasterTable {
|
|||||||
rt
|
rt
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item_drop(
|
pub fn get_item_drop(raws: &RawMaster, table: &str) -> Option<String> {
|
||||||
raws: &RawMaster,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
table: &str,
|
|
||||||
) -> Option<String> {
|
|
||||||
if raws.loot_index.contains_key(table) {
|
if raws.loot_index.contains_key(table) {
|
||||||
let mut rt = RandomTable::new();
|
let mut rt = RandomTable::new();
|
||||||
let available_options = &raws.raws.loot_tables[raws.loot_index[table]];
|
let available_options = &raws.raws.loot_tables[raws.loot_index[table]];
|
||||||
@ -987,7 +983,7 @@ pub fn get_item_drop(
|
|||||||
rt.add(item.name.clone(), item.weight);
|
rt.add(item.name.clone(), item.weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(rt.roll(rng));
|
return Some(rt.roll());
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use ::rltk::prelude::*;
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use ::rltk::prelude::*;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new());
|
static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn reseed(seed: u64) {
|
pub fn reseed(seed: u64) {
|
||||||
*RNG.lock().unwrap() = RandomNumberGenerator::seeded(seed);
|
*RNG.lock().unwrap() = RandomNumberGenerator::seeded(seed);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Spawns things
|
//! Spawns things
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ use crate::random_table::MasterTable;
|
|||||||
use crate::raws::{
|
use crate::raws::{
|
||||||
get_spawn_table_for_depth, spawn_all_spells, spawn_named_entity, SpawnType, RAWS,
|
get_spawn_table_for_depth, spawn_all_spells, spawn_named_entity, SpawnType, RAWS,
|
||||||
};
|
};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, Map, MasterDungeonMap, Rect, TileType};
|
use crate::{colors, Map, MasterDungeonMap, Rect, TileType};
|
||||||
|
|
||||||
/// Spawns the player and returns their entity object
|
/// Spawns the player and returns their entity object
|
||||||
@ -19,7 +20,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
|||||||
.create_entity()
|
.create_entity()
|
||||||
.with(Position::from((player_x, player_y)))
|
.with(Position::from((player_x, player_y)))
|
||||||
.with(Renderable {
|
.with(Renderable {
|
||||||
glyph: rltk::to_cp437('@'),
|
glyph: to_cp437('@'),
|
||||||
fg: colors::YELLOW,
|
fg: colors::YELLOW,
|
||||||
bg: colors::BLACK,
|
bg: colors::BLACK,
|
||||||
render_order: 0,
|
render_order: 0,
|
||||||
@ -84,13 +85,7 @@ fn room_table(map_depth: i32) -> MasterTable {
|
|||||||
|
|
||||||
/// fills a room with stuff!
|
/// fills a room with stuff!
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
pub fn spawn_room(
|
pub fn spawn_room(map: &Map, room: &Rect, map_depth: i32, spawn_list: &mut Vec<(usize, String)>) {
|
||||||
map: &Map,
|
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
room: &Rect,
|
|
||||||
map_depth: i32,
|
|
||||||
spawn_list: &mut Vec<(usize, String)>,
|
|
||||||
) {
|
|
||||||
let mut possible_targets: Vec<usize> = Vec::new();
|
let mut possible_targets: Vec<usize> = Vec::new();
|
||||||
|
|
||||||
// Borrow scope - to keep access to the map separated
|
// Borrow scope - to keep access to the map separated
|
||||||
@ -105,12 +100,11 @@ pub fn spawn_room(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_region(map, rng, &possible_targets, map_depth, spawn_list);
|
spawn_region(map, &possible_targets, map_depth, spawn_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_region(
|
pub fn spawn_region(
|
||||||
_map: &Map,
|
_map: &Map,
|
||||||
rng: &mut RandomNumberGenerator,
|
|
||||||
area: &[usize],
|
area: &[usize],
|
||||||
map_depth: i32,
|
map_depth: i32,
|
||||||
spawn_list: &mut Vec<(usize, String)>,
|
spawn_list: &mut Vec<(usize, String)>,
|
||||||
@ -123,7 +117,7 @@ pub fn spawn_region(
|
|||||||
{
|
{
|
||||||
let num_spawns = i32::min(
|
let num_spawns = i32::min(
|
||||||
areas.len() as i32,
|
areas.len() as i32,
|
||||||
rng.roll_dice(1, MAX_MONSTERS + 3) + (map_depth - 1) - 3,
|
roll_dice(1, MAX_MONSTERS + 3) + (map_depth - 1) - 3,
|
||||||
);
|
);
|
||||||
if num_spawns == 0 {
|
if num_spawns == 0 {
|
||||||
return;
|
return;
|
||||||
@ -133,10 +127,10 @@ pub fn spawn_region(
|
|||||||
let array_index = if areas.len() == 1 {
|
let array_index = if areas.len() == 1 {
|
||||||
0_usize
|
0_usize
|
||||||
} else {
|
} else {
|
||||||
(rng.roll_dice(1, areas.len() as i32) - 1) as usize
|
(roll_dice(1, areas.len() as i32) - 1) as usize
|
||||||
};
|
};
|
||||||
let map_idx = areas[array_index];
|
let map_idx = areas[array_index];
|
||||||
spawn_points.insert(map_idx, spawn_table.roll(rng));
|
spawn_points.insert(map_idx, spawn_table.roll());
|
||||||
areas.remove(array_index);
|
areas.remove(array_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +163,7 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if item_result.is_none() {
|
if item_result.is_none() {
|
||||||
::rltk::console::log(format!("WARNING: We don't know how to spawn [{}]!", name));
|
console::log(format!("WARNING: We don't know how to spawn [{}]!", name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +199,7 @@ pub fn spawn_town_portal(ecs: &mut World) {
|
|||||||
depth: 1,
|
depth: 1,
|
||||||
})
|
})
|
||||||
.with(Renderable {
|
.with(Renderable {
|
||||||
glyph: ::rltk::to_cp437('♥'),
|
glyph: to_cp437('♥'),
|
||||||
fg: colors::CYAN,
|
fg: colors::CYAN,
|
||||||
bg: colors::BLACK,
|
bg: colors::BLACK,
|
||||||
render_order: 0,
|
render_order: 0,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{ApplyMove, MoveMode, Movement, MyTurn, Position};
|
use crate::components::{ApplyMove, MoveMode, Movement, MyTurn, Position};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{spatial, tile_walkable, Map};
|
use crate::{spatial, tile_walkable, Map};
|
||||||
|
|
||||||
pub struct DefaultMoveAI {}
|
pub struct DefaultMoveAI {}
|
||||||
@ -13,13 +13,12 @@ impl<'a> System<'a> for DefaultMoveAI {
|
|||||||
WriteStorage<'a, MoveMode>,
|
WriteStorage<'a, MoveMode>,
|
||||||
ReadStorage<'a, Position>,
|
ReadStorage<'a, Position>,
|
||||||
ReadExpect<'a, Map>,
|
ReadExpect<'a, Map>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
WriteStorage<'a, ApplyMove>,
|
WriteStorage<'a, ApplyMove>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (mut turns, mut move_mode, positions, map, mut rng, mut apply_move, entities) = data;
|
let (mut turns, mut move_mode, positions, map, mut apply_move, entities) = data;
|
||||||
|
|
||||||
let mut turn_done: Vec<Entity> = Vec::new();
|
let mut turn_done: Vec<Entity> = Vec::new();
|
||||||
for (entity, pos, mut mode, _myturn) in
|
for (entity, pos, mut mode, _myturn) in
|
||||||
@ -33,7 +32,7 @@ impl<'a> System<'a> for DefaultMoveAI {
|
|||||||
let mut x = pos.x;
|
let mut x = pos.x;
|
||||||
let mut y = pos.y;
|
let mut y = pos.y;
|
||||||
|
|
||||||
match rng.roll_dice(1, 5) {
|
match roll_dice(1, 5) {
|
||||||
1 => x -= 1,
|
1 => x -= 1,
|
||||||
2 => x += 1,
|
2 => x += 1,
|
||||||
3 => y -= 1,
|
3 => y -= 1,
|
||||||
@ -67,8 +66,8 @@ impl<'a> System<'a> for DefaultMoveAI {
|
|||||||
mode.mode = Movement::RandomWaypoint { path: None };
|
mode.mode = Movement::RandomWaypoint { path: None };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let target_x = rng.roll_dice(1, map.width - 2);
|
let target_x = roll_dice(1, map.width - 2);
|
||||||
let target_y = rng.roll_dice(1, map.height - 2);
|
let target_y = roll_dice(1, map.height - 2);
|
||||||
let idx = map.xy_idx(target_x, target_y);
|
let idx = map.xy_idx(target_x, target_y);
|
||||||
if tile_walkable(map.tiles[idx]) {
|
if tile_walkable(map.tiles[idx]) {
|
||||||
let path = ::rltk::a_star_search(
|
let path = ::rltk::a_star_search(
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use ::rltk::{DistanceAlg, Point, RandomNumberGenerator};
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
Attributes, DamageOverTime, Duration, EquipmentChanged, Initiative, MyTurn, Pools, Position,
|
Attributes, DamageOverTime, Duration, EquipmentChanged, Initiative, MyTurn, Pools, Position,
|
||||||
StatusEffect,
|
StatusEffect,
|
||||||
};
|
};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::RunState;
|
use crate::RunState;
|
||||||
|
|
||||||
pub struct InitiativeSystem {}
|
pub struct InitiativeSystem {}
|
||||||
@ -16,7 +17,6 @@ impl<'a> System<'a> for InitiativeSystem {
|
|||||||
ReadStorage<'a, Position>,
|
ReadStorage<'a, Position>,
|
||||||
WriteStorage<'a, MyTurn>,
|
WriteStorage<'a, MyTurn>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
ReadStorage<'a, Attributes>,
|
ReadStorage<'a, Attributes>,
|
||||||
WriteExpect<'a, RunState>,
|
WriteExpect<'a, RunState>,
|
||||||
ReadExpect<'a, Entity>,
|
ReadExpect<'a, Entity>,
|
||||||
@ -34,7 +34,6 @@ impl<'a> System<'a> for InitiativeSystem {
|
|||||||
positions,
|
positions,
|
||||||
mut turns,
|
mut turns,
|
||||||
entities,
|
entities,
|
||||||
mut rng,
|
|
||||||
attributes,
|
attributes,
|
||||||
mut runstate,
|
mut runstate,
|
||||||
player,
|
player,
|
||||||
@ -60,7 +59,7 @@ impl<'a> System<'a> for InitiativeSystem {
|
|||||||
let mut myturn = true;
|
let mut myturn = true;
|
||||||
|
|
||||||
// Re-roll
|
// Re-roll
|
||||||
initiative.current = 6 + rng.roll_dice(1, 6);
|
initiative.current = 6 + roll_dice(1, 6);
|
||||||
|
|
||||||
// Give a bonus for quickness
|
// Give a bonus for quickness
|
||||||
if let Some(attr) = attributes.get(entity) {
|
if let Some(attr) = attributes.get(entity) {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use ::rltk::{Point, RandomNumberGenerator};
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{MyTurn, Name, Quips, Viewshed};
|
use crate::components::{MyTurn, Name, Quips, Viewshed};
|
||||||
use crate::gamelog;
|
use crate::gamelog;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
|
|
||||||
pub struct QuipSystem {}
|
pub struct QuipSystem {}
|
||||||
|
|
||||||
@ -14,21 +15,20 @@ impl<'a> System<'a> for QuipSystem {
|
|||||||
ReadStorage<'a, MyTurn>,
|
ReadStorage<'a, MyTurn>,
|
||||||
ReadExpect<'a, Point>,
|
ReadExpect<'a, Point>,
|
||||||
ReadStorage<'a, Viewshed>,
|
ReadStorage<'a, Viewshed>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (mut quips, names, turns, player_pos, viewsheds, mut rng) = data;
|
let (mut quips, names, turns, player_pos, viewsheds) = data;
|
||||||
|
|
||||||
for (quip, name, viewshed, _turn) in (&mut quips, &names, &viewsheds, &turns).join() {
|
for (quip, name, viewshed, _turn) in (&mut quips, &names, &viewsheds, &turns).join() {
|
||||||
if !quip.available.is_empty()
|
if !quip.available.is_empty()
|
||||||
&& viewshed.visible_tiles.contains(&player_pos)
|
&& viewshed.visible_tiles.contains(&player_pos)
|
||||||
&& rng.roll_dice(1, 6) == 1
|
&& roll_dice(1, 6) == 1
|
||||||
{
|
{
|
||||||
let quip_index = if quip.available.len() == 1 {
|
let quip_index = if quip.available.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
(rng.roll_dice(1, quip.available.len() as i32) - 1) as usize
|
(roll_dice(1, quip.available.len() as i32) - 1) as usize
|
||||||
};
|
};
|
||||||
|
|
||||||
gamelog::Logger::new()
|
gamelog::Logger::new()
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use rltk::{console, DistanceAlg, Point, RandomNumberGenerator};
|
use ::rltk::prelude::*;
|
||||||
use specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
Chasing, Equipped, Faction, MyTurn, Name, Position, SpecialAbilities, SpellTemplate, Viewshed,
|
Chasing, Equipped, Faction, MyTurn, Name, Position, SpecialAbilities, SpellTemplate, Viewshed,
|
||||||
WantsToApproach, WantsToCastSpell, WantsToFlee, WantsToShoot, Weapon,
|
WantsToApproach, WantsToCastSpell, WantsToFlee, WantsToShoot, Weapon,
|
||||||
};
|
};
|
||||||
use crate::raws::{self, find_spell_entity_by_name, Reaction, RAWS};
|
use crate::raws::{self, find_spell_entity_by_name, Reaction, RAWS};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{spatial, Map};
|
use crate::{spatial, Map};
|
||||||
|
|
||||||
pub struct VisibleAI {}
|
pub struct VisibleAI {}
|
||||||
@ -24,7 +25,6 @@ impl<'a> System<'a> for VisibleAI {
|
|||||||
ReadStorage<'a, Viewshed>,
|
ReadStorage<'a, Viewshed>,
|
||||||
WriteStorage<'a, Chasing>,
|
WriteStorage<'a, Chasing>,
|
||||||
ReadStorage<'a, SpecialAbilities>,
|
ReadStorage<'a, SpecialAbilities>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
WriteStorage<'a, WantsToCastSpell>,
|
WriteStorage<'a, WantsToCastSpell>,
|
||||||
ReadStorage<'a, Name>,
|
ReadStorage<'a, Name>,
|
||||||
ReadStorage<'a, SpellTemplate>,
|
ReadStorage<'a, SpellTemplate>,
|
||||||
@ -46,7 +46,6 @@ impl<'a> System<'a> for VisibleAI {
|
|||||||
viewsheds,
|
viewsheds,
|
||||||
mut chasing,
|
mut chasing,
|
||||||
abilities,
|
abilities,
|
||||||
mut rng,
|
|
||||||
mut casting,
|
mut casting,
|
||||||
names,
|
names,
|
||||||
spells,
|
spells,
|
||||||
@ -84,7 +83,7 @@ impl<'a> System<'a> for VisibleAI {
|
|||||||
for ability in abilities.abilities.iter() {
|
for ability in abilities.abilities.iter() {
|
||||||
if range >= ability.min_range
|
if range >= ability.min_range
|
||||||
&& range <= ability.range
|
&& range <= ability.range
|
||||||
&& rng.roll_dice(1, 100) >= (ability.chance * 100.0) as i32
|
&& roll_dice(1, 100) >= (ability.chance * 100.0) as i32
|
||||||
{
|
{
|
||||||
casting
|
casting
|
||||||
.insert(
|
.insert(
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use ::rltk::RandomNumberGenerator;
|
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
@ -7,6 +6,7 @@ use crate::components::{
|
|||||||
};
|
};
|
||||||
use crate::effects::{add_effect, EffectType, Targets};
|
use crate::effects::{add_effect, EffectType, Targets};
|
||||||
use crate::gamesystem::skill_bonus;
|
use crate::gamesystem::skill_bonus;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, gamelog};
|
use crate::{colors, gamelog};
|
||||||
|
|
||||||
pub struct MeleeCombatSystem {}
|
pub struct MeleeCombatSystem {}
|
||||||
@ -21,7 +21,6 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
ReadStorage<'a, Skills>,
|
ReadStorage<'a, Skills>,
|
||||||
ReadStorage<'a, HungerClock>,
|
ReadStorage<'a, HungerClock>,
|
||||||
ReadStorage<'a, Pools>,
|
ReadStorage<'a, Pools>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
ReadStorage<'a, Equipped>,
|
ReadStorage<'a, Equipped>,
|
||||||
ReadStorage<'a, Weapon>,
|
ReadStorage<'a, Weapon>,
|
||||||
ReadStorage<'a, Wearable>,
|
ReadStorage<'a, Wearable>,
|
||||||
@ -37,7 +36,6 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
skills,
|
skills,
|
||||||
hunger_clock,
|
hunger_clock,
|
||||||
pools,
|
pools,
|
||||||
mut rng,
|
|
||||||
equipped_items,
|
equipped_items,
|
||||||
meleeweapons,
|
meleeweapons,
|
||||||
wearables,
|
wearables,
|
||||||
@ -78,7 +76,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
let attack_index = if nat.attacks.len() == 1 {
|
let attack_index = if nat.attacks.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
rng.roll_dice(1, nat.attacks.len() as i32) as usize - 1
|
roll_dice(1, nat.attacks.len() as i32) as usize - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
let attk = &nat.attacks[attack_index];
|
let attk = &nat.attacks[attack_index];
|
||||||
@ -100,7 +98,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let natural_roll = rng.roll_dice(1, 20);
|
let natural_roll = roll_dice(1, 20);
|
||||||
let attribute_hit_bonus = if weapon_info.attribute == WeaponAttribute::Might {
|
let attribute_hit_bonus = if weapon_info.attribute == WeaponAttribute::Might {
|
||||||
attacker_attributes.might.bonus
|
attacker_attributes.might.bonus
|
||||||
} else {
|
} else {
|
||||||
@ -140,7 +138,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
|
|
||||||
if natural_roll != 1 && (natural_roll == 20 || modified_hit_roll > armor_class) {
|
if natural_roll != 1 && (natural_roll == 20 || modified_hit_roll > armor_class) {
|
||||||
// Target hit! Until we support weapons, we're going with 1d4
|
// Target hit! Until we support weapons, we're going with 1d4
|
||||||
let base_damage = rng.roll_dice(1, 4);
|
let base_damage = roll_dice(1, 4);
|
||||||
let attr_damage_bonus = attacker_attributes.might.bonus;
|
let attr_damage_bonus = attacker_attributes.might.bonus;
|
||||||
let skill_damage_bonus = skill_bonus(Skill::Melee, &*attacker_skills);
|
let skill_damage_bonus = skill_bonus(Skill::Melee, &*attacker_skills);
|
||||||
let weapon_damage_bonus = weapon_info.damage_bonus;
|
let weapon_damage_bonus = weapon_info.damage_bonus;
|
||||||
@ -171,7 +169,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
|
|
||||||
// Proc effects
|
// Proc effects
|
||||||
if let Some(chance) = &weapon_info.proc_chance {
|
if let Some(chance) = &weapon_info.proc_chance {
|
||||||
if rng.roll_dice(1, 100) <= (chance * 100.0) as i32 {
|
if roll_dice(1, 100) <= (chance * 100.0) as i32 {
|
||||||
let effect_target = if weapon_info.proc_target.unwrap() == "Self" {
|
let effect_target = if weapon_info.proc_target.unwrap() == "Self" {
|
||||||
Targets::Single { target: entity }
|
Targets::Single { target: entity }
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
use rltk::{to_cp437, LineAlg, Point, RandomNumberGenerator};
|
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, Name, NaturalAttackDefense,
|
Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, Name, NaturalAttackDefense,
|
||||||
@ -7,6 +7,7 @@ use crate::components::{
|
|||||||
};
|
};
|
||||||
use crate::effects::{add_effect, EffectType, Targets};
|
use crate::effects::{add_effect, EffectType, Targets};
|
||||||
use crate::gamesystem::skill_bonus;
|
use crate::gamesystem::skill_bonus;
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, gamelog, Map};
|
use crate::{colors, gamelog, Map};
|
||||||
|
|
||||||
pub struct RangedCombatSystem {}
|
pub struct RangedCombatSystem {}
|
||||||
@ -21,7 +22,6 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
ReadStorage<'a, Skills>,
|
ReadStorage<'a, Skills>,
|
||||||
ReadStorage<'a, HungerClock>,
|
ReadStorage<'a, HungerClock>,
|
||||||
ReadStorage<'a, Pools>,
|
ReadStorage<'a, Pools>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
ReadStorage<'a, Equipped>,
|
ReadStorage<'a, Equipped>,
|
||||||
ReadStorage<'a, Weapon>,
|
ReadStorage<'a, Weapon>,
|
||||||
ReadStorage<'a, Wearable>,
|
ReadStorage<'a, Wearable>,
|
||||||
@ -39,7 +39,6 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
skills,
|
skills,
|
||||||
hunger_clock,
|
hunger_clock,
|
||||||
pools,
|
pools,
|
||||||
mut rng,
|
|
||||||
equipped_items,
|
equipped_items,
|
||||||
weapons,
|
weapons,
|
||||||
wearables,
|
wearables,
|
||||||
@ -104,7 +103,7 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
let attack_index = if nat.attacks.len() == 1 {
|
let attack_index = if nat.attacks.len() == 1 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
rng.roll_dice(1, nat.attacks.len() as i32) as usize - 1
|
roll_dice(1, nat.attacks.len() as i32) as usize - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
let attk = &nat.attacks[attack_index];
|
let attk = &nat.attacks[attack_index];
|
||||||
@ -125,7 +124,7 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let natural_roll = rng.roll_dice(1, 20);
|
let natural_roll = roll_dice(1, 20);
|
||||||
let attribute_hit_bonus = if weapon_info.attribute == WeaponAttribute::Might {
|
let attribute_hit_bonus = if weapon_info.attribute == WeaponAttribute::Might {
|
||||||
attacker_attributes.might.bonus
|
attacker_attributes.might.bonus
|
||||||
} else {
|
} else {
|
||||||
@ -165,7 +164,7 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
|
|
||||||
if natural_roll != 1 && (natural_roll == 20 || modified_hit_roll > armor_class) {
|
if natural_roll != 1 && (natural_roll == 20 || modified_hit_roll > armor_class) {
|
||||||
// Target hit! Until we support weapons, we're going with 1d4
|
// Target hit! Until we support weapons, we're going with 1d4
|
||||||
let base_damage = rng.roll_dice(1, 4);
|
let base_damage = roll_dice(1, 4);
|
||||||
let attr_damage_bonus = attacker_attributes.might.bonus;
|
let attr_damage_bonus = attacker_attributes.might.bonus;
|
||||||
let skill_damage_bonus = skill_bonus(Skill::Melee, &*attacker_skills);
|
let skill_damage_bonus = skill_bonus(Skill::Melee, &*attacker_skills);
|
||||||
let weapon_damage_bonus = weapon_info.damage_bonus;
|
let weapon_damage_bonus = weapon_info.damage_bonus;
|
||||||
@ -195,7 +194,7 @@ impl<'a> System<'a> for RangedCombatSystem {
|
|||||||
.log();
|
.log();
|
||||||
// Proc effects
|
// Proc effects
|
||||||
if let Some(chance) = &weapon_info.proc_chance {
|
if let Some(chance) = &weapon_info.proc_chance {
|
||||||
if rng.roll_dice(1, 100) <= (chance * 100.0) as i32 {
|
if roll_dice(1, 100) <= (chance * 100.0) as i32 {
|
||||||
let effect_target = if weapon_info.proc_target.unwrap() == "Self" {
|
let effect_target = if weapon_info.proc_target.unwrap() == "Self" {
|
||||||
Targets::Single { target: entity }
|
Targets::Single { target: entity }
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use ::rltk::{field_of_view, Point, RandomNumberGenerator};
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{BlocksVisibility, Hidden, Name};
|
use crate::components::{BlocksVisibility, Hidden, Name};
|
||||||
|
use crate::rng::roll_dice;
|
||||||
use crate::{colors, gamelog, spatial, Map, Player, Position, Viewshed};
|
use crate::{colors, gamelog, spatial, Map, Player, Position, Viewshed};
|
||||||
|
|
||||||
pub struct VisibilitySystem {}
|
pub struct VisibilitySystem {}
|
||||||
@ -15,23 +16,13 @@ impl<'a> System<'a> for VisibilitySystem {
|
|||||||
ReadStorage<'a, Position>,
|
ReadStorage<'a, Position>,
|
||||||
ReadStorage<'a, Player>,
|
ReadStorage<'a, Player>,
|
||||||
WriteStorage<'a, Hidden>,
|
WriteStorage<'a, Hidden>,
|
||||||
WriteExpect<'a, RandomNumberGenerator>,
|
|
||||||
ReadStorage<'a, Name>,
|
ReadStorage<'a, Name>,
|
||||||
ReadStorage<'a, BlocksVisibility>,
|
ReadStorage<'a, BlocksVisibility>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (
|
let (mut map, entities, mut viewshed, pos, player, mut hidden, names, blocks_visibility) =
|
||||||
mut map,
|
data;
|
||||||
entities,
|
|
||||||
mut viewshed,
|
|
||||||
pos,
|
|
||||||
player,
|
|
||||||
mut hidden,
|
|
||||||
mut rng,
|
|
||||||
names,
|
|
||||||
blocks_visibility,
|
|
||||||
) = data;
|
|
||||||
|
|
||||||
map.view_blocked.clear();
|
map.view_blocked.clear();
|
||||||
for (block_pos, _block) in (&pos, &blocks_visibility).join() {
|
for (block_pos, _block) in (&pos, &blocks_visibility).join() {
|
||||||
@ -64,7 +55,7 @@ impl<'a> System<'a> for VisibilitySystem {
|
|||||||
spatial::for_each_tile_content(idx, |e| {
|
spatial::for_each_tile_content(idx, |e| {
|
||||||
let maybe_hidden = hidden.get(e);
|
let maybe_hidden = hidden.get(e);
|
||||||
if let Some(_maybe_hidden) = maybe_hidden {
|
if let Some(_maybe_hidden) = maybe_hidden {
|
||||||
if rng.roll_dice(1, 24) == 1 {
|
if roll_dice(1, 24) == 1 {
|
||||||
let name = names.get(e);
|
let name = names.get(e);
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
gamelog::line("You spotted:")
|
gamelog::line("You spotted:")
|
||||||
|
Loading…
Reference in New Issue
Block a user