Fix #10452: Limit river generation max_search_nodes #11544
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevent long stalls during river generation by capping the maximum search nodes to be the same as that defined in NPF.
Motivation / Problem
See #10452 (comment)
Terraforming occurs during river generation which causes issues for the pathfinding. If the tile the pathfinder is working with is no longer flat, a long stall occurs due to the pathfinding doing an exhaustive search around that tile, trying to connect a river path to it and ultimately failing in the end, leaving a river disconnected somewhere along the way from the spring to the sea.
The stall can last up to 3-5 minutes until all paths are tried.
https://github.com/OpenTTD/OpenTTD/assets/43006711/cbb18259-51cc-4f18-9b4e-3248334f4f11
Description
This PR fixes the stall, by preventing the pathfinder from initializing max_search_nodes as 0 (= infinite). Since AyStar is used, I created a constant with the default value equal to that of both NPF and YAPF and have it referred.
Limitations
This does not fix the river becoming disconnected due to terraforming.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.