From e82a2de997a1ebca4a8d1fcfeb1a85e33d65aa8f Mon Sep 17 00:00:00 2001 From: zaxcav Date: Thu, 29 Dec 2016 21:18:02 +0100 Subject: [PATCH] Constrain mechanics to their patrol area when heading to a ride --- src/network/network.h | 2 +- src/peep/peep.c | 32 +++++++++++++++++++++++++++++--- src/peep/staff.c | 6 +----- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/network/network.h b/src/network/network.h index 4d1c0a134d..20bf04e9c4 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -55,7 +55,7 @@ extern "C" { // This define specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "24" +#define NETWORK_STREAM_VERSION "25" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #ifdef __cplusplus diff --git a/src/peep/peep.c b/src/peep/peep.c index bd298c4544..e0ea091883 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -9005,7 +9005,7 @@ static bool path_is_thin_junction(rct_map_element *path, sint16 x, sint16 y, uin * * rct2: 0x0069A997 */ -static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep *peep, rct_map_element *currentMapElement, uint8 counter, uint16 *endScore, int test_edge, uint8 *endJunctions, rct_xyz8 junctionList[16], uint8 directionList[16], rct_xyz8 *endXYZ, uint8 *endSteps) { +static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep *peep, rct_map_element *currentMapElement, bool inPatrolArea, uint8 counter, uint16 *endScore, int test_edge, uint8 *endJunctions, rct_xyz8 junctionList[16], uint8 directionList[16], rct_xyz8 *endXYZ, uint8 *endSteps) { uint8 searchResult = PATH_SEARCH_FAILED; x += TileDirectionDelta[test_edge].x; @@ -9028,6 +9028,23 @@ static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep return; } + + bool nextInPatrolArea = inPatrolArea; + if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_MECHANIC) { + nextInPatrolArea = staff_is_location_in_patrol(peep, x, y); + if (inPatrolArea && !nextInPatrolArea) { + /* The mechanic will leave his patrol area by taking + * the test_edge so the current search path ends here. + * Return without updating the parameters (best result so far). */ + #if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 + if (gPathFindDebug) { + log_info("[%03d] Return from %d,%d,%d; Left patrol area", counter, x >> 5, y >> 5, z); + } + #endif // defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 + return; + } + } + /* Get the next map element of interest in the direction of test_edge. */ bool found = false; rct_map_element *mapElement = map_get_first_element_at(x / 32, y / 32); @@ -9437,7 +9454,7 @@ static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep _peepPathFindHistory[_peepPathFindNumJunctions + 1].direction = test_edge; } - peep_pathfind_heuristic_search(x, y, height, peep, mapElement, counter, endScore, test_edge, endJunctions, junctionList, directionList, endXYZ, endSteps); + peep_pathfind_heuristic_search(x, y, height, peep, mapElement, nextInPatrolArea, counter, endScore, test_edge, endJunctions, junctionList, directionList, endXYZ, endSteps); _peepPathFindNumJunctions = savedNumJunctions; #if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 @@ -9703,13 +9720,22 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep) rct_xyz8 endJunctionList[16] = { 0 }; uint8 endDirectionList[16] = { 0 }; + bool inPatrolArea = false; + if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_MECHANIC) { + /* Mechanics are the only staff type that + * pathfind to a destination. Determine if the + * mechanic is in their patrol area. */ + inPatrolArea = staff_is_location_in_patrol(peep, peep->next_x, peep->next_y); + } + #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); + peep_pathfind_heuristic_search(x, y, height, peep, first_map_element, inPatrolArea, 0, &score, test_edge, &endJunctions, endJunctionList, endDirectionList, &endXYZ, &endSteps); + #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) { log_verbose("Pathfind test edge: %d score: %d steps: %d end: %d,%d,%d junctions: %d", test_edge, score, endSteps, endXYZ.x, endXYZ.y, endXYZ.z, endJunctions); diff --git a/src/peep/staff.c b/src/peep/staff.c index 2d71dd5640..a462cec7a3 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -1035,11 +1035,7 @@ static uint8 staff_mechanic_direction_path(rct_peep* peep, uint8 validDirections uint8 direction = 0xFF; uint8 pathDirections = pathElement->properties.path.edges & 0xF; - if (peep->state != PEEP_STATE_ANSWERING && peep->state != PEEP_STATE_HEADING_TO_INSPECTION) { - /* Mechanic is patrolling, so mask with the valid - * patrol directions */ - pathDirections &= validDirections; - } + pathDirections &= validDirections; if (pathDirections == 0) { return staff_mechanic_direction_surface(peep);