Skip to content

Commit

Permalink
Turn TrackElemType into a strong enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Oct 1, 2024
1 parent 1719bbd commit 995f82e
Show file tree
Hide file tree
Showing 137 changed files with 1,356 additions and 946 deletions.
2 changes: 1 addition & 1 deletion src/openrct2-ui/ride/Construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace OpenRCT2
&& state != RideConstructionState::Back)
return list;

for (track_type_t trackType : DropdownOrder)
for (OpenRCT2::TrackElemType trackType : DropdownOrder)
{
const auto& ted = GetTrackElementDescriptor(trackType);
if (!IsTrackEnabled(ted.definition.group))
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/ride/Construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace OpenRCT2
constexpr size_t DropdownLength = DropdownOrder.size();

// Update the magic number with the current number of track elements to silence
static_assert(TrackElemType::Count == 339, "Reminder to add new track element to special dropdown list");
static_assert(EnumValue(TrackElemType::Count) == 339, "Reminder to add new track element to special dropdown list");

constexpr bool TrackPieceDirectionIsDiagonal(const uint8_t direction)
{
Expand All @@ -150,7 +150,7 @@ namespace OpenRCT2

struct SpecialElement
{
track_type_t TrackType;
OpenRCT2::TrackElemType TrackType;
bool Disabled;
};

Expand Down
2 changes: 1 addition & 1 deletion src/openrct2-ui/windows/NewRide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ namespace OpenRCT2::Ui::Windows
if (!(GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY))
{
// Get price of ride
int32_t startPieceId = GetRideTypeDescriptor(item.Type).StartTrackPiece;
auto startPieceId = GetRideTypeDescriptor(item.Type).StartTrackPiece;
money64 price = GetRideTypeDescriptor(item.Type).BuildCosts.TrackPrice;
const auto& ted = GetTrackElementDescriptor(startPieceId);
price *= ted.priceModifier;
Expand Down
84 changes: 49 additions & 35 deletions src/openrct2-ui/windows/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ namespace OpenRCT2::Ui::Windows
static RideConstructionState _rideConstructionState2;

static bool WindowRideConstructionUpdateState(
int32_t* trackType, int32_t* trackDirection, RideId* rideIndex, SelectedLiftAndInverted* _liftHillAndAlternativeState,
CoordsXYZ* trackPos, int32_t* properties);
OpenRCT2::TrackElemType* trackType, int32_t* trackDirection, RideId* rideIndex,
SelectedLiftAndInverted* _liftHillAndAlternativeState, CoordsXYZ* trackPos, int32_t* properties);
money64 PlaceProvisionalTrackPiece(
RideId rideIndex, int32_t trackType, int32_t trackDirection, SelectedLiftAndInverted liftHillAndAlternativeState,
const CoordsXYZ& trackPos);
static std::pair<bool, track_type_t> WindowRideConstructionUpdateStateGetTrackElement();
RideId rideIndex, OpenRCT2::TrackElemType trackType, int32_t trackDirection,
SelectedLiftAndInverted liftHillAndAlternativeState, const CoordsXYZ& trackPos);
static std::pair<bool, OpenRCT2::TrackElemType> WindowRideConstructionUpdateStateGetTrackElement();

static constexpr StringId WINDOW_TITLE = STR_RIDE_CONSTRUCTION_WINDOW_TITLE;
static constexpr int32_t WH = 394;
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace OpenRCT2::Ui::Windows
STR_RIDE_CONSTRUCTION_SEAT_ROTATION_ANGLE_450, STR_RIDE_CONSTRUCTION_SEAT_ROTATION_ANGLE_495,
};

static void WindowRideConstructionMouseUpDemolishNextPiece(const CoordsXYZD& piecePos, int32_t type);
static void WindowRideConstructionMouseUpDemolishNextPiece(const CoordsXYZD& piecePos, OpenRCT2::TrackElemType type);
static void WindowRideConstructionUpdateActiveElements();

/* move to ride.c */
Expand Down Expand Up @@ -946,6 +946,8 @@ namespace OpenRCT2::Ui::Windows
case TrackElemType::Waterfall:
WidgetInvalidate(*this, WIDX_CONSTRUCT);
break;
default:
break;
}
}

Expand Down Expand Up @@ -1452,7 +1454,7 @@ namespace OpenRCT2::Ui::Windows

RideConstructionInvalidateCurrentTrack();
_currentTrackPrice = kMoney64Undefined;
track_type_t trackPiece = _specialElementDropdownState.Elements[selectedIndex].TrackType;
OpenRCT2::TrackElemType trackPiece = _specialElementDropdownState.Elements[selectedIndex].TrackType;
switch (trackPiece)
{
case TrackElemType::EndStation:
Expand All @@ -1468,6 +1470,8 @@ namespace OpenRCT2::Ui::Windows
case TrackElemType::BlockBrakes:
case TrackElemType::DiagBlockBrakes:
_currentBrakeSpeed = kRCT2DefaultBlockBrakeSpeed;
default:
break;
}
_currentlySelectedTrack = trackPiece;
WindowRideConstructionUpdateActiveElements();
Expand Down Expand Up @@ -1602,7 +1606,8 @@ namespace OpenRCT2::Ui::Windows
return;

RideId rideIndex;
int32_t trackType, trackDirection;
OpenRCT2::TrackElemType trackType;
int32_t trackDirection;
SelectedLiftAndInverted liftHillAndInvertedState{};
if (WindowRideConstructionUpdateState(
&trackType, &trackDirection, &rideIndex, &liftHillAndInvertedState, nullptr, nullptr))
Expand Down Expand Up @@ -2158,7 +2163,8 @@ namespace OpenRCT2::Ui::Windows

void UpdateMapSelection()
{
int32_t trackType, trackDirection;
OpenRCT2::TrackElemType trackType;
int32_t trackDirection;
CoordsXYZ trackPos{};

MapInvalidateMapSelectionTiles();
Expand All @@ -2169,7 +2175,7 @@ namespace OpenRCT2::Ui::Windows
{
case RideConstructionState::State0:
trackDirection = _currentTrackPieceDirection;
trackType = 0;
trackType = TrackElemType::Flat;
trackPos = _currentTrackBegin;
break;
case RideConstructionState::Selected:
Expand All @@ -2184,7 +2190,7 @@ namespace OpenRCT2::Ui::Windows
if (WindowRideConstructionUpdateState(&trackType, &trackDirection, nullptr, nullptr, &trackPos, nullptr))
{
trackDirection = _currentTrackPieceDirection;
trackType = 0;
trackType = OpenRCT2::TrackElemType::Flat;
trackPos = _currentTrackBegin;
}
break;
Expand All @@ -2197,7 +2203,7 @@ namespace OpenRCT2::Ui::Windows
}
}

void SelectMapTiles(int32_t trackType, int32_t trackDirection, const CoordsXY& tileCoords)
void SelectMapTiles(OpenRCT2::TrackElemType trackType, int32_t trackDirection, const CoordsXY& tileCoords)
{
// If the scenery tool is active, we do not display our tiles as it
// will conflict with larger scenery objects selecting tiles
Expand All @@ -2222,7 +2228,8 @@ namespace OpenRCT2::Ui::Windows
void Construct()
{
RideId rideIndex;
int32_t trackType, trackDirection, properties;
OpenRCT2::TrackElemType trackType;
int32_t trackDirection, properties;
SelectedLiftAndInverted liftHillAndAlternativeState{};
CoordsXYZ trackPos{};

Expand Down Expand Up @@ -2327,7 +2334,7 @@ namespace OpenRCT2::Ui::Windows
direction = _currentTrackPieceDirection;
// The direction is reset by ride_initialise_construction_window(), but we need it to remove flat rides properly.
Direction currentDirection = _currentTrackPieceDirection;
track_type_t type = _currentTrackPieceType;
OpenRCT2::TrackElemType type = _currentTrackPieceType;
auto newCoords = GetTrackElementOriginAndApplyChanges(
{ _currentTrackBegin, static_cast<Direction>(direction & 3) }, type, 0, &tileElement, 0);
if (!newCoords.has_value())
Expand Down Expand Up @@ -2508,7 +2515,7 @@ namespace OpenRCT2::Ui::Windows
int32_t defaultIndex = -1;
for (size_t i = 0; i < _specialElementDropdownState.Elements.size(); i++)
{
track_type_t trackPiece = _specialElementDropdownState.Elements[i].TrackType;
OpenRCT2::TrackElemType trackPiece = _specialElementDropdownState.Elements[i].TrackType;

const auto& ted = GetTrackElementDescriptor(trackPiece);
StringId trackPieceStringId = ted.description;
Expand Down Expand Up @@ -2595,7 +2602,7 @@ namespace OpenRCT2::Ui::Windows
}

void DrawTrackPiece(
DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection,
DrawPixelInfo& dpi, RideId rideIndex, OpenRCT2::TrackElemType trackType, int32_t trackDirection,
SelectedLiftAndInverted liftHillAndInvertedState, int32_t widgetWidth, int32_t widgetHeight)
{
auto currentRide = GetRide(rideIndex);
Expand Down Expand Up @@ -2631,7 +2638,7 @@ namespace OpenRCT2::Ui::Windows
}

void DrawTrackPieceHelper(
DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection,
DrawPixelInfo& dpi, RideId rideIndex, OpenRCT2::TrackElemType trackType, int32_t trackDirection,
SelectedLiftAndInverted liftHillAndInvertedState, const CoordsXY& originCoords, int32_t originZ)
{
TileElement tempSideTrackTileElement{ 0x80, 0x8F, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Expand Down Expand Up @@ -3104,7 +3111,8 @@ namespace OpenRCT2::Ui::Windows
void UpdateGhostTrackAndArrow()
{
RideId rideIndex;
int32_t direction, type;
int32_t direction;
OpenRCT2::TrackElemType type;
SelectedLiftAndInverted liftHillAndAlternativeState{};
CoordsXYZ trackPos{};

Expand Down Expand Up @@ -3261,7 +3269,8 @@ namespace OpenRCT2::Ui::Windows
gMapSelectionTiles.push_back(*mapCoords);

RideId rideIndex;
int32_t trackType, trackDirection;
OpenRCT2::TrackElemType trackType;
int32_t trackDirection;
SelectedLiftAndInverted liftHillAndAlternativeState{};
if (WindowRideConstructionUpdateState(
&trackType, &trackDirection, &rideIndex, &liftHillAndAlternativeState, nullptr, nullptr))
Expand Down Expand Up @@ -3502,7 +3511,8 @@ namespace OpenRCT2::Ui::Windows
RideConstructionInvalidateCurrentTrack();

CoordsXYZ mapCoords{};
int32_t trackType, z, highestZ;
OpenRCT2::TrackElemType trackType;
int32_t z, highestZ;

if (WindowRideConstructionUpdateState(&trackType, nullptr, nullptr, nullptr, nullptr, nullptr))
return;
Expand Down Expand Up @@ -4580,7 +4590,7 @@ namespace OpenRCT2::Ui::Windows
w->OnMouseDown(WIDX_DEMOLISH);
}

static void WindowRideConstructionMouseUpDemolishNextPiece(const CoordsXYZD& piecePos, int32_t type)
static void WindowRideConstructionMouseUpDemolishNextPiece(const CoordsXYZD& piecePos, OpenRCT2::TrackElemType type)
{
if (_gotoStartPlacementMode)
{
Expand Down Expand Up @@ -4664,8 +4674,8 @@ namespace OpenRCT2::Ui::Windows
* rct2: 0x006CA162
*/
money64 PlaceProvisionalTrackPiece(
RideId rideIndex, int32_t trackType, int32_t trackDirection, SelectedLiftAndInverted liftHillAndAlternativeState,
const CoordsXYZ& trackPos)
RideId rideIndex, OpenRCT2::TrackElemType trackType, int32_t trackDirection,
SelectedLiftAndInverted liftHillAndAlternativeState, const CoordsXYZ& trackPos)
{
auto ride = GetRide(rideIndex);
if (ride == nullptr)
Expand Down Expand Up @@ -4736,7 +4746,7 @@ namespace OpenRCT2::Ui::Windows
return res.Cost;
}

static std::pair<bool, track_type_t> WindowRideConstructionUpdateStateGetTrackElement()
static std::pair<bool, OpenRCT2::TrackElemType> WindowRideConstructionUpdateStateGetTrackElement()
{
auto startSlope = _previousTrackPitchEnd;
auto endSlope = _currentTrackPitchEnd;
Expand All @@ -4754,7 +4764,7 @@ namespace OpenRCT2::Ui::Windows
auto selectedTrack = _currentlySelectedTrack;
if (selectedTrack == TrackElemType::None)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}

bool startsDiagonal = (_currentTrackPieceDirection & (1 << 2)) != 0;
Expand All @@ -4773,7 +4783,7 @@ namespace OpenRCT2::Ui::Windows
if (trackPiece != TrackElemType::None)
return std::make_pair(true, trackPiece);
else
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}

auto asTrackType = selectedTrack.trackType;
Expand All @@ -4784,12 +4794,12 @@ namespace OpenRCT2::Ui::Windows
case TrackElemType::SBendRight:
if (startSlope != TrackPitch::None || endSlope != TrackPitch::None)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}

if (startBank != TrackRoll::None || endBank != TrackRoll::None)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}

return std::make_pair(true, asTrackType);
Expand All @@ -4798,21 +4808,21 @@ namespace OpenRCT2::Ui::Windows
case TrackElemType::RightVerticalLoop:
if (startBank != TrackRoll::None || endBank != TrackRoll::None)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}

if (_rideConstructionState == RideConstructionState::Back)
{
if (endSlope != TrackPitch::Down25)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}
}
else
{
if (startSlope != TrackPitch::Up25)
{
return std::make_pair(false, 0);
return std::make_pair(false, OpenRCT2::TrackElemType::Flat);
}
}

Expand All @@ -4837,8 +4847,8 @@ namespace OpenRCT2::Ui::Windows
* @return (CF)
*/
static bool WindowRideConstructionUpdateState(
int32_t* _trackType, int32_t* _trackDirection, RideId* _rideIndex, SelectedLiftAndInverted* _liftHillAndInvertedState,
CoordsXYZ* _trackPos, int32_t* _properties)
OpenRCT2::TrackElemType* _trackType, int32_t* _trackDirection, RideId* _rideIndex,
SelectedLiftAndInverted* _liftHillAndInvertedState, CoordsXYZ* _trackPos, int32_t* _properties)
{
RideId rideIndex;
uint8_t trackDirection;
Expand All @@ -4853,7 +4863,7 @@ namespace OpenRCT2::Ui::Windows
return true;
}

track_type_t trackType = std::get<1>(updated_element);
OpenRCT2::TrackElemType trackType = std::get<1>(updated_element);
rideIndex = _currentRideIndex;
if (_currentTrackHasLiftHill)
{
Expand Down Expand Up @@ -4894,6 +4904,9 @@ namespace OpenRCT2::Ui::Windows
case TrackElemType::DiagFlatToDown60:
case TrackElemType::DiagDown60ToFlat:
return true;

default:
break;
}
}

Expand Down Expand Up @@ -5000,7 +5013,8 @@ namespace OpenRCT2::Ui::Windows
if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK)
{
RideId rideIndex;
int32_t direction, type;
int32_t direction;
OpenRCT2::TrackElemType type;
SelectedLiftAndInverted liftHillAndAlternativeState{};
CoordsXYZ trackPos;
if (WindowRideConstructionUpdateState(
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/windows/TileInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,12 @@ static uint64_t PageDisabledWidgets[] = {

// Track
ft = Formatter();
ft.Add<track_type_t>(trackElement->GetTrackType());
ft.Add<uint16_t>(trackElement->GetTrackType());
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 33 }, STR_TILE_INSPECTOR_TRACK_PIECE_ID, ft, { colours[1] });

ft = Formatter();
ft.Add<track_type_t>(trackElement->GetSequenceIndex());
ft.Add<uint16_t>(trackElement->GetSequenceIndex());
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 44 }, STR_TILE_INSPECTOR_TRACK_SEQUENCE, ft, { colours[1] });
if (trackElement->IsStation())
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/actions/RideSetColourSchemeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using namespace OpenRCT2;

RideSetColourSchemeAction::RideSetColourSchemeAction(
const CoordsXYZD& location, track_type_t trackType, uint16_t newColourScheme)
const CoordsXYZD& location, OpenRCT2::TrackElemType trackType, uint16_t newColourScheme)
: _loc(location)
, _trackType(trackType)
, _newColourScheme(newColourScheme)
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/RideSetColourSchemeAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class RideSetColourSchemeAction final : public GameActionBase<GameCommand::SetCo
{
private:
CoordsXYZD _loc;
track_type_t _trackType{};
OpenRCT2::TrackElemType _trackType{};
uint16_t _newColourScheme{};

public:
RideSetColourSchemeAction() = default;
RideSetColourSchemeAction(const CoordsXYZD& location, track_type_t trackType, uint16_t newColourScheme);
RideSetColourSchemeAction(const CoordsXYZD& location, OpenRCT2::TrackElemType trackType, uint16_t newColourScheme);

void AcceptParameters(GameActionParameterVisitor& visitor) override;

Expand Down
Loading

0 comments on commit 995f82e

Please sign in to comment.