veloren/world/src/all.rs

133 lines
3.7 KiB
Rust
Raw Normal View History

2021-03-05 01:23:11 +00:00
use crate::util::math::close;
use std::ops::Range;
use strum::EnumIter;
2022-03-02 16:28:04 +00:00
use vek::Vec2;
2021-02-07 19:55:13 +00:00
#[derive(Copy, Clone, Debug, EnumIter)]
2019-06-11 18:39:25 +00:00
pub enum ForestKind {
Palm,
Acacia,
Baobab,
2019-06-11 18:39:25 +00:00
Oak,
2021-08-29 17:38:34 +00:00
Chestnut,
Cedar,
2019-06-11 18:39:25 +00:00
Pine,
2022-03-02 19:04:34 +00:00
Redwood,
2020-11-09 22:59:41 +00:00
Birch,
2019-08-18 16:35:27 +00:00
Mangrove,
2021-02-07 23:50:05 +00:00
Giant,
Swamp,
2022-02-06 05:43:46 +00:00
Frostpine,
2022-03-02 17:29:42 +00:00
Dead,
2019-06-11 18:39:25 +00:00
}
2021-02-07 19:55:13 +00:00
pub struct Environment {
pub humid: f32,
pub temp: f32,
pub near_water: f32,
}
impl ForestKind {
pub fn humid_range(&self) -> Range<f32> {
match self {
ForestKind::Palm => 0.25..1.4,
2021-02-07 23:50:05 +00:00
ForestKind::Acacia => 0.05..0.55,
2021-02-07 19:55:13 +00:00
ForestKind::Baobab => 0.2..0.6,
2021-02-07 23:50:05 +00:00
ForestKind::Oak => 0.35..1.5,
2021-08-29 17:38:34 +00:00
ForestKind::Chestnut => 0.35..1.5,
ForestKind::Cedar => 0.275..1.45,
2021-02-07 19:55:13 +00:00
ForestKind::Pine => 0.2..1.4,
2022-03-02 19:04:34 +00:00
ForestKind::Redwood => 0.6..1.0,
2022-02-06 05:43:46 +00:00
ForestKind::Frostpine => 0.2..1.4,
2021-02-07 19:55:13 +00:00
ForestKind::Birch => 0.0..0.6,
2021-09-01 14:08:50 +00:00
ForestKind::Mangrove => 0.5..1.3,
2021-02-07 19:55:13 +00:00
ForestKind::Swamp => 0.5..1.1,
2022-03-02 17:29:42 +00:00
ForestKind::Dead => 0.0..1.5,
2021-03-05 01:23:11 +00:00
_ => 0.0..0.0,
2021-02-07 19:55:13 +00:00
}
}
pub fn temp_range(&self) -> Range<f32> {
match self {
ForestKind::Palm => 0.4..1.6,
2021-02-07 23:50:05 +00:00
ForestKind::Acacia => 0.3..1.6,
2021-02-07 19:55:13 +00:00
ForestKind::Baobab => 0.4..0.9,
2021-08-29 17:38:34 +00:00
ForestKind::Oak => -0.35..0.45,
ForestKind::Chestnut => -0.35..0.45,
ForestKind::Cedar => -0.65..0.15,
2022-02-06 05:43:46 +00:00
ForestKind::Pine => -0.85..-0.2,
2022-03-02 19:04:34 +00:00
ForestKind::Redwood => -0.5..-0.3,
2022-02-06 05:43:46 +00:00
ForestKind::Frostpine => -1.8..-0.8,
2021-02-07 19:55:13 +00:00
ForestKind::Birch => -0.7..0.25,
2021-09-01 14:08:50 +00:00
ForestKind::Mangrove => 0.35..1.6,
2021-02-07 19:55:13 +00:00
ForestKind::Swamp => -0.6..0.8,
2022-03-02 17:29:42 +00:00
ForestKind::Dead => -1.5..1.0,
2021-02-07 23:50:05 +00:00
_ => 0.0..0.0,
2021-02-07 19:55:13 +00:00
}
}
pub fn near_water_range(&self) -> Option<Range<f32>> {
match self {
ForestKind::Palm => Some(0.35..1.8),
ForestKind::Swamp => Some(0.5..1.8),
_ => None,
}
}
/// The relative rate at which this tree appears under ideal conditions
pub fn ideal_proclivity(&self) -> f32 {
match self {
ForestKind::Palm => 0.4,
ForestKind::Acacia => 0.6,
ForestKind::Baobab => 0.2,
ForestKind::Oak => 1.0,
2021-08-29 17:38:34 +00:00
ForestKind::Chestnut => 0.3,
ForestKind::Cedar => 0.3,
2021-02-07 19:55:13 +00:00
ForestKind::Pine => 1.0,
2022-03-02 19:04:34 +00:00
ForestKind::Redwood => 2.5,
2022-02-06 05:43:46 +00:00
ForestKind::Frostpine => 1.0,
2021-02-07 19:55:13 +00:00
ForestKind::Birch => 0.65,
2021-08-29 17:38:34 +00:00
ForestKind::Mangrove => 2.0,
2021-02-07 19:55:13 +00:00
ForestKind::Swamp => 1.0,
2022-03-02 17:29:42 +00:00
ForestKind::Dead => 0.01,
2021-02-07 23:50:05 +00:00
_ => 0.0,
2021-02-07 19:55:13 +00:00
}
}
pub fn shrub_density_factor(&self) -> f32 {
match self {
ForestKind::Palm => 0.2,
ForestKind::Acacia => 0.3,
ForestKind::Baobab => 0.2,
ForestKind::Oak => 0.4,
ForestKind::Chestnut => 0.3,
ForestKind::Cedar => 0.3,
2022-02-06 05:43:46 +00:00
ForestKind::Pine => 0.5,
ForestKind::Frostpine => 0.3,
ForestKind::Birch => 0.65,
ForestKind::Mangrove => 1.0,
ForestKind::Swamp => 0.4,
2021-10-26 00:20:59 +00:00
_ => 1.0,
}
}
2021-02-07 19:55:13 +00:00
pub fn proclivity(&self, env: &Environment) -> f32 {
self.ideal_proclivity()
2021-03-05 01:23:11 +00:00
* close(env.humid, self.humid_range())
* close(env.temp, self.temp_range())
* self.near_water_range().map_or(1.0, |near_water_range| {
close(env.near_water, near_water_range)
})
2021-02-07 19:55:13 +00:00
}
}
2022-03-02 16:28:04 +00:00
/// Not currently used with trees generated by the tree layer, needs to be
/// reworked
2021-02-07 19:55:13 +00:00
pub struct TreeAttr {
pub pos: Vec2<i32>,
pub seed: u32,
pub scale: f32,
pub forest_kind: ForestKind,
2021-02-08 17:57:55 +00:00
pub inhabited: bool,
2021-02-07 19:55:13 +00:00
}