Fixed castle bug, better field RNG

This commit is contained in:
Joshua Barretto 2020-07-25 13:37:00 +01:00
parent 41229b4665
commit c547cdd72c
6 changed files with 31 additions and 8 deletions

View File

@ -1,9 +1,11 @@
[ [
(25, Velorite), (25, Velorite),
(50, VeloriteFrag), (35, VeloriteFrag),
(15, WhiteFlower), (60, Stones),
(80, ShortGrass), (15, PurpleFlower),
(150, Mushroom), (150, ShortGrass),
(80, Mushroom),
(8, ShinyGem),
(5, Chest), (5, Chest),
(2, Crate), (2, Crate),
(1, Scarecrow), (1, Scarecrow),

View File

@ -156,6 +156,7 @@ impl Civs {
- (site.center - pos).map(|e| e as f32).magnitude() / flatten_radius) - (site.center - pos).map(|e| e as f32).magnitude() / flatten_radius)
* 1.25) * 1.25)
.min(1.0); .min(1.0);
let rng = &mut ctx.rng;
ctx.sim ctx.sim
.get_mut(pos) .get_mut(pos)
// Don't disrupt chunks that are near water // Don't disrupt chunks that are near water
@ -166,6 +167,7 @@ impl Civs {
chunk.basement += diff; chunk.basement += diff;
chunk.rockiness = 0.0; chunk.rockiness = 0.0;
chunk.warp_factor = 0.0; chunk.warp_factor = 0.0;
chunk.surface_veg *= 1.0 - factor * rng.gen_range(0.25, 0.9);
}); });
} }
} }

View File

@ -139,7 +139,7 @@ pub fn apply_caves_to<'a>(
} }
// Scatter things in caves // 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::<Lottery<BlockKind>>("common.cave_scatter") let kind = *assets::load_expect::<Lottery<BlockKind>>("common.cave_scatter")
.choose_seeded(RandomField::new(index.seed + 1).get(wpos2d.into())); .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())); let _ = vol.set(Vec3::new(offs.x, offs.y, cave_base), Block::new(kind, Rgb::zero()));

View File

@ -202,7 +202,7 @@ impl Castle {
for z in -5..3 { for z in -5..3 {
let pos = Vec3::new(offs.x, offs.y, surface_z + z); 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 { if vol.get(pos).unwrap().kind() != BlockKind::Water {
let _ = vol.set(pos, Block::empty()); let _ = vol.set(pos, Block::empty());
} }

View File

@ -201,6 +201,7 @@ pub struct Floor {
hollow_depth: i32, hollow_depth: i32,
#[allow(dead_code)] #[allow(dead_code)]
stair_tile: Vec2<i32>, stair_tile: Vec2<i32>,
final_level: bool,
} }
const FLOOR_SIZE: Vec2<i32> = Vec2::new(18, 18); const FLOOR_SIZE: Vec2<i32> = Vec2::new(18, 18);
@ -233,6 +234,7 @@ impl Floor {
solid_depth: if level == 0 { 80 } else { 32 }, solid_depth: if level == 0 { 80 } else { 32 },
hollow_depth: 30, hollow_depth: 30,
stair_tile: new_stair_tile - tile_offset, stair_tile: new_stair_tile - tile_offset,
final_level,
}; };
const STAIR_ROOM_HEIGHT: i32 = 13; const STAIR_ROOM_HEIGHT: i32 = 13;
@ -632,10 +634,12 @@ impl Floor {
empty empty
}; };
let tunnel_height = if self.final_level { 16.0 } else { 8.0 };
move |z| match self.tiles.get(tile_pos) { move |z| match self.tiles.get(tile_pos) {
Some(Tile::Solid) => BlockMask::nothing(), Some(Tile::Solid) => BlockMask::nothing(),
Some(Tile::Tunnel) => { 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 } if z == 0 { floor_sprite } else { empty }
} else { } else {

View File

@ -20,7 +20,22 @@ impl Sampler<'static> for RandomField {
fn get(&self, pos: Self::Index) -> Self::Sample { fn get(&self, pos: Self::Index) -> Self::Sample {
let pos = pos.map(|e| u32::from_le_bytes(e.to_le_bytes())); 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
} }
} }