forked from rosebudai/OpenRCT2-Web
Migrate some tile iteration loops to TileElementsView (#26769)
This commit is contained in:
1 parent
6903d5310e
commit
4aa32fd978
18 files changed
+175
-289
No files matched your search
@@ -23,6 +23,7 @@
|
||||
#include <openrct2/ride/ted/TrackElementDescriptor.h>
|
||||
#include <openrct2/util/Util.h>
|
||||
#include <openrct2/world/Map.h>
|
||||
#include <openrct2/world/TileElementsView.h>
|
||||
#include <openrct2/world/tile_element/TrackElement.h>
|
||||
|
||||
using namespace OpenRCT2::TrackMetadata;
|
||||
@@ -450,16 +451,10 @@ namespace OpenRCT2
|
||||
if (MapIsLocationValid(nextLocation))
|
||||
{
|
||||
// iterate over every element in the tile until we find what we want
|
||||
auto* tileElement = MapGetFirstElementAt(nextLocation);
|
||||
if (tileElement == nullptr)
|
||||
continue;
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(nextLocation))
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
if (trackElement->getBaseZ() != stationBaseZ)
|
||||
continue;
|
||||
if (tileElement->getBaseZ() != stationBaseZ)
|
||||
continue;
|
||||
auto* trackElement = tileElement->asTrack();
|
||||
if (trackElement->GetRideIndex() != gRideEntranceExitPlaceRideIndex)
|
||||
continue;
|
||||
if (trackElement->GetTrackType() == TrackElemType::maze)
|
||||
@@ -475,7 +470,7 @@ namespace OpenRCT2
|
||||
gRideEntranceExitPlaceStationIndex = trackElement->GetStationIndex();
|
||||
|
||||
// get the ride entrance's side relative to the TrackElement
|
||||
Direction direction = (DirectionReverse(entranceExitCoords.direction) - tileElement->getDirection()) & 3;
|
||||
Direction direction = (DirectionReverse(entranceExitCoords.direction) - trackElement->getDirection()) & 3;
|
||||
const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType());
|
||||
auto connectionSides = ted.sequenceData.sequences[trackElement->GetSequenceIndex()]
|
||||
.getEntranceConnectionSides();
|
||||
@@ -487,7 +482,7 @@ namespace OpenRCT2
|
||||
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
}
|
||||
}
|
||||
gRideEntranceExitPlaceDirection = kInvalidDirection;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openrct2/world/Banner.h>
|
||||
#include <openrct2/world/Map.h>
|
||||
#include <openrct2/world/Scenery.h>
|
||||
#include <openrct2/world/TileElementsView.h>
|
||||
#include <openrct2/world/tile_element/BannerElement.h>
|
||||
|
||||
namespace OpenRCT2::Ui::Windows
|
||||
@@ -109,24 +110,13 @@ namespace OpenRCT2::Ui::Windows
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TileElement* tileElement = MapGetFirstElementAt(banner->position);
|
||||
if (tileElement == nullptr)
|
||||
for (auto* bannerElement : TileElementsView<BannerElement>(banner->position))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
auto* bannerElement = tileElement->asBanner();
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (bannerElement->GetIndex() == GetBannerIndex())
|
||||
{
|
||||
return bannerElement;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <openrct2/world/Map.h>
|
||||
#include <openrct2/world/MapSelection.h>
|
||||
#include <openrct2/world/Park.h>
|
||||
#include <openrct2/world/TileElementsView.h>
|
||||
#include <openrct2/world/tile_element/PathElement.h>
|
||||
#include <openrct2/world/tile_element/Slope.h>
|
||||
#include <openrct2/world/tile_element/SurfaceElement.h>
|
||||
@@ -1537,12 +1538,12 @@ namespace OpenRCT2::Ui::Windows
|
||||
*
|
||||
* rct2: 0x006A78EF
|
||||
*/
|
||||
void FootpathRemoveTileElement(TileElement* tileElement)
|
||||
void FootpathRemoveTileElement(PathElement* pathElement)
|
||||
{
|
||||
auto z = tileElement->getBaseZ();
|
||||
if (tileElement->asPath()->IsSloped())
|
||||
auto z = pathElement->getBaseZ();
|
||||
if (pathElement->IsSloped())
|
||||
{
|
||||
uint8_t slopeDirection = tileElement->asPath()->GetSlopeDirection();
|
||||
uint8_t slopeDirection = pathElement->GetSlopeDirection();
|
||||
slopeDirection = DirectionReverse(slopeDirection);
|
||||
if (slopeDirection == _footpathConstructDirection)
|
||||
{
|
||||
@@ -1552,16 +1553,16 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
// Find a connected edge
|
||||
int32_t edge = DirectionReverse(_footpathConstructDirection);
|
||||
if (!(tileElement->asPath()->GetEdges() & (1 << edge)))
|
||||
if (!(pathElement->GetEdges() & (1 << edge)))
|
||||
{
|
||||
edge = (edge + 1) & 3;
|
||||
if (!(tileElement->asPath()->GetEdges() & (1 << edge)))
|
||||
if (!(pathElement->GetEdges() & (1 << edge)))
|
||||
{
|
||||
edge = (edge + 2) & 3;
|
||||
if (!(tileElement->asPath()->GetEdges() & (1 << edge)))
|
||||
if (!(pathElement->GetEdges() & (1 << edge)))
|
||||
{
|
||||
edge = (edge - 1) & 3;
|
||||
if (!(tileElement->asPath()->GetEdges() & (1 << edge)))
|
||||
if (!(pathElement->GetEdges() & (1 << edge)))
|
||||
{
|
||||
edge = DirectionReverse(edge);
|
||||
}
|
||||
@@ -1569,7 +1570,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
}
|
||||
}
|
||||
|
||||
_footpathConstructFromPosition.z = tileElement->getBaseZ();
|
||||
_footpathConstructFromPosition.z = pathElement->getBaseZ();
|
||||
auto action = GameActions::FootpathRemoveAction(_footpathConstructFromPosition);
|
||||
GameActions::Execute(&action, getGameState());
|
||||
|
||||
@@ -1586,9 +1587,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
*
|
||||
* rct2: 0x006A7873
|
||||
*/
|
||||
TileElement* FootpathGetTileElementToRemove()
|
||||
PathElement* FootpathGetTileElementToRemove()
|
||||
{
|
||||
TileElement* tileElement;
|
||||
int32_t z, zLow;
|
||||
|
||||
if (!MapIsLocationValid(_footpathConstructFromPosition))
|
||||
@@ -1599,39 +1599,33 @@ namespace OpenRCT2::Ui::Windows
|
||||
z = std::min(255 * kCoordsZStep, _footpathConstructFromPosition.z);
|
||||
zLow = z - kPathHeightStep;
|
||||
|
||||
tileElement = MapGetFirstElementAt(_footpathConstructFromPosition);
|
||||
do
|
||||
for (auto* pathElement : TileElementsView<PathElement>(_footpathConstructFromPosition))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
if (tileElement->getType() == TileElementType::path)
|
||||
if (pathElement->getBaseZ() == z)
|
||||
{
|
||||
if (tileElement->getBaseZ() == z)
|
||||
if (pathElement->IsSloped())
|
||||
{
|
||||
if (tileElement->asPath()->IsSloped())
|
||||
if (DirectionReverse(pathElement->GetSlopeDirection()) != _footpathConstructDirection)
|
||||
{
|
||||
if (DirectionReverse(tileElement->asPath()->GetSlopeDirection()) != _footpathConstructDirection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
return tileElement;
|
||||
}
|
||||
if (tileElement->getBaseZ() == zLow)
|
||||
{
|
||||
if (!tileElement->asPath()->IsSloped())
|
||||
{
|
||||
if ((tileElement->asPath()->GetSlopeDirection()) == _footpathConstructDirection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return tileElement;
|
||||
}
|
||||
return pathElement;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
if (pathElement->getBaseZ() == zLow)
|
||||
{
|
||||
if (!pathElement->IsSloped())
|
||||
{
|
||||
if ((pathElement->GetSlopeDirection()) == _footpathConstructDirection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return pathElement;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1642,12 +1636,10 @@ namespace OpenRCT2::Ui::Windows
|
||||
*/
|
||||
void WindowFootpathRemove()
|
||||
{
|
||||
TileElement* tileElement;
|
||||
|
||||
_windowFootpathCost = kMoney64Undefined;
|
||||
FootpathUpdateProvisional();
|
||||
|
||||
tileElement = FootpathGetTileElementToRemove();
|
||||
auto* tileElement = FootpathGetTileElementToRemove();
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
FootpathRemoveTileElement(tileElement);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <openrct2/world/MapSelection.h>
|
||||
#include <openrct2/world/Park.h>
|
||||
#include <openrct2/world/Scenery.h>
|
||||
#include <openrct2/world/TileElementsView.h>
|
||||
#include <openrct2/world/TileInspector.h>
|
||||
#include <openrct2/world/tile_element/BannerElement.h>
|
||||
#include <openrct2/world/tile_element/EntranceElement.h>
|
||||
@@ -1615,13 +1616,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
int32_t i = 0;
|
||||
char buffer[256];
|
||||
|
||||
const TileElement* tileElement = MapGetFirstElementAt(_toolMap);
|
||||
|
||||
do
|
||||
for (const auto* tileElement : TileElementsView(_toolMap))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
const bool selectedRow = i == windowTileInspectorSelectedIndex;
|
||||
const bool hoveredRow = i == _highlightedIndex;
|
||||
const char* typeName = "";
|
||||
@@ -1751,7 +1747,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
screenCoords.y -= kScrollableRowHeight;
|
||||
i++;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
}
|
||||
|
||||
void ClearClipboard()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../../world/ConstructionClearance.h"
|
||||
#include "../../world/Map.h"
|
||||
#include "../../world/MapAnimation.h"
|
||||
#include "../../world/TileElementsView.h"
|
||||
#include "../../world/Wall.h"
|
||||
#include "../../world/tile_element/LargeSceneryElement.h"
|
||||
#include "../../world/tile_element/PathElement.h"
|
||||
@@ -504,8 +505,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
TileElement* tileElement = MapGetFirstElementAt(_loc);
|
||||
do
|
||||
for (auto* tileElement : TileElementsView(_loc))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
@@ -584,7 +584,7 @@ namespace OpenRCT2::GameActions
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
return Result();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../../management/Finance.h"
|
||||
#include "../../world/Location.hpp"
|
||||
#include "../../world/Map.h"
|
||||
#include "../../world/TileElementsView.h"
|
||||
#include "../../world/tile_element/LargeSceneryElement.h"
|
||||
#include "../../world/tile_element/SmallSceneryElement.h"
|
||||
#include "../GameActionRunner.h"
|
||||
@@ -239,16 +240,10 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
for (int32_t x = 0; x < gameState.mapSize.x; x++)
|
||||
{
|
||||
auto tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
|
||||
do
|
||||
for (auto* sceneryElement : TileElementsView<LargeSceneryElement>(TileCoordsXY{ x, y }))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
if (tileElement->getType() == TileElementType::largeScenery)
|
||||
{
|
||||
tileElement->asLargeScenery()->SetIsAccounted(false);
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
sceneryElement->SetIsAccounted(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,19 +250,14 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
void LandSetHeightAction::SmallSceneryRemoval() const
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(_coords);
|
||||
do
|
||||
for (auto* sceneryElement : TileElementsView<SmallSceneryElement>(_coords))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
if (tileElement->getType() != TileElementType::smallScenery)
|
||||
if (_height > sceneryElement->clearanceHeight)
|
||||
continue;
|
||||
if (_height > tileElement->clearanceHeight)
|
||||
if (_height + 4 < sceneryElement->baseHeight)
|
||||
continue;
|
||||
if (_height + 4 < tileElement->baseHeight)
|
||||
continue;
|
||||
TileElementRemove(tileElement--);
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
TileElementRemove(reinterpret_cast<TileElement*>(sceneryElement));
|
||||
}
|
||||
}
|
||||
|
||||
StringId LandSetHeightAction::CheckRideSupports() const
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "../../ride/ted/TrackElementDescriptor.h"
|
||||
#include "../../world/Footpath.h"
|
||||
#include "../../world/Map.h"
|
||||
#include "../../world/TileElementsView.h"
|
||||
#include "../../world/tile_element/SurfaceElement.h"
|
||||
#include "../../world/tile_element/TrackElement.h"
|
||||
#include "../GameActionRunner.h"
|
||||
@@ -78,40 +79,33 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
bool found = false;
|
||||
TrackElement* foundElement = nullptr;
|
||||
bool isGhost = GetFlags().has(CommandFlag::ghost);
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(_origin))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->getBaseZ() != _origin.z)
|
||||
if (trackElement->getBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
if ((trackElement->getDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if ((tileElement->getDirection()) != _origin.direction)
|
||||
if (trackElement->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetSequenceIndex() != _sequence)
|
||||
if (trackElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
if (tileElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->asTrack()->GetTrackType());
|
||||
auto tileTrackType = normaliseTrackType(trackElement->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
foundElement = trackElement;
|
||||
break;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
if (!found)
|
||||
if (foundElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
@@ -119,14 +113,14 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (tileElement->asTrack()->IsIndestructible())
|
||||
if (foundElement->IsIndestructible())
|
||||
{
|
||||
return Result(
|
||||
Status::disallowed, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_YOU_ARE_NOT_ALLOWED_TO_REMOVE_THIS_SECTION);
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->asTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->asTrack()->GetTrackType();
|
||||
RideId rideIndex = foundElement->GetRideIndex();
|
||||
const auto trackType = foundElement->GetTrackType();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
@@ -141,7 +135,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->asTrack()->GetSequenceIndex();
|
||||
auto sequenceIndex = foundElement->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.sequenceData.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
@@ -150,7 +144,7 @@ namespace OpenRCT2::GameActions
|
||||
const auto& currentTrackBlock = ted.sequenceData.sequences[sequenceIndex].clearance;
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->getDirection();
|
||||
startLoc.direction = foundElement->getDirection();
|
||||
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
currentTrackBlock.z };
|
||||
@@ -175,36 +169,29 @@ namespace OpenRCT2::GameActions
|
||||
}
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
foundElement = nullptr;
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(mapLoc))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->getBaseZ() != mapLoc.z)
|
||||
if (trackElement->getBaseZ() != mapLoc.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
if (trackElement->getDirection() != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->getDirection() != _origin.direction)
|
||||
if (trackElement->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetSequenceIndex() != i)
|
||||
if (trackElement->GetTrackType() != trackType)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetTrackType() != trackType)
|
||||
if (trackElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
if (tileElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
foundElement = trackElement;
|
||||
break;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
if (!found)
|
||||
if (foundElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
@@ -212,8 +199,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (ted.sequenceData.sequences[0].flags.has(SequenceFlag::trackOrigin)
|
||||
&& (tileElement->asTrack()->GetSequenceIndex() == 0))
|
||||
if (ted.sequenceData.sequences[0].flags.has(SequenceFlag::trackOrigin) && (foundElement->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, {});
|
||||
if (!removeElementResult.Successful)
|
||||
@@ -229,7 +215,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->baseHeight - surfaceElement->baseHeight;
|
||||
int16_t _support_height = foundElement->baseHeight - surfaceElement->baseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
@@ -262,40 +248,33 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
bool found = false;
|
||||
TrackElement* foundElement = nullptr;
|
||||
bool isGhost = GetFlags().has(CommandFlag::ghost);
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(_origin))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->getBaseZ() != _origin.z)
|
||||
if (trackElement->getBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
if ((trackElement->getDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if ((tileElement->getDirection()) != _origin.direction)
|
||||
if (trackElement->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetSequenceIndex() != _sequence)
|
||||
if (trackElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
if (tileElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->asTrack()->GetTrackType());
|
||||
auto tileTrackType = normaliseTrackType(trackElement->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
foundElement = trackElement;
|
||||
break;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
if (!found)
|
||||
if (foundElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
@@ -303,9 +282,9 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->asTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->asTrack()->GetTrackType();
|
||||
bool isLiftHill = tileElement->asTrack()->HasChain();
|
||||
RideId rideIndex = foundElement->GetRideIndex();
|
||||
const auto trackType = foundElement->GetTrackType();
|
||||
bool isLiftHill = foundElement->HasChain();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
@@ -314,7 +293,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->asTrack()->GetSequenceIndex();
|
||||
auto sequenceIndex = foundElement->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.sequenceData.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
@@ -322,7 +301,7 @@ namespace OpenRCT2::GameActions
|
||||
}
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->getDirection();
|
||||
startLoc.direction = foundElement->getDirection();
|
||||
|
||||
const auto& currentTrackBlock = ted.sequenceData.sequences[sequenceIndex].clearance;
|
||||
auto rotatedTrackLoc = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
@@ -345,36 +324,29 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
foundElement = nullptr;
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(mapLoc))
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->getBaseZ() != mapLoc.z)
|
||||
if (trackElement->getBaseZ() != mapLoc.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
if (trackElement->getDirection() != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->getDirection() != _origin.direction)
|
||||
if (trackElement->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetSequenceIndex() != i)
|
||||
if (trackElement->GetTrackType() != trackType)
|
||||
continue;
|
||||
|
||||
if (tileElement->asTrack()->GetTrackType() != trackType)
|
||||
if (trackElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
if (tileElement->isGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
foundElement = trackElement;
|
||||
break;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
if (!found)
|
||||
if (foundElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
@@ -382,8 +354,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (ted.sequenceData.sequences[0].flags.has(SequenceFlag::trackOrigin)
|
||||
&& (tileElement->asTrack()->GetSequenceIndex() == 0))
|
||||
if (ted.sequenceData.sequences[0].flags.has(SequenceFlag::trackOrigin) && (foundElement->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, {});
|
||||
if (!removeElementResult.Successful)
|
||||
@@ -399,7 +370,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->baseHeight - surfaceElement->baseHeight;
|
||||
int16_t _support_height = foundElement->baseHeight - surfaceElement->baseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
@@ -411,7 +382,7 @@ namespace OpenRCT2::GameActions
|
||||
// Don't do this if the ride is simulating and the tile is a ghost to prevent desyncs.
|
||||
if (ted.sequenceData.sequences[0].flags.has(SequenceFlag::trackOrigin)
|
||||
&& (!GetFlags().has(CommandFlag::ghost) || (GetFlags().has(CommandFlag::trackDesign)))
|
||||
&& (tileElement->asTrack()->GetSequenceIndex() == 0))
|
||||
&& (foundElement->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement(
|
||||
{ mapLoc, _origin.direction }, rideIndex, { CommandFlag::apply });
|
||||
@@ -428,11 +399,11 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
InvalidateTestResults(*ride);
|
||||
FootpathQueueChainReset();
|
||||
if (!gameState.cheats.disableClearanceChecks || !(tileElement->isGhost()))
|
||||
if (!gameState.cheats.disableClearanceChecks || !(foundElement->isGhost()))
|
||||
{
|
||||
FootpathRemoveEdgesAt(mapLoc, tileElement);
|
||||
FootpathRemoveEdgesAt(mapLoc, reinterpret_cast<TileElement*>(foundElement));
|
||||
}
|
||||
TileElementRemove(tileElement);
|
||||
TileElementRemove(reinterpret_cast<TileElement*>(foundElement));
|
||||
ride->validateStations();
|
||||
if (!GetFlags().has(CommandFlag::ghost))
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "../ride/RideData.h"
|
||||
#include "../scenario/Scenario.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/tile_element/TrackElement.h"
|
||||
#include "EntityRegistry.h"
|
||||
|
||||
@@ -126,10 +127,7 @@ namespace OpenRCT2
|
||||
|
||||
bool Balloon::Collides() const
|
||||
{
|
||||
const TileElement* tileElement = MapGetFirstElementAt(CoordsXY({ x, y }));
|
||||
if (tileElement == nullptr)
|
||||
return false;
|
||||
do
|
||||
for (auto* tileElement : TileElementsView(CoordsXY(x, y)))
|
||||
{
|
||||
// the balloon has height so we add some padding to prevent it clipping through things.
|
||||
int32_t balloon_top = z + kCoordsZStep * 2;
|
||||
@@ -161,8 +159,7 @@ namespace OpenRCT2
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
@@ -5033,10 +5033,7 @@ namespace OpenRCT2
|
||||
};
|
||||
maze_type mazeType = maze_type::invalid;
|
||||
|
||||
auto tileElement = MapGetFirstElementAt(targetLoc);
|
||||
if (tileElement == nullptr)
|
||||
return;
|
||||
do
|
||||
for (auto* tileElement : TileElementsView(targetLoc))
|
||||
{
|
||||
if (stationBaseZ != tileElement->getBaseZ())
|
||||
continue;
|
||||
@@ -5053,7 +5050,7 @@ namespace OpenRCT2
|
||||
mazeType = maze_type::entrance_or_exit;
|
||||
break;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
switch (mazeType)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "../platform/Platform.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/Park.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/Weather.h"
|
||||
#include "../world/tile_element/SurfaceElement.h"
|
||||
#include "Viewport.h"
|
||||
@@ -194,19 +195,17 @@ std::string ScreenshotDumpPNG(RenderTarget& rt)
|
||||
static int32_t GetHighestBaseClearanceZ(const CoordsXY& location, const bool useViewClipping)
|
||||
{
|
||||
int32_t z = 0;
|
||||
auto element = MapGetFirstElementAt(location);
|
||||
if (element != nullptr)
|
||||
|
||||
for (const auto* tileElement : TileElementsView(location))
|
||||
{
|
||||
do
|
||||
if (useViewClipping && (tileElement->getBaseZ() > gClipHeight * kCoordsZStep))
|
||||
{
|
||||
if (useViewClipping && (element->getBaseZ() > gClipHeight * kCoordsZStep))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
z = std::max<int32_t>(z, element->getBaseZ());
|
||||
z = std::max<int32_t>(z, element->getClearanceZ());
|
||||
} while (!(element++)->isLastForTile());
|
||||
continue;
|
||||
}
|
||||
z = std::max<int32_t>(z, tileElement->getBaseZ());
|
||||
z = std::max<int32_t>(z, tileElement->getClearanceZ());
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../../../ride/RideData.h"
|
||||
#include "../../../ride/TrackPaint.h"
|
||||
#include "../../../world/Map.h"
|
||||
#include "../../../world/TileElementsView.h"
|
||||
#include "../../../world/tile_element/TileElement.h"
|
||||
#include "../../../world/tile_element/TrackElement.h"
|
||||
#include "../../Paint.h"
|
||||
@@ -126,24 +127,16 @@ static void ChairliftPaintUtilDrawSupports(PaintSession& session, int32_t segmen
|
||||
static const TrackElement* ChairliftPaintUtilMapGetTrackElementAtFromRideFuzzy(
|
||||
int32_t x, int32_t y, int32_t z, const Ride& ride)
|
||||
{
|
||||
const TileElement* tileElement = MapGetFirstElementAt(CoordsXY{ x, y });
|
||||
if (tileElement == nullptr)
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(CoordsXY(x, y)))
|
||||
{
|
||||
return nullptr;
|
||||
if (trackElement->GetRideIndex() != ride.id)
|
||||
continue;
|
||||
if (trackElement->baseHeight != z && trackElement->baseHeight != z - 1)
|
||||
continue;
|
||||
|
||||
return trackElement;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
continue;
|
||||
if (tileElement->GetRideIndex() != ride.id)
|
||||
continue;
|
||||
if (tileElement->baseHeight != z && tileElement->baseHeight != z - 1)
|
||||
continue;
|
||||
|
||||
return tileElement->asTrack();
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "../world/Map.h"
|
||||
#include "../world/Park.h"
|
||||
#include "../world/Scenery.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/Weather.h"
|
||||
#include "../world/tile_element/PathElement.h"
|
||||
#include "../world/tile_element/SmallSceneryElement.h"
|
||||
@@ -1279,22 +1280,14 @@ namespace OpenRCT2
|
||||
{
|
||||
for (int32_t x = 0; x < gameState.mapSize.x; x++)
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
|
||||
if (tileElement == nullptr)
|
||||
continue;
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(TileCoordsXY{ x, y }))
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
continue;
|
||||
|
||||
auto* trackElement = tileElement->asTrack();
|
||||
const auto* ride = GetRide(trackElement->GetRideIndex());
|
||||
if (ride != nullptr)
|
||||
{
|
||||
trackElement->SetRideType(ride->type);
|
||||
}
|
||||
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../world/Entrance.h"
|
||||
#include "../world/Footpath.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/Wall.h"
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
#include "../world/tile_element/EntranceElement.h"
|
||||
@@ -398,19 +399,13 @@ namespace OpenRCT2::PathFinding
|
||||
static PathSearchResult FootpathElementDestInDir(
|
||||
bool ignoreBanners, TileCoordsXYZ loc, Direction chosenDirection, RideId* outRideIndex, int32_t level)
|
||||
{
|
||||
TileElement* tileElement;
|
||||
Direction direction;
|
||||
|
||||
if (level > 25)
|
||||
return PathSearchResult::LimitReached;
|
||||
|
||||
loc += TileDirectionDelta[chosenDirection];
|
||||
tileElement = MapGetFirstElementAt(loc);
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
return PathSearchResult::Failed;
|
||||
}
|
||||
do
|
||||
for (auto* tileElement : TileElementsView(loc))
|
||||
{
|
||||
if (tileElement->isGhost())
|
||||
continue;
|
||||
@@ -490,7 +485,7 @@ namespace OpenRCT2::PathFinding
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
return PathSearchResult::Failed;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include "../world/MapAnimation.h"
|
||||
#include "../world/Park.h"
|
||||
#include "../world/Scenery.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/TilePointerIndex.hpp"
|
||||
#include "../world/Wall.h"
|
||||
#include "../world/Weather.h"
|
||||
@@ -2657,37 +2658,31 @@ namespace OpenRCT2::RCT1
|
||||
{
|
||||
for (int32_t y = 0; y < Limits::kMaxMapSize; y++)
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(TileCoordsXY{ x, y });
|
||||
if (tileElement == nullptr)
|
||||
continue;
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(TileCoordsXY(x, y)))
|
||||
{
|
||||
if (tileElement->getType() == TileElementType::track)
|
||||
// Lift hill tops are the only pieces present in RCT1 that can count as a block brake.
|
||||
if (!trackElement->HasChain())
|
||||
continue;
|
||||
|
||||
auto trackType = trackElement->GetTrackType();
|
||||
switch (trackType)
|
||||
{
|
||||
// Lift hill tops are the only pieces present in RCT1 that can count as a block brake.
|
||||
if (!tileElement->asTrack()->HasChain())
|
||||
case TrackElemType::up25ToFlat:
|
||||
case TrackElemType::up60ToFlat:
|
||||
case TrackElemType::diagUp25ToFlat:
|
||||
case TrackElemType::diagUp60ToFlat:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
|
||||
auto trackType = tileElement->asTrack()->GetTrackType();
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackElemType::up25ToFlat:
|
||||
case TrackElemType::up60ToFlat:
|
||||
case TrackElemType::diagUp25ToFlat:
|
||||
case TrackElemType::diagUp60ToFlat:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->asTrack()->GetRideIndex();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride != nullptr)
|
||||
{
|
||||
ride->numBlockBrakes++;
|
||||
}
|
||||
}
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
|
||||
RideId rideIndex = trackElement->GetRideIndex();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride != nullptr)
|
||||
{
|
||||
ride->numBlockBrakes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "../world/Footpath.h"
|
||||
#include "../world/Location.hpp"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/tile_element/EntranceElement.h"
|
||||
#include "../world/tile_element/PathElement.h"
|
||||
#include "../world/tile_element/Slope.h"
|
||||
@@ -341,21 +342,13 @@ static void ApplyTrackTypeFixes(const json_t& trackTilesFixes)
|
||||
|
||||
for (const auto& tile : coordinatesVector)
|
||||
{
|
||||
auto* tileElement = MapGetFirstElementAt(tile);
|
||||
if (tileElement == nullptr)
|
||||
continue;
|
||||
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(tile))
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
continue;
|
||||
|
||||
auto* trackElement = tileElement->asTrack();
|
||||
if (trackElement->GetTrackType() != fromTrackType)
|
||||
continue;
|
||||
|
||||
trackElement->SetTrackType(destinationTrackType);
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "../world/MapAnimation.h"
|
||||
#include "../world/Park.h"
|
||||
#include "../world/Scenery.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
#include "../world/TilePointerIndex.hpp"
|
||||
#include "../world/Weather.h"
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
@@ -1032,22 +1033,17 @@ namespace OpenRCT2::RCT2
|
||||
{
|
||||
const CoordsXYZ coords{ mapAnimation.x, mapAnimation.y, mapAnimation.BaseZ * kCoordsZStep };
|
||||
const TileCoordsXYZ tileCoords{ coords };
|
||||
TileElement* tileElement = MapGetFirstElementAt(tileCoords);
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
do
|
||||
for (auto* wallElement : TileElementsView<WallElement>(tileCoords))
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::wall || tileElement->baseHeight != tileCoords.z)
|
||||
if (wallElement->baseHeight != tileCoords.z)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
tileElement->asWall()->SetIsAnimating(true);
|
||||
wallElement->SetIsAnimating(true);
|
||||
MapAnimations::MarkTileForUpdate(tileCoords);
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,25 +104,19 @@ void Banner::formatTextTo(Formatter& ft) const
|
||||
*/
|
||||
static RideId BannerGetRideIndexAt(const CoordsXYZ& bannerCoords)
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(bannerCoords);
|
||||
RideId resultRideIndex = RideId::GetNull();
|
||||
if (tileElement == nullptr)
|
||||
return resultRideIndex;
|
||||
do
|
||||
for (auto* trackElement : TileElementsView<TrackElement>(bannerCoords))
|
||||
{
|
||||
if (tileElement->getType() != TileElementType::track)
|
||||
continue;
|
||||
|
||||
RideId rideIndex = tileElement->asTrack()->GetRideIndex();
|
||||
RideId rideIndex = trackElement->GetRideIndex();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr || ride->getRideTypeDescriptor().flags.has(RtdFlag::isShopOrFacility))
|
||||
continue;
|
||||
|
||||
if ((tileElement->getClearanceZ()) + (4 * kCoordsZStep) <= bannerCoords.z)
|
||||
if ((trackElement->getClearanceZ()) + (4 * kCoordsZStep) <= bannerCoords.z)
|
||||
continue;
|
||||
|
||||
resultRideIndex = rideIndex;
|
||||
} while (!(tileElement++)->isLastForTile());
|
||||
}
|
||||
|
||||
return resultRideIndex;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user