2020-02-26 21:43:31 +00:00
|
|
|
mod settlement;
|
2020-04-15 19:41:40 +00:00
|
|
|
mod dungeon;
|
2019-08-23 19:56:21 +00:00
|
|
|
|
|
|
|
// Reexports
|
2020-02-26 21:43:31 +00:00
|
|
|
pub use self::settlement::Settlement;
|
2020-04-15 19:41:40 +00:00
|
|
|
pub use self::dungeon::Dungeon;
|
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-15 19:41:40 +00:00
|
|
|
vol::{Vox, 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-15 19:41:40 +00:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct BlockMask {
|
|
|
|
block: Block,
|
|
|
|
priority: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BlockMask {
|
|
|
|
pub fn new(block: Block, priority: i32) -> Self {
|
|
|
|
Self { block, priority }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn nothing() -> Self {
|
|
|
|
Self {
|
|
|
|
block: Block::empty(),
|
|
|
|
priority: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_priority(mut self, priority: i32) -> Self {
|
|
|
|
self.priority = priority;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn resolve_with(self, other: Self) -> Self {
|
|
|
|
if self.priority >= other.priority {
|
|
|
|
self
|
|
|
|
} else {
|
|
|
|
other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn finish(self) -> Option<Block> {
|
|
|
|
if self.priority > 0 {
|
|
|
|
Some(self.block)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:38:01 +00:00
|
|
|
pub struct SpawnRules {
|
|
|
|
pub trees: bool,
|
|
|
|
}
|
|
|
|
|
2020-04-15 19:41:40 +00:00
|
|
|
impl Default for SpawnRules {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
trees: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 22:19:25 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum Site {
|
|
|
|
Settlement(Arc<Settlement>),
|
2020-04-15 19:41:40 +00:00
|
|
|
Dungeon(Arc<Dungeon>),
|
2020-02-07 22:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Site {
|
2020-02-09 21:56:52 +00:00
|
|
|
pub fn radius(&self) -> f32 {
|
|
|
|
match self {
|
|
|
|
Site::Settlement(settlement) => settlement.radius(),
|
2020-04-15 19:41:40 +00:00
|
|
|
Site::Dungeon(dungeon) => dungeon.radius(),
|
2020-02-09 21:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-15 19:41:40 +00:00
|
|
|
Site::Settlement(s) => s.spawn_rules(wpos),
|
|
|
|
Site::Dungeon(d) => d.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-04-15 19:41:40 +00:00
|
|
|
Site::Dungeon(dungeon) => dungeon.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
|
|
|
|
2020-04-15 19:41:40 +00:00
|
|
|
impl From<Dungeon> for Site {
|
|
|
|
fn from(dungeon: Dungeon) -> Self { Site::Dungeon(Arc::new(dungeon)) }
|
|
|
|
}
|
|
|
|
|
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"),
|
2020-04-15 19:41:40 +00:00
|
|
|
Site::Dungeon(_) => write!(f, "Dungeon"),
|
2020-03-27 23:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|