From dd89a32016b08d9799b30327ed3751fb4250a0e8 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Fri, 2 Dec 2016 10:20:49 +0100 Subject: [PATCH] Reset pathfind_history[i].direction when all directions have been tried. 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. --- src/peep/peep.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/peep/peep.c b/src/peep/peep.c index 19e4be157c..bd2b11ee2e 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -9545,6 +9545,25 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) log_verbose("Getting untried edges from pf_history for %d,%d,%d: %s,%s,%s,%s", x >> 5, y >> 5, z, (edges & 1) ? "0" : "-", (edges & 2) ? "1" : "-", (edges & 4) ? "2" : "-", (edges & 8) ? "3" : "-"); } #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + + if (edges == 0) { + /* If peep has tried all edges, reset to + * all edges are untried. + * This permits the pathfinding to try + * again, which is good for getting + * unstuck when the player has edited + * the paths or the pathfinding itself + * has changed (been fixed) since + * the game was saved. */ + peep->pathfind_history[i].direction = permitted_edges; + edges = peep->pathfind_history[i].direction; + + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_verbose("All edges tried for %d,%d,%d - resetting to all untried", x >> 5, y >> 5, z); + } + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + } break; } }