diff --git a/Source/engine/path.cpp b/Source/engine/path.cpp index 08e54607981..06affadc504 100644 --- a/Source/engine/path.cpp +++ b/Source/engine/path.cpp @@ -160,13 +160,13 @@ int ReconstructPath(const ExploredNodes &explored, PointT dest, int8_t *path, si const auto it = explored.find(cur); if (it == explored.end()) app_fatal("Failed to reconstruct path"); if (it->second.g == 0) break; // reached start - path[len++] = GetPathDirection(it->second.prev, cur); - cur = it->second.prev; if (len == maxPathLength) { // Path too long. len = 0; break; } + path[len++] = GetPathDirection(it->second.prev, cur); + cur = it->second.prev; } std::reverse(path, path + len); std::fill(path + len, path + maxPathLength, -1); diff --git a/test/path_test.cpp b/test/path_test.cpp index dd457d3d935..73719ff1d6b 100644 --- a/test/path_test.cpp +++ b/test/path_test.cpp @@ -91,7 +91,8 @@ std::vector ToSyms(std::span indices) void CheckPath(Point startPosition, Point destinationPosition, std::vector expectedSteps) { - constexpr size_t MaxPathLength = 25; + // Restrict tests to the longest possible path length in vanilla Diablo + constexpr size_t MaxPathLength = 24; int8_t pathSteps[MaxPathLength]; auto pathLength = FindPath( /*canStep=*/[](Point, Point) { return true; }, @@ -153,7 +154,7 @@ TEST(PathTest, LongPaths) // Starting from the middle of the world and trying to path to a border exceeds the maximum path size CheckPath({ 56, 56 }, { 0, 0 }, {}); - // Longest possible path is currently 24 steps meaning tiles 24 units away are reachable + // Longest possible path used to be 24 steps meaning tiles 24 units away are reachable Point startingPosition { 56, 56 }; CheckPath(startingPosition, startingPosition + Displacement { 24, 24 }, std::vector(24, "↘"));