From 4554d6d88371414f0bf972fe64ae624c3ecb9d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 19 Jan 2022 16:54:57 +0200 Subject: [PATCH] Fix all uses of RideId --- src/openrct2-ui/WindowManager.cpp | 12 ++--- .../windows/EditorObjectiveOptions.cpp | 6 +-- src/openrct2-ui/windows/Guest.cpp | 4 +- src/openrct2-ui/windows/GuestList.cpp | 6 +-- src/openrct2-ui/windows/MazeConstruction.cpp | 2 +- src/openrct2-ui/windows/NewCampaign.cpp | 2 +- src/openrct2-ui/windows/Ride.cpp | 16 +++---- src/openrct2-ui/windows/RideConstruction.cpp | 4 +- src/openrct2-ui/windows/RideList.cpp | 2 +- src/openrct2-ui/windows/TrackDesignPlace.cpp | 2 +- src/openrct2/actions/ParkMarketingAction.cpp | 2 +- src/openrct2/actions/RideDemolishAction.cpp | 14 +++--- .../actions/RideEntranceExitPlaceAction.cpp | 4 +- .../actions/RideEntranceExitRemoveAction.cpp | 8 ++-- .../actions/RideSetAppearanceAction.cpp | 9 ++-- src/openrct2/actions/RideSetNameAction.cpp | 4 +- src/openrct2/actions/RideSetPriceAction.cpp | 10 ++-- src/openrct2/actions/RideSetSettingAction.cpp | 6 +-- src/openrct2/actions/RideSetStatusAction.cpp | 14 +++--- src/openrct2/actions/RideSetVehicleAction.cpp | 6 +-- src/openrct2/actions/TrackPlaceAction.cpp | 10 ++-- src/openrct2/entity/Guest.cpp | 20 ++++---- src/openrct2/interface/InteractiveConsole.cpp | 14 +++--- src/openrct2/management/NewsItem.cpp | 2 +- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 8 ++-- src/openrct2/rct12/RCT12.cpp | 2 +- src/openrct2/rct12/RCT12.h | 2 +- src/openrct2/rct2/S6Importer.cpp | 8 ++-- src/openrct2/ride/Ride.cpp | 47 ++++++++++--------- src/openrct2/ride/Ride.h | 14 +++--- src/openrct2/ride/RideConstruction.cpp | 4 +- src/openrct2/ride/RideConstruction.h | 2 +- src/openrct2/ride/RideRatings.cpp | 16 +++---- src/openrct2/ride/TrackDesign.h | 2 +- src/openrct2/ride/Vehicle.cpp | 10 ++-- src/openrct2/scripting/ScriptEngine.cpp | 2 +- .../scripting/bindings/entity/ScVehicle.cpp | 4 +- .../scripting/bindings/ride/ScRide.cpp | 2 +- .../scripting/bindings/world/ScMap.cpp | 2 +- .../bindings/world/ScTileElement.cpp | 12 ++--- 41 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 254767854d..5d3f4d978a 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -183,9 +183,9 @@ public: case WD_BANNER: return WindowBannerOpen(id); case WD_DEMOLISH_RIDE: - return WindowRideDemolishPromptOpen(get_ride(static_cast(id))); + return WindowRideDemolishPromptOpen(get_ride(RideId::FromUnderlying(id))); case WD_REFURBISH_RIDE: - return WindowRideRefurbishPromptOpen(get_ride(static_cast(id))); + return WindowRideRefurbishPromptOpen(get_ride(RideId::FromUnderlying(id))); case WD_NEW_CAMPAIGN: return WindowNewCampaignOpen(id); case WD_SIGN: @@ -263,7 +263,7 @@ public: } case WC_RIDE: { - const auto rideId = static_cast(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID)); + const auto rideId = RideId::FromUnderlying(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID)); auto ride = get_ride(rideId); return ride == nullptr ? nullptr : WindowRideMainOpen(ride); } @@ -365,13 +365,13 @@ public: if (w == nullptr || w->number != rideIndex) { window_close_construction_windows(); - _currentRideIndex = static_cast(rideIndex); + _currentRideIndex = RideId::FromUnderlying(rideIndex); OpenWindow(WC_RIDE_CONSTRUCTION); } else { ride_construction_invalidate_current_track(); - _currentRideIndex = static_cast(rideIndex); + _currentRideIndex = RideId::FromUnderlying(rideIndex); } break; } @@ -417,7 +417,7 @@ public: case INTENT_ACTION_INVALIDATE_VEHICLE_WINDOW: { auto vehicle = static_cast(intent.GetPointerExtra(INTENT_EXTRA_VEHICLE)); - auto w = window_find_by_number(WC_RIDE, EnumValue(vehicle->ride)); + auto* w = window_find_by_number(WC_RIDE, vehicle->ride.ToUnderlying()); if (w == nullptr) return; diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index 2f32668579..fc6990a260 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -973,7 +973,7 @@ static void WindowEditorObjectiveOptionsRidesUpdate(rct_window* w) { if (ride.IsRide()) { - w->list_item_positions[numItems] = EnumValue(ride.id); + w->list_item_positions[numItems] = ride.id.ToUnderlying(); numItems++; } } @@ -1006,7 +1006,7 @@ static void WindowEditorObjectiveOptionsRidesScrollmousedown( if (i < 0 || i >= w->no_list_items) return; - const auto rideId = static_cast(w->list_item_positions[i]); + const auto rideId = RideId::FromUnderlying(w->list_item_positions[i]); auto ride = get_ride(rideId); if (ride != nullptr) { @@ -1100,7 +1100,7 @@ static void WindowEditorObjectiveOptionsRidesScrollpaint(rct_window* w, rct_draw } // Checkbox mark - const auto rideId = static_cast(w->list_item_positions[i]); + const auto rideId = RideId::FromUnderlying(w->list_item_positions[i]); auto ride = get_ride(rideId); if (ride != nullptr) { diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 7baa68b471..4e7fa4c518 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1487,7 +1487,7 @@ void WindowGuestRidesUpdate(rct_window* w) { if (ride.IsRide() && guest->HasRidden(&ride)) { - w->list_item_positions[curr_list_position] = EnumValue(ride.id); + w->list_item_positions[curr_list_position] = ride.id.ToUnderlying(); curr_list_position++; } } @@ -1638,7 +1638,7 @@ void WindowGuestRidesScrollPaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t stringId = STR_WINDOW_COLOUR_2_STRINGID; } - const auto rideId = static_cast(w->list_item_positions[list_index]); + const auto rideId = RideId::FromUnderlying(w->list_item_positions[list_index]); auto ride = get_ride(rideId); if (ride != nullptr) { diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 0b458267f3..545912e2a1 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -185,7 +185,7 @@ public: { case GuestListFilterType::GuestsOnRide: { - auto guestRide = get_ride(static_cast(index)); + auto guestRide = get_ride(RideId::FromUnderlying(index)); if (guestRide != nullptr) { ft.Add( @@ -201,7 +201,7 @@ public: } case GuestListFilterType::GuestsInQueue: { - auto guestRide = get_ride(static_cast(index)); + auto guestRide = get_ride(RideId::FromUnderlying(index)); if (guestRide != nullptr) { ft.Add(STR_QUEUING_FOR); @@ -216,7 +216,7 @@ public: } case GuestListFilterType::GuestsThinkingAboutRide: { - auto guestRide = get_ride(static_cast(index)); + auto guestRide = get_ride(RideId::FromUnderlying(index)); if (guestRide != nullptr) { ft.Add(STR_NONE); diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index 51b1de3697..cc10083bf5 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -130,7 +130,7 @@ public: else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(currentRide->id)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, currentRide->id.ToUnderlying()); context_open_intent(&intent); } } diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index 83942d2676..65cd068d94 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -259,7 +259,7 @@ public: case WIDX_START_BUTTON: { auto gameAction = ParkMarketingAction( - campaign.campaign_type, static_cast(campaign.RideId), campaign.no_weeks); + campaign.campaign_type, campaign.RideId.ToUnderlying(), campaign.no_weeks); gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) { diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index be2efacdac..c4e99f1870 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1195,7 +1195,7 @@ static void WindowRideUpdateOverallView(Ride* ride) max.z = std::max(max.z, clearZ); } - const auto rideIndex = EnumValue(ride->id); + const auto rideIndex = ride->id.ToUnderlying(); if (rideIndex >= ride_overall_views.size()) { ride_overall_views.resize(rideIndex + 1); @@ -1267,7 +1267,7 @@ rct_window* WindowRideMainOpen(Ride* ride) return nullptr; } - rct_window* w = window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); + rct_window* w = window_bring_to_front_by_number(WC_RIDE, ride->id.ToUnderlying()); if (w == nullptr) { w = WindowRideOpen(ride); @@ -1308,7 +1308,7 @@ static rct_window* WindowRideOpenStation(Ride* ride, StationIndex stationIndex) if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) return WindowRideMainOpen(ride); - auto w = window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); + auto w = window_bring_to_front_by_number(WC_RIDE, ride->id.ToUnderlying()); if (w == nullptr) { w = WindowRideOpen(ride); @@ -1414,7 +1414,7 @@ rct_window* WindowRideOpenVehicle(Vehicle* vehicle) view++; } - rct_window* w = window_find_by_number(WC_RIDE, EnumValue(ride->id)); + rct_window* w = window_find_by_number(WC_RIDE, ride->id.ToUnderlying()); if (w != nullptr) { w->Invalidate(); @@ -1449,8 +1449,8 @@ rct_window* WindowRideOpenVehicle(Vehicle* vehicle) } } - w = openedPeepWindow ? window_find_by_number(WC_RIDE, EnumValue(ride->id)) - : window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); + w = openedPeepWindow ? window_find_by_number(WC_RIDE, ride->id.ToUnderlying()) + : window_bring_to_front_by_number(WC_RIDE, ride->id.ToUnderlying()); } if (w == nullptr) @@ -1559,7 +1559,7 @@ static void WindowRideAnchorBorderWidgets(rct_window* w) static std::optional GetStationIndexFromViewSelection(const rct_window& w) { - const auto* ride = get_ride(static_cast(w.number)); + const auto* ride = get_ride(RideId::FromUnderlying(w.number)); if (ride == nullptr) return std::nullopt; @@ -1727,7 +1727,7 @@ static void WindowRideMainMouseup(rct_window* w, rct_widgetindex widgetIndex) if (ride != nullptr) { ride_construct(ride); - if (window_find_by_number(WC_RIDE_CONSTRUCTION, EnumValue(ride->id)) != nullptr) + if (window_find_by_number(WC_RIDE_CONSTRUCTION, ride->id.ToUnderlying()) != nullptr) { window_close(w); } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index f9a063299a..5b4f87263a 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -228,7 +228,7 @@ static int32_t RideGetAlternativeType(Ride* ride) /* move to ride.c */ static void CloseRideWindowForConstruction(RideId rideId) { - rct_window* w = window_find_by_number(WC_RIDE, EnumValue(rideId)); + rct_window* w = window_find_by_number(WC_RIDE, rideId.ToUnderlying()); if (w != nullptr && w->page == 1) window_close(w); } @@ -351,7 +351,7 @@ static void WindowRideConstructionClose(rct_window* w) ride->SetToDefaultInspectionInterval(); auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(ride->id)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id.ToUnderlying()); context_open_intent(&intent); } else diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 948684517e..a70e8ce9de 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -407,7 +407,7 @@ public: else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex.ToUnderlying()); context_open_intent(&intent); } } diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index a7c73439f9..1ec0ebf457 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -350,7 +350,7 @@ static void WindowTrackPlaceTooldown(rct_window* w, rct_widgetindex widgetIndex, if (track_design_are_entrance_and_exit_placed()) { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(rideId)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, rideId.ToUnderlying()); context_open_intent(&intent); auto wnd = window_find_by_class(WC_TRACK_DESIGN_PLACE); window_close(wnd); diff --git a/src/openrct2/actions/ParkMarketingAction.cpp b/src/openrct2/actions/ParkMarketingAction.cpp index 57e81c936b..59dc0eec13 100644 --- a/src/openrct2/actions/ParkMarketingAction.cpp +++ b/src/openrct2/actions/ParkMarketingAction.cpp @@ -70,7 +70,7 @@ GameActions::Result ParkMarketingAction::Execute() const campaign.Flags = MarketingCampaignFlags::FIRST_WEEK; if (campaign.Type == ADVERTISING_CAMPAIGN_RIDE_FREE || campaign.Type == ADVERTISING_CAMPAIGN_RIDE) { - campaign.RideId = static_cast(_item); + campaign.RideId = RideId::FromUnderlying(_item); } else if (campaign.Type == ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE) { diff --git a/src/openrct2/actions/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index f12cceae80..afe6f3186c 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -60,7 +60,7 @@ GameActions::Result RideDemolishAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_DEMOLISH_RIDE, STR_NONE); } @@ -104,7 +104,7 @@ GameActions::Result RideDemolishAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_DEMOLISH_RIDE, STR_NONE); } @@ -131,7 +131,7 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride* ride) const ride_clear_leftover_entrances(ride); const auto rideId = ride->id; - News::DisableNewsItems(News::ItemType::Ride, EnumValue(rideId)); + News::DisableNewsItems(News::ItemType::Ride, rideId.ToUnderlying()); UnlinkAllBannersForRide(ride->id); @@ -157,9 +157,9 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride* ride) const gParkValue = GetContext()->GetGameState()->GetPark().CalculateParkValue(); // Close windows related to the demolished ride - window_close_by_number(WC_RIDE_CONSTRUCTION, EnumValue(rideId)); - window_close_by_number(WC_RIDE, EnumValue(rideId)); - window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, EnumValue(rideId)); + window_close_by_number(WC_RIDE_CONSTRUCTION, rideId.ToUnderlying()); + window_close_by_number(WC_RIDE, rideId.ToUnderlying()); + window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, rideId.ToUnderlying()); window_close_by_class(WC_NEW_CAMPAIGN); // Refresh windows that display the ride name @@ -277,7 +277,7 @@ GameActions::Result RideDemolishAction::RefurbishRide(Ride* ride) const res.Position = { location, tile_element_height(location) }; } - window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, EnumValue(_rideIndex)); + window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, _rideIndex.ToUnderlying()); return res; } diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp index 7ac999eac9..6c5da7146b 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp @@ -55,7 +55,7 @@ GameActions::Result RideEntranceExitPlaceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %d", EnumValue(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_NONE); } @@ -135,7 +135,7 @@ GameActions::Result RideEntranceExitPlaceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %d", EnumValue(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_NONE); } diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp index 9ee4c52611..893c2ea545 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp @@ -74,7 +74,7 @@ GameActions::Result RideEntranceExitRemoveAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride id %d for entrance/exit removal", EnumValue(_rideIndex)); + log_warning("Invalid ride id %u for entrance/exit removal", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -99,7 +99,7 @@ GameActions::Result RideEntranceExitRemoveAction::Query() const if (entranceElement == nullptr) { log_warning( - "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, EnumValue(_rideIndex), + "Track Element not found. x = %d, y = %d, ride = %u, station = %d", _loc.x, _loc.y, _rideIndex.ToUnderlying(), _stationNum); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -112,7 +112,7 @@ GameActions::Result RideEntranceExitRemoveAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride id %d for entrance/exit removal", EnumValue(_rideIndex)); + log_warning("Invalid ride id %u for entrance/exit removal", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -130,7 +130,7 @@ GameActions::Result RideEntranceExitRemoveAction::Execute() const if (entranceElement == nullptr) { log_warning( - "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, EnumValue(_rideIndex), + "Track Element not found. x = %d, y = %d, ride = %u, station = %d", _loc.x, _loc.y, _rideIndex.ToUnderlying(), _stationNum); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } diff --git a/src/openrct2/actions/RideSetAppearanceAction.cpp b/src/openrct2/actions/RideSetAppearanceAction.cpp index 862c6a0350..511484691f 100644 --- a/src/openrct2/actions/RideSetAppearanceAction.cpp +++ b/src/openrct2/actions/RideSetAppearanceAction.cpp @@ -21,8 +21,7 @@ #include "../ui/WindowManager.h" #include "../world/Park.h" -RideSetAppearanceAction::RideSetAppearanceAction( - RideId rideIndex, RideSetAppearanceType type, uint16_t value, uint32_t index) +RideSetAppearanceAction::RideSetAppearanceAction(RideId rideIndex, RideSetAppearanceType type, uint16_t value, uint32_t index) : _rideIndex(rideIndex) , _type(type) , _value(value) @@ -54,7 +53,7 @@ GameActions::Result RideSetAppearanceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -94,7 +93,7 @@ GameActions::Result RideSetAppearanceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -138,7 +137,7 @@ GameActions::Result RideSetAppearanceAction::Execute() const gfx_invalidate_screen(); break; } - window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); + window_invalidate_by_number(WC_RIDE, _rideIndex.ToUnderlying()); auto res = GameActions::Result(); if (!ride->overall_view.IsNull()) diff --git a/src/openrct2/actions/RideSetNameAction.cpp b/src/openrct2/actions/RideSetNameAction.cpp index 7f4cb158f0..db9a25678e 100644 --- a/src/openrct2/actions/RideSetNameAction.cpp +++ b/src/openrct2/actions/RideSetNameAction.cpp @@ -50,7 +50,7 @@ GameActions::Result RideSetNameAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE); } @@ -68,7 +68,7 @@ GameActions::Result RideSetNameAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE); } diff --git a/src/openrct2/actions/RideSetPriceAction.cpp b/src/openrct2/actions/RideSetPriceAction.cpp index 4bcf851c64..d51088e3c9 100644 --- a/src/openrct2/actions/RideSetPriceAction.cpp +++ b/src/openrct2/actions/RideSetPriceAction.cpp @@ -54,14 +54,14 @@ GameActions::Result RideSetPriceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -76,14 +76,14 @@ GameActions::Result RideSetPriceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); } @@ -180,7 +180,7 @@ void RideSetPriceAction::RideSetCommonPrice(ShopItem shopItem) const } if (invalidate) { - window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); + window_invalidate_by_number(WC_RIDE, ride.id.ToUnderlying()); } } } diff --git a/src/openrct2/actions/RideSetSettingAction.cpp b/src/openrct2/actions/RideSetSettingAction.cpp index fba3a41115..6d1c87b421 100644 --- a/src/openrct2/actions/RideSetSettingAction.cpp +++ b/src/openrct2/actions/RideSetSettingAction.cpp @@ -45,7 +45,7 @@ GameActions::Result RideSetSettingAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride: #%d.", EnumValue(_rideIndex)); + log_warning("Invalid ride: #%u.", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_OPERATING_MODE, STR_NONE); } @@ -155,7 +155,7 @@ GameActions::Result RideSetSettingAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride: #%d.", EnumValue(_rideIndex)); + log_warning("Invalid ride: #%u.", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_OPERATING_MODE, STR_NONE); } @@ -236,7 +236,7 @@ GameActions::Result RideSetSettingAction::Execute() const auto location = ride->overall_view.ToTileCentre(); res.Position = { location, tile_element_height(location) }; } - window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); + window_invalidate_by_number(WC_RIDE, _rideIndex.ToUnderlying()); return res; } diff --git a/src/openrct2/actions/RideSetStatusAction.cpp b/src/openrct2/actions/RideSetStatusAction.cpp index a2bf6ab907..6892bba763 100644 --- a/src/openrct2/actions/RideSetStatusAction.cpp +++ b/src/openrct2/actions/RideSetStatusAction.cpp @@ -60,7 +60,7 @@ GameActions::Result RideSetStatusAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", EnumValue(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); res.Error = GameActions::Status::InvalidParameters; res.ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; res.ErrorMessage = STR_NONE; @@ -69,7 +69,7 @@ GameActions::Result RideSetStatusAction::Query() const if (_status >= RideStatus::Count) { - log_warning("Invalid ride status %u for ride %u", EnumValue(_status), EnumValue(_rideIndex)); + log_warning("Invalid ride status %u for ride %u", EnumValue(_status), _rideIndex.ToUnderlying()); res.Error = GameActions::Status::InvalidParameters; res.ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; res.ErrorMessage = STR_NONE; @@ -121,7 +121,7 @@ GameActions::Result RideSetStatusAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); + log_warning("Invalid game command for ride %u", _rideIndex.ToUnderlying()); res.Error = GameActions::Status::InvalidParameters; res.ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; res.ErrorMessage = STR_NONE; @@ -156,7 +156,7 @@ GameActions::Result RideSetStatusAction::Execute() const ride->lifecycle_flags &= ~RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING; ride->race_winner = SPRITE_INDEX_NULL; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; - window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); + window_invalidate_by_number(WC_RIDE, _rideIndex.ToUnderlying()); break; case RideStatus::Simulating: { @@ -178,7 +178,7 @@ GameActions::Result RideSetStatusAction::Execute() const ride->last_issue_time = 0; ride->GetMeasurement(); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; - window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); + window_invalidate_by_number(WC_RIDE, _rideIndex.ToUnderlying()); break; } case RideStatus::Testing: @@ -197,7 +197,7 @@ GameActions::Result RideSetStatusAction::Execute() const // Fix #3183: Make sure we close the construction window so the ride finishes any editing code before opening // otherwise vehicles get added to the ride incorrectly (such as to a ghost station) - rct_window* constructionWindow = window_find_by_number(WC_RIDE_CONSTRUCTION, EnumValue(_rideIndex)); + rct_window* constructionWindow = window_find_by_number(WC_RIDE_CONSTRUCTION, _rideIndex.ToUnderlying()); if (constructionWindow != nullptr) { window_close(constructionWindow); @@ -225,7 +225,7 @@ GameActions::Result RideSetStatusAction::Execute() const ride->last_issue_time = 0; ride->GetMeasurement(); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; - window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); + window_invalidate_by_number(WC_RIDE, _rideIndex.ToUnderlying()); break; } default: diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index 54a6f3c7cd..5a9b351ab8 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -69,7 +69,7 @@ GameActions::Result RideSetVehicleAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, errTitle, STR_NONE); } @@ -126,7 +126,7 @@ GameActions::Result RideSetVehicleAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); return GameActions::Result(GameActions::Status::InvalidParameters, errTitle, STR_NONE); } @@ -200,7 +200,7 @@ GameActions::Result RideSetVehicleAction::Execute() const } auto intent = Intent(INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(_rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, _rideIndex.ToUnderlying()); context_broadcast_intent(&intent); gfx_invalidate_screen(); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 02b2bb4257..8bd29cbb21 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -70,14 +70,14 @@ GameActions::Result TrackPlaceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); + log_warning("Invalid ride for track placement, rideIndex = %d", _rideIndex.ToUnderlying()); return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE); } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); + log_warning("Invalid ride subtype for track placement, rideIndex = %d", _rideIndex.ToUnderlying()); return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE); } @@ -411,7 +411,7 @@ GameActions::Result TrackPlaceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); + log_warning("Invalid ride for track placement, rideIndex = %d", _rideIndex.ToUnderlying()); return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE); } @@ -419,7 +419,7 @@ GameActions::Result TrackPlaceAction::Execute() const rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); + log_warning("Invalid ride subtype for track placement, rideIndex = %d", _rideIndex.ToUnderlying()); return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE); } @@ -588,7 +588,7 @@ GameActions::Result TrackPlaceAction::Execute() const auto* trackElement = TileElementInsert(mapLoc, quarterTile.GetBaseQuarterOccupied()); if (trackElement == nullptr) { - log_warning("Cannot create track element for ride = %d", EnumValue(_rideIndex)); + log_warning("Cannot create track element for ride = %d", _rideIndex.ToUnderlying()); return GameActions::Result( GameActions::Status::NoFreeElements, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 91d09e90d3..d08113c5f2 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1838,7 +1838,7 @@ Ride* Guest::FindBestRideToGoOn() Ride* mostExcitingRide = nullptr; for (auto& ride : GetRideManager()) { - const auto rideIndex = EnumValue(ride.id); + const auto rideIndex = ride.id.ToUnderlying(); if (rideConsideration.size() > rideIndex && rideConsideration[rideIndex]) { if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL)) @@ -1870,7 +1870,7 @@ BitSet Guest::FindRidesToGoOn() { if (!HasRidden(&ride)) { - rideConsideration[EnumValue(ride.id)] = true; + rideConsideration[ride.id.ToUnderlying()] = true; } } } @@ -1893,7 +1893,7 @@ BitSet Guest::FindRidesToGoOn() auto rideIndex = trackElement->GetRideIndex(); if (rideIndex != RIDE_ID_NULL) { - rideConsideration[EnumValue(rideIndex)] = true; + rideConsideration[rideIndex.ToUnderlying()] = true; } } } @@ -1904,7 +1904,7 @@ BitSet Guest::FindRidesToGoOn() { if (ride.highest_drop_height > 66 || ride.excitement >= RIDE_RATING(8, 00)) { - rideConsideration[EnumValue(ride.id)] = true; + rideConsideration[ride.id.ToUnderlying()] = true; } } } @@ -3120,7 +3120,7 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co { if (predicate(ride)) { - rideConsideration[EnumValue(ride.id)] = true; + rideConsideration[ride.id.ToUnderlying()] = true; } } } @@ -3148,7 +3148,7 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co if (!predicate(*ride)) continue; - rideConsideration[EnumValue(ride->id)] = true; + rideConsideration[ride->id.ToUnderlying()] = true; } } } @@ -3159,7 +3159,7 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co size_t numPotentialRides = 0; for (auto& ride : GetRideManager()) { - if (rideConsideration[EnumValue(ride.id)]) + if (rideConsideration[ride.id.ToUnderlying()]) { if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL)) { @@ -3671,7 +3671,7 @@ void Guest::UpdateRideAdvanceThroughEntrance() ride->FormatNameTo(ft); if (gConfigNotifications.ride_warnings) { - News::AddItemToQueue(News::ItemType::Ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, EnumValue(CurrentRide), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, CurrentRide.ToUnderlying(), ft); } } @@ -3824,7 +3824,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride* ride) if (queueTime != ride->stations[CurrentRideStation].QueueTime) { ride->stations[CurrentRideStation].QueueTime = queueTime; - window_invalidate_by_number(WC_RIDE, EnumValue(CurrentRide)); + window_invalidate_by_number(WC_RIDE, CurrentRide.ToUnderlying()); } if (PeepFlags & PEEP_FLAGS_TRACKING) @@ -6824,7 +6824,7 @@ void Guest::InsertNewThought(PeepThoughtType thought_type, ShopItem shopItem) void Guest::InsertNewThought(PeepThoughtType thought_type, RideId rideId) { - InsertNewThought(thought_type, static_cast(rideId)); + InsertNewThought(thought_type, rideId.ToUnderlying()); } /** * diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 0db4bde6d5..0ef9aedee9 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -196,7 +196,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - int32_t res = set_operating_setting(static_cast(ride_index), RideSetSetting::RideType, type); + int32_t res = set_operating_setting(RideId::FromUnderlying(ride_index), RideSetSetting::RideType, type); if (res == MONEY32_UNDEFINED) { if (!gCheatsAllowArbitraryRideTypeChanges) @@ -226,7 +226,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(static_cast(ride_index)); + auto ride = get_ride(RideId::FromUnderlying(ride_index)); if (mode >= static_cast(RideMode::Count)) { console.WriteFormatLine("Invalid ride mode."); @@ -258,7 +258,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(static_cast(ride_index)); + auto ride = get_ride(RideId::FromUnderlying(ride_index)); if (mass <= 0) { console.WriteFormatLine("Friction value must be strictly positive"); @@ -296,7 +296,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(static_cast(ride_index)); + auto ride = get_ride(RideId::FromUnderlying(ride_index)); if (excitement <= 0) { console.WriteFormatLine("Excitement value must be strictly positive"); @@ -327,7 +327,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(static_cast(ride_index)); + auto ride = get_ride(RideId::FromUnderlying(ride_index)); if (intensity <= 0) { console.WriteFormatLine("Intensity value must be strictly positive"); @@ -358,7 +358,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(static_cast(ride_index)); + auto ride = get_ride(RideId::FromUnderlying(ride_index)); if (nausea <= 0) { console.WriteFormatLine("Nausea value must be strictly positive"); @@ -428,7 +428,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto rideSetPrice = RideSetPriceAction(static_cast(rideId), price, true); + auto rideSetPrice = RideSetPriceAction(RideId::FromUnderlying(rideId), price, true); GameActions::Execute(&rideSetPrice); } } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index a2864fd157..abc06f42ba 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -213,7 +213,7 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s { case News::ItemType::Ride: { - Ride* ride = get_ride(static_cast(subject)); + Ride* ride = get_ride(RideId::FromUnderlying(subject)); if (ride == nullptr || ride->overall_view.IsNull()) { break; diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index be6fbf246f..91dcef23ac 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -1363,7 +1363,7 @@ namespace OpenRCT2 { if (srcArray[i / 8] & (1 << (i % 8))) { - ridesBeenOn.push_back(static_cast(i)); + ridesBeenOn.push_back(RideId::FromUnderlying(i)); } } return ridesBeenOn; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 66139b6c6a..f7789918a7 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -775,7 +775,7 @@ namespace RCT1 { if (_s4.rides[i].type != RideType::Null) { - const auto rideId = static_cast(i); + const auto rideId = RideId::FromUnderlying(i); ImportRide(GetOrAllocateRide(rideId), &_s4.rides[i], rideId); } } @@ -2518,7 +2518,7 @@ namespace RCT1 { if (_s4.scenario_slot_index == SC_URBAN_PARK && _isScenario) { - const auto merryGoRoundId = static_cast(0); + const auto merryGoRoundId = RideId::FromUnderlying(0); // First, make the queuing peep exit for (auto peep : EntityList()) @@ -2704,13 +2704,13 @@ namespace RCT1 { auto* dst = CreateEntityAt<::Vehicle>(srcBase.sprite_index); auto* src = static_cast(&srcBase); - const auto* ride = get_ride(static_cast(src->ride)); + const auto* ride = get_ride(RideId::FromUnderlying(src->ride)); if (ride == nullptr) return; uint8_t vehicleEntryIndex = RCT1::GetVehicleSubEntryIndex(src->vehicle_type); - dst->ride = static_cast(src->ride); + dst->ride = RideId::FromUnderlying(src->ride); dst->ride_subtype = RCTEntryIndexToOpenRCT2EntryIndex(ride->subtype); dst->vehicle_type = vehicleEntryIndex; diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index 73e83ce140..76ce4ea95d 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -492,7 +492,7 @@ RideId RCT12RideIdToOpenRCT2RideId(const RCT12RideId rideId) if (rideId == RCT12_RIDE_ID_NULL) return RIDE_ID_NULL; - return static_cast(rideId); + return RideId::FromUnderlying(rideId); } static bool RCT12IsFormatChar(codepoint_t c) diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index ce7e833e10..b122afd3be 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -881,7 +881,7 @@ template std::vector RCT12GetRidesBeenOn(T* srcPeep) { if (srcPeep->rides_been_on[i / 8] & (1 << (i % 8))) { - ridesBeenOn.push_back(static_cast(i)); + ridesBeenOn.push_back(RideId::FromUnderlying(i)); } } return ridesBeenOn; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 71d1505b10..a23f5fecbb 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -566,7 +566,7 @@ namespace RCT2 auto src = &_s6.rides[index]; if (src->type != RIDE_TYPE_NULL) { - const auto rideId = static_cast(index); + const auto rideId = RideId::FromUnderlying(index); auto dst = GetOrAllocateRide(rideId); ImportRide(dst, src, rideId); } @@ -960,7 +960,7 @@ namespace RCT2 { if (src.ride_index != RCT12_RIDE_ID_NULL) { - const auto rideId = static_cast(src.ride_index); + const auto rideId = RideId::FromUnderlying(src.ride_index); auto ride = get_ride(rideId); if (ride != nullptr) { @@ -1098,7 +1098,7 @@ namespace RCT2 { if (sprite.unknown.sprite_identifier == RCT12SpriteIdentifier::Peep) { - if (sprite.peep.current_ride == static_cast(rideIndex) + if (sprite.peep.current_ride == static_cast(rideIndex.ToUnderlying()) && (static_cast(sprite.peep.state) == PeepState::OnRide || static_cast(sprite.peep.state) == PeepState::EnteringRide)) { @@ -1795,7 +1795,7 @@ namespace RCT2 dst->remaining_distance = src->remaining_distance; dst->velocity = src->velocity; dst->acceleration = src->acceleration; - dst->ride = static_cast(src->ride); + dst->ride = RideId::FromUnderlying(src->ride); dst->vehicle_type = src->vehicle_type; dst->colours = src->colours; dst->track_progress = src->track_progress; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 40552d5205..44e950a045 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -127,18 +127,20 @@ size_t RideManager::size() const RideManager::Iterator RideManager::begin() { - return RideManager::Iterator(*this, 0, _rides.size()); + const auto endIndex = static_cast(_rides.size()); + return RideManager::Iterator(*this, 0u, endIndex); } RideManager::Iterator RideManager::end() { - return RideManager::Iterator(*this, _rides.size(), _rides.size()); + const auto endIndex = static_cast(_rides.size()); + return RideManager::Iterator(*this, endIndex, endIndex); } RideId GetNextFreeRideId() { - size_t result = _rides.size(); - for (size_t i = 0; i < _rides.size(); i++) + auto result = static_cast(_rides.size()); + for (RideId::UnderlyingType i = 0; i < _rides.size(); i++) { if (_rides[i].type == RIDE_TYPE_NULL) { @@ -150,12 +152,12 @@ RideId GetNextFreeRideId() { return RIDE_ID_NULL; } - return static_cast(result); + return RideId::FromUnderlying(result); } Ride* GetOrAllocateRide(RideId index) { - const auto idx = static_cast(index); + const auto idx = index.ToUnderlying(); if (_rides.size() <= idx) { _rides.resize(idx + 1); @@ -168,7 +170,7 @@ Ride* GetOrAllocateRide(RideId index) Ride* get_ride(RideId index) { - const auto idx = static_cast(index); + const auto idx = index.ToUnderlying(); if (idx < _rides.size()) { auto& ride = _rides[idx]; @@ -1039,7 +1041,7 @@ void Ride::Update() // with the increased MAX_RIDES the update is tied to the first byte of the id this allows // for identical balance with vanilla. const auto updatingRideByte = static_cast((gCurrentTicks / 2) & 0xFF); - if (updatingRideByte == static_cast(id)) + if (updatingRideByte == static_cast(id.ToUnderlying())) ride_breakdown_status_update(this); } @@ -1522,7 +1524,7 @@ void ride_breakdown_add_news_item(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, EnumValue(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, ride->id.ToUnderlying(), ft); } } @@ -1549,7 +1551,7 @@ static void ride_breakdown_status_update(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_STILL_NOT_FIXED, EnumValue(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_STILL_NOT_FIXED, ride->id.ToUnderlying(), ft); } } } @@ -2237,7 +2239,7 @@ static void ride_entrance_exit_connected(Ride* ride) ride->FormatNameTo(ft); if (gConfigNotifications.ride_warnings) { - News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, EnumValue(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, ride->id.ToUnderlying(), ft); } ride->connected_message_throttle = 3; } @@ -2249,7 +2251,7 @@ static void ride_entrance_exit_connected(Ride* ride) ride->FormatNameTo(ft); if (gConfigNotifications.ride_warnings) { - News::AddItemToQueue(News::ItemType::Ride, STR_EXIT_NOT_CONNECTED, EnumValue(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_EXIT_NOT_CONNECTED, ride->id.ToUnderlying(), ft); } ride->connected_message_throttle = 3; } @@ -2318,7 +2320,7 @@ static void ride_shop_connected(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, EnumValue(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, ride->id.ToUnderlying(), ft); } ride->connected_message_throttle = 3; @@ -3858,13 +3860,13 @@ bool Ride::Test(RideStatus newStatus, bool isApplying) if (type == RIDE_TYPE_NULL) { - log_warning("Invalid ride type for ride %u", EnumValue(id)); + log_warning("Invalid ride type for ride %u", id.ToUnderlying()); return false; } if (newStatus != RideStatus::Simulating) { - window_close_by_number(WC_RIDE_CONSTRUCTION, EnumValue(id)); + window_close_by_number(WC_RIDE_CONSTRUCTION, id.ToUnderlying()); } StationIndex stationIndex = ride_mode_check_station_present(this); @@ -3991,10 +3993,10 @@ bool Ride::Open(bool isApplying) // to set the track to its final state and clean up ghosts. // We can't just call close as it would cause a stack overflow during shop creation // with auto open on. - if (WC_RIDE_CONSTRUCTION == gCurrentToolWidget.window_classification && EnumValue(id) == gCurrentToolWidget.window_number + if (WC_RIDE_CONSTRUCTION == gCurrentToolWidget.window_classification && id.ToUnderlying() == gCurrentToolWidget.window_number && (input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) { - window_close_by_number(WC_RIDE_CONSTRUCTION, EnumValue(id)); + window_close_by_number(WC_RIDE_CONSTRUCTION, id.ToUnderlying()); } StationIndex stationIndex = ride_mode_check_station_present(this); @@ -4700,7 +4702,7 @@ void invalidate_test_results(Ride* ride) } } } - window_invalidate_by_number(WC_RIDE, static_cast(ride->id)); + window_invalidate_by_number(WC_RIDE, ride->id.ToUnderlying()); } /** @@ -5133,7 +5135,7 @@ void Ride::UpdateMaxVehicles() { num_cars_per_train = numCarsPerTrain; num_vehicles = numVehicles; - window_invalidate_by_number(WC_RIDE, EnumValue(id)); + window_invalidate_by_number(WC_RIDE, id.ToUnderlying()); } } @@ -5202,7 +5204,7 @@ void Ride::Crash(uint8_t vehicleIndex) { Formatter ft; FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, EnumValue(id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, id.ToUnderlying(), ft); } } @@ -5802,7 +5804,7 @@ std::vector GetTracklessRides() auto trackEl = it.element->AsTrack(); if (trackEl != nullptr && !trackEl->IsGhost()) { - auto rideId = static_cast(trackEl->GetRideIndex()); + auto rideId = trackEl->GetRideIndex().ToUnderlying(); if (rideId >= seen.size()) { seen.resize(rideId + 1); @@ -5816,7 +5818,8 @@ std::vector GetTracklessRides() std::vector result; for (const auto& ride : rideManager) { - if (seen.size() <= static_cast(ride.id) || !seen[static_cast(ride.id)]) + const auto rideIndex = ride.id.ToUnderlying(); + if (seen.size() <= rideIndex || !seen[rideIndex]) { result.push_back(ride.id); } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index a6aa349fb0..29137fca0e 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -888,8 +888,8 @@ struct RideManager private: RideManager* _rideManager; - size_t _index{}; - size_t _endIndex{}; + RideId::UnderlyingType _index{}; + RideId::UnderlyingType _endIndex{}; public: using difference_type = intptr_t; @@ -901,10 +901,10 @@ struct RideManager private: Iterator(RideManager& rideManager, size_t beginIndex, size_t endIndex) : _rideManager(&rideManager) - , _index(beginIndex) - , _endIndex(endIndex) + , _index(static_cast(beginIndex)) + , _endIndex(static_cast(endIndex)) { - if (_index < _endIndex && (*_rideManager)[static_cast(_index)] == nullptr) + if (_index < _endIndex && (*_rideManager)[RideId::FromUnderlying(_index)] == nullptr) { ++(*this); } @@ -916,7 +916,7 @@ struct RideManager do { _index++; - } while (_index < _endIndex && (*_rideManager)[static_cast(_index)] == nullptr); + } while (_index < _endIndex && (*_rideManager)[RideId::FromUnderlying(_index)] == nullptr); return *this; } Iterator operator++(int) @@ -935,7 +935,7 @@ struct RideManager } Ride& operator*() { - return *(*_rideManager)[static_cast(_index)]; + return *(*_rideManager)[RideId::FromUnderlying(_index)]; } }; diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 59517e9e32..d8dd456703 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -126,7 +126,7 @@ static rct_window* ride_create_or_find_construction_window(RideId rideIndex) { auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto intent = Intent(INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS); - intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex.ToUnderlying()); windowManager->BroadcastIntent(intent); return window_find_by_class(WC_RIDE_CONSTRUCTION); } @@ -243,7 +243,7 @@ void ride_clear_for_construction(Ride* ride) ride->RemoveVehicles(); ride_clear_blocked_tiles(ride); - auto w = window_find_by_number(WC_RIDE, EnumValue(ride->id)); + auto w = window_find_by_number(WC_RIDE, ride->id.ToUnderlying()); if (w != nullptr) window_event_resize_call(w); } diff --git a/src/openrct2/ride/RideConstruction.h b/src/openrct2/ride/RideConstruction.h index b1baa5616c..3417f1b0fd 100644 --- a/src/openrct2/ride/RideConstruction.h +++ b/src/openrct2/ride/RideConstruction.h @@ -9,6 +9,7 @@ #pragma once +#include "../Identifiers.h" #include "../common.h" #include "../world/Location.hpp" #include "Station.h" @@ -17,7 +18,6 @@ #include using track_type_t = uint16_t; -enum class RideId : uint16_t; struct TileElement; struct CoordsXYE; diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index a131c39397..804356c8c6 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -160,20 +160,18 @@ static void ride_ratings_update_state(RideRatingUpdateState& state) */ static void ride_ratings_update_state_0(RideRatingUpdateState& state) { - RideId currentRide = state.CurrentRide; - - currentRide = static_cast(EnumValue(currentRide) + 1); - if (currentRide >= static_cast(OpenRCT2::Limits::MaxRidesInPark)) + auto nextRide = RideId::FromUnderlying(state.CurrentRide.ToUnderlying() + 1); + if (nextRide.ToUnderlying() >= OpenRCT2::Limits::MaxRidesInPark) { - currentRide = {}; + nextRide = {}; } - auto ride = get_ride(currentRide); + auto ride = get_ride(nextRide); if (ride != nullptr && ride->status != RideStatus::Closed && !(ride->lifecycle_flags & RIDE_LIFECYCLE_FIXED_RATINGS)) { state.State = RIDE_RATINGS_STATE_INITIALISE; } - state.CurrentRide = currentRide; + state.CurrentRide = nextRide; } /** @@ -288,7 +286,7 @@ static void ride_ratings_update_state_3(RideRatingUpdateState& state) ride_ratings_calculate(state, ride); ride_ratings_calculate_value(ride); - window_invalidate_by_number(WC_RIDE, EnumValue(state.CurrentRide)); + window_invalidate_by_number(WC_RIDE, state.CurrentRide.ToUnderlying()); state.State = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; } @@ -753,7 +751,7 @@ static void ride_ratings_calculate(RideRatingUpdateState& state, Ride* ride) // Create event args object auto obj = DukObject(ctx); - obj.Set("rideId", EnumValue(ride->id)); + obj.Set("rideId", ride->id.ToUnderlying()); obj.Set("excitement", originalExcitement); obj.Set("intensity", originalIntensity); obj.Set("nausea", originalNausea); diff --git a/src/openrct2/ride/TrackDesign.h b/src/openrct2/ride/TrackDesign.h index 9dee4ce1bd..fb50db872a 100644 --- a/src/openrct2/ride/TrackDesign.h +++ b/src/openrct2/ride/TrackDesign.h @@ -208,7 +208,7 @@ enum MAZE_ELEMENT_TYPE_EXIT = (1 << 7) }; -static constexpr RideId PreviewRideId = static_cast(0); +static constexpr RideId PreviewRideId = RideId::FromUnderlying(0); extern bool gTrackDesignSceneryToggle; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f4497570de..98048d854a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1427,7 +1427,7 @@ void Vehicle::UpdateMeasurements() curRide->lifecycle_flags |= RIDE_LIFECYCLE_NO_RAW_STATS; curRide->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; ClearUpdateFlag(VEHICLE_UPDATE_FLAG_TESTING); - window_invalidate_by_number(WC_RIDE, EnumValue(ride)); + window_invalidate_by_number(WC_RIDE, ride.ToUnderlying()); return; } @@ -2937,7 +2937,7 @@ static void test_finish(Ride& ride) totalTime = std::max(totalTime, 1u); ride.average_speed = ride.average_speed / totalTime; - window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); + window_invalidate_by_number(WC_RIDE, ride.id.ToUnderlying()); } void Vehicle::UpdateTestFinish() @@ -2987,7 +2987,7 @@ static void test_reset(Ride& ride, StationIndex curStation) } ride.total_air_time = 0; ride.current_test_station = curStation; - window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); + window_invalidate_by_number(WC_RIDE, ride.id.ToUnderlying()); } void Vehicle::TestReset() @@ -3393,7 +3393,7 @@ void Vehicle::CheckIfMissing() curRide->FormatNameTo(ft); ft.Add(GetRideComponentName(GetRideTypeDescriptor(curRide->type).NameConvention.station).singular); - News::AddItemToQueue(News::ItemType::Ride, STR_NEWS_VEHICLE_HAS_STALLED, EnumValue(ride), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_NEWS_VEHICLE_HAS_STALLED, ride.ToUnderlying(), ft); } } @@ -5127,7 +5127,7 @@ static void ride_train_crash(Ride* ride, uint16_t numFatalities) { ride->FormatNameTo(ft); News::AddItemToQueue( - News::ItemType::Ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, EnumValue(ride->id), + News::ItemType::Ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, ride->id.ToUnderlying(), ft); } diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index b5f79f831f..c3dd1e68b7 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -892,7 +892,7 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const Gam if (result.Error == GameActions::Status::Ok) { const auto rideIndex = result.GetData(); - obj.Set("ride", EnumValue(rideIndex)); + obj.Set("ride", rideIndex.ToUnderlying()); } } else if (action.GetType() == GameCommand::HireNewStaffMember) diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp index 82cc5ea551..6e3ecded33 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp @@ -138,7 +138,7 @@ namespace OpenRCT2::Scripting int32_t ScVehicle::ride_get() const { auto vehicle = GetVehicle(); - return EnumValue(vehicle != nullptr ? vehicle->ride : RIDE_ID_NULL); + return (vehicle != nullptr ? vehicle->ride : RIDE_ID_NULL).ToUnderlying(); } void ScVehicle::ride_set(int32_t value) { @@ -146,7 +146,7 @@ namespace OpenRCT2::Scripting auto vehicle = GetVehicle(); if (vehicle != nullptr) { - vehicle->ride = static_cast(value); + vehicle->ride = RideId::FromUnderlying(value); } } diff --git a/src/openrct2/scripting/bindings/ride/ScRide.cpp b/src/openrct2/scripting/bindings/ride/ScRide.cpp index b0f7b211a4..6e83c7d850 100644 --- a/src/openrct2/scripting/bindings/ride/ScRide.cpp +++ b/src/openrct2/scripting/bindings/ride/ScRide.cpp @@ -27,7 +27,7 @@ namespace OpenRCT2::Scripting int32_t ScRide::id_get() const { - return EnumValue(_rideId); + return _rideId.ToUnderlying(); } std::shared_ptr ScRide::object_get() diff --git a/src/openrct2/scripting/bindings/world/ScMap.cpp b/src/openrct2/scripting/bindings/world/ScMap.cpp index 3cb2c7f535..dec9bec14d 100644 --- a/src/openrct2/scripting/bindings/world/ScMap.cpp +++ b/src/openrct2/scripting/bindings/world/ScMap.cpp @@ -69,7 +69,7 @@ namespace OpenRCT2::Scripting std::shared_ptr ScMap::getRide(int32_t id) const { auto rideManager = GetRideManager(); - auto ride = rideManager[static_cast(id)]; + auto ride = rideManager[RideId::FromUnderlying(id)]; if (ride != nullptr) { return std::make_shared(ride->id); diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 590c7bd3ad..d152c87d28 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -452,7 +452,7 @@ namespace OpenRCT2::Scripting { auto el = _element->AsPath(); if (el->IsQueue() && el->GetRideIndex() != RIDE_ID_NULL) - duk_push_int(ctx, EnumValue(el->GetRideIndex())); + duk_push_int(ctx, el->GetRideIndex().ToUnderlying()); else duk_push_null(ctx); break; @@ -460,13 +460,13 @@ namespace OpenRCT2::Scripting case TileElementType::Track: { auto el = _element->AsTrack(); - duk_push_int(ctx, EnumValue(el->GetRideIndex())); + duk_push_int(ctx, el->GetRideIndex().ToUnderlying()); break; } case TileElementType::Entrance: { auto el = _element->AsEntrance(); - duk_push_int(ctx, EnumValue(el->GetRideIndex())); + duk_push_int(ctx, el->GetRideIndex().ToUnderlying()); break; } default: @@ -488,7 +488,7 @@ namespace OpenRCT2::Scripting if (el->IsQueue()) { if (value.type() == DukValue::Type::NUMBER) - el->SetRideIndex(static_cast(value.as_uint())); + el->SetRideIndex(RideId::FromUnderlying(value.as_uint())); else el->SetRideIndex(RIDE_ID_NULL); Invalidate(); @@ -500,7 +500,7 @@ namespace OpenRCT2::Scripting if (value.type() == DukValue::Type::NUMBER) { auto el = _element->AsTrack(); - el->SetRideIndex(static_cast(value.as_uint())); + el->SetRideIndex(RideId::FromUnderlying(value.as_uint())); Invalidate(); } break; @@ -510,7 +510,7 @@ namespace OpenRCT2::Scripting if (value.type() == DukValue::Type::NUMBER) { auto el = _element->AsEntrance(); - el->SetRideIndex(static_cast(value.as_uint())); + el->SetRideIndex(RideId::FromUnderlying(value.as_uint())); Invalidate(); } break;