From b829b224157872e0547135dbfca07a1995d55194 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:01:35 -0300 Subject: [PATCH] Use CoordsXYRangedZ on fence_in_the_way() --- src/openrct2/peep/GuestPathfinding.cpp | 43 +++++++++++++------------- src/openrct2/peep/Peep.h | 2 ++ src/openrct2/peep/Staff.cpp | 10 ++++-- src/openrct2/world/Footpath.cpp | 18 +++++------ src/openrct2/world/Footpath.h | 3 +- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 15e0c570a2..d218af336e 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -137,20 +137,19 @@ static int32_t peep_move_one_tile(Direction direction, Peep* peep) */ static int32_t guest_surface_path_finding(Peep* peep) { - int16_t x = peep->next_x; - int16_t y = peep->next_y; - int16_t z = peep->next_z; + auto pathPos = CoordsXYRangedZ{ peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP, + (peep->next_z * COORDS_Z_STEP) + PATH_HEIGHT }; Direction randDirection = scenario_rand() & 3; - if (!fence_in_the_way(x, y, z, z + 4, randDirection)) + if (!fence_in_the_way(pathPos, randDirection)) { - x += CoordsDirectionDelta[randDirection].x; - y += CoordsDirectionDelta[randDirection].y; + pathPos.x += CoordsDirectionDelta[randDirection].x; + pathPos.y += CoordsDirectionDelta[randDirection].y; Direction backwardsDirection = direction_reverse(randDirection); - if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) + if (!fence_in_the_way(pathPos, backwardsDirection)) { - if (!map_surface_is_blocked({ x, y })) + if (!map_surface_is_blocked(pathPos)) { return peep_move_one_tile(randDirection, peep); } @@ -165,17 +164,17 @@ static int32_t guest_surface_path_finding(Peep* peep) } randDirection &= 3; - x = peep->next_x; - y = peep->next_y; - if (!fence_in_the_way(x, y, z, z + 4, randDirection)) + pathPos.x = peep->next_x; + pathPos.y = peep->next_y; + if (!fence_in_the_way(pathPos, randDirection)) { - x += CoordsDirectionDelta[randDirection].x; - y += CoordsDirectionDelta[randDirection].y; + pathPos.x += CoordsDirectionDelta[randDirection].x; + pathPos.y += CoordsDirectionDelta[randDirection].y; Direction backwardsDirection = direction_reverse(randDirection); - if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) + if (!fence_in_the_way(pathPos, backwardsDirection)) { - if (!map_surface_is_blocked({ x, y })) + if (!map_surface_is_blocked(pathPos)) { return peep_move_one_tile(randDirection, peep); } @@ -185,17 +184,17 @@ static int32_t guest_surface_path_finding(Peep* peep) randDirection -= 2; randDirection &= 3; - x = peep->next_x; - y = peep->next_y; - if (!fence_in_the_way(x, y, z, z + 4, randDirection)) + pathPos.x = peep->next_x; + pathPos.y = peep->next_y; + if (!fence_in_the_way(pathPos, randDirection)) { - x += CoordsDirectionDelta[randDirection].x; - y += CoordsDirectionDelta[randDirection].y; + pathPos.x += CoordsDirectionDelta[randDirection].x; + pathPos.y += CoordsDirectionDelta[randDirection].y; Direction backwardsDirection = direction_reverse(randDirection); - if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) + if (!fence_in_the_way(pathPos, backwardsDirection)) { - if (!map_surface_is_blocked({ x, y })) + if (!map_surface_is_blocked(pathPos)) { return peep_move_one_tile(randDirection, peep); } diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 083abac737..4f5c82b665 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -42,6 +42,8 @@ #define PEEP_MAX_NAUSEA 255 #define PEEP_MAX_THIRST 255 +constexpr auto PEEP_CLEARANCE_HEIGHT = 4 * COORDS_Z_STEP; + struct TileElement; struct Ride; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 86bdd06c6c..a4a23c58ff 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -727,10 +727,16 @@ static uint8_t staff_direction_surface(Peep* peep, uint8_t initialDirection) direction &= 3; - if (fence_in_the_way(peep->next_x, peep->next_y, peep->next_z, peep->next_z + 4, direction)) + if (fence_in_the_way( + { peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP, + (peep->next_z * COORDS_Z_STEP) + PEEP_CLEARANCE_HEIGHT }, + direction)) continue; - if (fence_in_the_way(peep->next_x, peep->next_y, peep->next_z, peep->next_z + 4, direction_reverse(direction))) + if (fence_in_the_way( + { peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP, + (peep->next_z * COORDS_Z_STEP) + PEEP_CLEARANCE_HEIGHT }, + direction_reverse(direction))) continue; CoordsXY chosenTile = { peep->next_x + CoordsDirectionDelta[direction].x, diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index dbce4bf6df..f3cda45e7e 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -454,11 +454,11 @@ void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z) * * rct2: 0x006E59DC */ -bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction) +bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction) { TileElement* tileElement; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(fencePos); if (tileElement == nullptr) return false; do @@ -467,9 +467,9 @@ bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t dire continue; if (tileElement->IsGhost()) continue; - if (z0 >= tileElement->clearance_height) + if (fencePos.baseZ >= tileElement->GetClearanceZ()) continue; - if (z1 <= tileElement->base_height) + if (fencePos.clearanceZ <= tileElement->GetBaseZ()) continue; if ((tileElement->GetDirection()) != direction) continue; @@ -710,10 +710,10 @@ static bool footpath_reconnect_queue_to_path(int32_t x, int32_t y, TileElement* if (action < 0) { - if (fence_in_the_way(x, y, tileElement->base_height, tileElement->clearance_height, direction)) + if (fence_in_the_way({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction)) return false; - if (fence_in_the_way(x1, y1, tileElement->base_height, tileElement->clearance_height, direction_reverse(direction))) + if (fence_in_the_way({ x1, y1, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction))) return false; } @@ -876,8 +876,7 @@ static void loc_6A6D7E( if (query) { if (fence_in_the_way( - targetPos.x, targetPos.y, tileElement->base_height, tileElement->clearance_height, - direction_reverse(direction))) + { targetPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction))) { return; } @@ -941,8 +940,7 @@ static void loc_6A6C85( { if (query && fence_in_the_way( - tileElementPos.x, tileElementPos.y, tileElementPos.element->base_height, tileElementPos.element->clearance_height, - direction)) + { tileElementPos, tileElementPos.element->GetBaseZ(), tileElementPos.element->GetClearanceZ() }, direction)) return; if (tileElementPos.element->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 383dd102a9..e4a44f2163 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -24,6 +24,7 @@ enum constexpr auto FootpathMaxHeight = 248; constexpr auto FootpathMinHeight = 2; constexpr auto PATH_HEIGHT_STEP = 2 * COORDS_Z_STEP; +constexpr auto PATH_HEIGHT = 4 * COORDS_Z_STEP; #define FOOTPATH_ELEMENT_INSERT_QUEUE 0x80 @@ -189,7 +190,7 @@ void footpath_bridge_get_info_from_pos( void footpath_remove_litter(int32_t x, int32_t y, int32_t z); void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags); void footpath_update_queue_chains(); -bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction); +bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction); void footpath_chain_ride_queue( ride_id_t rideIndex, int32_t entranceIndex, int32_t x, int32_t y, TileElement* tileElement, int32_t direction); void footpath_update_path_wide_flags(int32_t x, int32_t y);