From 1c91940397ba70d67cc42666fd96b1b12cad95bd Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 17 Feb 2021 02:17:19 +0000 Subject: [PATCH] Fixed biasing bug --- world/src/site2/mod.rs | 10 +++++----- world/src/site2/tile.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs index 716e92fcdd..0c7e584a90 100644 --- a/world/src/site2/mod.rs +++ b/world/src/site2/mod.rs @@ -110,14 +110,14 @@ impl Site { } pub fn find_roadside_aabr(&mut self, rng: &mut impl Rng, area_range: Range, min_dims: Extent2) -> Option<(Aabr, Vec2)> { - let dir = Vec2::::zero().map(|_| rng.gen_range(-1.0..1.0)); + let dir = Vec2::::zero().map(|_| rng.gen_range(-1.0..1.0)).normalized(); let search_pos = if rng.gen() { - self.plot(*self.plazas.choose(rng).unwrap()).root_tile + (dir * 5.0).map(|e: f32| e.round() as i32) + self.plot(*self.plazas.choose(rng)?).root_tile + (dir * 5.0).map(|e: f32| e.round() as i32) } else { if let PlotKind::Road(path) = &self.plot(*self.roads.choose(rng)?).kind { *path.nodes().choose(rng)? + (dir * 1.5).map(|e: f32| e.round() as i32) } else { - return None; + unreachable!() } }; @@ -128,7 +128,7 @@ impl Site { let pos = attempt(32, || { self.plazas .choose(rng) - .map(|&p| self.plot(p).root_tile + Vec2::new(rng.gen_range(-24..24), rng.gen_range(-24..24))) + .map(|&p| self.plot(p).root_tile + Vec2::new(rng.gen_range(-20..20), rng.gen_range(-20..20))) .filter(|&tile| self .plazas .iter() @@ -186,7 +186,7 @@ impl Site { let mut castles = 0; for _ in 0..1000 { - if site.plots.len() > 80 { + if site.plots.len() - site.plazas.len() > 80 { break; } diff --git a/world/src/site2/tile.rs b/world/src/site2/tile.rs index ea557dc077..64d23da4c0 100644 --- a/world/src/site2/tile.rs +++ b/world/src/site2/tile.rs @@ -73,7 +73,8 @@ impl TileGrid { } else if aabr.size().product() + if i % 2 == 0 { aabr.size().h } else { aabr.size().w } > area_range.end as i32 { break; } else { - match i % 4 { + // `center.sum()` to avoid biasing certain directions + match (i + center.sum().abs()) % 4 { 0 if (aabr.min.y..aabr.max.y + 1).all(|y| self.get(Vec2::new(aabr.max.x, y)).is_empty()) => { aabr.max.x += 1; last_growth = i;