2020-02-26 21:43:31 +00:00
|
|
|
mod settlement;
|
2019-08-23 19:56:21 +00:00
|
|
|
|
|
|
|
// Reexports
|
2020-02-26 21:43:31 +00:00
|
|
|
pub use self::settlement::Settlement;
|
2019-08-23 19:56:21 +00:00
|
|
|
|
2020-02-08 11:38:44 +00:00
|
|
|
use crate::{
|
|
|
|
column::ColumnSample,
|
|
|
|
util::{Grid, Sampler},
|
|
|
|
};
|
|
|
|
use common::{
|
|
|
|
terrain::Block,
|
2020-04-11 19:04:19 +00:00
|
|
|
vol::{BaseVol, RectSizedVol, ReadVol, WriteVol},
|
2020-02-08 11:38:44 +00:00
|
|
|
};
|
2020-03-27 23:06:23 +00:00
|
|
|
use std::{fmt, sync::Arc};
|
2019-08-23 19:56:21 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2020-04-01 20:38:01 +00:00
|
|
|
pub struct SpawnRules {
|
|
|
|
pub trees: bool,
|
|
|
|
}
|
|
|
|
|
2020-02-07 22:19:25 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum Site {
|
|
|
|
Settlement(Arc<Settlement>),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Site {
|
2020-02-09 21:56:52 +00:00
|
|
|
pub fn radius(&self) -> f32 {
|
|
|
|
match self {
|
|
|
|
Site::Settlement(settlement) => settlement.radius(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:38:01 +00:00
|
|
|
pub fn spawn_rules(&self, wpos: Vec2<i32>) -> SpawnRules {
|
2020-02-07 22:19:25 +00:00
|
|
|
match self {
|
2020-04-01 20:38:01 +00:00
|
|
|
Site::Settlement(s) => s.spawn_rules(wpos)
|
2020-02-07 22:19:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 11:38:44 +00:00
|
|
|
|
2020-02-26 22:44:30 +00:00
|
|
|
pub fn apply_to<'a>(
|
|
|
|
&'a self,
|
2020-02-08 11:38:44 +00:00
|
|
|
wpos2d: Vec2<i32>,
|
2020-02-26 22:44:30 +00:00
|
|
|
get_column: impl FnMut(Vec2<i32>) -> Option<&'a ColumnSample<'a>>,
|
2020-04-11 19:04:19 +00:00
|
|
|
vol: &mut (impl BaseVol<Vox = Block> + RectSizedVol + ReadVol + WriteVol),
|
2020-02-08 11:38:44 +00:00
|
|
|
) {
|
2020-02-08 19:58:42 +00:00
|
|
|
match self {
|
2020-02-26 22:44:30 +00:00
|
|
|
Site::Settlement(settlement) => settlement.apply_to(wpos2d, get_column, vol),
|
2020-02-08 19:58:42 +00:00
|
|
|
}
|
2020-02-08 11:38:44 +00:00
|
|
|
}
|
2020-02-07 22:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Settlement> for Site {
|
|
|
|
fn from(settlement: Settlement) -> Self { Site::Settlement(Arc::new(settlement)) }
|
|
|
|
}
|
2020-03-27 23:06:23 +00:00
|
|
|
|
|
|
|
impl fmt::Debug for Site {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Site::Settlement(_) => write!(f, "Settlement"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|