veloren_common/
spot.rs

1use common_assets::{Asset, AssetCombined, AssetHandle, Concatenate, RonLoader};
2use lazy_static::lazy_static;
3
4use crate::terrain::BiomeKind;
5
6#[derive(serde::Deserialize, Clone, Debug)]
7pub enum SpotCondition {
8    MaxGradient(f32),
9    Biome(Vec<BiomeKind>),
10    NearCliffs,
11    NearRiver,
12    IsWay,
13    IsUnderwater,
14
15    /// no cliffs, no river, no way
16    Typical,
17    /// implies IsUnderwater
18    MinWaterDepth(f32),
19
20    Not(Box<SpotCondition>),
21    All(Vec<SpotCondition>),
22    Any(Vec<SpotCondition>),
23}
24
25#[derive(serde::Deserialize, Clone, Debug)]
26pub struct SpotProperties {
27    pub base_structures: String,
28    pub freq: f32,
29    pub condition: SpotCondition,
30    pub spawn: bool,
31}
32
33#[derive(serde::Deserialize, Clone, Debug)]
34#[serde(transparent)]
35pub struct RonSpots(pub Vec<SpotProperties>);
36
37impl Asset for RonSpots {
38    type Loader = RonLoader;
39
40    const EXTENSION: &'static str = "ron";
41}
42
43impl Concatenate for RonSpots {
44    fn concatenate(self, b: Self) -> Self { Self(self.0.concatenate(b.0)) }
45}
46
47lazy_static! {
48    pub static ref RON_SPOT_PROPERTIES: RonSpots = {
49        let spots: AssetHandle<RonSpots> =
50            RonSpots::load_expect_combined_static("world.manifests.spots");
51        RonSpots(spots.read().0.to_vec())
52    };
53}