forest tweaks - foliage and proper grass
This commit is contained in:
parent
d032c847a0
commit
3301feaae0
5 changed files with 67 additions and 19 deletions
|
|
@ -19,32 +19,32 @@ pub const LONG_PARTICLE_LIFETIME: f32 = 300.0;
|
||||||
pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0);
|
pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0);
|
||||||
// DEFAULT THEME
|
// DEFAULT THEME
|
||||||
pub const DEFAULT_BG_COLOUR: (u8, u8, u8) = (29, 50, 50);
|
pub const DEFAULT_BG_COLOUR: (u8, u8, u8) = (29, 50, 50);
|
||||||
pub const DEFAULT_BG_OFFSETS: (i32, i32, i32) = (5, 5, 5);
|
pub const DEFAULT_BG_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const WALL_COLOUR: (u8, u8, u8) = (229, 191, 94);
|
pub const WALL_COLOUR: (u8, u8, u8) = (229, 191, 94);
|
||||||
pub const WALL_OFFSETS: (i32, i32, i32) = (48, 48, 48);
|
pub const WALL_OFFSETS: (i32, i32, i32) = (48, 48, 48);
|
||||||
pub const FLOOR_COLOUR: (u8, u8, u8) = (25, 204, 122);
|
pub const FLOOR_COLOUR: (u8, u8, u8) = (25, 204, 122);
|
||||||
pub const FLOOR_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const FLOOR_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const STAIR_COLOUR: (u8, u8, u8) = (200, 200, 0);
|
pub const STAIR_COLOUR: (u8, u8, u8) = (200, 200, 0);
|
||||||
pub const STAIR_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const STAIR_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const WOOD_FLOOR_COLOUR: (u8, u8, u8) = (41, 30, 20);
|
pub const WOOD_FLOOR_COLOUR: (u8, u8, u8) = (41, 30, 20);
|
||||||
pub const WOOD_FLOOR_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const WOOD_FLOOR_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const FENCE_FG_COLOUR: (u8, u8, u8) = (110, 24, 0);
|
pub const FENCE_FG_COLOUR: (u8, u8, u8) = (110, 24, 0);
|
||||||
pub const FENCE_COLOUR: (u8, u8, u8) = (45, 30, 10);
|
pub const FENCE_COLOUR: (u8, u8, u8) = (45, 30, 10);
|
||||||
pub const FENCE_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const FENCE_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const BRIDGE_COLOUR: (u8, u8, u8) = (42, 48, 37);
|
pub const BRIDGE_COLOUR: (u8, u8, u8) = (42, 48, 37);
|
||||||
pub const BRIDGE_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const BRIDGE_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const GRAVEL_COLOUR: (u8, u8, u8) = (26, 26, 53);
|
pub const GRAVEL_COLOUR: (u8, u8, u8) = (26, 26, 53);
|
||||||
pub const GRAVEL_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const GRAVEL_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const ROAD_COLOUR: (u8, u8, u8) = (8, 38, 40);
|
pub const ROAD_COLOUR: (u8, u8, u8) = (8, 38, 40);
|
||||||
pub const ROAD_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const ROAD_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const GRASS_COLOUR: (u8, u8, u8) = (9, 65, 6);
|
pub const GRASS_COLOUR: (u8, u8, u8) = (9, 65, 6);
|
||||||
pub const GRASS_OFFSETS: (i32, i32, i32) = (3, 40, 3);
|
pub const GRASS_OFFSETS: (i32, i32, i32) = (3, 20, 10);
|
||||||
pub const FOLIAGE_COLOUR: (u8, u8, u8) = (5, 60, 5);
|
pub const FOLIAGE_COLOUR: (u8, u8, u8) = (5, 60, 5);
|
||||||
pub const FOLIAGE_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const FOLIAGE_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const HEAVY_FOLIAGE_COLOUR: (u8, u8, u8) = (5, 60, 5);
|
pub const HEAVY_FOLIAGE_COLOUR: (u8, u8, u8) = (5, 60, 5);
|
||||||
pub const HEAVY_FOLIAGE_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const HEAVY_FOLIAGE_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const SAND_COLOUR: (u8, u8, u8) = (70, 70, 21);
|
pub const SAND_COLOUR: (u8, u8, u8) = (70, 70, 21);
|
||||||
pub const SAND_OFFSETS: (i32, i32, i32) = (0, 0, 0);
|
pub const SAND_OFFSETS: (i32, i32, i32) = (10, 10, 10);
|
||||||
pub const SHALLOW_WATER_COLOUR: (u8, u8, u8) = (24, 47, 99);
|
pub const SHALLOW_WATER_COLOUR: (u8, u8, u8) = (24, 47, 99);
|
||||||
pub const SHALLOW_WATER_OFFSETS: (i32, i32, i32) = (3, 10, 45);
|
pub const SHALLOW_WATER_OFFSETS: (i32, i32, i32) = (3, 10, 45);
|
||||||
pub const DEEP_WATER_COLOUR: (u8, u8, u8) = (18, 33, 63);
|
pub const DEEP_WATER_COLOUR: (u8, u8, u8) = (18, 33, 63);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
use super::{ BuilderMap, InitialMapBuilder, MetaMapBuilder, TileType };
|
use super::{ BuilderMap, InitialMapBuilder, MetaMapBuilder, TileType };
|
||||||
use rltk::RandomNumberGenerator;
|
use rltk::RandomNumberGenerator;
|
||||||
|
|
||||||
pub struct CellularAutomataBuilder {}
|
pub struct CellularAutomataBuilder {
|
||||||
|
floor_tile: TileType,
|
||||||
|
}
|
||||||
|
|
||||||
impl InitialMapBuilder for CellularAutomataBuilder {
|
impl InitialMapBuilder for CellularAutomataBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -20,7 +22,10 @@ impl MetaMapBuilder for CellularAutomataBuilder {
|
||||||
impl CellularAutomataBuilder {
|
impl CellularAutomataBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new() -> Box<CellularAutomataBuilder> {
|
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)]
|
#[allow(clippy::map_entry)]
|
||||||
|
|
@ -80,7 +85,7 @@ impl CellularAutomataBuilder {
|
||||||
if neighbors > 4 || neighbors == 0 {
|
if neighbors > 4 || neighbors == 0 {
|
||||||
newtiles[idx] = TileType::Wall;
|
newtiles[idx] = TileType::Wall;
|
||||||
} else {
|
} 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,
|
VoronoiSpawning,
|
||||||
XStart,
|
XStart,
|
||||||
YStart,
|
YStart,
|
||||||
|
Foliage,
|
||||||
};
|
};
|
||||||
use rltk::prelude::*;
|
use rltk::prelude::*;
|
||||||
use crate::data::names::*;
|
use crate::data::names::*;
|
||||||
|
|
@ -30,13 +31,15 @@ pub fn forest_builder(
|
||||||
NAME_FOREST_BUILDER,
|
NAME_FOREST_BUILDER,
|
||||||
initial_player_level
|
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(AreaStartingPosition::new(XStart::CENTRE, YStart::CENTRE));
|
||||||
chain.with(CullUnreachable::new());
|
chain.with(CullUnreachable::new());
|
||||||
chain.with(AreaStartingPosition::new(XStart::LEFT, YStart::CENTRE));
|
chain.with(AreaStartingPosition::new(XStart::LEFT, YStart::CENTRE));
|
||||||
// Setup an exit and spawn mobs
|
// Setup an exit and spawn mobs
|
||||||
chain.with(VoronoiSpawning::new());
|
chain.with(VoronoiSpawning::new());
|
||||||
chain.with(RoadExit::new());
|
chain.with(RoadExit::new());
|
||||||
|
chain.with(Foliage::percent(TileType::Grass, 30));
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,9 +120,9 @@ impl RoadExit {
|
||||||
let stream_idx = build_data.map.xy_idx(stream_x, stream_y) as usize;
|
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);
|
let stream = a_star_search(stairs_idx, stream_idx, &mut build_data.map);
|
||||||
for tile in stream.steps.iter() {
|
for tile in stream.steps.iter() {
|
||||||
if build_data.map.tiles[*tile as usize] == TileType::Floor {
|
// Maybe only turn grass to water here, and turn the road into a bridge.
|
||||||
build_data.map.tiles[*tile as usize] = TileType::ShallowWater;
|
// 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.map.tiles[stairs_idx] = TileType::DownStair;
|
||||||
build_data.take_snapshot();
|
build_data.take_snapshot();
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ mod town;
|
||||||
use town::town_builder;
|
use town::town_builder;
|
||||||
mod forest;
|
mod forest;
|
||||||
use forest::forest_builder;
|
use forest::forest_builder;
|
||||||
|
mod foliage;
|
||||||
|
use foliage::Foliage;
|
||||||
|
|
||||||
// Shared data to be passed around build chain
|
// Shared data to be passed around build chain
|
||||||
pub struct BuilderMap {
|
pub struct BuilderMap {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue