Replace ride_type_has_flag() with retrieving RTD

This commit is contained in:
Gymnasiast 2021-02-26 09:49:09 +01:00
parent b1ab20ec27
commit f118b2ede4
No known key found for this signature in database
GPG key ID: DBFFF47AB2CA3EDD
20 changed files with 37 additions and 51 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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)
{

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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))
{

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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()));
}

View file

@ -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<int32_t>(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

View file

@ -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();

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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");
}

View file

@ -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];
}