forest tweaks - foliage and proper grass
This commit is contained in:
parent
d032c847a0
commit
3301feaae0
5 changed files with 67 additions and 19 deletions
|
|
@ -1,7 +1,9 @@
|
|||
use super::{ BuilderMap, InitialMapBuilder, MetaMapBuilder, TileType };
|
||||
use rltk::RandomNumberGenerator;
|
||||
|
||||
pub struct CellularAutomataBuilder {}
|
||||
pub struct CellularAutomataBuilder {
|
||||
floor_tile: TileType,
|
||||
}
|
||||
|
||||
impl InitialMapBuilder for CellularAutomataBuilder {
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -20,7 +22,10 @@ impl MetaMapBuilder for CellularAutomataBuilder {
|
|||
impl CellularAutomataBuilder {
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Box<CellularAutomataBuilder> {
|
||||
Box::new(CellularAutomataBuilder {})
|
||||
Box::new(CellularAutomataBuilder { floor_tile: TileType::Floor })
|
||||
}
|
||||
pub fn floor(floor_tile: TileType) -> Box<CellularAutomataBuilder> {
|
||||
Box::new(CellularAutomataBuilder { floor_tile })
|
||||
}
|
||||
|
||||
#[allow(clippy::map_entry)]
|
||||
|
|
@ -80,7 +85,7 @@ impl CellularAutomataBuilder {
|
|||
if neighbors > 4 || neighbors == 0 {
|
||||
newtiles[idx] = TileType::Wall;
|
||||
} else {
|
||||
newtiles[idx] = TileType::Floor;
|
||||
newtiles[idx] = self.floor_tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
src/map_builders/foliage.rs
Normal file
38
src/map_builders/foliage.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use super::{ BuilderMap, MetaMapBuilder, TileType };
|
||||
use rltk::RandomNumberGenerator;
|
||||
|
||||
pub struct Foliage {
|
||||
start_tile: TileType,
|
||||
percent: i32,
|
||||
}
|
||||
|
||||
impl MetaMapBuilder for Foliage {
|
||||
#[allow(dead_code)]
|
||||
fn build_map(&mut self, rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
self.apply(rng, build_data);
|
||||
}
|
||||
}
|
||||
|
||||
impl Foliage {
|
||||
#[allow(dead_code)]
|
||||
pub fn percent(start_tile: TileType, percent: i32) -> Box<Foliage> {
|
||||
return Box::new(Foliage { start_tile, percent });
|
||||
}
|
||||
|
||||
fn apply(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
for tile in build_data.map.tiles.iter_mut() {
|
||||
if *tile == self.start_tile {
|
||||
if rng.roll_dice(1, 100) < self.percent {
|
||||
match rng.roll_dice(1, 2) {
|
||||
1 => {
|
||||
*tile = TileType::Foliage;
|
||||
}
|
||||
_ => {
|
||||
*tile = TileType::HeavyFoliage;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ use super::{
|
|||
VoronoiSpawning,
|
||||
XStart,
|
||||
YStart,
|
||||
Foliage,
|
||||
};
|
||||
use rltk::prelude::*;
|
||||
use crate::data::names::*;
|
||||
|
|
@ -30,13 +31,15 @@ pub fn forest_builder(
|
|||
NAME_FOREST_BUILDER,
|
||||
initial_player_level
|
||||
);
|
||||
chain.start_with(CellularAutomataBuilder::new());
|
||||
chain.start_with(CellularAutomataBuilder::floor(TileType::Grass));
|
||||
// Change ~30% of the floor to some sort of foliage.
|
||||
chain.with(AreaStartingPosition::new(XStart::CENTRE, YStart::CENTRE));
|
||||
chain.with(CullUnreachable::new());
|
||||
chain.with(AreaStartingPosition::new(XStart::LEFT, YStart::CENTRE));
|
||||
// Setup an exit and spawn mobs
|
||||
chain.with(VoronoiSpawning::new());
|
||||
chain.with(RoadExit::new());
|
||||
chain.with(Foliage::percent(TileType::Grass, 30));
|
||||
return chain;
|
||||
}
|
||||
|
||||
|
|
@ -117,9 +120,9 @@ impl RoadExit {
|
|||
let stream_idx = build_data.map.xy_idx(stream_x, stream_y) as usize;
|
||||
let stream = a_star_search(stairs_idx, stream_idx, &mut build_data.map);
|
||||
for tile in stream.steps.iter() {
|
||||
if build_data.map.tiles[*tile as usize] == TileType::Floor {
|
||||
build_data.map.tiles[*tile as usize] = TileType::ShallowWater;
|
||||
}
|
||||
// Maybe only turn grass to water here, and turn the road into a bridge.
|
||||
// i.e. if build_data.map.tiles[*tile as usize] == TileType::Grass
|
||||
build_data.map.tiles[*tile as usize] = TileType::ShallowWater;
|
||||
}
|
||||
build_data.map.tiles[stairs_idx] = TileType::DownStair;
|
||||
build_data.take_snapshot();
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ mod town;
|
|||
use town::town_builder;
|
||||
mod forest;
|
||||
use forest::forest_builder;
|
||||
mod foliage;
|
||||
use foliage::Foliage;
|
||||
|
||||
// Shared data to be passed around build chain
|
||||
pub struct BuilderMap {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue