mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #10375 from tupaschoal/coords-for-map-entrance-exit
Make map entrance/exit fetching functions use Coords objects
This commit is contained in:
commit
f59f5d9b1f
|
@ -221,7 +221,7 @@ private:
|
|||
zHigh += 2;
|
||||
}
|
||||
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc.x, _loc.y, zLow, false);
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc, false);
|
||||
// Make sure the entrance part is the middle
|
||||
if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0)
|
||||
{
|
||||
|
@ -286,7 +286,7 @@ private:
|
|||
zHigh += 2;
|
||||
}
|
||||
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc.x, _loc.y, zLow, false);
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc, false);
|
||||
// Make sure the entrance part is the middle
|
||||
if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0)
|
||||
{
|
||||
|
|
|
@ -130,7 +130,7 @@ private:
|
|||
zHigh += 2;
|
||||
}
|
||||
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc.x, _loc.y, zLow, false);
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc, false);
|
||||
// Make sure the entrance part is the middle
|
||||
if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0)
|
||||
{
|
||||
|
@ -198,7 +198,7 @@ private:
|
|||
zHigh += 2;
|
||||
}
|
||||
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc.x, _loc.y, zLow, false);
|
||||
auto entranceElement = map_get_park_entrance_element_at(_loc, false);
|
||||
// Make sure the entrance part is the middle
|
||||
if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0)
|
||||
{
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
private:
|
||||
void ParkEntranceRemoveSegment(CoordsXYZ loc) const
|
||||
{
|
||||
auto entranceElement = map_get_park_entrance_element_at(loc.x, loc.y, loc.z / 8, true);
|
||||
auto entranceElement = map_get_park_entrance_element_at(loc, true);
|
||||
if (entranceElement == nullptr)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -79,13 +79,12 @@ public:
|
|||
|
||||
int8_t zLow = _loc.z / 8;
|
||||
int8_t zHigh = zLow + 12;
|
||||
LocationXY16 entranceLoc = { (int16_t)_loc.x, (int16_t)_loc.y };
|
||||
CoordsXYZ entranceLoc = _loc;
|
||||
for (uint8_t index = 0; index < 3; index++)
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].x;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].y;
|
||||
entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3];
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
|
@ -100,7 +99,7 @@ public:
|
|||
}
|
||||
|
||||
// Check that entrance element does not already exist at this location
|
||||
EntranceElement* entranceElement = map_get_park_entrance_element_at(entranceLoc.x, entranceLoc.y, zLow, false);
|
||||
EntranceElement* entranceElement = map_get_park_entrance_element_at(entranceLoc, false);
|
||||
if (entranceElement != nullptr)
|
||||
{
|
||||
return std::make_unique<GameActionResult>(
|
||||
|
|
|
@ -2970,10 +2970,9 @@ private:
|
|||
ride->stations[0].Entrance = entranceCoords;
|
||||
ride->stations[0].Exit = exitCoords;
|
||||
|
||||
auto entranceElement = map_get_ride_exit_element_at(
|
||||
entranceCoords.x * 32, entranceCoords.y * 32, entranceCoords.z, false);
|
||||
auto entranceElement = map_get_ride_exit_element_at(entranceCoords.ToCoordsXYZD(), false);
|
||||
entranceElement->SetEntranceType(ENTRANCE_TYPE_RIDE_ENTRANCE);
|
||||
auto exitElement = map_get_ride_entrance_element_at(exitCoords.x * 32, exitCoords.y * 32, exitCoords.z, false);
|
||||
auto exitElement = map_get_ride_entrance_element_at(exitCoords.ToCoordsXYZD(), false);
|
||||
exitElement->SetEntranceType(ENTRANCE_TYPE_RIDE_EXIT);
|
||||
|
||||
// Trigger footpath update
|
||||
|
|
|
@ -7677,8 +7677,7 @@ void determine_ride_entrance_and_exit_locations()
|
|||
// Skip if the station has no entrance
|
||||
if (!entranceLoc.isNull())
|
||||
{
|
||||
const EntranceElement* entranceElement = map_get_ride_entrance_element_at(
|
||||
entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false);
|
||||
const EntranceElement* entranceElement = map_get_ride_entrance_element_at(entranceLoc.ToCoordsXYZD(), false);
|
||||
|
||||
if (entranceElement == nullptr || entranceElement->GetRideIndex() != ride.id
|
||||
|| entranceElement->GetStationIndex() != stationIndex)
|
||||
|
@ -7693,8 +7692,7 @@ void determine_ride_entrance_and_exit_locations()
|
|||
|
||||
if (!exitLoc.isNull())
|
||||
{
|
||||
const EntranceElement* entranceElement = map_get_ride_exit_element_at(
|
||||
exitLoc.x * 32, exitLoc.y * 32, exitLoc.z, false);
|
||||
const EntranceElement* entranceElement = map_get_ride_exit_element_at(exitLoc.ToCoordsXYZD(), false);
|
||||
|
||||
if (entranceElement == nullptr || entranceElement->GetRideIndex() != ride.id
|
||||
|| entranceElement->GetStationIndex() != stationIndex)
|
||||
|
|
|
@ -214,9 +214,7 @@ void fix_park_entrance_locations(void)
|
|||
gParkEntrances.erase(
|
||||
std::remove_if(
|
||||
gParkEntrances.begin(), gParkEntrances.end(),
|
||||
[](const auto& entrance) {
|
||||
return map_get_park_entrance_element_at(entrance.x, entrance.y, entrance.z >> 3, false) == nullptr;
|
||||
}),
|
||||
[](const auto& entrance) { return map_get_park_entrance_element_at(entrance, false) == nullptr; }),
|
||||
gParkEntrances.end());
|
||||
}
|
||||
|
||||
|
|
|
@ -395,6 +395,11 @@ struct TileCoordsXYZD
|
|||
{
|
||||
return x == COORDS_NULL;
|
||||
};
|
||||
|
||||
CoordsXYZD ToCoordsXYZD() const
|
||||
{
|
||||
return { x * 32, y * 32, z * 8, direction };
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1779,9 +1779,10 @@ LargeSceneryElement* map_get_large_scenery_segment(int32_t x, int32_t y, int32_t
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost)
|
||||
EntranceElement* map_get_park_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost)
|
||||
{
|
||||
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
|
||||
auto entranceTileCoords = TileCoordsXYZ(entranceCoords);
|
||||
TileElement* tileElement = map_get_first_element_at(entranceTileCoords.x, entranceTileCoords.y);
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
do
|
||||
|
@ -1789,7 +1790,7 @@ EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t
|
|||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->base_height != z)
|
||||
if (tileElement->base_height != entranceTileCoords.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE)
|
||||
|
@ -1804,9 +1805,10 @@ EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost)
|
||||
EntranceElement* map_get_ride_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost)
|
||||
{
|
||||
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
|
||||
auto entranceTileCoords = TileCoordsXYZ{ entranceCoords };
|
||||
TileElement* tileElement = map_get_first_element_at(entranceTileCoords.x, entranceTileCoords.y);
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
do
|
||||
|
@ -1814,7 +1816,7 @@ EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t
|
|||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->base_height != z)
|
||||
if (tileElement->base_height != entranceTileCoords.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE)
|
||||
|
@ -1829,9 +1831,10 @@ EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost)
|
||||
EntranceElement* map_get_ride_exit_element_at(const CoordsXYZ& exitCoords, bool ghost)
|
||||
{
|
||||
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
|
||||
auto exitTileCoords = TileCoordsXYZ{ exitCoords };
|
||||
TileElement* tileElement = map_get_first_element_at(exitTileCoords.x, exitTileCoords.y);
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
do
|
||||
|
@ -1839,7 +1842,7 @@ EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, b
|
|||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->base_height != z)
|
||||
if (tileElement->base_height != exitTileCoords.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT)
|
||||
|
|
|
@ -148,9 +148,9 @@ SurfaceElement* map_get_surface_element_at(const CoordsXY& coords);
|
|||
PathElement* map_get_path_element_at(const TileCoordsXYZ& loc);
|
||||
WallElement* map_get_wall_element_at(CoordsXYZD wallCoords);
|
||||
SmallSceneryElement* map_get_small_scenery_element_at(int32_t x, int32_t y, int32_t z, int32_t type, uint8_t quadrant);
|
||||
EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
|
||||
EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
|
||||
EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
|
||||
EntranceElement* map_get_park_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost);
|
||||
EntranceElement* map_get_ride_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost);
|
||||
EntranceElement* map_get_ride_exit_element_at(const CoordsXYZ& exitCoords, bool ghost);
|
||||
int16_t tile_element_height(const CoordsXY& loc);
|
||||
int16_t tile_element_water_height(const CoordsXY& loc);
|
||||
uint8_t map_get_highest_land_height(const MapRange& range);
|
||||
|
|
|
@ -94,7 +94,8 @@ TEST_F(TileElementWantsFootpathConnection, Stall)
|
|||
TEST_F(TileElementWantsFootpathConnection, RideEntrance)
|
||||
{
|
||||
// Ride entrances and exits want a connection in one direction
|
||||
const EntranceElement* const entranceElement = map_get_ride_entrance_element_at(18 << 5, 8 << 5, 14, false);
|
||||
const EntranceElement* const entranceElement = map_get_ride_entrance_element_at(
|
||||
TileCoordsXYZ{ 18, 8, 14 }.ToCoordsXYZ(), false);
|
||||
ASSERT_NE(entranceElement, nullptr);
|
||||
EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 8, 14, 0 }, nullptr));
|
||||
EXPECT_FALSE(tile_element_wants_path_connection_towards({ 18, 8, 14, 1 }, nullptr));
|
||||
|
@ -106,7 +107,7 @@ TEST_F(TileElementWantsFootpathConnection, RideEntrance)
|
|||
TEST_F(TileElementWantsFootpathConnection, RideExit)
|
||||
{
|
||||
// The exit has been rotated; it wants a path connection in direction 1, but not 0 like the entrance
|
||||
const EntranceElement* const exitElement = map_get_ride_exit_element_at(18 << 5, 10 << 5, 14, false);
|
||||
const EntranceElement* const exitElement = map_get_ride_exit_element_at(TileCoordsXYZ{ 18, 10, 14 }.ToCoordsXYZ(), false);
|
||||
ASSERT_NE(exitElement, nullptr);
|
||||
EXPECT_FALSE(tile_element_wants_path_connection_towards({ 18, 10, 14, 0 }, nullptr));
|
||||
EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 10, 14, 1 }, nullptr));
|
||||
|
|
Loading…
Reference in New Issue