2014-04-23 01:50:40 +01:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2014-04-23 01:50:40 +01:00
|
|
|
*
|
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
|
2014-04-23 01:50:40 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-04-23 01:50:40 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:14:18 +02:00
|
|
|
#include "Track.h"
|
|
|
|
|
|
2017-12-13 13:02:24 +01:00
|
|
|
#include "../Cheats.h"
|
2024-07-09 16:23:31 +02:00
|
|
|
#include "../Diagnostic.h"
|
2017-11-30 18:17:06 +01:00
|
|
|
#include "../Game.h"
|
2024-03-03 21:44:15 +00:00
|
|
|
#include "../GameState.h"
|
2025-02-17 07:24:03 -05:00
|
|
|
#include "../audio/Audio.h"
|
2018-06-22 23:14:18 +02:00
|
|
|
#include "../config/Config.h"
|
2018-01-05 23:45:53 +00:00
|
|
|
#include "../interface/Viewport.h"
|
2017-10-06 22:37:06 +02:00
|
|
|
#include "../management/Finance.h"
|
2025-02-24 04:43:06 -05:00
|
|
|
#include "../network/Network.h"
|
2022-02-18 21:57:00 +01:00
|
|
|
#include "../platform/Platform.h"
|
2018-01-09 10:40:42 +01:00
|
|
|
#include "../rct1/RCT1.h"
|
2024-07-02 18:50:12 +02:00
|
|
|
#include "../ride/RideColour.h"
|
2025-07-02 20:32:43 +02:00
|
|
|
#include "../sawyer_coding/SawyerCoding.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "../world/Footpath.h"
|
2018-01-03 14:56:08 +01:00
|
|
|
#include "../world/Map.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "../world/MapAnimation.h"
|
2017-12-31 21:40:00 +01:00
|
|
|
#include "../world/Park.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "../world/Scenery.h"
|
2024-10-15 22:02:31 +02:00
|
|
|
#include "../world/tile_element/TileElement.h"
|
2024-10-14 14:26:10 +02:00
|
|
|
#include "../world/tile_element/TrackElement.h"
|
2017-12-31 13:21:34 +01:00
|
|
|
#include "Ride.h"
|
2018-01-10 00:00:09 +01:00
|
|
|
#include "RideData.h"
|
2018-06-22 23:14:18 +02:00
|
|
|
#include "RideRatings.h"
|
2017-10-23 14:47:12 +02:00
|
|
|
#include "Station.h"
|
2017-10-16 12:02:23 +02:00
|
|
|
#include "TrackData.h"
|
2018-03-19 23:28:40 +01:00
|
|
|
#include "TrackDesign.h"
|
2014-04-23 01:50:40 +01:00
|
|
|
|
2024-07-09 16:43:03 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2024-03-03 21:44:15 +00:00
|
|
|
using namespace OpenRCT2;
|
2021-08-29 20:15:44 -04:00
|
|
|
using namespace OpenRCT2::TrackMetaData;
|
2025-12-11 00:12:21 +01:00
|
|
|
using OpenRCT2::GameActions::CommandFlag;
|
|
|
|
|
using OpenRCT2::GameActions::CommandFlags;
|
2014-04-23 01:50:40 +01:00
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
PitchAndRoll TrackPitchAndRollStart(OpenRCT2::TrackElemType trackType)
|
2020-06-14 21:03:46 -03:00
|
|
|
{
|
2021-08-29 20:15:44 -04:00
|
|
|
const auto& ted = GetTrackElementDescriptor(trackType);
|
2024-08-11 14:52:25 +02:00
|
|
|
return { ted.definition.pitchStart, ted.definition.rollStart };
|
2020-06-14 21:03:46 -03:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
PitchAndRoll TrackPitchAndRollEnd(OpenRCT2::TrackElemType trackType)
|
2020-06-14 21:03:46 -03:00
|
|
|
{
|
2021-08-29 20:15:44 -04:00
|
|
|
const auto& ted = GetTrackElementDescriptor(trackType);
|
2024-08-11 14:52:25 +02:00
|
|
|
return { ted.definition.pitchEnd, ted.definition.rollEnd };
|
2020-06-14 21:03:46 -03:00
|
|
|
}
|
|
|
|
|
|
2015-01-29 21:10:34 +00:00
|
|
|
/**
|
|
|
|
|
* Helper method to determine if a connects to b by its bank and angle, not location.
|
|
|
|
|
*/
|
2023-01-17 01:32:54 +01:00
|
|
|
int32_t TrackIsConnectedByShape(TileElement* a, TileElement* b)
|
2015-01-29 21:10:34 +00:00
|
|
|
{
|
2024-01-14 23:36:12 +01:00
|
|
|
auto trackType = a->AsTrack()->GetTrackType();
|
2021-08-29 20:15:44 -04:00
|
|
|
const auto* ted = &GetTrackElementDescriptor(trackType);
|
2024-08-11 14:52:25 +02:00
|
|
|
auto aBank = ted->definition.rollEnd;
|
|
|
|
|
auto aAngle = ted->definition.pitchEnd;
|
2023-01-17 01:32:54 +01:00
|
|
|
aBank = TrackGetActualBank(a, aBank);
|
2015-01-29 21:10:34 +00:00
|
|
|
|
2018-09-17 21:54:36 +02:00
|
|
|
trackType = b->AsTrack()->GetTrackType();
|
2021-08-29 20:15:44 -04:00
|
|
|
ted = &GetTrackElementDescriptor(trackType);
|
2024-08-11 14:52:25 +02:00
|
|
|
auto bBank = ted->definition.rollStart;
|
|
|
|
|
auto bAngle = ted->definition.pitchStart;
|
2023-01-17 01:32:54 +01:00
|
|
|
bBank = TrackGetActualBank(b, bBank);
|
2015-01-29 21:10:34 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
return aBank == bBank && aAngle == bAngle;
|
2015-02-17 17:00:47 +00:00
|
|
|
}
|
2015-02-26 19:02:26 +00:00
|
|
|
|
2022-01-19 15:17:11 +02:00
|
|
|
static TileElement* find_station_element(const CoordsXYZD& loc, RideId rideIndex)
|
2016-02-14 15:29:53 +00:00
|
|
|
{
|
2022-10-11 19:39:24 +01:00
|
|
|
TileElement* tileElement = MapGetFirstElementAt(loc);
|
2019-10-09 11:02:21 -03:00
|
|
|
if (tileElement == nullptr)
|
|
|
|
|
return nullptr;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2020-03-07 21:54:47 +01:00
|
|
|
if (loc.z != tileElement->GetBaseZ())
|
2017-10-17 13:55:53 +02:00
|
|
|
continue;
|
2021-12-11 00:39:39 +01:00
|
|
|
if (tileElement->GetType() != TileElementType::Track)
|
2017-10-17 13:55:53 +02:00
|
|
|
continue;
|
2020-03-07 22:14:29 +01:00
|
|
|
if (tileElement->GetDirection() != loc.direction)
|
2017-10-17 13:55:53 +02:00
|
|
|
continue;
|
2018-09-18 13:10:29 +02:00
|
|
|
if (tileElement->AsTrack()->GetRideIndex() != rideIndex)
|
2017-10-17 13:55:53 +02:00
|
|
|
continue;
|
2020-06-05 22:55:15 +02:00
|
|
|
if (!tileElement->AsTrack()->IsStation())
|
2017-10-17 13:55:53 +02:00
|
|
|
continue;
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2017-10-31 14:03:45 +01:00
|
|
|
return tileElement;
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (!(tileElement++)->IsLastForTile());
|
2017-10-17 13:55:53 +02:00
|
|
|
return nullptr;
|
2016-02-14 15:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-07 14:02:18 +01:00
|
|
|
static void ride_remove_station(Ride& ride, const CoordsXYZ& location)
|
2016-02-14 15:29:53 +00:00
|
|
|
{
|
2025-03-09 00:26:25 +01:00
|
|
|
for (auto& station : ride.getStations())
|
2017-07-18 12:23:24 +02:00
|
|
|
{
|
2022-01-28 00:34:04 +01:00
|
|
|
auto stationStart = station.GetStart();
|
2020-03-07 22:14:29 +01:00
|
|
|
if (stationStart == location)
|
2017-07-18 12:23:24 +02:00
|
|
|
{
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Start.SetNull();
|
2025-03-09 00:26:25 +01:00
|
|
|
ride.numStations--;
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-05 20:34:56 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006C4D89
|
|
|
|
|
*/
|
2025-12-11 00:12:21 +01:00
|
|
|
ResultWithMessage TrackAddStationElement(CoordsXYZD loc, RideId rideIndex, CommandFlags flags, bool fromTrackDesign)
|
2015-09-05 20:34:56 +01:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto ride = GetRide(rideIndex);
|
2019-08-08 22:58:56 +01:00
|
|
|
if (ride == nullptr)
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false };
|
2019-08-08 22:58:56 +01:00
|
|
|
|
2020-03-25 14:20:29 +01:00
|
|
|
CoordsXY stationBackLoc = loc;
|
|
|
|
|
CoordsXY stationFrontLoc = loc;
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t stationLength = 1;
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2025-03-09 00:26:25 +01:00
|
|
|
if (ride->getRideTypeDescriptor().HasFlag(RtdFlag::hasSinglePieceStation))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-03-09 00:26:25 +01:00
|
|
|
if (ride->numStations >= Limits::kMaxStationsPerRide)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false, STR_NO_MORE_STATIONS_ALLOWED_ON_THIS_RIDE };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-07-18 13:39:12 +02:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto stationIndex = RideGetFirstEmptyStationStart(*ride);
|
2022-01-26 13:28:19 +01:00
|
|
|
assert(!stationIndex.IsNull());
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2025-03-09 00:26:25 +01:00
|
|
|
auto& station = ride->getStation(stationIndex);
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Start.x = loc.x;
|
|
|
|
|
station.Start.y = loc.y;
|
2024-07-26 18:23:25 +10:00
|
|
|
station.Height = loc.z / kCoordsZStep;
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Depart = 1;
|
|
|
|
|
station.Length = 0;
|
2025-03-09 00:26:25 +01:00
|
|
|
ride->numStations++;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2022-07-30 18:04:59 +02:00
|
|
|
return { true };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2018-11-01 13:53:50 +01:00
|
|
|
TileElement* stationElement;
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Search backwards for more station
|
2020-03-25 14:20:29 +01:00
|
|
|
loc = { stationBackLoc, loc.z, loc.direction };
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2020-03-07 22:14:29 +01:00
|
|
|
loc -= CoordsDirectionDelta[loc.direction];
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-07 22:14:29 +01:00
|
|
|
stationElement = find_station_element(loc, rideIndex);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (stationElement != nullptr)
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
if (stationElement->AsTrack()->GetTrackType() == TrackElemType::EndStation)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2023-01-07 14:02:18 +01:00
|
|
|
ride_remove_station(*ride, loc);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-25 14:20:29 +01:00
|
|
|
stationBackLoc = loc;
|
2017-06-06 23:24:18 +02:00
|
|
|
stationLength++;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (stationElement != nullptr);
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Search forwards for more station
|
2020-03-25 14:20:29 +01:00
|
|
|
loc = { stationFrontLoc, loc.z, loc.direction };
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2020-03-07 22:14:29 +01:00
|
|
|
loc += CoordsDirectionDelta[loc.direction];
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-07 22:14:29 +01:00
|
|
|
stationElement = find_station_element(loc, rideIndex);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (stationElement != nullptr)
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
if (stationElement->AsTrack()->GetTrackType() == TrackElemType::EndStation)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2023-01-07 14:02:18 +01:00
|
|
|
ride_remove_station(*ride, loc);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-25 14:20:29 +01:00
|
|
|
stationFrontLoc = loc;
|
2017-06-06 23:24:18 +02:00
|
|
|
stationLength++;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (stationElement != nullptr);
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-25 14:20:29 +01:00
|
|
|
// When attempting to place a track design, it sometimes happens that the front and back of station 0 are built,
|
|
|
|
|
// but the middle is not. Allow this, so the track place function can actually finish building all 4 stations.
|
2020-03-26 06:53:49 +01:00
|
|
|
// This _might_ cause issues if the track designs is bugged and actually has 5.
|
2025-03-09 00:26:25 +01:00
|
|
|
if (stationBackLoc == stationFrontLoc && ride->numStations >= Limits::kMaxStationsPerRide && !fromTrackDesign)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false, STR_NO_MORE_STATIONS_ALLOWED_ON_THIS_RIDE };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2024-03-24 22:49:50 +01:00
|
|
|
if (stationLength > kMaxStationPlatformLength)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false, STR_STATION_PLATFORM_TOO_LONG };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-03-25 14:20:29 +01:00
|
|
|
loc = { stationFrontLoc, loc.z, loc.direction };
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
bool finaliseStationDone;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
finaliseStationDone = true;
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-07 22:14:29 +01:00
|
|
|
stationElement = find_station_element(loc, rideIndex);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (stationElement != nullptr)
|
|
|
|
|
{
|
2024-10-11 15:30:27 +02:00
|
|
|
OpenRCT2::TrackElemType targetTrackType;
|
2020-03-25 14:20:29 +01:00
|
|
|
if (stationFrontLoc == loc)
|
2017-07-18 13:39:12 +02:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto stationIndex = RideGetFirstEmptyStationStart(*ride);
|
2022-01-26 13:28:19 +01:00
|
|
|
if (stationIndex.IsNull())
|
2020-03-21 15:18:55 +01:00
|
|
|
{
|
2023-01-17 13:24:51 +01:00
|
|
|
LOG_VERBOSE("No empty station starts, not updating metadata! This can happen with hacked rides.");
|
2020-03-21 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-03-09 00:26:25 +01:00
|
|
|
auto& station = ride->getStation(stationIndex);
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Start = loc;
|
2024-07-26 18:23:25 +10:00
|
|
|
station.Height = loc.z / kCoordsZStep;
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Depart = 1;
|
|
|
|
|
station.Length = stationLength;
|
2025-03-09 00:26:25 +01:00
|
|
|
ride->numStations++;
|
2020-03-21 15:18:55 +01:00
|
|
|
}
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::EndStation;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
2020-03-25 14:20:29 +01:00
|
|
|
else if (stationBackLoc == loc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::BeginStation;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::MiddleStation;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2018-09-17 21:54:36 +02:00
|
|
|
stationElement->AsTrack()->SetTrackType(targetTrackType);
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2022-10-12 13:14:45 +01:00
|
|
|
MapInvalidateElement(loc, stationElement);
|
2016-02-14 15:29:53 +00:00
|
|
|
|
2020-03-25 14:20:29 +01:00
|
|
|
if (stationBackLoc != loc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-03-07 22:14:29 +01:00
|
|
|
loc -= CoordsDirectionDelta[loc.direction];
|
2017-06-06 23:24:18 +02:00
|
|
|
finaliseStationDone = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (!finaliseStationDone);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2022-07-30 18:04:59 +02:00
|
|
|
return { true };
|
2015-09-05 20:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-14 17:37:28 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006C494B
|
|
|
|
|
*/
|
2025-12-11 00:12:21 +01:00
|
|
|
ResultWithMessage TrackRemoveStationElement(const CoordsXYZD& loc, RideId rideIndex, CommandFlags flags)
|
2016-02-14 17:37:28 +00:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto ride = GetRide(rideIndex);
|
2019-08-08 22:58:56 +01:00
|
|
|
if (ride == nullptr)
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false };
|
2019-08-08 22:58:56 +01:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
CoordsXYZD removeLoc = loc;
|
|
|
|
|
CoordsXYZD stationBackLoc = loc;
|
|
|
|
|
CoordsXYZD stationFrontLoc = loc;
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t stationLength = 0;
|
2023-01-21 16:41:03 +01:00
|
|
|
int32_t ByteF441D1 = -1;
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2025-03-09 00:26:25 +01:00
|
|
|
if (ride->getRideTypeDescriptor().HasFlag(RtdFlag::hasSinglePieceStation))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2022-10-12 13:14:45 +01:00
|
|
|
TileElement* tileElement = MapGetTrackElementAtWithDirectionFromRide(loc, rideIndex);
|
2017-10-31 14:03:45 +01:00
|
|
|
if (tileElement != nullptr)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2023-01-07 14:02:18 +01:00
|
|
|
ride_remove_station(*ride, loc);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-30 18:04:59 +02:00
|
|
|
return { true };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2018-11-01 13:53:50 +01:00
|
|
|
TileElement* stationElement;
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Search backwards for more station
|
2020-08-09 07:25:44 +01:00
|
|
|
CoordsXYZD currentLoc = stationBackLoc;
|
|
|
|
|
while ((stationElement = find_station_element(currentLoc, rideIndex)) != nullptr)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
if (stationElement->AsTrack()->GetTrackType() == TrackElemType::EndStation)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2023-01-07 14:02:18 +01:00
|
|
|
ride_remove_station(*ride, currentLoc);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
stationBackLoc = currentLoc;
|
2023-01-21 16:41:03 +01:00
|
|
|
ByteF441D1++;
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
currentLoc -= CoordsDirectionDelta[currentLoc.direction];
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Search forwards for more station
|
2020-08-09 07:25:44 +01:00
|
|
|
currentLoc = stationFrontLoc;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2020-08-09 07:25:44 +01:00
|
|
|
currentLoc += CoordsDirectionDelta[currentLoc.direction];
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
stationElement = find_station_element(currentLoc, rideIndex);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (stationElement != nullptr)
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
if (stationElement->AsTrack()->GetTrackType() == TrackElemType::EndStation)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-12-11 00:12:21 +01:00
|
|
|
if (flags.has(CommandFlag::apply))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2023-01-07 14:02:18 +01:00
|
|
|
ride_remove_station(*ride, currentLoc);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-09 07:25:44 +01:00
|
|
|
stationFrontLoc = currentLoc;
|
2017-06-06 23:24:18 +02:00
|
|
|
stationLength++;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (stationElement != nullptr);
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2025-12-11 00:12:21 +01:00
|
|
|
if (!(flags.has(CommandFlag::apply)))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2025-03-09 00:26:25 +01:00
|
|
|
if ((removeLoc != stationBackLoc) && (removeLoc != stationFrontLoc) && ride->numStations >= Limits::kMaxStationsPerRide)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2022-07-30 18:04:59 +02:00
|
|
|
return { false, STR_NO_MORE_STATIONS_ALLOWED_ON_THIS_RIDE };
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
2021-09-15 22:22:15 +02:00
|
|
|
|
2022-07-30 18:04:59 +02:00
|
|
|
return { true };
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
currentLoc = stationFrontLoc;
|
2017-06-06 23:24:18 +02:00
|
|
|
bool finaliseStationDone;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
finaliseStationDone = true;
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
if (currentLoc != removeLoc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-09 07:25:44 +01:00
|
|
|
stationElement = find_station_element(currentLoc, rideIndex);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (stationElement != nullptr)
|
|
|
|
|
{
|
2024-10-11 15:30:27 +02:00
|
|
|
OpenRCT2::TrackElemType targetTrackType;
|
2020-08-09 07:25:44 +01:00
|
|
|
if ((currentLoc == stationFrontLoc) || (currentLoc + CoordsDirectionDelta[currentLoc.direction] == removeLoc))
|
2017-07-18 13:39:12 +02:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto stationIndex = RideGetFirstEmptyStationStart(*ride);
|
2022-01-26 13:28:19 +01:00
|
|
|
if (stationIndex.IsNull())
|
2020-03-21 15:18:55 +01:00
|
|
|
{
|
2023-01-17 13:24:51 +01:00
|
|
|
LOG_VERBOSE("No empty station starts, not updating metadata! This can happen with hacked rides.");
|
2020-03-21 15:18:55 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-03-09 00:26:25 +01:00
|
|
|
auto& station = ride->getStation(stationIndex);
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Start = currentLoc;
|
2024-07-26 18:23:25 +10:00
|
|
|
station.Height = currentLoc.z / kCoordsZStep;
|
2022-01-28 00:34:04 +01:00
|
|
|
station.Depart = 1;
|
2023-01-21 16:41:03 +01:00
|
|
|
station.Length = stationLength != 0 ? stationLength : ByteF441D1;
|
2025-03-09 00:26:25 +01:00
|
|
|
ride->numStations++;
|
2020-03-21 15:18:55 +01:00
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2018-06-22 23:14:18 +02:00
|
|
|
stationLength = 0;
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::EndStation;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-09 07:25:44 +01:00
|
|
|
if (currentLoc - CoordsDirectionDelta[currentLoc.direction] == removeLoc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::BeginStation;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-09 07:25:44 +01:00
|
|
|
if (currentLoc == stationBackLoc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::BeginStation;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
targetTrackType = TrackElemType::MiddleStation;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-17 21:54:36 +02:00
|
|
|
stationElement->AsTrack()->SetTrackType(targetTrackType);
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2022-10-12 13:14:45 +01:00
|
|
|
MapInvalidateElement(currentLoc, stationElement);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-14 17:37:28 +00:00
|
|
|
|
2020-08-09 07:25:44 +01:00
|
|
|
if (currentLoc != stationBackLoc)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-09 07:25:44 +01:00
|
|
|
currentLoc -= CoordsDirectionDelta[currentLoc.direction];
|
2017-06-06 23:24:18 +02:00
|
|
|
finaliseStationDone = false;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (!finaliseStationDone);
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2022-07-30 18:04:59 +02:00
|
|
|
return { true };
|
2016-02-14 17:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 19:57:17 +00:00
|
|
|
void TrackCircuitIteratorBegin(TrackCircuitIterator* it, CoordsXYE first)
|
2015-07-11 22:51:11 +01:00
|
|
|
{
|
2018-06-22 23:14:18 +02:00
|
|
|
it->last = first;
|
|
|
|
|
it->first = nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
it->firstIteration = true;
|
2018-06-22 23:14:18 +02:00
|
|
|
it->looped = false;
|
2015-07-11 22:51:11 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 19:57:17 +00:00
|
|
|
bool TrackCircuitIteratorPrevious(TrackCircuitIterator* it)
|
2015-09-13 02:59:55 +01:00
|
|
|
{
|
2023-01-20 20:58:55 +00:00
|
|
|
TrackBeginEnd trackBeginEnd;
|
2015-09-13 02:59:55 +01:00
|
|
|
|
2017-10-17 13:55:53 +02:00
|
|
|
if (it->first == nullptr)
|
|
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
if (!TrackBlockGetPrevious({ it->last.x, it->last.y, it->last.element }, &trackBeginEnd))
|
2017-06-06 23:24:18 +02:00
|
|
|
return false;
|
2015-09-13 02:59:55 +01:00
|
|
|
|
2018-06-22 23:14:18 +02:00
|
|
|
it->current.x = trackBeginEnd.begin_x;
|
|
|
|
|
it->current.y = trackBeginEnd.begin_y;
|
|
|
|
|
it->current.element = trackBeginEnd.begin_element;
|
|
|
|
|
it->currentZ = trackBeginEnd.begin_z;
|
2017-06-06 23:24:18 +02:00
|
|
|
it->currentDirection = trackBeginEnd.begin_direction;
|
2015-09-13 02:59:55 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
it->first = it->current.element;
|
|
|
|
|
return true;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
2021-09-15 22:22:15 +02:00
|
|
|
|
|
|
|
|
if (!it->firstIteration && it->first == it->current.element)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2021-09-15 22:22:15 +02:00
|
|
|
it->looped = true;
|
|
|
|
|
return false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2021-09-15 22:22:15 +02:00
|
|
|
|
|
|
|
|
it->firstIteration = false;
|
|
|
|
|
it->last = it->current;
|
|
|
|
|
|
2023-01-17 01:32:54 +01:00
|
|
|
if (TrackBlockGetPrevious({ it->last.x, it->last.y, it->last.element }, &trackBeginEnd))
|
2021-09-15 22:22:15 +02:00
|
|
|
{
|
|
|
|
|
it->current.x = trackBeginEnd.end_x;
|
|
|
|
|
it->current.y = trackBeginEnd.end_y;
|
|
|
|
|
it->current.element = trackBeginEnd.begin_element;
|
|
|
|
|
it->currentZ = trackBeginEnd.begin_z;
|
|
|
|
|
it->currentDirection = trackBeginEnd.begin_direction;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-09-13 02:59:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 19:57:17 +00:00
|
|
|
bool TrackCircuitIteratorNext(TrackCircuitIterator* it)
|
2015-07-11 22:51:11 +01:00
|
|
|
{
|
2017-10-17 13:55:53 +02:00
|
|
|
if (it->first == nullptr)
|
|
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
if (!TrackBlockGetNext(&it->last, &it->current, &it->currentZ, &it->currentDirection))
|
2017-06-06 23:24:18 +02:00
|
|
|
return false;
|
2015-07-11 22:51:11 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
it->first = it->current.element;
|
|
|
|
|
return true;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
2015-07-11 22:51:11 +01:00
|
|
|
|
2021-09-15 22:22:15 +02:00
|
|
|
if (!it->firstIteration && it->first == it->current.element)
|
|
|
|
|
{
|
|
|
|
|
it->looped = true;
|
|
|
|
|
return false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2021-09-15 22:22:15 +02:00
|
|
|
|
|
|
|
|
it->firstIteration = false;
|
|
|
|
|
it->last = it->current;
|
2023-01-17 01:32:54 +01:00
|
|
|
return TrackBlockGetNext(&it->last, &it->current, &it->currentZ, &it->currentDirection);
|
2015-07-11 22:51:11 +01:00
|
|
|
}
|
2015-07-12 14:26:14 +01:00
|
|
|
|
2023-01-21 19:57:17 +00:00
|
|
|
bool TrackCircuitIteratorsMatch(const TrackCircuitIterator* firstIt, const TrackCircuitIterator* secondIt)
|
2018-01-20 21:51:26 +00:00
|
|
|
{
|
2018-06-22 23:14:18 +02:00
|
|
|
return (
|
|
|
|
|
firstIt->currentZ == secondIt->currentZ && firstIt->currentDirection == secondIt->currentDirection
|
|
|
|
|
&& firstIt->current.x == secondIt->current.x && firstIt->current.y == secondIt->current.y);
|
2018-01-20 21:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 01:32:54 +01:00
|
|
|
void TrackGetBack(const CoordsXYE& input, CoordsXYE* output)
|
2015-07-12 14:26:14 +01:00
|
|
|
{
|
2018-06-22 23:14:18 +02:00
|
|
|
CoordsXYE lastTrack;
|
2023-01-20 20:58:55 +00:00
|
|
|
TrackBeginEnd currentTrack;
|
2018-06-22 23:14:18 +02:00
|
|
|
bool result;
|
2015-07-12 14:26:14 +01:00
|
|
|
|
2022-12-17 17:34:00 +01:00
|
|
|
lastTrack = input;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
result = TrackBlockGetPrevious(lastTrack, ¤tTrack);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (result)
|
|
|
|
|
{
|
2018-06-22 23:14:18 +02:00
|
|
|
lastTrack.x = currentTrack.begin_x;
|
|
|
|
|
lastTrack.y = currentTrack.begin_y;
|
2017-06-06 23:24:18 +02:00
|
|
|
lastTrack.element = currentTrack.begin_element;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (result);
|
2017-06-06 23:24:18 +02:00
|
|
|
*output = lastTrack;
|
2015-07-12 14:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 01:32:54 +01:00
|
|
|
void TrackGetFront(const CoordsXYE& input, CoordsXYE* output)
|
2015-07-12 14:26:14 +01:00
|
|
|
{
|
2018-02-15 17:42:53 +01:00
|
|
|
CoordsXYE lastTrack, currentTrack;
|
2018-06-22 23:14:18 +02:00
|
|
|
int32_t z, direction;
|
|
|
|
|
bool result;
|
2015-07-12 14:26:14 +01:00
|
|
|
|
2022-12-17 17:34:00 +01:00
|
|
|
lastTrack = input;
|
2017-10-17 13:55:53 +02:00
|
|
|
do
|
|
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
result = TrackBlockGetNext(&lastTrack, ¤tTrack, &z, &direction);
|
2017-10-17 13:55:53 +02:00
|
|
|
if (result)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
lastTrack = currentTrack;
|
|
|
|
|
}
|
2018-06-22 23:14:18 +02:00
|
|
|
} while (result);
|
2017-06-06 23:24:18 +02:00
|
|
|
*output = lastTrack;
|
2015-07-12 14:26:14 +01:00
|
|
|
}
|
2015-10-25 16:00:21 +00:00
|
|
|
|
2024-12-22 19:24:15 +01:00
|
|
|
TrackElement* TrackGetPreviousBlock(CoordsXYZ& location, TileElement* tileElement)
|
|
|
|
|
{
|
|
|
|
|
CoordsXYZ startLocation = location;
|
|
|
|
|
TrackBeginEnd trackBeginEnd, slowTrackBeginEnd;
|
|
|
|
|
TileElement slowTileElement = *tileElement;
|
|
|
|
|
bool counter = true;
|
|
|
|
|
CoordsXY slowLocation = location;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (!TrackBlockGetPrevious({ location, tileElement }, &trackBeginEnd))
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (trackBeginEnd.begin_x == startLocation.x && trackBeginEnd.begin_y == startLocation.y
|
|
|
|
|
&& tileElement == trackBeginEnd.begin_element)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location.x = trackBeginEnd.end_x;
|
|
|
|
|
location.y = trackBeginEnd.end_y;
|
|
|
|
|
location.z = trackBeginEnd.begin_z;
|
|
|
|
|
tileElement = trackBeginEnd.begin_element;
|
|
|
|
|
|
|
|
|
|
// #2081: prevent infinite loop
|
|
|
|
|
counter = !counter;
|
|
|
|
|
if (counter)
|
|
|
|
|
{
|
|
|
|
|
TrackBlockGetPrevious({ slowLocation, &slowTileElement }, &slowTrackBeginEnd);
|
|
|
|
|
slowLocation.x = slowTrackBeginEnd.end_x;
|
|
|
|
|
slowLocation.y = slowTrackBeginEnd.end_y;
|
|
|
|
|
slowTileElement = *(slowTrackBeginEnd.begin_element);
|
|
|
|
|
if (slowLocation == location && slowTileElement.GetBaseZ() == tileElement->GetBaseZ()
|
|
|
|
|
&& slowTileElement.GetType() == tileElement->GetType()
|
|
|
|
|
&& slowTileElement.GetDirection() == tileElement->GetDirection())
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (!(trackBeginEnd.begin_element->AsTrack()->IsBlockStart()));
|
|
|
|
|
|
|
|
|
|
// Get the start of the track block instead of the end
|
|
|
|
|
location = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z };
|
|
|
|
|
auto trackOrigin = MapGetTrackElementAtOfTypeSeq(location, trackBeginEnd.begin_element->AsTrack()->GetTrackType(), 0);
|
|
|
|
|
if (trackOrigin == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return trackOrigin->AsTrack();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 23:46:28 +01:00
|
|
|
TrackRoll TrackGetActualBank(TileElement* tileElement, TrackRoll bank)
|
2015-11-22 12:14:53 +00:00
|
|
|
{
|
2023-01-17 01:32:54 +01:00
|
|
|
auto ride = GetRide(tileElement->AsTrack()->GetRideIndex());
|
2019-08-08 22:58:56 +01:00
|
|
|
if (ride != nullptr)
|
|
|
|
|
{
|
|
|
|
|
bool isInverted = tileElement->AsTrack()->IsInverted();
|
2023-01-17 01:32:54 +01:00
|
|
|
return TrackGetActualBank2(ride->type, isInverted, bank);
|
2019-08-08 22:58:56 +01:00
|
|
|
}
|
|
|
|
|
return bank;
|
2015-11-22 12:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-22 19:59:36 +01:00
|
|
|
TrackRoll TrackGetActualBank2(ride_type_t rideType, bool isInverted, TrackRoll bank)
|
2015-11-22 12:14:53 +00:00
|
|
|
{
|
2024-08-13 22:20:25 +02:00
|
|
|
if (GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::hasInvertedVariant))
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2017-11-14 13:15:17 +01:00
|
|
|
if (isInverted)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2024-01-14 23:46:28 +01:00
|
|
|
if (bank == TrackRoll::None)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2024-01-14 23:46:28 +01:00
|
|
|
bank = TrackRoll::UpsideDown;
|
2017-10-17 13:55:53 +02:00
|
|
|
}
|
2024-01-14 23:46:28 +01:00
|
|
|
else if (bank == TrackRoll::UpsideDown)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2024-01-14 23:46:28 +01:00
|
|
|
bank = TrackRoll::None;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bank;
|
2015-11-22 12:14:53 +00:00
|
|
|
}
|
2015-11-22 14:55:46 +00:00
|
|
|
|
2024-01-14 23:46:28 +01:00
|
|
|
TrackRoll TrackGetActualBank3(bool useInvertedSprites, TileElement* tileElement)
|
2015-12-13 16:10:30 +00:00
|
|
|
{
|
2019-08-09 08:06:25 +01:00
|
|
|
auto trackType = tileElement->AsTrack()->GetTrackType();
|
2021-08-29 20:15:44 -04:00
|
|
|
const auto& ted = GetTrackElementDescriptor(trackType);
|
2024-08-11 14:52:25 +02:00
|
|
|
auto bankStart = ted.definition.rollStart;
|
2023-01-17 01:32:54 +01:00
|
|
|
auto ride = GetRide(tileElement->AsTrack()->GetRideIndex());
|
2019-08-09 08:06:25 +01:00
|
|
|
if (ride == nullptr)
|
|
|
|
|
return bankStart;
|
|
|
|
|
|
2020-06-14 19:50:26 -03:00
|
|
|
bool isInverted = useInvertedSprites ^ tileElement->AsTrack()->IsInverted();
|
2023-01-17 01:32:54 +01:00
|
|
|
return TrackGetActualBank2(ride->type, isInverted, bankStart);
|
2015-12-13 16:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeIsStation(OpenRCT2::TrackElemType trackType)
|
2020-06-05 22:55:15 +02:00
|
|
|
{
|
|
|
|
|
switch (trackType)
|
2017-10-17 13:55:53 +02:00
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
case TrackElemType::EndStation:
|
|
|
|
|
case TrackElemType::BeginStation:
|
|
|
|
|
case TrackElemType::MiddleStation:
|
2018-06-22 23:14:18 +02:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-11-22 14:55:46 +00:00
|
|
|
}
|
2015-11-22 17:50:33 +00:00
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeIsBrakes(OpenRCT2::TrackElemType trackType)
|
2022-01-28 00:46:35 -08:00
|
|
|
{
|
2024-10-03 06:42:36 -04:00
|
|
|
switch (trackType)
|
|
|
|
|
{
|
|
|
|
|
case TrackElemType::Brakes:
|
|
|
|
|
case TrackElemType::DiagBrakes:
|
|
|
|
|
case TrackElemType::Down25Brakes:
|
2025-02-19 12:53:43 -05:00
|
|
|
case TrackElemType::DiagDown25Brakes:
|
2024-10-03 06:42:36 -04:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-01-28 00:46:35 -08:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeIsBlockBrakes(OpenRCT2::TrackElemType trackType)
|
2022-01-28 00:46:35 -08:00
|
|
|
{
|
|
|
|
|
return (trackType == TrackElemType::BlockBrakes) || (trackType == TrackElemType::DiagBlockBrakes);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeIsBooster(OpenRCT2::TrackElemType trackType)
|
2023-12-02 09:53:16 -08:00
|
|
|
{
|
2024-11-24 21:12:51 +01:00
|
|
|
switch (trackType)
|
|
|
|
|
{
|
|
|
|
|
case TrackElemType::Booster:
|
|
|
|
|
case TrackElemType::DiagBooster:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-12-02 09:53:16 -08:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackElementIsCovered(OpenRCT2::TrackElemType trackElementType)
|
2015-11-22 17:50:33 +00:00
|
|
|
{
|
2017-10-17 13:55:53 +02:00
|
|
|
switch (trackElementType)
|
|
|
|
|
{
|
2020-08-18 07:28:41 +01:00
|
|
|
case TrackElemType::FlatCovered:
|
|
|
|
|
case TrackElemType::Up25Covered:
|
|
|
|
|
case TrackElemType::Up60Covered:
|
|
|
|
|
case TrackElemType::FlatToUp25Covered:
|
|
|
|
|
case TrackElemType::Up25ToUp60Covered:
|
|
|
|
|
case TrackElemType::Up60ToUp25Covered:
|
|
|
|
|
case TrackElemType::Up25ToFlatCovered:
|
|
|
|
|
case TrackElemType::Down25Covered:
|
|
|
|
|
case TrackElemType::Down60Covered:
|
|
|
|
|
case TrackElemType::FlatToDown25Covered:
|
|
|
|
|
case TrackElemType::Down25ToDown60Covered:
|
|
|
|
|
case TrackElemType::Down60ToDown25Covered:
|
|
|
|
|
case TrackElemType::Down25ToFlatCovered:
|
|
|
|
|
case TrackElemType::LeftQuarterTurn5TilesCovered:
|
|
|
|
|
case TrackElemType::RightQuarterTurn5TilesCovered:
|
|
|
|
|
case TrackElemType::SBendLeftCovered:
|
|
|
|
|
case TrackElemType::SBendRightCovered:
|
|
|
|
|
case TrackElemType::LeftQuarterTurn3TilesCovered:
|
|
|
|
|
case TrackElemType::RightQuarterTurn3TilesCovered:
|
2018-06-22 23:14:18 +02:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-11-22 17:50:33 +00:00
|
|
|
}
|
2017-06-20 14:23:49 +02:00
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
OpenRCT2::TrackElemType UncoverTrackElement(OpenRCT2::TrackElemType trackElementType)
|
2023-11-25 13:57:13 +01:00
|
|
|
{
|
|
|
|
|
switch (trackElementType)
|
|
|
|
|
{
|
|
|
|
|
case TrackElemType::FlatCovered:
|
|
|
|
|
return TrackElemType::Flat;
|
|
|
|
|
case TrackElemType::Up25Covered:
|
|
|
|
|
return TrackElemType::Up25;
|
|
|
|
|
case TrackElemType::Up60Covered:
|
|
|
|
|
return TrackElemType::Up60;
|
|
|
|
|
case TrackElemType::FlatToUp25Covered:
|
|
|
|
|
return TrackElemType::FlatToUp25;
|
|
|
|
|
case TrackElemType::Up25ToUp60Covered:
|
|
|
|
|
return TrackElemType::Up25ToUp60;
|
|
|
|
|
case TrackElemType::Up60ToUp25Covered:
|
|
|
|
|
return TrackElemType::Up60ToUp25;
|
|
|
|
|
case TrackElemType::Up25ToFlatCovered:
|
|
|
|
|
return TrackElemType::Up25ToFlat;
|
|
|
|
|
case TrackElemType::Down25Covered:
|
|
|
|
|
return TrackElemType::Down25;
|
|
|
|
|
case TrackElemType::Down60Covered:
|
|
|
|
|
return TrackElemType::Down60;
|
|
|
|
|
case TrackElemType::FlatToDown25Covered:
|
|
|
|
|
return TrackElemType::FlatToDown25;
|
|
|
|
|
case TrackElemType::Down25ToDown60Covered:
|
|
|
|
|
return TrackElemType::Down25ToDown60;
|
|
|
|
|
case TrackElemType::Down60ToDown25Covered:
|
|
|
|
|
return TrackElemType::Down60ToDown25;
|
|
|
|
|
case TrackElemType::Down25ToFlatCovered:
|
|
|
|
|
return TrackElemType::Down25ToFlat;
|
|
|
|
|
case TrackElemType::LeftQuarterTurn5TilesCovered:
|
|
|
|
|
return TrackElemType::LeftQuarterTurn5Tiles;
|
|
|
|
|
case TrackElemType::RightQuarterTurn5TilesCovered:
|
|
|
|
|
return TrackElemType::RightQuarterTurn5Tiles;
|
|
|
|
|
case TrackElemType::SBendLeftCovered:
|
|
|
|
|
return TrackElemType::SBendLeft;
|
|
|
|
|
case TrackElemType::SBendRightCovered:
|
|
|
|
|
return TrackElemType::SBendRight;
|
|
|
|
|
case TrackElemType::LeftQuarterTurn3TilesCovered:
|
|
|
|
|
return TrackElemType::LeftQuarterTurn3Tiles;
|
|
|
|
|
case TrackElemType::RightQuarterTurn3TilesCovered:
|
|
|
|
|
return TrackElemType::RightQuarterTurn3Tiles;
|
|
|
|
|
default:
|
|
|
|
|
return trackElementType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeHasSpeedSetting(OpenRCT2::TrackElemType trackType)
|
2017-06-20 14:23:49 +02:00
|
|
|
{
|
2023-12-02 09:53:16 -08:00
|
|
|
return TrackTypeIsBooster(trackType) || TrackTypeIsBrakes(trackType) || TrackTypeIsBlockBrakes(trackType);
|
2017-06-20 14:23:49 +02:00
|
|
|
}
|
2017-10-04 17:14:53 +02:00
|
|
|
|
2024-10-11 15:30:27 +02:00
|
|
|
bool TrackTypeIsHelix(OpenRCT2::TrackElemType trackType)
|
2023-01-03 00:10:07 +01:00
|
|
|
{
|
|
|
|
|
if (trackType >= TrackElemType::LeftHalfBankedHelixUpSmall && trackType <= TrackElemType::RightHalfBankedHelixDownLarge)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (trackType >= TrackElemType::LeftQuarterBankedHelixLargeUp && trackType <= TrackElemType::RightQuarterHelixLargeDown)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 03:02:55 +00:00
|
|
|
std::optional<CoordsXYZD> GetTrackSegmentOrigin(const CoordsXYE& posEl)
|
|
|
|
|
{
|
2024-03-22 02:51:11 +01:00
|
|
|
if (posEl.element == nullptr)
|
|
|
|
|
return {};
|
|
|
|
|
|
2022-03-13 03:02:55 +00:00
|
|
|
auto trackEl = posEl.element->AsTrack();
|
|
|
|
|
if (trackEl == nullptr)
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
const auto& ted = GetTrackElementDescriptor(trackEl->GetTrackType());
|
|
|
|
|
auto direction = trackEl->GetDirection();
|
|
|
|
|
auto coords = CoordsXYZ(posEl.x, posEl.y, trackEl->GetBaseZ());
|
|
|
|
|
|
|
|
|
|
// Subtract the current sequence's offset
|
2024-09-12 22:48:21 +02:00
|
|
|
auto sequenceIndex = trackEl->GetSequenceIndex();
|
|
|
|
|
if (sequenceIndex >= ted.numSequences)
|
2022-12-10 22:31:23 +01:00
|
|
|
return {};
|
|
|
|
|
|
2024-09-12 22:48:21 +02:00
|
|
|
const auto& trackBlock = ted.sequences[sequenceIndex].clearance;
|
|
|
|
|
CoordsXY trackBlockOffset = { trackBlock.x, trackBlock.y };
|
2022-10-04 20:12:38 +01:00
|
|
|
coords += trackBlockOffset.Rotate(DirectionReverse(direction));
|
2025-05-19 20:52:45 +02:00
|
|
|
coords.z -= trackBlock.z;
|
2022-03-13 03:02:55 +00:00
|
|
|
|
|
|
|
|
return CoordsXYZD(coords, direction);
|
|
|
|
|
}
|