diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-11 18:48:31 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-11 18:48:31 +0200 |
commit | f78568656ffe39f7cc4db293570e29900cffc6f2 (patch) | |
tree | ecc1d44e642507c0ea6c23495a1199723f3dfe98 /server | |
parent | 1a2a29c0f39db6aea9c3ff1bdc038d59225def2c (diff) | |
download | hurrycurry-f78568656ffe39f7cc4db293570e29900cffc6f2.tar hurrycurry-f78568656ffe39f7cc4db293570e29900cffc6f2.tar.bz2 hurrycurry-f78568656ffe39f7cc4db293570e29900cffc6f2.tar.zst |
find path with distance
Diffstat (limited to 'server')
-rw-r--r-- | server/bot/src/pathfinding.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs index 87ccf391..d0c6c8ef 100644 --- a/server/bot/src/pathfinding.rs +++ b/server/bot/src/pathfinding.rs @@ -42,7 +42,12 @@ impl Path { } } -pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> { +pub fn find_path( + walkable: &HashSet<IVec2>, + from: IVec2, + to: IVec2, + dist_squared: i32, +) -> Option<Path> { #[derive(Debug, PartialEq, Eq)] struct Open(i32, IVec2, IVec2, i32); impl PartialOrd for Open { @@ -66,7 +71,7 @@ pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Pa continue; } visited.insert(pos, f); - if pos == to { + if pos.distance_squared(to) <= dist_squared { break; } for dir in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { |