Add wildlife density modifier to features.ron

This commit is contained in:
Imbris 2021-12-23 13:59:44 -05:00
parent 027f2f5719
commit 972c8ba41d
4 changed files with 8 additions and 3 deletions

View File

@ -10,4 +10,5 @@
paths: true,
spots: true,
site2: false,
wildlife_density: 1.0,
)

View File

@ -87,6 +87,8 @@ pub struct Features {
pub paths: bool,
pub spots: bool,
pub site2: bool,
// 1.0 is the default wildlife density
pub wildlife_density: f32,
}
impl assets::Asset for Features {

View File

@ -119,6 +119,7 @@ impl IndexOwned {
// Reload the fields from the asset handle, which is updated automatically
self.colors = self.index.colors.cloned();
self.features = self.index.features.cloned();
// Update wildlife spawns which is based on base_density in features
reload(self)
})
}

View File

@ -21,8 +21,6 @@ fn close(x: f32, tgt: f32, falloff: f32) -> f32 {
(1.0 - (x - tgt).abs() / falloff).max(0.0).powf(0.125)
}
const BASE_DENSITY: f32 = 1.0e-5; // Base wildlife density
#[derive(Clone, Debug, Deserialize)]
pub struct SpawnEntry {
/// User-facing info for wiki, statistical tools, etc.
@ -131,6 +129,7 @@ impl Pack {
pub type DensityFn = fn(&SimChunk, &ColumnSample) -> f32;
pub fn spawn_manifest() -> Vec<(&'static str, DensityFn)> {
const BASE_DENSITY: f32 = 1.0e-5; // Base wildlife density
// NOTE: Order matters.
// Entries with more specific requirements
// and overall scarcity should come first, where possible.
@ -317,6 +316,8 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
time: Option<&(TimeOfDay, Calendar)>,
) {
let scatter = &index.wildlife_spawns;
// Configurable density multiplier
let wildlife_density_modifier = index.features.wildlife_density;
for y in 0..vol.size_xy().y as i32 {
for x in 0..vol.size_xy().x as i32 {
@ -342,7 +343,7 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
.iter()
.enumerate()
.find_map(|(_i, (entry, get_density))| {
let density = get_density(chunk, col_sample);
let density = get_density(chunk, col_sample) * wildlife_density_modifier;
(density > 0.0)
.then(|| {
entry