mirror of https://github.com/OpenRCT2/OpenRCT2.git
Make Map::map_get_track_element_at() use CoordsXYZ
This commit is contained in:
parent
10c9a48fd6
commit
6c998d7b4d
|
@ -4884,7 +4884,7 @@ void Guest::UpdateRideMazePathfinding()
|
|||
int16_t stationHeight = ride->stations[0].Height;
|
||||
|
||||
// Find the station track element
|
||||
auto trackElement = map_get_track_element_at(targetLoc.x, targetLoc.y, stationHeight);
|
||||
auto trackElement = map_get_track_element_at({ targetLoc, stationHeight << 3 });
|
||||
if (trackElement == nullptr)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -2339,11 +2339,10 @@ bool Staff::UpdateFixingMoveToStationEnd(bool firstRun, Ride* ride)
|
|||
return true;
|
||||
}
|
||||
|
||||
uint8_t stationZ = ride->stations[current_ride_station].Height;
|
||||
uint16_t stationX = stationPosition.x * 32;
|
||||
uint16_t stationY = stationPosition.y * 32;
|
||||
auto stationTilePos = TileCoordsXYZ{ stationPosition, ride->stations[current_ride_station].Height };
|
||||
auto stationPos = stationTilePos.ToCoordsXYZ();
|
||||
|
||||
auto tileElement = map_get_track_element_at(stationX, stationY, stationZ);
|
||||
auto tileElement = map_get_track_element_at(stationPos);
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
log_error("Couldn't find tile_element");
|
||||
|
@ -2353,20 +2352,20 @@ bool Staff::UpdateFixingMoveToStationEnd(bool firstRun, Ride* ride)
|
|||
int32_t trackDirection = tileElement->GetDirection();
|
||||
CoordsXY offset = _StationFixingOffsets[trackDirection];
|
||||
|
||||
stationX += 16 + offset.x;
|
||||
stationPos.x += 16 + offset.x;
|
||||
if (offset.x == 0)
|
||||
{
|
||||
stationX = destination_x;
|
||||
stationPos.x = destination_x;
|
||||
}
|
||||
|
||||
stationY += 16 + offset.y;
|
||||
stationPos.y += 16 + offset.y;
|
||||
if (offset.y == 0)
|
||||
{
|
||||
stationY = destination_y;
|
||||
stationPos.y = destination_y;
|
||||
}
|
||||
|
||||
destination_x = stationX;
|
||||
destination_y = stationY;
|
||||
destination_x = stationPos.x;
|
||||
destination_y = stationPos.y;
|
||||
destination_tolerance = 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -4692,15 +4692,13 @@ static void vehicle_unset_update_flag_b1(rct_vehicle* head)
|
|||
static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYElement)
|
||||
{
|
||||
rct_vehicle* vehicle = GET_VEHICLE(ride->vehicles[0]);
|
||||
int32_t firstX = vehicle->track_x;
|
||||
int32_t firstY = vehicle->track_y;
|
||||
int32_t firstZ = vehicle->track_z;
|
||||
auto firstElement = map_get_track_element_at(firstX, firstY, firstZ / 8);
|
||||
auto firstPos = CoordsXYZ{ vehicle->track_x, vehicle->track_y, vehicle->track_z };
|
||||
auto firstElement = map_get_track_element_at(firstPos);
|
||||
|
||||
assert(firstElement != nullptr);
|
||||
|
||||
int32_t x = firstX;
|
||||
int32_t y = firstY;
|
||||
int32_t x = firstPos.x;
|
||||
int32_t y = firstPos.y;
|
||||
auto trackElement = firstElement;
|
||||
track_begin_end trackBeginEnd;
|
||||
while (track_block_get_previous(x, y, reinterpret_cast<TileElement*>(trackElement), &trackBeginEnd))
|
||||
|
@ -4708,7 +4706,7 @@ static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYEl
|
|||
x = trackBeginEnd.end_x;
|
||||
y = trackBeginEnd.end_y;
|
||||
trackElement = trackBeginEnd.begin_element->AsTrack();
|
||||
if (x == firstX && y == firstY && trackElement == firstElement)
|
||||
if (x == firstPos.x && y == firstPos.y && trackElement == firstElement)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -4752,8 +4750,8 @@ static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYEl
|
|||
}
|
||||
}
|
||||
|
||||
outXYElement->x = firstX;
|
||||
outXYElement->y = firstY;
|
||||
outXYElement->x = firstPos.x;
|
||||
outXYElement->y = firstPos.y;
|
||||
outXYElement->element = reinterpret_cast<TileElement*>(firstElement);
|
||||
}
|
||||
|
||||
|
@ -4794,7 +4792,7 @@ static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApply
|
|||
x = element->x - CoordsDirectionDelta[direction].x;
|
||||
y = element->y - CoordsDirectionDelta[direction].y;
|
||||
|
||||
tileElement = reinterpret_cast<TileElement*>(map_get_track_element_at(x, y, z));
|
||||
tileElement = reinterpret_cast<TileElement*>(map_get_track_element_at({ x, y, z << 3 }));
|
||||
|
||||
z = tileElement->base_height;
|
||||
direction = tileElement->GetDirection();
|
||||
|
@ -5054,7 +5052,7 @@ static bool ride_create_cable_lift(ride_id_t rideIndex, bool isApplying)
|
|||
}
|
||||
|
||||
auto cableLiftLoc = ride->CableLiftLoc;
|
||||
auto tileElement = map_get_track_element_at(cableLiftLoc.x, cableLiftLoc.y, cableLiftLoc.z / 8);
|
||||
auto tileElement = map_get_track_element_at(cableLiftLoc);
|
||||
int32_t direction = tileElement->GetDirection();
|
||||
|
||||
rct_vehicle* head = nullptr;
|
||||
|
|
|
@ -2801,7 +2801,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle)
|
|||
int32_t y = location.y * 32;
|
||||
int32_t z = ride->stations[station].Height;
|
||||
|
||||
auto tileElement = map_get_track_element_at(x, y, z);
|
||||
auto tileElement = map_get_track_element_at({ x, y, z << 3 });
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
return false;
|
||||
|
@ -3978,7 +3978,7 @@ loc_6D8E36:
|
|||
return;
|
||||
}
|
||||
|
||||
auto trackElement = map_get_track_element_at(vehicle->track_x, vehicle->track_y, vehicle->track_z / 8);
|
||||
auto trackElement = map_get_track_element_at({ vehicle->track_x, vehicle->track_y, vehicle->track_z });
|
||||
|
||||
if (trackElement == nullptr)
|
||||
{
|
||||
|
@ -4248,7 +4248,7 @@ static void loc_6DA9F9(rct_vehicle* vehicle, int32_t x, int32_t y, int32_t bx, i
|
|||
vehicle->track_x = bx;
|
||||
vehicle->track_y = dx;
|
||||
|
||||
auto trackElement = map_get_track_element_at(vehicle->track_x, vehicle->track_y, vehicle->track_z >> 3);
|
||||
auto trackElement = map_get_track_element_at({ vehicle->track_x, vehicle->track_y, vehicle->track_z });
|
||||
|
||||
auto ride = get_ride(vehicle->ride);
|
||||
if (ride != nullptr)
|
||||
|
@ -6748,7 +6748,7 @@ static void vehicle_update_block_brakes_open_previous_section(rct_vehicle* vehic
|
|||
x = trackBeginEnd.begin_x;
|
||||
y = trackBeginEnd.begin_y;
|
||||
z = trackBeginEnd.begin_z;
|
||||
auto trackElement = map_get_track_element_at(x, y, z >> 3);
|
||||
auto trackElement = map_get_track_element_at({ x, y, z });
|
||||
if (trackElement == nullptr)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -301,6 +301,12 @@ struct TileCoordsXYZ : public TileCoordsXY
|
|||
{
|
||||
}
|
||||
|
||||
TileCoordsXYZ(TileCoordsXY c, int32_t z_)
|
||||
: TileCoordsXY(c.x, c.y)
|
||||
, z(z_)
|
||||
{
|
||||
}
|
||||
|
||||
TileCoordsXYZ(CoordsXY c, int32_t z_)
|
||||
: TileCoordsXY(c)
|
||||
, z(z_)
|
||||
|
|
|
@ -2130,16 +2130,17 @@ void map_clear_all_elements()
|
|||
* @param y y units, not tiles.
|
||||
* @param z Base height.
|
||||
*/
|
||||
TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z)
|
||||
TrackElement* map_get_track_element_at(const CoordsXYZ& trackPos)
|
||||
{
|
||||
TileElement* tileElement = map_get_first_element_at({ x, y });
|
||||
TileElement* tileElement = map_get_first_element_at(trackPos);
|
||||
if (tileElement == nullptr)
|
||||
return nullptr;
|
||||
auto trackTilePos = TileCoordsXYZ{ trackPos };
|
||||
do
|
||||
{
|
||||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
|
||||
continue;
|
||||
if (tileElement->base_height != z)
|
||||
if (tileElement->base_height != trackTilePos.z)
|
||||
continue;
|
||||
|
||||
return tileElement->AsTrack();
|
||||
|
|
|
@ -229,7 +229,7 @@ bool map_large_scenery_get_origin(
|
|||
|
||||
ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos);
|
||||
|
||||
TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z);
|
||||
TrackElement* map_get_track_element_at(const CoordsXYZ& trackPos);
|
||||
TileElement* map_get_track_element_at_of_type(int32_t x, int32_t y, int32_t z, int32_t trackType);
|
||||
TileElement* map_get_track_element_at_of_type_seq(int32_t x, int32_t y, int32_t z, int32_t trackType, int32_t sequence);
|
||||
TrackElement* map_get_track_element_at_of_type(CoordsXYZD location, int32_t trackType);
|
||||
|
|
|
@ -82,7 +82,7 @@ TEST_F(TileElementWantsFootpathConnection, SlopedPath)
|
|||
TEST_F(TileElementWantsFootpathConnection, Stall)
|
||||
{
|
||||
// Stalls usually have one path direction flag, but can have multiple (info kiosk for example)
|
||||
const TrackElement* const stallElement = map_get_track_element_at(19 << 5, 15 << 5, 14);
|
||||
const TrackElement* const stallElement = map_get_track_element_at({ 19 << 5, 15 << 5, 14 << 3 });
|
||||
ASSERT_NE(stallElement, nullptr);
|
||||
EXPECT_TRUE(tile_element_wants_path_connection_towards({ 19, 15, 14, 0 }, nullptr));
|
||||
EXPECT_FALSE(tile_element_wants_path_connection_towards({ 19, 15, 14, 1 }, nullptr));
|
||||
|
|
Loading…
Reference in New Issue