From 144b8bbcda4372e6806c4accea3336c0de3e7059 Mon Sep 17 00:00:00 2001
From: Joshua Barretto <joshua.s.barretto@gmail.com>
Date: Fri, 5 Mar 2021 13:53:55 +0000
Subject: [PATCH] Brick fill

---
 world/src/site2/gen.rs        | 10 +++++++++-
 world/src/site2/mod.rs        | 15 +++++++++------
 world/src/site2/plot/house.rs |  6 +++---
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/world/src/site2/gen.rs b/world/src/site2/gen.rs
index 5bb17afd49..f5522d113b 100644
--- a/world/src/site2/gen.rs
+++ b/world/src/site2/gen.rs
@@ -1,7 +1,8 @@
 use super::*;
+use crate::util::{RandomField, Sampler};
 use common::{
     store::{Id, Store},
-    terrain::Block,
+    terrain::{Block, BlockKind},
 };
 use vek::*;
 
@@ -20,6 +21,7 @@ pub enum Primitive {
 
 pub enum Fill {
     Block(Block),
+    Brick(BlockKind, Rgb<u8>, u8),
 }
 
 impl Fill {
@@ -71,6 +73,12 @@ impl Fill {
         if self.contains_at(tree, prim, pos) {
             match self {
                 Fill::Block(block) => Some(*block),
+                Fill::Brick(bk, col, range) => Some(Block::new(
+                    *bk,
+                    *col + (RandomField::new(13)
+                        .get((pos + Vec3::new(pos.z, pos.z, 0)) / Vec3::new(2, 2, 1))
+                        % *range as u32) as u8,
+                )),
             }
         } else {
             None
diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs
index f1dcb5cbf0..9581e140c4 100644
--- a/world/src/site2/mod.rs
+++ b/world/src/site2/mod.rs
@@ -98,16 +98,19 @@ impl Site {
         w: u16,
     ) -> Option<Id<Plot>> {
         const MAX_ITERS: usize = 4096;
-        let range = -(w as i32) / 2..w as i32 - w as i32 / 2;
+        let range = -(w as i32) / 2..w as i32 - (w as i32 + 1) / 2;
         let heuristic = |tile: &Vec2<i32>| {
+            let mut max_cost = (tile.distance_squared(b) as f32).sqrt();
             for y in range.clone() {
                 for x in range.clone() {
                     if self.tiles.get(*tile + Vec2::new(x, y)).is_obstacle() {
-                        return 1000.0;
+                        max_cost = max_cost.max(1000.0);
+                    } else if !self.tiles.get(*tile + Vec2::new(x, y)).is_empty() {
+                        max_cost = max_cost.max(25.0);
                     }
                 }
             }
-            (tile.distance_squared(b) as f32).sqrt()
+            max_cost
         };
         let path = Astar::new(MAX_ITERS, a, &heuristic, DefaultHashBuilder::default())
             .poll(
@@ -488,7 +491,7 @@ impl Site {
                         .map(|aabr| aabr.distance_to_point(wpos2df))
                         .min_by_key(|d| (*d * 100.0) as i32);
 
-                    if dist.map_or(false, |d| d <= 3.0) {
+                    if dist.map_or(false, |d| d <= 1.5) {
                         let alt = canvas.col(wpos2d).map_or(0, |col| col.alt as i32);
                         (-8..6).for_each(|z| {
                             canvas.map(Vec3::new(wpos2d.x, wpos2d.y, alt + z), |b| {
@@ -521,8 +524,8 @@ impl Site {
                     if let TileKind::Road { a, b, w } = &tile.kind {
                         if let Some(PlotKind::Road(path)) = tile.plot.map(|p| &self.plot(p).kind) {
                             Some((LineSegment2 {
-                                start: self.tile_wpos(path.nodes()[*a as usize]).map(|e| e as f32),
-                                end: self.tile_wpos(path.nodes()[*b as usize]).map(|e| e as f32),
+                                start: self.tile_center_wpos(path.nodes()[*a as usize]).map(|e| e as f32),
+                                end: self.tile_center_wpos(path.nodes()[*b as usize]).map(|e| e as f32),
                             }, *w))
                         } else {
                             None
diff --git a/world/src/site2/plot/house.rs b/world/src/site2/plot/house.rs
index 352d458b3f..b9a32ce2a7 100644
--- a/world/src/site2/plot/house.rs
+++ b/world/src/site2/plot/house.rs
@@ -68,7 +68,7 @@ impl Structure for House {
         }));
         fill(
             outer,
-            Fill::Block(Block::new(BlockKind::Rock, Rgb::new(181, 170, 148))),
+            Fill::Brick(BlockKind::Rock, Rgb::new(80, 75, 85), 24),
         );
         fill(inner, Fill::Block(Block::empty()));
         let walls = prim(Primitive::Xor(outer, inner));
@@ -149,8 +149,8 @@ impl Structure for House {
             // Floor
             fill(
                 prim(Primitive::Aabb(Aabb {
-                    min: self.bounds.min.with_z(self.alt + height),
-                    max: (self.bounds.max + 1).with_z(self.alt + height + 1),
+                    min: (self.bounds.min + 1).with_z(self.alt + height),
+                    max: self.bounds.max.with_z(self.alt + height + 1),
                 })),
                 Fill::Block(Block::new(BlockKind::Rock, Rgb::new(89, 44, 14))),
             );