From 355019f97f7508b042ee00976c8c057ba7c8ecf1 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Tue, 14 Sep 2021 19:36:58 -0400 Subject: [PATCH] #15367: Encode RideType in TrackElement --- src/openrct2-ui/windows/RideConstruction.cpp | 1 + src/openrct2/actions/MazePlaceTrackAction.cpp | 1 + src/openrct2/actions/MazeSetTrackAction.cpp | 1 + src/openrct2/actions/TrackPlaceAction.cpp | 1 + src/openrct2/rct1/S4Importer.cpp | 1 + src/openrct2/rct2/S6Importer.cpp | 3 ++- src/openrct2/ride/Track.cpp | 12 ++++++++++++ src/openrct2/ride/TrackPaint.cpp | 4 +++- src/openrct2/world/TileElement.h | 7 ++++++- 9 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 6d252746dc..13ad0e23de 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2444,6 +2444,7 @@ static void sub_6CBCE2( _tempTrackTileElement.SetBaseZ(baseZ); _tempTrackTileElement.SetClearanceZ(clearanceZ); _tempTrackTileElement.AsTrack()->SetTrackType(trackType); + _tempTrackTileElement.AsTrack()->SetRideType(ride->type); _tempTrackTileElement.AsTrack()->SetSequenceIndex(trackBlock->index); _tempTrackTileElement.AsTrack()->SetHasCableLift(false); _tempTrackTileElement.AsTrack()->SetInverted((liftHillAndInvertedState & CONSTRUCTION_INVERTED_TRACK_SELECTED) != 0); diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index c62e469524..a2e01c3642 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -168,6 +168,7 @@ GameActions::Result::Ptr MazePlaceTrackAction::Execute() const trackElement->SetClearanceZ(clearanceHeight); trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); trackElement->SetRideIndex(_rideIndex); trackElement->SetMazeEntry(_mazeEntry); trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index 19e38f95d0..3605a425d7 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -183,6 +183,7 @@ GameActions::Result::Ptr MazeSetTrackAction::Execute() const trackElement->SetClearanceZ(_loc.z + MAZE_CLEARANCE_HEIGHT); trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); trackElement->SetRideIndex(_rideIndex); trackElement->SetMazeEntry(0xFFFF); trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index f0fc1898cb..39b508c804 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -561,6 +561,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const trackElement->SetSequenceIndex(trackBlock->index); trackElement->SetRideIndex(_rideIndex); trackElement->SetTrackType(_trackType); + trackElement->SetRideType(ride->type); trackElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); switch (_trackType) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 6916c69a81..a4a7e1cc1d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1631,6 +1631,7 @@ namespace RCT1 auto rideType = (ride != nullptr) ? ride->type : RIDE_TYPE_NULL; dst2->SetTrackType(RCT1TrackTypeToOpenRCT2(src2->GetTrackType(), rideType)); + dst2->SetRideType(rideType); dst2->SetSequenceIndex(src2->GetSequenceIndex()); dst2->SetRideIndex(RCT12RideIdToOpenRCT2RideId(src2->GetRideIndex())); dst2->SetColourScheme(src2->GetColourScheme()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 5c7c7145a4..de66b3eede 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1198,7 +1198,8 @@ public: auto rideType = _s6.rides[src2->GetRideIndex()].type; track_type_t trackType = static_cast(src2->GetTrackType()); - dst2->SetTrackType(RCT2TrackTypeToOpenRCT2(trackType, _s6.rides[src2->GetRideIndex()].type)); + dst2->SetTrackType(RCT2TrackTypeToOpenRCT2(trackType, rideType)); + dst2->SetRideType(rideType); dst2->SetSequenceIndex(src2->GetSequenceIndex()); dst2->SetRideIndex(RCT12RideIdToOpenRCT2RideId(src2->GetRideIndex())); dst2->SetColourScheme(src2->GetColourScheme()); diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index c7996973a1..cb90d20660 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -244,6 +244,7 @@ bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flag targetTrackType = TrackElemType::MiddleStation; } stationElement->AsTrack()->SetTrackType(targetTrackType); + stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(loc, stationElement); @@ -389,6 +390,7 @@ bool track_remove_station_element(const CoordsXYZD& loc, ride_id_t rideIndex, in } } stationElement->AsTrack()->SetTrackType(targetTrackType); + stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(currentLoc, stationElement); } @@ -730,6 +732,16 @@ void TrackElement::SetTrackType(uint16_t newType) TrackType = newType; } +uint8_t TrackElement::GetRideType() const +{ + return RideType; +} + +void TrackElement::SetRideType(const uint8_t rideType) +{ + RideType = rideType; +} + uint8_t TrackElement::GetSequenceIndex() const { return Sequence; diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index b2529b4da2..259a6e89d7 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -2276,7 +2276,9 @@ void PaintTrack(paint_session* session, Direction direction, int32_t height, con { return; } - TRACK_PAINT_FUNCTION_GETTER paintFunctionGetter = ride->GetRideTypeDescriptor().TrackPaintFunction; + + const auto& rtd = GetRideTypeDescriptor(trackElement.GetRideType()); + TRACK_PAINT_FUNCTION_GETTER paintFunctionGetter = rtd.TrackPaintFunction; if (paintFunctionGetter != nullptr) { TRACK_PAINT_FUNCTION paintFunction = paintFunctionGetter(trackType); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 68f289c8ce..ecea23c948 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -380,13 +380,18 @@ private: ride_id_t RideIndex; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad[2]; + // uint8_t pad[2]; + uint8_t RideType; + uint8_t pad; #pragma clang diagnostic pop public: track_type_t GetTrackType() const; void SetTrackType(track_type_t newEntryIndex); + uint8_t GetRideType() const; + void SetRideType(const uint8_t rideType); + uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex);