Skip to content

Commit e41d9be

Browse files
author
rtri
committed
fix #5411
1 parent ae0ef2f commit e41d9be

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rts/Sim/Path/Default/PathFinderDef.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ bool CPathFinderDef::IsGoal(unsigned int xSquare, unsigned int zSquare) const {
3131
// returns distance to goal center in heightmap-squares
3232
float CPathFinderDef::Heuristic(unsigned int xSquare, unsigned int zSquare, unsigned int blockSize) const
3333
{
34-
const float s = 1.0f / blockSize;
35-
const float dx = std::abs(int(xSquare) - int(goalSquareX)) * s;
36-
const float dz = std::abs(int(zSquare) - int(goalSquareZ)) * s;
34+
(void) blockSize;
3735

38-
// grid is 8-connected, so use octile distance (normalized by block-size)
39-
constexpr const float C1 = 1.0f;
40-
constexpr const float C2 = 1.4142f - (2.0f * C1);
36+
const float dx = std::abs(int(xSquare) - int(goalSquareX));
37+
const float dz = std::abs(int(zSquare) - int(goalSquareZ));
38+
39+
// grid is 8-connected, so use octile distance metric
40+
// note that using C1=1 and C2=sqrt(2) will over-estimate
41+
// on terrain with extreme speed modifiers, so scale both
42+
constexpr const float C1 = 1.0f * 0.5f;
43+
constexpr const float C2 = 1.4142f * 0.5f - (2.0f * C1);
4144
return ((dx + dz) * C1 + std::min(dx, dz) * C2);
4245
}
4346

0 commit comments

Comments
 (0)