mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #12198 from heliobatimarqui/issue_12159
Close #12159: Use Coords for Ride functions #12182
This commit is contained in:
@@ -123,7 +123,7 @@ Direction gRideEntranceExitPlaceDirection;
|
||||
uint8_t gLastEntranceStyle;
|
||||
|
||||
// Static function declarations
|
||||
Peep* find_closest_mechanic(int32_t x, int32_t y, int32_t forInspection);
|
||||
Peep* find_closest_mechanic(const CoordsXY& entrancePosition, int32_t forInspection);
|
||||
static void ride_breakdown_status_update(Ride* ride);
|
||||
static void ride_breakdown_update(Ride* ride);
|
||||
static void ride_call_closest_mechanic(Ride* ride);
|
||||
@@ -2670,7 +2670,7 @@ Peep* ride_find_closest_mechanic(Ride* ride, int32_t forInspection)
|
||||
// Set x,y to centre of the station exit for the mechanic search.
|
||||
auto centreMapLocation = mapLocation.ToTileCentre();
|
||||
|
||||
return find_closest_mechanic(centreMapLocation.x, centreMapLocation.y, forInspection);
|
||||
return find_closest_mechanic(centreMapLocation, forInspection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2678,7 +2678,7 @@ Peep* ride_find_closest_mechanic(Ride* ride, int32_t forInspection)
|
||||
* rct2: 0x006B774B (forInspection = 0)
|
||||
* rct2: 0x006B78C3 (forInspection = 1)
|
||||
*/
|
||||
Peep* find_closest_mechanic(int32_t x, int32_t y, int32_t forInspection)
|
||||
Peep* find_closest_mechanic(const CoordsXY& entrancePosition, int32_t forInspection)
|
||||
{
|
||||
Peep* closestMechanic = nullptr;
|
||||
uint32_t closestDistance = std::numeric_limits<uint32_t>::max();
|
||||
@@ -2707,7 +2707,7 @@ Peep* find_closest_mechanic(int32_t x, int32_t y, int32_t forInspection)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto location = CoordsXY(x, y).ToTileStart();
|
||||
auto location = entrancePosition.ToTileStart();
|
||||
if (map_is_location_in_park(location))
|
||||
if (!peep->AsStaff()->IsLocationInPatrol(location))
|
||||
continue;
|
||||
@@ -2716,7 +2716,7 @@ Peep* find_closest_mechanic(int32_t x, int32_t y, int32_t forInspection)
|
||||
continue;
|
||||
|
||||
// Manhattan distance
|
||||
uint32_t distance = std::abs(peep->x - x) + std::abs(peep->y - y);
|
||||
uint32_t distance = std::abs(peep->x - entrancePosition.x) + std::abs(peep->y - entrancePosition.y);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
@@ -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. */
|
||||
@@ -7247,16 +7247,17 @@ TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tol
|
||||
/**
|
||||
* Check for an adjacent station to x,y,z in direction.
|
||||
*/
|
||||
static bool check_for_adjacent_station(int32_t x, int32_t y, int32_t z, uint8_t direction)
|
||||
static bool check_for_adjacent_station(const CoordsXYZ& stationCoords, uint8_t direction)
|
||||
{
|
||||
bool found = false;
|
||||
int32_t adjX = x;
|
||||
int32_t adjY = y;
|
||||
int32_t adjX = stationCoords.x;
|
||||
int32_t adjY = stationCoords.y;
|
||||
for (uint32_t i = 0; i <= RIDE_ADJACENCY_CHECK_DISTANCE; i++)
|
||||
{
|
||||
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, stationCoords.z }, stationCoords.z + 2 * COORDS_Z_STEP });
|
||||
if (stationElement != nullptr)
|
||||
{
|
||||
auto rideIndex = stationElement->AsTrack()->GetRideIndex();
|
||||
@@ -7285,19 +7286,19 @@ 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;
|
||||
}
|
||||
/* Check the first side of the station */
|
||||
int32_t direction = stationElement->GetDirectionWithOffset(1);
|
||||
found = check_for_adjacent_station(stationStart.x, stationStart.y, stationStart.z, direction);
|
||||
found = check_for_adjacent_station(stationStart, direction);
|
||||
if (found)
|
||||
break;
|
||||
/* Check the other side of the station */
|
||||
direction = direction_reverse(direction);
|
||||
found = check_for_adjacent_station(stationStart.x, stationStart.y, stationStart.z, direction);
|
||||
found = check_for_adjacent_station(stationStart, direction);
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user