less blocking - targets will try to path to any space around their tar

This commit is contained in:
Llywelwyn 2023-08-30 09:15:45 +01:00
parent 340aefa9e1
commit 64caf0dc1a
16 changed files with 252 additions and 68 deletions

View file

@ -0,0 +1,78 @@
use super::{ BuilderMap, MetaMapBuilder, Rect, TileType };
use crate::tile_walkable;
use rltk::RandomNumberGenerator;
pub enum Theme {
Grass,
Forest,
}
pub struct ThemeRooms {
pub theme: Theme,
pub percent: i32,
}
impl MetaMapBuilder for ThemeRooms {
fn build_map(&mut self, rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap) {
self.build(rng, build_data);
}
}
impl ThemeRooms {
#[allow(dead_code)]
pub fn grass(percent: i32) -> Box<ThemeRooms> {
return Box::new(ThemeRooms { theme: Theme::Grass, percent });
}
pub fn forest(percent: i32) -> Box<ThemeRooms> {
return Box::new(ThemeRooms { theme: Theme::Forest, percent });
}
fn grassify(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap, room: &Rect) {
let (var_x, var_y) = (rng.roll_dice(1, 3), rng.roll_dice(1, 3));
let x1 = if room.x1 - var_x > 0 { room.x1 - var_x } else { room.x1 };
let x2 = if room.x2 + var_x < build_data.map.width - 1 { room.x2 + var_x } else { room.x2 };
let y1 = if room.y1 - var_y > 0 { room.y1 - var_y } else { room.y1 };
let y2 = if room.y2 + var_y < build_data.map.height - 1 { room.y2 + var_y } else { room.y2 };
for x in x1..x2 {
for y in y1..y2 {
let idx = build_data.map.xy_idx(x, y);
if tile_walkable(build_data.map.tiles[idx]) && build_data.map.tiles[idx] != TileType::DownStair {
let tar = if x < room.x1 || x > room.x2 || y < room.y1 || y > room.y2 { 45 } else { 90 };
if rng.roll_dice(1, 100) <= tar {
match rng.roll_dice(1, 6) {
1..=4 => {
build_data.map.tiles[idx] = TileType::Grass;
}
5 => {
build_data.map.tiles[idx] = TileType::Foliage;
}
_ => {
build_data.map.tiles[idx] = TileType::HeavyFoliage;
build_data.spawn_list.push((idx, "treant_small".to_string()));
}
}
}
}
}
}
}
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
let rooms: Vec<Rect>;
if let Some(rooms_builder) = &build_data.rooms {
rooms = rooms_builder.clone();
} else {
panic!("RoomCornerRounding requires a builder with rooms.");
}
for room in rooms.iter() {
if rng.roll_dice(1, 100) < self.percent {
match self.theme {
Theme::Grass => self.grassify(rng, build_data, room),
_ => {}
}
build_data.take_snapshot();
}
}
}
}