diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 40186e2f5f..d03500d4b5 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -748,7 +748,7 @@ static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetInd { rct_widget* widget = &w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { int32_t newLeft; newLeft = w->scrolls[scroll_id].h_right; @@ -787,7 +787,7 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd assert(w != nullptr); rct_widget* widget = &w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { int32_t newTop; newTop = w->scrolls[scroll_id].v_bottom; @@ -824,7 +824,7 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) { assert(w != nullptr); - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { w->scrolls[scroll_id].flags |= HSCROLLBAR_LEFT_PRESSED; if (w->scrolls[scroll_id].h_left >= 3) @@ -842,7 +842,7 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd { assert(w != nullptr); rct_widget* widget = &w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { w->scrolls[scroll_id].flags |= HSCROLLBAR_RIGHT_PRESSED; w->scrolls[scroll_id].h_left += 3; @@ -867,7 +867,7 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) { assert(w != nullptr); - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { w->scrolls[scroll_id].flags |= VSCROLLBAR_UP_PRESSED; if (w->scrolls[scroll_id].v_top >= 3) @@ -885,7 +885,7 @@ static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIn { assert(w != nullptr); rct_widget* widget = &w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number)) + if (window_find_by_number(w->classification, w->number) != nullptr) { w->scrolls[scroll_id].flags |= VSCROLLBAR_DOWN_PRESSED; w->scrolls[scroll_id].v_top += 3; @@ -1170,7 +1170,7 @@ void ProcessMouseTool(const ScreenCoordsXY& screenCoords) { rct_window* w = window_find_by_number(gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number); - if (!w) + if (w == nullptr) tool_cancel(); else window_event_tool_update_call(w, gCurrentToolWidget.widget_index, screenCoords); @@ -1200,7 +1200,8 @@ void InputStateWidgetPressed( switch (state) { case MouseState::Released: - if (!w || cursor_w_class != w->classification || cursor_w_number != w->number || widgetIndex != cursor_widgetIndex) + if (w == nullptr || cursor_w_class != w->classification || cursor_w_number != w->number + || widgetIndex != cursor_widgetIndex) break; if (w->disabled_widgets & (1ULL << widgetIndex)) @@ -1237,7 +1238,7 @@ void InputStateWidgetPressed( case MouseState::RightPress: if (_inputState == InputState::DropdownActive) { - if (w) + if (w != nullptr) { auto wClass = w->classification; auto wNumber = w->number; @@ -1317,10 +1318,10 @@ void InputStateWidgetPressed( gTooltipTimeout = 0; gTooltipWidget.widget_index = cursor_widgetIndex; - if (!w) + if (w == nullptr) break; - if (!widget) + if (widget == nullptr) break; { diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 61bdc07687..20e9ef3818 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -175,7 +175,7 @@ public: Close(); break; case WIDX_OPEN_URL: - if (_newVersionInfo) + if (_newVersionInfo != nullptr) { GetContext()->GetUiContext()->OpenURL(_newVersionInfo->url); } diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index c7063690af..c956f3556c 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -595,7 +595,7 @@ void window_guest_overview_mouse_up(rct_window* w, rct_widgetindex widgetIndex) if (result->Error != GameActions::Status::Ok) return; rct_window* wind = window_find_by_number(WC_PEEP, peepnum); - if (wind) + if (wind != nullptr) { tool_set(wind, WC_PEEP__WIDX_PICKUP, Tool::Picker); } @@ -678,7 +678,7 @@ void window_guest_set_page(rct_window* w, int32_t page) tool_cancel(); } int32_t listen = 0; - if (page == WINDOW_GUEST_OVERVIEW && w->page == WINDOW_GUEST_OVERVIEW && w->viewport) + if (page == WINDOW_GUEST_OVERVIEW && w->page == WINDOW_GUEST_OVERVIEW && w->viewport != nullptr) { if (!(w->viewport->flags & VIEWPORT_FLAG_SOUND_ON)) listen = 1; @@ -703,7 +703,7 @@ void window_guest_set_page(rct_window* w, int32_t page) WindowInitScrollWidgets(w); w->Invalidate(); - if (listen && w->viewport) + if (listen && w->viewport != nullptr) w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON; } @@ -986,7 +986,7 @@ void window_guest_overview_paint(rct_window* w, rct_drawpixelinfo* dpi) window_guest_debug_tab_paint(w, dpi); // Draw the viewport no sound sprite - if (w->viewport) + if (w->viewport != nullptr) { window_draw_viewport(dpi, w); rct_viewport* viewport = w->viewport; diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 6299fcc0f1..a328ed206f 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -2011,7 +2011,7 @@ static void window_options_advanced_mouseup(rct_window* w, rct_widgetindex widge case WIDX_PATH_TO_RCT1_BUTTON: { utf8string rct1path = platform_open_directory_browser(language_get_string(STR_PATH_TO_RCT1_BROWSER)); - if (rct1path) + if (rct1path != nullptr) { // Check if this directory actually contains RCT1 if (Csg1datPresentAtLocation(rct1path)) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 1f2d68054b..51d7d275d0 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1485,7 +1485,7 @@ static void window_ride_set_page(rct_window* w, int32_t page) if (page == WINDOW_RIDE_PAGE_VEHICLE) { auto constructionWindow = window_find_by_class(WC_RIDE_CONSTRUCTION); - if (constructionWindow && constructionWindow->number == w->number) + if (constructionWindow != nullptr && constructionWindow->number == w->number) { window_close_by_class(WC_RIDE_CONSTRUCTION); // Closing the construction window sets the tab to the first page, which we don't want here, @@ -1595,7 +1595,7 @@ static void window_ride_init_viewport(rct_window* w) { uint16_t vehId = ride->vehicles[viewSelectionIndex]; rct_ride_entry* ride_entry = ride->GetRideEntry(); - if (ride_entry && ride_entry->tab_vehicle != 0) + if (ride_entry != nullptr && ride_entry->tab_vehicle != 0) { Vehicle* vehicle = GetEntity(vehId); if (vehicle == nullptr) @@ -1654,7 +1654,7 @@ static void window_ride_init_viewport(rct_window* w) w->focus = focus; // rct2: 0x006aec9c only used here so brought it into the function - if (!w->viewport && !ride->overall_view.IsNull()) + if (w->viewport == nullptr && !ride->overall_view.IsNull()) { rct_widget* view_widget = &w->widgets[WIDX_VIEWPORT]; @@ -1667,7 +1667,7 @@ static void window_ride_init_viewport(rct_window* w) w->flags |= WF_NO_SCROLLING; w->Invalidate(); } - if (w->viewport) + if (w->viewport != nullptr) { w->viewport->flags = viewport_flags; w->Invalidate(); @@ -5225,8 +5225,7 @@ static void cancel_scenery_selection() OpenRCT2::Audio::Resume(); rct_window* main_w = window_get_main(); - - if (main_w) + if (main_w != nullptr) { main_w->viewport->flags &= ~(VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE); } @@ -5258,8 +5257,7 @@ static void setup_scenery_selection(rct_window* w) OpenRCT2::Audio::StopAll(); rct_window* w_main = window_get_main(); - - if (w_main) + if (w_main != nullptr) { w_main->viewport->flags |= (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE); } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 8a34c04e84..3044c96961 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2139,7 +2139,7 @@ static std::optional ride_get_place_position_from_screen_position(Scre _trackPlaceShiftZ = _trackPlaceShiftStart.y - screenCoords.y + 4; // Scale delta by zoom to match mouse position. auto* mainWnd = window_get_main(); - if (mainWnd && mainWnd->viewport) + if (mainWnd != nullptr && mainWnd->viewport != nullptr) { _trackPlaceShiftZ = _trackPlaceShiftZ * mainWnd->viewport->zoom; } @@ -2444,6 +2444,7 @@ static void sub_6CBCE2( _tempTrackTileElement.SetBaseZ(baseZ); _tempTrackTileElement.SetClearanceZ(clearanceZ); _tempTrackTileElement.AsTrack()->SetTrackType(trackType); + _tempTrackTileElement.AsTrack()->SetRideType(ride->type); _tempTrackTileElement.AsTrack()->SetSequenceIndex(trackBlock->index); _tempTrackTileElement.AsTrack()->SetHasCableLift(false); _tempTrackTileElement.AsTrack()->SetInverted((liftHillAndInvertedState & CONSTRUCTION_INVERTED_TRACK_SELECTED) != 0); @@ -3566,17 +3567,18 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords) { pathsByDir[i] = map_get_footpath_element({ *mapCoords + CoordsDirectionDelta[i], z }); - if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsSloped() && (pathsByDir[i])->AsPath()->GetSlopeDirection() != i) + if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsSloped() + && (pathsByDir[i])->AsPath()->GetSlopeDirection() != i) { pathsByDir[i] = nullptr; } // Sloped path on the level below - if (!pathsByDir[i]) + if (pathsByDir[i] == nullptr) { pathsByDir[i] = map_get_footpath_element({ *mapCoords + CoordsDirectionDelta[i], z - PATH_HEIGHT_STEP }); - if (pathsByDir[i] + if (pathsByDir[i] != nullptr && (!(pathsByDir[i])->AsPath()->IsSloped() || (pathsByDir[i])->AsPath()->GetSlopeDirection() != direction_reverse(i))) { @@ -3584,12 +3586,12 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords) } } - if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsQueue()) + if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsQueue()) { pathsByDir[i] = nullptr; } - if (pathsByDir[i] && i == _currentTrackPieceDirection) + if (pathsByDir[i] != nullptr && i == _currentTrackPieceDirection) { keepOrientation = true; break; @@ -3600,7 +3602,7 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords) { for (int8_t i = 0; i < 4; i++) { - if (pathsByDir[i]) + if (pathsByDir[i] != nullptr) { _currentTrackPieceDirection = i; diff --git a/src/openrct2-ui/windows/SavePrompt.cpp b/src/openrct2-ui/windows/SavePrompt.cpp index 476e1f647f..4c36ac67e6 100644 --- a/src/openrct2-ui/windows/SavePrompt.cpp +++ b/src/openrct2-ui/windows/SavePrompt.cpp @@ -121,7 +121,7 @@ rct_window* window_save_prompt_open() // Check if window is already open window = window_bring_to_front_by_class(WC_SAVE_PROMPT); - if (window) + if (window != nullptr) { window_close(window); } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 89da4d7b59..e5eb4fe1d0 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -357,7 +357,7 @@ void window_staff_set_page(rct_window* w, int32_t page) } int32_t listen = 0; - if (page == WINDOW_STAFF_OVERVIEW && w->page == WINDOW_STAFF_OVERVIEW && w->viewport) + if (page == WINDOW_STAFF_OVERVIEW && w->page == WINDOW_STAFF_OVERVIEW && w->viewport != nullptr) { if (!(w->viewport->flags & VIEWPORT_FLAG_SOUND_ON)) listen = 1; @@ -383,7 +383,7 @@ void window_staff_set_page(rct_window* w, int32_t page) WindowInitScrollWidgets(w); w->Invalidate(); - if (listen && w->viewport) + if (listen && w->viewport != nullptr) w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON; } @@ -419,7 +419,7 @@ void window_staff_overview_mouseup(rct_window* w, rct_widgetindex widgetIndex) if (result->Error != GameActions::Status::Ok) return; rct_window* wind = window_find_by_number(WC_PEEP, peepnum); - if (wind) + if (wind != nullptr) { tool_set(wind, WC_STAFF__WIDX_PICKUP, Tool::Picker); } @@ -482,8 +482,7 @@ void window_staff_overview_resize(rct_window* w) } rct_viewport* viewport = w->viewport; - - if (viewport) + if (viewport != nullptr) { int32_t new_width = w->width - 30; int32_t new_height = w->height - 62; @@ -947,7 +946,7 @@ void window_staff_overview_paint(rct_window* w, rct_drawpixelinfo* dpi) window_staff_stats_tab_paint(w, dpi); // Draw the viewport no sound sprite - if (w->viewport) + if (w->viewport != nullptr) { window_draw_viewport(dpi, w); rct_viewport* viewport = w->viewport; @@ -1354,7 +1353,7 @@ void window_staff_viewport_init(rct_window* w) uint16_t viewport_flags; - if (w->viewport) + if (w->viewport != nullptr) { if (focus == w->focus) return; @@ -1375,7 +1374,7 @@ void window_staff_viewport_init(rct_window* w) if (peep->State != PeepState::Picked) { - if (!(w->viewport)) + if (w->viewport == nullptr) { rct_widget* view_widget = &w->widgets[WIDX_VIEWPORT]; @@ -1389,7 +1388,7 @@ void window_staff_viewport_init(rct_window* w) } } - if (w->viewport) + if (w->viewport != nullptr) w->viewport->flags = viewport_flags; w->Invalidate(); } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 9801988a35..c6209f547e 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1912,28 +1912,31 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) case TILE_ELEMENT_TYPE_TRACK: { - // Details - // Ride auto trackElement = tileElement->AsTrack(); ride_id_t rideId = trackElement->GetRideIndex(); auto ride = get_ride(rideId); - if (ride != nullptr) - { - auto ft = Formatter(); - ft.Add(ride->GetRideTypeDescriptor().Naming.Name); - DrawTextBasic(dpi, screenCoords, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE }); - } + + // Ride ID auto ft = Formatter(); - ft.Add(trackElement->GetRideIndex()); - DrawTextBasic( - dpi, screenCoords + ScreenCoordsXY{ 0, 11 }, STR_TILE_INSPECTOR_TRACK_RIDE_ID, ft, { COLOUR_WHITE }); + ft.Add(rideId); + DrawTextBasic(dpi, screenCoords, STR_TILE_INSPECTOR_TRACK_RIDE_ID, ft, { COLOUR_WHITE }); + + // Ride name if (ride != nullptr) { ft = Formatter(); ride->FormatNameTo(ft); DrawTextBasic( - dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_TRACK_RIDE_NAME, ft, { COLOUR_WHITE }); + dpi, screenCoords + ScreenCoordsXY{ 0, 11 }, STR_TILE_INSPECTOR_TRACK_RIDE_NAME, ft, { COLOUR_WHITE }); } + + // Ride type. Individual pieces may be of a different ride type from the ride it belongs to. + const auto& rtd = GetRideTypeDescriptor(trackElement->GetRideType()); + ft = Formatter(); + ft.Add(rtd.Naming.Name); + DrawTextBasic( + dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_TRACK_RIDE_TYPE, ft, { COLOUR_WHITE }); + // Track ft = Formatter(); ft.Add(trackElement->GetTrackType()); diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index cd4272695e..9ba4c896c3 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1215,7 +1215,7 @@ static void sub_6E1F34_update_screen_coords_and_buttons_pressed(bool canRaiseIte gSceneryShiftPressZOffset = (gSceneryShiftPressY - screenPos.y + 4); // Scale delta by zoom to match mouse position. auto* mainWnd = window_get_main(); - if (mainWnd && mainWnd->viewport) + if (mainWnd != nullptr && mainWnd->viewport != nullptr) { gSceneryShiftPressZOffset = gSceneryShiftPressZOffset * mainWnd->viewport->zoom; } @@ -3061,7 +3061,7 @@ static money64 selection_lower_land(uint8_t flags) static void window_top_toolbar_land_tool_drag(const ScreenCoordsXY& screenPos) { rct_window* window = window_find_from_point(screenPos); - if (!window) + if (window == nullptr) return; rct_widgetindex widget_index = window_find_widget_from_point(window, screenPos); if (widget_index == -1) @@ -3070,7 +3070,7 @@ static void window_top_toolbar_land_tool_drag(const ScreenCoordsXY& screenPos) if (widget->type != WindowWidgetType::Viewport) return; rct_viewport* viewport = window->viewport; - if (!viewport) + if (viewport == nullptr) return; int16_t tile_height = -16 / viewport->zoom; @@ -3113,7 +3113,7 @@ static void window_top_toolbar_water_tool_drag(const ScreenCoordsXY& screenPos) if (widget->type != WindowWidgetType::Viewport) return; rct_viewport* viewport = window->viewport; - if (!viewport) + if (viewport == nullptr) return; int16_t dx = -16 / viewport->zoom; @@ -3558,7 +3558,7 @@ static void top_toolbar_init_network_menu(rct_window* w, rct_widget* widget) static void top_toolbar_debug_menu_dropdown(int16_t dropdownIndex) { rct_window* w = window_get_main(); - if (w) + if (w != nullptr) { switch (dropdownIndex) { @@ -3585,7 +3585,7 @@ static void top_toolbar_debug_menu_dropdown(int16_t dropdownIndex) static void top_toolbar_network_menu_dropdown(int16_t dropdownIndex) { rct_window* w = window_get_main(); - if (w) + if (w != nullptr) { switch (dropdownIndex) { @@ -3681,7 +3681,7 @@ static void top_toolbar_init_view_menu(rct_window* w, rct_widget* widget) static void top_toolbar_view_menu_dropdown(int16_t dropdownIndex) { rct_window* w = window_get_main(); - if (w) + if (w != nullptr) { switch (dropdownIndex) { diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 513c7300ea..75459838e3 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -408,12 +408,12 @@ namespace Editor switch (gEditorStep) { case EditorStep::ObjectSelection: - if (window_find_by_class(WC_EDITOR_OBJECT_SELECTION)) + if (window_find_by_class(WC_EDITOR_OBJECT_SELECTION) != nullptr) { return; } - if (window_find_by_class(WC_INSTALL_TRACK)) + if (window_find_by_class(WC_INSTALL_TRACK) != nullptr) { return; } @@ -426,7 +426,7 @@ namespace Editor context_open_window(WC_EDITOR_OBJECT_SELECTION); break; case EditorStep::InventionsListSetUp: - if (window_find_by_class(WC_EDITOR_INVENTION_LIST)) + if (window_find_by_class(WC_EDITOR_INVENTION_LIST) != nullptr) { return; } @@ -434,7 +434,7 @@ namespace Editor context_open_window(WC_EDITOR_INVENTION_LIST); break; case EditorStep::OptionsSelection: - if (window_find_by_class(WC_EDITOR_SCENARIO_OPTIONS)) + if (window_find_by_class(WC_EDITOR_SCENARIO_OPTIONS) != nullptr) { return; } @@ -442,7 +442,7 @@ namespace Editor context_open_window(WC_EDITOR_SCENARIO_OPTIONS); break; case EditorStep::ObjectiveSelection: - if (window_find_by_class(WC_EDITOR_OBJECTIVE_OPTIONS)) + if (window_find_by_class(WC_EDITOR_OBJECTIVE_OPTIONS) != nullptr) { return; } diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index c45ca1b4c4..a3c890b025 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -744,7 +744,7 @@ struct GameStateSnapshots final : public IGameStateSnapshots auto outputBuffer = GetCompareDataText(cmpData); FILE* fp = fopen(fileName.c_str(), "wt"); - if (!fp) + if (fp == nullptr) return false; fputs(outputBuffer.c_str(), fp); diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 436a146fb0..11ce4acfa5 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -321,7 +321,7 @@ namespace OpenRCT2 const std::string& outFile = _currentRecording->filePath; FILE* fp = fopen(outFile.c_str(), "wb"); - if (fp) + if (fp != nullptr) { const auto& fileStream = fileSerialiser.GetStream(); fwrite(fileStream.GetData(), 1, fileStream.GetLength(), fp); @@ -548,7 +548,7 @@ namespace OpenRCT2 bool ReadReplayFromFile(const std::string& file, MemoryStream& stream) { FILE* fp = fopen(file.c_str(), "rb"); - if (!fp) + if (fp == nullptr) return false; char buffer[128]; diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index bc63e30825..0856d018a3 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -502,7 +502,7 @@ namespace GameActions bool commandExecutes = (flags & GAME_COMMAND_FLAG_GHOST) == 0 && (flags & GAME_COMMAND_FLAG_NO_SPEND) == 0; bool recordAction = false; - if (replayManager) + if (replayManager != nullptr) { if (replayManager->IsRecording() && commandExecutes) recordAction = true; diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index c62e469524..a2e01c3642 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -168,6 +168,7 @@ GameActions::Result::Ptr MazePlaceTrackAction::Execute() const trackElement->SetClearanceZ(clearanceHeight); trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); trackElement->SetRideIndex(_rideIndex); trackElement->SetMazeEntry(_mazeEntry); trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index 19e38f95d0..3605a425d7 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -183,6 +183,7 @@ GameActions::Result::Ptr MazeSetTrackAction::Execute() const trackElement->SetClearanceZ(_loc.z + MAZE_CLEARANCE_HEIGHT); trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); trackElement->SetRideIndex(_rideIndex); trackElement->SetMazeEntry(0xFFFF); trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); diff --git a/src/openrct2/actions/PeepPickupAction.cpp b/src/openrct2/actions/PeepPickupAction.cpp index db89689ddd..ef29ca21e8 100644 --- a/src/openrct2/actions/PeepPickupAction.cpp +++ b/src/openrct2/actions/PeepPickupAction.cpp @@ -67,7 +67,7 @@ GameActions::Result::Ptr PeepPickupAction::Query() const return MakeResult(GameActions::Status::Disallowed, STR_ERR_CANT_PLACE_PERSON_HERE); } Peep* existing = network_get_pickup_peep(_owner); - if (existing) + if (existing != nullptr) { // already picking up a peep PeepPickupAction existingPickupAction{ @@ -122,7 +122,7 @@ GameActions::Result::Ptr PeepPickupAction::Execute() const res->Position = { peep->x, peep->y, peep->z }; Peep* existing = network_get_pickup_peep(_owner); - if (existing) + if (existing != nullptr) { // already picking up a peep PeepPickupAction existingPickupAction{ @@ -151,7 +151,7 @@ GameActions::Result::Ptr PeepPickupAction::Execute() const res->Position = { peep->x, peep->y, peep->z }; Peep* const pickedUpPeep = network_get_pickup_peep(_owner); - if (pickedUpPeep) + if (pickedUpPeep != nullptr) { pickedUpPeep->PickupAbort(_loc.x); } diff --git a/src/openrct2/actions/SignSetStyleAction.cpp b/src/openrct2/actions/SignSetStyleAction.cpp index e38319c71d..60599db6aa 100644 --- a/src/openrct2/actions/SignSetStyleAction.cpp +++ b/src/openrct2/actions/SignSetStyleAction.cpp @@ -64,7 +64,7 @@ GameActions::Result::Ptr SignSetStyleAction::Query() const { WallElement* wallElement = banner_get_scrolling_wall_tile_element(_bannerIndex); - if (!wallElement) + if (wallElement == nullptr) { log_warning("Invalid game command for setting sign style, banner id '%d' not found", _bannerIndex); return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index f0fc1898cb..39b508c804 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -561,6 +561,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const trackElement->SetSequenceIndex(trackBlock->index); trackElement->SetRideIndex(_rideIndex); trackElement->SetTrackType(_trackType); + trackElement->SetRideType(ride->type); trackElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); switch (_trackType) diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index 454a81dd1f..6fb3c4f673 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -207,7 +207,7 @@ namespace OpenRCT2::Audio params.pan = 0; auto element = map_get_surface_element_at(location); - if (element && (element->GetBaseZ()) - 5 > location.z) + if (element != nullptr && (element->GetBaseZ()) - 5 > location.z) { volumeDown = 10; } diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 837742d48b..0b8f31751b 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -331,7 +331,7 @@ void lightfx_prepare_light_list() int32_t minDist = 0; int32_t baseHeight = (-999) * COORDS_Z_STEP; - if (interactionType != ViewportInteractionItem::Entity && tileElement) + if (interactionType != ViewportInteractionItem::Entity && tileElement != nullptr) { baseHeight = tileElement->GetBaseZ(); } @@ -440,7 +440,7 @@ void lightfx_swap_buffers() void lightfx_update_viewport_settings() { rct_window* mainWindow = window_get_main(); - if (mainWindow) + if (mainWindow != nullptr) { rct_viewport* viewport = window_get_viewport(mainWindow); _current_view_x_back = viewport->viewPos.x; diff --git a/src/openrct2/drawing/TTFSDLPort.cpp b/src/openrct2/drawing/TTFSDLPort.cpp index 030bb3aeef..0df6e8697c 100644 --- a/src/openrct2/drawing/TTFSDLPort.cpp +++ b/src/openrct2/drawing/TTFSDLPort.cpp @@ -550,12 +550,12 @@ static void Flush_Glyph(c_glyph* glyph) { glyph->stored = 0; glyph->index = 0; - if (glyph->bitmap.buffer) + if (glyph->bitmap.buffer != nullptr) { free(glyph->bitmap.buffer); glyph->bitmap.buffer = 0; } - if (glyph->pixmap.buffer) + if (glyph->pixmap.buffer != nullptr) { free(glyph->pixmap.buffer); glyph->pixmap.buffer = 0; @@ -754,7 +754,7 @@ static FT_Error Load_Glyph(TTF_Font* font, uint16_t ch, c_glyph* cached, int wan if (dst->rows != 0) { dst->buffer = static_cast(malloc(dst->pitch * dst->rows)); - if (!dst->buffer) + if (dst->buffer == nullptr) { return FT_Err_Out_Of_Memory; } @@ -1236,12 +1236,12 @@ int TTF_SizeUTF8(TTF_Font* font, const char* text, int* w, int* h) } /* Fill the bounds rectangle */ - if (w) + if (w != nullptr) { /* Add outline extra width */ *w = (maxx - minx) + outline_delta; } - if (h) + if (h != nullptr) { /* Some fonts descend below font height (FletcherGothicFLF) */ /* Add outline extra height */ diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 28cab048bd..a3d53b70d7 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -559,7 +559,7 @@ void viewport_update_position(rct_window* window) window_event_resize_call(window); rct_viewport* viewport = window->viewport; - if (!viewport) + if (viewport == nullptr) return; if (window->viewport_smart_follow_sprite != SPRITE_INDEX_NULL) @@ -656,7 +656,7 @@ void viewport_update_position(rct_window* window) void viewport_update_sprite_follow(rct_window* window) { - if (window->viewport_target_sprite != SPRITE_INDEX_NULL && window->viewport) + if (window->viewport_target_sprite != SPRITE_INDEX_NULL && window->viewport != nullptr) { auto* sprite = GetEntity(window->viewport_target_sprite); if (sprite == nullptr) diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 42bf213b8a..5bd3668607 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -806,7 +806,7 @@ void window_scroll_to_location(rct_window* w, const CoordsXYZ& coords) { assert(w != nullptr); window_unfollow_sprite(w); - if (w->viewport) + if (w->viewport != nullptr) { int16_t height = tile_element_height(coords); if (coords.z < height - 16) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 364bcbcff9..99bec0e452 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -701,7 +701,7 @@ const char* NetworkBase::FormatChat(NetworkPlayer* fromplayer, const char* text) static std::string formatted; formatted.clear(); formatted += "{OUTLINE}"; - if (fromplayer) + if (fromplayer != nullptr) { formatted += "{BABYBLUE}"; formatted += fromplayer->Name; @@ -935,7 +935,7 @@ uint8_t NetworkBase::GetDefaultGroup() void NetworkBase::SetDefaultGroup(uint8_t id) { - if (GetGroupByID(id)) + if (GetGroupByID(id) != nullptr) { default_group = id; } @@ -1358,7 +1358,7 @@ NetworkStats_t NetworkBase::GetStats() const void NetworkBase::Server_Send_AUTH(NetworkConnection& connection) { uint8_t new_playerid = 0; - if (connection.Player) + if (connection.Player != nullptr) { new_playerid = connection.Player->Id; } @@ -1378,7 +1378,7 @@ void NetworkBase::Server_Send_AUTH(NetworkConnection& connection) void NetworkBase::Server_Send_MAP(NetworkConnection* connection) { std::vector objects; - if (connection) + if (connection != nullptr) { objects = connection->RequestedObjects; } @@ -1394,7 +1394,7 @@ void NetworkBase::Server_Send_MAP(NetworkConnection* connection) auto header = save_for_network(objects); if (header.empty()) { - if (connection) + if (connection != nullptr) { connection->SetLastDisconnectReason(STR_MULTIPLAYER_CONNECTION_CLOSED); connection->Disconnect(); @@ -1408,7 +1408,7 @@ void NetworkBase::Server_Send_MAP(NetworkConnection* connection) NetworkPacket packet(NetworkCommand::Map); packet << static_cast(header.size()) << static_cast(i); packet.Write(&header[i], datasize); - if (connection) + if (connection != nullptr) { connection->QueuePacket(std::move(packet)); } @@ -1847,7 +1847,7 @@ void NetworkBase::ProcessPlayerList() { // Add new player. player = AddPlayer("", ""); - if (player) + if (player != nullptr) { *player = pendingPlayer; if (player->Flags & NETWORK_PLAYER_FLAG_ISSERVER) @@ -1968,7 +1968,7 @@ void NetworkBase::ServerClientDisconnected(std::unique_ptr& c connection_player->Name.c_str(), connection->GetLastDisconnectReason(), }; - if (has_disconnected_args[1]) + if (has_disconnected_args[1] != nullptr) { format_string(text, 256, STR_MULTIPLAYER_PLAYER_HAS_DISCONNECTED_WITH_REASON, has_disconnected_args); } @@ -1979,7 +1979,7 @@ void NetworkBase::ServerClientDisconnected(std::unique_ptr& c chat_history_add(text); Peep* pickup_peep = network_get_pickup_peep(connection_player->Id); - if (pickup_peep) + if (pickup_peep != nullptr) { PeepPickupAction pickupAction{ PeepPickupType::Cancel, pickup_peep->sprite_index, @@ -2184,7 +2184,7 @@ void NetworkBase::Server_Handle_REQUEST_GAMESTATE(NetworkConnection& connection, IGameStateSnapshots* snapshots = GetContext().GetGameStateSnapshots(); const GameStateSnapshot_t* snapshot = snapshots->GetLinkedSnapshot(tick); - if (snapshot) + if (snapshot != nullptr) { MemoryStream snapshotMemory; DataSerialiser ds(true, snapshotMemory); @@ -2448,7 +2448,7 @@ void NetworkBase::Client_Handle_GAMESTATE(NetworkConnection& connection, Network snapshots->SerialiseSnapshot(serverSnapshot, ds); const GameStateSnapshot_t* desyncSnapshot = snapshots->GetLinkedSnapshot(tick); - if (desyncSnapshot) + if (desyncSnapshot != nullptr) { GameStateCompareData_t cmpData = snapshots->Compare(serverSnapshot, *desyncSnapshot); @@ -2490,7 +2490,7 @@ void NetworkBase::Server_Handle_MAPREQUEST(NetworkConnection& connection, Networ connection.SetLastDisconnectReason(STR_MULTIPLAYER_CLIENT_INVALID_REQUEST); connection.Disconnect(); std::string playerName = "(unknown)"; - if (connection.Player) + if (connection.Player != nullptr) { playerName = connection.Player->Name; } @@ -2837,10 +2837,10 @@ void NetworkBase::Server_Handle_CHAT(NetworkConnection& connection, NetworkPacke if (szText.empty()) return; - if (connection.Player) + if (connection.Player != nullptr) { NetworkGroup* group = GetGroupByID(connection.Player->Group); - if (!group || !group->CanPerformCommand(GameCommand::Chat)) + if (group == nullptr || !group->CanPerformCommand(GameCommand::Chat)) { return; } @@ -3041,7 +3041,7 @@ void NetworkBase::Server_Handle_PING(NetworkConnection& connection, [[maybe_unus { ping = 0; } - if (connection.Player) + if (connection.Player != nullptr) { connection.Player->Ping = ping; window_invalidate_by_number(WC_PLAYER, connection.Player->Id); @@ -3058,7 +3058,7 @@ void NetworkBase::Client_Handle_PINGLIST([[maybe_unused]] NetworkConnection& con uint16_t ping; packet >> id >> ping; NetworkPlayer* player = GetPlayerByID(id); - if (player) + if (player != nullptr) { player->Ping = ping; } @@ -3467,7 +3467,7 @@ GameActions::Result::Ptr network_set_player_group( return std::make_unique(GameActions::Status::InvalidParameters, STR_CANT_DO_THIS); } - if (!network.GetGroupByID(groupId)) + if (network.GetGroupByID(groupId) == nullptr) { return std::make_unique(GameActions::Status::InvalidParameters, STR_CANT_DO_THIS); } @@ -3478,7 +3478,7 @@ GameActions::Result::Ptr network_set_player_group( GameActions::Status::InvalidParameters, STR_CANT_CHANGE_GROUP_THAT_THE_HOST_BELONGS_TO); } - if (groupId == 0 && fromgroup && fromgroup->Id != 0) + if (groupId == 0 && fromgroup != nullptr && fromgroup->Id != 0) { return std::make_unique(GameActions::Status::InvalidParameters, STR_CANT_SET_TO_THIS_GROUP); } @@ -3658,7 +3658,7 @@ GameActions::Result::Ptr network_kick_player(NetworkPlayerId_t playerId, bool is return std::make_unique(GameActions::Status::Unknown, STR_NONE); } - if (player && player->Flags & NETWORK_PLAYER_FLAG_ISSERVER) + if (player->Flags & NETWORK_PLAYER_FLAG_ISSERVER) { return std::make_unique(GameActions::Status::Disallowed, STR_CANT_KICK_THE_HOST); } @@ -3725,7 +3725,7 @@ void network_set_pickup_peep(uint8_t playerid, Peep* peep) else { NetworkPlayer* player = network.GetPlayerByID(playerid); - if (player) + if (player != nullptr) { player->PickupPeep = peep; } @@ -3741,7 +3741,7 @@ Peep* network_get_pickup_peep(uint8_t playerid) } NetworkPlayer* player = network.GetPlayerByID(playerid); - if (player) + if (player != nullptr) { return player->PickupPeep; } @@ -3758,7 +3758,7 @@ void network_set_pickup_peep_old_x(uint8_t playerid, int32_t x) else { NetworkPlayer* player = network.GetPlayerByID(playerid); - if (player) + if (player != nullptr) { player->PickupPeepOldX = x; } @@ -3774,7 +3774,7 @@ int32_t network_get_pickup_peep_old_x(uint8_t playerid) } NetworkPlayer* player = network.GetPlayerByID(playerid); - if (player) + if (player != nullptr) { return player->PickupPeepOldX; } @@ -3785,7 +3785,7 @@ int32_t network_get_current_player_group_index() { auto& network = OpenRCT2::GetContext()->GetNetwork(); NetworkPlayer* player = network.GetPlayerByID(network.GetPlayerID()); - if (player) + if (player != nullptr) { return network_get_group_index(player->Group); } diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 862a5a8b10..aab007274d 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -525,7 +525,7 @@ void PaintDrawStructs(paint_session* session) { paint_struct* ps = &session->PaintHead; - for (ps = ps->next_quadrant_ps; ps;) + for (ps = ps->next_quadrant_ps; ps != nullptr;) { PaintDrawStruct(session, ps); @@ -541,7 +541,7 @@ void PaintDrawStructs(paint_session* session) static void PaintAttachedPS(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t viewFlags) { attached_paint_struct* attached_ps = ps->attached_ps; - for (; attached_ps; attached_ps = attached_ps->next) + for (; attached_ps != nullptr; attached_ps = attached_ps->next) { auto screenCoords = ScreenCoordsXY{ attached_ps->x + ps->x, attached_ps->y + ps->y }; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 1ea67cce27..42627faf8d 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -1061,7 +1061,7 @@ void path_paint_box_support( // If we are on the same tile as a straight track, add the offset 2 so we // can clip above gravel part of the track sprite - if (session->TrackElementOnSameHeight) + if (session->TrackElementOnSameHeight != nullptr) { if (session->TrackElementOnSameHeight->AsTrack()->GetTrackType() == TrackElemType::Flat) { @@ -1200,7 +1200,7 @@ void path_paint_pole_support( // If we are on the same tile as a straight track, add the offset 2 so we // can clip above gravel part of the track sprite - if (session->TrackElementOnSameHeight) + if (session->TrackElementOnSameHeight != nullptr) { if (session->TrackElementOnSameHeight->AsTrack()->GetTrackType() == TrackElemType::Flat) { diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 996c4e0741..2254b73933 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -1407,7 +1407,7 @@ void Guest::CheckCantFindRide() GuestHeadingToRideId = RIDE_ID_NULL; rct_window* w = window_find_by_number(WC_PEEP, sprite_index); - if (w) + if (w != nullptr) { window_event_invalidate_call(w); } diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 2f27e93843..8eb9dbced2 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -88,7 +88,7 @@ static TileElement* get_banner_on_path(TileElement* path_element) if (bannerElement->IsLastForTile()) return nullptr; - } while (bannerElement++); + } while (bannerElement++ != nullptr); return nullptr; } diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 71c27737e2..1a5ff47bb1 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -573,12 +573,12 @@ std::unique_ptr Peep::Place(const TileCoordsXYZ& location, { auto* pathElement = map_get_path_element_at(location); TileElement* tileElement = reinterpret_cast(pathElement); - if (!pathElement) + if (pathElement == nullptr) { tileElement = reinterpret_cast(map_get_surface_element_at(location.ToCoordsXYZ())); } - if (!tileElement) + if (tileElement == nullptr) return std::make_unique(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE); // Set the coordinate of destination to be exactly @@ -2055,7 +2055,7 @@ static void peep_interact_with_path(Peep* peep, const CoordsXYE& coords) auto* guest = peep->As(); if (map_is_location_owned({ coords, z })) { - if (guest && guest->OutsideOfPark) + if (guest != nullptr && guest->OutsideOfPark) { peep_return_to_centre_of_tile(guest); return; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 958f376cb8..c422968818 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1670,6 +1670,7 @@ namespace RCT1 auto rideType = (ride != nullptr) ? ride->type : RIDE_TYPE_NULL; dst2->SetTrackType(RCT1TrackTypeToOpenRCT2(src2->GetTrackType(), rideType)); + dst2->SetRideType(rideType); dst2->SetSequenceIndex(src2->GetSequenceIndex()); dst2->SetRideIndex(RCT12RideIdToOpenRCT2RideId(src2->GetRideIndex())); dst2->SetColourScheme(src2->GetColourScheme()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 9f224a8603..1b846505e8 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1174,7 +1174,8 @@ public: auto rideType = _s6.rides[src2->GetRideIndex()].type; track_type_t trackType = static_cast(src2->GetTrackType()); - dst2->SetTrackType(RCT2TrackTypeToOpenRCT2(trackType, _s6.rides[src2->GetRideIndex()].type)); + dst2->SetTrackType(RCT2TrackTypeToOpenRCT2(trackType, rideType)); + dst2->SetRideType(rideType); dst2->SetSequenceIndex(src2->GetSequenceIndex()); dst2->SetRideIndex(RCT12RideIdToOpenRCT2RideId(src2->GetRideIndex())); dst2->SetColourScheme(src2->GetColourScheme()); diff --git a/src/openrct2/ride/RideTypes.h b/src/openrct2/ride/RideTypes.h index 7d8b11b344..b9747b58c8 100644 --- a/src/openrct2/ride/RideTypes.h +++ b/src/openrct2/ride/RideTypes.h @@ -20,6 +20,8 @@ struct Ride; constexpr const ride_id_t RIDE_ID_NULL = static_cast(std::numeric_limits>::max()); +using ride_type_t = uint16_t; + /** * Couples a ride type and subtype together. */ diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index c7996973a1..33406d53bb 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -730,6 +730,16 @@ void TrackElement::SetTrackType(uint16_t newType) TrackType = newType; } +ride_type_t TrackElement::GetRideType() const +{ + return RideType; +} + +void TrackElement::SetRideType(const ride_type_t rideType) +{ + RideType = rideType; +} + uint8_t TrackElement::GetSequenceIndex() const { return Sequence; diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index 39645719be..362d89d0d2 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -2277,7 +2277,9 @@ void PaintTrack(paint_session* session, Direction direction, int32_t height, con { return; } - TRACK_PAINT_FUNCTION_GETTER paintFunctionGetter = ride->GetRideTypeDescriptor().TrackPaintFunction; + + const auto& rtd = GetRideTypeDescriptor(trackElement.GetRideType()); + TRACK_PAINT_FUNCTION_GETTER paintFunctionGetter = rtd.TrackPaintFunction; if (paintFunctionGetter != nullptr) { TRACK_PAINT_FUNCTION paintFunction = paintFunctionGetter(trackType); diff --git a/src/openrct2/ride/TrainManager.cpp b/src/openrct2/ride/TrainManager.cpp index 52b6e75028..eea7d347ef 100644 --- a/src/openrct2/ride/TrainManager.cpp +++ b/src/openrct2/ride/TrainManager.cpp @@ -22,7 +22,7 @@ namespace TrainManager while (iter != end && Entity == nullptr) { Entity = GetEntity(*iter++); - if (Entity && !Entity->IsHead()) + if (Entity != nullptr && !Entity->IsHead()) { Entity = nullptr; } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 44e8a8cfd7..014527677b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -9802,7 +9802,7 @@ void Vehicle::UpdateCrossings() const frontVehicle->TrackLocation, frontVehicle->GetTrackType(), 0) }; int32_t curZ = frontVehicle->TrackLocation.z; - if (xyElement.element && status != Vehicle::Status::Arriving) + if (xyElement.element != nullptr && status != Vehicle::Status::Arriving) { int16_t autoReserveAhead = 4 + abs(velocity) / 150000; int16_t crossingBonus = 0; @@ -9822,7 +9822,7 @@ void Vehicle::UpdateCrossings() const // Many New Element parks have invisible rides hacked into the path. // Limit path blocking to rides actually supporting level crossings to prevent peeps getting stuck everywhere. - if (pathElement && curRide != nullptr + if (pathElement != nullptr && curRide != nullptr && GetRideTypeDescriptor(curRide->type).HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)) { if (!playedClaxon && !pathElement->IsBlockedByVehicle()) @@ -9873,7 +9873,7 @@ void Vehicle::UpdateCrossings() const map_get_track_element_at_of_type_seq(backVehicle->TrackLocation, backVehicle->GetTrackType(), 0) }; curZ = backVehicle->TrackLocation.z; - if (xyElement.element) + if (xyElement.element != nullptr) { uint8_t freeCount = travellingForwards ? 3 : 1; @@ -9890,7 +9890,7 @@ void Vehicle::UpdateCrossings() const } auto* pathElement = map_get_path_element_at(TileCoordsXYZ(CoordsXYZ{ xyElement, xyElement.element->GetBaseZ() })); - if (pathElement) + if (pathElement != nullptr) { pathElement->SetIsBlockedByVehicle(false); } diff --git a/src/openrct2/ride/transport/MiniatureRailway.cpp b/src/openrct2/ride/transport/MiniatureRailway.cpp index 3acb96aa18..613e90d8d5 100644 --- a/src/openrct2/ride/transport/MiniatureRailway.cpp +++ b/src/openrct2/ride/transport/MiniatureRailway.cpp @@ -558,7 +558,7 @@ static uint32_t miniature_railway_track_to_grooved(uint32_t imageId) static uint32_t miniature_railway_track_to_grooved_indent( uint32_t imageId, const TileElement* path, uint8_t direction, uint8_t rotation) { - if (!path) + if (path == nullptr) { return 0; } @@ -598,7 +598,7 @@ static void paint_miniature_railway_track_flat( bool paintAsGravel = false; bool paintGrooved = false; - if (session->PathElementOnSameHeight) + if (session->PathElementOnSameHeight != nullptr) { paintAsGravel = true; paintGrooved = true; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 6a88ce3922..b60317c71d 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1735,7 +1735,7 @@ void map_extend_boundary_surface() existingTileElement = map_get_surface_element_at(TileCoordsXY{ x, y - 1 }.ToCoordsXY()); newTileElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); - if (existingTileElement && newTileElement) + if (existingTileElement != nullptr && newTileElement != nullptr) { map_extend_boundary_surface_extend_tile(*existingTileElement, *newTileElement); } @@ -1749,7 +1749,7 @@ void map_extend_boundary_surface() existingTileElement = map_get_surface_element_at(TileCoordsXY{ x - 1, y }.ToCoordsXY()); newTileElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); - if (existingTileElement && newTileElement) + if (existingTileElement != nullptr && newTileElement != nullptr) { map_extend_boundary_surface_extend_tile(*existingTileElement, *newTileElement); } diff --git a/src/openrct2/world/MapHelpers.cpp b/src/openrct2/world/MapHelpers.cpp index 0fc73a2221..b8857f6302 100644 --- a/src/openrct2/world/MapHelpers.cpp +++ b/src/openrct2/world/MapHelpers.cpp @@ -17,7 +17,7 @@ static uint8_t getBaseHeightOrZero(int32_t x, int32_t y) { auto surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); - return surfaceElement ? surfaceElement->base_height : 0; + return surfaceElement != nullptr ? surfaceElement->base_height : 0; } /** diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 43fee6930a..e71522fd23 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -375,15 +375,15 @@ private: }; uint8_t Flags2; ride_id_t RideIndex; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad[2]; -#pragma clang diagnostic pop + ride_type_t RideType; public: track_type_t GetTrackType() const; void SetTrackType(track_type_t newEntryIndex); + ride_type_t GetRideType() const; + void SetRideType(const ride_type_t rideType); + uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 43a2f34e05..e4b16617d8 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -149,7 +149,7 @@ namespace OpenRCT2::TileInspector } auto largeScenery = tileElement->AsLargeScenery(); - if (largeScenery) + if (largeScenery != nullptr) { // Only delete the banner entry if there are no other parts of the large scenery to delete if (numLargeScenerySequences(loc, largeScenery) == 1)