From b1dc6ed6edad428304996e586c2192cb1f700c66 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 07:31:02 -0300 Subject: [PATCH 01/18] Use CoordsXY on footpath_connect_edges() --- src/openrct2/actions/FootpathPlaceAction.hpp | 2 +- src/openrct2/actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/actions/RideEntranceExitPlaceAction.hpp | 2 +- src/openrct2/actions/TrackPlaceAction.hpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/world/Footpath.cpp | 10 +++++----- src/openrct2/world/Footpath.h | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 67eeb5df84..1777b61f16 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -426,7 +426,7 @@ private: } if (!(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)) - footpath_connect_edges(_loc.x, _loc.y, (TileElement*)pathElement, GetFlags()); + footpath_connect_edges(_loc, reinterpret_cast(pathElement), GetFlags()); footpath_update_queue_chains(); map_invalidate_tile_full(_loc); diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index b903a84327..6699782ff7 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -171,7 +171,7 @@ public: if (!(flags & GAME_COMMAND_FLAG_GHOST)) { - footpath_connect_edges(entranceLoc.x, entranceLoc.y, newElement, 1); + footpath_connect_edges(entranceLoc, newElement, GAME_COMMAND_FLAG_APPLY); } update_park_fences(entranceLoc); diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index 5072bc8eda..6af2a3cd6e 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -224,7 +224,7 @@ public: maze_entrance_hedge_removal(_loc.x, _loc.y, tileElement); } - footpath_connect_edges(_loc.x, _loc.y, tileElement, GetFlags()); + footpath_connect_edges(_loc, tileElement, GetFlags()); footpath_update_queue_chains(); map_invalidate_tile_full(_loc); diff --git a/src/openrct2/actions/TrackPlaceAction.hpp b/src/openrct2/actions/TrackPlaceAction.hpp index 36fa46ddd1..9ed8f1b507 100644 --- a/src/openrct2/actions/TrackPlaceAction.hpp +++ b/src/openrct2/actions/TrackPlaceAction.hpp @@ -676,7 +676,7 @@ public: if (!gCheatsDisableClearanceChecks || !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_connect_edges(mapLoc.x, mapLoc.y, tileElement, GetFlags()); + footpath_connect_edges(mapLoc, tileElement, GetFlags()); } map_invalidate_tile_full(mapLoc); } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 70fdf3d7bc..2764d8260d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -3001,7 +3001,7 @@ private: // Trigger footpath update footpath_queue_chain_reset(); footpath_connect_edges( - entranceCoords.x * 32, (entranceCoords.y) * 32, (TileElement*)entranceElement, + entranceCoords.ToCoordsXY(), reinterpret_cast(entranceElement), GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED); footpath_update_queue_chains(); } diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index eee7fbbba6..a8ed22297c 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1205,7 +1205,7 @@ static bool TrackDesignPlaceSceneryElement( | GAME_COMMAND_FLAG_GHOST; } - footpath_connect_edges(mapCoord.x, mapCoord.y, reinterpret_cast(pathElement), flags); + footpath_connect_edges(mapCoord, reinterpret_cast(pathElement), flags); footpath_update_queue_chains(); return true; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 2d42a5b897..fae2c5e943 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -987,7 +987,7 @@ static void loc_6A6C85( * * rct2: 0x006A6C66 */ -void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int32_t flags) +void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags) { rct_neighbour_list neighbourList; rct_neighbour neighbour; @@ -996,10 +996,10 @@ void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int3 neighbour_list_init(&neighbourList); - footpath_update_queue_entrance_banner(x, y, tileElement); + footpath_update_queue_entrance_banner(footpathPos.x, footpathPos.y, tileElement); for (Direction direction : ALL_DIRECTIONS) { - loc_6A6C85(x, y, direction, tileElement, flags, true, &neighbourList); + loc_6A6C85(footpathPos.x, footpathPos.y, direction, tileElement, flags, true, &neighbourList); } neighbour_list_sort(&neighbourList); @@ -1035,12 +1035,12 @@ void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int3 while (neighbour_list_pop(&neighbourList, &neighbour)) { - loc_6A6C85(x, y, neighbour.direction, tileElement, flags, false, nullptr); + loc_6A6C85(footpathPos.x, footpathPos.y, neighbour.direction, tileElement, flags, false, nullptr); } if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - footpath_connect_corners(x, y, tileElement); + footpath_connect_corners(footpathPos.x, footpathPos.y, tileElement); } } diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 8d4eabc7cd..383dd102a9 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -187,7 +187,7 @@ void footpath_get_coordinates_from_pos( void footpath_bridge_get_info_from_pos( ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); void footpath_remove_litter(int32_t x, int32_t y, int32_t z); -void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int32_t flags); +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); void footpath_chain_ride_queue( From 482ca8765c7862b6bd811816bbb32a34df1b5b92 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 07:44:36 -0300 Subject: [PATCH 02/18] Use CoordsXY on Footpath's loc_6A6D7E() and loc_6A6C85() --- src/openrct2/world/Footpath.cpp | 75 ++++++++++++++++++--------------- src/openrct2/world/Map.h | 15 ++++++- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index fae2c5e943..68948aec64 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -772,12 +772,11 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElemen * rct2: 0x006A6D7E */ static void loc_6A6D7E( - int32_t initialX, int32_t initialY, int32_t z, int32_t direction, TileElement* initialTileElement, int32_t flags, - bool query, rct_neighbour_list* neighbourList) + const CoordsXYZ& initialTileElementPos, int32_t direction, TileElement* initialTileElement, int32_t flags, bool query, + rct_neighbour_list* neighbourList) { - int32_t x = initialX + CoordsDirectionDelta[direction].x; - int32_t y = initialY + CoordsDirectionDelta[direction].y; - if (((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && map_is_edge({ x, y })) + auto targetPos = CoordsXY{ initialTileElementPos } + CoordsDirectionDelta[direction]; + if (((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && map_is_edge(targetPos)) { if (query) { @@ -786,7 +785,7 @@ static void loc_6A6D7E( } else { - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(targetPos); if (tileElement == nullptr) return; do @@ -794,7 +793,7 @@ static void loc_6A6D7E( switch (tileElement->GetType()) { case TILE_ELEMENT_TYPE_PATH: - if (z == tileElement->base_height) + if (initialTileElementPos.z == tileElement->GetBaseZ()) { if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() != direction) { @@ -805,7 +804,7 @@ static void loc_6A6D7E( goto loc_6A6F1F; } } - if (z - 2 == tileElement->base_height) + if (initialTileElementPos.z - LAND_HEIGHT_STEP == tileElement->GetBaseZ()) { if (!tileElement->AsPath()->IsSloped() || tileElement->AsPath()->GetSlopeDirection() != direction_reverse(direction)) @@ -816,7 +815,7 @@ static void loc_6A6D7E( } break; case TILE_ELEMENT_TYPE_TRACK: - if (z == tileElement->base_height) + if (initialTileElementPos.z == tileElement->GetBaseZ()) { auto ride = get_ride(tileElement->AsTrack()->GetRideIndex()); if (ride == nullptr || !ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_FLAT_RIDE)) @@ -844,7 +843,7 @@ static void loc_6A6D7E( } break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (z == tileElement->base_height) + if (initialTileElementPos.z == tileElement->GetBaseZ()) { if (entrance_has_direction(tileElement, direction_reverse(direction - tileElement->GetDirection()))) { @@ -872,7 +871,9 @@ static void loc_6A6D7E( loc_6A6F1F: if (query) { - if (fence_in_the_way(x, y, tileElement->base_height, tileElement->clearance_height, direction_reverse(direction))) + if (fence_in_the_way( + targetPos.x, targetPos.y, tileElement->base_height, tileElement->clearance_height, + direction_reverse(direction))) { return; } @@ -888,7 +889,7 @@ static void loc_6A6D7E( { if ((initialTileElement)->GetType() == TILE_ELEMENT_TYPE_PATH && initialTileElement->AsPath()->IsQueue()) { - if (footpath_disconnect_queue_from_path(x, y, tileElement, 0)) + if (footpath_disconnect_queue_from_path(targetPos.x, targetPos.y, tileElement, 0)) { neighbour_list_push( neighbourList, 3, direction, tileElement->AsPath()->GetRideIndex(), @@ -904,7 +905,7 @@ static void loc_6A6D7E( } else { - footpath_disconnect_queue_from_path(x, y, tileElement, 1 + ((flags >> 6) & 1)); + footpath_disconnect_queue_from_path(targetPos.x, targetPos.y, tileElement, 1 + ((flags >> 6) & 1)); tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() | (1 << direction_reverse(direction))); if (tileElement->AsPath()->IsQueue()) { @@ -913,9 +914,9 @@ static void loc_6A6D7E( } if (!(flags & (GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED))) { - footpath_interrupt_peeps(x, y, tileElement->GetBaseZ()); + footpath_interrupt_peeps(targetPos.x, targetPos.y, tileElement->GetBaseZ()); } - map_invalidate_element({ x, y }, tileElement); + map_invalidate_element(targetPos, tileElement); } loc_6A6FD2: @@ -924,63 +925,67 @@ loc_6A6FD2: if (!query) { initialTileElement->AsPath()->SetEdges(initialTileElement->AsPath()->GetEdges() | (1 << direction)); - map_invalidate_element({ initialX, initialY }, initialTileElement); + map_invalidate_element(initialTileElementPos, initialTileElement); } } } +// TODO: Change this into a simple check that validates if the direction should be fully checked with loc_6A6D7E and move the +// calling of loc_6A6D7E into the parent function. static void loc_6A6C85( - int32_t x, int32_t y, int32_t direction, TileElement* tileElement, int32_t flags, bool query, - rct_neighbour_list* neighbourList) + const CoordsXYE& tileElementPos, int32_t direction, int32_t flags, bool query, rct_neighbour_list* neighbourList) { - if (query && fence_in_the_way(x, y, tileElement->base_height, tileElement->clearance_height, direction)) + if (query + && fence_in_the_way( + tileElementPos.x, tileElementPos.y, tileElementPos.element->base_height, tileElementPos.element->clearance_height, + direction)) return; - if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) + if (tileElementPos.element->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { - if (!entrance_has_direction(tileElement, direction - tileElement->GetDirection())) + if (!entrance_has_direction(tileElementPos.element, direction - tileElementPos.element->GetDirection())) { return; } } - if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) + if (tileElementPos.element->GetType() == TILE_ELEMENT_TYPE_TRACK) { - auto ride = get_ride(tileElement->AsTrack()->GetRideIndex()); + auto ride = get_ride(tileElementPos.element->AsTrack()->GetRideIndex()); if (ride == nullptr || !ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_FLAT_RIDE)) { return; } - const uint8_t trackType = tileElement->AsTrack()->GetTrackType(); - const uint8_t trackSequence = tileElement->AsTrack()->GetSequenceIndex(); + const uint8_t trackType = tileElementPos.element->AsTrack()->GetTrackType(); + const uint8_t trackSequence = tileElementPos.element->AsTrack()->GetSequenceIndex(); if (!(FlatRideTrackSequenceProperties[trackType][trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH)) { return; } - uint16_t dx = (direction - tileElement->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK; + uint16_t dx = (direction - tileElementPos.element->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK; if (!(FlatRideTrackSequenceProperties[trackType][trackSequence] & (1 << dx))) { return; } } - int32_t z = tileElement->base_height; - if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) + auto pos = CoordsXYZ{ tileElementPos, tileElementPos.element->GetBaseZ() }; + if (tileElementPos.element->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (tileElement->AsPath()->IsSloped()) + if (tileElementPos.element->AsPath()->IsSloped()) { - if ((tileElement->AsPath()->GetSlopeDirection() - direction) & 1) + if ((tileElementPos.element->AsPath()->GetSlopeDirection() - direction) & 1) { return; } - if (tileElement->AsPath()->GetSlopeDirection() == direction) + if (tileElementPos.element->AsPath()->GetSlopeDirection() == direction) { - z += 2; + pos.z += LAND_HEIGHT_STEP; } } } - loc_6A6D7E(x, y, z, direction, tileElement, flags, query, neighbourList); + loc_6A6D7E(pos, direction, tileElementPos.element, flags, query, neighbourList); } /** @@ -999,7 +1004,7 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen footpath_update_queue_entrance_banner(footpathPos.x, footpathPos.y, tileElement); for (Direction direction : ALL_DIRECTIONS) { - loc_6A6C85(footpathPos.x, footpathPos.y, direction, tileElement, flags, true, &neighbourList); + loc_6A6C85({ footpathPos, tileElement }, direction, flags, true, &neighbourList); } neighbour_list_sort(&neighbourList); @@ -1035,7 +1040,7 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen while (neighbour_list_pop(&neighbourList, &neighbour)) { - loc_6A6C85(footpathPos.x, footpathPos.y, neighbour.direction, tileElement, flags, false, nullptr); + loc_6A6C85({ footpathPos, tileElement }, neighbour.direction, flags, false, nullptr); } if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 8574f66ab4..1d03f321db 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -43,9 +43,20 @@ constexpr const int32_t LAND_HEIGHT_STEP = 2 * COORDS_Z_STEP; typedef CoordsXYZD PeepSpawn; -struct CoordsXYE +struct CoordsXYE : public CoordsXY { - int32_t x, y; + CoordsXYE() = default; + constexpr CoordsXYE(int32_t _x, int32_t _y, TileElement* _e) + : CoordsXY(_x, _y) + , element(_e) + { + } + + constexpr CoordsXYE(CoordsXY c, TileElement* _e) + : CoordsXY(c) + , element(_e) + { + } TileElement* element; }; From e7ee8ebc0392c4ad9ef1f82740cd9afc872fffc5 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 07:46:46 -0300 Subject: [PATCH 03/18] Use CoordsXY on footpath_update_queue_entrance_banner() --- src/openrct2/world/Footpath.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 68948aec64..dc4887e107 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -35,7 +35,7 @@ #include #include -void footpath_update_queue_entrance_banner(int32_t x, int32_t y, TileElement* tileElement); +void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElement* tileElement); uint8_t gFootpathProvisionalFlags; CoordsXYZ gFootpathProvisionalPosition; @@ -1001,7 +1001,7 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen neighbour_list_init(&neighbourList); - footpath_update_queue_entrance_banner(footpathPos.x, footpathPos.y, tileElement); + footpath_update_queue_entrance_banner(footpathPos, tileElement); for (Direction direction : ALL_DIRECTIONS) { loc_6A6C85({ footpathPos, tileElement }, direction, flags, true, &neighbourList); @@ -1884,7 +1884,7 @@ bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position) * * rct2: 0x006A7642 */ -void footpath_update_queue_entrance_banner(int32_t x, int32_t y, TileElement* tileElement) +void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElement* tileElement) { int32_t elementType = tileElement->GetType(); switch (elementType) @@ -1897,7 +1897,7 @@ void footpath_update_queue_entrance_banner(int32_t x, int32_t y, TileElement* ti { if (tileElement->AsPath()->GetEdges() & (1 << direction)) { - footpath_chain_ride_queue(255, 0, x, y, tileElement, direction); + footpath_chain_ride_queue(255, 0, footpathPos.x, footpathPos.y, tileElement, direction); } } tileElement->AsPath()->SetRideIndex(RIDE_ID_NULL); @@ -1907,7 +1907,8 @@ void footpath_update_queue_entrance_banner(int32_t x, int32_t y, TileElement* ti if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { footpath_queue_chain_push(tileElement->AsEntrance()->GetRideIndex()); - footpath_chain_ride_queue(255, 0, x, y, tileElement, direction_reverse(tileElement->GetDirection())); + footpath_chain_ride_queue( + 255, 0, footpathPos.x, footpathPos.y, tileElement, direction_reverse(tileElement->GetDirection())); } break; } @@ -2137,7 +2138,7 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) return; } - footpath_update_queue_entrance_banner(x, y, tileElement); + footpath_update_queue_entrance_banner({ x, y }, tileElement); bool fixCorners = false; for (uint8_t direction = 0; direction < 4; direction++) From 78611b664f2b5caacf5394e637a42229ff5c248d Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 07:51:20 -0300 Subject: [PATCH 04/18] Use CoordsXY on footpath_connect_corners() --- src/openrct2/world/Footpath.cpp | 84 +++++++++++++++++---------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index dc4887e107..dbce4bf6df 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -479,7 +479,7 @@ bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t dire return false; } -static TileElement* footpath_connect_corners_get_neighbour(int32_t x, int32_t y, int32_t z, int32_t requireEdges) +static PathElement * footpath_connect_corners_get_neighbour(int32_t x, int32_t y, int32_t z, int32_t requireEdges) { if (!map_is_location_valid({ x, y })) { @@ -493,14 +493,15 @@ static TileElement* footpath_connect_corners_get_neighbour(int32_t x, int32_t y, { if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (tileElement->AsPath()->IsQueue()) + auto pathElement = tileElement->AsPath(); + if (pathElement->IsQueue()) continue; if (tileElement->base_height != z) continue; - if (!(tileElement->AsPath()->GetEdgesAndCorners() & requireEdges)) + if (!(pathElement->GetEdgesAndCorners() & requireEdges)) continue; - return tileElement; + return pathElement; } while (!(tileElement++)->IsLastForTile()); return nullptr; @@ -514,65 +515,68 @@ static TileElement* footpath_connect_corners_get_neighbour(int32_t x, int32_t y, * * rct2: 0x006A70EB */ -static void footpath_connect_corners(int32_t initialX, int32_t initialY, TileElement* initialTileElement) +static void footpath_connect_corners(const CoordsXY& footpathPos, PathElement* initialTileElement) { - TileElement* tileElement[4]; + using PathElementCoordsPair = std::pair; + std::array tileElements; - if (initialTileElement->AsPath()->IsQueue()) + if (initialTileElement->IsQueue()) return; - if (initialTileElement->AsPath()->IsSloped()) + if (initialTileElement->IsSloped()) return; - tileElement[0] = initialTileElement; - int32_t z = initialTileElement->base_height; + tileElements[0] = { initialTileElement, footpathPos }; + int32_t z = initialTileElement->GetBaseZ(); for (int32_t initialDirection = 0; initialDirection < 4; initialDirection++) { - int32_t x = initialX; - int32_t y = initialY; int32_t direction = initialDirection; + auto currentPos = footpathPos + CoordsDirectionDelta[direction]; - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; - tileElement[1] = footpath_connect_corners_get_neighbour(x, y, z, (1 << direction_reverse(direction))); - if (tileElement[1] == nullptr) + tileElements[1] = { footpath_connect_corners_get_neighbour( + currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + currentPos }; + if (tileElements[1].first == nullptr) continue; - direction = (direction + 1) & 3; - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; - tileElement[2] = footpath_connect_corners_get_neighbour(x, y, z, (1 << direction_reverse(direction))); - if (tileElement[2] == nullptr) + direction = direction_next(direction); + currentPos += CoordsDirectionDelta[direction]; + tileElements[2] = { footpath_connect_corners_get_neighbour( + currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + currentPos }; + if (tileElements[2].first == nullptr) continue; - direction = (direction + 1) & 3; - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; + direction = direction_next(direction); + currentPos += CoordsDirectionDelta[direction]; // First check link to previous tile - tileElement[3] = footpath_connect_corners_get_neighbour(x, y, z, (1 << direction_reverse(direction))); - if (tileElement[3] == nullptr) + tileElements[3] = { footpath_connect_corners_get_neighbour( + currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + currentPos }; + if (tileElements[3].first == nullptr) continue; // Second check link to initial tile - tileElement[3] = footpath_connect_corners_get_neighbour(x, y, z, (1 << ((direction + 1) & 3))); - if (tileElement[3] == nullptr) + tileElements[3] = { footpath_connect_corners_get_neighbour(currentPos.x, currentPos.y, z, (1 << ((direction + 1) & 3))), + currentPos }; + if (tileElements[3].first == nullptr) continue; - direction = (direction + 1) & 3; - tileElement[3]->AsPath()->SetCorners(tileElement[3]->AsPath()->GetCorners() | (1 << (direction))); - map_invalidate_element({ x, y }, tileElement[3]); + direction = direction_next(direction); + tileElements[3].first->SetCorners(tileElements[3].first->GetCorners() | (1 << (direction))); + map_invalidate_element(tileElements[3].second, reinterpret_cast(tileElements[3].first)); - direction = (direction - 1) & 3; - tileElement[2]->AsPath()->SetCorners(tileElement[2]->AsPath()->GetCorners() | (1 << (direction))); + direction = direction_prev(direction); + tileElements[2].first->SetCorners(tileElements[2].first->GetCorners() | (1 << (direction))); - map_invalidate_element({ x, y }, tileElement[2]); + map_invalidate_element(tileElements[2].second, reinterpret_cast(tileElements[2].first)); - direction = (direction - 1) & 3; - tileElement[1]->AsPath()->SetCorners(tileElement[1]->AsPath()->GetCorners() | (1 << (direction))); + direction = direction_prev(direction); + tileElements[1].first->SetCorners(tileElements[1].first->GetCorners() | (1 << (direction))); - map_invalidate_element({ x, y }, tileElement[1]); + map_invalidate_element(tileElements[1].second, reinterpret_cast(tileElements[1].first)); direction = initialDirection; - tileElement[0]->AsPath()->SetCorners(tileElement[0]->AsPath()->GetCorners() | (1 << (direction))); - map_invalidate_element({ x, y }, tileElement[0]); + tileElements[0].first->SetCorners(tileElements[0].first->GetCorners() | (1 << (direction))); + map_invalidate_element(tileElements[0].second, reinterpret_cast(tileElements[0].first)); } } @@ -1045,7 +1049,7 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - footpath_connect_corners(footpathPos.x, footpathPos.y, tileElement); + footpath_connect_corners(footpathPos, tileElement->AsPath()); } } From b829b224157872e0547135dbfca07a1995d55194 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:01:35 -0300 Subject: [PATCH 05/18] 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); From 9aad709d5c35ea093b2da3f82f6d2a72f4a1a35e Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:03:39 -0300 Subject: [PATCH 06/18] Use CoordsXY on footpath_disconnect_queue_from_path() --- src/openrct2/world/Footpath.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index f3cda45e7e..282dcf026b 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -741,7 +741,7 @@ static bool footpath_reconnect_queue_to_path(int32_t x, int32_t y, TileElement* return false; } -static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElement* tileElement, int32_t action) +static bool footpath_disconnect_queue_from_path(const CoordsXY& footpathPos, TileElement* tileElement, int32_t action) { if (!tileElement->AsPath()->IsQueue()) return false; @@ -756,7 +756,7 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElemen if (action < 0) { uint8_t direction = tileElement->AsPath()->GetSlopeDirection(); - if (footpath_reconnect_queue_to_path(x, y, tileElement, action, direction)) + if (footpath_reconnect_queue_to_path(footpathPos.x, footpathPos.y, tileElement, action, direction)) return true; } @@ -764,7 +764,7 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElemen { if ((action < 0) && (direction == tileElement->AsPath()->GetSlopeDirection())) continue; - if (footpath_reconnect_queue_to_path(x, y, tileElement, action, direction)) + if (footpath_reconnect_queue_to_path(footpathPos.x, footpathPos.y, tileElement, action, direction)) return true; } @@ -892,7 +892,7 @@ static void loc_6A6D7E( { if ((initialTileElement)->GetType() == TILE_ELEMENT_TYPE_PATH && initialTileElement->AsPath()->IsQueue()) { - if (footpath_disconnect_queue_from_path(targetPos.x, targetPos.y, tileElement, 0)) + if (footpath_disconnect_queue_from_path(targetPos, tileElement, 0)) { neighbour_list_push( neighbourList, 3, direction, tileElement->AsPath()->GetRideIndex(), @@ -908,7 +908,7 @@ static void loc_6A6D7E( } else { - footpath_disconnect_queue_from_path(targetPos.x, targetPos.y, tileElement, 1 + ((flags >> 6) & 1)); + footpath_disconnect_queue_from_path(targetPos, tileElement, 1 + ((flags >> 6) & 1)); tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() | (1 << direction_reverse(direction))); if (tileElement->AsPath()->IsQueue()) { @@ -1937,7 +1937,7 @@ static void footpath_remove_edges_towards_here( map_invalidate_tile({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); if (isQueue) - footpath_disconnect_queue_from_path(x, y, tileElement, -1); + footpath_disconnect_queue_from_path({ x, y }, tileElement, -1); direction = (direction + 1) & 3; x += CoordsDirectionDelta[direction].x; From 2b1101d3201211c4b2c1b6fdc4f7da98fc04cf5f Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:10:10 -0300 Subject: [PATCH 07/18] Use CoordsXYZ on footpath_interrupt_peeps() --- src/openrct2/actions/FootpathPlaceAction.hpp | 2 +- src/openrct2/actions/FootpathPlaceFromTrackAction.hpp | 2 +- src/openrct2/actions/FootpathRemoveAction.hpp | 2 +- src/openrct2/actions/FootpathSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/FootpathSceneryRemoveAction.hpp | 2 +- src/openrct2/world/Footpath.cpp | 8 ++++---- src/openrct2/world/Footpath.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 1777b61f16..f72a0f2b67 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -117,7 +117,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_interrupt_peeps(_loc.x, _loc.y, _loc.z); + footpath_interrupt_peeps(_loc); } gFootpathGroundFlags = 0; diff --git a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp index 397374909f..e0d8b1cbb9 100644 --- a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp +++ b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp @@ -98,7 +98,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_interrupt_peeps(_loc.x, _loc.y, _loc.z); + footpath_interrupt_peeps(_loc); } gFootpathGroundFlags = 0; diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index 89d296bb22..5ad5749bbb 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -78,7 +78,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_interrupt_peeps(_loc.x, _loc.y, _loc.z); + footpath_interrupt_peeps(_loc); footpath_remove_litter(_loc.x, _loc.y, _loc.z); } diff --git a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp index b5580b8f2e..bdf4feeb73 100644 --- a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp +++ b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp @@ -176,7 +176,7 @@ public: } else { - footpath_interrupt_peeps(_loc.x, _loc.y, _loc.z); + footpath_interrupt_peeps(_loc); } if ((_pathItemType != 0 && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) diff --git a/src/openrct2/actions/FootpathSceneryRemoveAction.hpp b/src/openrct2/actions/FootpathSceneryRemoveAction.hpp index 1c4ceb225f..92190a1aaa 100644 --- a/src/openrct2/actions/FootpathSceneryRemoveAction.hpp +++ b/src/openrct2/actions/FootpathSceneryRemoveAction.hpp @@ -99,7 +99,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_interrupt_peeps(_loc.x, _loc.y, _loc.z); + footpath_interrupt_peeps(_loc); } if (pathElement == nullptr) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 282dcf026b..44e3d907d9 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -421,9 +421,9 @@ void footpath_remove_litter(int32_t x, int32_t y, int32_t z) * * rct2: 0x0069A48B */ -void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z) +void footpath_interrupt_peeps(const CoordsXYZ& footpathPos) { - uint16_t spriteIndex = sprite_get_first_in_quadrant(x, y); + uint16_t spriteIndex = sprite_get_first_in_quadrant(footpathPos.x, footpathPos.y); while (spriteIndex != SPRITE_INDEX_NULL) { Peep* peep = &get_sprite(spriteIndex)->peep; @@ -432,7 +432,7 @@ void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z) { if (peep->state == PEEP_STATE_SITTING || peep->state == PEEP_STATE_WATCHING) { - if (peep->z == z) + if (peep->z == footpathPos.z) { peep->SetState(PEEP_STATE_WALKING); peep->destination_x = (peep->x & 0xFFE0) + 16; @@ -917,7 +917,7 @@ static void loc_6A6D7E( } if (!(flags & (GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED))) { - footpath_interrupt_peeps(targetPos.x, targetPos.y, tileElement->GetBaseZ()); + footpath_interrupt_peeps({ targetPos, tileElement->GetBaseZ() }); } map_invalidate_element(targetPos, tileElement); } diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index e4a44f2163..00897b36aa 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -178,7 +178,7 @@ extern const LocationXY16 BenchUseOffsets[NumOrthogonalDirections * 2]; TileElement* map_get_footpath_element(CoordsXYZ coords); struct PathElement; PathElement* map_get_footpath_element_slope(int32_t x, int32_t y, int32_t z, int32_t slope); -void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z); +void footpath_interrupt_peeps(const CoordsXYZ& footpathPos); money32 footpath_remove(CoordsXYZ footpathLoc, int32_t flags); money32 footpath_provisional_set(int32_t type, CoordsXYZ footpathLoc, int32_t slope); void footpath_provisional_remove(); From 7cf03d3e412397d09e0f0c09ad4eaa35fa59d2bf Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:33:19 -0300 Subject: [PATCH 08/18] Use CoordsXY on footpath_remove_edges_at() --- src/openrct2/actions/FootpathPlaceAction.hpp | 4 ++-- src/openrct2/actions/FootpathRemoveAction.hpp | 2 +- .../actions/RideEntranceExitRemoveAction.hpp | 2 +- src/openrct2/actions/TrackRemoveAction.hpp | 2 +- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/world/Footpath.cpp | 12 +++++++----- src/openrct2/world/Footpath.h | 2 +- src/openrct2/world/Location.hpp | 6 ++++++ src/openrct2/world/Map.cpp | 2 +- 10 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index f72a0f2b67..6d37b04859 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -182,7 +182,7 @@ private: if (!(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)) { - footpath_remove_edges_at(_loc.x, _loc.y, (TileElement*)pathElement); + footpath_remove_edges_at(_loc, reinterpret_cast(pathElement)); } pathElement->SetPathEntryIndex(_type); @@ -358,7 +358,7 @@ private: if (!(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)) { - footpath_remove_edges_at(_loc.x, _loc.y, tileElement); + footpath_remove_edges_at(_loc, tileElement); } if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index 5ad5749bbb..f3b3df8898 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -91,7 +91,7 @@ public: { res->Cost += bannerRes->Cost; } - footpath_remove_edges_at(_loc.x, _loc.y, footpathElement); + footpath_remove_edges_at(_loc, footpathElement); map_invalidate_tile_full(_loc); tile_element_remove(footpathElement); footpath_update_queue_chains(); diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp index 9298c7f1f6..a1b2d86d79 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp @@ -172,7 +172,7 @@ public: footpath_queue_chain_reset(); maze_entrance_hedge_replacement(_loc.x, _loc.y, tileElement); - footpath_remove_edges_at(_loc.x, _loc.y, tileElement); + footpath_remove_edges_at(_loc, tileElement); tile_element_remove(tileElement); diff --git a/src/openrct2/actions/TrackRemoveAction.hpp b/src/openrct2/actions/TrackRemoveAction.hpp index ea757e56b4..6517abd375 100644 --- a/src/openrct2/actions/TrackRemoveAction.hpp +++ b/src/openrct2/actions/TrackRemoveAction.hpp @@ -434,7 +434,7 @@ public: footpath_queue_chain_reset(); if (!gCheatsDisableClearanceChecks || !(tileElement->IsGhost())) { - footpath_remove_edges_at(mapLoc.x, mapLoc.y, tileElement); + footpath_remove_edges_at(mapLoc, tileElement); } tile_element_remove(tileElement); sub_6CB945(ride); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c8bc435f6e..09bd2c100f 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7089,7 +7089,7 @@ void sub_6CB945(Ride* ride) { footpath_queue_chain_reset(); maze_entrance_hedge_replacement(location.x, location.y, tileElement); - footpath_remove_edges_at(location.x, location.y, tileElement); + footpath_remove_edges_at(location, tileElement); footpath_update_queue_chains(); map_invalidate_tile_full(location); tile_element_remove(tileElement); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index a8ed22297c..797d7c265b 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1192,7 +1192,7 @@ static bool TrackDesignPlaceSceneryElement( } footpath_queue_chain_reset(); - footpath_remove_edges_at(mapCoord.x, mapCoord.y, reinterpret_cast(pathElement)); + footpath_remove_edges_at(mapCoord, reinterpret_cast(pathElement)); flags = GAME_COMMAND_FLAG_APPLY; if (_trackDesignPlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 44e3d907d9..c787f0d683 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -2130,7 +2130,7 @@ static void footpath_fix_corners_around(int32_t x, int32_t y, TileElement* pathE * @param x x-coordinate in units (not tiles) * @param y y-coordinate in units (not tiles) */ -void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) +void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement) { if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) { @@ -2140,7 +2140,7 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) return; } - footpath_update_queue_entrance_banner({ x, y }, tileElement); + footpath_update_queue_entrance_banner(footpathPos, tileElement); bool fixCorners = false; for (uint8_t direction = 0; direction < 4; direction++) @@ -2163,12 +2163,13 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) // When clearance checks were disabled a neighbouring path can be connected to both the path-ghost and to something // else, so before removing edges from neighbouring paths we have to make sure there is nothing else they are connected // to. - if (!tile_element_wants_path_connection_towards({ x / 32, y / 32, z1, direction }, tileElement)) + if (!tile_element_wants_path_connection_towards({ TileCoordsXY{ footpathPos }, z1, direction }, tileElement)) { bool isQueue = tileElement->GetType() == TILE_ELEMENT_TYPE_PATH ? tileElement->AsPath()->IsQueue() : false; int32_t z0 = z1 - 2; footpath_remove_edges_towards( - x + CoordsDirectionDelta[direction].x, y + CoordsDirectionDelta[direction].y, z0, z1, direction, isQueue); + footpathPos.x + CoordsDirectionDelta[direction].x, footpathPos.y + CoordsDirectionDelta[direction].y, z0, z1, + direction, isQueue); } else { @@ -2180,7 +2181,8 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) // Only fix corners when needed, to avoid changing corners that have been set for its looks. if (fixCorners && tileElement->IsGhost()) { - footpath_fix_corners_around(x / 32, y / 32, tileElement); + auto tileFootpathPos = TileCoordsXY{ footpathPos }; + footpath_fix_corners_around(tileFootpathPos.x, tileFootpathPos.y, tileElement); } if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 00897b36aa..107ededa12 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -197,7 +197,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y); bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position); int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags); -void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement); +void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement); int32_t entrance_get_directions(const TileElement* tileElement); PathSurfaceEntry* get_path_surface_entry(int32_t entryIndex); diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 50ac431104..ee95940285 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -475,6 +475,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ { } + TileCoordsXYZD(TileCoordsXY t_, int32_t z_, Direction d_) + : TileCoordsXYZ(t_, z_) + , direction(d_) + { + } + TileCoordsXYZD(CoordsXY c_, int32_t z_, Direction d_) : TileCoordsXYZ(c_, z_) , direction(d_) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 1eb5fccbce..e17b1660b8 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -964,7 +964,7 @@ void map_remove_all_rides() [[fallthrough]]; case TILE_ELEMENT_TYPE_TRACK: footpath_queue_chain_reset(); - footpath_remove_edges_at(it.x * 32, it.y * 32, it.element); + footpath_remove_edges_at(TileCoordsXY{ it.x, it.y }.ToCoordsXY(), it.element); tile_element_remove(it.element); tile_element_iterator_restart_for_tile(&it); break; From d8c8f2d8049b7894ee24ce0dbb4e224ca8cb5d40 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:36:16 -0300 Subject: [PATCH 09/18] Use CoordsXYZ on footpath_connect_corners_get_neighbour() --- src/openrct2/world/Footpath.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index c787f0d683..19e1fae799 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -479,14 +479,14 @@ bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction) return false; } -static PathElement * footpath_connect_corners_get_neighbour(int32_t x, int32_t y, int32_t z, int32_t requireEdges) +static PathElement* footpath_connect_corners_get_neighbour(const CoordsXYZ& footpathPos, int32_t requireEdges) { - if (!map_is_location_valid({ x, y })) + if (!map_is_location_valid(footpathPos)) { return nullptr; } - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(footpathPos); if (tileElement == nullptr) return nullptr; do @@ -496,7 +496,7 @@ static PathElement * footpath_connect_corners_get_neighbour(int32_t x, int32_t y auto pathElement = tileElement->AsPath(); if (pathElement->IsQueue()) continue; - if (tileElement->base_height != z) + if (tileElement->GetBaseZ() != footpathPos.z) continue; if (!(pathElement->GetEdgesAndCorners() & requireEdges)) continue; @@ -532,16 +532,14 @@ static void footpath_connect_corners(const CoordsXY& footpathPos, PathElement* i int32_t direction = initialDirection; auto currentPos = footpathPos + CoordsDirectionDelta[direction]; - tileElements[1] = { footpath_connect_corners_get_neighbour( - currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + tileElements[1] = { footpath_connect_corners_get_neighbour({ currentPos, z }, (1 << direction_reverse(direction))), currentPos }; if (tileElements[1].first == nullptr) continue; direction = direction_next(direction); currentPos += CoordsDirectionDelta[direction]; - tileElements[2] = { footpath_connect_corners_get_neighbour( - currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + tileElements[2] = { footpath_connect_corners_get_neighbour({ currentPos, z }, (1 << direction_reverse(direction))), currentPos }; if (tileElements[2].first == nullptr) continue; @@ -549,13 +547,12 @@ static void footpath_connect_corners(const CoordsXY& footpathPos, PathElement* i direction = direction_next(direction); currentPos += CoordsDirectionDelta[direction]; // First check link to previous tile - tileElements[3] = { footpath_connect_corners_get_neighbour( - currentPos.x, currentPos.y, z, (1 << direction_reverse(direction))), + tileElements[3] = { footpath_connect_corners_get_neighbour({ currentPos, z }, (1 << direction_reverse(direction))), currentPos }; if (tileElements[3].first == nullptr) continue; // Second check link to initial tile - tileElements[3] = { footpath_connect_corners_get_neighbour(currentPos.x, currentPos.y, z, (1 << ((direction + 1) & 3))), + tileElements[3] = { footpath_connect_corners_get_neighbour({ currentPos, z }, (1 << ((direction + 1) & 3))), currentPos }; if (tileElements[3].first == nullptr) continue; From 777898fd6c03879800fb1138025b4282805ab2c1 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:39:19 -0300 Subject: [PATCH 10/18] Use CoordsXY on footpath_reconnect_queue_to_path() --- src/openrct2/world/Footpath.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 19e1fae799..7e15cc35c8 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -697,42 +697,45 @@ static TileElement* footpath_get_element(int32_t x, int32_t y, int32_t z0, int32 /** * Attempt to connect a newly disconnected queue tile to the specified path tile */ -static bool footpath_reconnect_queue_to_path(int32_t x, int32_t y, TileElement* tileElement, int32_t action, int32_t direction) +static bool footpath_reconnect_queue_to_path( + const CoordsXY& footpathPos, TileElement* tileElement, int32_t action, int32_t direction) { if (((tileElement->AsPath()->GetEdges() & (1 << direction)) == 0) ^ (action < 0)) return false; - int32_t x1 = x + CoordsDirectionDelta[direction].x; - int32_t y1 = y + CoordsDirectionDelta[direction].y; + auto targetQueuePos = footpathPos + CoordsDirectionDelta[direction]; if (action < 0) { - if (fence_in_the_way({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction)) + if (fence_in_the_way({ footpathPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction)) return false; - if (fence_in_the_way({ x1, y1, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction))) + if (fence_in_the_way( + { targetQueuePos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction))) return false; } int32_t z = tileElement->base_height; - TileElement* otherTileElement = footpath_get_element(x1, y1, z - 2, z, direction); + TileElement* otherTileElement = footpath_get_element(targetQueuePos.x, targetQueuePos.y, z - 2, z, direction); if (otherTileElement != nullptr && !otherTileElement->AsPath()->IsQueue()) { tileElement->AsPath()->SetSlopeDirection(0); if (action > 0) { tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() & ~(1 << direction)); - otherTileElement->AsPath()->SetEdges(otherTileElement->AsPath()->GetEdges() & ~(1 << ((direction + 2) & 3))); + otherTileElement->AsPath()->SetEdges( + otherTileElement->AsPath()->GetEdges() & ~(1 << (direction_reverse(direction) & 3))); if (action >= 2) tileElement->AsPath()->SetSlopeDirection(direction); } else if (action < 0) { tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() | (1 << direction)); - otherTileElement->AsPath()->SetEdges(otherTileElement->AsPath()->GetEdges() | (1 << ((direction + 2) & 3))); + otherTileElement->AsPath()->SetEdges( + otherTileElement->AsPath()->GetEdges() | (1 << (direction_reverse(direction) & 3))); } if (action != 0) - map_invalidate_tile_full({ x1, y1 }); + map_invalidate_tile_full(targetQueuePos); return true; } return false; @@ -753,7 +756,7 @@ static bool footpath_disconnect_queue_from_path(const CoordsXY& footpathPos, Til if (action < 0) { uint8_t direction = tileElement->AsPath()->GetSlopeDirection(); - if (footpath_reconnect_queue_to_path(footpathPos.x, footpathPos.y, tileElement, action, direction)) + if (footpath_reconnect_queue_to_path(footpathPos, tileElement, action, direction)) return true; } @@ -761,7 +764,7 @@ static bool footpath_disconnect_queue_from_path(const CoordsXY& footpathPos, Til { if ((action < 0) && (direction == tileElement->AsPath()->GetSlopeDirection())) continue; - if (footpath_reconnect_queue_to_path(footpathPos.x, footpathPos.y, tileElement, action, direction)) + if (footpath_reconnect_queue_to_path(footpathPos, tileElement, action, direction)) return true; } From 09e434bc193f27d824b699628be18bcc05bc3fa8 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:47:01 -0300 Subject: [PATCH 11/18] Use CoordsXYZD on footpath_remove_edges_towards_here() --- src/openrct2/world/Footpath.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 7e15cc35c8..2074d4e0a5 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1921,44 +1921,43 @@ void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElem * rct2: 0x006A6B7F */ static void footpath_remove_edges_towards_here( - int32_t x, int32_t y, int32_t z, int32_t direction, TileElement* tileElement, bool isQueue) + const CoordsXYZ& footpathPos, int32_t direction, TileElement* tileElement, bool isQueue) { if (tileElement->AsPath()->IsQueue()) { footpath_queue_chain_push(tileElement->AsPath()->GetRideIndex()); } - int32_t d = direction_reverse(direction); + auto d = direction_reverse(direction); tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() & ~(1 << d)); int32_t cd = ((d - 1) & 3); tileElement->AsPath()->SetCorners(tileElement->AsPath()->GetCorners() & ~(1 << cd)); cd = ((cd + 1) & 3); tileElement->AsPath()->SetCorners(tileElement->AsPath()->GetCorners() & ~(1 << cd)); - map_invalidate_tile({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile({ footpathPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); if (isQueue) - footpath_disconnect_queue_from_path({ x, y }, tileElement, -1); + footpath_disconnect_queue_from_path(footpathPos, tileElement, -1); - direction = (direction + 1) & 3; - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; + Direction shiftedDirection = (direction + 1) & 3; + auto targetFootPathPos = CoordsXYZ{ CoordsXY{ footpathPos } + CoordsDirectionDelta[shiftedDirection], footpathPos.z }; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(targetFootPathPos); if (tileElement == nullptr) return; do { if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (tileElement->base_height != z) + if (tileElement->GetBaseZ() != targetFootPathPos.z) continue; if (tileElement->AsPath()->IsSloped()) break; - cd = ((direction + 1) & 3); + cd = ((shiftedDirection + 1) & 3); tileElement->AsPath()->SetCorners(tileElement->AsPath()->GetCorners() & ~(1 << cd)); - map_invalidate_tile({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile({ targetFootPathPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); break; } while (!(tileElement++)->IsLastForTile()); } @@ -1990,7 +1989,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (slope != direction) break; } - footpath_remove_edges_towards_here(x, y, z1, direction, tileElement, isQueue); + footpath_remove_edges_towards_here({ x, y, z1 * COORDS_Z_STEP}, direction, tileElement, isQueue); break; } @@ -2003,7 +2002,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (slope != direction) break; - footpath_remove_edges_towards_here(x, y, z1, direction, tileElement, isQueue); + footpath_remove_edges_towards_here({ x, y, z1 * COORDS_Z_STEP }, direction, tileElement, isQueue); break; } } while (!(tileElement++)->IsLastForTile()); From 8e0020e5a2ce6a65350a63cf81a84f1213e54c4e Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:52:18 -0300 Subject: [PATCH 12/18] Use CoordsXYRangedZ for footpath_remove_edges_towards() --- src/openrct2/world/Footpath.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 2074d4e0a5..8d70febc4a 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1966,14 +1966,14 @@ static void footpath_remove_edges_towards_here( * * rct2: 0x006A6B14 */ -static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction, bool isQueue) +static void footpath_remove_edges_towards(const CoordsXYRangedZ& footPathPos, int32_t direction, bool isQueue) { - if (!map_is_location_valid({ x, y })) + if (!map_is_location_valid(footPathPos)) { return; } - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(footPathPos); if (tileElement == nullptr) return; do @@ -1981,7 +1981,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (z1 == tileElement->base_height) + if (footPathPos.clearanceZ == tileElement->GetBaseZ()) { if (tileElement->AsPath()->IsSloped()) { @@ -1989,11 +1989,11 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (slope != direction) break; } - footpath_remove_edges_towards_here({ x, y, z1 * COORDS_Z_STEP}, direction, tileElement, isQueue); + footpath_remove_edges_towards_here({ footPathPos, footPathPos.clearanceZ }, direction, tileElement, isQueue); break; } - if (z0 == tileElement->base_height) + if (footPathPos.baseZ == tileElement->GetBaseZ()) { if (!tileElement->AsPath()->IsSloped()) break; @@ -2002,7 +2002,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (slope != direction) break; - footpath_remove_edges_towards_here({ x, y, z1 * COORDS_Z_STEP }, direction, tileElement, isQueue); + footpath_remove_edges_towards_here({ footPathPos, footPathPos.clearanceZ }, direction, tileElement, isQueue); break; } } while (!(tileElement++)->IsLastForTile()); @@ -2167,8 +2167,7 @@ void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElem bool isQueue = tileElement->GetType() == TILE_ELEMENT_TYPE_PATH ? tileElement->AsPath()->IsQueue() : false; int32_t z0 = z1 - 2; footpath_remove_edges_towards( - footpathPos.x + CoordsDirectionDelta[direction].x, footpathPos.y + CoordsDirectionDelta[direction].y, z0, z1, - direction, isQueue); + { footpathPos + CoordsDirectionDelta[direction], z0 * COORDS_Z_STEP, z1 * COORDS_Z_STEP }, direction, isQueue); } else { From 900a2fbd7b766dfb7f72bce02ab747311d18f7dd Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:55:21 -0300 Subject: [PATCH 13/18] Use CoordsXYRangedZ on footpath_get_element() --- src/openrct2/world/Footpath.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 8d70febc4a..ed05c6430d 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -656,12 +656,12 @@ static void neighbour_list_sort(rct_neighbour_list* neighbourList) qsort(neighbourList->items, neighbourList->count, sizeof(rct_neighbour), rct_neighbour_compare); } -static TileElement* footpath_get_element(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction) +static TileElement* footpath_get_element(const CoordsXYRangedZ& footpathPos, int32_t direction) { TileElement* tileElement; int32_t slope; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(footpathPos); if (tileElement == nullptr) return nullptr; do @@ -669,7 +669,7 @@ static TileElement* footpath_get_element(int32_t x, int32_t y, int32_t z0, int32 if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (z1 == tileElement->base_height) + if (footpathPos.clearanceZ == tileElement->GetBaseZ()) { if (tileElement->AsPath()->IsSloped()) { @@ -679,7 +679,7 @@ static TileElement* footpath_get_element(int32_t x, int32_t y, int32_t z0, int32 } return tileElement; } - if (z0 == tileElement->base_height) + if (footpathPos.baseZ == tileElement->GetBaseZ()) { if (!tileElement->AsPath()->IsSloped()) break; @@ -715,24 +715,23 @@ static bool footpath_reconnect_queue_to_path( return false; } - int32_t z = tileElement->base_height; - TileElement* otherTileElement = footpath_get_element(targetQueuePos.x, targetQueuePos.y, z - 2, z, direction); - if (otherTileElement != nullptr && !otherTileElement->AsPath()->IsQueue()) + int32_t z = tileElement->GetBaseZ(); + TileElement* targetFootpathElement = footpath_get_element({ targetQueuePos, z - LAND_HEIGHT_STEP, z }, direction); + if (targetFootpathElement != nullptr && !targetFootpathElement->AsPath()->IsQueue()) { + auto targetQueueElement = targetFootpathElement->AsPath(); tileElement->AsPath()->SetSlopeDirection(0); if (action > 0) { tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() & ~(1 << direction)); - otherTileElement->AsPath()->SetEdges( - otherTileElement->AsPath()->GetEdges() & ~(1 << (direction_reverse(direction) & 3))); + targetQueueElement->SetEdges(targetQueueElement->GetEdges() & ~(1 << (direction_reverse(direction) & 3))); if (action >= 2) tileElement->AsPath()->SetSlopeDirection(direction); } else if (action < 0) { tileElement->AsPath()->SetEdges(tileElement->AsPath()->GetEdges() | (1 << direction)); - otherTileElement->AsPath()->SetEdges( - otherTileElement->AsPath()->GetEdges() | (1 << (direction_reverse(direction) & 3))); + targetQueueElement->SetEdges(targetQueueElement->GetEdges() | (1 << (direction_reverse(direction) & 3))); } if (action != 0) map_invalidate_tile_full(targetQueuePos); From 613dd41b53dc4b6d58dfb427e47236a4516f143f Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:59:25 -0300 Subject: [PATCH 14/18] Use CoordsXYZ on map_get_footpath_element_slope() --- src/openrct2/actions/FootpathPlaceAction.hpp | 10 +++++----- src/openrct2/world/Footpath.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 6d37b04859..683690f2bb 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -95,7 +95,7 @@ public: } footpath_provisional_remove(); - auto tileElement = map_get_footpath_element_slope((_loc.x / 32), (_loc.y / 32), _loc.z / 8, _slope); + auto tileElement = map_get_footpath_element_slope(_loc, _slope); if (tileElement == nullptr) { return ElementInsertQuery(std::move(res)); @@ -141,7 +141,7 @@ public: } } - auto tileElement = map_get_footpath_element_slope((_loc.x / 32), (_loc.y / 32), _loc.z / 8, _slope); + auto tileElement = map_get_footpath_element_slope(_loc, _slope); if (tileElement == nullptr) { return ElementInsertExecute(std::move(res)); @@ -432,17 +432,17 @@ private: map_invalidate_tile_full(_loc); } - PathElement* map_get_footpath_element_slope(int32_t x, int32_t y, int32_t z, int32_t slope) const + PathElement* map_get_footpath_element_slope(const CoordsXYZ& footpathPos, int32_t slope) const { TileElement* tileElement; bool isSloped = slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; - tileElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); + tileElement = map_get_first_element_at(footpathPos); do { if (tileElement == nullptr) break; - if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == z + if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->GetBaseZ() == footpathPos.z && (tileElement->AsPath()->IsSloped() == isSloped) && (tileElement->AsPath()->GetSlopeDirection() == (slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK))) { diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 107ededa12..0d3e444c16 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -177,7 +177,7 @@ extern const LocationXY16 BenchUseOffsets[NumOrthogonalDirections * 2]; TileElement* map_get_footpath_element(CoordsXYZ coords); struct PathElement; -PathElement* map_get_footpath_element_slope(int32_t x, int32_t y, int32_t z, int32_t slope); +PathElement* map_get_footpath_element_slope(const CoordsXYZ& footpathPos, int32_t slope); void footpath_interrupt_peeps(const CoordsXYZ& footpathPos); money32 footpath_remove(CoordsXYZ footpathLoc, int32_t flags); money32 footpath_provisional_set(int32_t type, CoordsXYZ footpathLoc, int32_t slope); From 301e0cfeb10bcfca9351a9122559f422f1d547f0 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 09:03:59 -0300 Subject: [PATCH 15/18] Use CoordsXYZ on footpath_remove_litter() --- src/openrct2/actions/FootpathPlaceAction.hpp | 2 +- src/openrct2/actions/FootpathPlaceFromTrackAction.hpp | 2 +- src/openrct2/actions/FootpathRemoveAction.hpp | 2 +- src/openrct2/actions/LandSetHeightAction.hpp | 2 +- src/openrct2/actions/LargeSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/MazePlaceTrackAction.hpp | 2 +- src/openrct2/actions/MazeSetTrackAction.hpp | 2 +- src/openrct2/actions/RideEntranceExitPlaceAction.hpp | 2 +- src/openrct2/actions/SmallSceneryPlaceAction.hpp | 2 +- src/openrct2/actions/SurfaceSetStyleAction.hpp | 2 +- src/openrct2/actions/TrackPlaceAction.hpp | 2 +- src/openrct2/actions/WaterSetHeightAction.hpp | 2 +- src/openrct2/world/Footpath.cpp | 6 +++--- src/openrct2/world/Footpath.h | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 683690f2bb..e486e0386e 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -272,7 +272,7 @@ private: if (!(GetFlags() & (GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_GHOST))) { - footpath_remove_litter(_loc.x, _loc.y, _loc.z); + footpath_remove_litter(_loc); } res->Cost = MONEY(12, 00); diff --git a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp index e0d8b1cbb9..44212d68b0 100644 --- a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp +++ b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp @@ -184,7 +184,7 @@ private: if (!(GetFlags() & (GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_GHOST))) { - footpath_remove_litter(_loc.x, _loc.y, _loc.z); + footpath_remove_litter(_loc); } res->Cost = MONEY(12, 00); diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index f3b3df8898..70001ddf7f 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -79,7 +79,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { footpath_interrupt_peeps(_loc); - footpath_remove_litter(_loc.x, _loc.y, _loc.z); + footpath_remove_litter(_loc); } TileElement* footpathElement = GetFootpathElement(); diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index de33ddab24..9dbba52c67 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -148,7 +148,7 @@ public: { money32 cost = MONEY(0, 0); auto surfaceHeight = tile_element_height(_coords); - footpath_remove_litter(_coords.x, _coords.y, surfaceHeight); + footpath_remove_litter({ _coords, surfaceHeight }); if (!gCheatsDisableClearanceChecks) { diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.hpp b/src/openrct2/actions/LargeSceneryPlaceAction.hpp index 686b4efc11..3836645458 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.hpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.hpp @@ -304,7 +304,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_remove_litter(curTile.x, curTile.y, zLow * 8); + footpath_remove_litter({ curTile, zLow * COORDS_Z_STEP }); if (!gCheatsDisableClearanceChecks) { wall_remove_at({ curTile, zLow * 8, zHigh * 8 }); diff --git a/src/openrct2/actions/MazePlaceTrackAction.hpp b/src/openrct2/actions/MazePlaceTrackAction.hpp index 303bf7485b..664e9cc97b 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.hpp +++ b/src/openrct2/actions/MazePlaceTrackAction.hpp @@ -150,7 +150,7 @@ public: uint32_t flags = GetFlags(); if (!(flags & GAME_COMMAND_FLAG_GHOST)) { - footpath_remove_litter(_loc.x, _loc.y, _loc.z); + footpath_remove_litter(_loc); wall_remove_at({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); } diff --git a/src/openrct2/actions/MazeSetTrackAction.hpp b/src/openrct2/actions/MazeSetTrackAction.hpp index 2c9d56c901..ebce59eb8f 100644 --- a/src/openrct2/actions/MazeSetTrackAction.hpp +++ b/src/openrct2/actions/MazeSetTrackAction.hpp @@ -195,7 +195,7 @@ public: uint32_t flags = GetFlags(); if (!(flags & GAME_COMMAND_FLAG_GHOST)) { - footpath_remove_litter(_loc.x, _loc.y, _loc.z); + footpath_remove_litter(_loc); wall_remove_at({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); } diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index 6af2a3cd6e..f24cca4dc0 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -169,7 +169,7 @@ public: auto z = ride->stations[_stationNum].GetBaseZ(); if (!(GetFlags() & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_remove_litter(_loc.x, _loc.y, z); + footpath_remove_litter({ _loc, z }); wall_remove_at_z({ _loc, z }); } diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.hpp b/src/openrct2/actions/SmallSceneryPlaceAction.hpp index cde4070701..298cae7172 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.hpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.hpp @@ -370,7 +370,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - footpath_remove_litter(_loc.x, _loc.y, targetHeight); + footpath_remove_litter({ _loc, targetHeight }); if (!gCheatsDisableClearanceChecks && (scenery_small_entry_has_flag(sceneryEntry, SMALL_SCENERY_FLAG_NO_WALLS))) { wall_remove_at({ _loc, targetHeight, targetHeight + sceneryEntry->small_scenery.height }); diff --git a/src/openrct2/actions/SurfaceSetStyleAction.hpp b/src/openrct2/actions/SurfaceSetStyleAction.hpp index 84e8d15727..c9dd186979 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.hpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.hpp @@ -219,7 +219,7 @@ public: surfaceElement->SetSurfaceStyle(_surfaceStyle); map_invalidate_tile_full(coords); - footpath_remove_litter(coords.x, coords.y, tile_element_height(coords)); + footpath_remove_litter({ coords, tile_element_height(coords) }); } } } diff --git a/src/openrct2/actions/TrackPlaceAction.hpp b/src/openrct2/actions/TrackPlaceAction.hpp index 9ed8f1b507..11f3238dbe 100644 --- a/src/openrct2/actions/TrackPlaceAction.hpp +++ b/src/openrct2/actions/TrackPlaceAction.hpp @@ -468,7 +468,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !gCheatsDisableClearanceChecks) { - footpath_remove_litter(mapLoc.x, mapLoc.y, mapLoc.z); + footpath_remove_litter(mapLoc); if (rideTypeFlags & RIDE_TYPE_FLAG_TRACK_NO_WALLS) { wall_remove_at({ mapLoc, baseZ * 8, clearanceZ * 8 }); diff --git a/src/openrct2/actions/WaterSetHeightAction.hpp b/src/openrct2/actions/WaterSetHeightAction.hpp index 0405565284..0bf1c43b6d 100644 --- a/src/openrct2/actions/WaterSetHeightAction.hpp +++ b/src/openrct2/actions/WaterSetHeightAction.hpp @@ -114,7 +114,7 @@ public: res->Position.z = _height * 8; int32_t surfaceHeight = tile_element_height(_coords); - footpath_remove_litter(_coords.x, _coords.y, surfaceHeight); + footpath_remove_litter({ _coords, surfaceHeight }); if (!gCheatsDisableClearanceChecks) wall_remove_at_z({ _coords, surfaceHeight }); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index ed05c6430d..dc31b476cb 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -397,16 +397,16 @@ void footpath_bridge_get_info_from_pos( * * rct2: 0x00673883 */ -void footpath_remove_litter(int32_t x, int32_t y, int32_t z) +void footpath_remove_litter(const CoordsXYZ& footpathPos) { - uint16_t spriteIndex = sprite_get_first_in_quadrant(x, y); + uint16_t spriteIndex = sprite_get_first_in_quadrant(footpathPos.x, footpathPos.y); while (spriteIndex != SPRITE_INDEX_NULL) { rct_litter* sprite = &get_sprite(spriteIndex)->litter; uint16_t nextSpriteIndex = sprite->next_in_quadrant; if (sprite->linked_list_index == SPRITE_LIST_LITTER) { - int32_t distanceZ = abs(sprite->z - z); + int32_t distanceZ = abs(sprite->z - footpathPos.z); if (distanceZ <= 32) { invalidate_sprite_0((rct_sprite*)sprite); diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 0d3e444c16..cd161a7d1a 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -187,7 +187,7 @@ void footpath_get_coordinates_from_pos( ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); void footpath_bridge_get_info_from_pos( ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); -void footpath_remove_litter(int32_t x, int32_t y, int32_t z); +void footpath_remove_litter(const CoordsXYZ& footpathPos); void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags); void footpath_update_queue_chains(); bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction); From 6189d13b2c787bf82798d871ba0aee9cb649718d Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 09:09:07 -0300 Subject: [PATCH 16/18] Use CoordsXYZD on footpath_is_connected_to_map_edge() --- src/openrct2/Editor.cpp | 7 ++----- src/openrct2/world/Footpath.cpp | 6 ++++-- src/openrct2/world/Footpath.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index bf8c11c0ad..f12392ec04 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -500,12 +500,9 @@ namespace Editor for (const auto& parkEntrance : gParkEntrances) { - int32_t x = parkEntrance.x; - int32_t y = parkEntrance.y; - int32_t z = parkEntrance.z / 8; int32_t direction = direction_reverse(parkEntrance.direction); - switch (footpath_is_connected_to_map_edge(x, y, z, direction, 0)) + switch (footpath_is_connected_to_map_edge(parkEntrance, direction, 0)) { case FOOTPATH_SEARCH_NOT_FOUND: gGameCommandErrorText = STR_PARK_ENTRANCE_WRONG_DIRECTION_OR_NO_PATH; @@ -516,7 +513,7 @@ namespace Editor return false; case FOOTPATH_SEARCH_SUCCESS: // Run the search again and unown the path - footpath_is_connected_to_map_edge(x, y, z, direction, (1 << 5)); + footpath_is_connected_to_map_edge(parkEntrance, direction, (1 << 5)); break; } } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index dc31b476cb..0d3aa846aa 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1418,10 +1418,12 @@ searchFromFootpath: } } -int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags) +// TODO: Use GAME_COMMAND_FLAGS +int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags) { flags |= (1 << 0); - return footpath_is_connected_to_map_edge_recurse(x, y, z, direction, flags, 0, 0, 16); + return footpath_is_connected_to_map_edge_recurse( + footpathPos.x, footpathPos.y, footpathPos.z / COORDS_Z_STEP, direction, flags, 0, 0, 16); } bool PathElement::IsSloped() const diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index cd161a7d1a..540ad54ab3 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -196,7 +196,7 @@ void footpath_chain_ride_queue( void footpath_update_path_wide_flags(int32_t x, int32_t y); bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position); -int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags); +int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags); void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement); int32_t entrance_get_directions(const TileElement* tileElement); From 57da25cab9bb437a94fcd337e69a68f70e971b20 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 09:17:01 -0300 Subject: [PATCH 17/18] Use CoordsXYZD on footpath_is_connected_to_map_edge_recurse() --- src/openrct2/world/Footpath.cpp | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 0d3aa846aa..54d47704c3 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1285,24 +1285,23 @@ static bool get_next_direction(int32_t edges, int32_t* direction) * (1 << 7): Ignore no entry signs */ static int32_t footpath_is_connected_to_map_edge_recurse( - int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags, int32_t level, int32_t distanceFromJunction, + const CoordsXYZ& footpathPos, int32_t direction, int32_t flags, int32_t level, int32_t distanceFromJunction, int32_t junctionTolerance) { TileElement* tileElement; int32_t edges, slopeDirection; - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; + auto targetPos = CoordsXYZ{ CoordsXY{ footpathPos } + CoordsDirectionDelta[direction], footpathPos.z }; if (++level > 250) return FOOTPATH_SEARCH_TOO_COMPLEX; // Check if we are at edge of map - if (x < 32 || y < 32) + if (targetPos.x < COORDS_XY_STEP || targetPos.y < COORDS_XY_STEP) return FOOTPATH_SEARCH_SUCCESS; - if (x >= gMapSizeUnits || y >= gMapSizeUnits) + if (targetPos.x >= gMapSizeUnits || targetPos.y >= gMapSizeUnits) return FOOTPATH_SEARCH_SUCCESS; - tileElement = map_get_first_element_at({ x, y }); + tileElement = map_get_first_element_at(targetPos); if (tileElement == nullptr) return level == 1 ? FOOTPATH_SEARCH_NOT_FOUND : FOOTPATH_SEARCH_INCOMPLETE; do @@ -1314,10 +1313,10 @@ static int32_t footpath_is_connected_to_map_edge_recurse( { if (direction_reverse(slopeDirection) != direction) continue; - if (tileElement->base_height + 2 != z) + if (tileElement->GetBaseZ() + PATH_HEIGHT_STEP != targetPos.z) continue; } - else if (tileElement->base_height != z) + else if (tileElement->GetBaseZ() != targetPos.z) { continue; } @@ -1332,7 +1331,7 @@ static int32_t footpath_is_connected_to_map_edge_recurse( if (flags & (1 << 5)) { - footpath_fix_ownership(x, y); + footpath_fix_ownership(targetPos.x, targetPos.y); } edges = tileElement->AsPath()->GetEdges(); direction = direction_reverse(direction); @@ -1367,14 +1366,16 @@ static int32_t footpath_is_connected_to_map_edge_recurse( searchFromFootpath: // Exclude direction we came from - z = tileElement->base_height; + targetPos.z = tileElement->GetBaseZ(); edges &= ~(1 << direction); // Find next direction to go - if (!get_next_direction(edges, &direction)) + int32_t newDirection{}; + if (!get_next_direction(edges, &newDirection)) { return FOOTPATH_SEARCH_INCOMPLETE; } + direction = newDirection; edges &= ~(1 << direction); if (edges == 0) @@ -1382,10 +1383,10 @@ searchFromFootpath: // Only possible direction to go if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction) { - z += 2; + targetPos.z += PATH_HEIGHT_STEP; } return footpath_is_connected_to_map_edge_recurse( - x, y, z, direction, flags, level, distanceFromJunction + 1, junctionTolerance); + targetPos, direction, flags, level, distanceFromJunction + 1, junctionTolerance); } else { @@ -1402,17 +1403,19 @@ searchFromFootpath: do { + direction = newDirection; edges &= ~(1 << direction); if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction) { - z += 2; + targetPos.z += PATH_HEIGHT_STEP; } - int32_t result = footpath_is_connected_to_map_edge_recurse(x, y, z, direction, flags, level, 0, junctionTolerance); + int32_t result = footpath_is_connected_to_map_edge_recurse( + targetPos, direction, flags, level, 0, junctionTolerance); if (result == FOOTPATH_SEARCH_SUCCESS) { return result; } - } while (get_next_direction(edges, &direction)); + } while (get_next_direction(edges, &newDirection)); return FOOTPATH_SEARCH_INCOMPLETE; } @@ -1422,8 +1425,7 @@ searchFromFootpath: int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags) { flags |= (1 << 0); - return footpath_is_connected_to_map_edge_recurse( - footpathPos.x, footpathPos.y, footpathPos.z / COORDS_Z_STEP, direction, flags, 0, 0, 16); + return footpath_is_connected_to_map_edge_recurse(footpathPos, direction, flags, 0, 0, 16); } bool PathElement::IsSloped() const From c5ec4982a389c760c64b7a09b95c22986fc69814 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:20:03 -0300 Subject: [PATCH 18/18] Use CoordsXY on footpath_chain_ride_queue() --- src/openrct2/ride/Ride.cpp | 8 +++---- src/openrct2/world/Footpath.cpp | 38 +++++++++++++++++---------------- src/openrct2/world/Footpath.h | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 09bd2c100f..3701d47384 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -3931,9 +3931,7 @@ static void sub_6B5952(Ride* ride) if (location.isNull()) continue; - int32_t x = location.x * 32; - int32_t y = location.y * 32; - int32_t z = location.z; + auto mapLocation = location.ToCoordsXYZ(); // This will fire for every entrance on this x, y and z, regardless whether that actually belongs to // the ride or not. @@ -3944,11 +3942,11 @@ static void sub_6B5952(Ride* ride) { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->base_height != z) + if (tileElement->GetBaseZ() != mapLocation.z) continue; int32_t direction = tileElement->GetDirection(); - footpath_chain_ride_queue(ride->id, i, x, y, tileElement, direction_reverse(direction)); + footpath_chain_ride_queue(ride->id, i, mapLocation, tileElement, direction_reverse(direction)); } while (!(tileElement++)->IsLastForTile()); } } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 54d47704c3..c3a16e2ffa 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1055,34 +1055,36 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen * rct2: 0x006A742F */ void footpath_chain_ride_queue( - ride_id_t rideIndex, int32_t entranceIndex, int32_t x, int32_t y, TileElement* tileElement, int32_t direction) + ride_id_t rideIndex, int32_t entranceIndex, const CoordsXY& initialFootpathPos, TileElement* const initialTileElement, + int32_t direction) { TileElement *lastPathElement, *lastQueuePathElement; - int32_t lastPathX = x, lastPathY = y, lastPathDirection = direction; + auto tileElement = initialTileElement; + auto curQueuePos = initialFootpathPos; + auto lastPath = curQueuePos; + int32_t baseZ = tileElement->GetBaseZ(); + int32_t lastPathDirection = direction; lastPathElement = nullptr; lastQueuePathElement = nullptr; - int32_t z = tileElement->base_height; for (;;) { if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { lastPathElement = tileElement; - lastPathX = x; - lastPathY = y; + lastPath = curQueuePos; lastPathDirection = direction; if (tileElement->AsPath()->IsSloped()) { if (tileElement->AsPath()->GetSlopeDirection() == direction) { - z += 2; + baseZ += LAND_HEIGHT_STEP; } } } - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; - tileElement = map_get_first_element_at({ x, y }); + auto targetQueuePos = curQueuePos + CoordsDirectionDelta[direction]; + tileElement = map_get_first_element_at(targetQueuePos); if (tileElement != nullptr) { do @@ -1091,7 +1093,7 @@ void footpath_chain_ride_queue( continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (tileElement->base_height == z) + if (tileElement->GetBaseZ() == baseZ) { if (tileElement->AsPath()->IsSloped()) { @@ -1100,7 +1102,7 @@ void footpath_chain_ride_queue( } goto foundNextPath; } - if (tileElement->base_height == z - 2) + if (tileElement->GetBaseZ() == baseZ - LAND_HEIGHT_STEP) { if (!tileElement->AsPath()->IsSloped()) break; @@ -1108,7 +1110,7 @@ void footpath_chain_ride_queue( if (direction_reverse(tileElement->AsPath()->GetSlopeDirection()) != direction) break; - z -= 2; + baseZ -= LAND_HEIGHT_STEP; goto foundNextPath; } } while (!(tileElement++)->IsLastForTile()); @@ -1136,7 +1138,8 @@ void footpath_chain_ride_queue( tileElement->AsPath()->SetRideIndex(rideIndex); tileElement->AsPath()->SetStationIndex(entranceIndex); - map_invalidate_element({ x, y }, tileElement); + curQueuePos = targetQueuePos; + map_invalidate_element(targetQueuePos, tileElement); if (lastQueuePathElement == nullptr) { @@ -1164,7 +1167,7 @@ void footpath_chain_ride_queue( lastPathElement->AsPath()->SetHasQueueBanner(true); lastPathElement->AsPath()->SetQueueBannerDirection(lastPathDirection); // set the ride sign direction - map_animation_create(MAP_ANIMATION_TYPE_QUEUE_BANNER, { lastPathX, lastPathY, lastPathElement->GetBaseZ() }); + map_animation_create(MAP_ANIMATION_TYPE_QUEUE_BANNER, { lastPath, lastPathElement->GetBaseZ() }); } } } @@ -1222,7 +1225,7 @@ void footpath_update_queue_chains() continue; Direction direction = direction_reverse(tileElement->GetDirection()); - footpath_chain_ride_queue(rideIndex, i, location.x << 5, location.y << 5, tileElement, direction); + footpath_chain_ride_queue(rideIndex, i, location.ToCoordsXY(), tileElement, direction); } while (!(tileElement++)->IsLastForTile()); } } @@ -1902,7 +1905,7 @@ void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElem { if (tileElement->AsPath()->GetEdges() & (1 << direction)) { - footpath_chain_ride_queue(255, 0, footpathPos.x, footpathPos.y, tileElement, direction); + footpath_chain_ride_queue(255, 0, footpathPos, tileElement, direction); } } tileElement->AsPath()->SetRideIndex(RIDE_ID_NULL); @@ -1912,8 +1915,7 @@ void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElem if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { footpath_queue_chain_push(tileElement->AsEntrance()->GetRideIndex()); - footpath_chain_ride_queue( - 255, 0, footpathPos.x, footpathPos.y, tileElement, direction_reverse(tileElement->GetDirection())); + footpath_chain_ride_queue(255, 0, footpathPos, tileElement, direction_reverse(tileElement->GetDirection())); } break; } diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 540ad54ab3..1a2d213261 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -192,7 +192,7 @@ void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElemen void footpath_update_queue_chains(); 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); + ride_id_t rideIndex, int32_t entranceIndex, const CoordsXY& footpathPos, TileElement* tileElement, int32_t direction); void footpath_update_path_wide_flags(int32_t x, int32_t y); bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position);