From 355019f97f7508b042ee00976c8c057ba7c8ecf1 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Tue, 14 Sep 2021 19:36:58 -0400 Subject: [PATCH 1/5] #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); From f21b941b462219dc5db93faf170f5d1b81382b9a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 21:02:24 +0200 Subject: [PATCH 2/5] Introduce ride_type_t --- src/openrct2/ride/RideTypes.h | 2 ++ src/openrct2/ride/Track.cpp | 4 ++-- src/openrct2/world/TileElement.h | 11 +++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/openrct2/ride/RideTypes.h b/src/openrct2/ride/RideTypes.h index 7d8b11b344..b9747b58c8 100644 --- a/src/openrct2/ride/RideTypes.h +++ b/src/openrct2/ride/RideTypes.h @@ -20,6 +20,8 @@ struct Ride; constexpr const ride_id_t RIDE_ID_NULL = static_cast(std::numeric_limits>::max()); +using ride_type_t = uint16_t; + /** * Couples a ride type and subtype together. */ diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index cb90d20660..b4550ba438 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -732,12 +732,12 @@ void TrackElement::SetTrackType(uint16_t newType) TrackType = newType; } -uint8_t TrackElement::GetRideType() const +ride_type_t TrackElement::GetRideType() const { return RideType; } -void TrackElement::SetRideType(const uint8_t rideType) +void TrackElement::SetRideType(const ride_type_t rideType) { RideType = rideType; } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index ecea23c948..893b3f06b5 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -378,19 +378,14 @@ private: }; uint8_t Flags2; ride_id_t RideIndex; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" - // uint8_t pad[2]; - uint8_t RideType; - uint8_t pad; -#pragma clang diagnostic pop + ride_type_t RideType; public: track_type_t GetTrackType() const; void SetTrackType(track_type_t newEntryIndex); - uint8_t GetRideType() const; - void SetRideType(const uint8_t rideType); + ride_type_t GetRideType() const; + void SetRideType(const ride_type_t rideType); uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); From 1e17304e766b285fae0880f332bd06f1b3e00135 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 21:10:40 +0200 Subject: [PATCH 3/5] Show the appropriate ride type in the TI --- src/openrct2-ui/windows/TileInspector.cpp | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a128f0d6c4..05df9f2b03 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1928,28 +1928,31 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) case TILE_ELEMENT_TYPE_TRACK: { - // Details - // Ride auto trackElement = tileElement->AsTrack(); ride_id_t rideId = trackElement->GetRideIndex(); auto ride = get_ride(rideId); - if (ride != nullptr) - { - auto ft = Formatter(); - ft.Add(ride->GetRideTypeDescriptor().Naming.Name); - DrawTextBasic(dpi, screenCoords, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE }); - } + + // Ride ID auto ft = Formatter(); - ft.Add(trackElement->GetRideIndex()); - DrawTextBasic( - dpi, screenCoords + ScreenCoordsXY{ 0, 11 }, STR_TILE_INSPECTOR_TRACK_RIDE_ID, ft, { COLOUR_WHITE }); + ft.Add(rideId); + DrawTextBasic(dpi, screenCoords, STR_TILE_INSPECTOR_TRACK_RIDE_ID, ft, { COLOUR_WHITE }); + + // Ride name if (ride != nullptr) { ft = Formatter(); ride->FormatNameTo(ft); DrawTextBasic( - dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_TRACK_RIDE_NAME, ft, { COLOUR_WHITE }); + dpi, screenCoords + ScreenCoordsXY{ 0, 11 }, STR_TILE_INSPECTOR_TRACK_RIDE_NAME, ft, { COLOUR_WHITE }); } + + // Ride type. Individual pieces may be of a different ride type from the ride it belongs to. + auto rtd = GetRideTypeDescriptor(trackElement->GetRideType()); + ft = Formatter(); + ft.Add(rtd.Naming.Name); + DrawTextBasic( + dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE }); + // Track ft = Formatter(); ft.Add(trackElement->GetTrackType()); From 11607f525db1c7b9657b9764d413b5c31e552e34 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 23:01:47 +0200 Subject: [PATCH 4/5] const auto& --- src/openrct2-ui/windows/TileInspector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 05df9f2b03..656940b942 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1947,7 +1947,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) } // Ride type. Individual pieces may be of a different ride type from the ride it belongs to. - auto rtd = GetRideTypeDescriptor(trackElement->GetRideType()); + const auto& rtd = GetRideTypeDescriptor(trackElement->GetRideType()); ft = Formatter(); ft.Add(rtd.Naming.Name); DrawTextBasic( From 8fb8b2a4c1dde92fd06ceaec63b0404c206d2bde Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 21 Sep 2021 10:50:38 +0200 Subject: [PATCH 5/5] Do not overwrite ride type when extending station --- src/openrct2/ride/Track.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index b4550ba438..33406d53bb 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -244,7 +244,6 @@ 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); @@ -390,7 +389,6 @@ 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); }