-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix pathfinder zigzagging by only pathing between OMT centers #82577
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is entirely too magical a fix. That means that there is something else going on and you are likely adding a bug elsewhere.
|
Figuring out the need for the +1 felt like an excellent aha moment. I am pretty confident that the root cause of the original bug is what I've identified here. I agree that the mysterious off-by-three is too magical. I am hoping that this step toward a solution will prompt someone to point out what I missed. |
d6f7b3f to
ecbc144
Compare
|
Converting to draft while I attempt to address the problem of the last half-map of travel not being accounted for in the path cost analysis. |
|
My current effort is based on the idea of adding a fake pathfinding node connected to the center direction of the destination, and not ending pathfinding until the optimal path to THAT node is found, instead of the current behavior that ends after finding the "optimal" path to [the edge of] the destination map. |
ecbc144 to
823c111
Compare
|
I tried a few more approaches and decided that the increasing complexity isn't worth the better pathfinding in a few edge cases. I've updated this PR to undo the changes from #77556 that allowed pathfinding along map edges. This brings us back to pathfinding from OMT center to OMT center, but keeps diagonal pathfinding. |
823c111 to
83ebbe5
Compare
|
I'm not sure why the tests fail only on certain compilers/OSes. I'll be investigating. |



Summary
Bugfixes "Fix pathfinder zigzagging"
Purpose of change
When traveling orthogonally with a diagonal move at one end, the pathfinder will make a zigzag path. #82058 reported this and was closed when the vehicle diagonal pathfinding change was reverted, but the problem persists for foot travel.
Describe the solution
Undo the changes from #77556 that enabled pathfinding along map edges. Those changes improved pathfinding in rare edge cases, but also made it more expensive and introduced complexity that makes solving problems like this much harder, and would also have complicated upcoming efforts to make pathfinding compatible with highways.
Describe alternatives you've considered
See Discord discussion below https://discord.com/channels/598523535169945603/598529174302490644/1412437256802930789 and comments on this PR for description of some prior attempted solutions.
Testing
Did some overmap fast travel in game, confirmed paths generally look as expected and don't zig-zag.
Additional context
The pathfinder pretends that you can travel between vertices of the submap grid. This is generally a good abstraction, despite the player not actually occupying those locations but instead a tile adjacent to those locations. The abstraction breaks down when the pathfinder wants to travel along the edge of an OMT, thinking that there is no difference in cost between the two sides of that edge. A previous effort toward a solution was to add a penalty weight to the zigzag pattern, but this did not work reliably due to other complexities.
Also the pathfinder doesn't account for the cost of crossing half of the final map to reach its center, resulting in it scoring reaching the corner of that map as equivalent to reaching its edge. This causes the pathfinder to often prioritize traveling along the edges of a line of maps, which causes a zigzag.
I also added some new pathfinding test cases and additional checks and comments in existing test cases.