From 2f4c5c4a06211afbfee9e4b17625aae3c773e6a1 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Fri, 2 Dec 2016 10:49:15 +0100 Subject: [PATCH] Reset pathfind_goal when choose direction fails. 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. --- src/peep/peep.c | 12 ++++++++++-- src/peep/peep.h | 1 + src/peep/staff.c | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 0637e0cd13..aabc309143 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -143,7 +143,7 @@ static void peep_ride_is_too_intense(rct_peep *peep, int rideIndex, bool peepAtR static void peep_chose_not_to_go_on_ride(rct_peep *peep, int rideIndex, bool peepAtRide, bool updateLastRide); static void peep_tried_to_enter_full_queue(rct_peep *peep, int rideIndex); static bool peep_should_go_to_shop(rct_peep *peep, int rideIndex, bool peepAtShop); -static void peep_reset_pathfind_goal(rct_peep *peep); +void peep_reset_pathfind_goal(rct_peep *peep); static bool peep_find_ride_to_look_at(rct_peep *peep, uint8 edge, uint8 *rideToView, uint8 *rideSeatToView); static void peep_easter_egg_peep_interactions(rct_peep *peep); static int peep_get_height_on_slope(rct_peep *peep, int x, int y); @@ -10248,6 +10248,14 @@ static int guest_path_finding(rct_peep* peep) #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (direction == -1){ + /* Heuristic search failed for all directions. + * Reset the pathfind_goal - this means that the pathfind_history + * will be reset in the next call to peep_pathfind_choose_direction(). + * This lets the heuristic search "try again" in case the player has + * edited the path layout or the mechanic was already stuck in the + * save game (e.g. with a worse version of the pathfinding). */ + peep_reset_pathfind_goal(peep); + return guest_path_find_aimless(peep, edges); } return peep_move_one_tile(direction, peep); @@ -11005,7 +11013,7 @@ static bool peep_should_use_cash_machine(rct_peep *peep, int rideIndex) * * rct2: 0x0069A98C */ -static void peep_reset_pathfind_goal(rct_peep *peep) +void peep_reset_pathfind_goal(rct_peep *peep) { peep->pathfind_goal.x = 0xFF; peep->pathfind_goal.y = 0xFF; diff --git a/src/peep/peep.h b/src/peep/peep.h index bb86b94cb1..f7a30de629 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -685,5 +685,6 @@ money32 set_peep_name(int flags, int state, uint16 sprite_index, uint8* text_1, void game_command_set_guest_name(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep); +void peep_reset_pathfind_goal(rct_peep *peep); #endif diff --git a/src/peep/staff.c b/src/peep/staff.c index d8eac92e62..0ba60a2296 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -1129,6 +1129,13 @@ static uint8 staff_mechanic_direction_path(rct_peep* peep, uint8 validDirections #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (pathfindDirection == -1) { + /* Heuristic search failed for all directions. + * Reset the pathfind_goal - this means that the pathfind_history + * will be reset in the next call to peep_pathfind_choose_direction(). + * This lets the heuristic search "try again" in case the player has + * edited the path layout or the mechanic was already stuck in the + * save game (e.g. with a worse version of the pathfinding). */ + peep_reset_pathfind_goal(peep); return staff_mechanic_direction_path_rand(peep, pathDirections); }