2020-06-17 18:05:47 +00:00
|
|
|
mod block_mask;
|
2020-06-27 23:37:14 +00:00
|
|
|
mod castle;
|
2020-06-28 15:09:31 +00:00
|
|
|
mod dungeon;
|
2020-06-17 18:05:47 +00:00
|
|
|
pub mod economy;
|
2020-04-17 23:29:01 +00:00
|
|
|
mod settlement;
|
2019-08-23 19:56:21 +00:00
|
|
|
|
|
|
|
// Reexports
|
2020-06-27 23:37:14 +00:00
|
|
|
pub use self::{
|
2020-06-28 15:09:31 +00:00
|
|
|
block_mask::BlockMask, castle::Castle, dungeon::Dungeon, economy::Economy,
|
2020-06-27 23:37:14 +00:00
|
|
|
settlement::Settlement,
|
|
|
|
};
|
2019-08-23 19:56:21 +00:00
|
|
|
|
2020-04-23 15:16:08 +00:00
|
|
|
use crate::column::ColumnSample;
|
2020-02-08 11:38:44 +00:00
|
|
|
use common::{
|
2020-04-16 21:01:13 +00:00
|
|
|
generation::ChunkSupplement,
|
2020-04-17 23:29:01 +00:00
|
|
|
terrain::Block,
|
|
|
|
vol::{BaseVol, ReadVol, RectSizedVol, Vox, WriteVol},
|
2020-02-08 11:38:44 +00:00
|
|
|
};
|
2020-04-18 20:26:43 +00:00
|
|
|
use rand::Rng;
|
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-04-15 19:41:40 +00:00
|
|
|
impl Default for SpawnRules {
|
2020-04-17 23:29:01 +00:00
|
|
|
fn default() -> Self { Self { trees: true } }
|
2020-04-15 19:41:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 18:05:47 +00:00
|
|
|
pub struct Site {
|
|
|
|
pub kind: SiteKind,
|
|
|
|
pub economy: Economy,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum SiteKind {
|
|
|
|
Settlement(Settlement),
|
|
|
|
Dungeon(Dungeon),
|
2020-06-27 23:37:14 +00:00
|
|
|
Castle(Castle),
|
2020-02-07 22:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Site {
|
2020-06-17 18:05:47 +00:00
|
|
|
pub fn settlement(s: Settlement) -> Self {
|
|
|
|
Self {
|
|
|
|
kind: SiteKind::Settlement(s),
|
|
|
|
economy: Economy::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dungeon(d: Dungeon) -> Self {
|
|
|
|
Self {
|
|
|
|
kind: SiteKind::Dungeon(d),
|
|
|
|
economy: Economy::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-27 23:37:14 +00:00
|
|
|
pub fn castle(c: Castle) -> Self {
|
|
|
|
Self {
|
|
|
|
kind: SiteKind::Castle(c),
|
|
|
|
economy: Economy::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 21:56:52 +00:00
|
|
|
pub fn radius(&self) -> f32 {
|
2020-06-17 18:05:47 +00:00
|
|
|
match &self.kind {
|
2020-06-27 23:37:14 +00:00
|
|
|
SiteKind::Settlement(s) => s.radius(),
|
|
|
|
SiteKind::Dungeon(d) => d.radius(),
|
|
|
|
SiteKind::Castle(c) => c.radius(),
|
2020-02-09 21:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 20:59:09 +00:00
|
|
|
pub fn get_origin(&self) -> Vec2<i32> {
|
2020-06-17 18:05:47 +00:00
|
|
|
match &self.kind {
|
|
|
|
SiteKind::Settlement(s) => s.get_origin(),
|
|
|
|
SiteKind::Dungeon(d) => d.get_origin(),
|
2020-06-27 23:37:14 +00:00
|
|
|
SiteKind::Castle(c) => c.get_origin(),
|
2020-04-23 20:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:38:01 +00:00
|
|
|
pub fn spawn_rules(&self, wpos: Vec2<i32>) -> SpawnRules {
|
2020-06-17 18:05:47 +00:00
|
|
|
match &self.kind {
|
|
|
|
SiteKind::Settlement(s) => s.spawn_rules(wpos),
|
|
|
|
SiteKind::Dungeon(d) => d.spawn_rules(wpos),
|
2020-06-27 23:37:14 +00:00
|
|
|
SiteKind::Castle(c) => c.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-06-17 18:05:47 +00:00
|
|
|
match &self.kind {
|
2020-06-27 23:37:14 +00:00
|
|
|
SiteKind::Settlement(s) => s.apply_to(wpos2d, get_column, vol),
|
|
|
|
SiteKind::Dungeon(d) => d.apply_to(wpos2d, get_column, vol),
|
|
|
|
SiteKind::Castle(c) => c.apply_to(wpos2d, get_column, vol),
|
2020-02-08 19:58:42 +00:00
|
|
|
}
|
2020-02-08 11:38:44 +00:00
|
|
|
}
|
2020-04-16 21:01:13 +00:00
|
|
|
|
|
|
|
pub fn apply_supplement<'a>(
|
|
|
|
&'a self,
|
2020-04-18 20:26:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2020-04-16 21:01:13 +00:00
|
|
|
wpos2d: Vec2<i32>,
|
|
|
|
get_column: impl FnMut(Vec2<i32>) -> Option<&'a ColumnSample<'a>>,
|
|
|
|
supplement: &mut ChunkSupplement,
|
|
|
|
) {
|
2020-06-17 18:05:47 +00:00
|
|
|
match &self.kind {
|
2020-06-27 23:37:14 +00:00
|
|
|
SiteKind::Settlement(s) => s.apply_supplement(rng, wpos2d, get_column, supplement),
|
|
|
|
SiteKind::Dungeon(d) => d.apply_supplement(rng, wpos2d, get_column, supplement),
|
|
|
|
SiteKind::Castle(c) => c.apply_supplement(rng, wpos2d, get_column, supplement),
|
2020-03-27 23:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|