diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index b36792a9bf..dc55030481 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -321,7 +321,7 @@ static void window_install_track_paint(rct_window* w, rct_drawpixelinfo* dpi) screenPos.y += LIST_ROW_HEIGHT; } - if (ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_G_FORCES)) + if (GetRideTypeDescriptor(td6->type).HasFlag(RIDE_TYPE_FLAG_HAS_G_FORCES)) { // Maximum positive vertical Gs { @@ -358,7 +358,7 @@ static void window_install_track_paint(rct_window* w, rct_drawpixelinfo* dpi) } } - if (ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_DROPS)) + if (GetRideTypeDescriptor(td6->type).HasFlag(RIDE_TYPE_FLAG_HAS_DROPS)) { // Drops uint16_t drops = td6->drops & 0x3F; diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index ee79ca73b0..a89fbcc4b3 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -949,7 +949,7 @@ static void window_new_ride_paint_ride_information( // rct_string_id stringId = STR_NEW_RIDE_COST; - if (!ride_type_has_flag(item.Type, RIDE_TYPE_FLAG_HAS_NO_TRACK)) + if (!GetRideTypeDescriptor(item.Type).HasFlag(RIDE_TYPE_FLAG_HAS_NO_TRACK)) stringId = STR_NEW_RIDE_COST_FROM; ft = Formatter(); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index e667616356..c1d8875f40 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2107,7 +2107,7 @@ static void populate_vehicle_type_dropdown(Ride* ride) for (; rideTypeIterator <= rideTypeIteratorMax; rideTypeIterator++) { - if (selectionShouldBeExpanded && ride_type_has_flag(rideTypeIterator, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (selectionShouldBeExpanded && GetRideTypeDescriptor(rideTypeIterator).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) continue; if (selectionShouldBeExpanded && (rideTypeIterator == RIDE_TYPE_MAZE || rideTypeIterator == RIDE_TYPE_MINI_GOLF)) continue; diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 552bf8f512..267954250f 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -1188,7 +1188,7 @@ static void window_ride_construction_resize(rct_window* w) disabledWidgets |= (1ULL << WIDX_CONSTRUCT); } } - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) { disabledWidgets &= ~(1ULL << WIDX_BANKING_GROUPBOX); } @@ -2772,7 +2772,7 @@ static void window_ride_construction_update_widgets(rct_window* w) int32_t rideType = ride_get_alternative_type(ride); w->hold_down_widgets = 0; - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_IS_SHOP) || !_stationConstructed) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_IS_SHOP) || !_stationConstructed) { window_ride_construction_widgets[WIDX_ENTRANCE_EXIT_GROUPBOX].type = WindowWidgetType::Empty; window_ride_construction_widgets[WIDX_ENTRANCE].type = WindowWidgetType::Empty; @@ -2803,7 +2803,7 @@ static void window_ride_construction_update_widgets(rct_window* w) window_ride_construction_widgets[WIDX_STRAIGHT].type = WindowWidgetType::Empty; } - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_LARGE_CURVES)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_HAS_LARGE_CURVES)) { window_ride_construction_widgets[WIDX_LEFT_CURVE_LARGE].type = WindowWidgetType::FlatBtn; window_ride_construction_widgets[WIDX_RIGHT_CURVE_LARGE].type = WindowWidgetType::FlatBtn; @@ -3047,7 +3047,7 @@ static void window_ride_construction_update_widgets(rct_window* w) window_ride_construction_widgets[WIDX_BANK_STRAIGHT].type = WindowWidgetType::FlatBtn; window_ride_construction_widgets[WIDX_BANK_RIGHT].type = WindowWidgetType::FlatBtn; } - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) { if (rideType == RIDE_TYPE_WATER_COASTER) { @@ -3150,7 +3150,7 @@ static void window_ride_construction_update_widgets(rct_window* w) window_ride_construction_widgets[WIDX_CONSTRUCT].type = WindowWidgetType::Empty; window_ride_construction_widgets[WIDX_DEMOLISH].type = WindowWidgetType::FlatBtn; window_ride_construction_widgets[WIDX_ROTATE].type = WindowWidgetType::Empty; - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_CANNOT_HAVE_GAPS)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_CANNOT_HAVE_GAPS)) { window_ride_construction_widgets[WIDX_PREVIOUS_SECTION].type = WindowWidgetType::Empty; window_ride_construction_widgets[WIDX_NEXT_SECTION].type = WindowWidgetType::Empty; @@ -3249,7 +3249,7 @@ static void window_ride_construction_update_widgets(rct_window* w) if (!_currentlyShowingBrakeOrBoosterSpeed) { - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_TRACK_ELEMENTS_HAVE_TWO_VARIETIES)) { if (_currentTrackAlternative & RIDE_TYPE_ALTERNATIVE_TRACK_PIECES) { diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index dc09c85778..2948502d77 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -578,7 +578,7 @@ static void window_track_list_paint(rct_window* w, rct_drawpixelinfo* dpi) screenPos.y += LIST_ROW_HEIGHT + 4; // Information for tracked rides. - if (ride_type_has_flag(_loadedTrackDesign->type, RIDE_TYPE_FLAG_HAS_TRACK)) + if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_TRACK)) { if (_loadedTrackDesign->type != RIDE_TYPE_MAZE) { @@ -610,7 +610,7 @@ static void window_track_list_paint(rct_window* w, rct_drawpixelinfo* dpi) screenPos.y += LIST_ROW_HEIGHT; } - if (ride_type_has_flag(_loadedTrackDesign->type, RIDE_TYPE_FLAG_HAS_G_FORCES)) + if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_G_FORCES)) { // Maximum positive vertical Gs int32_t gForces = _loadedTrackDesign->max_positive_vertical_g * 32; @@ -636,7 +636,7 @@ static void window_track_list_paint(rct_window* w, rct_drawpixelinfo* dpi) } } - if (ride_type_has_flag(_loadedTrackDesign->type, RIDE_TYPE_FLAG_HAS_DROPS)) + if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_DROPS)) { // Drops uint16_t drops = _loadedTrackDesign->drops & 0x3F; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 9e2c146dc5..ddf732dc34 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -60,7 +60,7 @@ static void setup_track_manager_objects() for (auto rideType : item->RideInfo.RideType) { - if (rideType != RIDE_TYPE_NULL && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_TRACK)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_HAS_TRACK)) { *selectionFlags &= ~OBJECT_SELECTION_FLAG_6; break; diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index 20c6f9b139..2663b1d86b 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -231,7 +231,7 @@ bool RideSetVehicleAction::ride_is_vehicle_type_valid(Ride* ride) const { if (selectionShouldBeExpanded) { - if (ride_type_has_flag(rideTypeIterator, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(rideTypeIterator).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) continue; if (rideTypeIterator == RIDE_TYPE_MAZE || rideTypeIterator == RIDE_TYPE_MINI_GOLF) continue; diff --git a/src/openrct2/actions/WallPlaceAction.cpp b/src/openrct2/actions/WallPlaceAction.cpp index cba576b6e3..7adaff2f90 100644 --- a/src/openrct2/actions/WallPlaceAction.cpp +++ b/src/openrct2/actions/WallPlaceAction.cpp @@ -618,7 +618,7 @@ GameActions::Result::Ptr WallPlaceAction::WallCheckObstruction( bool WallPlaceAction::TrackIsAllowedWallEdges( uint8_t rideType, track_type_t trackType, uint8_t trackSequence, uint8_t direction) { - if (!ride_type_has_flag(rideType, RIDE_TYPE_FLAG_TRACK_NO_WALLS)) + if (!GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_TRACK_NO_WALLS)) { if (TrackSequenceElementAllowedWallEdges[trackType][trackSequence] & (1 << direction)) { diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 33c66147a5..d87e5111a8 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -3012,16 +3012,16 @@ void Guest::StopPurchaseThought(uint8_t ride_type) { auto thoughtType = PeepThoughtType::Hungry; - if (!ride_type_has_flag(ride_type, RIDE_TYPE_FLAG_SELLS_FOOD)) + if (!GetRideTypeDescriptor(ride_type).HasFlag(RIDE_TYPE_FLAG_SELLS_FOOD)) { thoughtType = PeepThoughtType::Thirsty; - if (!ride_type_has_flag(ride_type, RIDE_TYPE_FLAG_SELLS_DRINKS)) + if (!GetRideTypeDescriptor(ride_type).HasFlag(RIDE_TYPE_FLAG_SELLS_DRINKS)) { thoughtType = PeepThoughtType::RunningOut; if (ride_type != RIDE_TYPE_CASH_MACHINE) { thoughtType = PeepThoughtType::Toilet; - if (!ride_type_has_flag(ride_type, RIDE_TYPE_FLAG_IS_TOILET)) + if (!GetRideTypeDescriptor(ride_type).HasFlag(RIDE_TYPE_FLAG_IS_TOILET)) { return; } diff --git a/src/openrct2/rct1/Tables.cpp b/src/openrct2/rct1/Tables.cpp index 0cb45ac90c..b0882fd014 100644 --- a/src/openrct2/rct1/Tables.cpp +++ b/src/openrct2/rct1/Tables.cpp @@ -1390,7 +1390,7 @@ namespace RCT1 track_type_t RCT1TrackTypeToOpenRCT2(RCT12TrackType origTrackType, uint8_t rideType) { - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) return RCT12FlatTrackTypeToOpenRCT2(origTrackType); return origTrackType; diff --git a/src/openrct2/rct2/RCT2.cpp b/src/openrct2/rct2/RCT2.cpp index c306ea5e79..dbead6fffd 100644 --- a/src/openrct2/rct2/RCT2.cpp +++ b/src/openrct2/rct2/RCT2.cpp @@ -145,7 +145,7 @@ bool RCT2TrackTypeIsBooster(uint8_t rideType, uint16_t trackType) track_type_t RCT2TrackTypeToOpenRCT2(RCT12TrackType origTrackType, uint8_t rideType) { - if (rideType < std::size(RideTypeDescriptors) && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) return RCT12FlatTrackTypeToOpenRCT2(origTrackType); if (origTrackType == TrackElemType::RotationControlToggleAlias && !RCT2TrackTypeIsBooster(rideType, origTrackType)) return TrackElemType::RotationControlToggle; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 0584669d63..ca69b1fa8f 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1382,7 +1382,7 @@ public: dst->SetTrackType(src->GetTrackType()); // RotationControlToggle and Booster are saved as the same track piece ID // Which one the vehicle is using must be determined - if (ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(ride.type).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) { dst->SetTrackType(RCT12FlatTrackTypeToOpenRCT2(src->GetTrackType())); } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index cc5c40371b..e466941484 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -5351,19 +5351,6 @@ RideNaming get_ride_naming(const uint8_t rideType, rct_ride_entry* rideEntry) } } -bool ride_type_has_flag(int32_t rideType, uint64_t flag) -{ - if (rideType < static_cast(std::size(RideTypeDescriptors))) - { - return (RideTypeDescriptors[rideType].Flags & flag) != 0; - } - else - { - Guard::Assert(false); - return false; - } -} - /* * The next eight functions are helpers to access ride data at the offset 10E & * 110. Known as the turn counts. There are 3 different types (default, banked, sloped) @@ -7333,10 +7320,7 @@ uint64_t Ride::GetAvailableModes() const const RideTypeDescriptor& Ride::GetRideTypeDescriptor() const { - if (type >= std::size(RideTypeDescriptors)) - return DummyRTD; - - return RideTypeDescriptors[type]; + return ::GetRideTypeDescriptor(type); } uint8_t Ride::GetMinCarsPerTrain() const diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index a2894272c5..6aa102cd88 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1169,7 +1169,6 @@ int32_t get_turn_count_4_plus_elements(Ride* ride, uint8_t type); uint8_t ride_get_helix_sections(Ride* ride); -bool ride_type_has_flag(int32_t rideType, uint64_t flag); bool ride_has_any_track_elements(const Ride* ride); void ride_construction_set_default_next_piece(); diff --git a/src/openrct2/ride/RideData.h b/src/openrct2/ride/RideData.h index bc855ccd36..91e04c291f 100644 --- a/src/openrct2/ride/RideData.h +++ b/src/openrct2/ride/RideData.h @@ -351,4 +351,12 @@ constexpr const RideTypeDescriptor DummyRTD = }; // clang-format on +constexpr const RideTypeDescriptor& GetRideTypeDescriptor(ObjectEntryIndex rideType) +{ + if (rideType >= std::size(RideTypeDescriptors)) + return DummyRTD; + + return RideTypeDescriptors[rideType]; +} + #endif diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 4017e7f746..13cc4dfd00 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1912,7 +1912,7 @@ static bool track_design_place_preview(TrackDesign* td6, money32* cost, Ride** o // Flat rides need their vehicle colours loaded for display // in the preview window - if (!ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_TRACK)) + if (!GetRideTypeDescriptor(td6->type).HasFlag(RIDE_TYPE_FLAG_HAS_TRACK)) { for (int32_t i = 0; i < RCT12_MAX_VEHICLE_COLOURS; i++) { @@ -2017,7 +2017,7 @@ void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels) // Special case for flat rides - Z-axis info is irrelevant // and must be zeroed out lest the preview be off-centre - if (!ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_TRACK)) + if (!GetRideTypeDescriptor(td6->type).HasFlag(RIDE_TYPE_FLAG_HAS_TRACK)) { centre.z = 0; size_z = 0; diff --git a/test/testpaint/Compat.cpp b/test/testpaint/Compat.cpp index 235f64668a..fdc2858cf0 100644 --- a/test/testpaint/Compat.cpp +++ b/test/testpaint/Compat.cpp @@ -213,11 +213,6 @@ TileElement* map_get_first_element_at(const CoordsXY& elementPos) return gTileElementTilePointers[tileElementPos.x + tileElementPos.y * 256]; } -bool ride_type_has_flag(int rideType, uint64_t flag) -{ - return (RideTypeDescriptors[rideType].Flags & flag) != 0; -} - int16_t get_height_marker_offset() { return 0; diff --git a/test/testpaint/TestTrack.cpp b/test/testpaint/TestTrack.cpp index f725273cb0..cba62ad737 100644 --- a/test/testpaint/TestTrack.cpp +++ b/test/testpaint/TestTrack.cpp @@ -86,7 +86,7 @@ class ChainLiftFilter : public ITestTrackFilter public: bool AppliesTo(uint8_t rideType, uint8_t trackType) override { - return !ride_type_has_flag(rideType, RIDE_TYPE_FLAG_FLAT_RIDE); + return !GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE); } int Variations(uint8_t rideType, uint8_t trackType) override diff --git a/test/testpaint/generate.cpp b/test/testpaint/generate.cpp index 583756df77..0279c7f2b5 100644 --- a/test/testpaint/generate.cpp +++ b/test/testpaint/generate.cpp @@ -1163,7 +1163,7 @@ private: int generatePaintCode(uint8_t rideType) { - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) { fprintf(stderr, "Flat rides not supported.\n"); } diff --git a/test/testpaint/main.cpp b/test/testpaint/main.cpp index e39aecab47..4db67bd03d 100644 --- a/test/testpaint/main.cpp +++ b/test/testpaint/main.cpp @@ -520,7 +520,7 @@ int main(int argc, char* argv[]) TestCase testCase = {}; testCase.rideType = rideType; - if (ride_type_has_flag(rideType, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) { testCase.trackTypes.push_back(RideTypeDescriptors[rideType].StartTrackPiece); } @@ -564,7 +564,7 @@ int main(int argc, char* argv[]) for (auto&& trackType : tc.trackTypes) { utf8string trackTypeName; - if (ride_type_has_flag(tc.rideType, RIDE_TYPE_FLAG_FLAT_RIDE)) + if (GetRideTypeDescriptor(tc.rideType).HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE)) { trackTypeName = FlatTrackNames[trackType]; }