Skip to content

Commit

Permalink
Track Archetype Proof-Of-Concept
Browse files Browse the repository at this point in the history
  • Loading branch information
spacek531 committed Jan 19, 2025
1 parent 68789ec commit 3bb71b8
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 66 deletions.
24 changes: 15 additions & 9 deletions src/openrct2-ui/windows/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,8 @@ namespace OpenRCT2::Ui::Windows
Direction currentDirection = _currentTrackPieceDirection;
OpenRCT2::TrackElemType type = _currentTrackPieceType;
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, type, 0, &tileElement, 0);
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, GetSimplifiedTrackType(type),
GetTrackArchetype(type), 0, &tileElement, 0);
if (!newCoords.has_value())
{
WindowRideConstructionUpdateActiveElements();
Expand Down Expand Up @@ -2382,7 +2383,8 @@ namespace OpenRCT2::Ui::Windows
direction = _currentTrackPieceDirection;
type = _currentTrackPieceType;
newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, type, 0, &tileElement, 0);
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, GetSimplifiedTrackType(type),
GetTrackArchetype(type), 0, &tileElement, 0);

if (!newCoords.has_value())
{
Expand Down Expand Up @@ -2510,8 +2512,9 @@ namespace OpenRCT2::Ui::Windows
TileElement* tileElement;

if (GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) }, _currentTrackPieceType, 0,
&tileElement, 0)
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) },
GetSimplifiedTrackType(_currentTrackPieceType), GetTrackArchetype(_currentTrackPieceType), 0, &tileElement,
0)
!= std::nullopt)
{
auto trackSetBrakeSpeed = TrackSetBrakeSpeedAction(
Expand Down Expand Up @@ -2565,8 +2568,9 @@ namespace OpenRCT2::Ui::Windows
void RideSelectedTrackSetSeatRotation(int32_t seatRotation)
{
GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) }, _currentTrackPieceType,
seatRotation, nullptr, TRACK_ELEMENT_SET_SEAT_ROTATION);
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) },
GetSimplifiedTrackType(_currentTrackPieceType), GetTrackArchetype(_currentTrackPieceType), seatRotation,
nullptr, TRACK_ELEMENT_SET_SEAT_ROTATION);
WindowRideConstructionUpdateActiveElements();
}

Expand Down Expand Up @@ -3089,8 +3093,9 @@ namespace OpenRCT2::Ui::Windows
{
TileElement* tileElement;
if (GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) }, _currentTrackPieceType, 0,
&tileElement, 0)
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) },
GetSimplifiedTrackType(_currentTrackPieceType), GetTrackArchetype(_currentTrackPieceType), 0, &tileElement,
0)
!= std::nullopt)
{
_selectedTrackType = tileElement->AsTrack()->GetTrackType();
Expand Down Expand Up @@ -3212,7 +3217,8 @@ namespace OpenRCT2::Ui::Windows
uint16_t flags = _currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ARROW ? TRACK_ELEMENT_SET_HIGHLIGHT_TRUE
: TRACK_ELEMENT_SET_HIGHLIGHT_FALSE;
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction) }, type, 0, nullptr, flags);
{ _currentTrackBegin, static_cast<Direction>(direction) }, GetSimplifiedTrackType(type),
GetTrackArchetype(type), 0, nullptr, flags);
if (!newCoords.has_value())
{
RideConstructionRemoveGhosts();
Expand Down
9 changes: 6 additions & 3 deletions src/openrct2/actions/RideSetColourSchemeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ GameActions::Result RideSetColourSchemeAction::Query() const
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_SET_COLOUR_SCHEME, STR_OFF_EDGE_OF_MAP);
}
// Find the relevant track piece, prefer sequence 0 (logic copied from GetTrackElementOriginAndApplyChanges)
auto trackElement = MapGetTrackElementAtOfTypeSeq(_loc, _trackType, 0);
auto trackElement = MapGetTrackElementAtOfTypeSeqArchetype(
_loc, GetSimplifiedTrackType(_trackType), GetTrackArchetype(_trackType), 0);
if (trackElement == nullptr)
{
trackElement = MapGetTrackElementAtOfType(_loc, _trackType);
Expand All @@ -77,8 +78,10 @@ GameActions::Result RideSetColourSchemeAction::Execute() const
GameActions::Result res = GameActions::Result();
res.Expenditure = ExpenditureType::RideConstruction;
res.ErrorTitle = STR_CANT_SET_COLOUR_SCHEME;

GetTrackElementOriginAndApplyChanges(_loc, _trackType, _newColourScheme, nullptr, TRACK_ELEMENT_SET_COLOUR_SCHEME);
// TODO: Update this after proof-of-concept
GetTrackElementOriginAndApplyChanges(
_loc, GetSimplifiedTrackType(_trackType), GetTrackArchetype(_trackType), _newColourScheme, nullptr,
TRACK_ELEMENT_SET_COLOUR_SCHEME);

return res;
}
7 changes: 5 additions & 2 deletions src/openrct2/actions/TrackSetBrakeSpeedAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ GameActions::Result TrackSetBrakeSpeedAction::QueryExecute(bool isExecuting) con
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_THIS, STR_OFF_EDGE_OF_MAP);
}

TileElement* tileElement = MapGetTrackElementAtOfType(_loc, _trackType);
TileElement* tileElement = MapGetTrackElementAtOfTypeArchetype(
_loc, GetSimplifiedTrackType(_trackType), GetTrackArchetype(_trackType));
if (tileElement == nullptr)
{
LOG_ERROR("Track element of type %u not found at x = %d, y = %d, z = %d", _trackType, _loc.x, _loc.y, _loc.z);
Expand All @@ -80,8 +81,10 @@ GameActions::Result TrackSetBrakeSpeedAction::QueryExecute(bool isExecuting) con

if (isExecuting)
{
// TODO: Update this after proof-of-concept
GetTrackElementOriginAndApplyChanges(
{ _loc, tileElement->GetDirection() }, tileElement->AsTrack()->GetTrackType(), _brakeSpeed, nullptr,
{ _loc, tileElement->GetDirection() }, GetSimplifiedTrackType(tileElement->AsTrack()->GetTrackType()),
GetTrackArchetype(tileElement->AsTrack()->GetTrackType()), _brakeSpeed, nullptr,
TRACK_ELEMENT_SET_BRAKE_BOOSTER_SPEED);
}
return res;
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,9 @@ namespace OpenRCT2::RCT2
// ride is on. It's possible to create unwanted behavior if a user layers spinning control track on top of
// booster track but this is unlikely since only two rides have spinning control track - by default they load as
// booster.
TileElement* tileElement2 = MapGetTrackElementAtOfTypeSeq(
dst->TrackLocation, TrackElemType::RotationControlToggle, 0);
TileElement* tileElement2 = MapGetTrackElementAtOfTypeSeqArchetype(
dst->TrackLocation, GetSimplifiedTrackType(TrackElemType::RotationControlToggle), GetTrackArchetype(TrackElemType::RotationControlToggle),
0);

if (tileElement2 != nullptr)
dst->SetTrackType(TrackElemType::RotationControlToggle);
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/ride/CableLift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards()
uint16_t trackTotalProgress = GetTrackProgress();
if (trackProgress >= trackTotalProgress)
{
TileElement* trackElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, trackType, 0);
TileElement* trackElement = MapGetTrackElementAtOfTypeSeqArchetype(
TrackLocation, GetSimplifiedTrackType(trackType), GetTrackArchetype(trackType), 0);

CoordsXYE output;
int32_t outputZ;
Expand Down Expand Up @@ -312,7 +313,8 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
if (static_cast<int16_t>(trackProgress) == -1)
{
auto trackType = GetTrackType();
TileElement* trackElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, trackType, 0);
TileElement* trackElement = MapGetTrackElementAtOfTypeSeqArchetype(
TrackLocation, GetSimplifiedTrackType(trackType), GetTrackArchetype(trackType), 0);

auto input = CoordsXYE{ TrackLocation, trackElement };
TrackBeginEnd output;
Expand Down
15 changes: 10 additions & 5 deletions src/openrct2/ride/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,8 @@ static void RideSetBoatHireReturnPoint(Ride& ride, const CoordsXYE& startElement
int32_t direction = trackBeginEnd.begin_direction;
trackType = trackBeginEnd.begin_element->AsTrack()->GetTrackType();
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ trackCoords, static_cast<Direction>(direction) }, trackType, 0, &returnPos.element, 0);
{ trackCoords, static_cast<Direction>(direction) }, GetSimplifiedTrackType(trackType), GetTrackArchetype(trackType),
0, &returnPos.element, 0);
returnPos = newCoords.has_value() ? CoordsXYE{ newCoords.value(), returnPos.element }
: CoordsXYE{ trackCoords, returnPos.element };
};
Expand Down Expand Up @@ -3056,7 +3057,8 @@ void SetBrakeClosedMultiTile(TrackElement& trackElement, const CoordsXY& trackLo
case TrackElemType::DiagBrakes:
case TrackElemType::DiagBlockBrakes:
GetTrackElementOriginAndApplyChanges(
{ trackLocation, trackElement.GetBaseZ(), trackElement.GetDirection() }, trackElement.GetTrackType(), isClosed,
{ trackLocation, trackElement.GetBaseZ(), trackElement.GetDirection() },
GetSimplifiedTrackType(trackElement.GetTrackType()), GetTrackArchetype(trackElement.GetTrackType()), isClosed,
nullptr, TRACK_ELEMENT_SET_BRAKE_CLOSED_STATE);
break;
default:
Expand All @@ -3074,6 +3076,7 @@ static void RideOpenBlockBrakes(const CoordsXYE& startElement)
do
{
auto trackType = currentElement.element->AsTrack()->GetTrackType();
// TODO: Update this after proof-of-concept
switch (trackType)
{
case TrackElemType::BlockBrakes:
Expand Down Expand Up @@ -3541,8 +3544,9 @@ static void RideCreateVehiclesFindFirstBlock(const Ride& ride, CoordsXYE* outXYE
[[fallthrough]];
case TrackElemType::DiagBlockBrakes:
{
TileElement* tileElement = MapGetTrackElementAtOfTypeSeq(
{ trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }, trackType, 0);
TileElement* tileElement = MapGetTrackElementAtOfTypeSeqArchetype(
{ trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }, GetSimplifiedTrackType(trackType),
GetTrackArchetype(trackType), 0);

if (tileElement != nullptr)
{
Expand Down Expand Up @@ -3859,7 +3863,8 @@ static ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool isA
auto tmpLoc = CoordsXYZ{ it.current, tileElement->GetBaseZ() };
auto direction = tileElement->GetDirection();
trackType = tileElement->AsTrack()->GetTrackType();
GetTrackElementOriginAndApplyChanges({ tmpLoc, direction }, trackType, 0, &tileElement, flags);
GetTrackElementOriginAndApplyChanges(
{ tmpLoc, direction }, GetSimplifiedTrackType(trackType), GetTrackArchetype(trackType), 0, &tileElement, flags);
}
}
return { true };
Expand Down
25 changes: 15 additions & 10 deletions src/openrct2/ride/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ void RideClearBlockedTiles(const Ride& ride)
* bp : flags
*/
std::optional<CoordsXYZ> GetTrackElementOriginAndApplyChanges(
const CoordsXYZD& location, OpenRCT2::TrackElemType type, uint16_t extra_params, TileElement** output_element,
uint16_t flags)
const CoordsXYZD& location, OpenRCT2::TrackElemType type, OpenRCT2::TrackArchetype archetype, uint16_t extra_params,
TileElement** output_element, uint16_t flags)
{
// Find the relevant track piece, prefer sequence 0 (this ensures correct behaviour for diagonal track pieces)
auto trackElement = MapGetTrackElementAtOfTypeSeq(location, type, 0);
auto trackElement = MapGetTrackElementAtOfTypeSeqArchetype(location, type, archetype, 0);
if (trackElement == nullptr)
{
trackElement = MapGetTrackElementAtOfType(location, type);
trackElement = MapGetTrackElementAtOfTypeArchetype(location, type, archetype);
if (trackElement == nullptr)
{
return std::nullopt;
Expand Down Expand Up @@ -423,7 +423,8 @@ std::optional<CoordsXYZ> GetTrackElementOriginAndApplyChanges(

MapInvalidateTileFull(cur);

trackElement = MapGetTrackElementAtOfTypeSeq({ cur, cur_z, static_cast<Direction>(location.direction) }, type, i);
trackElement = MapGetTrackElementAtOfTypeSeqArchetype(
{ cur, cur_z, static_cast<Direction>(location.direction) }, type, archetype, i);
if (trackElement == nullptr)
{
return std::nullopt;
Expand Down Expand Up @@ -502,8 +503,9 @@ void RideConstructionInvalidateCurrentTrack()
{
case RideConstructionState::Selected:
GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) }, _currentTrackPieceType, 0,
nullptr, TRACK_ELEMENT_SET_HIGHLIGHT_FALSE);
{ _currentTrackBegin, static_cast<Direction>(_currentTrackPieceDirection & 3) },
GetSimplifiedTrackType(_currentTrackPieceType), GetTrackArchetype(_currentTrackPieceType), 0, nullptr,
TRACK_ELEMENT_SET_HIGHLIGHT_FALSE);
break;
case RideConstructionState::MazeBuild:
case RideConstructionState::MazeMove:
Expand Down Expand Up @@ -707,7 +709,8 @@ void RideSelectNextSection()
auto type = _currentTrackPieceType;
TileElement* tileElement;
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, type, 0, &tileElement, 0);
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, GetSimplifiedTrackType(type),
GetTrackArchetype(type), 0, &tileElement, 0);
if (!newCoords.has_value())
{
_rideConstructionState = RideConstructionState::State0;
Expand Down Expand Up @@ -765,7 +768,8 @@ void RideSelectPreviousSection()
auto type = _currentTrackPieceType;
TileElement* tileElement;
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, type, 0, &tileElement, 0);
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, GetSimplifiedTrackType(type),
GetTrackArchetype(type), 0, &tileElement, 0);
if (newCoords == std::nullopt)
{
_rideConstructionState = RideConstructionState::State0;
Expand Down Expand Up @@ -980,7 +984,8 @@ bool RideModify(const CoordsXYE& input)
auto tileCoords = CoordsXYZ{ tileElement, tileElement.element->GetBaseZ() };
auto direction = tileElement.element->GetDirection();
auto type = tileElement.element->AsTrack()->GetTrackType();
auto newCoords = GetTrackElementOriginAndApplyChanges({ tileCoords, direction }, type, 0, nullptr, 0);
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ tileCoords, direction }, GetSimplifiedTrackType(type), GetTrackArchetype(type), 0, nullptr, 0);
if (!newCoords.has_value())
return false;

Expand Down
79 changes: 78 additions & 1 deletion src/openrct2/ride/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,9 @@ TrackElement* TrackGetPreviousBlock(CoordsXYZ& location, TileElement* tileElemen

// 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);
auto trackOrigin = MapGetTrackElementAtOfTypeSeqArchetype(
location, GetSimplifiedTrackType(trackBeginEnd.begin_element->AsTrack()->GetTrackType()), GetTrackArchetype(trackBeginEnd.begin_element->AsTrack()->GetTrackType()),
0);
if (trackOrigin == nullptr)
{
return nullptr;
Expand Down Expand Up @@ -778,3 +780,78 @@ std::optional<CoordsXYZD> GetTrackSegmentOrigin(const CoordsXYE& posEl)

return CoordsXYZD(coords, direction);
}

TrackArchetype GetTrackArchetype(TrackElemType trackType)
{
TrackArchetype archetype;
archetype = TrackArchetype::normal;
if (TrackTypeIsBrakes(trackType))
archetype = TrackArchetype::brake;
if (TrackTypeIsBlockBrakes(trackType))
archetype = TrackArchetype::blockBrake;
if (TrackTypeIsBooster(trackType))
archetype = TrackArchetype::booster;
if (TrackElementIsCovered(trackType))
archetype = static_cast<TrackArchetype>(EnumValue(archetype) + EnumValue(TrackArchetype::covered));

return archetype;
}

TrackElemType GetSimplifiedTrackType(TrackElemType trackType)
{
switch (trackType)
{
case TrackElemType::Booster:
case TrackElemType::Brakes:
case TrackElemType::BlockBrakes:
case TrackElemType::FlatCovered:
return TrackElemType::Flat;

case TrackElemType::DiagBooster:
case TrackElemType::DiagBrakes:
case TrackElemType::DiagBlockBrakes:
return TrackElemType::DiagFlat;

case TrackElemType::Down25Brakes:
case TrackElemType::Down25Covered:
return TrackElemType::Down25;

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::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 trackType;
}
}
Loading

0 comments on commit 3bb71b8

Please sign in to comment.