FillEdges map builder, to fill walkable edges with overmap transition
This commit is contained in:
parent
8e3ed5cead
commit
2890c16a3c
2 changed files with 20 additions and 8 deletions
|
|
@ -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<FillEdges> {
|
||||
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<FillEdges> {
|
||||
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<usize> = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue