Skip to content

Commit

Permalink
Merge pull request #15414 from frutiemax/develop
Browse files Browse the repository at this point in the history
#15367: Encode RideType in TrackElement
  • Loading branch information
Gymnasiast committed Sep 25, 2021
2 parents a8b8498 + 8fb8b2a commit 1feac16
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/openrct2-ui/windows/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 15 additions & 12 deletions src/openrct2-ui/windows/TileInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rct_string_id>(ride->GetRideTypeDescriptor().Naming.Name);
DrawTextBasic(dpi, screenCoords, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE });
}

// Ride ID
auto ft = Formatter();
ft.Add<int16_t>(trackElement->GetRideIndex());
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 11 }, STR_TILE_INSPECTOR_TRACK_RIDE_ID, ft, { COLOUR_WHITE });
ft.Add<int16_t>(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.
const auto& rtd = GetRideTypeDescriptor(trackElement->GetRideType());
ft = Formatter();
ft.Add<rct_string_id>(rtd.Naming.Name);
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE });

// Track
ft = Formatter();
ft.Add<track_type_t>(trackElement->GetTrackType());
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/actions/MazePlaceTrackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/actions/MazeSetTrackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/actions/TrackPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,8 @@ class S6Importer final : public IParkImporter
auto rideType = _s6.rides[src2->GetRideIndex()].type;
track_type_t trackType = static_cast<track_type_t>(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());
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/ride/RideTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct Ride;

constexpr const ride_id_t RIDE_ID_NULL = static_cast<ride_id_t>(std::numeric_limits<std::underlying_type_t<ride_id_t>>::max());

using ride_type_t = uint16_t;

/**
* Couples a ride type and subtype together.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/openrct2/ride/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,16 @@ void TrackElement::SetTrackType(uint16_t newType)
TrackType = newType;
}

ride_type_t TrackElement::GetRideType() const
{
return RideType;
}

void TrackElement::SetRideType(const ride_type_t rideType)
{
RideType = rideType;
}

uint8_t TrackElement::GetSequenceIndex() const
{
return Sequence;
Expand Down
4 changes: 3 additions & 1 deletion src/openrct2/ride/TrackPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,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);
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/world/TileElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ struct TrackElement : TileElementBase
};
uint8_t Flags2;
ride_id_t RideIndex;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
uint8_t pad[2];
#pragma clang diagnostic pop
ride_type_t RideType;

public:
track_type_t GetTrackType() const;
void SetTrackType(track_type_t newEntryIndex);

ride_type_t GetRideType() const;
void SetRideType(const ride_type_t rideType);

uint8_t GetSequenceIndex() const;
void SetSequenceIndex(uint8_t newSequenceIndex);

Expand Down

0 comments on commit 1feac16

Please sign in to comment.