From 69436db64ca6794aa5a8968a290150281ab600c8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 28 Jan 2022 13:58:41 +0000 Subject: [PATCH] Added wall lamps --- common/src/terrain/block.rs | 18 ++++++++++ server/src/rtsim/mod.rs | 2 +- world/src/site/mod.rs | 1 + world/src/site2/mod.rs | 8 ++--- world/src/site2/plot/house.rs | 68 +++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 5 deletions(-) diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 10b8617f12..1362f94d57 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -90,6 +90,24 @@ impl BlockKind { /// fields. #[inline] pub const fn has_color(&self) -> bool { self.is_filled() } + + /// Determine whether the block is 'terrain-like'. This definition is + /// arbitrary, but includes things like rocks, soils, sands, grass, and + /// other blocks that might be expected to the landscape. Plant matter and + /// snow are *not* included. + #[inline] + pub const fn is_terrain(&self) -> bool { + matches!( + self, + BlockKind::Rock + | BlockKind::WeakRock + | BlockKind::GlowingRock + | BlockKind::GlowingWeakRock + | BlockKind::Grass + | BlockKind::Earth + | BlockKind::Sand + ) + } } #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index 9db64ae900..4dcec06cc2 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -198,7 +198,7 @@ pub fn init( _ => {}, }, SiteKind::Refactor(site2) => { - for _ in 0..(site.economy.pop as usize).min(site2.plots().len() * 3) { + for _ in 0..site.economy.pop.min(site2.plots().len() as f32 * 1.5) as usize { rtsim.entities.insert(Entity { is_loaded: false, pos: site2 diff --git a/world/src/site/mod.rs b/world/src/site/mod.rs index 8019111c25..81888397dd 100644 --- a/world/src/site/mod.rs +++ b/world/src/site/mod.rs @@ -30,6 +30,7 @@ pub struct SpawnRules { } impl SpawnRules { + #[must_use] pub fn combine(self, other: Self) -> Self { // Should be commutative Self { diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs index 0a8dadabbc..d9ee89ce3a 100644 --- a/world/src/site2/mod.rs +++ b/world/src/site2/mod.rs @@ -222,7 +222,7 @@ impl Site { pub fn make_plaza(&mut self, land: &Land, rng: &mut impl Rng) -> Id { let plaza_radius = rng.gen_range(1..4); - let plaza_dist = 10.0 + plaza_radius as f32 * 5.0; + let plaza_dist = 6.5 + plaza_radius as f32 * 4.0; let pos = attempt(32, || { self.plazas .choose(rng) @@ -382,7 +382,7 @@ impl Site { match *build_chance.choose_seeded(rng.gen()) { // House 1 => { - let size = (2.0 + rng.gen::().powf(5.0) * 1.5).round() as u32; + let size = (1.5 + rng.gen::().powf(5.0) * 1.0).round() as u32; if let Some((aabr, door_tile, door_dir)) = attempt(32, || { site.find_roadside_aabr( &mut rng, @@ -713,7 +713,7 @@ impl Site { for z in -8..6 { canvas.map(Vec3::new(wpos2d.x, wpos2d.y, alt + z), |b| { if b.is_filled() { - if underground { + if underground && b.is_terrain() { Block::new(BlockKind::Earth, Rgb::new(0x6A, 0x47, 0x24)) } else { b @@ -781,7 +781,7 @@ impl Site { canvas.map( Vec3::new(wpos2d.x, wpos2d.y, alt + z), |b| if b.is_filled() { - if underground { + if underground && b.is_terrain() { Block::new(BlockKind::Earth, Rgb::new(0x6A, 0x47, 0x24)) } else { b diff --git a/world/src/site2/plot/house.rs b/world/src/site2/plot/house.rs index fe04481bda..c49ba1168f 100644 --- a/world/src/site2/plot/house.rs +++ b/world/src/site2/plot/house.rs @@ -856,6 +856,40 @@ impl Structure for House { painter.prim(Primitive::intersect(walls, windows)), Fill::Block(Block::air(SpriteKind::Window1).with_ori(2).unwrap()), ); + // Wall lamps + if i == 1 { + let mut torches_min = painter.prim(Primitive::Empty); + let mut torches_max = painter.prim(Primitive::Empty); + for y in self.tile_aabr.min.y..self.tile_aabr.max.y { + let pos = site + .tile_wpos(Vec2::new(self.tile_aabr.min.x, y)) + .with_z(alt + previous_height + 3) + + Vec3::new(-1, 0, 0); + let torch = painter.prim(Primitive::Aabb(Aabb { + min: pos, + max: pos + 1, + })); + torches_min = painter.prim(Primitive::union(torches_min, torch)); + + let pos = site + .tile_wpos(Vec2::new(self.tile_aabr.max.x, y + 1)) + .with_z(alt + previous_height + 3) + + Vec3::new(1, 0, 0); + let torch = painter.prim(Primitive::Aabb(Aabb { + min: pos, + max: pos + 1, + })); + torches_max = painter.prim(Primitive::union(torches_max, torch)); + } + painter.fill( + torches_min, + Fill::Block(Block::air(SpriteKind::WallLampSmall).with_ori(6).unwrap()), + ); + painter.fill( + torches_max, + Fill::Block(Block::air(SpriteKind::WallLampSmall).with_ori(2).unwrap()), + ); + } } // Windows y axis { @@ -886,6 +920,40 @@ impl Structure for House { painter.prim(Primitive::intersect(walls, windows)), Fill::Block(Block::air(SpriteKind::Window1).with_ori(0).unwrap()), ); + // Wall lamps + if i == 1 { + let mut torches_min = painter.prim(Primitive::Empty); + let mut torches_max = painter.prim(Primitive::Empty); + for x in self.tile_aabr.min.x..self.tile_aabr.max.x { + let pos = site + .tile_wpos(Vec2::new(x + 1, self.tile_aabr.min.y)) + .with_z(alt + previous_height + 3) + + Vec3::new(0, -1, 0); + let torch = painter.prim(Primitive::Aabb(Aabb { + min: pos, + max: pos + 1, + })); + torches_min = painter.prim(Primitive::union(torches_min, torch)); + + let pos = site + .tile_wpos(Vec2::new(x, self.tile_aabr.max.y)) + .with_z(alt + previous_height + 3) + + Vec3::new(0, 1, 0); + let torch = painter.prim(Primitive::Aabb(Aabb { + min: pos, + max: pos + 1, + })); + torches_max = painter.prim(Primitive::union(torches_max, torch)); + } + painter.fill( + torches_min, + Fill::Block(Block::air(SpriteKind::WallLampSmall).with_ori(0).unwrap()), + ); + painter.fill( + torches_max, + Fill::Block(Block::air(SpriteKind::WallLampSmall).with_ori(4).unwrap()), + ); + } } // Shed roof on negative overhangs