1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 13:03:11 +01:00

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.
This commit is contained in:
Helio Santos
2020-07-10 09:40:23 -07:00
parent fb9fab69a9
commit b0a4f2a97e
4 changed files with 57 additions and 50 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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,

View File

@@ -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;