Refactored some code into functions for enabling/disabling pathfinding debugging for a specific peep.
Some new log messages for improved clarity when debugging pathfinding.
Added a #define to independently enable/disable pathfinding debugging to be friendly to others using debugging builds.
Currently pathfinding falls back to aimless movement in this case.
Resetting the pathfind_goal (which in turn will cause the pathfind_history to be reset) makes the pathfinding try again afresh the next time around.
Potentially useful for adjusting to path changes by the player and recovering from a stuck position due to earlier bad pathfinding.
In the existing version, returning to a junction in the pathfind history is considered a loop. This is not useful as it prevents the pathfinding from backtracking, which is what the pathfind_history is intended to allow.
Updated to consider it a loop only when returning to a junction with no more edges left to try.
When choosing a direction at a junction in pathfind_history (with no untried directions) the existing path finding falls back to aimless movement.
This change makes the pathfinding try again.
Useful for adjusting to path changes by the player and recovering from a stuck position in a savegame due to earlier bad pathfinding.
Now that the heuristic search uses the pathfind_history for loop detection it is important that when the pathfind_goal is reset the pathfind_history gets reset before calling the heuristic search.
This is applicable for overlaid paths placed with zero clearance.
Previously the pathfinding only used the first path element.
Notes:
1. Logic related to path slope still only uses the the first path element. Overlaying path elements with the same base height but different slopes may cause pathfinding glitches.
2. The heuristic search already uses a similar approach - the inconsistency could have caused pathfinding glitches.
The heuristic search currently only inludes detection of loops in the current search path - i.e. from where the peep is now.
The peep->pathfind_history includes (limited) junctions that the peep has already passed through for the current search goal to get to their current location. Consider search paths through these junctions as loops as well.
This will prevent peeps getting stuck in some path layouts where looping back through a junction they already walked through and then proceeding via an alternative path (such that there is no loop in the current search path) hits the search limits on a continuing path that is closer to the goal than simply continuing on along the path which then turns (temporarily) away from the goal.
This prevents _some_ cases of alternate, longer routes to nearer tiles being returned as a better result than a route that goes through that same tile (with less steps) and then continues on to end overall further from the goal though closer to getting to the goal (as was previously documented in PR #4527).
The network version is incremented in this PR.
When sending a mechanic to a ride exit/entrance, the original pathfinding was setting the goal to the path next to the exit/entrance with goal.z set to the exit/entrance height. This is wrong when the path slopes up to the exit/entrance. Consequently the original pathfinding included a hack to allow the mechanic to enter the exit/entrance from the goal tile.
The changes in PR #4527 (commit f3cf23f) will ignore the relevant tile when the height is wrong, preventing the original hack from working. To fix this the height of paths sloping up was adjusted in the heuristic search ... which inadvertently broke pathfinding for other goals on such a sloped path (such as the start of a ride queue that slopes up).
To fix, set the goal to the ride exit/entrance itself, make the heuristic search aware of ride exits (code existed but was commented out; entrances are already there for rides without queues) and remove both the original hack and the (incorrect) heigh adjustment made in PR #4527.
Fixes issues #4626, #4629.
Use of zero clearance will no longer block the path finding when paths and other map elements are placed in the same tile at the same height.
Pathfinding recognises map elements for shops, so peeps can find shops again.
Pathfinding recognises the park entrance, so peeps can leave the park again.
This commit also renamed a flag, and corrected the use of one. The
flags in question are WALL_SCENERY_BANNER, WALL_SCENERY_2_FLAG4, and
WALL_SCENERY_2_FLAG5.