veloren/world/src/layer/wildlife.rs

1140 lines
46 KiB
Rust
Raw Normal View History

use crate::{column::ColumnSample, sim::SimChunk, IndexRef, CONFIG};
2020-10-01 21:00:46 +00:00
use common::{
2020-11-21 20:59:25 +00:00
comp::{
2021-04-11 22:22:08 +00:00
biped_large, bird_large, bird_medium, fish_medium, fish_small, quadruped_low,
quadruped_medium, quadruped_small, theropod, Alignment,
2020-11-21 20:59:25 +00:00
},
2020-10-06 08:18:35 +00:00
generation::{ChunkSupplement, EntityInfo},
2021-04-16 11:17:15 +00:00
resources::TimeOfDay,
terrain::Block,
2021-04-16 11:17:15 +00:00
time::DayPeriod::{self, Evening, Morning, Night, Noon},
2020-10-01 21:00:46 +00:00
vol::{BaseVol, ReadVol, RectSizedVol, WriteVol},
};
use rand::prelude::*;
use std::{f32, ops::Range};
use vek::*;
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
#[allow(clippy::eval_order_dependence)]
pub fn apply_wildlife_supplement<'a, R: Rng>(
// NOTE: Used only for dynamic elements like chests and entities!
dynamic_rng: &mut R,
wpos2d: Vec2<i32>,
mut get_column: impl FnMut(Vec2<i32>) -> Option<&'a ColumnSample<'a>>,
vol: &(impl BaseVol<Vox = Block> + RectSizedVol + ReadVol + WriteVol),
_index: IndexRef,
2020-10-01 21:00:46 +00:00
chunk: &SimChunk,
supplement: &mut ChunkSupplement,
2021-04-16 11:17:15 +00:00
time: Option<TimeOfDay>,
2020-10-01 21:00:46 +00:00
) {
2020-11-21 12:33:52 +00:00
struct Entry<R> {
make_entity: fn(Vec3<f32>, &mut R) -> EntityInfo, // Entity
group_size: Range<usize>, // Group size range
is_underwater: bool, // Underwater?
2021-04-16 11:17:15 +00:00
day_period: Vec<DayPeriod>, // Period of the day
2020-11-21 12:33:52 +00:00
get_density: fn(&SimChunk, &ColumnSample) -> f32, // Density
}
let scatter: &[Entry<R>] = &[
// Tundra snow pack ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-01-26 20:23:18 +00:00
.with_body(match rng.gen_range(0..3) {
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Frostfang,
)
.into(),
2020-11-21 20:59:25 +00:00
1 => {
theropod::Body::random_with(rng, &theropod::Species::Snowraptor).into()
},
2020-11-29 21:22:43 +00:00
_ => quadruped_medium::Body {
species: quadruped_medium::Species::Roshwalr,
body_type: quadruped_medium::BodyType::Male,
}
.into(),
})
.with_alignment(Alignment::Enemy)
},
group_size: 1..4,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
get_density: |c, col| {
close(c.temp, CONFIG.snow_temp, 0.3)
* BASE_DENSITY
* col.snow_cover as i32 as f32
* 1.0
},
},
// Tundra solitary ennemies
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-03-12 00:20:05 +00:00
.with_body(match rng.gen_range(0..4) {
0 => {
theropod::Body::random_with(rng, &theropod::Species::Snowraptor).into()
},
2021-03-12 00:20:05 +00:00
1 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Snowleopard,
)
.into(),
2 => theropod::Body::random_with(rng, &theropod::Species::Yale).into(),
_ => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Grolgar,
)
.into(),
})
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
2020-11-21 12:33:52 +00:00
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-03-18 00:56:27 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.snow_temp, 0.3) * col.tree_density * BASE_DENSITY * 1.4
},
2020-11-21 12:33:52 +00:00
},
// Tundra rare solitary ennemies
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
theropod::Body::random_with(rng, &theropod::Species::Snowraptor).into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
get_density: |c, _col| close(c.temp, CONFIG.snow_temp, 0.15) * BASE_DENSITY * 0.5,
},
2021-03-18 00:56:27 +00:00
// Tundra rarer solitary ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-06-24 21:04:17 +00:00
.with_body(match rng.gen_range(0..3) {
0 => biped_large::Body::random_with(rng, &biped_large::Species::Wendigo)
.into(),
2021-06-24 21:04:17 +00:00
1 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Mammoth,
)
.into(),
_ => biped_large::Body::random_with(
rng,
&biped_large::Species::Mountaintroll,
)
.into(),
})
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-06-24 21:04:17 +00:00
get_density: |c, _col| close(c.temp, CONFIG.snow_temp, 0.15) * BASE_DENSITY * 0.15,
2020-11-21 12:33:52 +00:00
},
2021-03-14 13:23:54 +00:00
// Tundra rock solitary ennemies
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Rocksnapper)
.into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-03-14 13:23:54 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.snow_temp, 0.15) * BASE_DENSITY * col.rock * 1.0
},
},
// Taiga rare solitary ennemies
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-03-18 00:56:27 +00:00
.with_body(match rng.gen_range(0..2) {
2021-03-14 13:23:54 +00:00
0 => biped_large::Body::random_with(rng, &biped_large::Species::Wendigo)
.into(),
_ => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Dreadhorn,
)
.into(),
})
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-03-14 13:23:54 +00:00
get_density: |c, col| {
2021-03-18 00:56:27 +00:00
close(c.temp, CONFIG.snow_temp + 0.2, 0.2) * col.tree_density * BASE_DENSITY * 0.4
2021-03-14 13:23:54 +00:00
},
},
2020-10-14 21:02:48 +00:00
// Taiga pack ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-06 08:18:35 +00:00
EntityInfo::at(pos)
.with_body(
quadruped_medium::Body::random_with(rng, &quadruped_medium::Species::Wolf)
.into(),
)
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 3..8,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * col.tree_density * BASE_DENSITY * 0.9
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
},
2020-10-14 21:02:48 +00:00
// Taiga pack wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-06 08:18:35 +00:00
EntityInfo::at(pos)
2021-06-22 23:43:18 +00:00
.with_body(match rng.gen_range(0..5) {
2021-01-13 23:45:56 +00:00
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Mouflon,
)
.into(),
1 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Yak,
)
.into(),
2021-06-22 23:43:18 +00:00
2 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Llama,
)
.into(),
3 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Alpaca,
)
.into(),
_ => quadruped_medium::Body::random_with(
2020-10-06 08:18:35 +00:00
rng,
&quadruped_medium::Species::Highland,
2020-10-06 08:18:35 +00:00
)
.into(),
})
2020-10-14 21:02:48 +00:00
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..4,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.2) * BASE_DENSITY * 1.0,
},
2020-10-14 21:02:48 +00:00
// Taiga solitary wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-03-18 00:56:27 +00:00
.with_body(match rng.gen_range(0..6) {
2020-10-14 21:02:48 +00:00
0 => {
bird_medium::Body::random_with(rng, &bird_medium::Species::Eagle).into()
},
2021-01-13 23:45:56 +00:00
1 => bird_medium::Body::random_with(rng, &bird_medium::Species::Owl).into(),
2 => quadruped_small::Body {
species: quadruped_small::Species::Fox,
body_type: quadruped_small::BodyType::Female,
}
.into(),
2021-03-12 00:20:05 +00:00
3 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Moose,
)
.into(),
2021-03-18 00:56:27 +00:00
4 => {
quadruped_small::Body {
species: quadruped_small::Species::Hare,
body_type: quadruped_small::BodyType::Female,
}
}
.into(),
2020-10-14 21:02:48 +00:00
_ => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Tuskram,
)
.into(),
})
.with_alignment(Alignment::Wild)
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * BASE_DENSITY * 5.0,
},
// Temperate solitary ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-02-18 00:41:34 +00:00
.with_body(match rng.gen_range(0..5) {
2020-10-14 21:02:48 +00:00
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Tarasque,
2020-10-14 21:02:48 +00:00
)
.into(),
1 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Bear,
)
.into(),
2 => {
2020-11-21 20:59:25 +00:00
theropod::Body::random_with(rng, &theropod::Species::Woodraptor).into()
},
2021-02-18 00:41:34 +00:00
3 => {
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Deadwood)
.into()
},
2020-10-14 21:02:48 +00:00
_ => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Saber,
2020-10-14 21:02:48 +00:00
)
.into(),
})
2020-10-06 08:18:35 +00:00
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
get_density: |c, col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.temperate_temp + 0.1, 0.5)
* col.tree_density
* BASE_DENSITY
* 1.0
},
2020-11-21 12:33:52 +00:00
},
// Temperate pack wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-06 08:18:35 +00:00
EntityInfo::at(pos)
2021-06-24 21:04:17 +00:00
.with_body(match rng.gen_range(0..14) {
2020-10-06 08:18:35 +00:00
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Deer,
)
.into(),
2020-10-14 21:02:48 +00:00
1 => {
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Rat)
.into()
},
2020-10-06 08:18:35 +00:00
2 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Rabbit,
)
.into(),
3 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Jackalope,
)
.into(),
4 => {
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Boar)
.into()
},
5 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Sheep,
)
.into(),
6 => {
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Pig)
.into()
},
7 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Squirrel,
2020-10-06 08:18:35 +00:00
)
.into(),
2021-03-18 00:56:27 +00:00
8 => quadruped_medium::Body::random_with(
2020-10-06 08:18:35 +00:00
rng,
&quadruped_medium::Species::Horse,
2020-10-06 08:18:35 +00:00
)
.into(),
2021-03-18 00:56:27 +00:00
9 => quadruped_medium::Body::random_with(
2021-01-13 23:45:56 +00:00
rng,
&quadruped_medium::Species::Cattle,
)
.into(),
2021-03-18 00:56:27 +00:00
10 => {
2021-03-12 00:20:05 +00:00
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Goat)
.into()
},
2021-06-24 21:04:17 +00:00
11 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Llama,
)
.into(),
12 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Alpaca,
)
.into(),
2020-10-14 21:02:48 +00:00
_ => bird_medium::Body::random_with(rng, &bird_medium::Species::Chicken)
.into(),
})
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..8,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.temperate_temp + 0.1, 0.6)
* close(c.humidity, CONFIG.forest_hum, 0.6)
* BASE_DENSITY
* 4.0
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
},
2020-10-14 21:02:48 +00:00
// Temperate solitary wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-04-17 10:38:00 +00:00
.with_body(match rng.gen_range(0..10) {
0 => quadruped_small::Body {
species: quadruped_small::Species::Fox,
body_type: quadruped_small::BodyType::Male,
}
.into(),
2021-03-12 00:20:05 +00:00
1 => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
2021-03-12 00:20:05 +00:00
&quadruped_medium::Species::Donkey,
2020-10-14 21:02:48 +00:00
)
.into(),
2 => {
bird_medium::Body::random_with(rng, &bird_medium::Species::Goose).into()
},
3 => bird_medium::Body::random_with(rng, &bird_medium::Species::Peacock)
.into(),
4 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Skunk,
)
.into(),
5 => quadruped_small::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_small::Species::Raccoon,
)
.into(),
6 => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_medium::Species::Catoblepas,
)
.into(),
7 => quadruped_small::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_small::Species::Turtle,
)
.into(),
8 => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_medium::Species::Hirdrasil,
)
.into(),
_ => quadruped_small::Body::random_with(
rng,
2021-04-17 10:38:00 +00:00
&quadruped_small::Species::Truffler,
2020-10-14 21:02:48 +00:00
)
.into(),
2020-10-06 08:18:35 +00:00
})
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.temperate_temp + 0.1, 0.6)
* BASE_DENSITY
2021-03-14 13:23:54 +00:00
* close(c.humidity, CONFIG.forest_hum, 0.6)
* 8.0
},
2020-11-21 12:33:52 +00:00
},
2021-04-17 10:38:00 +00:00
// Temperate solitary wild night
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Batfox)
.into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
day_period: vec![Night],
get_density: |c, _col| {
close(c.temp, CONFIG.temperate_temp + 0.1, 0.6)
* BASE_DENSITY
* close(c.humidity, CONFIG.forest_hum, 0.6)
* 0.8
},
},
2020-10-14 21:02:48 +00:00
// Rare temperate solitary enemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-01-26 20:23:18 +00:00
.with_body(match rng.gen_range(0..3) {
2020-10-14 21:02:48 +00:00
0 => {
biped_large::Body::random_with(rng, &biped_large::Species::Ogre).into()
},
2021-05-26 00:37:31 +00:00
1 => biped_large::Body::random_with(rng, &biped_large::Species::Swamptroll)
.into(),
_ => biped_large::Body::random_with(rng, &biped_large::Species::Cyclops)
2020-10-14 21:02:48 +00:00
.into(),
})
.with_alignment(Alignment::Enemy)
2020-10-06 08:18:35 +00:00
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
get_density: |c, _col| close(c.temp, CONFIG.temperate_temp, 0.8) * BASE_DENSITY * 0.08,
2020-11-21 12:33:52 +00:00
},
// Temperate river wildlife
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-06 08:18:35 +00:00
EntityInfo::at(pos)
2021-03-14 13:23:54 +00:00
.with_body(match rng.gen_range(0..4) {
0 => quadruped_small::Body::random_with(
2020-10-06 08:18:35 +00:00
rng,
&quadruped_small::Species::Beaver,
2020-10-06 08:18:35 +00:00
)
.into(),
1 => quadruped_low::Body {
species: quadruped_low::Species::Salamander,
body_type: quadruped_low::BodyType::Female,
}
2020-10-06 08:18:35 +00:00
.into(),
2021-03-14 13:23:54 +00:00
2 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Kelpie,
)
.into(),
_ => {
bird_medium::Body::random_with(rng, &bird_medium::Species::Duck).into()
},
2020-10-06 08:18:35 +00:00
})
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |_c, col| {
close(col.temp, CONFIG.temperate_temp, 0.6)
2020-10-06 08:18:35 +00:00
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.001
2020-10-06 08:18:35 +00:00
} else {
0.0
}
},
2020-11-21 12:33:52 +00:00
},
2021-03-18 00:56:27 +00:00
// Temperate rare river ennemies
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Kelpie,
)
.into(),
)
.with_alignment(Alignment::Wild)
},
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-03-18 00:56:27 +00:00
get_density: |_c, col| {
close(col.temp, CONFIG.temperate_temp, 0.6)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.00005
} else {
0.0
}
},
},
// Temperate river ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
.with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Hakulaq)
.into(),
)
.with_alignment(Alignment::Enemy)
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |_c, col| {
2020-10-14 21:02:48 +00:00
close(col.temp, CONFIG.temperate_temp, 0.6)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.0001
2020-10-14 21:02:48 +00:00
} else {
0.0
}
},
2020-11-21 12:33:52 +00:00
},
2020-10-14 21:02:48 +00:00
// Tropical rock solitary ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
.with_body(
quadruped_small::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_small::Species::Dodarock,
)
.into(),
)
.with_alignment(Alignment::Enemy)
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.5) * col.rock * BASE_DENSITY * 5.0
},
},
2020-10-14 21:02:48 +00:00
// Jungle solitary ennemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-03-12 00:20:05 +00:00
.with_body(match rng.gen_range(0..3) {
2020-10-14 21:02:48 +00:00
0 => {
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Maneater)
.into()
},
2021-03-12 00:20:05 +00:00
1 => quadruped_low::Body::random_with(rng, &quadruped_low::Species::Asp)
2021-03-14 13:23:54 +00:00
.into(),
_ => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_medium::Species::Tiger,
)
.into(),
})
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.tropical_temp + 0.2, 0.2)
* close(c.humidity, CONFIG.jungle_hum, 0.2)
2020-10-14 21:02:48 +00:00
* BASE_DENSITY
2021-04-17 10:38:00 +00:00
* 2.8
},
},
2021-04-17 10:38:00 +00:00
// Jungle solitary ennemies day
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
theropod::Body::random_with(rng, &theropod::Species::Sunlizard).into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
day_period: vec![Morning, Noon, Evening],
get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.2, 0.2)
* close(c.humidity, CONFIG.jungle_hum, 0.2)
* BASE_DENSITY
* 0.5
},
},
// Jungle rare solitary wild day
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(match rng.gen_range(0..5) {
0 => theropod::Body::random_with(rng, &theropod::Species::Odonto).into(),
1 => {
biped_large::Body::random_with(rng, &biped_large::Species::Mightysaurok)
.into()
},
2 => {
biped_large::Body::random_with(rng, &biped_large::Species::Occultsaurok)
.into()
},
3 => bird_large::Body::random_with(rng, &bird_large::Species::Cockatrice)
.into(),
_ => biped_large::Body::random_with(rng, &biped_large::Species::Slysaurok)
.into(),
})
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
2021-04-17 10:38:00 +00:00
day_period: vec![Morning, Noon, Evening],
get_density: |c, _col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.tropical_temp + 0.2, 0.2)
* close(c.humidity, CONFIG.jungle_hum, 0.2)
* BASE_DENSITY
2021-03-12 00:20:05 +00:00
* 0.8
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
},
2020-10-14 21:02:48 +00:00
// Jungle solitary wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
.with_body(match rng.gen_range(0..3) {
2020-10-14 21:02:48 +00:00
0 => bird_medium::Body::random_with(rng, &bird_medium::Species::Parrot)
.into(),
1 => quadruped_small::Body::random_with(
2021-03-12 00:20:05 +00:00
rng,
&quadruped_small::Species::Quokka,
)
.into(),
2020-10-14 21:02:48 +00:00
_ => {
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Tortoise)
.into()
},
})
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
2021-03-14 13:23:54 +00:00
close(c.temp, CONFIG.tropical_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.jungle_hum, 0.2)
2020-10-14 21:02:48 +00:00
* BASE_DENSITY
* 8.0
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
},
2021-04-17 10:38:00 +00:00
// Jungle solitary wild day
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Monitor)
.into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
is_underwater: false,
day_period: vec![Morning, Noon, Evening],
get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.jungle_hum, 0.2)
* BASE_DENSITY
* 2.0
},
},
// Tropical rare river enemy
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
.with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Alligator)
.into(),
)
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..3,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |_c, col| {
close(col.temp, CONFIG.tropical_temp + 0.2, 0.5)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.0001
} else {
0.0
}
},
2020-11-21 12:33:52 +00:00
},
// Tropical rare river wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-01-26 20:23:18 +00:00
.with_body(match rng.gen_range(0..3) {
0 => {
quadruped_small::Body::random_with(rng, &quadruped_small::Species::Frog)
.into()
},
2020-10-14 21:02:48 +00:00
1 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Axolotl,
2020-10-14 21:02:48 +00:00
)
.into(),
_ => quadruped_small::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_small::Species::Fungome,
)
.into(),
})
.with_alignment(Alignment::Wild)
},
2020-11-21 12:33:52 +00:00
group_size: 1..3,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |_c, col| {
close(col.temp, CONFIG.tropical_temp, 0.5)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.001
} else {
0.0
}
},
2020-11-21 12:33:52 +00:00
},
// Tropical pack enemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-01-26 20:23:18 +00:00
.with_body(match rng.gen_range(0..2) {
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Lion,
)
.into(),
_ => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Hyena,
2020-10-14 21:02:48 +00:00
)
.into(),
})
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..3,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.4)
* close(c.humidity, CONFIG.desert_hum, 0.4)
* BASE_DENSITY
* 2.0
},
2020-11-21 12:33:52 +00:00
},
// Desert pack wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-01-26 20:23:18 +00:00
.with_body(match rng.gen_range(0..2) {
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Zebra,
)
.into(),
_ => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_medium::Species::Antelope,
2020-10-14 21:02:48 +00:00
)
.into(),
})
.with_alignment(Alignment::Wild)
},
group_size: 3..7,
2020-11-21 12:33:52 +00:00
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.4)
* close(c.humidity, CONFIG.desert_hum, 0.4)
* BASE_DENSITY
* 0.8
},
2020-11-21 12:33:52 +00:00
},
// Desert solitary enemies
2020-11-21 20:59:25 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-06-24 21:04:17 +00:00
.with_body(match rng.gen_range(0..4) {
0 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Bonerattler,
)
.into(),
2021-03-12 00:20:05 +00:00
1 => {
theropod::Body::random_with(rng, &theropod::Species::Sandraptor).into()
},
2021-06-24 21:04:17 +00:00
2 => quadruped_medium::Body::random_with(
rng,
&quadruped_medium::Species::Ngoubou,
)
.into(),
_ => quadruped_low::Body::random_with(
rng,
&quadruped_low::Species::Sandshark,
)
.into(),
})
2020-11-21 20:59:25 +00:00
.with_alignment(Alignment::Enemy)
},
group_size: 1..2,
2020-11-21 20:59:25 +00:00
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 20:59:25 +00:00
get_density: |c, _col| {
close(c.temp, CONFIG.desert_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.desert_hum, 0.5)
2020-11-21 20:59:25 +00:00
* BASE_DENSITY
2021-03-18 00:56:27 +00:00
* 1.3
2020-11-21 20:59:25 +00:00
},
},
// Desert rare solitary enemies
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-03-12 00:20:05 +00:00
.with_body(match rng.gen_range(0..3) {
0 => quadruped_low::Body::random_with(
2020-11-21 20:59:25 +00:00
rng,
&quadruped_low::Species::Lavadrake,
)
.into(),
2021-03-12 00:20:05 +00:00
1 => theropod::Body::random_with(rng, &theropod::Species::Ntouka).into(),
_ => theropod::Body::random_with(rng, &theropod::Species::Archaeos).into(),
})
2020-10-14 21:02:48 +00:00
.with_alignment(Alignment::Enemy)
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
close(c.temp, CONFIG.desert_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.desert_hum, 0.5)
* BASE_DENSITY
2021-03-12 00:20:05 +00:00
* 0.15
},
},
2020-11-29 21:22:43 +00:00
// Desert river solitary enemy
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Crocodile)
.into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..3,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
get_density: |_c, col| {
close(col.temp, CONFIG.desert_temp + 0.2, 0.3)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.0001
} else {
0.0
}
},
2020-11-21 12:33:52 +00:00
},
2020-11-29 21:22:43 +00:00
// Desert secret solitary enemy
Entry {
make_entity: |pos, _rng| {
EntityInfo::at(pos)
.with_body(
quadruped_medium::Body {
species: quadruped_medium::Species::Roshwalr,
body_type: quadruped_medium::BodyType::Female,
}
.into(),
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..3,
is_underwater: false,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-29 21:22:43 +00:00
get_density: |c, _col| {
close(c.temp, CONFIG.desert_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.desert_hum, 0.5)
* BASE_DENSITY
2021-06-22 23:43:18 +00:00
* 0.005
2020-11-29 21:22:43 +00:00
},
},
2020-10-14 21:02:48 +00:00
// Desert solitary wild
2020-11-21 12:33:52 +00:00
Entry {
make_entity: |pos, rng| {
2020-10-14 21:02:48 +00:00
EntityInfo::at(pos)
2021-04-17 10:38:00 +00:00
.with_body(match rng.gen_range(0..4) {
0 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Holladon,
)
.into(),
2020-10-14 21:02:48 +00:00
1 => {
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Pangolin)
.into()
},
2 => quadruped_medium::Body::random_with(
2020-10-14 21:02:48 +00:00
rng,
&quadruped_medium::Species::Camel,
2020-10-14 21:02:48 +00:00
)
.into(),
2021-04-17 10:38:00 +00:00
3 => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Porcupine,
)
.into(),
2021-04-17 10:38:00 +00:00
_ => quadruped_small::Body {
2021-03-18 00:56:27 +00:00
species: quadruped_small::Species::Hare,
body_type: quadruped_small::BodyType::Male,
}
.into(),
2021-04-17 10:38:00 +00:00
})
.with_alignment(Alignment::Wild)
},
group_size: 1..2,
is_underwater: false,
day_period: vec![Night, Morning, Noon, Evening],
get_density: |c, _col| {
close(c.temp, CONFIG.desert_temp + 0.2, 0.3) * BASE_DENSITY * 3.8
},
},
// Desert solitary wild day
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(match rng.gen_range(0..3) {
1 => quadruped_low::Body {
species: quadruped_low::Species::Salamander,
body_type: quadruped_low::BodyType::Male,
}
.into(),
2020-10-14 21:02:48 +00:00
_ => quadruped_small::Body::random_with(
rng,
&quadruped_small::Species::Gecko,
)
.into(),
})
.with_alignment(Alignment::Wild)
2020-10-14 21:02:48 +00:00
},
2020-11-21 12:33:52 +00:00
group_size: 1..2,
is_underwater: false,
2021-04-17 10:38:00 +00:00
day_period: vec![Morning, Noon, Evening],
2020-11-21 12:33:52 +00:00
get_density: |c, _col| {
2021-04-17 10:38:00 +00:00
close(c.temp, CONFIG.desert_temp + 0.2, 0.3) * BASE_DENSITY * 1.0
2020-11-21 12:33:52 +00:00
},
},
2021-03-12 00:20:05 +00:00
// Underwater temperate
2020-11-26 21:57:38 +00:00
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
2021-02-18 00:41:34 +00:00
.with_body(match rng.gen_range(0..3) {
2020-11-29 21:22:43 +00:00
0 => fish_medium::Body::random_with(rng, &fish_medium::Species::Marlin)
.into(),
2021-02-18 00:41:34 +00:00
1 => {
fish_small::Body::random_with(rng, &fish_small::Species::Piranha).into()
},
2020-11-29 21:22:43 +00:00
_ => fish_small::Body::random_with(rng, &fish_small::Species::Clownfish)
.into(),
})
2020-11-26 21:57:38 +00:00
.with_alignment(Alignment::Wild)
},
group_size: 3..5,
is_underwater: true,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2020-11-26 21:57:38 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.temperate_temp, 1.0) * col.tree_density * BASE_DENSITY * 5.0
},
},
2021-03-12 00:20:05 +00:00
// Underwater taiga
Entry {
make_entity: |pos, rng| {
EntityInfo::at(pos)
.with_body(
2021-03-14 13:23:54 +00:00
fish_medium::Body::random_with(rng, &fish_medium::Species::Icepike).into(),
2021-03-12 00:20:05 +00:00
)
.with_alignment(Alignment::Enemy)
},
group_size: 1..3,
2021-03-14 13:23:54 +00:00
is_underwater: true,
2021-04-16 11:17:15 +00:00
day_period: vec![Night, Morning, Noon, Evening],
2021-03-12 00:20:05 +00:00
get_density: |c, col| {
close(c.temp, CONFIG.snow_temp, 0.15) * col.tree_density * BASE_DENSITY * 5.0
},
},
2020-10-01 21:00:46 +00:00
];
for y in 0..vol.size_xy().y as i32 {
for x in 0..vol.size_xy().x as i32 {
let offs = Vec2::new(x, y);
let wpos2d = wpos2d + offs;
// Sample terrain
let col_sample = if let Some(col_sample) = get_column(offs) {
col_sample
} else {
continue;
};
let underwater = col_sample.water_level > col_sample.alt;
2021-04-16 11:17:15 +00:00
let current_day_period;
if let Some(time) = time {
current_day_period = DayPeriod::from(time.0)
} else {
current_day_period = Noon
}
2020-10-01 21:00:46 +00:00
2020-10-06 08:18:35 +00:00
let entity_group = scatter.iter().enumerate().find_map(
2020-11-21 12:33:52 +00:00
|(
_i,
Entry {
make_entity,
group_size,
is_underwater,
2021-04-16 11:17:15 +00:00
day_period,
2020-11-21 12:33:52 +00:00
get_density,
},
)| {
let density = get_density(chunk, col_sample);
2020-10-01 21:00:46 +00:00
if density > 0.0
2020-11-22 22:32:15 +00:00
&& dynamic_rng.gen::<f32>() < density * col_sample.spawn_rate
2020-10-01 21:00:46 +00:00
&& underwater == *is_underwater
2021-04-16 11:17:15 +00:00
&& day_period.contains(&current_day_period)
&& col_sample.gradient < Some(1.3)
2020-10-01 21:00:46 +00:00
{
Some((make_entity, group_size.clone()))
} else {
None
}
2020-10-06 08:18:35 +00:00
},
);
2020-10-01 21:00:46 +00:00
let alt = col_sample.alt as i32;
2020-10-01 21:00:46 +00:00
if let Some((make_entity, group_size)) = entity_group {
let group_size = dynamic_rng.gen_range(group_size.start..group_size.end);
let entity = make_entity(
(wpos2d.map(|e| e as f32) + 0.5).with_z(alt as f32),
dynamic_rng,
);
for e in 0..group_size {
// Choose a nearby position
let offs_wpos2d = (Vec2::new(
(e as f32 / group_size as f32 * 2.0 * f32::consts::PI).sin(),
(e as f32 / group_size as f32 * 2.0 * f32::consts::PI).cos(),
) * (5.0 + dynamic_rng.gen::<f32>().powf(0.5) * 5.0))
.map(|e| e as i32);
// Clamp position to chunk
let offs_wpos2d = (offs + offs_wpos2d)
.clamped(Vec2::zero(), vol.size_xy().map(|e| e as i32) - 1)
- offs;
// Find the intersection between ground and air, if there is one near the
// surface
if let Some(solid_end) = (-8..8).find(|z| {
(0..2).all(|z2| {
vol.get(Vec3::new(offs.x, offs.y, alt) + offs_wpos2d.with_z(z + z2))
2020-10-01 21:00:46 +00:00
.map(|b| !b.is_solid())
.unwrap_or(true)
})
}) {
2020-10-06 08:18:35 +00:00
let mut entity = entity.clone();
entity.pos += offs_wpos2d.with_z(solid_end).map(|e| e as f32);
2020-10-06 08:18:35 +00:00
supplement.add_entity(entity.with_automatic_name());
2020-10-01 21:00:46 +00:00
}
}
}
}
}
}