From f0cf7c2763eac47d2961aac6538554b412ca7dc2 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Fri, 2 Dec 2016 10:23:56 +0100 Subject: [PATCH] Fix loop detection in heuristic search based on pathfind_history. 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. --- src/peep/peep.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index bd2b11ee2e..0637e0cd13 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -9297,7 +9297,17 @@ static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep if (peep->pathfind_history[i].x == x >> 5 && peep->pathfind_history[i].y == y >> 5 && peep->pathfind_history[i].z == z) { - pathLoop = true; + if (peep->pathfind_history[i].direction == 0) { + /* If all directions have already been tried while + * heading to this goal, this is a loop. */ + pathLoop = true; + } + else { + /* The peep remembers walking through this junction + * before, but has not yet tried all directions. + * Limit the edges to search to those not yet tried. */ + edges &= peep->pathfind_history[i].direction; + } break; } }