diff --git a/src/data/visuals.rs b/src/data/visuals.rs index b1c2217..1ac0998 100644 --- a/src/data/visuals.rs +++ b/src/data/visuals.rs @@ -19,32 +19,32 @@ pub const LONG_PARTICLE_LIFETIME: f32 = 300.0; pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0); // DEFAULT THEME 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_OFFSETS: (i32, i32, i32) = (48, 48, 48); 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_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_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_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_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_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_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_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_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_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_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_OFFSETS: (i32, i32, i32) = (3, 10, 45); pub const DEEP_WATER_COLOUR: (u8, u8, u8) = (18, 33, 63); diff --git a/src/map_builders/cellular_automata.rs b/src/map_builders/cellular_automata.rs index 2830bd8..5bbf361 100644 --- a/src/map_builders/cellular_automata.rs +++ b/src/map_builders/cellular_automata.rs @@ -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 { - Box::new(CellularAutomataBuilder {}) + Box::new(CellularAutomataBuilder { floor_tile: TileType::Floor }) + } + pub fn floor(floor_tile: TileType) -> Box { + 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; } } } diff --git a/src/map_builders/foliage.rs b/src/map_builders/foliage.rs new file mode 100644 index 0000000..34b5151 --- /dev/null +++ b/src/map_builders/foliage.rs @@ -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 { + 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; + } + }; + } + } + } + } +} diff --git a/src/map_builders/forest.rs b/src/map_builders/forest.rs index 8bdfc00..2c74be8 100644 --- a/src/map_builders/forest.rs +++ b/src/map_builders/forest.rs @@ -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(); diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index d170b1e..56fe035 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -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 {