diff --git a/src/map_builders/fill_edges.rs b/src/map_builders/fill_edges.rs index 9b42c81..b05e691 100644 --- a/src/map_builders/fill_edges.rs +++ b/src/map_builders/fill_edges.rs @@ -1,8 +1,10 @@ use super::{ BuilderMap, MetaMapBuilder, TileType }; +use crate::tile_walkable; use rltk::RandomNumberGenerator; pub struct FillEdges { fill_with: TileType, + only_walkable: bool, } impl MetaMapBuilder for FillEdges { @@ -15,21 +17,32 @@ impl MetaMapBuilder for FillEdges { impl FillEdges { #[allow(dead_code)] pub fn wall() -> Box { - return Box::new(FillEdges { fill_with: TileType::Wall }); + return Box::new(FillEdges { fill_with: TileType::Wall, only_walkable: false }); + } + pub fn overmap_transition(id: i32) -> Box { + return Box::new(FillEdges { fill_with: TileType::ToOvermap(id), only_walkable: true }); } fn fill_edges(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) { + // Get map edges as possible points to fill + let mut possible_idxs: Vec = Vec::new(); for x in 0..build_data.map.width { let mut idx = build_data.map.xy_idx(x, 0); - build_data.map.tiles[idx] = self.fill_with; + possible_idxs.push(idx); idx = build_data.map.xy_idx(x, build_data.map.height - 1); - build_data.map.tiles[idx] = self.fill_with; + possible_idxs.push(idx); } for y in 0..build_data.map.height { let mut idx = build_data.map.xy_idx(0, y); - build_data.map.tiles[idx] = self.fill_with; + possible_idxs.push(idx); idx = build_data.map.xy_idx(build_data.map.width - 1, y); - build_data.map.tiles[idx] = self.fill_with; + possible_idxs.push(idx); + } + // For every possible point, first check if we only want to fill walkable tiles (and if its walkable if so) + for idx in possible_idxs { + if !self.only_walkable || tile_walkable(build_data.map.tiles[idx]) { + build_data.map.tiles[idx] = self.fill_with; + } } } } diff --git a/src/map_builders/town.rs b/src/map_builders/town.rs index b768219..1727f56 100644 --- a/src/map_builders/town.rs +++ b/src/map_builders/town.rs @@ -1,4 +1,4 @@ -use super::{ BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType }; +use super::{ BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType, FillEdges }; use std::collections::HashSet; use crate::data::names::*; @@ -21,6 +21,7 @@ pub fn town_builder( initial_player_level ); chain.start_with(TownBuilder::new()); + chain.with(FillEdges::overmap_transition(new_id)); return chain; } @@ -74,8 +75,6 @@ impl TownBuilder { x: build_data.width - 2, y: wall_gap_y, }); - let overmap_entrance = build_data.map.xy_idx(build_data.width - 2, wall_gap_y); - build_data.map.tiles[overmap_entrance] = TileType::ToOvermap(build_data.map.id); build_data.take_snapshot(); }