Files
OpenRCT2-Web/src/openrct2/world/TileInspector.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

978 lines
40 KiB
C++
Raw Normal View History

/*****************************************************************************
2026-01-05 14:42:59 +01:00
* Copyright (c) 2014-2026 OpenRCT2 developers
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 23:17:03 +02:00
#include "TileInspector.h"
2024-07-09 16:23:31 +02:00
#include "../Diagnostic.h"
2026-02-09 15:07:42 +01:00
#include "../actions/GameAction.hpp"
2026-01-06 21:03:31 +01:00
#include "../core/Guard.hpp"
2023-01-26 18:44:42 +00:00
#include "../object/LargeSceneryEntry.h"
2018-06-22 23:17:03 +02:00
#include "../ride/Station.h"
2021-02-08 21:28:41 +01:00
#include "../ride/TrackData.h"
#include "../ride/ted/TrackElementDescriptor.h"
#include "../ui/WindowManager.h"
2023-01-17 20:46:55 +01:00
#include "../windows/TileInspectorGlobals.h"
2018-06-22 23:17:03 +02:00
#include "Banner.h"
2018-01-11 10:59:26 +01:00
#include "Footpath.h"
#include "Location.hpp"
#include "Map.h"
#include "MapAnimation.h"
2018-06-22 23:17:03 +02:00
#include "Park.h"
#include "Scenery.h"
#include "tile_element/BannerElement.h"
2024-10-03 12:42:53 +02:00
#include "tile_element/EntranceElement.h"
2024-10-15 22:02:31 +02:00
#include "tile_element/LargeSceneryElement.h"
#include "tile_element/PathElement.h"
2024-05-02 23:31:01 +02:00
#include "tile_element/Slope.h"
2024-10-15 22:02:31 +02:00
#include "tile_element/SmallSceneryElement.h"
#include "tile_element/SurfaceElement.h"
#include "tile_element/TrackElement.h"
#include "tile_element/WallElement.h"
2021-02-19 18:28:09 +02:00
#include <optional>
2021-02-19 18:17:04 +02:00
TileCoordsXY windowTileInspectorTile;
int32_t windowTileInspectorElementCount = 0;
int32_t windowTileInspectorSelectedIndex = -1;
2017-11-23 00:42:12 +01:00
2026-02-28 18:02:27 +01:00
using namespace OpenRCT2::TrackMetadata;
namespace OpenRCT2::TileInspector
{
2024-02-19 15:58:04 -08:00
static GameActions::Result SwapTileElements(const CoordsXY& loc, int16_t first, int16_t second)
2017-11-20 11:37:15 +01:00
{
TileElement* const firstElement = MapGetNthElementAt(loc, first);
TileElement* const secondElement = MapGetNthElementAt(loc, second);
if (firstElement == nullptr)
2017-06-06 23:24:18 +02:00
{
LOG_ERROR("First element is out of range for the tile");
2024-02-19 15:58:04 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
}
if (secondElement == nullptr)
{
LOG_ERROR("Second element is out of range for the tile");
2024-02-19 15:58:04 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
}
if (firstElement == secondElement)
{
LOG_ERROR("Can't swap the element with itself");
2024-02-19 15:58:04 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_CANT_SWAP_TILE_ELEMENT_WITH_ITSELF);
2017-06-06 23:24:18 +02:00
}
// Swap their memory
2021-02-19 18:17:04 +02:00
std::swap(*firstElement, *secondElement);
// Swap the 'last map element for tile' flag if either one of them was last
2026-05-17 15:21:16 +02:00
if ((firstElement)->isLastForTile() || (secondElement)->isLastForTile())
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
firstElement->setLastForTile(!firstElement->isLastForTile());
secondElement->setLastForTile(!secondElement->isLastForTile());
}
2024-02-19 15:58:04 -08:00
return GameActions::Result();
}
static bool IsTileSelected(const CoordsXY& loc)
2021-02-19 18:28:09 +02:00
{
// Return true for everyone who has the window open and tile selected
auto* windowMgr = Ui::GetWindowManager();
auto* window = windowMgr->FindByClass(WindowClass::tileInspector);
return window != nullptr && loc == windowTileInspectorTile.ToCoordsXY();
2021-02-19 18:28:09 +02:00
}
static int32_t NumLargeScenerySequences(const CoordsXY& loc, const LargeSceneryElement* const largeScenery)
{
const auto* const largeEntry = largeScenery->GetEntry();
2026-05-17 15:21:16 +02:00
const auto direction = largeScenery->getDirection();
2021-02-21 19:13:58 +02:00
const auto sequenceIndex = largeScenery->GetSequenceIndex();
2024-10-16 22:35:29 +01:00
const auto& tiles = largeEntry->tiles;
const auto& initialTile = tiles[sequenceIndex];
2021-02-21 19:13:58 +02:00
const auto rotatedFirstTile = CoordsXYZ{
2024-10-16 22:35:29 +01:00
CoordsXY{ initialTile.offset }.Rotate(direction),
initialTile.offset.z,
2021-02-21 19:13:58 +02:00
};
2026-05-17 15:21:16 +02:00
const auto firstTile = CoordsXYZ{ loc, largeScenery->getBaseZ() } - rotatedFirstTile;
auto numFoundElements = 0;
2024-10-16 22:35:29 +01:00
for (auto& tile : tiles)
2017-06-06 23:24:18 +02:00
{
2024-10-16 22:35:29 +01:00
const auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(direction), tile.offset.z };
const auto currentTile = firstTile + rotatedCurrentTile;
const TileElement* tileElement = MapGetFirstElementAt(currentTile);
if (tileElement != nullptr)
2017-06-06 23:24:18 +02:00
{
do
{
2026-05-17 15:21:16 +02:00
if (tileElement->getType() != TileElementType::LargeScenery)
continue;
2026-05-17 15:21:16 +02:00
if (tileElement->getDirection() != direction)
continue;
2026-05-17 15:21:16 +02:00
if (tileElement->asLargeScenery()->GetSequenceIndex() != tile.index)
continue;
2026-05-17 15:21:16 +02:00
if (tileElement->getBaseZ() != currentTile.z)
continue;
numFoundElements++;
break;
2026-05-17 15:21:16 +02:00
} while (!(tileElement++)->isLastForTile());
}
}
return numFoundElements;
}
/**
* Forcefully removes an element for a given tile
* @param x The x coordinate of the tile
* @param y The y coordinate of the tile
* @param elementIndex The nth element on this tile
*/
GameActions::Result RemoveElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting)
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
if (tileElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
if (isExecuting)
{
// Forcefully remove the element
2026-05-17 15:21:16 +02:00
auto largeScenery = tileElement->asLargeScenery();
2021-09-24 20:05:50 +02:00
if (largeScenery != nullptr)
{
// Only delete the banner entry if there are no other parts of the large scenery to delete
if (NumLargeScenerySequences(loc, largeScenery) == 1)
{
tileElement->RemoveBannerEntry();
}
}
else
{
// Removes any potential banners from the entry
tileElement->RemoveBannerEntry();
}
2022-10-12 06:35:20 +01:00
TileElementRemove(tileElement);
2017-01-23 17:08:16 +01:00
if (IsTileSelected(loc))
2017-06-06 23:24:18 +02:00
{
// Update the window
windowTileInspectorElementCount--;
2021-02-19 18:28:09 +02:00
if (windowTileInspectorSelectedIndex >= elementIndex)
{
windowTileInspectorSelectedIndex--;
}
}
}
return GameActions::Result();
}
GameActions::Result SwapElementsAt(const CoordsXY& loc, int16_t first, int16_t second, bool isExecuting)
{
if (isExecuting)
{
2024-02-19 15:58:04 -08:00
auto res = SwapTileElements(loc, first, second);
2025-12-12 12:11:49 +01:00
if (res.error != GameActions::Status::ok)
{
2024-02-19 15:58:04 -08:00
return res;
}
if (IsTileSelected(loc))
{
// If one of them was selected, update selected list item
if (windowTileInspectorSelectedIndex == first)
windowTileInspectorSelectedIndex = second;
else if (windowTileInspectorSelectedIndex == second)
windowTileInspectorSelectedIndex = first;
}
}
return GameActions::Result();
}
GameActions::Result RotateElementAt(const CoordsXY& loc, int32_t elementIndex, bool isExecuting)
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
if (tileElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
if (isExecuting)
{
uint8_t newRotation, pathEdges, pathCorners;
2026-05-17 15:21:16 +02:00
switch (tileElement->getType())
{
2021-12-11 00:39:39 +01:00
case TileElementType::Path:
2026-05-17 15:21:16 +02:00
if (tileElement->asPath()->IsSloped())
{
2026-05-17 15:21:16 +02:00
newRotation = (tileElement->asPath()->GetSlopeDirection() + 1) & kTileElementDirectionMask;
tileElement->asPath()->SetSlopeDirection(newRotation);
}
2026-05-17 15:21:16 +02:00
pathEdges = tileElement->asPath()->GetEdges();
pathCorners = tileElement->asPath()->GetCorners();
tileElement->asPath()->SetEdges((pathEdges << 1) | (pathEdges >> 3));
tileElement->asPath()->SetCorners((pathCorners << 1) | (pathCorners >> 3));
break;
2021-12-11 00:39:39 +01:00
case TileElementType::Entrance:
{
// Update element rotation
2026-05-17 15:21:16 +02:00
newRotation = tileElement->getDirectionWithOffset(1);
tileElement->setDirection(newRotation);
// Update ride's known entrance/exit rotation
2026-05-17 15:21:16 +02:00
auto ride = GetRide(tileElement->asEntrance()->GetRideIndex());
if (ride != nullptr)
{
2026-05-17 15:21:16 +02:00
auto stationIndex = tileElement->asEntrance()->GetStationIndex();
2025-03-09 00:26:25 +01:00
auto& station = ride->getStation(stationIndex);
2022-01-28 15:57:28 +01:00
auto entrance = station.Entrance;
auto exit = station.Exit;
2026-05-17 15:21:16 +02:00
uint8_t entranceType = tileElement->asEntrance()->GetEntranceType();
uint8_t z = tileElement->baseHeight;
// Make sure this is the correct entrance or exit
2024-07-26 18:23:25 +10:00
if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entrance.x == loc.x / kCoordsXYStep
&& entrance.y == loc.y / kCoordsXYStep && entrance.z == z)
{
station.Entrance = { entrance, newRotation };
}
else if (
2024-07-26 18:23:25 +10:00
entranceType == ENTRANCE_TYPE_RIDE_EXIT && exit.x == loc.x / kCoordsXYStep
&& exit.y == loc.y / kCoordsXYStep && exit.z == z)
{
station.Exit = { exit, newRotation };
}
}
break;
}
2021-12-11 00:39:39 +01:00
case TileElementType::Track:
case TileElementType::SmallScenery:
case TileElementType::Wall:
2026-05-17 15:21:16 +02:00
newRotation = tileElement->getDirectionWithOffset(1);
tileElement->setDirection(newRotation);
break;
2021-12-11 00:39:39 +01:00
case TileElementType::Banner:
{
2026-05-17 15:21:16 +02:00
uint8_t unblockedEdges = tileElement->asBanner()->GetAllowedEdges();
unblockedEdges = (unblockedEdges << 1 | unblockedEdges >> 3) & 0xF;
2026-05-17 15:21:16 +02:00
tileElement->asBanner()->SetAllowedEdges(unblockedEdges);
tileElement->asBanner()->SetPosition((tileElement->asBanner()->GetPosition() + 1) & 3);
break;
}
2021-12-11 00:39:39 +01:00
case TileElementType::Surface:
case TileElementType::LargeScenery:
break;
}
}
return GameActions::Result();
}
GameActions::Result ToggleInvisibilityOfElementAt(const CoordsXY& loc, int32_t elementIndex, bool isExecuting)
2021-10-27 14:21:14 +02:00
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
if (tileElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
2021-10-27 14:21:14 +02:00
if (!isExecuting)
{
return GameActions::Result();
2021-10-27 14:21:14 +02:00
}
2026-05-17 15:21:16 +02:00
bool currentlyInvisible = tileElement->isInvisible();
tileElement->setInvisible(!currentlyInvisible);
2021-10-27 14:21:14 +02:00
return GameActions::Result();
2021-10-27 14:21:14 +02:00
}
GameActions::Result PasteElementAt(const CoordsXY& loc, TileElement element, Banner banner, bool isExecuting)
{
// Make sure there is enough space for the new element
if (!MapCheckCapacityAndReorganise(loc))
{
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::noFreeElements, STR_CANT_PASTE, STR_TILE_ELEMENT_LIMIT_REACHED);
}
auto tileLoc = TileCoordsXY(loc);
if (isExecuting)
{
// Check if the element to be pasted has a banner
if (element.GetBannerIndex() != BannerIndex::GetNull())
{
// The element to be pasted has a banner - make a copy of it from the banner provided
2021-07-27 10:25:58 +01:00
auto newBanner = CreateBanner();
if (newBanner == nullptr)
{
LOG_ERROR("No free banners available");
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::unknown, STR_TOO_MANY_BANNERS_IN_GAME, kStringIdNone);
}
auto newId = newBanner->id;
// Copy the banners style
*newBanner = banner;
// Reset the location to the paste location
2021-07-27 10:25:58 +01:00
newBanner->position = tileLoc;
newBanner->id = newId;
// If the linked ride has been destroyed since copying, unlink the pasted banner
2025-05-20 23:36:51 +02:00
if (newBanner->flags.has(BannerFlag::linkedToRide) && GetRide(newBanner->rideIndex) == nullptr)
{
2025-05-20 23:28:40 +02:00
newBanner->flags.unset(BannerFlag::linkedToRide);
2025-05-20 23:36:51 +02:00
newBanner->rideIndex = RideId::GetNull();
}
// Use the new banner index
2021-07-27 10:25:58 +01:00
element.SetBannerIndex(newBanner->id);
}
// The occupiedQuadrants will be automatically set when the element is copied over, so it's not necessary to set
// them correctly _here_.
2026-05-17 15:21:16 +02:00
TileElement* const pastedElement = TileElementInsert({ loc, element.getBaseZ() }, 0b0000, TileElementType::Surface);
2026-05-17 15:21:16 +02:00
bool lastForTile = pastedElement->isLastForTile();
*pastedElement = element;
2026-05-17 15:21:16 +02:00
pastedElement->setLastForTile(lastForTile);
MapAnimations::MarkTileForUpdate(tileLoc);
if (IsTileSelected(loc))
{
windowTileInspectorElementCount++;
// Select new element if there was none selected already
int16_t newIndex = static_cast<int16_t>((pastedElement - MapGetFirstElementAt(loc)));
if (windowTileInspectorSelectedIndex == -1)
windowTileInspectorSelectedIndex = newIndex;
else if (windowTileInspectorSelectedIndex >= newIndex)
windowTileInspectorSelectedIndex++;
}
}
return GameActions::Result();
}
GameActions::Result SortElementsAt(const CoordsXY& loc, bool isExecuting)
{
if (isExecuting)
{
const TileElement* const firstElement = MapGetFirstElementAt(loc);
if (firstElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
// Count elements on tile
int32_t numElement = 0;
const TileElement* elementIterator = firstElement;
do
{
numElement++;
2026-05-17 15:21:16 +02:00
} while (!(elementIterator++)->isLastForTile());
// Bubble sort
for (int32_t loopStart = 1; loopStart < numElement; loopStart++)
{
int32_t currentId = loopStart;
const TileElement* currentElement = firstElement + currentId;
const TileElement* otherElement = currentElement - 1;
// While current element's base height is lower, or (when their baseheight is the same) the other map element's
// clearance height is lower...
while (currentId > 0
2026-05-17 15:21:16 +02:00
&& (otherElement->baseHeight > currentElement->baseHeight
|| (otherElement->baseHeight == currentElement->baseHeight
&& otherElement->clearanceHeight > currentElement->clearanceHeight)))
{
2024-02-19 15:58:04 -08:00
auto res = SwapTileElements(loc, currentId - 1, currentId);
2025-12-12 12:11:49 +01:00
if (res.error != GameActions::Status::ok)
{
// don't return error here, we've already ran some actions
// and moved things as far as we could, the only sensible
// thing left to do is to invalidate the window.
loopStart = numElement;
break;
}
currentId--;
currentElement--;
otherElement--;
}
}
if (IsTileSelected(loc))
{
// Deselect tile for clients who had it selected
windowTileInspectorSelectedIndex = -1;
}
2017-06-06 23:24:18 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
2017-01-23 17:08:16 +01:00
static GameActions::Result ValidateTileHeight(TileElement* const tileElement, int8_t heightOffset)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
int16_t newBaseHeight = static_cast<int16_t>(tileElement->baseHeight + heightOffset);
int16_t newClearanceHeight = static_cast<int16_t>(tileElement->clearanceHeight + heightOffset);
if (newBaseHeight < 0)
2017-11-20 11:37:15 +01:00
{
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::tooLow, STR_CANT_LOWER_ELEMENT_HERE, STR_TOO_LOW);
2017-06-06 23:24:18 +02:00
}
2024-10-15 22:02:31 +02:00
if (newBaseHeight > kMaxTileElementHeight)
2017-06-06 23:24:18 +02:00
{
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::tooHigh, STR_CANT_RAISE_ELEMENT_HERE, STR_TOO_HIGH);
2017-06-06 23:24:18 +02:00
}
2021-09-15 22:22:15 +02:00
if (newClearanceHeight < 0)
{
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::noClearance, STR_CANT_LOWER_ELEMENT_HERE, STR_NO_CLEARANCE);
}
2024-10-15 22:02:31 +02:00
if (newClearanceHeight > kMaxTileElementHeight)
{
2025-12-12 11:41:49 +01:00
return GameActions::Result(GameActions::Status::noClearance, STR_CANT_RAISE_ELEMENT_HERE, STR_NO_CLEARANCE);
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
2017-01-23 21:04:28 +01:00
GameActions::Result AnyBaseHeightOffset(const CoordsXY& loc, int16_t elementIndex, int8_t heightOffset, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
if (tileElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
2017-01-25 13:42:04 +01:00
auto heightValidationResult = ValidateTileHeight(tileElement, heightOffset);
2025-12-12 12:11:49 +01:00
if (heightValidationResult.error != GameActions::Status::ok)
return heightValidationResult;
2017-01-25 13:42:04 +01:00
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
if (tileElement->getType() == TileElementType::Entrance)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
uint8_t entranceType = tileElement->asEntrance()->GetEntranceType();
if (entranceType != ENTRANCE_TYPE_PARK_ENTRANCE)
2017-11-20 11:37:15 +01:00
{
// Update the ride's known entrance or exit height
2026-05-17 15:21:16 +02:00
auto ride = GetRide(tileElement->asEntrance()->GetRideIndex());
if (ride != nullptr)
{
2026-05-17 15:21:16 +02:00
auto entranceIndex = tileElement->asEntrance()->GetStationIndex();
2025-03-09 00:26:25 +01:00
auto& station = ride->getStation(entranceIndex);
const auto& entranceLoc = station.Entrance;
const auto& exitLoc = station.Exit;
2026-05-17 15:21:16 +02:00
uint8_t z = tileElement->baseHeight;
// Make sure this is the correct entrance or exit
if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entranceLoc == TileCoordsXYZ{ loc, z })
station.Entrance = { entranceLoc, z + heightOffset, entranceLoc.direction };
else if (entranceType == ENTRANCE_TYPE_RIDE_EXIT && exitLoc == TileCoordsXYZ{ loc, z })
station.Exit = { exitLoc, z + heightOffset, exitLoc.direction };
}
2017-06-06 23:24:18 +02:00
}
}
2026-05-17 15:21:16 +02:00
tileElement->baseHeight += heightOffset;
tileElement->clearanceHeight += heightOffset;
2017-06-06 23:24:18 +02:00
}
2017-01-25 13:42:04 +01:00
return GameActions::Result();
}
GameActions::Result SurfaceShowParkFences(const CoordsXY& loc, bool showFences, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
auto* const surfaceelement = MapGetSurfaceElementAt(loc);
// No surface element on tile
if (surfaceelement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
if (isExecuting)
{
if (!showFences)
surfaceelement->SetParkFences(0);
else
Park::UpdateFences(loc);
}
return GameActions::Result();
}
GameActions::Result SurfaceToggleCorner(const CoordsXY& loc, int32_t cornerIndex, bool isExecuting)
{
auto* const surfaceElement = MapGetSurfaceElementAt(loc);
// No surface element on tile
if (surfaceElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
if (isExecuting)
{
const uint8_t originalSlope = surfaceElement->GetSlope();
uint8_t newSlope = surfaceElement->GetSlope() ^ (1 << cornerIndex);
// All corners are raised
2024-05-02 23:31:01 +02:00
if ((newSlope & kTileSlopeRaisedCornersMask) == kTileSlopeRaisedCornersMask)
{
2024-05-02 23:31:01 +02:00
newSlope = kTileSlopeFlat;
if ((originalSlope & kTileSlopeDiagonalFlag) != 0)
{
2024-05-02 23:31:01 +02:00
switch (originalSlope & kTileSlopeRaisedCornersMask)
{
2024-05-02 23:31:01 +02:00
case kTileSlopeSCornerDown:
newSlope |= kTileSlopeNCornerUp;
break;
2024-05-02 23:31:01 +02:00
case kTileSlopeWCornerDown:
newSlope |= kTileSlopeECornerUp;
break;
2024-05-02 23:31:01 +02:00
case kTileSlopeNCornerDown:
newSlope |= kTileSlopeSCornerUp;
break;
2024-05-02 23:31:01 +02:00
case kTileSlopeECornerDown:
newSlope |= kTileSlopeWCornerUp;
break;
}
}
2026-05-17 15:21:16 +02:00
surfaceElement->baseHeight += 2;
surfaceElement->clearanceHeight = surfaceElement->baseHeight;
}
surfaceElement->SetSlope(newSlope);
}
return GameActions::Result();
}
GameActions::Result SurfaceToggleDiagonal(const CoordsXY& loc, bool isExecuting)
{
auto* const surfaceElement = MapGetSurfaceElementAt(loc);
// No surface element on tile
if (surfaceElement == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2024-05-02 23:31:01 +02:00
uint8_t newSlope = surfaceElement->GetSlope() ^ kTileSlopeDiagonalFlag;
surfaceElement->SetSlope(newSlope);
}
return GameActions::Result();
}
GameActions::Result PathSetSloped(const CoordsXY& loc, int32_t elementIndex, bool sloped, bool isExecuting)
{
TileElement* const pathElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (pathElement == nullptr || pathElement->getType() != TileElementType::Path)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PATH_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
pathElement->asPath()->SetSloped(sloped);
}
return GameActions::Result();
}
GameActions::Result PathSetJunctionRailings(
const CoordsXY& loc, int32_t elementIndex, bool hasJunctionRailings, bool isExecuting)
{
TileElement* const pathElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (pathElement == nullptr || pathElement->getType() != TileElementType::Path)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PATH_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
pathElement->asPath()->SetJunctionRailings(hasJunctionRailings);
}
return GameActions::Result();
}
GameActions::Result PathSetBroken(const CoordsXY& loc, int32_t elementIndex, bool broken, bool isExecuting)
{
TileElement* const pathElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (pathElement == nullptr || pathElement->getType() != TileElementType::Path)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PATH_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
pathElement->asPath()->SetIsBroken(broken);
}
return GameActions::Result();
}
GameActions::Result PathToggleEdge(const CoordsXY& loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting)
{
TileElement* const pathElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (pathElement == nullptr || pathElement->getType() != TileElementType::Path)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_PATH_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
uint8_t newEdges = pathElement->asPath()->GetEdgesAndCorners() ^ (1 << edgeIndex);
pathElement->asPath()->SetEdgesAndCorners(newEdges);
}
return GameActions::Result();
}
GameActions::Result EntranceMakeUsable(const CoordsXY& loc, int32_t elementIndex, bool isExecuting)
{
TileElement* const entranceElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (entranceElement == nullptr || entranceElement->getType() != TileElementType::Entrance)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ENTRANCE_ELEMENT_NOT_FOUND);
2026-05-17 15:21:16 +02:00
auto ride = GetRide(entranceElement->asEntrance()->GetRideIndex());
if (ride == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
auto stationIndex = entranceElement->asEntrance()->GetStationIndex();
2025-03-09 00:26:25 +01:00
auto& station = ride->getStation(stationIndex);
2026-05-17 15:21:16 +02:00
switch (entranceElement->asEntrance()->GetEntranceType())
2017-06-06 23:24:18 +02:00
{
case ENTRANCE_TYPE_RIDE_ENTRANCE:
2026-05-17 15:21:16 +02:00
station.Entrance = { loc, entranceElement->baseHeight, entranceElement->getDirection() };
break;
case ENTRANCE_TYPE_RIDE_EXIT:
2026-05-17 15:21:16 +02:00
station.Exit = { loc, entranceElement->baseHeight, entranceElement->getDirection() };
break;
2017-06-06 23:24:18 +02:00
}
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
GameActions::Result WallSetSlope(const CoordsXY& loc, int32_t elementIndex, int32_t slopeValue, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const wallElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (wallElement == nullptr || wallElement->getType() != TileElementType::Wall)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_WALL_ELEMENT_NOT_FOUND);
if (isExecuting)
{
// Set new slope value
2026-05-17 15:21:16 +02:00
wallElement->asWall()->SetSlope(slopeValue);
}
return GameActions::Result();
}
GameActions::Result WallAnimationFrameOffset(
const CoordsXY& loc, int16_t elementIndex, int8_t animationFrameOffset, bool isExecuting)
{
TileElement* const wallElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (wallElement == nullptr || wallElement->getType() != TileElementType::Wall)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_WALL_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
uint8_t animationFrame = wallElement->asWall()->GetAnimationFrame();
wallElement->asWall()->SetAnimationFrame(animationFrame + animationFrameOffset);
}
return GameActions::Result();
}
// Changes the height of all track elements that belong to the same track piece
// Broxzier: Copied from track_remove and stripped of unneeded code, but I think this should be smaller
GameActions::Result TrackBaseHeightOffset(const CoordsXY& loc, int32_t elementIndex, int8_t offset, bool isExecuting)
{
if (offset == 0)
return GameActions::Result();
TileElement* const trackElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (trackElement == nullptr || trackElement->getType() != TileElementType::Track)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
auto type = trackElement->asTrack()->GetTrackType();
int16_t originX = loc.x;
int16_t originY = loc.y;
2026-05-17 15:21:16 +02:00
int16_t originZ = trackElement->getBaseZ();
uint8_t rotation = trackElement->getDirection();
auto rideIndex = trackElement->asTrack()->GetRideIndex();
auto ride = GetRide(rideIndex);
if (ride == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
2021-08-27 17:49:32 -04:00
const auto& ted = GetTrackElementDescriptor(type);
2026-05-17 15:21:16 +02:00
auto sequenceIndex = trackElement->asTrack()->GetSequenceIndex();
if (sequenceIndex >= ted.sequenceData.numSequences)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_BLOCK_NOT_FOUND);
const auto& trackBlock = ted.sequenceData.sequences[sequenceIndex].clearance;
2026-05-17 15:21:16 +02:00
uint8_t originDirection = trackElement->getDirection();
2024-09-12 22:48:21 +02:00
CoordsXY offsets = { trackBlock.x, trackBlock.y };
CoordsXY coords = { originX, originY };
coords += offsets.Rotate(DirectionReverse(originDirection));
originX = static_cast<int16_t>(coords.x);
originY = static_cast<int16_t>(coords.y);
2024-09-12 22:48:21 +02:00
originZ -= trackBlock.z;
for (uint8_t i = 0; i < ted.sequenceData.numSequences; i++)
2017-06-06 23:24:18 +02:00
{
const auto& trackBlock2 = ted.sequenceData.sequences[i].clearance;
2024-09-12 22:48:21 +02:00
CoordsXYZD elem = { originX, originY, originZ + trackBlock2.z, rotation };
offsets.x = trackBlock2.x;
offsets.y = trackBlock2.y;
elem += offsets.Rotate(originDirection);
2024-09-12 22:48:21 +02:00
TrackElement* nextTrackElement = MapGetTrackElementAtOfTypeSeq(elem, type, i);
if (nextTrackElement == nullptr)
{
LOG_ERROR("Track map element part not found!");
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
}
2021-02-19 18:28:09 +02:00
// track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is
// for when you decrease the map size.
Guard::Assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5);
// Keep?
// invalidate_test_results(ride);
2026-05-17 15:21:16 +02:00
nextTrackElement->baseHeight += offset;
nextTrackElement->clearanceHeight += offset;
MapInvalidateTileFull(elem);
2017-06-06 23:24:18 +02:00
}
2021-02-19 18:28:09 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
// Sets chainlift, optionally for an entire track block
2021-02-19 18:28:09 +02:00
// Broxzier: Basically a copy of the above function, with just two different lines... should probably be combined
// somehow
GameActions::Result TrackSetChain(
const CoordsXY& loc, int32_t elementIndex, bool entireTrackBlock, bool setChain, bool isExecuting)
{
TileElement* const trackElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (trackElement == nullptr || trackElement->getType() != TileElementType::Track)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
if (isExecuting)
{
if (!entireTrackBlock)
{
// Set chain for only the selected piece
2026-05-17 15:21:16 +02:00
if (trackElement->asTrack()->HasChain() != setChain)
{
2026-05-17 15:21:16 +02:00
trackElement->asTrack()->SetHasChain(setChain);
}
return GameActions::Result();
}
2026-05-17 15:21:16 +02:00
auto type = trackElement->asTrack()->GetTrackType();
int16_t originX = loc.x;
int16_t originY = loc.y;
2026-05-17 15:21:16 +02:00
int16_t originZ = trackElement->getBaseZ();
uint8_t rotation = trackElement->getDirection();
auto rideIndex = trackElement->asTrack()->GetRideIndex();
auto ride = GetRide(rideIndex);
if (ride == nullptr)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
2021-08-27 17:49:32 -04:00
const auto& ted = GetTrackElementDescriptor(type);
2026-05-17 15:21:16 +02:00
auto sequenceIndex = trackElement->asTrack()->GetSequenceIndex();
if (sequenceIndex >= ted.sequenceData.numSequences)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_BLOCK_NOT_FOUND);
const auto& trackBlock = ted.sequenceData.sequences[sequenceIndex].clearance;
2026-05-17 15:21:16 +02:00
uint8_t originDirection = trackElement->getDirection();
2024-09-12 22:48:21 +02:00
CoordsXY offsets = { trackBlock.x, trackBlock.y };
CoordsXY coords = { originX, originY };
coords += offsets.Rotate(DirectionReverse(originDirection));
originX = static_cast<int16_t>(coords.x);
originY = static_cast<int16_t>(coords.y);
2024-09-12 22:48:21 +02:00
originZ -= trackBlock.z;
for (uint8_t i = 0; i < ted.sequenceData.numSequences; i++)
{
const auto& trackBlock2 = ted.sequenceData.sequences[i].clearance;
2024-09-12 22:48:21 +02:00
CoordsXYZD elem = { originX, originY, originZ + trackBlock2.z, rotation };
offsets.x = trackBlock2.x;
offsets.y = trackBlock2.y;
elem += offsets.Rotate(originDirection);
2024-09-12 22:48:21 +02:00
TrackElement* nextTrackElement = MapGetTrackElementAtOfTypeSeq(elem, type, i);
if (nextTrackElement == nullptr)
{
LOG_ERROR("Track map element part not found!");
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
}
2021-02-19 18:28:09 +02:00
// track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is
// for when you decrease the map size.
Guard::Assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5);
// Keep?
// invalidate_test_results(ride);
2026-05-17 15:21:16 +02:00
if (nextTrackElement->asTrack()->HasChain() != setChain)
{
2026-05-17 15:21:16 +02:00
nextTrackElement->asTrack()->SetHasChain(setChain);
}
MapInvalidateTileFull(elem);
}
2021-02-19 18:28:09 +02:00
}
return GameActions::Result();
}
2022-12-31 05:06:22 -08:00
GameActions::Result TrackSetBrakeClosed(const CoordsXY& loc, int32_t elementIndex, bool isClosed, bool isExecuting)
{
TileElement* const trackElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (trackElement == nullptr || trackElement->getType() != TileElementType::Track)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
trackElement->asTrack()->SetBrakeClosed(isClosed);
}
return GameActions::Result();
}
GameActions::Result TrackSetIndestructible(
const CoordsXY& loc, int32_t elementIndex, bool isIndestructible, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const trackElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (trackElement == nullptr || trackElement->getType() != TileElementType::Track)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
trackElement->asTrack()->SetIsIndestructible(isIndestructible);
2017-06-06 23:24:18 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
GameActions::Result ScenerySetQuarterLocation(
const CoordsXY& loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (tileElement == nullptr || tileElement->getType() != TileElementType::SmallScenery)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
// Set quadrant index
2026-05-17 15:21:16 +02:00
tileElement->asSmallScenery()->SetSceneryQuadrant(quarterIndex);
// Update collision
2026-05-17 15:21:16 +02:00
tileElement->setOccupiedQuadrants(1 << ((quarterIndex + 2) & 3));
2017-06-06 23:24:18 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
GameActions::Result ScenerySetQuarterCollision(
const CoordsXY& loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const tileElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (tileElement == nullptr || tileElement->getType() != TileElementType::SmallScenery)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
auto occupiedQuadrants = tileElement->getOccupiedQuadrants();
occupiedQuadrants ^= 1 << quarterIndex;
2026-05-17 15:21:16 +02:00
tileElement->setOccupiedQuadrants(occupiedQuadrants);
2017-06-06 23:24:18 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
2017-02-07 21:42:39 +01:00
GameActions::Result BannerToggleBlockingEdge(const CoordsXY& loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting)
2017-06-06 23:24:18 +02:00
{
TileElement* const bannerElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (bannerElement == nullptr || bannerElement->getType() != TileElementType::Banner)
2024-01-22 02:29:08 -08:00
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
if (isExecuting)
2017-06-06 23:24:18 +02:00
{
2026-05-17 15:21:16 +02:00
uint8_t edges = bannerElement->asBanner()->GetAllowedEdges();
edges ^= (1 << edgeIndex);
2026-05-17 15:21:16 +02:00
bannerElement->asBanner()->SetAllowedEdges(edges);
2017-06-06 23:24:18 +02:00
}
return GameActions::Result();
2017-06-06 23:24:18 +02:00
}
2017-02-07 15:39:07 +01:00
GameActions::Result WallSetAnimationIsBackwards(const CoordsXY& loc, int32_t elementIndex, bool backwards, bool isExecuting)
{
TileElement* const wallElement = MapGetNthElementAt(loc, elementIndex);
2026-05-17 15:21:16 +02:00
if (wallElement == nullptr || wallElement->getType() != TileElementType::Wall)
return GameActions::Result(
2025-12-12 11:41:49 +01:00
GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_WALL_ELEMENT_NOT_FOUND);
if (isExecuting)
{
2026-05-17 15:21:16 +02:00
wallElement->asWall()->SetAnimationIsBackwards(backwards);
}
return GameActions::Result();
}
TileElement* GetSelectedElement()
{
if (windowTileInspectorSelectedIndex == -1)
{
return nullptr;
}
Guard::Assert(
windowTileInspectorSelectedIndex >= 0 && windowTileInspectorSelectedIndex < windowTileInspectorElementCount,
"Selected list item out of range");
return MapGetNthElementAt(windowTileInspectorTile.ToCoordsXY(), windowTileInspectorSelectedIndex);
}
} // namespace OpenRCT2::TileInspector