Skip to main content

veloren_common/terrain/
biome.rs

1use serde::{Deserialize, Serialize};
2use strum::EnumIter;
3
4#[derive(
5    Default, Debug, Copy, Clone, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, EnumIter,
6)]
7pub enum BiomeKind {
8    #[default]
9    Void,
10    Lake,
11    Grassland,
12    Ocean,
13    Mountain,
14    Snowland,
15    Desert,
16    Swamp,
17    Jungle,
18    Forest,
19    Savannah,
20    Taiga,
21}
22
23impl BiomeKind {
24    /// Roughly represents the difficulty of a biome (value between 1 and 5)
25    pub fn difficulty(&self) -> i32 {
26        match self {
27            BiomeKind::Void => 1,
28            BiomeKind::Lake => 1,
29            BiomeKind::Grassland => 2,
30            BiomeKind::Ocean => 1,
31            BiomeKind::Mountain => 1,
32            BiomeKind::Snowland => 2,
33            BiomeKind::Desert => 5,
34            BiomeKind::Swamp => 2,
35            BiomeKind::Jungle => 3,
36            BiomeKind::Forest => 1,
37            BiomeKind::Savannah => 2,
38            BiomeKind::Taiga => 2,
39        }
40    }
41}
42
43#[cfg(test)]
44#[test]
45fn test_biome_difficulty() {
46    use strum::IntoEnumIterator;
47
48    for biome_kind in BiomeKind::iter() {
49        assert!(
50            (1..=5).contains(&biome_kind.difficulty()),
51            "Biome {biome_kind:?} has invalid difficulty {}",
52            biome_kind.difficulty()
53        );
54    }
55}