From b0a4f2a97ebb04b6a1a0f484998dc89d98fc4c3f Mon Sep 17 00:00:00 2001 From: Helio Santos Date: Fri, 10 Jul 2020 09:40:23 -0700 Subject: [PATCH] Part of #12159: updated get_station_platform to use CoordsXYRangedZ Updated get_station_platform function to use CoordsXYRangedZ. Updated caller(s) accordingly. Implemented constructor for CoordsXYRangedZ that takes a CoordsXYZ as argument. --- src/openrct2/ride/Ride.cpp | 10 ++-- src/openrct2/ride/Ride.h | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/world/Location.hpp | 93 ++++++++++++++++++--------------- 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 82f0ba1abb..b4337d4de8 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7211,10 +7211,10 @@ money16 ride_get_price(const Ride* ride) * Return the tile_element of an adjacent station at x,y,z(+-2). * Returns nullptr if no suitable tile_element is found. */ -TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tolerance) +TileElement* get_station_platform(const CoordsXYRangedZ& coords) { bool foundTileElement = false; - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(coords); if (tileElement != nullptr) { do @@ -7225,7 +7225,7 @@ TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tol if (!tileElement->AsTrack()->IsStation()) continue; - if (z - z_tolerance > tileElement->GetBaseZ() || z + z_tolerance < tileElement->GetBaseZ()) + if (coords.baseZ > tileElement->GetBaseZ() || coords.clearanceZ < tileElement->GetBaseZ()) { /* The base height if tileElement is not within * the z tolerance. */ @@ -7256,7 +7256,7 @@ static bool check_for_adjacent_station(int32_t x, int32_t y, int32_t z, uint8_t { adjX += CoordsDirectionDelta[direction].x; adjY += CoordsDirectionDelta[direction].y; - TileElement* stationElement = get_station_platform(adjX, adjY, z, 2 * COORDS_Z_STEP); + TileElement* stationElement = get_station_platform({ { adjX, adjY, z }, z + 2 * COORDS_Z_STEP }); if (stationElement != nullptr) { auto rideIndex = stationElement->AsTrack()->GetRideIndex(); @@ -7285,7 +7285,7 @@ bool ride_has_adjacent_station(Ride* ride) if (!stationStart.isNull()) { /* Get the map element for the station start. */ - TileElement* stationElement = get_station_platform(stationStart.x, stationStart.y, stationStart.z, 0); + TileElement* stationElement = get_station_platform({ stationStart, stationStart.z + 0 }); if (stationElement == nullptr) { continue; diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index dc82a5432e..cce23d736d 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1201,7 +1201,7 @@ void window_ride_construction_do_entrance_exit_check(); money16 ride_get_price(const Ride* ride); -TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tolerance); +TileElement* get_station_platform(const CoordsXYRangedZ& coords); bool ride_has_adjacent_station(Ride* ride); bool ride_has_station_shelter(Ride* ride); bool ride_has_ratings(const Ride* ride); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index b9dc2b3cea..374c4c8886 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2698,7 +2698,7 @@ static bool try_add_synchronised_station(const CoordsXYZ& coords) return false; } - TileElement* tileElement = get_station_platform(coords.x, coords.y, coords.z, 2 * COORDS_Z_STEP); + TileElement* tileElement = get_station_platform({ coords, coords.z + 2 * COORDS_Z_STEP }); if (tileElement == nullptr) { /* No station platform element found, diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index c7567e14cf..1fac1d938c 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -218,6 +218,49 @@ struct CoordsXY } }; +struct CoordsXYZ : public CoordsXY +{ + int32_t z = 0; + + CoordsXYZ() = default; + constexpr CoordsXYZ(int32_t _x, int32_t _y, int32_t _z) + : CoordsXY(_x, _y) + , z(_z) + { + } + + constexpr CoordsXYZ(const CoordsXY& c, int32_t _z) + : CoordsXY(c) + , z(_z) + { + } + + const CoordsXYZ operator+(const CoordsXYZ& rhs) const + { + return { x + rhs.x, y + rhs.y, z + rhs.z }; + } + + const CoordsXYZ operator-(const CoordsXYZ& rhs) const + { + return { x - rhs.x, y - rhs.y, z - rhs.z }; + } + + bool operator==(const CoordsXYZ& other) const + { + return x == other.x && y == other.y && z == other.z; + } + + CoordsXYZ ToTileStart() const + { + return { floor2(x, COORDS_XY_STEP), floor2(y, COORDS_XY_STEP), z }; + } + + CoordsXYZ ToTileCentre() const + { + return ToTileStart() + CoordsXYZ{ COORDS_XY_HALF_TILE, COORDS_XY_HALF_TILE, 0 }; + } +}; + struct CoordsXYRangedZ : public CoordsXY { int32_t baseZ = 0; @@ -237,6 +280,13 @@ struct CoordsXYRangedZ : public CoordsXY , clearanceZ(_clearanceZ) { } + + constexpr CoordsXYRangedZ(const CoordsXYZ& _c, int32_t _clearanceZ) + : CoordsXY(_c) + , baseZ(_c.z) + , clearanceZ(_clearanceZ) + { + } }; struct TileCoordsXY @@ -337,49 +387,6 @@ struct TileCoordsXY } }; -struct CoordsXYZ : public CoordsXY -{ - int32_t z = 0; - - CoordsXYZ() = default; - constexpr CoordsXYZ(int32_t _x, int32_t _y, int32_t _z) - : CoordsXY(_x, _y) - , z(_z) - { - } - - constexpr CoordsXYZ(const CoordsXY& c, int32_t _z) - : CoordsXY(c) - , z(_z) - { - } - - const CoordsXYZ operator+(const CoordsXYZ& rhs) const - { - return { x + rhs.x, y + rhs.y, z + rhs.z }; - } - - const CoordsXYZ operator-(const CoordsXYZ& rhs) const - { - return { x - rhs.x, y - rhs.y, z - rhs.z }; - } - - bool operator==(const CoordsXYZ& other) const - { - return x == other.x && y == other.y && z == other.z; - } - - CoordsXYZ ToTileStart() const - { - return { floor2(x, COORDS_XY_STEP), floor2(y, COORDS_XY_STEP), z }; - } - - CoordsXYZ ToTileCentre() const - { - return ToTileStart() + CoordsXYZ{ COORDS_XY_HALF_TILE, COORDS_XY_HALF_TILE, 0 }; - } -}; - struct TileCoordsXYZ : public TileCoordsXY { int32_t z = 0;