From e23638548a2c141ceda25209ab79ef2627b85930 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 4 Aug 2019 14:45:17 +0100 Subject: [PATCH] Reduce use of MAX_RIDES and RIDE_TYPE_NULL --- src/openrct2-ui/windows/RideConstruction.cpp | 2 +- src/openrct2/EditorObjectSelectionSession.cpp | 4 +-- src/openrct2/actions/RideDemolishAction.hpp | 8 ++--- .../actions/RideEntranceExitPlaceAction.hpp | 10 ++---- .../actions/RideEntranceExitRemoveAction.hpp | 12 ++----- .../actions/RideSetAppearanceAction.hpp | 10 ++---- src/openrct2/actions/RideSetName.hpp | 8 ++--- src/openrct2/actions/RideSetPriceAction.hpp | 12 ++----- src/openrct2/actions/RideSetSetting.hpp | 12 ++----- src/openrct2/actions/RideSetStatus.hpp | 23 ++++++------ .../actions/RideSetVehiclesAction.hpp | 12 ++----- src/openrct2/actions/TrackPlaceAction.hpp | 5 --- src/openrct2/interface/InteractiveConsole.cpp | 36 +++++++++---------- src/openrct2/ride/Ride.h | 3 +- src/openrct2/ride/RideRatings.cpp | 12 +++---- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/ride/TrackPaint.cpp | 4 +-- src/openrct2/world/Footpath.cpp | 4 +-- src/openrct2/world/Park.cpp | 2 +- 19 files changed, 69 insertions(+), 112 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 0e05989792..1794868de9 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -607,7 +607,7 @@ static void window_ride_construction_close(rct_window* w) // If we demolish a ride all windows will be closed including the construction window, // the ride at this point is already gone. auto ride = get_ride(_currentRideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { return; } diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index b7cdf1cf5a..a8bc528557 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -187,8 +187,8 @@ void setup_in_use_selection_flags() for (uint8_t ride_index = 0; ride_index < 0xFF; ride_index++) { - Ride* ride = get_ride(ride_index); - if (ride->type != RIDE_TYPE_NULL) + auto ride = get_ride(ride_index); + if (ride != nullptr) { uint8_t type = ride->subtype; Editor::SetSelectedObject(OBJECT_TYPE_RIDE, type, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 2b7fdfcf5e..0b2c654782 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -59,8 +59,8 @@ public: GameActionResult::Ptr Query() const override { - Ride* ride = get_ride(_rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_DEMOLISH_RIDE, STR_NONE); @@ -105,8 +105,8 @@ public: GameActionResult::Ptr Execute() const override { - Ride* ride = get_ride(_rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_DEMOLISH_RIDE, STR_NONE); diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index 3dd6ebc504..7d37a0a129 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -60,14 +60,8 @@ public: return MakeResult(GA_ERROR::NO_FREE_ELEMENTS, errorTitle); } - if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL) - { - log_warning("Invalid game command for ride %d", (int32_t)_rideIndex); - return MakeResult(GA_ERROR::INVALID_PARAMETERS, errorTitle); - } - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid game command for ride %d", (int32_t)_rideIndex); return MakeResult(GA_ERROR::INVALID_PARAMETERS, errorTitle); @@ -147,7 +141,7 @@ public: auto errorTitle = _isExit ? STR_CANT_BUILD_MOVE_EXIT_FOR_THIS_RIDE_ATTRACTION : STR_CANT_BUILD_MOVE_ENTRANCE_FOR_THIS_RIDE_ATTRACTION; Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid game command for ride %d", (int32_t)_rideIndex); return MakeResult(GA_ERROR::INVALID_PARAMETERS, errorTitle); diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp index 0b67bbddf0..44cf69d825 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp @@ -47,14 +47,8 @@ public: GameActionResult::Ptr Query() const override { - if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL) - { - log_warning("Invalid game command for ride %d", int32_t(_rideIndex)); - return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); - } - - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid ride id %d for entrance/exit removal", (int32_t)_rideIndex); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); @@ -117,7 +111,7 @@ public: GameActionResult::Ptr Execute() const override { Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid ride id %d for entrance/exit removal", (int32_t)_rideIndex); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); diff --git a/src/openrct2/actions/RideSetAppearanceAction.hpp b/src/openrct2/actions/RideSetAppearanceAction.hpp index 0701910143..bda3232938 100644 --- a/src/openrct2/actions/RideSetAppearanceAction.hpp +++ b/src/openrct2/actions/RideSetAppearanceAction.hpp @@ -68,14 +68,8 @@ public: GameActionResult::Ptr Query() const override { - if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL) - { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); - return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); - } - - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); diff --git a/src/openrct2/actions/RideSetName.hpp b/src/openrct2/actions/RideSetName.hpp index 468d08a26d..2c423e8009 100644 --- a/src/openrct2/actions/RideSetName.hpp +++ b/src/openrct2/actions/RideSetName.hpp @@ -52,8 +52,8 @@ public: GameActionResult::Ptr Query() const override { - Ride* ride = get_ride(_rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE); @@ -70,8 +70,8 @@ public: GameActionResult::Ptr Execute() const override { - Ride* ride = get_ride(_rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE); diff --git a/src/openrct2/actions/RideSetPriceAction.hpp b/src/openrct2/actions/RideSetPriceAction.hpp index cc056176a0..5f5ed9cd25 100644 --- a/src/openrct2/actions/RideSetPriceAction.hpp +++ b/src/openrct2/actions/RideSetPriceAction.hpp @@ -57,14 +57,8 @@ public: { GameActionResult::Ptr res = std::make_unique(); - if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL) - { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); - return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); - } - - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); @@ -86,7 +80,7 @@ public: res->ExpenditureType = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS; Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); diff --git a/src/openrct2/actions/RideSetSetting.hpp b/src/openrct2/actions/RideSetSetting.hpp index ed560e9053..725cf3e82e 100644 --- a/src/openrct2/actions/RideSetSetting.hpp +++ b/src/openrct2/actions/RideSetSetting.hpp @@ -60,14 +60,8 @@ public: GameActionResult::Ptr Query() const override { - if (_rideIndex >= MAX_RIDES || _rideIndex < 0) - { - log_warning("Invalid game command for ride %d", int32_t(_rideIndex)); - return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_CHANGE_OPERATING_MODE); - } - - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid ride: #%d.", (int32_t)_rideIndex); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_CHANGE_OPERATING_MODE); @@ -172,7 +166,7 @@ public: GameActionResult::Ptr Execute() const override { Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid ride: #%d.", (int32_t)_rideIndex); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_CHANGE_OPERATING_MODE); diff --git a/src/openrct2/actions/RideSetStatus.hpp b/src/openrct2/actions/RideSetStatus.hpp index 3ed8a0888d..5bd1487888 100644 --- a/src/openrct2/actions/RideSetStatus.hpp +++ b/src/openrct2/actions/RideSetStatus.hpp @@ -59,18 +59,19 @@ public: GameActionResult::Ptr Query() const override { GameActionResult::Ptr res = std::make_unique(); - Ride* ride = get_ride(_rideIndex); - res->ErrorTitle = _StatusErrorTitles[_status]; - ride->FormatNameTo(res->ErrorMessageArgs.data() + 6); - if (_rideIndex >= MAX_RIDES || _rideIndex < 0) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); res->Error = GA_ERROR::INVALID_PARAMETERS; - res->ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; + res->ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; + res->ErrorMessage = STR_NONE; return res; } + res->ErrorTitle = _StatusErrorTitles[_status]; + ride->FormatNameTo(res->ErrorMessageArgs.data() + 6); if (_status != ride->status) { if (_status == RIDE_STATUS_SIMULATING && (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)) @@ -107,18 +108,18 @@ public: GameActionResult::Ptr res = std::make_unique(); res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS; - Ride* ride = get_ride(_rideIndex); - res->ErrorTitle = _StatusErrorTitles[_status]; - ride->FormatNameTo(res->ErrorMessageArgs.data() + 6); - - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); res->Error = GA_ERROR::INVALID_PARAMETERS; - res->ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; + res->ErrorTitle = STR_RIDE_DESCRIPTION_UNKNOWN; + res->ErrorMessage = STR_NONE; return res; } + res->ErrorTitle = _StatusErrorTitles[_status]; + ride->FormatNameTo(res->ErrorMessageArgs.data() + 6); if (ride->overall_view.xy != RCT_XY8_UNDEFINED) { res->Position.x = ride->overall_view.x * 32 + 16; diff --git a/src/openrct2/actions/RideSetVehiclesAction.hpp b/src/openrct2/actions/RideSetVehiclesAction.hpp index 69b89c02ac..04120166a7 100644 --- a/src/openrct2/actions/RideSetVehiclesAction.hpp +++ b/src/openrct2/actions/RideSetVehiclesAction.hpp @@ -74,14 +74,8 @@ public: } auto errTitle = SetVehicleTypeErrorTitle[_type]; - if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL) - { - log_warning("Invalid game command for ride %u", uint32_t(_rideIndex)); - return std::make_unique(GA_ERROR::INVALID_PARAMETERS, errTitle); - } - - Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(_rideIndex); + if (ride == nullptr) { log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, errTitle); @@ -138,7 +132,7 @@ public: { auto errTitle = SetVehicleTypeErrorTitle[_type]; Ride* ride = get_ride(_rideIndex); - if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid game command, ride_id = %u", uint32_t(_rideIndex)); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, errTitle); diff --git a/src/openrct2/actions/TrackPlaceAction.hpp b/src/openrct2/actions/TrackPlaceAction.hpp index ef8e7c9443..bce9e895b8 100644 --- a/src/openrct2/actions/TrackPlaceAction.hpp +++ b/src/openrct2/actions/TrackPlaceAction.hpp @@ -93,11 +93,6 @@ public: log_warning("Invalid ride for track placement, rideIndex = %d", (int32_t)_rideIndex); return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); } - if (ride->type == RIDE_TYPE_NULL) - { - log_warning("Invalid ride type, rideIndex = %d", (int32_t)_rideIndex); - return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); - } rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); if (rideEntry == nullptr) { diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 47865996c9..05643e2031 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -136,14 +136,12 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) { if (argv[0] == "list") { - Ride* ride; - int32_t i; - FOR_ALL_RIDES (i, ride) + for (const auto& ride : GetRideManager()) { - auto name = ride->GetName(); + auto name = ride.GetName(); console.WriteFormatLine( - "ride: %03d type: %02u subtype %03u operating mode: %02u name: %s", i, ride->type, ride->subtype, - ride->mode, name.c_str()); + "ride: %03d type: %02u subtype %03u operating mode: %02u name: %s", ride.id, ride.type, ride.subtype, + ride.mode, name.c_str()); } } else if (argv[0] == "set") @@ -215,7 +213,7 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) { console.WriteFormatLine("Invalid ride mode."); } - else if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + else if (ride == nullptr) { console.WriteFormatLine("No ride found with index %d", ride_index); } @@ -242,12 +240,12 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - Ride* ride = get_ride(ride_index); + auto ride = get_ride(ride_index); if (mass <= 0) { console.WriteFormatLine("Friction value must be strictly positive"); } - else if (ride->type == RIDE_TYPE_NULL) + else if (ride == nullptr) { console.WriteFormatLine("No ride found with index %d", ride_index); } @@ -282,12 +280,12 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - Ride* ride = get_ride(ride_index); + auto ride = get_ride(ride_index); if (excitement <= 0) { console.WriteFormatLine("Excitement value must be strictly positive"); } - else if (ride->type == RIDE_TYPE_NULL) + else if (ride == nullptr) { console.WriteFormatLine("No ride found with index %d", ride_index); } @@ -313,12 +311,12 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - Ride* ride = get_ride(ride_index); + auto ride = get_ride(ride_index); if (intensity <= 0) { console.WriteFormatLine("Intensity value must be strictly positive"); } - else if (ride->type == RIDE_TYPE_NULL) + else if (ride == nullptr) { console.WriteFormatLine("No ride found with index %d", ride_index); } @@ -344,12 +342,12 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - Ride* ride = get_ride(ride_index); + auto ride = get_ride(ride_index); if (nausea <= 0) { console.WriteFormatLine("Nausea value must be strictly positive"); } - else if (ride->type == RIDE_TYPE_NULL) + else if (ride == nullptr) { console.WriteFormatLine("No ride found with index %d", ride_index); } @@ -390,13 +388,11 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) if (int_valid[0] && int_valid[1]) { - uint16_t rideId{}; - Ride* ride; - FOR_ALL_RIDES (rideId, ride) + for (const auto& ride : GetRideManager()) { - if (ride->type == rideType) + if (ride.type == rideType) { - auto rideSetPrice = RideSetPriceAction(rideId, price, true); + auto rideSetPrice = RideSetPriceAction(ride.id, price, true); GameActions::Execute(&rideSetPrice); } } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 960edec1d3..343ecbf587 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -18,6 +18,7 @@ #include "RideTypes.h" #include "Vehicle.h" +#include #include interface IObjectManager; @@ -39,10 +40,10 @@ struct Staff; #define MAX_CARS_PER_TRAIN 255 #define MAX_STATIONS 4 #define MAX_RIDES 255 -#define RIDE_ID_NULL 255 #define RIDE_TYPE_NULL 255 #define RIDE_ADJACENCY_CHECK_DISTANCE 5 +constexpr ride_id_t RIDE_ID_NULL = std::numeric_limits::max(); constexpr uint16_t const MAX_INVERSIONS = RCT12_MAX_INVERSIONS; constexpr uint16_t const MAX_GOLF_HOLES = RCT12_MAX_GOLF_HOLES; constexpr uint16_t const MAX_HELICES = RCT12_MAX_HELICES; diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 926978f2c3..4cdb7a8f71 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -194,8 +194,8 @@ static void ride_ratings_update_state_1() static void ride_ratings_update_state_2() { const ride_id_t rideIndex = gRideRatingsCalcData.current_ride; - Ride* ride = get_ride(rideIndex); - if (ride->type == RIDE_TYPE_NULL || ride->status == RIDE_STATUS_CLOSED) + auto ride = get_ride(rideIndex); + if (ride == nullptr || ride->status == RIDE_STATUS_CLOSED) { gRideRatingsCalcData.state = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; return; @@ -268,8 +268,8 @@ static void ride_ratings_update_state_2() */ static void ride_ratings_update_state_3() { - Ride* ride = get_ride(gRideRatingsCalcData.current_ride); - if (ride->type == RIDE_TYPE_NULL || ride->status == RIDE_STATUS_CLOSED) + auto ride = get_ride(gRideRatingsCalcData.current_ride); + if (ride == nullptr || ride->status == RIDE_STATUS_CLOSED) { gRideRatingsCalcData.state = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; return; @@ -298,8 +298,8 @@ static void ride_ratings_update_state_4() */ static void ride_ratings_update_state_5() { - Ride* ride = get_ride(gRideRatingsCalcData.current_ride); - if (ride->type == RIDE_TYPE_NULL || ride->status == RIDE_STATUS_CLOSED) + auto ride = get_ride(gRideRatingsCalcData.current_ride); + if (ride == nullptr || ride->status == RIDE_STATUS_CLOSED) { gRideRatingsCalcData.state = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; return; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 47f8d22f6b..da8d0021f7 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1870,7 +1870,7 @@ static money32 place_track_design(int16_t x, int16_t y, int16_t z, uint8_t flags } auto ride = get_ride(rideIndex); - if (ride->type == RIDE_TYPE_NULL) + if (ride == nullptr) { log_warning("Invalid game command for track placement, ride id = %d", ride->id); return MONEY32_UNDEFINED; diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index b95f39c0e3..a6b8690c36 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -2157,8 +2157,8 @@ void track_paint_util_left_corkscrew_up_supports(paint_session* session, uint8_t void track_paint(paint_session* session, uint8_t direction, int32_t height, const TileElement* tileElement) { ride_id_t rideIndex = tileElement->AsTrack()->GetRideIndex(); - Ride* ride = get_ride(rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(rideIndex); + if (ride == nullptr) { log_error("Attempted to paint invalid ride: %d", rideIndex); return; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e7b61a181d..e0b3058891 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1176,8 +1176,8 @@ void footpath_update_queue_chains() for (uint8_t* queueChainPtr = _footpathQueueChain; queueChainPtr < _footpathQueueChainNext; queueChainPtr++) { ride_id_t rideIndex = *queueChainPtr; - Ride* ride = get_ride(rideIndex); - if (ride->type == RIDE_TYPE_NULL) + auto ride = get_ride(rideIndex); + if (ride == nullptr) continue; for (int32_t i = 0; i < MAX_STATIONS; i++) diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 74c55e9dd9..b9eebad9f7 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -509,7 +509,7 @@ money32 Park::CalculateParkValue() const money32 Park::CalculateRideValue(const Ride* ride) const { money32 result = 0; - if (ride->type != RIDE_TYPE_NULL && ride->value != RIDE_VALUE_UNDEFINED) + if (ride != nullptr && ride->value != RIDE_VALUE_UNDEFINED) { result = (ride->value * 10) * (ride_customers_in_last_5_minutes(ride) + rideBonusValue[ride->type] * 4); }