From 8c7e96e313182edeb2d9d18e01e0b132290d3cf9 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 25 Jan 2020 20:43:34 +0000 Subject: [PATCH] Improved waypoint spawn locations, scaled down pathfinding cost --- common/src/path.rs | 2 +- server/src/lib.rs | 2 +- world/src/lib.rs | 2 +- world/src/sim/mod.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/common/src/path.rs b/common/src/path.rs index f75c8c77d4..1797a1d5ec 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -246,7 +246,7 @@ where Some(astar) => astar, }; - let path_result = new_astar.poll(30, heuristic, neighbors, transition, satisfied); + let path_result = new_astar.poll(20, heuristic, neighbors, transition, satisfied); *astar = Some(new_astar); diff --git a/server/src/lib.rs b/server/src/lib.rs index 064cf39496..2c190be2d6 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -971,7 +971,7 @@ impl Server { ( &self.state.ecs().entities(), &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), + !&self.state.ecs().read_storage::(), ) .join() .filter(|(_, pos, _)| terrain.get(pos.0.map(|e| e.floor() as i32)).is_err()) diff --git a/world/src/lib.rs b/world/src/lib.rs index 7d205bb16a..3745a84a1a 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -167,7 +167,7 @@ impl World { }, }; - if chunk_pos.map(|e| e % 8 == 0).reduce_and() { + if sim_chunk.contains_waypoint { supplement = supplement.with_entity(EntityInfo { pos: gen_entity_pos(), kind: EntityKind::Waypoint, diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index b8bd973eef..0eb8e9399e 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1446,6 +1446,50 @@ impl WorldSim { chunk.structures.town = maybe_town; }); + // Create waypoints + const WAYPOINT_EVERY: usize = 8; + let this = &self; + let waypoints = (0..WORLD_SIZE.x) + .step_by(WAYPOINT_EVERY) + .map(|i| { + (0..WORLD_SIZE.y) + .step_by(WAYPOINT_EVERY) + .filter_map(move |j| { + let mut pos = Vec2::new(i as i32, j as i32); + + // Slide the waypoints down hills + loop { + let last_pos = pos; + let alt = this.get(pos + Vec2::new(1, 0))?.alt; + const MAX_HEIGHT_DIFF: f32 = 5.0; + if this.get(pos + Vec2::new(1, 0))?.alt + MAX_HEIGHT_DIFF < alt { + pos.x += 1; + } + if this.get(pos + Vec2::new(-1, 0))?.alt + MAX_HEIGHT_DIFF < alt { + pos.x -= 1; + } + if this.get(pos + Vec2::new(0, 1))?.alt + MAX_HEIGHT_DIFF < alt { + pos.y += 1; + } + if this.get(pos + Vec2::new(0, -1))?.alt + MAX_HEIGHT_DIFF < alt { + pos.y -= 1; + } + + if last_pos == pos { + break; + } + } + + Some(pos) + }) + }) + .flatten() + .collect::>(); + + for waypoint in waypoints { + self.get_mut(waypoint).map(|sc| sc.contains_waypoint = true); + } + self.rng = rng; self.locations = locations; } @@ -1679,6 +1723,7 @@ pub struct SimChunk { pub is_underwater: bool, pub structures: Structures, + pub contains_waypoint: bool, } #[derive(Copy, Clone)] @@ -1922,6 +1967,7 @@ impl SimChunk { location: None, river, structures: Structures { town: None }, + contains_waypoint: false, } }