-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix off-by-one in path finding logic #7682
Conversation
That does fix it in game. But now the tests are broken 🫠 |
The failing test says: // Longest possible path is currently 24 steps meaning tiles 24 units away are reachable
Point startingPosition { 56, 56 };
CheckPath(startingPosition, startingPosition + Displacement { 24, 24 }, std::vector<std::string>(24, "↘"));
// But trying to navigate 25 units fails
CheckPath(startingPosition, startingPosition + Displacement { 25, 25 }, {}); However, the longest possible path is actually 25, so I think the test is wrong (or we can reduce the maximum path length for monsters to 24, I think that might be closer to previous behaviour) |
f995ba8
to
00d08c0
Compare
I kept the monster path length at 25 because I do not think it particularly matters. Assuming the save format supports path lengths of 25, I think it's reasonable to consider this a bugfix. I restricted the path tests to 24 so we wouldn't have to change the current test suite. It's still a good test to demonstrate we are appropriately failing when we reach the maximum path length. |
This was a flaw in the vanilla pathfinding code. The array that stored pathfinding steps had room for 25 entries, but vanilla logic would never use the final entry. https://github.com/diasurgical/devilution/blob/6b7135cec37e9cf0f6740d7e1a1ec880f89e73ff/Source/path.cpp#L78 should've been <= instead to allow for up to 25 steps instead of limiting to 24 or fewer. The test was set up to document that restriction but now that it's been fixed changing the test is fine. |
This fixes an issue where items and objects can no longer be interacted with unless the player is on top of them.
In the following conditional statement, the call to
GetDistance()
always returned zero. The reason is that the logic thought that a path of length 1 exceeds the maximum path length of 1 that was passed in via the second argument.devilutionX/Source/controls/plrctrls.cpp
Lines 171 to 174 in 20c0a8d
This resolves #7681