From 5ff6199ba13d9d852e64174c8436bca456d14506 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Fri, 2 Dec 2016 10:55:40 +0100 Subject: [PATCH] Changes/additions to the pathfinding logging messages. 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. --- src/peep/peep.c | 122 +++++++++++++++++++++++++++++++++++++---------- src/peep/peep.h | 19 +++++--- src/peep/staff.c | 12 ++--- 3 files changed, 114 insertions(+), 39 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index aabc309143..2c7c549927 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -9675,6 +9675,12 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) rct_xyz8 endJunctionList[16] = { 0 }; uint8 endDirectionList[16] = { 0 }; + #if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 + if (gPathFindDebug) { + log_verbose("Pathfind searching in direction: %d from %d,%d,%d", test_edge, x >> 5, y >> 5, z); + } + #endif // defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 + peep_pathfind_heuristic_search(x, y, height, peep, first_map_element, 0, &score, test_edge, &endJunctions, endJunctionList, endDirectionList, &endXYZ, &endSteps); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) { @@ -9755,7 +9761,7 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) peep->pathfind_history[i].direction &= ~(1 << chosen_edge); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) { - log_verbose("Storing new pf_history for %d,%d,%d without edge %d.", x >> 5, y >> 5, z, chosen_edge); + log_verbose("Storing new pf_history (in index: %d) for %d,%d,%d without edge %d.", i, x >> 5, y >> 5, z, chosen_edge); } #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 } @@ -9882,18 +9888,13 @@ static int guest_path_find_park_entrance(rct_peep* peep, rct_map_element *map_el gPeepPathFindQueueRideIndex = 255; #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - /* Determine if the pathfinding debugging is wanted for this peep. */ - /* For guests, use the existing PEEP_FLAGS_TRACKING flag to - * determine for which guest(s) the pathfinding debugging will - * be output for. */ - format_string(gPathFindDebugPeepName, sizeof(gPathFindDebugPeepName), peep->name_string_idx, &(peep->id)); - gPathFindDebug = peep->peep_flags & PEEP_FLAGS_TRACKING; + pathfind_logging_enable(peep); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 int chosenDirection = peep_pathfind_choose_direction(peep->next_x, peep->next_y, peep->next_z, peep); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - gPathFindDebug = false; + pathfind_logging_disable(); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (chosenDirection == -1) @@ -10033,6 +10034,13 @@ static int guest_path_finding(rct_peep* peep) { sint16 x, y, z; + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + pathfind_logging_enable(peep); + if (gPathFindDebug) { + log_info("Starting guest_path_finding for %s", gPathFindDebugPeepName); + } + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (peep->next_var_29 & 0x18) { return guest_surface_path_finding(peep); } @@ -10088,6 +10096,12 @@ static int guest_path_finding(rct_peep* peep) direction = bitscanforward(edges); // IF only one edge to choose from if ((edges & ~(1 << direction)) == 0) { + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - taking only direction available: %d.", gPathFindDebugPeepName, direction); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 return peep_move_one_tile(direction, peep); } @@ -10096,6 +10110,12 @@ static int guest_path_finding(rct_peep* peep) // Peep is outside the park. // loc_694F19: if (peep->outside_of_park != 0){ + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - peep is outside the park.", gPathFindDebugPeepName); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 switch (peep->state) { case PEEP_STATE_ENTERING_PARK: return guest_path_find_entering_park(peep, mapElement, edges); @@ -10149,18 +10169,39 @@ static int guest_path_finding(rct_peep* peep) } } - if (peep->peep_flags & PEEP_FLAGS_LEAVING_PARK) + if (peep->peep_flags & PEEP_FLAGS_LEAVING_PARK) { + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - peep is leaving the park.", gPathFindDebugPeepName); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 return guest_path_find_park_entrance(peep, mapElement, edges); + } - if (peep->guest_heading_to_ride_id == 0xFF) + if (peep->guest_heading_to_ride_id == 0xFF) { + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - peep is aimless.", gPathFindDebugPeepName); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 return guest_path_find_aimless(peep, edges); + } // Peep is heading for a ride. uint8 rideIndex = peep->guest_heading_to_ride_id; rct_ride* ride = get_ride(rideIndex); - if (ride->status != RIDE_STATUS_OPEN) + if (ride->status != RIDE_STATUS_OPEN) { + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - peep is heading to closed ride == aimless.", gPathFindDebugPeepName); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 return guest_path_find_aimless(peep, edges); + } // The ride is open. gPeepPathFindQueueRideIndex = rideIndex; @@ -10232,21 +10273,8 @@ static int guest_path_finding(rct_peep* peep) gPeepPathFindGoalPosition = (rct_xyz16) { x, y, z }; gPeepPathFindIgnoreForeignQueues = true; - #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - /* Determine if the pathfinding debugging is wanted for this peep. */ - /* For guests, use the existing PEEP_FLAGS_TRACKING flag to - * determine for which guest(s) the pathfinding debugging will - * be output for. */ - format_string(gPathFindDebugPeepName, sizeof(gPathFindDebugPeepName), peep->name_string_idx, &(peep->id)); - gPathFindDebug = peep->peep_flags & PEEP_FLAGS_TRACKING; - #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - direction = peep_pathfind_choose_direction(peep->next_x, peep->next_y, peep->next_z, peep); - #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - gPathFindDebug = false; - #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 @@ -10256,8 +10284,21 @@ static int guest_path_finding(rct_peep* peep) * save game (e.g. with a worse version of the pathfinding). */ peep_reset_pathfind_goal(peep); + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - failed to choose a direction == aimless.", gPathFindDebugPeepName); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + return guest_path_find_aimless(peep, edges); } + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Completed guest_path_finding for %s - direction chosen: %d.", gPathFindDebugPeepName, direction); + } + pathfind_logging_disable(); + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 return peep_move_one_tile(direction, peep); } @@ -11015,6 +11056,13 @@ static bool peep_should_use_cash_machine(rct_peep *peep, int rideIndex) */ void peep_reset_pathfind_goal(rct_peep *peep) { + + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + if (gPathFindDebug) { + log_info("Resetting pathfind_goal for %s", gPathFindDebugPeepName); + } + #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + peep->pathfind_goal.x = 0xFF; peep->pathfind_goal.y = 0xFF; peep->pathfind_goal.z = 0xFF; @@ -12573,3 +12621,29 @@ void game_command_set_guest_name(int *eax, int *ebx, int *ecx, int *edx, int *es (uint8*)edi ); } + +void pathfind_logging_enable(rct_peep* peep) { + #if defined(PATHFIND_DEBUG) && PATHFIND_DEBUG + /* Determine if the pathfinding debugging is wanted for this peep. */ + format_string(gPathFindDebugPeepName, sizeof(gPathFindDebugPeepName), peep->name_string_idx, &(peep->id)); + + /* For guests, use the existing PEEP_FLAGS_TRACKING flag to + * determine for which guest(s) the pathfinding debugging will + * be output for. */ + if (peep->type == PEEP_TYPE_GUEST){ + gPathFindDebug = peep->peep_flags & PEEP_FLAGS_TRACKING; + } + /* For staff, there is no tracking button (any other similar + * suitable existing mechanism?), so fall back to a crude + * string comparison with a compile time hardcoded name. */ + else { + gPathFindDebug = strcmp(gPathFindDebugPeepName, "Mechanic Debug") == 0; + } + #endif // defined(PATHFIND_DEBUG) && PATHFIND_DEBUG +} + +void pathfind_logging_disable() { + #if defined(PATHFIND_DEBUG) && PATHFIND_DEBUG + gPathFindDebug = false; + #endif // defined(PATHFIND_DEBUG) && PATHFIND_DEBUG +} diff --git a/src/peep/peep.h b/src/peep/peep.h index f7a30de629..17a3daea98 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -20,12 +20,6 @@ #include "../common.h" #include "../world/map.h" -#if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 -// Some variables used for the path finding debugging. -extern bool gPathFindDebug; -extern utf8 gPathFindDebugPeepName[256]; -#endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - #define PEEP_MAX_THOUGHTS 5 #define PEEP_HUNGER_WARNING_THRESHOLD 25 @@ -687,4 +681,17 @@ void game_command_set_guest_name(int *eax, int *ebx, int *ecx, int *edx, int *es int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep); void peep_reset_pathfind_goal(rct_peep *peep); +#if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 +#define PATHFIND_DEBUG 0 // Set to 0 to disable pathfinding debugging; + // Set to 1 to enable pathfinding debugging. +// Some variables used for the path finding debugging. +extern bool gPathFindDebug; // Use to guard calls to log messages +extern utf8 gPathFindDebugPeepName[256]; // Use to put the peep name in the log message + +// The following calls set the above two variables for a peep. +// ... when PATHFIND_DEBUG is 1 (non zero) +void pathfind_logging_enable(rct_peep* peep); +void pathfind_logging_disable(); +#endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 + #endif diff --git a/src/peep/staff.c b/src/peep/staff.c index 0ba60a2296..1ee228216f 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -1073,7 +1073,7 @@ static uint8 staff_mechanic_direction_path(rct_peep* peep, uint8 validDirections gPeepPathFindGoalPosition.z = z; /* Find location of the exit for the target ride station - * or if the ride has no exit, the entrance */ + * or if the ride has no exit, the entrance. */ uint16 location = ride->exits[peep->current_ride_station]; if (location == 0xFFFF) { location = ride->entrances[peep->current_ride_station]; @@ -1113,19 +1113,13 @@ static uint8 staff_mechanic_direction_path(rct_peep* peep, uint8 validDirections gPeepPathFindQueueRideIndex = 255; #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - /* Determine if the pathfinding debugging is wanted for this peep. */ - /* For staff, there is no tracking button (any other similar - * suitable existing mechanism?), so fall back to a crude - * string comparison with a compile time hardcoded name. */ - format_string(gPathFindDebugPeepName, sizeof(gPathFindDebugPeepName), peep->name_string_idx, &(peep->id)); - - gPathFindDebug = strcmp(gPathFindDebugPeepName, "Mechanic Debug") == 0; + pathfind_logging_enable(peep); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 int pathfindDirection = peep_pathfind_choose_direction(peep->next_x, peep->next_y, peep->next_z, peep); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - gPathFindDebug = false; + pathfind_logging_disable(); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (pathfindDirection == -1) {