diff options
Diffstat (limited to 'server/src/customer/pathfinding.rs')
-rw-r--r-- | server/src/customer/pathfinding.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/server/src/customer/pathfinding.rs b/server/src/customer/pathfinding.rs index 5354407f..5056975e 100644 --- a/server/src/customer/pathfinding.rs +++ b/server/src/customer/pathfinding.rs @@ -1,19 +1,19 @@ /* Undercooked - a game about cooking Copyright 2024 metamuffin - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License only. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. - + */ use super::movement::MovementBase; use crate::protocol::PacketS; @@ -29,22 +29,22 @@ pub struct Path(Vec<Vec2>); impl Path { pub fn execute_tick( &mut self, - customer: &mut MovementBase, + player: &mut MovementBase, walkable: &HashSet<IVec2>, dt: f32, ) -> PacketS { if let Some(next) = self.0.last().copied() { debug!("next {next}"); - if next.distance(customer.position) < if self.0.len() == 1 { 0.1 } else { 0.6 } { + if next.distance(player.position) < if self.0.len() == 1 { 0.1 } else { 0.6 } { self.0.pop(); } - customer.update( + player.update( &walkable, - (next - customer.position).normalize_or_zero() * 0.5, + (next - player.position).normalize_or_zero() * 0.5, dt, ) } else { - customer.update(&walkable, Vec2::ZERO, dt) + player.update(&walkable, Vec2::ZERO, dt) } } pub fn is_done(&self) -> bool { @@ -52,7 +52,7 @@ impl Path { } } -pub fn find_path(map: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> { +pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> { #[derive(Debug, PartialEq, Eq)] struct Open(i32, IVec2, IVec2); impl PartialOrd for Open { @@ -84,7 +84,7 @@ pub fn find_path(map: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> { } for d in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { let n = p + d; - if map.contains(&n) { + if walkable.contains(&n) { open.push(Open(-d.distance_squared(to), n, p)); } } |