From b83ab8d6e7a34d0e05644a534e96db5ea265f82c Mon Sep 17 00:00:00 2001 From: zaxcav Date: Fri, 2 Dec 2016 10:15:33 +0100 Subject: [PATCH] Reset pathfind_history before the heuristic search function is called. 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. --- src/peep/peep.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 9bf5d9abd4..19e4be157c 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -9550,6 +9550,26 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) } } + /* If this is a new goal for the peep. Store it and reset the peep's + * pathfind_history. */ + if (peep->pathfind_goal.direction > 3 || + peep->pathfind_goal.x != goal.x || + peep->pathfind_goal.y != goal.y || + peep->pathfind_goal.z != goal.z + ) { + peep->pathfind_goal.x = goal.x; + peep->pathfind_goal.y = goal.y; + peep->pathfind_goal.z = goal.z; + peep->pathfind_goal.direction = 0; + + // Clear pathfinding history + memset(peep->pathfind_history, 0xFF, sizeof(peep->pathfind_history)); + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_verbose("New goal; clearing pf_history."); + } + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + } // Peep has tried all edges. if (edges == 0) return -1; @@ -9677,27 +9697,6 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 } - /* If this is a new goal for the peep. Store it and reset the peep's - * pathfind_history. */ - if (peep->pathfind_goal.direction > 3 || - peep->pathfind_goal.x != goal.x || - peep->pathfind_goal.y != goal.y || - peep->pathfind_goal.z != goal.z - ) { - peep->pathfind_goal.x = goal.x; - peep->pathfind_goal.y = goal.y; - peep->pathfind_goal.z = goal.z; - peep->pathfind_goal.direction = 0; - - // Clear pathfinding history - memset(peep->pathfind_history, 0xFF, sizeof(peep->pathfind_history)); - #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - if (gPathFindDebug) { - log_verbose("New goal; clearing pf_history."); - } - #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - } - if (isThin) { for (int i = 0; i < 4; ++i) { if (peep->pathfind_history[i].x == x >> 5 &&