From 355019f97f7508b042ee00976c8c057ba7c8ecf1 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Tue, 14 Sep 2021 19:36:58 -0400 Subject: [PATCH 1/7] #15367: Encode RideType in TrackElement --- src/openrct2-ui/windows/RideConstruction.cpp | 1 + src/openrct2/actions/MazePlaceTrackAction.cpp | 1 + src/openrct2/actions/MazeSetTrackAction.cpp | 1 + src/openrct2/actions/TrackPlaceAction.cpp | 1 + src/openrct2/rct1/S4Importer.cpp | 1 + src/openrct2/rct2/S6Importer.cpp | 3 ++- src/openrct2/ride/Track.cpp | 12 ++++++++++++ src/openrct2/ride/TrackPaint.cpp | 4 +++- src/openrct2/world/TileElement.h | 7 ++++++- 9 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 6d252746dc..13ad0e23de 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -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); 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/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/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 6916c69a81..a4a7e1cc1d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1631,6 +1631,7 @@ namespace RCT1 auto rideType = (ride != nullptr) ? ride->type : RIDE_TYPE_NULL; dst2->SetTrackType(RCT1TrackTypeToOpenRCT2(src2->GetTrackType(), rideType)); + dst2->SetRideType(rideType); dst2->SetSequenceIndex(src2->GetSequenceIndex()); dst2->SetRideIndex(RCT12RideIdToOpenRCT2RideId(src2->GetRideIndex())); dst2->SetColourScheme(src2->GetColourScheme()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 5c7c7145a4..de66b3eede 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1198,7 +1198,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/Track.cpp b/src/openrct2/ride/Track.cpp index c7996973a1..cb90d20660 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -244,6 +244,7 @@ bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flag targetTrackType = TrackElemType::MiddleStation; } stationElement->AsTrack()->SetTrackType(targetTrackType); + stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(loc, stationElement); @@ -389,6 +390,7 @@ bool track_remove_station_element(const CoordsXYZD& loc, ride_id_t rideIndex, in } } stationElement->AsTrack()->SetTrackType(targetTrackType); + stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(currentLoc, stationElement); } @@ -730,6 +732,16 @@ void TrackElement::SetTrackType(uint16_t newType) TrackType = newType; } +uint8_t TrackElement::GetRideType() const +{ + return RideType; +} + +void TrackElement::SetRideType(const uint8_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 b2529b4da2..259a6e89d7 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -2276,7 +2276,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/world/TileElement.h b/src/openrct2/world/TileElement.h index 68f289c8ce..ecea23c948 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -380,13 +380,18 @@ private: ride_id_t RideIndex; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad[2]; + // uint8_t pad[2]; + uint8_t RideType; + uint8_t pad; #pragma clang diagnostic pop public: track_type_t GetTrackType() const; void SetTrackType(track_type_t newEntryIndex); + uint8_t GetRideType() const; + void SetRideType(const uint8_t rideType); + uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); From f21b941b462219dc5db93faf170f5d1b81382b9a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 21:02:24 +0200 Subject: [PATCH 2/7] Introduce ride_type_t --- src/openrct2/ride/RideTypes.h | 2 ++ src/openrct2/ride/Track.cpp | 4 ++-- src/openrct2/world/TileElement.h | 11 +++-------- 3 files changed, 7 insertions(+), 10 deletions(-) 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 cb90d20660..b4550ba438 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -732,12 +732,12 @@ void TrackElement::SetTrackType(uint16_t newType) TrackType = newType; } -uint8_t TrackElement::GetRideType() const +ride_type_t TrackElement::GetRideType() const { return RideType; } -void TrackElement::SetRideType(const uint8_t rideType) +void TrackElement::SetRideType(const ride_type_t rideType) { RideType = rideType; } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index ecea23c948..893b3f06b5 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -378,19 +378,14 @@ private: }; uint8_t Flags2; ride_id_t RideIndex; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" - // uint8_t pad[2]; - uint8_t RideType; - uint8_t pad; -#pragma clang diagnostic pop + ride_type_t RideType; public: track_type_t GetTrackType() const; void SetTrackType(track_type_t newEntryIndex); - uint8_t GetRideType() const; - void SetRideType(const uint8_t rideType); + ride_type_t GetRideType() const; + void SetRideType(const ride_type_t rideType); uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); From 1e17304e766b285fae0880f332bd06f1b3e00135 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 21:10:40 +0200 Subject: [PATCH 3/7] Show the appropriate ride type in the TI --- src/openrct2-ui/windows/TileInspector.cpp | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a128f0d6c4..05df9f2b03 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1928,28 +1928,31 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) case TILE_ELEMENT_TYPE_TRACK: { - // Details - // Ride auto trackElement = tileElement->AsTrack(); ride_id_t rideId = trackElement->GetRideIndex(); auto ride = get_ride(rideId); - if (ride != nullptr) - { - auto ft = Formatter(); - ft.Add(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. + 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()); From 11607f525db1c7b9657b9764d413b5c31e552e34 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 19 Sep 2021 23:01:47 +0200 Subject: [PATCH 4/7] const auto& --- src/openrct2-ui/windows/TileInspector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 05df9f2b03..656940b942 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1947,7 +1947,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) } // Ride type. Individual pieces may be of a different ride type from the ride it belongs to. - auto rtd = GetRideTypeDescriptor(trackElement->GetRideType()); + const auto& rtd = GetRideTypeDescriptor(trackElement->GetRideType()); ft = Formatter(); ft.Add(rtd.Naming.Name); DrawTextBasic( From 8fb8b2a4c1dde92fd06ceaec63b0404c206d2bde Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 21 Sep 2021 10:50:38 +0200 Subject: [PATCH 5/7] Do not overwrite ride type when extending station --- src/openrct2/ride/Track.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index b4550ba438..33406d53bb 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -244,7 +244,6 @@ bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flag targetTrackType = TrackElemType::MiddleStation; } stationElement->AsTrack()->SetTrackType(targetTrackType); - stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(loc, stationElement); @@ -390,7 +389,6 @@ bool track_remove_station_element(const CoordsXYZD& loc, ride_id_t rideIndex, in } } stationElement->AsTrack()->SetTrackType(targetTrackType); - stationElement->AsTrack()->SetRideType(ride->type); map_invalidate_element(currentLoc, stationElement); } From 53c22c9b4bae8b8ed907271dbbe3944f9a8d4d7e Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Fri, 24 Sep 2021 20:05:50 +0200 Subject: [PATCH 6/7] Check for nullptr explicitly (#15458) --- src/openrct2/Editor.cpp | 10 ++-- src/openrct2/GameStateSnapshots.cpp | 2 +- src/openrct2/ReplayManager.cpp | 4 +- src/openrct2/actions/GameAction.cpp | 2 +- src/openrct2/actions/PeepPickupAction.cpp | 6 +-- src/openrct2/actions/SignSetStyleAction.cpp | 2 +- src/openrct2/audio/Audio.cpp | 2 +- src/openrct2/drawing/LightFX.cpp | 4 +- src/openrct2/drawing/TTFSDLPort.cpp | 10 ++-- src/openrct2/interface/Viewport.cpp | 4 +- src/openrct2/interface/Window.cpp | 2 +- src/openrct2/network/NetworkBase.cpp | 48 +++++++++---------- src/openrct2/paint/Paint.cpp | 4 +- .../paint/tile_element/Paint.Path.cpp | 4 +- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 2 +- src/openrct2/peep/Peep.cpp | 6 +-- src/openrct2/rct2/S6Exporter.cpp | 4 +- src/openrct2/ride/TrainManager.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 8 ++-- .../ride/transport/MiniatureRailway.cpp | 4 +- src/openrct2/world/Map.cpp | 4 +- src/openrct2/world/MapHelpers.cpp | 2 +- src/openrct2/world/TileInspector.cpp | 2 +- 24 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 37ec3865ee..cbc88b6d31 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -377,12 +377,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; } @@ -395,7 +395,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; } @@ -403,7 +403,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; } @@ -411,7 +411,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 0090e08e09..bde55168e2 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -745,7 +745,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 ad17d560f7..d2090aa077 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); @@ -554,7 +554,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/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/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 137ef0c030..ee2555fdc6 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -700,7 +700,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; @@ -934,7 +934,7 @@ uint8_t NetworkBase::GetDefaultGroup() void NetworkBase::SetDefaultGroup(uint8_t id) { - if (GetGroupByID(id)) + if (GetGroupByID(id) != nullptr) { default_group = id; } @@ -1336,7 +1336,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; } @@ -1356,7 +1356,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; } @@ -1372,7 +1372,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(); @@ -1386,7 +1386,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)); } @@ -1844,7 +1844,7 @@ void NetworkBase::ProcessPlayerList() { // Add new player. player = AddPlayer("", ""); - if (player) + if (player != nullptr) { *player = pendingPlayer; if (player->Flags & NETWORK_PLAYER_FLAG_ISSERVER) @@ -1965,7 +1965,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); } @@ -1976,7 +1976,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, @@ -2181,7 +2181,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); @@ -2426,7 +2426,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); @@ -2468,7 +2468,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; } @@ -2880,10 +2880,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; } @@ -3084,7 +3084,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); @@ -3101,7 +3101,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; } @@ -3510,7 +3510,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); } @@ -3521,7 +3521,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); } @@ -3701,7 +3701,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); } @@ -3768,7 +3768,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; } @@ -3784,7 +3784,7 @@ Peep* network_get_pickup_peep(uint8_t playerid) } NetworkPlayer* player = network.GetPlayerByID(playerid); - if (player) + if (player != nullptr) { return player->PickupPeep; } @@ -3801,7 +3801,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; } @@ -3817,7 +3817,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; } @@ -3828,7 +3828,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 c11d0991e3..24625f0bc0 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) { @@ -1199,7 +1199,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 9895036e18..33cea3719d 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 4a36e8622b..288b096b81 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 @@ -2056,7 +2056,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/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 7ef6c5f03e..7015d66994 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1148,7 +1148,7 @@ constexpr RCT12EntityLinkListOffset GetRCT2LinkListOffset(const EntityBase* src) case EntityType::Vehicle: { auto veh = src->As(); - if (veh && veh->IsHead()) + if (veh != nullptr && veh->IsHead()) { output = RCT12EntityLinkListOffset::TrainHead; } @@ -1863,7 +1863,7 @@ void S6Exporter::ExportTileElement(RCT12TileElement* dst, const TileElement* src // This has to be done last, since the maze entry shares fields with the colour and sequence fields. auto ride = get_ride(static_cast(dst2->GetRideIndex())); - if (ride) + if (ride != nullptr) { if (ride->type == RIDE_TYPE_MAZE) { 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 cda70e0a21..7f9be950eb 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1691,7 +1691,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); } @@ -1705,7 +1705,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/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index e032676314..56c5613875 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -212,7 +212,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) From a8b84989eb00de695f47c15e956cc7629cdfe8d2 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 25 Sep 2021 08:45:06 +0200 Subject: [PATCH 7/7] Check for nullptr explicitly in operct2-ui (#15460) --- src/openrct2-ui/input/MouseInput.cpp | 23 ++++++++++---------- src/openrct2-ui/windows/Changelog.cpp | 2 +- src/openrct2-ui/windows/Guest.cpp | 8 +++---- src/openrct2-ui/windows/Options.cpp | 2 +- src/openrct2-ui/windows/Ride.cpp | 14 +++++------- src/openrct2-ui/windows/RideConstruction.cpp | 15 +++++++------ src/openrct2-ui/windows/SavePrompt.cpp | 2 +- src/openrct2-ui/windows/Staff.cpp | 17 +++++++-------- src/openrct2-ui/windows/TopToolbar.cpp | 14 ++++++------ 9 files changed, 48 insertions(+), 49 deletions(-) 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..15ca93958e 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; } @@ -3566,17 +3566,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 +3585,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 +3601,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 727e755429..8f9ea88b71 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; @@ -954,7 +953,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; @@ -1361,7 +1360,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; @@ -1382,7 +1381,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]; @@ -1396,7 +1395,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/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 4ea2643e09..a7f7660dfa 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; } @@ -3058,7 +3058,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) @@ -3067,7 +3067,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; @@ -3110,7 +3110,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; @@ -3555,7 +3555,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) { @@ -3582,7 +3582,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) { @@ -3678,7 +3678,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) {