Merge branch 'zesterer/small-fixes' into 'master'

Prevent creatures spawning in the ground

See merge request veloren/veloren!2418
This commit is contained in:
Marcel
2021-06-11 07:20:49 +00:00
2 changed files with 88 additions and 80 deletions

View File

@ -439,15 +439,18 @@ pub fn apply_caves_supplement<'a>(
let cave_depth = (col_sample.alt - cave.alt).max(0.0); //slightly different from earlier cave depth? let cave_depth = (col_sample.alt - cave.alt).max(0.0); //slightly different from earlier cave depth?
// Scatter things in caves // Scatter things in caves
if let Some(z) = (-4..8).map(|z| cave_base + z).find(|z| {
(0..2).all(|z_offs| {
vol.get(offs.with_z(z + z_offs))
.map_or(true, |b| b.is_fluid())
})
}) {
if RandomField::new(index.seed).chance(wpos2d.into(), 0.0018) if RandomField::new(index.seed).chance(wpos2d.into(), 0.0018)
&& cave_base < surface_z as i32 - 40 && cave_base < surface_z as i32 - 40
{ {
let is_hostile: bool; let is_hostile: bool;
let entity = EntityInfo::at(Vec3::new( let entity =
wpos2d.x as f32, EntityInfo::at(Vec3::new(wpos2d.x as f32, wpos2d.y as f32, z as f32))
wpos2d.y as f32,
cave_base as f32,
))
.with_body(if cave_depth < 70.0 { .with_body(if cave_depth < 70.0 {
is_hostile = false; is_hostile = false;
let species = match dynamic_rng.gen_range(0..4) { let species = match dynamic_rng.gen_range(0..4) {
@ -456,7 +459,8 @@ pub fn apply_caves_supplement<'a>(
2 => comp::quadruped_small::Species::Holladon, 2 => comp::quadruped_small::Species::Holladon,
_ => comp::quadruped_small::Species::Batfox, _ => comp::quadruped_small::Species::Batfox,
}; };
comp::quadruped_small::Body::random_with(dynamic_rng, &species).into() comp::quadruped_small::Body::random_with(dynamic_rng, &species)
.into()
} else if cave_depth < 120.0 { } else if cave_depth < 120.0 {
is_hostile = true; is_hostile = true;
let species = match dynamic_rng.gen_range(0..3) { let species = match dynamic_rng.gen_range(0..3) {
@ -464,7 +468,8 @@ pub fn apply_caves_supplement<'a>(
1 => comp::quadruped_low::Species::Salamander, 1 => comp::quadruped_low::Species::Salamander,
_ => comp::quadruped_low::Species::Asp, _ => comp::quadruped_low::Species::Asp,
}; };
comp::quadruped_low::Body::random_with(dynamic_rng, &species).into() comp::quadruped_low::Body::random_with(dynamic_rng, &species)
.into()
} else if cave_depth < 200.0 { } else if cave_depth < 200.0 {
is_hostile = true; is_hostile = true;
let species = match dynamic_rng.gen_range(0..3) { let species = match dynamic_rng.gen_range(0..3) {
@ -472,7 +477,8 @@ pub fn apply_caves_supplement<'a>(
1 => comp::quadruped_low::Species::Lavadrake, 1 => comp::quadruped_low::Species::Lavadrake,
_ => comp::quadruped_low::Species::Basilisk, _ => comp::quadruped_low::Species::Basilisk,
}; };
comp::quadruped_low::Body::random_with(dynamic_rng, &species).into() comp::quadruped_low::Body::random_with(dynamic_rng, &species)
.into()
} else { } else {
is_hostile = true; is_hostile = true;
let species = match dynamic_rng.gen_range(0..5) { let species = match dynamic_rng.gen_range(0..5) {
@ -485,7 +491,8 @@ pub fn apply_caves_supplement<'a>(
}, },
_ => comp::biped_large::Species::Troll, _ => comp::biped_large::Species::Troll,
}; };
comp::biped_large::Body::random_with(dynamic_rng, &species).into() comp::biped_large::Body::random_with(dynamic_rng, &species)
.into()
}) })
.with_alignment(if is_hostile { .with_alignment(if is_hostile {
comp::Alignment::Enemy comp::Alignment::Enemy
@ -500,6 +507,7 @@ pub fn apply_caves_supplement<'a>(
} }
} }
} }
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn apply_coral_to(canvas: &mut Canvas) { pub fn apply_coral_to(canvas: &mut Canvas) {

View File

@ -1063,37 +1063,37 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}, },
); );
if let Some((make_entity, group_size)) = entity_group {
let alt = col_sample.alt as i32; let alt = col_sample.alt as i32;
// Find the intersection between ground and air, if there is one near the
// surface if let Some((make_entity, group_size)) = entity_group {
if let Some(solid_end) = (-4..8)
.find(|z| {
vol.get(Vec3::new(offs.x, offs.y, alt + z))
.map(|b| b.is_solid())
.unwrap_or(false)
})
.and_then(|solid_start| {
(1..8).map(|z| solid_start + z).find(|z| {
vol.get(Vec3::new(offs.x, offs.y, alt + z))
.map(|b| !b.is_solid())
.unwrap_or(true)
})
})
{
let group_size = dynamic_rng.gen_range(group_size.start..group_size.end); let group_size = dynamic_rng.gen_range(group_size.start..group_size.end);
let entity = make_entity( let entity = make_entity(
Vec3::new(wpos2d.x, wpos2d.y, alt + solid_end).map(|e| e as f32), (wpos2d.map(|e| e as f32) + 0.5).with_z(alt as f32),
dynamic_rng, dynamic_rng,
); );
for e in 0..group_size { for e in 0..group_size {
let mut entity = entity.clone(); // Choose a nearby position
entity.pos = entity.pos.map(|e| e + dynamic_rng.gen::<f32>()) let offs_wpos2d = (Vec2::new(
+ Vec3::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).sin(),
(e as f32 / group_size as f32 * 2.0 * f32::consts::PI).cos(), (e as f32 / group_size as f32 * 2.0 * f32::consts::PI).cos(),
0.0, ) * (5.0 + dynamic_rng.gen::<f32>().powf(0.5) * 5.0))
) * (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))
.map(|b| !b.is_solid())
.unwrap_or(true)
})
}) {
let mut entity = entity.clone();
entity.pos += offs_wpos2d.with_z(solid_end).map(|e| e as f32);
supplement.add_entity(entity.with_automatic_name()); supplement.add_entity(entity.with_automatic_name());
} }
} }