From c547cdd72c6f691ffd13e5a41529298882cf57fd Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 25 Jul 2020 13:37:00 +0100 Subject: [PATCH] Fixed castle bug, better field RNG --- assets/common/cave_scatter.ron | 10 ++++++---- world/src/civ/mod.rs | 2 ++ world/src/layer/mod.rs | 2 +- world/src/site/castle/mod.rs | 2 +- world/src/site/dungeon/mod.rs | 6 +++++- world/src/util/random.rs | 17 ++++++++++++++++- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/assets/common/cave_scatter.ron b/assets/common/cave_scatter.ron index d45653c98e..ea35812776 100644 --- a/assets/common/cave_scatter.ron +++ b/assets/common/cave_scatter.ron @@ -1,9 +1,11 @@ [ (25, Velorite), - (50, VeloriteFrag), - (15, WhiteFlower), - (80, ShortGrass), - (150, Mushroom), + (35, VeloriteFrag), + (60, Stones), + (15, PurpleFlower), + (150, ShortGrass), + (80, Mushroom), + (8, ShinyGem), (5, Chest), (2, Crate), (1, Scarecrow), diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index 53888f46de..f443373a5c 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -156,6 +156,7 @@ impl Civs { - (site.center - pos).map(|e| e as f32).magnitude() / flatten_radius) * 1.25) .min(1.0); + let rng = &mut ctx.rng; ctx.sim .get_mut(pos) // Don't disrupt chunks that are near water @@ -166,6 +167,7 @@ impl Civs { chunk.basement += diff; chunk.rockiness = 0.0; chunk.warp_factor = 0.0; + chunk.surface_veg *= 1.0 - factor * rng.gen_range(0.25, 0.9); }); } } diff --git a/world/src/layer/mod.rs b/world/src/layer/mod.rs index 612b5ca9cc..e64d54e501 100644 --- a/world/src/layer/mod.rs +++ b/world/src/layer/mod.rs @@ -139,7 +139,7 @@ pub fn apply_caves_to<'a>( } // Scatter things in caves - if RandomField::new(index.seed).chance(wpos2d.into(), 0.002) && cave_base < surface_z as i32 - 25 { + if RandomField::new(index.seed).chance(wpos2d.into(), 0.001) && cave_base < surface_z as i32 - 25 { let kind = *assets::load_expect::>("common.cave_scatter") .choose_seeded(RandomField::new(index.seed + 1).get(wpos2d.into())); let _ = vol.set(Vec3::new(offs.x, offs.y, cave_base), Block::new(kind, Rgb::zero())); diff --git a/world/src/site/castle/mod.rs b/world/src/site/castle/mod.rs index d3039e11bc..307c888568 100644 --- a/world/src/site/castle/mod.rs +++ b/world/src/site/castle/mod.rs @@ -202,7 +202,7 @@ impl Castle { for z in -5..3 { let pos = Vec3::new(offs.x, offs.y, surface_z + z); - if z >= 0 { + if z > 0 { if vol.get(pos).unwrap().kind() != BlockKind::Water { let _ = vol.set(pos, Block::empty()); } diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index e2decc7fc3..42476f53c6 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -201,6 +201,7 @@ pub struct Floor { hollow_depth: i32, #[allow(dead_code)] stair_tile: Vec2, + final_level: bool, } const FLOOR_SIZE: Vec2 = Vec2::new(18, 18); @@ -233,6 +234,7 @@ impl Floor { solid_depth: if level == 0 { 80 } else { 32 }, hollow_depth: 30, stair_tile: new_stair_tile - tile_offset, + final_level, }; const STAIR_ROOM_HEIGHT: i32 = 13; @@ -632,10 +634,12 @@ impl Floor { empty }; + let tunnel_height = if self.final_level { 16.0 } else { 8.0 }; + move |z| match self.tiles.get(tile_pos) { Some(Tile::Solid) => BlockMask::nothing(), Some(Tile::Tunnel) => { - if dist_to_wall >= wall_thickness && (z as f32) < 8.0 - 8.0 * tunnel_dist.powf(4.0) + if dist_to_wall >= wall_thickness && (z as f32) < tunnel_height * (1.0 - tunnel_dist.powf(4.0)) { if z == 0 { floor_sprite } else { empty } } else { diff --git a/world/src/util/random.rs b/world/src/util/random.rs index f9d1afdcc8..390ab51e8e 100644 --- a/world/src/util/random.rs +++ b/world/src/util/random.rs @@ -20,7 +20,22 @@ impl Sampler<'static> for RandomField { fn get(&self, pos: Self::Index) -> Self::Sample { let pos = pos.map(|e| u32::from_le_bytes(e.to_le_bytes())); - seed_expan::diffuse_mult(&[self.seed, pos.x, pos.y, pos.z]) + + let mut a = self.seed; + a = (a ^ 61) ^ (a >> 16); + a = a.wrapping_add(a << 3); + a = a ^ pos.x; + a = a ^ (a >> 4); + a = a.wrapping_mul(0x27d4eb2d); + a = a ^ (a >> 15); + a = a ^ pos.y; + a = (a ^ 61) ^ (a >> 16); + a = a.wrapping_add(a << 3); + a = a ^ (a >> 4); + a = a ^ pos.z; + a = a.wrapping_mul(0x27d4eb2d); + a = a ^ (a >> 15); + a } }