From 49bbc0f8544dce4b09adb5a54a816372e40e367c Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 07:24:39 +0300 Subject: [PATCH 01/22] Turn ride_id_t into a strong type --- src/openrct2/ride/RideTypes.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/RideTypes.h b/src/openrct2/ride/RideTypes.h index 2a1567ad4b..7d8b11b344 100644 --- a/src/openrct2/ride/RideTypes.h +++ b/src/openrct2/ride/RideTypes.h @@ -13,11 +13,12 @@ #include #include +#include -using ride_id_t = uint16_t; +enum class ride_id_t : uint16_t; struct Ride; -constexpr const ride_id_t RIDE_ID_NULL = std::numeric_limits::max(); +constexpr const ride_id_t RIDE_ID_NULL = static_cast(std::numeric_limits>::max()); /** * Couples a ride type and subtype together. From 3ad72baaae388114f684a995c941a1d5c2fcb417 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 07:24:52 +0300 Subject: [PATCH 02/22] Cast fixes --- src/openrct2-ui/WindowManager.cpp | 13 +- .../windows/DemolishRidePrompt.cpp | 12 +- .../windows/EditorObjectiveOptions.cpp | 8 +- src/openrct2-ui/windows/Guest.cpp | 5 +- src/openrct2-ui/windows/GuestList.cpp | 6 +- src/openrct2-ui/windows/MazeConstruction.cpp | 6 +- src/openrct2-ui/windows/NewCampaign.cpp | 9 +- src/openrct2-ui/windows/Ride.cpp | 255 +++++++++--------- src/openrct2-ui/windows/RideConstruction.cpp | 10 +- src/openrct2-ui/windows/RideList.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2-ui/windows/TrackDesignPlace.cpp | 13 +- src/openrct2/actions/ParkMarketingAction.cpp | 2 +- src/openrct2/actions/RideDemolishAction.cpp | 18 +- .../actions/RideSetAppearanceAction.cpp | 2 +- src/openrct2/actions/RideSetPriceAction.cpp | 2 +- src/openrct2/actions/RideSetSettingAction.cpp | 2 +- src/openrct2/actions/RideSetStatusAction.cpp | 8 +- src/openrct2/actions/RideSetVehicleAction.cpp | 2 +- src/openrct2/interface/InteractiveConsole.cpp | 14 +- src/openrct2/management/NewsItem.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 4 +- src/openrct2/rct12/RCT12.cpp | 4 +- src/openrct2/ride/Ride.cpp | 40 +-- src/openrct2/ride/RideConstruction.cpp | 4 +- src/openrct2/ride/RideRatings.cpp | 10 +- src/openrct2/ride/TrackDesign.cpp | 9 +- src/openrct2/ride/Vehicle.cpp | 11 +- src/openrct2/scripting/ScriptEngine.cpp | 2 +- 29 files changed, 256 insertions(+), 221 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 850a2122ef..bdcb8a0c9a 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -184,9 +184,9 @@ public: case WD_BANNER: return window_banner_open(id); case WD_DEMOLISH_RIDE: - return window_ride_demolish_prompt_open(get_ride(id)); + return window_ride_demolish_prompt_open(get_ride(static_cast(id))); case WD_REFURBISH_RIDE: - return window_ride_refurbish_prompt_open(get_ride(id)); + return window_ride_refurbish_prompt_open(get_ride(static_cast(id))); case WD_NEW_CAMPAIGN: return window_new_campaign_open(id); case WD_SIGN: @@ -264,7 +264,8 @@ public: } case WC_RIDE: { - auto ride = get_ride(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID)); + const auto rideId = static_cast(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID)); + auto ride = get_ride(rideId); return ride == nullptr ? nullptr : window_ride_main_open(ride); } case WC_TRACK_DESIGN_PLACE: @@ -343,13 +344,13 @@ public: if (w == nullptr || w->number != rideIndex) { window_close_construction_windows(); - _currentRideIndex = rideIndex; + _currentRideIndex = static_cast(rideIndex); w = OpenWindow(WC_RIDE_CONSTRUCTION); } else { ride_construction_invalidate_current_track(); - _currentRideIndex = rideIndex; + _currentRideIndex = static_cast(rideIndex); } break; } @@ -395,7 +396,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, vehicle->ride); + auto w = window_find_by_number(WC_RIDE, static_cast(vehicle->ride)); if (w == nullptr) return; diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index 395bd145cf..88f61a5d8b 100644 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -84,7 +84,7 @@ rct_window* window_ride_demolish_prompt_open(Ride* ride) w->widgets = window_ride_demolish_widgets; w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); WindowInitScrollWidgets(w); - w->number = ride->id; + w->number = static_cast(ride->id); _demolishRideCost = -ride_get_refund_price(ride); return w; @@ -109,7 +109,7 @@ rct_window* window_ride_refurbish_prompt_open(Ride* ride) w->widgets = window_ride_refurbish_widgets; w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); WindowInitScrollWidgets(w); - w->number = ride->id; + w->number = static_cast(ride->id); _demolishRideCost = -ride_get_refund_price(ride); return w; @@ -125,7 +125,7 @@ static void window_ride_demolish_mouseup(rct_window* w, rct_widgetindex widgetIn { case WIDX_DEMOLISH: { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); ride_action_modify(ride, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY); break; } @@ -142,7 +142,7 @@ static void window_ride_refurbish_mouseup(rct_window* w, rct_widgetindex widgetI { case WIDX_REFURBISH: { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); ride_action_modify(ride, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); break; } @@ -161,7 +161,7 @@ static void window_ride_demolish_paint(rct_window* w, rct_drawpixelinfo* dpi) { WindowDrawWidgets(w, dpi); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID : STR_DEMOLISH_RIDE_ID_MONEY; @@ -178,7 +178,7 @@ static void window_ride_refurbish_paint(rct_window* w, rct_drawpixelinfo* dpi) { WindowDrawWidgets(w, dpi); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index bd3c0357ae..50bb176749 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -972,7 +972,7 @@ static void window_editor_objective_options_rides_update(rct_window* w) { if (ride.IsRide()) { - w->list_item_positions[numItems] = ride.id; + w->list_item_positions[numItems] = static_cast(ride.id); numItems++; } } @@ -1005,7 +1005,8 @@ static void window_editor_objective_options_rides_scrollmousedown( if (i < 0 || i >= w->no_list_items) return; - auto ride = get_ride(w->list_item_positions[i]); + const auto rideId = static_cast(w->list_item_positions[i]); + auto ride = get_ride(rideId); if (ride != nullptr) { ride->lifecycle_flags ^= RIDE_LIFECYCLE_INDESTRUCTIBLE; @@ -1098,7 +1099,8 @@ static void window_editor_objective_options_rides_scrollpaint(rct_window* w, rct } // Checkbox mark - auto ride = get_ride(w->list_item_positions[i]); + const auto rideId = static_cast(w->list_item_positions[i]); + auto ride = get_ride(rideId); if (ride != nullptr) { if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 4e62cf9142..4c35e18d02 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1456,7 +1456,7 @@ void window_guest_rides_update(rct_window* w) { if (ride.IsRide() && guest->HasRidden(&ride)) { - w->list_item_positions[curr_list_position] = ride.id; + w->list_item_positions[curr_list_position] = static_cast(ride.id); curr_list_position++; } } @@ -1607,7 +1607,8 @@ void window_guest_rides_scroll_paint(rct_window* w, rct_drawpixelinfo* dpi, int3 stringId = STR_WINDOW_COLOUR_2_STRINGID; } - auto ride = get_ride(w->list_item_positions[list_index]); + const auto rideId = static_cast(w->list_item_positions[list_index]); + auto ride = get_ride(rideId); if (ride != nullptr) { auto ft = Formatter(); diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index d1b2d29c4b..cc3b1254c9 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -182,7 +182,7 @@ public: { case GuestListFilterType::GuestsOnRide: { - auto guestRide = get_ride(index); + auto guestRide = get_ride(static_cast(index)); if (guestRide != nullptr) { ft.Add( @@ -198,7 +198,7 @@ public: } case GuestListFilterType::GuestsInQueue: { - auto guestRide = get_ride(index); + auto guestRide = get_ride(static_cast(index)); if (guestRide != nullptr) { ft.Add(STR_QUEUING_FOR); @@ -213,7 +213,7 @@ public: } case GuestListFilterType::GuestsThinkingAboutRide: { - auto guestRide = get_ride(index); + auto guestRide = get_ride(static_cast(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 8ba2e75354..9d7a3654cc 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -130,7 +130,7 @@ rct_window* window_maze_construction_open() WindowInitScrollWidgets(w); - w->number = _currentRideIndex; + w->number = static_cast(_currentRideIndex); window_push_others_right(w); show_gridlines(); @@ -169,7 +169,7 @@ static void window_maze_construction_close(rct_window* w) else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(ride->id)); context_open_intent(&intent); } } @@ -181,7 +181,7 @@ static void window_maze_construction_entrance_mouseup(rct_window* w, rct_widgeti return; gRideEntranceExitPlaceType = widgetIndex == WIDX_MAZE_ENTRANCE ? ENTRANCE_TYPE_RIDE_ENTRANCE : ENTRANCE_TYPE_RIDE_EXIT; - gRideEntranceExitPlaceRideIndex = static_cast(w->number); + gRideEntranceExitPlaceRideIndex = static_cast(w->number); gRideEntranceExitPlaceStationIndex = 0; input_set_flag(INPUT_FLAG_6, true); diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index d1ad6aa8d9..78139854cb 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -22,7 +22,9 @@ static constexpr const rct_string_id WINDOW_TITLE = STR_NONE; static constexpr const int32_t WH = 109; static constexpr const int32_t WW = 350; -constexpr uint16_t SELECTED_RIDE_UNDEFINED = 0xFFFF; + +constexpr auto SELECTED_RIDE_UNDEFINED = RIDE_ID_NULL; +constexpr uint16_t SELECTED_ITEM_UNDEFINED = 0xFFFF; // clang-format off enum WINDOW_NEW_CAMPAIGN_WIDGET_IDX { @@ -252,7 +254,8 @@ public: break; case WIDX_START_BUTTON: { - auto gameAction = ParkMarketingAction(campaign.campaign_type, campaign.RideId, campaign.no_weeks); + auto gameAction = ParkMarketingAction( + campaign.campaign_type, static_cast(campaign.RideId), campaign.no_weeks); gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) { @@ -322,7 +325,7 @@ public: widgets[WIDX_RIDE_DROPDOWN].type = WindowWidgetType::DropdownMenu; widgets[WIDX_RIDE_DROPDOWN_BUTTON].type = WindowWidgetType::Button; widgets[WIDX_RIDE_LABEL].text = STR_MARKETING_ITEM; - if (campaign.ShopItemId != SELECTED_RIDE_UNDEFINED) + if (campaign.ShopItemId != SELECTED_ITEM_UNDEFINED) { widgets[WIDX_RIDE_DROPDOWN].text = GetShopItemDescriptor(ShopItem(campaign.ShopItemId)).Naming.Plural; } diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index b79a7cec0e..e014523787 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -958,7 +958,7 @@ static void window_ride_draw_tab_main(rct_drawpixelinfo* dpi, rct_window* w) rct_widgetindex widgetIndex = WIDX_TAB_1 + WINDOW_RIDE_PAGE_MAIN; if (!(w->disabled_widgets & (1LL << widgetIndex))) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { int32_t spriteIndex = 0; @@ -1014,7 +1014,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo* dpi, rct_window* w) screenCoords = ScreenCoordsXY{ widget->width() / 2, widget->height() - 12 }; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -1108,7 +1108,7 @@ static void window_ride_draw_tab_images(rct_drawpixelinfo* dpi, rct_window* w) static void window_ride_disable_tabs(rct_window* w) { uint32_t disabled_tabs = 0; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -1192,12 +1192,12 @@ static void window_ride_update_overall_view(Ride* ride) maxz = std::max(maxz, clearZ); } - if (ride->id >= ride_overall_views.size()) + if (static_cast(ride->id) >= ride_overall_views.size()) { - ride_overall_views.resize(ride->id + 1); + ride_overall_views.resize(static_cast(ride->id) + 1); } - auto& view = ride_overall_views[ride->id]; + auto& view = ride_overall_views[static_cast(ride->id)]; view.x = (minx + maxx) / 2 + 16; view.y = (miny + maxy) / 2 + 16; view.z = (minz + maxz) / 2 - 8; @@ -1234,7 +1234,7 @@ static rct_window* window_ride_open(Ride* ride) w->widgets = window_ride_page_widgets[WINDOW_RIDE_PAGE_MAIN]; w->enabled_widgets = window_ride_page_enabled_widgets[WINDOW_RIDE_PAGE_MAIN]; w->hold_down_widgets = window_ride_page_hold_down_widgets[WINDOW_RIDE_PAGE_MAIN]; - w->number = ride->id; + w->number = static_cast(ride->id); w->page = WINDOW_RIDE_PAGE_MAIN; w->vehicleIndex = 0; @@ -1264,7 +1264,7 @@ rct_window* window_ride_main_open(Ride* ride) return nullptr; } - rct_window* w = window_bring_to_front_by_number(WC_RIDE, ride->id); + rct_window* w = window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); if (w == nullptr) { w = window_ride_open(ride); @@ -1305,7 +1305,7 @@ static rct_window* window_ride_open_station(Ride* ride, StationIndex stationInde if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) return window_ride_main_open(ride); - auto w = window_bring_to_front_by_number(WC_RIDE, ride->id); + auto w = window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); if (w == nullptr) { w = window_ride_open(ride); @@ -1407,7 +1407,7 @@ rct_window* window_ride_open_vehicle(Vehicle* vehicle) view++; } - rct_window* w = window_find_by_number(WC_RIDE, ride->id); + rct_window* w = window_find_by_number(WC_RIDE, static_cast(ride->id)); if (w != nullptr) { w->Invalidate(); @@ -1442,7 +1442,8 @@ rct_window* window_ride_open_vehicle(Vehicle* vehicle) } } - w = openedPeepWindow ? window_find_by_number(WC_RIDE, ride->id) : window_bring_to_front_by_number(WC_RIDE, ride->id); + w = openedPeepWindow ? window_find_by_number(WC_RIDE, static_cast(ride->id)) + : window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); } if (w == nullptr) @@ -1584,7 +1585,7 @@ static void window_ride_init_viewport(rct_window* w) if (w->page != WINDOW_RIDE_PAGE_MAIN) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -1716,7 +1717,7 @@ static void window_ride_init_viewport(rct_window* w) */ static void window_ride_rename(rct_window* w) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto rideName = ride->GetName(); @@ -1750,11 +1751,11 @@ static void window_ride_main_mouseup(rct_window* w, rct_widgetindex widgetIndex) break; case WIDX_CONSTRUCTION: { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { ride_construct(ride); - if (window_find_by_number(WC_RIDE_CONSTRUCTION, ride->id) != nullptr) + if (window_find_by_number(WC_RIDE_CONSTRUCTION, static_cast(ride->id)) != nullptr) { window_close(w); } @@ -1775,7 +1776,7 @@ static void window_ride_main_mouseup(rct_window* w, rct_widgetindex widgetIndex) case WIDX_TEST_LIGHT: case WIDX_OPEN_LIGHT: { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { RideStatus status; @@ -1813,7 +1814,7 @@ static void window_ride_main_resize(rct_window* w) { minHeight += 20 + RCT1_LIGHT_OFFSET; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { #ifdef __SIMULATE_IN_RIDE_WINDOW__ @@ -1845,7 +1846,7 @@ static void window_ride_main_resize(rct_window* w) static void window_ride_show_view_dropdown(rct_window* w, rct_widget* widget) { rct_widget* dropdownWidget = widget - 1; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -1961,7 +1962,7 @@ static void window_ride_set_dropdown(RideStatusDropdownInfo& info, RideStatus st static void window_ride_show_open_dropdown(rct_window* w, rct_widget* widget) { RideStatusDropdownInfo info; - info.Ride = get_ride(w->number); + info.Ride = get_ride(static_cast(w->number)); if (info.Ride == nullptr) return; @@ -2029,7 +2030,7 @@ static void populate_ride_type_dropdown() static void window_ride_show_ride_type_dropdown(rct_window* w, rct_widget* widget) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2125,7 +2126,7 @@ static void populate_vehicle_type_dropdown(Ride* ride) static void window_ride_show_vehicle_type_dropdown(rct_window* w, rct_widget* widget) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2192,7 +2193,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex if (dropdownIndex == -1) { dropdownIndex = w->ride.view + 1; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { if (dropdownIndex != 0 && dropdownIndex <= ride->num_vehicles @@ -2213,7 +2214,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex break; case WIDX_OPEN: { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto status = RideStatus::Closed; @@ -2250,7 +2251,8 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id; if (rideType < RIDE_TYPE_COUNT) { - auto rideSetSetting = RideSetSettingAction(w->number, RideSetSetting::RideType, rideType); + const auto rideId = static_cast(w->number); + auto rideSetSetting = RideSetSettingAction(rideId, RideSetSetting::RideType, rideType); rideSetSetting.SetCallback([](const GameAction* ga, const GameActions::Result* result) { // Reset ghost track if ride construction window is open, prevents a crash // Will get set to the correct Alternative variable during set_default_next_piece. @@ -2276,7 +2278,7 @@ static void window_ride_main_update(rct_window* w) widget_invalidate(w, WIDX_TAB_1); // Update status - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { if (!(ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_MAIN)) @@ -2311,7 +2313,7 @@ static void window_ride_main_textinput(rct_window* w, rct_widgetindex widgetInde if (widgetIndex != WIDX_RENAME || text == nullptr) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { ride_set_name(ride, text, 0); @@ -2345,7 +2347,7 @@ static void window_ride_main_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2477,7 +2479,7 @@ static void window_ride_main_invalidate(rct_window* w) static rct_string_id window_ride_get_status_overall_view(rct_window* w, Formatter& ft) { auto stringId = STR_NONE; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { ride->FormatStatusTo(ft); @@ -2496,7 +2498,7 @@ static rct_string_id window_ride_get_status_overall_view(rct_window* w, Formatte */ static rct_string_id window_ride_get_status_vehicle(rct_window* w, Formatter& ft) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return STR_EMPTY; @@ -2544,7 +2546,7 @@ static rct_string_id window_ride_get_status_vehicle(rct_window* w, Formatter& ft */ static rct_string_id window_ride_get_status_station(rct_window* w, Formatter& ft) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return STR_NONE; @@ -2595,7 +2597,7 @@ static rct_string_id window_ride_get_status_station(rct_window* w, Formatter& ft */ static rct_string_id window_ride_get_status(rct_window* w, Formatter& ft) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (w->ride.view == 0) return window_ride_get_status_overall_view(w, ft); if (ride != nullptr && w->ride.view <= ride->num_vehicles) @@ -2625,7 +2627,7 @@ static void window_ride_main_paint(rct_window* w, rct_drawpixelinfo* dpi) } // View dropdown - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2707,7 +2709,7 @@ static void window_ride_vehicle_resize(rct_window* w) */ static void window_ride_vehicle_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2750,7 +2752,7 @@ static void window_ride_vehicle_dropdown(rct_window* w, rct_widgetindex widgetIn case WIDX_VEHICLE_TYPE_DROPDOWN: if (dropdownIndex >= 0 && static_cast(dropdownIndex) < VehicleDropdownData.size()) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto newRideType = VehicleDropdownData[dropdownIndex].subtype_id; @@ -2775,7 +2777,7 @@ static void window_ride_vehicle_update(rct_window* w) static OpenRCT2String window_ride_vehicle_tooltip( rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return { STR_NONE, {} }; @@ -2842,7 +2844,7 @@ static void window_ride_vehicle_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2922,7 +2924,7 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -2997,7 +2999,7 @@ static rct_vehicle_paintinfo _sprites_to_draw[144]; */ static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3090,7 +3092,8 @@ static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dp */ static void window_ride_mode_tweak_increase(rct_window* w) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3106,7 +3109,7 @@ static void window_ride_mode_tweak_increase(rct_window* w) uint8_t increment = ride->mode == RideMode::Dodgems ? 10 : 1; set_operating_setting( - w->number, RideSetSetting::Operation, std::clamp(ride->operation_option + increment, minValue, maxValue)); + rideId, RideSetSetting::Operation, std::clamp(ride->operation_option + increment, minValue, maxValue)); } /** @@ -3115,7 +3118,8 @@ static void window_ride_mode_tweak_increase(rct_window* w) */ static void window_ride_mode_tweak_decrease(rct_window* w) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3130,7 +3134,7 @@ static void window_ride_mode_tweak_decrease(rct_window* w) uint8_t decrement = ride->mode == RideMode::Dodgems ? 10 : 1; set_operating_setting( - w->number, RideSetSetting::Operation, std::clamp(ride->operation_option - decrement, minValue, maxValue)); + rideId, RideSetSetting::Operation, std::clamp(ride->operation_option - decrement, minValue, maxValue)); } /** @@ -3142,7 +3146,8 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) rct_widget* dropdownWidget; dropdownWidget = widget - 1; - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3181,7 +3186,8 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) */ static void window_ride_load_dropdown(rct_window* w, rct_widget* widget) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3204,7 +3210,8 @@ static void window_ride_load_dropdown(rct_window* w, rct_widget* widget) */ static void window_ride_operating_mouseup(rct_window* w, rct_widgetindex widgetIndex) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3226,23 +3233,21 @@ static void window_ride_operating_mouseup(rct_window* w, rct_widgetindex widgetI window_ride_set_page(w, widgetIndex - WIDX_TAB_1); break; case WIDX_LOAD_CHECKBOX: - set_operating_setting(w->number, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_LOAD); + set_operating_setting(rideId, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_LOAD); break; case WIDX_LEAVE_WHEN_ANOTHER_ARRIVES_CHECKBOX: set_operating_setting( - w->number, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_LEAVE_WHEN_ANOTHER_ARRIVES); + rideId, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_LEAVE_WHEN_ANOTHER_ARRIVES); break; case WIDX_MINIMUM_LENGTH_CHECKBOX: - set_operating_setting( - w->number, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH); + set_operating_setting(rideId, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH); break; case WIDX_MAXIMUM_LENGTH_CHECKBOX: - set_operating_setting( - w->number, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH); + set_operating_setting(rideId, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH); break; case WIDX_SYNCHRONISE_WITH_ADJACENT_STATIONS_CHECKBOX: set_operating_setting( - w->number, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS); + rideId, RideSetSetting::Departure, ride->depart_flags ^ RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS); break; } } @@ -3262,7 +3267,8 @@ static void window_ride_operating_resize(rct_window* w) */ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3279,42 +3285,42 @@ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widge upper_bound = gCheatsUnlockOperatingLimits ? 255 : ride->GetRideTypeDescriptor().LiftData.maximum_speed; lower_bound = gCheatsUnlockOperatingLimits ? 0 : ride->GetRideTypeDescriptor().LiftData.minimum_speed; set_operating_setting( - w->number, RideSetSetting::LiftHillSpeed, + rideId, RideSetSetting::LiftHillSpeed, std::clamp(ride->lift_hill_speed + 1, lower_bound, upper_bound)); break; case WIDX_LIFT_HILL_SPEED_DECREASE: upper_bound = gCheatsUnlockOperatingLimits ? 255 : ride->GetRideTypeDescriptor().LiftData.maximum_speed; lower_bound = gCheatsUnlockOperatingLimits ? 0 : ride->GetRideTypeDescriptor().LiftData.minimum_speed; set_operating_setting( - w->number, RideSetSetting::LiftHillSpeed, + rideId, RideSetSetting::LiftHillSpeed, std::clamp(ride->lift_hill_speed - 1, lower_bound, upper_bound)); break; case WIDX_MINIMUM_LENGTH_INCREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( - w->number, RideSetSetting::MinWaitingTime, + rideId, RideSetSetting::MinWaitingTime, std::clamp(ride->min_waiting_time + 1, lower_bound, upper_bound)); break; case WIDX_MINIMUM_LENGTH_DECREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( - w->number, RideSetSetting::MinWaitingTime, + rideId, RideSetSetting::MinWaitingTime, std::clamp(ride->min_waiting_time - 1, lower_bound, upper_bound)); break; case WIDX_MAXIMUM_LENGTH_INCREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( - w->number, RideSetSetting::MaxWaitingTime, + rideId, RideSetSetting::MaxWaitingTime, std::clamp(ride->max_waiting_time + 1, lower_bound, upper_bound)); break; case WIDX_MAXIMUM_LENGTH_DECREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( - w->number, RideSetSetting::MaxWaitingTime, + rideId, RideSetSetting::MaxWaitingTime, std::clamp(ride->max_waiting_time - 1, lower_bound, upper_bound)); break; case WIDX_MODE_DROPDOWN: @@ -3327,13 +3333,13 @@ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widge upper_bound = gCheatsUnlockOperatingLimits ? 255 : MAX_CIRCUITS_PER_RIDE; lower_bound = 1; set_operating_setting( - w->number, RideSetSetting::NumCircuits, std::clamp(ride->num_circuits + 1, lower_bound, upper_bound)); + rideId, RideSetSetting::NumCircuits, std::clamp(ride->num_circuits + 1, lower_bound, upper_bound)); break; case WIDX_OPERATE_NUMBER_OF_CIRCUITS_DECREASE: upper_bound = gCheatsUnlockOperatingLimits ? 255 : MAX_CIRCUITS_PER_RIDE; lower_bound = 1; set_operating_setting( - w->number, RideSetSetting::NumCircuits, std::clamp(ride->num_circuits - 1, lower_bound, upper_bound)); + rideId, RideSetSetting::NumCircuits, std::clamp(ride->num_circuits - 1, lower_bound, upper_bound)); break; } } @@ -3347,7 +3353,8 @@ static void window_ride_operating_dropdown(rct_window* w, rct_widgetindex widget if (dropdownIndex == -1) return; - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3371,12 +3378,12 @@ static void window_ride_operating_dropdown(rct_window* w, rct_widgetindex widget } } if (rideMode != RideMode::NullMode) - set_operating_setting(w->number, RideSetSetting::Mode, static_cast(rideMode)); + set_operating_setting(rideId, RideSetSetting::Mode, static_cast(rideMode)); break; } case WIDX_LOAD_DROPDOWN: set_operating_setting( - w->number, RideSetSetting::Departure, (ride->depart_flags & ~RIDE_DEPART_WAIT_FOR_LOAD_MASK) | dropdownIndex); + rideId, RideSetSetting::Departure, (ride->depart_flags & ~RIDE_DEPART_WAIT_FOR_LOAD_MASK) | dropdownIndex); break; } } @@ -3391,7 +3398,7 @@ static void window_ride_operating_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_3); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_OPERATING) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_OPERATING; @@ -3417,7 +3424,7 @@ static void window_ride_operating_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3658,7 +3665,7 @@ static void window_ride_operating_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3690,7 +3697,7 @@ static void window_ride_operating_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_ride_locate_mechanic(rct_window* w) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3780,7 +3787,7 @@ static void window_ride_maintenance_resize(rct_window* w) */ static void window_ride_maintenance_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -3884,7 +3891,8 @@ static void window_ride_maintenance_dropdown(rct_window* w, rct_widgetindex widg if (dropdownIndex == -1) return; - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3895,7 +3903,7 @@ static void window_ride_maintenance_dropdown(rct_window* w, rct_widgetindex widg switch (widgetIndex) { case WIDX_INSPECTION_INTERVAL_DROPDOWN: - set_operating_setting(w->number, RideSetSetting::InspectionInterval, dropdownIndex); + set_operating_setting(rideId, RideSetSetting::InspectionInterval, dropdownIndex); break; case WIDX_FORCE_BREAKDOWN: @@ -3990,7 +3998,7 @@ static void window_ride_maintenance_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_4); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_MAINTENANCE) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_MAINTENANCE; @@ -4013,7 +4021,7 @@ static void window_ride_maintenance_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4055,7 +4063,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4210,7 +4218,7 @@ static void window_ride_set_track_colour_scheme(rct_window* w, const ScreenCoord return; if (info.Element->GetType() != TILE_ELEMENT_TYPE_TRACK) return; - if (info.Element->AsTrack()->GetRideIndex() != w->number) + if (info.Element->AsTrack()->GetRideIndex() != static_cast(w->number)) return; if (info.Element->AsTrack()->GetColourScheme() == newColourScheme) return; @@ -4288,7 +4296,7 @@ static void window_ride_colour_mousedown(rct_window* w, rct_widgetindex widgetIn int32_t i, numItems; rct_string_id stringId; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4421,6 +4429,7 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd if (dropdownIndex == -1) return; + const auto rideId = static_cast(w->number); switch (widgetIndex) { case WIDX_TRACK_COLOUR_SCHEME_DROPDOWN: @@ -4430,28 +4439,28 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd case WIDX_TRACK_MAIN_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::TrackColourMain, dropdownIndex, w->ride_colour); + rideId, RideSetAppearanceType::TrackColourMain, dropdownIndex, w->ride_colour); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_TRACK_ADDITIONAL_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::TrackColourAdditional, dropdownIndex, w->ride_colour); + rideId, RideSetAppearanceType::TrackColourAdditional, dropdownIndex, w->ride_colour); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_TRACK_SUPPORT_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::TrackColourSupports, dropdownIndex, w->ride_colour); + rideId, RideSetAppearanceType::TrackColourSupports, dropdownIndex, w->ride_colour); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_MAZE_STYLE_DROPDOWN: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::MazeStyle, dropdownIndex, w->ride_colour); + rideId, RideSetAppearanceType::MazeStyle, dropdownIndex, w->ride_colour); GameActions::Execute(&rideSetAppearanceAction); } break; @@ -4467,7 +4476,7 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd if (ddIndex == dropdownIndex) { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::EntranceStyle, ddIndex, 0); + rideId, RideSetAppearanceType::EntranceStyle, ddIndex, 0); GameActions::Execute(&rideSetAppearanceAction); break; } @@ -4479,7 +4488,7 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd case WIDX_VEHICLE_COLOUR_SCHEME_DROPDOWN: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::VehicleColourScheme, dropdownIndex, 0); + rideId, RideSetAppearanceType::VehicleColourScheme, dropdownIndex, 0); GameActions::Execute(&rideSetAppearanceAction); w->vehicleIndex = 0; } @@ -4491,21 +4500,21 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd case WIDX_VEHICLE_MAIN_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::VehicleColourBody, dropdownIndex, w->vehicleIndex); + rideId, RideSetAppearanceType::VehicleColourBody, dropdownIndex, w->vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_VEHICLE_ADDITIONAL_COLOUR_1: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::VehicleColourTrim, dropdownIndex, w->vehicleIndex); + rideId, RideSetAppearanceType::VehicleColourTrim, dropdownIndex, w->vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_VEHICLE_ADDITIONAL_COLOUR_2: { auto rideSetAppearanceAction = RideSetAppearanceAction( - w->number, RideSetAppearanceType::VehicleColourTernary, dropdownIndex, w->vehicleIndex); + rideId, RideSetAppearanceType::VehicleColourTernary, dropdownIndex, w->vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; @@ -4562,7 +4571,7 @@ static void window_ride_colour_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4788,7 +4797,7 @@ static void window_ride_colour_paint(rct_window* w, rct_drawpixelinfo* dpi) rct_drawpixelinfo clippedDpi; rct_widget* widget; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4888,7 +4897,7 @@ static void window_ride_colour_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_ride_colour_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -4951,11 +4960,12 @@ static std::vector window_ride_current_music_style_order; */ static void window_ride_toggle_music(rct_window* w) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride != nullptr) { int32_t activateMusic = (ride->lifecycle_flags & RIDE_LIFECYCLE_MUSIC) ? 0 : 1; - set_operating_setting(w->number, RideSetSetting::Music, activateMusic); + set_operating_setting(rideId, RideSetSetting::Music, activateMusic); } } @@ -5027,7 +5037,7 @@ static void window_ride_music_mousedown(rct_window* w, rct_widgetindex widgetInd return; auto dropdownWidget = widget - 1; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -5106,7 +5116,7 @@ static void window_ride_music_dropdown(rct_window* w, rct_widgetindex widgetInde && static_cast(dropdownIndex) < window_ride_current_music_style_order.size()) { auto musicStyle = window_ride_current_music_style_order[dropdownIndex]; - set_operating_setting(w->number, RideSetSetting::MusicType, musicStyle); + set_operating_setting(static_cast(w->number), RideSetSetting::MusicType, musicStyle); } } @@ -5136,7 +5146,7 @@ static void window_ride_music_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -5227,7 +5237,7 @@ static void setup_scenery_selection(rct_window* w) while (tool_set(w, WIDX_BACKGROUND, Tool::Crosshair)) ; - gTrackDesignSaveRideIndex = w->number; + gTrackDesignSaveRideIndex = static_cast(w->number); track_design_save_init(); gGamePaused |= GAME_PAUSED_SAVING_TRACK; @@ -5290,7 +5300,7 @@ static void TrackDesignCallback(int32_t result, [[maybe_unused]] const utf8* pat */ static void window_ride_measurements_design_save(rct_window* w) { - Ride* ride = get_ride(w->number); + Ride* ride = get_ride(static_cast(w->number)); _trackDesign = ride->SaveToTrackDesign(); if (!_trackDesign) { @@ -5382,7 +5392,7 @@ static void window_ride_measurements_mousedown(rct_window* w, rct_widgetindex wi if (widgetIndex != WIDX_SAVE_TRACK_DESIGN) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -5508,7 +5518,8 @@ static void window_ride_measurements_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -5517,7 +5528,7 @@ static void window_ride_measurements_invalidate(rct_window* w) window_ride_measurements_widgets[WIDX_SAVE_TRACK_DESIGN].tooltip = STR_SAVE_TRACK_DESIGN_NOT_POSSIBLE; window_ride_measurements_widgets[WIDX_SAVE_TRACK_DESIGN].type = WindowWidgetType::Empty; - if (gTrackDesignSaveMode && gTrackDesignSaveRideIndex == w->number) + if (gTrackDesignSaveMode && gTrackDesignSaveRideIndex == rideId) { window_ride_measurements_widgets[WIDX_SELECT_NEARBY_SCENERY].type = WindowWidgetType::Button; window_ride_measurements_widgets[WIDX_RESET_SELECTION].type = WindowWidgetType::Button; @@ -5570,7 +5581,7 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi } else { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -5894,7 +5905,7 @@ static void window_ride_graphs_update(rct_window* w) x = w->scrolls[0].h_left; if (!(w->list_information_type & 0x8000)) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { RideMeasurement* measurement{}; @@ -5919,7 +5930,7 @@ static void window_ride_graphs_scrollgetheight(rct_window* w, int32_t scrollInde *width = window_ride_graphs_widgets[WIDX_GRAPH].width() - 2; // Get measurement size - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { RideMeasurement* measurement{}; @@ -5948,7 +5959,7 @@ static OpenRCT2String window_ride_graphs_tooltip(rct_window* w, const rct_widget { if (widgetIndex == WIDX_GRAPH) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto [measurement, message] = ride->GetMeasurement(); @@ -5988,7 +5999,7 @@ static void window_ride_graphs_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -6054,7 +6065,7 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi gfx_clear(dpi, ColourMapA[COLOUR_SATURATED_GREEN].darker); auto widget = &window_ride_graphs_widgets[WIDX_GRAPH]; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) { return; @@ -6247,7 +6258,8 @@ static void update_same_price_throughout_flags(ShopItem shop_item) */ static void window_ride_income_toggle_primary_price(rct_window* w) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -6273,7 +6285,7 @@ static void window_ride_income_toggle_primary_price(rct_window* w) update_same_price_throughout_flags(shop_item); - auto rideSetPriceAction = RideSetPriceAction(w->number, ride->price[0], true); + auto rideSetPriceAction = RideSetPriceAction(rideId, ride->price[0], true); GameActions::Execute(&rideSetPriceAction); } @@ -6283,7 +6295,8 @@ static void window_ride_income_toggle_primary_price(rct_window* w) */ static void window_ride_income_toggle_secondary_price(rct_window* w) { - auto ride = get_ride(w->number); + const auto rideId = static_cast(w->number); + auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -6297,13 +6310,13 @@ static void window_ride_income_toggle_secondary_price(rct_window* w) update_same_price_throughout_flags(shop_item); - auto rideSetPriceAction = RideSetPriceAction(w->number, ride->price[1], false); + auto rideSetPriceAction = RideSetPriceAction(rideId, ride->price[1], false); GameActions::Execute(&rideSetPriceAction); } static void window_ride_income_set_primary_price(rct_window* w, money16 price) { - auto rideSetPriceAction = RideSetPriceAction(w->number, price, true); + auto rideSetPriceAction = RideSetPriceAction(static_cast(w->number), price, true); GameActions::Execute(&rideSetPriceAction); } @@ -6316,7 +6329,7 @@ static void window_ride_income_increase_primary_price(rct_window* w) if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -6336,7 +6349,7 @@ static void window_ride_income_decrease_primary_price(rct_window* w) if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -6349,7 +6362,7 @@ static void window_ride_income_decrease_primary_price(rct_window* w) static money16 window_ride_income_get_secondary_price(rct_window* w) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return 0; @@ -6359,13 +6372,13 @@ static money16 window_ride_income_get_secondary_price(rct_window* w) static void window_ride_income_set_secondary_price(rct_window* w, money16 price) { - auto rideSetPriceAction = RideSetPriceAction((w->number & 0x00FF), price, false); + auto rideSetPriceAction = RideSetPriceAction(static_cast(w->number), price, false); GameActions::Execute(&rideSetPriceAction); } static bool window_ride_income_can_modify_primary_price(rct_window* w) { - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return false; @@ -6430,7 +6443,7 @@ static void window_ride_income_mouseup(rct_window* w, rct_widgetindex widgetInde if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { money_to_string(static_cast(ride->price[0]), _moneyInputText, MONEY_STRING_MAXLENGTH, true); @@ -6500,7 +6513,7 @@ static void window_ride_income_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_9); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_INCOME) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_INCOME; @@ -6547,7 +6560,7 @@ static void window_ride_income_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -6658,7 +6671,7 @@ static void window_ride_income_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; @@ -6826,7 +6839,7 @@ static void window_ride_customer_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_10); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_CUSTOMER) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_CUSTOMER; @@ -6849,7 +6862,7 @@ static void window_ride_customer_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride != nullptr) { auto ft = Formatter::Common(); @@ -6885,7 +6898,7 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(w->number); + auto ride = get_ride(static_cast(w->number)); if (ride == nullptr) return; diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 8d6c70f41e..d8424785d3 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -509,7 +509,7 @@ static void close_ride_window_for_construction(rct_windownumber number) rct_window* window_ride_construction_open() { ride_id_t rideIndex = _currentRideIndex; - close_ride_window_for_construction(rideIndex); + close_ride_window_for_construction(static_cast(rideIndex)); auto ride = get_ride(rideIndex); if (ride == nullptr) @@ -543,7 +543,7 @@ rct_window* window_ride_construction_open() w->colours[1] = COLOUR_DARK_BROWN; w->colours[2] = COLOUR_DARK_BROWN; - w->number = rideIndex; + w->number = static_cast(rideIndex); window_push_others_right(w); show_gridlines(); @@ -620,7 +620,7 @@ static void window_ride_construction_close(rct_window* w) ride->SetToDefaultInspectionInterval(); auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(ride->id)); context_open_intent(&intent); } else @@ -1937,7 +1937,7 @@ static void window_ride_construction_mouseup_demolish(rct_window* w) _currentTrackPieceType, 0, { _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z, _currentTrackPieceDirection }); - const auto rideId = w->number; + const auto rideId = static_cast(w->number); trackRemoveAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) { @@ -2017,7 +2017,7 @@ static void window_ride_construction_exit_click(rct_window* w) else { gRideEntranceExitPlaceType = ENTRANCE_TYPE_RIDE_EXIT; - gRideEntranceExitPlaceRideIndex = w->number & 0xFF; + gRideEntranceExitPlaceRideIndex = static_cast(w->number); gRideEntranceExitPlaceStationIndex = 0; input_set_flag(INPUT_FLAG_6, true); ride_construction_invalidate_current_track(); diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index aa932db73e..94a51eb2c9 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -443,7 +443,7 @@ static void window_ride_list_scrollmousedown(rct_window* w, int32_t scrollIndex, else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(rideIndex)); context_open_intent(&intent); } } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index bfadeab869..575710c2ea 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1931,7 +1931,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) // Details // Ride auto trackElement = tileElement->AsTrack(); - int16_t rideId = trackElement->GetRideIndex(); + ride_id_t rideId = trackElement->GetRideIndex(); auto ride = get_ride(rideId); if (ride != nullptr) { diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index ce83d160f7..35ad8b135b 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -268,7 +268,9 @@ static void window_track_place_toolupdate(rct_window* w, rct_widgetindex widgetI // Check if tool map position has changed since last update if (mapCoords == _windowTrackPlaceLast) { - place_virtual_track(_trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(0), { mapCoords, 0 }); + place_virtual_track( + _trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), + { mapCoords, 0 }); return; } @@ -308,7 +310,8 @@ static void window_track_place_toolupdate(rct_window* w, rct_widgetindex widgetI widget_invalidate(w, WIDX_PRICE); } - place_virtual_track(_trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(0), trackLoc); + place_virtual_track( + _trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), trackLoc); } /** @@ -348,7 +351,7 @@ static void window_track_place_tooldown(rct_window* w, rct_widgetindex widgetInd if (track_design_are_entrance_and_exit_placed()) { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, result->rideIndex); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(result->rideIndex)); context_open_intent(&intent); auto wnd = window_find_by_class(WC_TRACK_DESIGN_PLACE); window_close(wnd); @@ -469,7 +472,9 @@ static int32_t window_track_place_get_base_z(const CoordsXY& loc) if (surfaceElement->GetWaterHeight() > 0) z = std::max(z, surfaceElement->GetWaterHeight()); - return z + place_virtual_track(_trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(0), { loc, z }); + return z + + place_virtual_track( + _trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(static_cast(0)), { loc, z }); } /** diff --git a/src/openrct2/actions/ParkMarketingAction.cpp b/src/openrct2/actions/ParkMarketingAction.cpp index aa9c2abda4..665f00fbc5 100644 --- a/src/openrct2/actions/ParkMarketingAction.cpp +++ b/src/openrct2/actions/ParkMarketingAction.cpp @@ -70,7 +70,7 @@ GameActions::Result::Ptr ParkMarketingAction::Execute() const campaign.Flags = MarketingCampaignFlags::FIRST_WEEK; if (campaign.Type == ADVERTISING_CAMPAIGN_RIDE_FREE || campaign.Type == ADVERTISING_CAMPAIGN_RIDE) { - campaign.RideId = _item; + campaign.RideId = static_cast(_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 e53af79c82..c59bc5c1c3 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -131,14 +131,16 @@ GameActions::Result::Ptr RideDemolishAction::DemolishRide(Ride* ride) const ride->ValidateStations(); ride_clear_leftover_entrances(ride); - News::DisableNewsItems(News::ItemType::Ride, _rideIndex); - UnlinkAllBannersForRide(_rideIndex); + const auto rideId = ride->id; + News::DisableNewsItems(News::ItemType::Ride, EnumValue(rideId)); - RideUse::GetHistory().RemoveValue(_rideIndex); + UnlinkAllBannersForRide(ride->id); + + RideUse::GetHistory().RemoveValue(ride->id); for (auto peep : EntityList()) { - peep->RemoveRideFromMemory(_rideIndex); + peep->RemoveRideFromMemory(ride->id); } MarketingCancelCampaignsForRide(_rideIndex); @@ -157,9 +159,9 @@ GameActions::Result::Ptr RideDemolishAction::DemolishRide(Ride* ride) const gParkValue = GetContext()->GetGameState()->GetPark().CalculateParkValue(); // Close windows related to the demolished ride - window_close_by_number(WC_RIDE_CONSTRUCTION, _rideIndex); - window_close_by_number(WC_RIDE, _rideIndex); - window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, _rideIndex); + 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_class(WC_NEW_CAMPAIGN); // Refresh windows that display the ride name @@ -272,7 +274,7 @@ GameActions::Result::Ptr RideDemolishAction::RefurbishRide(Ride* ride) const res->Position = { location, tile_element_height(location) }; } - window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, _rideIndex); + window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, static_cast(_rideIndex)); return res; } diff --git a/src/openrct2/actions/RideSetAppearanceAction.cpp b/src/openrct2/actions/RideSetAppearanceAction.cpp index 53b76ff27a..bf8e9fc366 100644 --- a/src/openrct2/actions/RideSetAppearanceAction.cpp +++ b/src/openrct2/actions/RideSetAppearanceAction.cpp @@ -139,7 +139,7 @@ GameActions::Result::Ptr RideSetAppearanceAction::Execute() const gfx_invalidate_screen(); break; } - window_invalidate_by_number(WC_RIDE, _rideIndex); + window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); auto res = std::make_unique(); if (!ride->overall_view.IsNull()) diff --git a/src/openrct2/actions/RideSetPriceAction.cpp b/src/openrct2/actions/RideSetPriceAction.cpp index caf508d1e0..268fd7d9a7 100644 --- a/src/openrct2/actions/RideSetPriceAction.cpp +++ b/src/openrct2/actions/RideSetPriceAction.cpp @@ -180,7 +180,7 @@ void RideSetPriceAction::RideSetCommonPrice(ShopItem shopItem) const } if (invalidate) { - window_invalidate_by_number(WC_RIDE, ride.id); + window_invalidate_by_number(WC_RIDE, static_cast(ride.id)); } } } diff --git a/src/openrct2/actions/RideSetSettingAction.cpp b/src/openrct2/actions/RideSetSettingAction.cpp index 220c0ced3d..233b19154e 100644 --- a/src/openrct2/actions/RideSetSettingAction.cpp +++ b/src/openrct2/actions/RideSetSettingAction.cpp @@ -233,7 +233,7 @@ GameActions::Result::Ptr RideSetSettingAction::Execute() const auto location = ride->overall_view.ToTileCentre(); res->Position = { location, tile_element_height(location) }; } - window_invalidate_by_number(WC_RIDE, _rideIndex); + window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); return res; } diff --git a/src/openrct2/actions/RideSetStatusAction.cpp b/src/openrct2/actions/RideSetStatusAction.cpp index f6cffc84aa..5a79dae8bd 100644 --- a/src/openrct2/actions/RideSetStatusAction.cpp +++ b/src/openrct2/actions/RideSetStatusAction.cpp @@ -154,7 +154,7 @@ GameActions::Result::Ptr 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, _rideIndex); + window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); break; case RideStatus::Simulating: { @@ -176,7 +176,7 @@ GameActions::Result::Ptr 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, _rideIndex); + window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); break; } case RideStatus::Testing: @@ -195,7 +195,7 @@ GameActions::Result::Ptr 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, _rideIndex); + rct_window* constructionWindow = window_find_by_number(WC_RIDE_CONSTRUCTION, static_cast(_rideIndex)); if (constructionWindow != nullptr) { window_close(constructionWindow); @@ -223,7 +223,7 @@ GameActions::Result::Ptr 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, _rideIndex); + window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); break; } default: diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index 320aeafe12..bda774375f 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -199,7 +199,7 @@ GameActions::Result::Ptr RideSetVehicleAction::Execute() const } auto intent = Intent(INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, _rideIndex); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(_rideIndex)); context_broadcast_intent(&intent); gfx_invalidate_screen(); diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 3ad3c5fb25..a4f4e2b559 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -194,7 +194,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - int32_t res = set_operating_setting(ride_index, RideSetSetting::RideType, type); + int32_t res = set_operating_setting(static_cast(ride_index), RideSetSetting::RideType, type); if (res == MONEY32_UNDEFINED) { if (!gCheatsAllowArbitraryRideTypeChanges) @@ -224,7 +224,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(ride_index); + auto ride = get_ride(static_cast(ride_index)); if (mode >= static_cast(RideMode::Count)) { console.WriteFormatLine("Invalid ride mode."); @@ -256,7 +256,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(ride_index); + auto ride = get_ride(static_cast(ride_index)); if (mass <= 0) { console.WriteFormatLine("Friction value must be strictly positive"); @@ -294,7 +294,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(ride_index); + auto ride = get_ride(static_cast(ride_index)); if (excitement <= 0) { console.WriteFormatLine("Excitement value must be strictly positive"); @@ -325,7 +325,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(ride_index); + auto ride = get_ride(static_cast(ride_index)); if (intensity <= 0) { console.WriteFormatLine("Intensity value must be strictly positive"); @@ -356,7 +356,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(ride_index); + auto ride = get_ride(static_cast(ride_index)); if (nausea <= 0) { console.WriteFormatLine("Nausea value must be strictly positive"); @@ -426,7 +426,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto rideSetPrice = RideSetPriceAction(rideId, price, true); + auto rideSetPrice = RideSetPriceAction(static_cast(rideId), price, true); GameActions::Execute(&rideSetPrice); } } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index e9cd6b3147..bbd1d07af6 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -211,7 +211,7 @@ std::optional News::GetSubjectLocation(News::ItemType type, int32_t s { case News::ItemType::Ride: { - Ride* ride = get_ride(subject); + Ride* ride = get_ride(static_cast(subject)); if (ride == nullptr || ride->overall_view.IsNull()) { break; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 708aa59be2..91a3e633f7 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -2095,8 +2095,8 @@ int32_t guest_path_finding(Guest* peep) if (!(adjustedEdges & (1 << chosenDirection))) continue; - ride_id_t rideIndex, pathSearchResult; - pathSearchResult = footpath_element_destination_in_direction(loc, pathElement, chosenDirection, &rideIndex); + ride_id_t rideIndex = RIDE_ID_NULL; + auto pathSearchResult = footpath_element_destination_in_direction(loc, pathElement, chosenDirection, &rideIndex); switch (pathSearchResult) { case PATH_SEARCH_DEAD_END: diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index 96a9df55ca..560cd73cfd 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -1046,7 +1046,7 @@ ride_id_t RCT12RideIdToOpenRCT2RideId(const RCT12RideId rideId) if (rideId == RCT12_RIDE_ID_NULL) return RIDE_ID_NULL; - return rideId; + return static_cast(rideId); } RCT12RideId OpenRCT2RideIdToRCT12RideId(const ride_id_t rideId) @@ -1054,7 +1054,7 @@ RCT12RideId OpenRCT2RideIdToRCT12RideId(const ride_id_t rideId) if (rideId == RIDE_ID_NULL) return RCT12_RIDE_ID_NULL; - return rideId; + return static_cast(rideId); } static bool RCT12IsFormatChar(codepoint_t c) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 833a6c3250..392992b9ae 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -147,21 +147,23 @@ ride_id_t GetNextFreeRideId() Ride* GetOrAllocateRide(ride_id_t index) { - if (_rides.size() <= index) + const auto idx = static_cast(index); + if (_rides.size() <= idx) { - _rides.resize(index + 1); + _rides.resize(idx + 1); } - auto result = &_rides[index]; + auto result = &_rides[idx]; result->id = index; return result; } Ride* get_ride(ride_id_t index) { - if (index < _rides.size()) + const auto idx = static_cast(index); + if (idx < _rides.size()) { - auto& ride = _rides[index]; + auto& ride = _rides[idx]; if (ride.type != RIDE_TYPE_NULL) { assert(ride.id == index); @@ -1503,7 +1505,7 @@ void ride_breakdown_add_news_item(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, ride->id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, static_cast(ride->id), ft); } } @@ -1530,7 +1532,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, ride->id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_STILL_NOT_FIXED, static_cast(ride->id), ft); } } } @@ -2181,7 +2183,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, ride->id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, static_cast(ride->id), ft); } ride->connected_message_throttle = 3; } @@ -2193,7 +2195,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, ride->id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_EXIT_NOT_CONNECTED, static_cast(ride->id), ft); } ride->connected_message_throttle = 3; } @@ -2262,7 +2264,7 @@ static void ride_shop_connected(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, ride->id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, static_cast(ride->id), ft); } ride->connected_message_throttle = 3; @@ -3795,13 +3797,13 @@ bool Ride::Test(RideStatus newStatus, bool isApplying) if (type == RIDE_TYPE_NULL) { - log_warning("Invalid ride type for ride %u", id); + log_warning("Invalid ride type for ride %u", static_cast(id)); return false; } if (newStatus != RideStatus::Simulating) { - window_close_by_number(WC_RIDE_CONSTRUCTION, id); + window_close_by_number(WC_RIDE_CONSTRUCTION, static_cast(id)); } StationIndex stationIndex = ride_mode_check_station_present(this); @@ -3928,9 +3930,11 @@ 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 && id == gCurrentToolWidget.window_number - && (input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) - window_close_by_number(WC_RIDE_CONSTRUCTION, id); + if (WC_RIDE_CONSTRUCTION == gCurrentToolWidget.window_classification + && static_cast(id) == gCurrentToolWidget.window_number && (input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) + { + window_close_by_number(WC_RIDE_CONSTRUCTION, static_cast(id)); + } StationIndex stationIndex = ride_mode_check_station_present(this); if (stationIndex == STATION_INDEX_NULL) @@ -4637,7 +4641,7 @@ void invalidate_test_results(Ride* ride) } } } - window_invalidate_by_number(WC_RIDE, ride->id); + window_invalidate_by_number(WC_RIDE, static_cast(ride->id)); } /** @@ -5085,7 +5089,7 @@ void Ride::UpdateMaxVehicles() { num_cars_per_train = numCarsPerTrain; num_vehicles = numVehicles; - window_invalidate_by_number(WC_RIDE, id); + window_invalidate_by_number(WC_RIDE, static_cast(id)); } } @@ -5154,7 +5158,7 @@ void Ride::Crash(uint8_t vehicleIndex) { Formatter ft; FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, id, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, static_cast(id), ft); } } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index d0e06c9a88..df0b9c152c 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -122,7 +122,7 @@ static rct_window* ride_create_or_find_construction_window(ride_id_t rideIndex) { auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto intent = Intent(INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS); - intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex); + intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(rideIndex)); windowManager->BroadcastIntent(intent); return window_find_by_class(WC_RIDE_CONSTRUCTION); } @@ -239,7 +239,7 @@ void ride_clear_for_construction(Ride* ride) ride->RemoveVehicles(); ride_clear_blocked_tiles(ride); - auto w = window_find_by_number(WC_RIDE, ride->id); + auto w = window_find_by_number(WC_RIDE, static_cast(ride->id)); if (w != nullptr) window_event_resize_call(w); } diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 515e710c43..19b7b1b03d 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -159,10 +159,10 @@ static void ride_ratings_update_state_0(RideRatingUpdateState& state) { ride_id_t currentRide = state.CurrentRide; - currentRide++; - if (currentRide >= MAX_RIDES) + currentRide = static_cast(static_cast(currentRide) + 1); + if (currentRide >= static_cast(MAX_RIDES)) { - currentRide = 0; + currentRide = {}; } auto ride = get_ride(currentRide); @@ -285,7 +285,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, state.CurrentRide); + window_invalidate_by_number(WC_RIDE, static_cast(state.CurrentRide)); state.State = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; } @@ -753,7 +753,7 @@ static void ride_ratings_calculate(RideRatingUpdateState& state, Ride* ride) // Create event args object auto obj = DukObject(ctx); - obj.Set("rideId", ride->id); + obj.Set("rideId", static_cast(ride->id)); obj.Set("excitement", originalExcitement); obj.Set("intensity", originalIntensity); obj.Set("nausea", originalNausea); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index a8d3f0aa67..f419047418 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -319,7 +319,8 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride) } } - place_virtual_track(this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(0), { 4096, 4096, 0 }); + place_virtual_track( + this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), { 4096, 4096, 0 }); // Resave global vars for scenery reasons. _trackPreviewOrigin = startPos; @@ -438,7 +439,8 @@ rct_string_id TrackDesign::CreateTrackDesignMaze(const Ride& ride) // Save global vars as they are still used by scenery???? int32_t startZ = _trackPreviewOrigin.z; - place_virtual_track(this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(0), { 4096, 4096, 0 }); + place_virtual_track( + this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), { 4096, 4096, 0 }); _trackPreviewOrigin = { startLoc.x, startLoc.y, startZ }; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT; @@ -1931,7 +1933,8 @@ static bool track_design_place_preview(TrackDesign* td6, money32* cost, Ride** o int32_t mapSize = gMapSize << 4; _currentTrackPieceDirection = 0; - int32_t z = place_virtual_track(td6, PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(0), { mapSize, mapSize, 16 }); + int32_t z = place_virtual_track( + td6, PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(static_cast(0)), { mapSize, mapSize, 16 }); if (_trackDesignPlaceStateHasScenery) { diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 659d40b00c..7b29615007 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1600,7 +1600,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, ride); + window_invalidate_by_number(WC_RIDE, static_cast(ride)); return; } @@ -3114,7 +3114,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, ride.id); + window_invalidate_by_number(WC_RIDE, static_cast(ride.id)); } void Vehicle::UpdateTestFinish() @@ -3164,7 +3164,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, ride.id); + window_invalidate_by_number(WC_RIDE, static_cast(ride.id)); } void Vehicle::TestReset() @@ -3570,7 +3570,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, ride, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_NEWS_VEHICLE_HAS_STALLED, static_cast(ride), ft); } } @@ -5305,7 +5305,8 @@ 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, ride->id, ft); + News::ItemType::Ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, + static_cast(ride->id), ft); } if (gParkRatingCasualtyPenalty < 500) diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 4b127d5a69..2f363306b6 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -893,7 +893,7 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std auto& rideCreateResult = static_cast(*result.get()); if (rideCreateResult.rideIndex != RIDE_ID_NULL) { - obj.Set("ride", rideCreateResult.rideIndex); + obj.Set("ride", static_cast(rideCreateResult.rideIndex)); } } else if (action.GetType() == GameCommand::HireNewStaffMember) From 2768910fbf4d80f93b6ea8b2a31f963fee24691d Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:00:38 +0300 Subject: [PATCH 03/22] Allow Formatter to accept ride_id_t --- src/openrct2/localisation/Formatter.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/openrct2/localisation/Formatter.h b/src/openrct2/localisation/Formatter.h index 7151fdbf94..fb392c9d97 100644 --- a/src/openrct2/localisation/Formatter.h +++ b/src/openrct2/localisation/Formatter.h @@ -16,6 +16,8 @@ extern thread_local uint8_t gCommonFormatArgs[80]; +enum class ride_id_t : uint16_t; + class Formatter { std::array Buffer{}; @@ -83,6 +85,7 @@ public: std::is_same_v::type, int32_t> || std::is_same_v::type, money32> || std::is_same_v::type, money64> || + std::is_same_v::type, ride_id_t> || std::is_same_v::type, rct_string_id> || std::is_same_v::type, uint16_t> || std::is_same_v::type, uint32_t> || @@ -92,7 +95,7 @@ public: // clang-format on uint64_t convertedValue; - if constexpr (std::is_integral_v) + if constexpr (std::is_integral_v || std::is_enum_v) { convertedValue = static_cast(value); } From e65a1f6fc52961e897620091cb1d941fbb1be854 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:02:23 +0300 Subject: [PATCH 04/22] Forward NetworkRideId_t to ride_id_t and adjust serialiser --- src/openrct2/core/DataSerialiserTraits.h | 8 ++++---- src/openrct2/network/NetworkTypes.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index 7cea7fe8f5..ec862bab38 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -218,7 +218,7 @@ template<> struct DataSerializerTraits_t { static void encode(OpenRCT2::IStream* stream, const NetworkRideId_t& val) { - uint32_t temp = static_cast(val.id); + uint32_t temp = static_cast(val); temp = ByteSwapBE(temp); stream->Write(&temp); } @@ -226,16 +226,16 @@ template<> struct DataSerializerTraits_t { uint32_t temp; stream->Read(&temp); - val.id = static_cast(ByteSwapBE(temp)); + val = static_cast(ByteSwapBE(temp)); } static void log(OpenRCT2::IStream* stream, const NetworkRideId_t& val) { char rideId[28] = {}; - snprintf(rideId, sizeof(rideId), "%u", val.id); + snprintf(rideId, sizeof(rideId), "%u", val); stream->Write(rideId, strlen(rideId)); - auto ride = get_ride(val.id); + auto ride = get_ride(val); if (ride != nullptr) { auto rideName = ride->GetName(); diff --git a/src/openrct2/network/NetworkTypes.h b/src/openrct2/network/NetworkTypes.h index 6e4df2285b..c173fbfb16 100644 --- a/src/openrct2/network/NetworkTypes.h +++ b/src/openrct2/network/NetworkTypes.h @@ -126,10 +126,11 @@ template struct NetworkObjectId_t }; #pragma pack(pop) +using NetworkRideId_t = ride_id_t; + // NOTE: When adding new types make sure to have no duplicate _TypeID's otherwise // there is no way to specialize templates if they have the exact symbol. using NetworkPlayerId_t = NetworkObjectId_t; -using NetworkRideId_t = NetworkObjectId_t; using NetworkCheatType_t = NetworkObjectId_t; enum class NetworkStatisticsGroup : uint32_t From b9c679d23e9cd10347cf2f03344c2e8cf7769169 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:03:00 +0300 Subject: [PATCH 05/22] Fix window list only able to hold 255 indices --- src/openrct2/interface/Window_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 9fd1784815..396f46839d 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -48,7 +48,7 @@ struct rct_window rct_windownumber number{}; uint16_t flags{}; rct_scroll scrolls[3]; - uint8_t list_item_positions[1024]{}; + uint32_t list_item_positions[1024]{}; uint16_t no_list_items{}; // 0 for no items int16_t selected_list_item{}; // -1 for none selected union From 47b782ec2d451eb2fe9d8c5a934fd24e178f6439 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:04:15 +0300 Subject: [PATCH 06/22] Use correct type in path finding code --- test/tests/Pathfinding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index df55e74b3e..c34ea49c8f 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -64,7 +64,7 @@ protected: return nullptr; } - static bool FindPath(TileCoordsXYZ* pos, const TileCoordsXYZ& goal, int expectedSteps, int targetRideID) + static bool FindPath(TileCoordsXYZ* pos, const TileCoordsXYZ& goal, int expectedSteps, ride_id_t targetRideID) { // Our start position is in tile coordinates, but we need to give the peep spawn // position in actual world coords (32 units per tile X/Y, 8 per Z level). From ca605d6f82bc758a15a16906d6b73009084de40c Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:07:53 +0300 Subject: [PATCH 07/22] Refactor object selection to use RideManager --- src/openrct2/EditorObjectSelectionSession.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 622262fe06..bafce4fc47 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -192,14 +192,10 @@ void setup_in_use_selection_flags() } } while (tile_element_iterator_next(&iter)); - for (ride_id_t ride_index = 0; ride_index < MAX_RIDES; ride_index++) + for (auto& ride : GetRideManager()) { - auto ride = get_ride(ride_index); - if (ride != nullptr) - { - ObjectEntryIndex type = ride->subtype; - Editor::SetSelectedObject(ObjectType::Ride, type, OBJECT_SELECTION_FLAG_SELECTED); - } + ObjectEntryIndex type = ride.subtype; + Editor::SetSelectedObject(ObjectType::Ride, type, OBJECT_SELECTION_FLAG_SELECTED); } // Apply selected object status for hacked vehicles that may not have an associated ride From 18fa68813d03364ba4540445b2fc55b4a210d88f Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 2 Aug 2021 09:09:51 +0300 Subject: [PATCH 08/22] Adjust importer/exporter --- src/openrct2/rct2/S6Exporter.cpp | 14 +++++++------- src/openrct2/rct2/S6Importer.cpp | 12 +++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 2cffe9bc09..a1ef85dc30 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -609,7 +609,7 @@ void S6Exporter::ExportRides() const Ride nullRide{}; for (int32_t index = 0; index < RCT12_MAX_RIDES_IN_PARK; index++) { - const auto* src = get_ride(index); + const auto* src = get_ride(static_cast(index)); if (src == nullptr) { src = &nullRide; @@ -931,9 +931,9 @@ void S6Exporter::ExportRideMeasurements() { // Get all the ride measurements std::vector ridesWithMeasurements; - for (ride_id_t i = 0; i < RCT12_MAX_RIDES_IN_PARK; i++) + for (size_t i = 0; i < RCT12_MAX_RIDES_IN_PARK; i++) { - auto ride = get_ride(i); + auto ride = get_ride(static_cast(i)); if (ride != nullptr && ride->measurement != nullptr) { ridesWithMeasurements.push_back(ride); @@ -958,8 +958,8 @@ void S6Exporter::ExportRideMeasurements() ExportRideMeasurement(_s6.ride_measurements[i], *src->measurement.get()); auto rideId = src->id; - dst.ride_index = rideId; - _s6.rides[rideId].measurement_index = i; + dst.ride_index = static_cast(rideId); + _s6.rides[static_cast(rideId)].measurement_index = i; i++; } } @@ -1224,7 +1224,7 @@ template<> void S6Exporter::ExportEntity(RCT2SpriteVehicle* dst, const Vehicle* dst->remaining_distance = src->remaining_distance; dst->velocity = src->velocity; dst->acceleration = src->acceleration; - dst->ride = src->ride; + dst->ride = static_cast(src->ride); dst->vehicle_type = src->vehicle_type; dst->colours = src->colours; dst->track_progress = src->track_progress; @@ -1840,7 +1840,7 @@ void S6Exporter::ExportTileElement(RCT12TileElement* dst, const TileElement* src // Skipping IsHighlighted() // This has to be done last, since the maze entry shares fields with the colour and sequence fields. - auto ride = get_ride(dst2->GetRideIndex()); + auto ride = get_ride(static_cast(dst2->GetRideIndex())); if (ride) { if (ride->type == RIDE_TYPE_MAZE) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 5510056d77..1ae9885831 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -530,8 +530,9 @@ public: auto src = &_s6.rides[index]; if (src->type != RIDE_TYPE_NULL) { - auto dst = GetOrAllocateRide(index); - ImportRide(dst, src, index); + const auto rideId = static_cast(index); + auto dst = GetOrAllocateRide(rideId); + ImportRide(dst, src, rideId); } } } @@ -872,7 +873,8 @@ public: { if (src.ride_index != RCT12_RIDE_ID_NULL) { - auto ride = get_ride(src.ride_index); + const auto rideId = static_cast(src.ride_index); + auto ride = get_ride(rideId); if (ride != nullptr) { ride->measurement = std::make_unique(); @@ -1061,7 +1063,7 @@ public: { if (sprite.unknown.sprite_identifier == RCT12SpriteIdentifier::Peep) { - if (sprite.peep.current_ride == rideIndex + if (sprite.peep.current_ride == static_cast(rideIndex) && (static_cast(sprite.peep.state) == PeepState::OnRide || static_cast(sprite.peep.state) == PeepState::EnteringRide)) { @@ -1597,7 +1599,7 @@ template<> void S6Importer::ImportEntity(const RCT12SpriteBase& baseSrc dst->remaining_distance = src->remaining_distance; dst->velocity = src->velocity; dst->acceleration = src->acceleration; - dst->ride = src->ride; + dst->ride = static_cast(src->ride); dst->vehicle_type = src->vehicle_type; dst->colours = src->colours; dst->track_progress = src->track_progress; From ec65a04883736978073d9293e95c62f8bb60c9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 18:36:35 +0300 Subject: [PATCH 09/22] Cast fixes --- src/openrct2-ui/windows/Ride.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index e014523787..9b9aa774bd 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1552,7 +1552,7 @@ static void window_ride_anchor_border_widgets(rct_window* w) static std::optional GetStationIndexFromViewSelection(const rct_window& w) { - const auto* ride = get_ride(w.number); + const auto* ride = get_ride(static_cast(w.number)); if (ride == nullptr) return {}; From 078d12a2070f1aabe4125a1fbde31c4936f28bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 18:36:47 +0300 Subject: [PATCH 10/22] Fix S4 importer --- src/openrct2/rct1/S4Importer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 436fc72c41..fbfd9fa4a8 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -716,7 +716,8 @@ namespace RCT1 { if (_s4.rides[i].type != RideType::Null) { - ImportRide(GetOrAllocateRide(i), &_s4.rides[i], i); + const auto rideId = static_cast(i); + ImportRide(GetOrAllocateRide(rideId), &_s4.rides[i], rideId); } } } @@ -2482,10 +2483,12 @@ namespace RCT1 { if (_s4.scenario_slot_index == SC_URBAN_PARK && _isScenario) { + const auto firstRideId = static_cast(0); + // First, make the queuing peep exit for (auto peep : EntityList()) { - if (peep->State == PeepState::QueuingFront && peep->CurrentRide == 0) + if (peep->State == PeepState::QueuingFront && peep->CurrentRide == firstRideId) { peep->RemoveFromQueue(); peep->SetState(PeepState::Falling); @@ -2494,7 +2497,7 @@ namespace RCT1 } // Now, swap the entrance and exit. - auto ride = get_ride(0); + auto ride = get_ride(firstRideId); if (ride != nullptr) { auto entranceCoords = ride->stations[0].Exit; @@ -2666,13 +2669,13 @@ namespace RCT1 { auto* dst = CreateEntityAt<::Vehicle>(srcBase.sprite_index); auto* src = static_cast(&srcBase); - const auto* ride = get_ride(src->ride); + const auto* ride = get_ride(static_cast(src->ride)); if (ride == nullptr) return; uint8_t vehicleEntryIndex = RCT1::GetVehicleSubEntryIndex(src->vehicle_type); - dst->ride = src->ride; + dst->ride = static_cast(src->ride); dst->ride_subtype = RCTEntryIndexToOpenRCT2EntryIndex(ride->subtype); dst->vehicle_type = vehicleEntryIndex; From e1e29379bafb20a8cdf174bd9206592000463f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 18:37:49 +0300 Subject: [PATCH 11/22] Add thought insertion overload with strong ride id type --- src/openrct2/peep/Guest.cpp | 4 ++++ src/openrct2/peep/Peep.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index b1bc71cba3..deb4807785 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -6811,6 +6811,10 @@ void Guest::InsertNewThought(PeepThoughtType thought_type, ShopItem shopItem) InsertNewThought(thought_type, static_cast(shopItem)); } +void Guest::InsertNewThought(PeepThoughtType thought_type, ride_id_t ride) +{ + InsertNewThought(thought_type, static_cast(ride)); +} /** * * rct2: 0x699F5A diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 5165766865..08b7f6a340 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -774,6 +774,7 @@ public: void UpdateEasterEggInteractions(); void InsertNewThought(PeepThoughtType thought_type); void InsertNewThought(PeepThoughtType thought_type, ShopItem thought_arguments); + void InsertNewThought(PeepThoughtType thought_type, ride_id_t ride); void InsertNewThought(PeepThoughtType thought_type, uint16_t thought_arguments); static Guest* Generate(const CoordsXYZ& coords); bool UpdateQueuePosition(PeepActionType previous_action); From eda3188ecf667546ed045627968a3aeb68d5305f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 18:50:21 +0300 Subject: [PATCH 12/22] Fix rebase --- src/openrct2/peep/Guest.cpp | 23 ++++++++++--------- src/openrct2/rct12/RCT12.h | 2 +- src/openrct2/rct2/S6Exporter.cpp | 5 ++-- .../scripting/bindings/entity/ScVehicle.cpp | 8 +++---- .../scripting/bindings/entity/ScVehicle.hpp | 4 ++-- .../scripting/bindings/ride/ScRide.cpp | 2 +- .../bindings/world/ScTileElement.cpp | 14 +++++------ .../bindings/world/ScTileElement.hpp | 2 +- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index deb4807785..7842dff1e1 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -1822,7 +1822,8 @@ Ride* Guest::FindBestRideToGoOn() Ride* mostExcitingRide = nullptr; for (auto& ride : GetRideManager()) { - if (rideConsideration.size() > ride.id && rideConsideration[ride.id]) + const auto rideIndex = EnumValue(ride.id); + if (rideConsideration.size() > rideIndex && rideConsideration[rideIndex]) { if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL)) { @@ -1853,7 +1854,7 @@ std::bitset Guest::FindRidesToGoOn() { if (!HasRidden(&ride)) { - rideConsideration[ride.id] = true; + rideConsideration[EnumValue(ride.id)] = true; } } } @@ -1874,7 +1875,7 @@ std::bitset Guest::FindRidesToGoOn() for (auto* trackElement : TileElementsView(location)) { auto rideIndex = trackElement->GetRideIndex(); - rideConsideration[rideIndex] = true; + rideConsideration[EnumValue(rideIndex)] = true; } } } @@ -1884,7 +1885,7 @@ std::bitset Guest::FindRidesToGoOn() { if (ride.highest_drop_height > 66 || ride.excitement >= RIDE_RATING(8, 00)) { - rideConsideration[ride.id] = true; + rideConsideration[EnumValue(ride.id)] = true; } } } @@ -3105,7 +3106,7 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co { if (predicate(ride)) { - rideConsideration[ride.id] = true; + rideConsideration[EnumValue(ride.id)] = true; } } } @@ -3133,18 +3134,18 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co if (!predicate(*ride)) continue; - rideConsideration[rideIndex] = true; + rideConsideration[EnumValue(ride->id)] = true; } } } } // Filter the considered rides - uint8_t potentialRides[MAX_RIDES]; + ride_id_t potentialRides[MAX_RIDES]; size_t numPotentialRides = 0; for (auto& ride : GetRideManager()) { - if (rideConsideration[ride.id]) + if (rideConsideration[EnumValue(ride.id)]) { if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL)) { @@ -3657,7 +3658,7 @@ void Guest::UpdateRideAdvanceThroughEntrance() ride->FormatNameTo(ft); if (gConfigNotifications.ride_warnings) { - News::AddItemToQueue(News::ItemType::Ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, CurrentRide, ft); + News::AddItemToQueue(News::ItemType::Ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, EnumValue(CurrentRide), ft); } } @@ -3811,7 +3812,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride* ride) if (queueTime != ride->stations[CurrentRideStation].QueueTime) { ride->stations[CurrentRideStation].QueueTime = queueTime; - window_invalidate_by_number(WC_RIDE, CurrentRide); + window_invalidate_by_number(WC_RIDE, EnumValue(CurrentRide)); } if (PeepFlags & PEEP_FLAGS_TRACKING) @@ -7458,7 +7459,7 @@ void Guest::RemoveRideFromMemory(ride_id_t rideId) break; // Ride ids and shop item ids might have the same value, look only for ride thoughts. - if (IsThoughtShopItemRelated(entry.type) || entry.item != rideId) + if (IsThoughtShopItemRelated(entry.type) || entry.rideId != rideId) { it++; continue; diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index 418b3f08a6..9507cb1c90 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -966,7 +966,7 @@ template std::vector RCT12GetRidesBeenOn(T* srcPeep) { if (srcPeep->rides_been_on[i / 8] & (1 << (i % 8))) { - ridesBeenOn.push_back(i); + ridesBeenOn.push_back(static_cast(i)); } } return ridesBeenOn; diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index a1ef85dc30..e7ffb9ee58 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -170,7 +170,7 @@ static void ride_all_has_any_track_elements(std::arrayIsGhost()) continue; - rideIndexArray[it.element->AsTrack()->GetRideIndex()] = true; + rideIndexArray[EnumValue(it.element->AsTrack()->GetRideIndex())] = true; } } @@ -1330,7 +1330,8 @@ template<> void S6Exporter::ExportEntity(RCT2SpritePeep* dst, const Guest* src) { for (auto rideId : *rideHistory) { - dst->rides_been_on[rideId / 8] |= (1 << (rideId % 8)); + const auto rideIndex = EnumValue(rideId); + dst->rides_been_on[rideIndex / 8] |= (1 << (rideIndex % 8)); } } dst->item_extra_flags = static_cast(src->GetItemFlags() >> 32); diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp index 90389d7157..2f4be2efcb 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp @@ -135,18 +135,18 @@ namespace OpenRCT2::Scripting } } - ride_id_t ScVehicle::ride_get() const + int32_t ScVehicle::ride_get() const { auto vehicle = GetVehicle(); - return vehicle != nullptr ? vehicle->ride : 0; + return EnumValue(vehicle != nullptr ? vehicle->ride : RIDE_ID_NULL); } - void ScVehicle::ride_set(ride_id_t value) + void ScVehicle::ride_set(int32_t value) { ThrowIfGameStateNotMutable(); auto vehicle = GetVehicle(); if (vehicle != nullptr) { - vehicle->ride = value; + vehicle->ride = static_cast(value); } } diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.hpp b/src/openrct2/scripting/bindings/entity/ScVehicle.hpp index 57d29c6194..c98cd5b3dc 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.hpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.hpp @@ -35,8 +35,8 @@ namespace OpenRCT2::Scripting uint8_t spriteType_get() const; void spriteType_set(uint8_t value); - ride_id_t ride_get() const; - void ride_set(ride_id_t value); + int32_t ride_get() const; + void ride_set(int32_t value); uint8_t numSeats_get() const; void numSeats_set(uint8_t value); diff --git a/src/openrct2/scripting/bindings/ride/ScRide.cpp b/src/openrct2/scripting/bindings/ride/ScRide.cpp index 9e81db6ce2..d03c54d141 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 _rideId; + return EnumValue(_rideId); } std::shared_ptr ScRide::object_get() diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 1cc7aadbfb..18f644c1f9 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -431,7 +431,7 @@ namespace OpenRCT2::Scripting { auto el = _element->AsPath(); if (el->IsQueue() && el->GetRideIndex() != RIDE_ID_NULL) - duk_push_int(ctx, el->GetRideIndex()); + duk_push_int(ctx, EnumValue(el->GetRideIndex())); else duk_push_null(ctx); break; @@ -439,13 +439,13 @@ namespace OpenRCT2::Scripting case TILE_ELEMENT_TYPE_TRACK: { auto el = _element->AsTrack(); - duk_push_int(ctx, el->GetRideIndex()); + duk_push_int(ctx, EnumValue(el->GetRideIndex())); break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); - duk_push_int(ctx, el->GetRideIndex()); + duk_push_int(ctx, EnumValue(el->GetRideIndex())); break; } default: @@ -456,7 +456,7 @@ namespace OpenRCT2::Scripting } return DukValue::take_from_stack(ctx); } - void ScTileElement::ride_set(ride_id_t value) + void ScTileElement::ride_set(int32_t value) { ThrowIfGameStateNotMutable(); switch (_element->GetType()) @@ -466,7 +466,7 @@ namespace OpenRCT2::Scripting auto el = _element->AsPath(); if (!el->HasAddition()) { - el->SetRideIndex(value); + el->SetRideIndex(static_cast(value)); Invalidate(); } break; @@ -474,14 +474,14 @@ namespace OpenRCT2::Scripting case TILE_ELEMENT_TYPE_TRACK: { auto el = _element->AsTrack(); - el->SetRideIndex(value); + el->SetRideIndex(static_cast(value)); Invalidate(); break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); - el->SetRideIndex(value); + el->SetRideIndex(static_cast(value)); Invalidate(); break; } diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.hpp b/src/openrct2/scripting/bindings/world/ScTileElement.hpp index 9b0fcd7060..7fa36099ea 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.hpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.hpp @@ -85,7 +85,7 @@ namespace OpenRCT2::Scripting void sequence_set(uint8_t value); DukValue ride_get() const; - void ride_set(ride_id_t value); + void ride_set(int32_t value); DukValue station_get() const; void station_set(uint8_t value); From 18af5d49501097c9322f5ad83e745a7c99609127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:04:53 +0300 Subject: [PATCH 13/22] Use union for window association to prevent casts --- .../windows/DemolishRidePrompt.cpp | 8 +- src/openrct2-ui/windows/MazeConstruction.cpp | 2 +- src/openrct2-ui/windows/NewCampaign.cpp | 4 +- src/openrct2-ui/windows/Ride.cpp | 163 +++++++++--------- src/openrct2-ui/windows/RideConstruction.cpp | 6 +- src/openrct2/interface/Window_internal.h | 6 +- 6 files changed, 96 insertions(+), 93 deletions(-) diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index 88f61a5d8b..b95252ea82 100644 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -125,7 +125,7 @@ static void window_ride_demolish_mouseup(rct_window* w, rct_widgetindex widgetIn { case WIDX_DEMOLISH: { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); ride_action_modify(ride, RIDE_MODIFY_DEMOLISH, GAME_COMMAND_FLAG_APPLY); break; } @@ -142,7 +142,7 @@ static void window_ride_refurbish_mouseup(rct_window* w, rct_widgetindex widgetI { case WIDX_REFURBISH: { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); ride_action_modify(ride, RIDE_MODIFY_RENEW, GAME_COMMAND_FLAG_APPLY); break; } @@ -161,7 +161,7 @@ static void window_ride_demolish_paint(rct_window* w, rct_drawpixelinfo* dpi) { WindowDrawWidgets(w, dpi); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_DEMOLISH_RIDE_ID : STR_DEMOLISH_RIDE_ID_MONEY; @@ -178,7 +178,7 @@ static void window_ride_refurbish_paint(rct_window* w, rct_drawpixelinfo* dpi) { WindowDrawWidgets(w, dpi); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto stringId = (gParkFlags & PARK_FLAGS_NO_MONEY) ? STR_REFURBISH_RIDE_ID_NO_MONEY : STR_REFURBISH_RIDE_ID_MONEY; diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index 9d7a3654cc..aa8e791130 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -181,7 +181,7 @@ static void window_maze_construction_entrance_mouseup(rct_window* w, rct_widgeti return; gRideEntranceExitPlaceType = widgetIndex == WIDX_MAZE_ENTRANCE ? ENTRANCE_TYPE_RIDE_ENTRANCE : ENTRANCE_TYPE_RIDE_EXIT; - gRideEntranceExitPlaceRideIndex = static_cast(w->number); + gRideEntranceExitPlaceRideIndex = w->rideId; gRideEntranceExitPlaceStationIndex = 0; input_set_flag(INPUT_FLAG_6, true); diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index 78139854cb..b091ac7a4a 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -207,9 +207,9 @@ public: else { int32_t numItems = 0; - for (auto rideId : RideList) + for (auto rideIndex : RideList) { - auto curRide = get_ride(rideId); + auto curRide = get_ride(rideIndex); if (curRide != nullptr) { // HACK until dropdown items have longer argument buffers diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 9b9aa774bd..7fb73ba416 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -958,7 +958,7 @@ static void window_ride_draw_tab_main(rct_drawpixelinfo* dpi, rct_window* w) rct_widgetindex widgetIndex = WIDX_TAB_1 + WINDOW_RIDE_PAGE_MAIN; if (!(w->disabled_widgets & (1LL << widgetIndex))) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { int32_t spriteIndex = 0; @@ -1014,7 +1014,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo* dpi, rct_window* w) screenCoords = ScreenCoordsXY{ widget->width() / 2, widget->height() - 12 }; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -1108,7 +1108,7 @@ static void window_ride_draw_tab_images(rct_drawpixelinfo* dpi, rct_window* w) static void window_ride_disable_tabs(rct_window* w) { uint32_t disabled_tabs = 0; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -1585,7 +1585,7 @@ static void window_ride_init_viewport(rct_window* w) if (w->page != WINDOW_RIDE_PAGE_MAIN) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -1717,7 +1717,7 @@ static void window_ride_init_viewport(rct_window* w) */ static void window_ride_rename(rct_window* w) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto rideName = ride->GetName(); @@ -1751,7 +1751,7 @@ static void window_ride_main_mouseup(rct_window* w, rct_widgetindex widgetIndex) break; case WIDX_CONSTRUCTION: { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { ride_construct(ride); @@ -1776,7 +1776,7 @@ static void window_ride_main_mouseup(rct_window* w, rct_widgetindex widgetIndex) case WIDX_TEST_LIGHT: case WIDX_OPEN_LIGHT: { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { RideStatus status; @@ -1814,7 +1814,7 @@ static void window_ride_main_resize(rct_window* w) { minHeight += 20 + RCT1_LIGHT_OFFSET; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { #ifdef __SIMULATE_IN_RIDE_WINDOW__ @@ -1846,7 +1846,7 @@ static void window_ride_main_resize(rct_window* w) static void window_ride_show_view_dropdown(rct_window* w, rct_widget* widget) { rct_widget* dropdownWidget = widget - 1; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -1962,7 +1962,7 @@ static void window_ride_set_dropdown(RideStatusDropdownInfo& info, RideStatus st static void window_ride_show_open_dropdown(rct_window* w, rct_widget* widget) { RideStatusDropdownInfo info; - info.Ride = get_ride(static_cast(w->number)); + info.Ride = get_ride(w->rideId); if (info.Ride == nullptr) return; @@ -2030,7 +2030,7 @@ static void populate_ride_type_dropdown() static void window_ride_show_ride_type_dropdown(rct_window* w, rct_widget* widget) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2126,7 +2126,7 @@ static void populate_vehicle_type_dropdown(Ride* ride) static void window_ride_show_vehicle_type_dropdown(rct_window* w, rct_widget* widget) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2193,7 +2193,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex if (dropdownIndex == -1) { dropdownIndex = w->ride.view + 1; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { if (dropdownIndex != 0 && dropdownIndex <= ride->num_vehicles @@ -2214,7 +2214,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex break; case WIDX_OPEN: { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto status = RideStatus::Closed; @@ -2251,7 +2251,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id; if (rideType < RIDE_TYPE_COUNT) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto rideSetSetting = RideSetSettingAction(rideId, RideSetSetting::RideType, rideType); rideSetSetting.SetCallback([](const GameAction* ga, const GameActions::Result* result) { // Reset ghost track if ride construction window is open, prevents a crash @@ -2278,7 +2278,7 @@ static void window_ride_main_update(rct_window* w) widget_invalidate(w, WIDX_TAB_1); // Update status - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { if (!(ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_MAIN)) @@ -2313,7 +2313,7 @@ static void window_ride_main_textinput(rct_window* w, rct_widgetindex widgetInde if (widgetIndex != WIDX_RENAME || text == nullptr) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { ride_set_name(ride, text, 0); @@ -2347,7 +2347,7 @@ static void window_ride_main_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2479,7 +2479,7 @@ static void window_ride_main_invalidate(rct_window* w) static rct_string_id window_ride_get_status_overall_view(rct_window* w, Formatter& ft) { auto stringId = STR_NONE; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { ride->FormatStatusTo(ft); @@ -2498,7 +2498,7 @@ static rct_string_id window_ride_get_status_overall_view(rct_window* w, Formatte */ static rct_string_id window_ride_get_status_vehicle(rct_window* w, Formatter& ft) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return STR_EMPTY; @@ -2546,7 +2546,7 @@ static rct_string_id window_ride_get_status_vehicle(rct_window* w, Formatter& ft */ static rct_string_id window_ride_get_status_station(rct_window* w, Formatter& ft) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return STR_NONE; @@ -2597,7 +2597,7 @@ static rct_string_id window_ride_get_status_station(rct_window* w, Formatter& ft */ static rct_string_id window_ride_get_status(rct_window* w, Formatter& ft) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (w->ride.view == 0) return window_ride_get_status_overall_view(w, ft); if (ride != nullptr && w->ride.view <= ride->num_vehicles) @@ -2627,7 +2627,7 @@ static void window_ride_main_paint(rct_window* w, rct_drawpixelinfo* dpi) } // View dropdown - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2709,7 +2709,7 @@ static void window_ride_vehicle_resize(rct_window* w) */ static void window_ride_vehicle_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2752,7 +2752,7 @@ static void window_ride_vehicle_dropdown(rct_window* w, rct_widgetindex widgetIn case WIDX_VEHICLE_TYPE_DROPDOWN: if (dropdownIndex >= 0 && static_cast(dropdownIndex) < VehicleDropdownData.size()) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto newRideType = VehicleDropdownData[dropdownIndex].subtype_id; @@ -2777,7 +2777,7 @@ static void window_ride_vehicle_update(rct_window* w) static OpenRCT2String window_ride_vehicle_tooltip( rct_window* const w, const rct_widgetindex widgetIndex, rct_string_id fallback) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return { STR_NONE, {} }; @@ -2844,7 +2844,7 @@ static void window_ride_vehicle_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2924,7 +2924,7 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -2999,7 +2999,7 @@ static rct_vehicle_paintinfo _sprites_to_draw[144]; */ static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3092,7 +3092,7 @@ static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dp */ static void window_ride_mode_tweak_increase(rct_window* w) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3118,8 +3118,7 @@ static void window_ride_mode_tweak_increase(rct_window* w) */ static void window_ride_mode_tweak_decrease(rct_window* w) { - const auto rideId = static_cast(w->number); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3134,7 +3133,7 @@ static void window_ride_mode_tweak_decrease(rct_window* w) uint8_t decrement = ride->mode == RideMode::Dodgems ? 10 : 1; set_operating_setting( - rideId, RideSetSetting::Operation, std::clamp(ride->operation_option - decrement, minValue, maxValue)); + w->rideId, RideSetSetting::Operation, std::clamp(ride->operation_option - decrement, minValue, maxValue)); } /** @@ -3146,7 +3145,7 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) rct_widget* dropdownWidget; dropdownWidget = widget - 1; - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3186,7 +3185,7 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) */ static void window_ride_load_dropdown(rct_window* w, rct_widget* widget) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3210,7 +3209,7 @@ static void window_ride_load_dropdown(rct_window* w, rct_widget* widget) */ static void window_ride_operating_mouseup(rct_window* w, rct_widgetindex widgetIndex) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3267,7 +3266,7 @@ static void window_ride_operating_resize(rct_window* w) */ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3353,7 +3352,7 @@ static void window_ride_operating_dropdown(rct_window* w, rct_widgetindex widget if (dropdownIndex == -1) return; - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3398,7 +3397,7 @@ static void window_ride_operating_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_3); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_OPERATING) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_OPERATING; @@ -3424,7 +3423,7 @@ static void window_ride_operating_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3665,7 +3664,7 @@ static void window_ride_operating_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3697,7 +3696,7 @@ static void window_ride_operating_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_ride_locate_mechanic(rct_window* w) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3787,7 +3786,7 @@ static void window_ride_maintenance_resize(rct_window* w) */ static void window_ride_maintenance_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3891,7 +3890,7 @@ static void window_ride_maintenance_dropdown(rct_window* w, rct_widgetindex widg if (dropdownIndex == -1) return; - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -3998,7 +3997,7 @@ static void window_ride_maintenance_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_4); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_MAINTENANCE) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_MAINTENANCE; @@ -4021,7 +4020,7 @@ static void window_ride_maintenance_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4063,7 +4062,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4218,7 +4217,7 @@ static void window_ride_set_track_colour_scheme(rct_window* w, const ScreenCoord return; if (info.Element->GetType() != TILE_ELEMENT_TYPE_TRACK) return; - if (info.Element->AsTrack()->GetRideIndex() != static_cast(w->number)) + if (info.Element->AsTrack()->GetRideIndex() != w->rideId) return; if (info.Element->AsTrack()->GetColourScheme() == newColourScheme) return; @@ -4296,7 +4295,7 @@ static void window_ride_colour_mousedown(rct_window* w, rct_widgetindex widgetIn int32_t i, numItems; rct_string_id stringId; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4429,7 +4428,7 @@ static void window_ride_colour_dropdown(rct_window* w, rct_widgetindex widgetInd if (dropdownIndex == -1) return; - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; switch (widgetIndex) { case WIDX_TRACK_COLOUR_SCHEME_DROPDOWN: @@ -4571,7 +4570,7 @@ static void window_ride_colour_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4797,7 +4796,7 @@ static void window_ride_colour_paint(rct_window* w, rct_drawpixelinfo* dpi) rct_drawpixelinfo clippedDpi; rct_widget* widget; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4897,7 +4896,7 @@ static void window_ride_colour_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_ride_colour_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -4960,7 +4959,7 @@ static std::vector window_ride_current_music_style_order; */ static void window_ride_toggle_music(rct_window* w) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride != nullptr) { @@ -5037,7 +5036,7 @@ static void window_ride_music_mousedown(rct_window* w, rct_widgetindex widgetInd return; auto dropdownWidget = widget - 1; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -5116,7 +5115,7 @@ static void window_ride_music_dropdown(rct_window* w, rct_widgetindex widgetInde && static_cast(dropdownIndex) < window_ride_current_music_style_order.size()) { auto musicStyle = window_ride_current_music_style_order[dropdownIndex]; - set_operating_setting(static_cast(w->number), RideSetSetting::MusicType, musicStyle); + set_operating_setting(w->rideId, RideSetSetting::MusicType, musicStyle); } } @@ -5146,7 +5145,7 @@ static void window_ride_music_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -5237,7 +5236,7 @@ static void setup_scenery_selection(rct_window* w) while (tool_set(w, WIDX_BACKGROUND, Tool::Crosshair)) ; - gTrackDesignSaveRideIndex = static_cast(w->number); + gTrackDesignSaveRideIndex = w->rideId; track_design_save_init(); gGamePaused |= GAME_PAUSED_SAVING_TRACK; @@ -5300,7 +5299,7 @@ static void TrackDesignCallback(int32_t result, [[maybe_unused]] const utf8* pat */ static void window_ride_measurements_design_save(rct_window* w) { - Ride* ride = get_ride(static_cast(w->number)); + Ride* ride = get_ride(w->rideId); _trackDesign = ride->SaveToTrackDesign(); if (!_trackDesign) { @@ -5392,7 +5391,7 @@ static void window_ride_measurements_mousedown(rct_window* w, rct_widgetindex wi if (widgetIndex != WIDX_SAVE_TRACK_DESIGN) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -5518,7 +5517,7 @@ static void window_ride_measurements_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -5581,7 +5580,7 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi } else { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -5905,7 +5904,7 @@ static void window_ride_graphs_update(rct_window* w) x = w->scrolls[0].h_left; if (!(w->list_information_type & 0x8000)) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { RideMeasurement* measurement{}; @@ -5930,7 +5929,7 @@ static void window_ride_graphs_scrollgetheight(rct_window* w, int32_t scrollInde *width = window_ride_graphs_widgets[WIDX_GRAPH].width() - 2; // Get measurement size - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { RideMeasurement* measurement{}; @@ -5959,7 +5958,7 @@ static OpenRCT2String window_ride_graphs_tooltip(rct_window* w, const rct_widget { if (widgetIndex == WIDX_GRAPH) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto [measurement, message] = ride->GetMeasurement(); @@ -5999,7 +5998,7 @@ static void window_ride_graphs_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -6065,7 +6064,7 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi gfx_clear(dpi, ColourMapA[COLOUR_SATURATED_GREEN].darker); auto widget = &window_ride_graphs_widgets[WIDX_GRAPH]; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) { return; @@ -6258,7 +6257,7 @@ static void update_same_price_throughout_flags(ShopItem shop_item) */ static void window_ride_income_toggle_primary_price(rct_window* w) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -6295,7 +6294,7 @@ static void window_ride_income_toggle_primary_price(rct_window* w) */ static void window_ride_income_toggle_secondary_price(rct_window* w) { - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; auto ride = get_ride(rideId); if (ride == nullptr) return; @@ -6316,7 +6315,7 @@ static void window_ride_income_toggle_secondary_price(rct_window* w) static void window_ride_income_set_primary_price(rct_window* w, money16 price) { - auto rideSetPriceAction = RideSetPriceAction(static_cast(w->number), price, true); + auto rideSetPriceAction = RideSetPriceAction(w->rideId, price, true); GameActions::Execute(&rideSetPriceAction); } @@ -6329,7 +6328,7 @@ static void window_ride_income_increase_primary_price(rct_window* w) if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -6349,7 +6348,7 @@ static void window_ride_income_decrease_primary_price(rct_window* w) if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -6362,7 +6361,7 @@ static void window_ride_income_decrease_primary_price(rct_window* w) static money16 window_ride_income_get_secondary_price(rct_window* w) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return 0; @@ -6372,13 +6371,13 @@ static money16 window_ride_income_get_secondary_price(rct_window* w) static void window_ride_income_set_secondary_price(rct_window* w, money16 price) { - auto rideSetPriceAction = RideSetPriceAction(static_cast(w->number), price, false); + auto rideSetPriceAction = RideSetPriceAction(w->rideId, price, false); GameActions::Execute(&rideSetPriceAction); } static bool window_ride_income_can_modify_primary_price(rct_window* w) { - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return false; @@ -6443,7 +6442,7 @@ static void window_ride_income_mouseup(rct_window* w, rct_widgetindex widgetInde if (!window_ride_income_can_modify_primary_price(w)) return; - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { money_to_string(static_cast(ride->price[0]), _moneyInputText, MONEY_STRING_MAXLENGTH, true); @@ -6513,7 +6512,7 @@ static void window_ride_income_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_9); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_INCOME) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_INCOME; @@ -6560,7 +6559,7 @@ static void window_ride_income_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -6671,7 +6670,7 @@ static void window_ride_income_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -6839,7 +6838,7 @@ static void window_ride_customer_update(rct_window* w) window_event_invalidate_call(w); widget_invalidate(w, WIDX_TAB_10); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr && ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_CUSTOMER) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_CUSTOMER; @@ -6862,7 +6861,7 @@ static void window_ride_customer_invalidate(rct_window* w) window_ride_set_pressed_tab(w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride != nullptr) { auto ft = Formatter::Common(); @@ -6898,7 +6897,7 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(w, dpi); window_ride_draw_tab_images(dpi, w); - auto ride = get_ride(static_cast(w->number)); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index d8424785d3..5cdb6c6934 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -1937,7 +1937,7 @@ static void window_ride_construction_mouseup_demolish(rct_window* w) _currentTrackPieceType, 0, { _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z, _currentTrackPieceDirection }); - const auto rideId = static_cast(w->number); + const auto rideId = w->rideId; trackRemoveAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) { @@ -1987,7 +1987,7 @@ static void window_ride_construction_entrance_click(rct_window* w) else { gRideEntranceExitPlaceType = ENTRANCE_TYPE_RIDE_ENTRANCE; - gRideEntranceExitPlaceRideIndex = static_cast(w->number); + gRideEntranceExitPlaceRideIndex = w->rideId; gRideEntranceExitPlaceStationIndex = 0; input_set_flag(INPUT_FLAG_6, true); ride_construction_invalidate_current_track(); @@ -2017,7 +2017,7 @@ static void window_ride_construction_exit_click(rct_window* w) else { gRideEntranceExitPlaceType = ENTRANCE_TYPE_RIDE_EXIT; - gRideEntranceExitPlaceRideIndex = static_cast(w->number); + gRideEntranceExitPlaceRideIndex = w->rideId; gRideEntranceExitPlaceStationIndex = 0; input_set_flag(INPUT_FLAG_6, true); ride_construction_invalidate_current_track(); diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 396f46839d..ed63206e35 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -45,7 +45,11 @@ struct rct_window int16_t max_width{}; int16_t min_height{}; int16_t max_height{}; - rct_windownumber number{}; + union + { + rct_windownumber number{}; + ride_id_t rideId; + }; uint16_t flags{}; rct_scroll scrolls[3]; uint32_t list_item_positions[1024]{}; From 120bb10fd5e48f9bf4c139db515d944cbc3c7650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:06:28 +0300 Subject: [PATCH 14/22] Fix serialiser traits --- src/openrct2/core/DataSerialiserTraits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index ec862bab38..b3cfc9dc04 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -231,7 +231,7 @@ template<> struct DataSerializerTraits_t static void log(OpenRCT2::IStream* stream, const NetworkRideId_t& val) { char rideId[28] = {}; - snprintf(rideId, sizeof(rideId), "%u", val); + snprintf(rideId, sizeof(rideId), "%u", EnumValue(val)); stream->Write(rideId, strlen(rideId)); From f8e26a3752a359c76829c1a36156ae3ac9309458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:17:37 +0300 Subject: [PATCH 15/22] Fix signed/unsigned mismatch --- src/openrct2-ui/windows/Ride.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 7fb73ba416..b9bb9f2673 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1192,12 +1192,13 @@ static void window_ride_update_overall_view(Ride* ride) maxz = std::max(maxz, clearZ); } - if (static_cast(ride->id) >= ride_overall_views.size()) + const auto rideIndex = EnumValue(ride->id); + if (rideIndex >= ride_overall_views.size()) { - ride_overall_views.resize(static_cast(ride->id) + 1); + ride_overall_views.resize(rideIndex + 1); } - auto& view = ride_overall_views[static_cast(ride->id)]; + auto& view = ride_overall_views[rideIndex]; view.x = (minx + maxx) / 2 + 16; view.y = (miny + maxy) / 2 + 16; view.z = (minz + maxz) / 2 - 8; From 50467d4fd8c9079726a2b0a7e63a430d844c4813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Sep 2021 16:20:34 +0300 Subject: [PATCH 16/22] Remove unused serialiser traits --- src/openrct2/core/DataSerialiserTraits.h | 33 ------------------------ 1 file changed, 33 deletions(-) diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index b3cfc9dc04..ca391d360c 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -214,39 +214,6 @@ template<> struct DataSerializerTraits_t } }; -template<> struct DataSerializerTraits_t -{ - static void encode(OpenRCT2::IStream* stream, const NetworkRideId_t& val) - { - uint32_t temp = static_cast(val); - temp = ByteSwapBE(temp); - stream->Write(&temp); - } - static void decode(OpenRCT2::IStream* stream, NetworkRideId_t& val) - { - uint32_t temp; - stream->Read(&temp); - val = static_cast(ByteSwapBE(temp)); - } - static void log(OpenRCT2::IStream* stream, const NetworkRideId_t& val) - { - char rideId[28] = {}; - snprintf(rideId, sizeof(rideId), "%u", EnumValue(val)); - - stream->Write(rideId, strlen(rideId)); - - auto ride = get_ride(val); - if (ride != nullptr) - { - auto rideName = ride->GetName(); - - stream->Write(" \"", 2); - stream->Write(rideName.c_str(), rideName.size()); - stream->Write("\"", 1); - } - } -}; - template struct DataSerializerTraits_t> { static void encode(OpenRCT2::IStream* stream, const DataSerialiserTag& tag) From 0cdd348428c8277c347750e6407debece6079868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Sep 2021 16:22:35 +0300 Subject: [PATCH 17/22] Update replays --- CMakeLists.txt | 4 ++-- openrct2.proj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab47c2c638..622ac35946 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,9 +50,9 @@ set(OBJECTS_VERSION "1.0.21") set(OBJECTS_URL "https://github.com/OpenRCT2/objects/releases/download/v${OBJECTS_VERSION}/objects.zip") set(OBJECTS_SHA1 "c38af45d51a6e440386180feacf76c64720b6ac5") -set(REPLAYS_VERSION "0.0.50") +set(REPLAYS_VERSION "0.0.51") set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v${REPLAYS_VERSION}/replays.zip") -set(REPLAYS_SHA1 "C569C73147F1C1554807B6FBE74C39A4F0E20EAF") +set(REPLAYS_SHA1 "01086A05A3291B296906AE215855BC7CDB045A6A") option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags.") option(WITH_TESTS "Build tests") diff --git a/openrct2.proj b/openrct2.proj index 504b00508c..f2f33c624f 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -48,8 +48,8 @@ 304d13a126c15bf2c86ff13b81a2f2cc1856ac8d https://github.com/OpenRCT2/objects/releases/download/v1.0.21/objects.zip c38af45d51a6e440386180feacf76c64720b6ac5 - https://github.com/OpenRCT2/replays/releases/download/v0.0.50/replays.zip - C569C73147F1C1554807B6FBE74C39A4F0E20EAF + https://github.com/OpenRCT2/replays/releases/download/v0.0.51/replays.zip + 01086A05A3291B296906AE215855BC7CDB045A6A From 8a21bd01c664ce2143d9e7f8b5631271a616e1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Sep 2021 16:46:16 +0300 Subject: [PATCH 18/22] Bump up scripting version --- src/openrct2/scripting/ScriptEngine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 404e7daffd..1e0c0db23b 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 36; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 37; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; From d7e0e473c13e827faa8e2e7d24e961643ee7b847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Sep 2021 16:40:12 +0300 Subject: [PATCH 19/22] Apply review suggestion, cleanup --- .../windows/DemolishRidePrompt.cpp | 4 +- src/openrct2-ui/windows/MazeConstruction.cpp | 2 +- src/openrct2-ui/windows/Ride.cpp | 38 ++++++++----------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index b95252ea82..94fc63ea8a 100644 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -84,7 +84,7 @@ rct_window* window_ride_demolish_prompt_open(Ride* ride) w->widgets = window_ride_demolish_widgets; w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_DEMOLISH); WindowInitScrollWidgets(w); - w->number = static_cast(ride->id); + w->rideId = ride->id; _demolishRideCost = -ride_get_refund_price(ride); return w; @@ -109,7 +109,7 @@ rct_window* window_ride_refurbish_prompt_open(Ride* ride) w->widgets = window_ride_refurbish_widgets; w->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_CANCEL) | (1ULL << WIDX_REFURBISH); WindowInitScrollWidgets(w); - w->number = static_cast(ride->id); + w->rideId = ride->id; _demolishRideCost = -ride_get_refund_price(ride); return w; diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index aa8e791130..e08708daa6 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -130,7 +130,7 @@ rct_window* window_maze_construction_open() WindowInitScrollWidgets(w); - w->number = static_cast(_currentRideIndex); + w->rideId = _currentRideIndex; window_push_others_right(w); show_gridlines(); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index b9bb9f2673..acab395266 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1235,7 +1235,7 @@ static rct_window* window_ride_open(Ride* ride) w->widgets = window_ride_page_widgets[WINDOW_RIDE_PAGE_MAIN]; w->enabled_widgets = window_ride_page_enabled_widgets[WINDOW_RIDE_PAGE_MAIN]; w->hold_down_widgets = window_ride_page_hold_down_widgets[WINDOW_RIDE_PAGE_MAIN]; - w->number = static_cast(ride->id); + w->rideId = ride->id; w->page = WINDOW_RIDE_PAGE_MAIN; w->vehicleIndex = 0; @@ -1265,7 +1265,7 @@ rct_window* window_ride_main_open(Ride* ride) return nullptr; } - rct_window* w = window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); + rct_window* w = window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); if (w == nullptr) { w = window_ride_open(ride); @@ -1306,7 +1306,7 @@ static rct_window* window_ride_open_station(Ride* ride, StationIndex stationInde if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) return window_ride_main_open(ride); - auto w = window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); + auto w = window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); if (w == nullptr) { w = window_ride_open(ride); @@ -1408,7 +1408,7 @@ rct_window* window_ride_open_vehicle(Vehicle* vehicle) view++; } - rct_window* w = window_find_by_number(WC_RIDE, static_cast(ride->id)); + rct_window* w = window_find_by_number(WC_RIDE, EnumValue(ride->id)); if (w != nullptr) { w->Invalidate(); @@ -1443,8 +1443,8 @@ rct_window* window_ride_open_vehicle(Vehicle* vehicle) } } - w = openedPeepWindow ? window_find_by_number(WC_RIDE, static_cast(ride->id)) - : window_bring_to_front_by_number(WC_RIDE, static_cast(ride->id)); + w = openedPeepWindow ? window_find_by_number(WC_RIDE, EnumValue(ride->id)) + : window_bring_to_front_by_number(WC_RIDE, EnumValue(ride->id)); } if (w == nullptr) @@ -1756,7 +1756,7 @@ static void window_ride_main_mouseup(rct_window* w, rct_widgetindex widgetIndex) if (ride != nullptr) { ride_construct(ride); - if (window_find_by_number(WC_RIDE_CONSTRUCTION, static_cast(ride->id)) != nullptr) + if (window_find_by_number(WC_RIDE_CONSTRUCTION, EnumValue(ride->id)) != nullptr) { window_close(w); } @@ -2252,8 +2252,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id; if (rideType < RIDE_TYPE_COUNT) { - const auto rideId = w->rideId; - auto rideSetSetting = RideSetSettingAction(rideId, RideSetSetting::RideType, rideType); + auto rideSetSetting = RideSetSettingAction(w->rideId, RideSetSetting::RideType, rideType); rideSetSetting.SetCallback([](const GameAction* ga, const GameActions::Result* result) { // Reset ghost track if ride construction window is open, prevents a crash // Will get set to the correct Alternative variable during set_default_next_piece. @@ -3093,8 +3092,7 @@ static void window_ride_vehicle_scrollpaint(rct_window* w, rct_drawpixelinfo* dp */ static void window_ride_mode_tweak_increase(rct_window* w) { - const auto rideId = w->rideId; - auto ride = get_ride(rideId); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3110,7 +3108,7 @@ static void window_ride_mode_tweak_increase(rct_window* w) uint8_t increment = ride->mode == RideMode::Dodgems ? 10 : 1; set_operating_setting( - rideId, RideSetSetting::Operation, std::clamp(ride->operation_option + increment, minValue, maxValue)); + w->rideId, RideSetSetting::Operation, std::clamp(ride->operation_option + increment, minValue, maxValue)); } /** @@ -3146,8 +3144,7 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) rct_widget* dropdownWidget; dropdownWidget = widget - 1; - const auto rideId = w->rideId; - auto ride = get_ride(rideId); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3186,8 +3183,7 @@ static void window_ride_mode_dropdown(rct_window* w, rct_widget* widget) */ static void window_ride_load_dropdown(rct_window* w, rct_widget* widget) { - const auto rideId = w->rideId; - auto ride = get_ride(rideId); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3891,8 +3887,7 @@ static void window_ride_maintenance_dropdown(rct_window* w, rct_widgetindex widg if (dropdownIndex == -1) return; - const auto rideId = w->rideId; - auto ride = get_ride(rideId); + auto ride = get_ride(w->rideId); if (ride == nullptr) return; @@ -3903,7 +3898,7 @@ static void window_ride_maintenance_dropdown(rct_window* w, rct_widgetindex widg switch (widgetIndex) { case WIDX_INSPECTION_INTERVAL_DROPDOWN: - set_operating_setting(rideId, RideSetSetting::InspectionInterval, dropdownIndex); + set_operating_setting(w->rideId, RideSetSetting::InspectionInterval, dropdownIndex); break; case WIDX_FORCE_BREAKDOWN: @@ -4960,12 +4955,11 @@ static std::vector window_ride_current_music_style_order; */ static void window_ride_toggle_music(rct_window* w) { - const auto rideId = w->rideId; - auto ride = get_ride(rideId); + auto ride = get_ride(w->rideId); if (ride != nullptr) { int32_t activateMusic = (ride->lifecycle_flags & RIDE_LIFECYCLE_MUSIC) ? 0 : 1; - set_operating_setting(rideId, RideSetSetting::Music, activateMusic); + set_operating_setting(w->rideId, RideSetSetting::Music, activateMusic); } } From d21ccc103b99102afc5f0bc4ede135fd0b6318d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:23:46 +0300 Subject: [PATCH 20/22] Bump up network version --- src/openrct2/network/NetworkBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 691c0467e9..d2c3334245 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -37,7 +37,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "8" +#define NETWORK_STREAM_VERSION "9" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; From 516232e0a79d525ba8243d2afe8e8daf325e7fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 8 Sep 2021 17:07:41 +0300 Subject: [PATCH 21/22] Change static casts to EnumValue --- src/openrct2-ui/WindowManager.cpp | 2 +- .../windows/EditorObjectiveOptions.cpp | 2 +- src/openrct2-ui/windows/Guest.cpp | 2 +- src/openrct2-ui/windows/MazeConstruction.cpp | 2 +- src/openrct2-ui/windows/RideConstruction.cpp | 6 ++--- src/openrct2-ui/windows/RideList.cpp | 2 +- src/openrct2/actions/RideDemolishAction.cpp | 2 +- .../actions/RideEntranceExitPlaceAction.cpp | 4 ++-- .../actions/RideEntranceExitRemoveAction.cpp | 12 +++++----- .../actions/RideSetAppearanceAction.cpp | 2 +- src/openrct2/actions/RideSetPriceAction.cpp | 2 +- src/openrct2/actions/RideSetSettingAction.cpp | 6 ++--- src/openrct2/actions/RideSetStatusAction.cpp | 12 +++++----- src/openrct2/actions/RideSetVehicleAction.cpp | 2 +- src/openrct2/actions/TrackPlaceAction.cpp | 10 ++++---- src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/ride/Ride.cpp | 24 +++++++++---------- src/openrct2/ride/RideConstruction.cpp | 4 ++-- src/openrct2/ride/RideRatings.cpp | 6 ++--- src/openrct2/ride/Vehicle.cpp | 12 +++++----- src/openrct2/scripting/ScriptEngine.cpp | 2 +- 21 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index bdcb8a0c9a..4b9366ecb1 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -396,7 +396,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, static_cast(vehicle->ride)); + auto w = window_find_by_number(WC_RIDE, EnumValue(vehicle->ride)); if (w == nullptr) return; diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index 50bb176749..5bd5919deb 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -972,7 +972,7 @@ static void window_editor_objective_options_rides_update(rct_window* w) { if (ride.IsRide()) { - w->list_item_positions[numItems] = static_cast(ride.id); + w->list_item_positions[numItems] = EnumValue(ride.id); numItems++; } } diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 4c35e18d02..cbdb074338 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1456,7 +1456,7 @@ void window_guest_rides_update(rct_window* w) { if (ride.IsRide() && guest->HasRidden(&ride)) { - w->list_item_positions[curr_list_position] = static_cast(ride.id); + w->list_item_positions[curr_list_position] = EnumValue(ride.id); curr_list_position++; } } diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index e08708daa6..e82f43edbc 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -169,7 +169,7 @@ static void window_maze_construction_close(rct_window* w) else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(ride->id)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(ride->id)); context_open_intent(&intent); } } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 5cdb6c6934..8eb5a7dc55 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -509,7 +509,7 @@ static void close_ride_window_for_construction(rct_windownumber number) rct_window* window_ride_construction_open() { ride_id_t rideIndex = _currentRideIndex; - close_ride_window_for_construction(static_cast(rideIndex)); + close_ride_window_for_construction(EnumValue(rideIndex)); auto ride = get_ride(rideIndex); if (ride == nullptr) @@ -543,7 +543,7 @@ rct_window* window_ride_construction_open() w->colours[1] = COLOUR_DARK_BROWN; w->colours[2] = COLOUR_DARK_BROWN; - w->number = static_cast(rideIndex); + w->rideId = rideIndex; window_push_others_right(w); show_gridlines(); @@ -620,7 +620,7 @@ static void window_ride_construction_close(rct_window* w) ride->SetToDefaultInspectionInterval(); auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(ride->id)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(ride->id)); context_open_intent(&intent); } else diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 94a51eb2c9..de3ecf4b09 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -443,7 +443,7 @@ static void window_ride_list_scrollmousedown(rct_window* w, int32_t scrollIndex, else { auto intent = Intent(WC_RIDE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(rideIndex)); context_open_intent(&intent); } } diff --git a/src/openrct2/actions/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index c59bc5c1c3..2d063ce8f6 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -274,7 +274,7 @@ GameActions::Result::Ptr RideDemolishAction::RefurbishRide(Ride* ride) const res->Position = { location, tile_element_height(location) }; } - window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, static_cast(_rideIndex)); + window_close_by_number(WC_DEMOLISH_RIDE_PROMPT, EnumValue(_rideIndex)); return res; } diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp index fc20629013..df49331e73 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp @@ -54,7 +54,7 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %d", static_cast(_rideIndex)); + log_warning("Invalid game command for ride %d", EnumValue(_rideIndex)); return MakeResult(GameActions::Status::InvalidParameters, errorTitle); } @@ -132,7 +132,7 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid game command for ride %d", static_cast(_rideIndex)); + log_warning("Invalid game command for ride %d", EnumValue(_rideIndex)); return MakeResult(GameActions::Status::InvalidParameters, errorTitle); } diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp index f4fac8cae3..6144d29eda 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp @@ -74,7 +74,7 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride id %d for entrance/exit removal", static_cast(_rideIndex)); + log_warning("Invalid ride id %d for entrance/exit removal", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters, STR_NONE); } @@ -99,8 +99,8 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Query() const if (entranceElement == nullptr) { log_warning( - "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, - static_cast(_rideIndex), _stationNum); + "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, EnumValue(_rideIndex), + _stationNum); return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); } @@ -112,7 +112,7 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride id %d for entrance/exit removal", static_cast(_rideIndex)); + log_warning("Invalid ride id %d for entrance/exit removal", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters, STR_NONE); } @@ -130,8 +130,8 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Execute() const if (entranceElement == nullptr) { log_warning( - "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, - static_cast(_rideIndex), _stationNum); + "Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y, EnumValue(_rideIndex), + _stationNum); return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); } diff --git a/src/openrct2/actions/RideSetAppearanceAction.cpp b/src/openrct2/actions/RideSetAppearanceAction.cpp index bf8e9fc366..d5355db520 100644 --- a/src/openrct2/actions/RideSetAppearanceAction.cpp +++ b/src/openrct2/actions/RideSetAppearanceAction.cpp @@ -139,7 +139,7 @@ GameActions::Result::Ptr RideSetAppearanceAction::Execute() const gfx_invalidate_screen(); break; } - window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); + window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); auto res = std::make_unique(); if (!ride->overall_view.IsNull()) diff --git a/src/openrct2/actions/RideSetPriceAction.cpp b/src/openrct2/actions/RideSetPriceAction.cpp index 268fd7d9a7..81b29ce432 100644 --- a/src/openrct2/actions/RideSetPriceAction.cpp +++ b/src/openrct2/actions/RideSetPriceAction.cpp @@ -180,7 +180,7 @@ void RideSetPriceAction::RideSetCommonPrice(ShopItem shopItem) const } if (invalidate) { - window_invalidate_by_number(WC_RIDE, static_cast(ride.id)); + window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); } } } diff --git a/src/openrct2/actions/RideSetSettingAction.cpp b/src/openrct2/actions/RideSetSettingAction.cpp index 233b19154e..1c5a5ac262 100644 --- a/src/openrct2/actions/RideSetSettingAction.cpp +++ b/src/openrct2/actions/RideSetSettingAction.cpp @@ -45,7 +45,7 @@ GameActions::Result::Ptr RideSetSettingAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride: #%d.", static_cast(_rideIndex)); + log_warning("Invalid ride: #%d.", EnumValue(_rideIndex)); return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_OPERATING_MODE); } @@ -153,7 +153,7 @@ GameActions::Result::Ptr RideSetSettingAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride: #%d.", static_cast(_rideIndex)); + log_warning("Invalid ride: #%d.", EnumValue(_rideIndex)); return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_OPERATING_MODE); } @@ -233,7 +233,7 @@ GameActions::Result::Ptr RideSetSettingAction::Execute() const auto location = ride->overall_view.ToTileCentre(); res->Position = { location, tile_element_height(location) }; } - window_invalidate_by_number(WC_RIDE, static_cast(_rideIndex)); + window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); return res; } diff --git a/src/openrct2/actions/RideSetStatusAction.cpp b/src/openrct2/actions/RideSetStatusAction.cpp index 5a79dae8bd..9743b311a0 100644 --- a/src/openrct2/actions/RideSetStatusAction.cpp +++ b/src/openrct2/actions/RideSetStatusAction.cpp @@ -59,7 +59,7 @@ GameActions::Result::Ptr RideSetStatusAction::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", EnumValue(_rideIndex)); res->Error = GameActions::Status::InvalidParameters; res->ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; res->ErrorMessage = STR_NONE; @@ -68,7 +68,7 @@ GameActions::Result::Ptr RideSetStatusAction::Query() const if (_status >= RideStatus::Count) { - log_warning("Invalid ride status %u for ride %u", uint32_t(_status), uint32_t(_rideIndex)); + log_warning("Invalid ride status %u for ride %u", EnumValue(_status), EnumValue(_rideIndex)); res->Error = GameActions::Status::InvalidParameters; res->ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; res->ErrorMessage = STR_NONE; @@ -154,7 +154,7 @@ GameActions::Result::Ptr 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, static_cast(_rideIndex)); + window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); break; case RideStatus::Simulating: { @@ -176,7 +176,7 @@ GameActions::Result::Ptr 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, static_cast(_rideIndex)); + window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); break; } case RideStatus::Testing: @@ -195,7 +195,7 @@ GameActions::Result::Ptr 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, static_cast(_rideIndex)); + rct_window* constructionWindow = window_find_by_number(WC_RIDE_CONSTRUCTION, EnumValue(_rideIndex)); if (constructionWindow != nullptr) { window_close(constructionWindow); @@ -223,7 +223,7 @@ GameActions::Result::Ptr 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, static_cast(_rideIndex)); + window_invalidate_by_number(WC_RIDE, EnumValue(_rideIndex)); break; } default: diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index bda774375f..b03b792348 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -199,7 +199,7 @@ GameActions::Result::Ptr RideSetVehicleAction::Execute() const } auto intent = Intent(INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(_rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(_rideIndex)); context_broadcast_intent(&intent); gfx_invalidate_screen(); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index aeb736728c..a3269cbe9a 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -85,13 +85,13 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride for track placement, rideIndex = %d", static_cast(_rideIndex)); + log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters, STR_NONE); } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid ride subtype for track placement, rideIndex = %d", static_cast(_rideIndex)); + log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters, STR_NONE); } @@ -379,14 +379,14 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const auto ride = get_ride(_rideIndex); if (ride == nullptr) { - log_warning("Invalid ride for track placement, rideIndex = %d", static_cast(_rideIndex)); + log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters); } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { - log_warning("Invalid ride subtype for track placement, rideIndex = %d", static_cast(_rideIndex)); + log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::InvalidParameters); } @@ -550,7 +550,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const auto* trackElement = TileElementInsert(mapLoc, quarterTile.GetBaseQuarterOccupied()); if (trackElement == nullptr) { - log_warning("Cannot create track element for ride = %d", static_cast(_rideIndex)); + log_warning("Cannot create track element for ride = %d", EnumValue(_rideIndex)); return std::make_unique(GameActions::Status::NoFreeElements); } diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index e7ffb9ee58..d646534def 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -959,7 +959,7 @@ void S6Exporter::ExportRideMeasurements() auto rideId = src->id; dst.ride_index = static_cast(rideId); - _s6.rides[static_cast(rideId)].measurement_index = i; + _s6.rides[dst.ride_index].measurement_index = i; i++; } } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 392992b9ae..d39f418e69 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1505,7 +1505,7 @@ void ride_breakdown_add_news_item(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, static_cast(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_BROKEN_DOWN, EnumValue(ride->id), ft); } } @@ -1532,7 +1532,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, static_cast(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_IS_STILL_NOT_FIXED, EnumValue(ride->id), ft); } } } @@ -2183,7 +2183,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, static_cast(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, EnumValue(ride->id), ft); } ride->connected_message_throttle = 3; } @@ -2195,7 +2195,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, static_cast(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_EXIT_NOT_CONNECTED, EnumValue(ride->id), ft); } ride->connected_message_throttle = 3; } @@ -2264,7 +2264,7 @@ static void ride_shop_connected(Ride* ride) { Formatter ft; ride->FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, static_cast(ride->id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, EnumValue(ride->id), ft); } ride->connected_message_throttle = 3; @@ -3797,13 +3797,13 @@ bool Ride::Test(RideStatus newStatus, bool isApplying) if (type == RIDE_TYPE_NULL) { - log_warning("Invalid ride type for ride %u", static_cast(id)); + log_warning("Invalid ride type for ride %u", EnumValue(id)); return false; } if (newStatus != RideStatus::Simulating) { - window_close_by_number(WC_RIDE_CONSTRUCTION, static_cast(id)); + window_close_by_number(WC_RIDE_CONSTRUCTION, EnumValue(id)); } StationIndex stationIndex = ride_mode_check_station_present(this); @@ -3930,10 +3930,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 - && static_cast(id) == gCurrentToolWidget.window_number && (input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) + if (WC_RIDE_CONSTRUCTION == gCurrentToolWidget.window_classification && EnumValue(id) == gCurrentToolWidget.window_number + && (input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) { - window_close_by_number(WC_RIDE_CONSTRUCTION, static_cast(id)); + window_close_by_number(WC_RIDE_CONSTRUCTION, EnumValue(id)); } StationIndex stationIndex = ride_mode_check_station_present(this); @@ -5089,7 +5089,7 @@ void Ride::UpdateMaxVehicles() { num_cars_per_train = numCarsPerTrain; num_vehicles = numVehicles; - window_invalidate_by_number(WC_RIDE, static_cast(id)); + window_invalidate_by_number(WC_RIDE, EnumValue(id)); } } @@ -5158,7 +5158,7 @@ void Ride::Crash(uint8_t vehicleIndex) { Formatter ft; FormatNameTo(ft); - News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, static_cast(id), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_RIDE_HAS_CRASHED, EnumValue(id), ft); } } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index df0b9c152c..722bea5ecc 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -122,7 +122,7 @@ static rct_window* ride_create_or_find_construction_window(ride_id_t rideIndex) { auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto intent = Intent(INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS); - intent.putExtra(INTENT_EXTRA_RIDE_ID, static_cast(rideIndex)); + intent.putExtra(INTENT_EXTRA_RIDE_ID, EnumValue(rideIndex)); windowManager->BroadcastIntent(intent); return window_find_by_class(WC_RIDE_CONSTRUCTION); } @@ -239,7 +239,7 @@ void ride_clear_for_construction(Ride* ride) ride->RemoveVehicles(); ride_clear_blocked_tiles(ride); - auto w = window_find_by_number(WC_RIDE, static_cast(ride->id)); + auto w = window_find_by_number(WC_RIDE, EnumValue(ride->id)); if (w != nullptr) window_event_resize_call(w); } diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 19b7b1b03d..2f338b1be8 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -159,7 +159,7 @@ static void ride_ratings_update_state_0(RideRatingUpdateState& state) { ride_id_t currentRide = state.CurrentRide; - currentRide = static_cast(static_cast(currentRide) + 1); + currentRide = static_cast(EnumValue(currentRide) + 1); if (currentRide >= static_cast(MAX_RIDES)) { currentRide = {}; @@ -285,7 +285,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, static_cast(state.CurrentRide)); + window_invalidate_by_number(WC_RIDE, EnumValue(state.CurrentRide)); state.State = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; } @@ -753,7 +753,7 @@ static void ride_ratings_calculate(RideRatingUpdateState& state, Ride* ride) // Create event args object auto obj = DukObject(ctx); - obj.Set("rideId", static_cast(ride->id)); + obj.Set("rideId", EnumValue(ride->id)); obj.Set("excitement", originalExcitement); obj.Set("intensity", originalIntensity); obj.Set("nausea", originalNausea); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7b29615007..a13689a586 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1600,7 +1600,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, static_cast(ride)); + window_invalidate_by_number(WC_RIDE, EnumValue(ride)); return; } @@ -3114,7 +3114,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, static_cast(ride.id)); + window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); } void Vehicle::UpdateTestFinish() @@ -3164,7 +3164,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, static_cast(ride.id)); + window_invalidate_by_number(WC_RIDE, EnumValue(ride.id)); } void Vehicle::TestReset() @@ -3570,7 +3570,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, static_cast(ride), ft); + News::AddItemToQueue(News::ItemType::Ride, STR_NEWS_VEHICLE_HAS_STALLED, EnumValue(ride), ft); } } @@ -5305,8 +5305,8 @@ 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, - static_cast(ride->id), ft); + News::ItemType::Ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, EnumValue(ride->id), + ft); } if (gParkRatingCasualtyPenalty < 500) diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 2f363306b6..3f5cf95324 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -893,7 +893,7 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std auto& rideCreateResult = static_cast(*result.get()); if (rideCreateResult.rideIndex != RIDE_ID_NULL) { - obj.Set("ride", static_cast(rideCreateResult.rideIndex)); + obj.Set("ride", EnumValue(rideCreateResult.rideIndex)); } } else if (action.GetType() == GameCommand::HireNewStaffMember) From e5eb8f84cf69ba273838c631d09a43842ab6a037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 9 Sep 2021 00:06:34 +0300 Subject: [PATCH 22/22] Apply review suggestions --- src/openrct2-ui/windows/RideConstruction.cpp | 6 +++--- src/openrct2-ui/windows/TrackDesignPlace.cpp | 8 +++----- src/openrct2/peep/Guest.cpp | 4 ++-- src/openrct2/peep/Peep.h | 2 +- src/openrct2/rct1/S4Importer.cpp | 6 +++--- src/openrct2/ride/TrackDesign.cpp | 9 ++++----- src/openrct2/ride/TrackDesign.h | 2 ++ 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 8eb5a7dc55..24fdf0f985 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -495,9 +495,9 @@ static int32_t ride_get_alternative_type(Ride* ride) } /* move to ride.c */ -static void close_ride_window_for_construction(rct_windownumber number) +static void close_ride_window_for_construction(ride_id_t rideId) { - rct_window* w = window_find_by_number(WC_RIDE, number); + rct_window* w = window_find_by_number(WC_RIDE, EnumValue(rideId)); if (w != nullptr && w->page == 1) window_close(w); } @@ -509,7 +509,7 @@ static void close_ride_window_for_construction(rct_windownumber number) rct_window* window_ride_construction_open() { ride_id_t rideIndex = _currentRideIndex; - close_ride_window_for_construction(EnumValue(rideIndex)); + close_ride_window_for_construction(rideIndex); auto ride = get_ride(rideIndex); if (ride == nullptr) diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 35ad8b135b..9cc6a33cc7 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -269,8 +269,7 @@ static void window_track_place_toolupdate(rct_window* w, rct_widgetindex widgetI if (mapCoords == _windowTrackPlaceLast) { place_virtual_track( - _trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), - { mapCoords, 0 }); + _trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(PreviewRideId), { mapCoords, 0 }); return; } @@ -310,8 +309,7 @@ static void window_track_place_toolupdate(rct_window* w, rct_widgetindex widgetI widget_invalidate(w, WIDX_PRICE); } - place_virtual_track( - _trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), trackLoc); + place_virtual_track(_trackDesign.get(), PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(PreviewRideId), trackLoc); } /** @@ -474,7 +472,7 @@ static int32_t window_track_place_get_base_z(const CoordsXY& loc) return z + place_virtual_track( - _trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(static_cast(0)), { loc, z }); + _trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(PreviewRideId), { loc, z }); } /** diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 7842dff1e1..747b8670f4 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -6812,9 +6812,9 @@ void Guest::InsertNewThought(PeepThoughtType thought_type, ShopItem shopItem) InsertNewThought(thought_type, static_cast(shopItem)); } -void Guest::InsertNewThought(PeepThoughtType thought_type, ride_id_t ride) +void Guest::InsertNewThought(PeepThoughtType thought_type, ride_id_t rideId) { - InsertNewThought(thought_type, static_cast(ride)); + InsertNewThought(thought_type, static_cast(rideId)); } /** * diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 08b7f6a340..08ca29df35 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -774,7 +774,7 @@ public: void UpdateEasterEggInteractions(); void InsertNewThought(PeepThoughtType thought_type); void InsertNewThought(PeepThoughtType thought_type, ShopItem thought_arguments); - void InsertNewThought(PeepThoughtType thought_type, ride_id_t ride); + void InsertNewThought(PeepThoughtType thought_type, ride_id_t rideId); void InsertNewThought(PeepThoughtType thought_type, uint16_t thought_arguments); static Guest* Generate(const CoordsXYZ& coords); bool UpdateQueuePosition(PeepActionType previous_action); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index fbfd9fa4a8..bd9def7a5c 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2483,12 +2483,12 @@ namespace RCT1 { if (_s4.scenario_slot_index == SC_URBAN_PARK && _isScenario) { - const auto firstRideId = static_cast(0); + const auto merryGoRoundId = static_cast(0); // First, make the queuing peep exit for (auto peep : EntityList()) { - if (peep->State == PeepState::QueuingFront && peep->CurrentRide == firstRideId) + if (peep->State == PeepState::QueuingFront && peep->CurrentRide == merryGoRoundId) { peep->RemoveFromQueue(); peep->SetState(PeepState::Falling); @@ -2497,7 +2497,7 @@ namespace RCT1 } // Now, swap the entrance and exit. - auto ride = get_ride(firstRideId); + auto ride = get_ride(merryGoRoundId); if (ride != nullptr) { auto entranceCoords = ride->stations[0].Exit; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index f419047418..747430bc7c 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -57,6 +57,7 @@ #include "RideData.h" #include "Track.h" #include "TrackData.h" +#include "TrackDesign.h" #include "TrackDesignRepository.h" #include "Vehicle.h" @@ -319,8 +320,7 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride) } } - place_virtual_track( - this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), { 4096, 4096, 0 }); + place_virtual_track(this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(PreviewRideId), { 4096, 4096, 0 }); // Resave global vars for scenery reasons. _trackPreviewOrigin = startPos; @@ -439,8 +439,7 @@ rct_string_id TrackDesign::CreateTrackDesignMaze(const Ride& ride) // Save global vars as they are still used by scenery???? int32_t startZ = _trackPreviewOrigin.z; - place_virtual_track( - this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(static_cast(0)), { 4096, 4096, 0 }); + place_virtual_track(this, PTD_OPERATION_DRAW_OUTLINES, true, GetOrAllocateRide(PreviewRideId), { 4096, 4096, 0 }); _trackPreviewOrigin = { startLoc.x, startLoc.y, startZ }; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT; @@ -1934,7 +1933,7 @@ static bool track_design_place_preview(TrackDesign* td6, money32* cost, Ride** o _currentTrackPieceDirection = 0; int32_t z = place_virtual_track( - td6, PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(static_cast(0)), { mapSize, mapSize, 16 }); + td6, PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(PreviewRideId), { mapSize, mapSize, 16 }); if (_trackDesignPlaceStateHasScenery) { diff --git a/src/openrct2/ride/TrackDesign.h b/src/openrct2/ride/TrackDesign.h index d459527365..e78fa32c68 100644 --- a/src/openrct2/ride/TrackDesign.h +++ b/src/openrct2/ride/TrackDesign.h @@ -191,6 +191,8 @@ enum MAZE_ELEMENT_TYPE_EXIT = (1 << 7) }; +static constexpr ride_id_t PreviewRideId = static_cast(0); + extern bool gTrackDesignSceneryToggle; extern bool _trackDesignDrawingPreview;