From 8ba5b4363634c25ca67c3413fdd1cecc305c9205 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 6 Aug 2019 21:28:34 +0100 Subject: [PATCH 1/3] Fix #9729. Change peep pathfinding to take entrance height into account When choosing which entrance to head to peeps would not take into account the height difference between the locations. This caused peeps to choose badly especially when useing lift transport rides. --- distribution/changelog.txt | 2 ++ src/openrct2/peep/GuestPathfinding.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index fe7e27a598..977babe0a3 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -7,6 +7,8 @@ - Fix: [#9625] Show correct cost in scenery selection. - Fix: [#9669] The tile inspector shortcut key does not work with debugging tools disabled. - Fix: [#9717] Scroll bars do not render correctly when using OpenGL renderer. +- Fix: [#9729] Peeps do not take into account height difference when +deciding to pathfind to a ride entrance. (original bug) - Improved: [#9466] Add the rain weather effect to the OpenGL renderer. 0.2.3 (2019-07-10) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 7837749dc4..44963d1239 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -2054,7 +2054,7 @@ int32_t guest_path_finding(Guest* peep) /* Find the ride's closest entrance station to the peep. * At the same time, count how many entrance stations there are and * which stations are entrance stations. */ - uint16_t closestDist = 0xFFFF; + uint16_t bestScore = 0xFFFF; uint8_t closestStationNum = 0; int32_t numEntranceStations = 0; @@ -2073,11 +2073,11 @@ int32_t guest_path_finding(Guest* peep) int16_t stationX = (int16_t)(entranceLocation.x * 32); int16_t stationY = (int16_t)(entranceLocation.y * 32); - uint16_t dist = abs(stationX - peep->next_x) + abs(stationY - peep->next_y); - - if (dist < closestDist) + uint16_t score = abs(stationX - peep->next_x) + abs(stationY - peep->next_y); + score += abs(entranceLocation.z - peep->next_z) * 2; + if (score < bestScore) { - closestDist = dist; + bestScore = score; closestStationNum = stationNum; continue; } From 2557e373dbdbe77e810e28bff7dfe331fc4721f4 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 6 Aug 2019 21:29:08 +0100 Subject: [PATCH 2/3] Increment network version --- src/openrct2/network/Network.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 401465bf5c..47a92e47de 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -34,7 +34,7 @@ // This string 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 "3" +#define NETWORK_STREAM_VERSION "4" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; From ad06491d213530ec91f3b08de35f2066732b052e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 7 Aug 2019 20:35:20 +0100 Subject: [PATCH 3/3] Abstract the common score generator --- distribution/changelog.txt | 3 +-- src/openrct2/peep/GuestPathfinding.cpp | 35 ++++++++++++++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 977babe0a3..3380b6b86f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -7,8 +7,7 @@ - Fix: [#9625] Show correct cost in scenery selection. - Fix: [#9669] The tile inspector shortcut key does not work with debugging tools disabled. - Fix: [#9717] Scroll bars do not render correctly when using OpenGL renderer. -- Fix: [#9729] Peeps do not take into account height difference when -deciding to pathfind to a ride entrance. (original bug) +- Fix: [#9729] Peeps do not take into account height difference when deciding to pathfind to a ride entrance. (original bug) - Improved: [#9466] Add the rain weather effect to the OpenGL renderer. 0.2.3 (2019-07-10) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 44963d1239..ddf2dd4d8f 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -505,6 +505,20 @@ static bool path_is_thin_junction(TileElement* path, TileCoordsXYZ loc) return thin_junction; } +static int32_t CalculateHeuristicPathingScore(TileCoordsXYZ loc1, TileCoordsXYZ loc2) +{ + auto xDelta = abs(loc1.x - loc2.x) * 32; + auto yDelta = abs(loc1.y - loc2.y) * 32; + auto zDelta = abs(loc1.z - loc2.z) * 2; + + if (xDelta < yDelta) + xDelta >>= 4; + else + yDelta >>= 4; + + return xDelta + yDelta + zDelta; +} + /** * Searches for the tile with the best heuristic score within the search limits * starting from the given tile x,y,z and going in the given direction test_edge. @@ -784,16 +798,7 @@ static void peep_pathfind_heuristic_search( * Ignore for now. */ // Calculate the heuristic score of this map element. - uint16_t x_delta = abs(gPeepPathFindGoalPosition.x - loc.x) * 32; - uint16_t y_delta = abs(gPeepPathFindGoalPosition.y - loc.y) * 32; - if (x_delta < y_delta) - x_delta >>= 4; - else - y_delta >>= 4; - uint16_t new_score = x_delta + y_delta; - uint16_t z_delta = abs(gPeepPathFindGoalPosition.z - loc.z); - z_delta <<= 1; - new_score += z_delta; + uint16_t new_score = CalculateHeuristicPathingScore(loc, gPeepPathFindGoalPosition); /* If this map element is the search goal the current search path ends here. */ if (new_score == 0) @@ -2054,7 +2059,7 @@ int32_t guest_path_finding(Guest* peep) /* Find the ride's closest entrance station to the peep. * At the same time, count how many entrance stations there are and * which stations are entrance stations. */ - uint16_t bestScore = 0xFFFF; + auto bestScore = std::numeric_limits::max(); uint8_t closestStationNum = 0; int32_t numEntranceStations = 0; @@ -2070,11 +2075,9 @@ int32_t guest_path_finding(Guest* peep) entranceStations |= (1 << stationNum); TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, stationNum); - - int16_t stationX = (int16_t)(entranceLocation.x * 32); - int16_t stationY = (int16_t)(entranceLocation.y * 32); - uint16_t score = abs(stationX - peep->next_x) + abs(stationY - peep->next_y); - score += abs(entranceLocation.z - peep->next_z) * 2; + auto score = CalculateHeuristicPathingScore( + { entranceLocation.x, entranceLocation.y, entranceLocation.z }, + { peep->next_x / 32, peep->next_y / 32, peep->next_z }); if (score < bestScore) { bestScore = score;