From eff9fc5393046ae6cb8f75fbf707e1a7b70a4835 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 6 Mar 2021 15:39:20 +0000 Subject: [PATCH] Better giant tree spawn rate --- world/src/civ/mod.rs | 8 ++++---- world/src/site/tree.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index c91c720811..ef45d370c1 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -106,10 +106,10 @@ impl Civs { for _ in 0..initial_civ_count * 3 { attempt(5, || { - let (kind, size) = match ctx.rng.gen_range(0..16) { - 0..=1 => (SiteKind::Castle, 3), - 2..=7 => (SiteKind::Refactor, 6), - 8 => (SiteKind::Tree, 4), + let (kind, size) = match ctx.rng.gen_range(0..64) { + 0..=4 => (SiteKind::Castle, 3), + 5..=28 => (SiteKind::Refactor, 6), + 29..=31 => (SiteKind::Tree, 4), _ => (SiteKind::Dungeon, 0), }; let loc = find_site_loc(&mut ctx, None, size)?; diff --git a/world/src/site/tree.rs b/world/src/site/tree.rs index 9011b9b90d..965e8e0670 100644 --- a/world/src/site/tree.rs +++ b/world/src/site/tree.rs @@ -1,5 +1,6 @@ use crate::{ layer::tree::{ProceduralTree, TreeConfig}, + util::{FastNoise, Sampler}, site::SpawnRules, Canvas, Land, }; @@ -11,6 +12,7 @@ use vek::*; pub struct Tree { pub origin: Vec2, alt: i32, + seed: u32, tree: ProceduralTree, } @@ -19,6 +21,7 @@ impl Tree { Self { origin, alt: land.get_alt_approx(origin) as i32, + seed: rng.gen(), tree: { let config = TreeConfig::giant(rng, 4.0, false); ProceduralTree::generate(config, rng) @@ -36,6 +39,8 @@ impl Tree { } pub fn render(&self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng) { + let nz = FastNoise::new(self.seed); + canvas.foreach_col(|canvas, wpos2d, col| { let rpos2d = wpos2d - self.origin; let bounds = self.tree.get_bounds().map(|e| e as i32); @@ -51,7 +56,10 @@ impl Tree { let (branch, leaves, _, _) = self.tree.is_branch_or_leaves_at(rposf); if leaves { - canvas.set(wpos, Block::new(BlockKind::Leaves, Rgb::new(30, 130, 40))); + let dark = Rgb::new(10, 70, 50).map(|e| e as f32); + let light = Rgb::new(80, 140, 10).map(|e| e as f32); + let leaf_col = Lerp::lerp(dark, light, nz.get(rposf.map(|e| e as f64) * 0.05) * 0.5 + 0.5); + canvas.set(wpos, Block::new(BlockKind::Leaves, leaf_col.map(|e| e as u8))); } else if branch { canvas.set(wpos, Block::new(BlockKind::Wood, Rgb::new(80, 32, 0))); }