1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Merge pull request #16638 from Gymnasiast/fix/16576

Fix #16576: Cannot select vehicle types with entry index >= 256
This commit is contained in:
Michael Steenbeek
2022-02-13 21:33:53 +01:00
committed by GitHub
6 changed files with 20 additions and 17 deletions

View File

@@ -926,7 +926,7 @@ static std::vector<RideTypeLabel> RideDropdownData;
// Used for sorting the vehicle type dropdown.
struct VehicleTypeLabel
{
int32_t subtype_id;
ObjectEntryIndex subtype_id;
rct_string_id label_id;
const char* label_string;
};
@@ -1043,7 +1043,7 @@ static void WindowRideDrawTabVehicle(rct_drawpixelinfo* dpi, rct_window* w)
screenCoords.y /= 4;
}
const uint8_t vehicle = ride_entry_get_vehicle_at_position(
const auto vehicle = ride_entry_get_vehicle_at_position(
ride->subtype, ride->num_cars_per_train, rideEntry->tab_vehicle);
rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[vehicle];
@@ -2016,8 +2016,8 @@ static void WindowRideShowRideTypeDropdown(rct_window* w, rct_widget* widget)
w->colours[1], Dropdown::Flag::StayOpen, RIDE_TYPE_COUNT);
// Find the current ride type in the ordered list.
uint8_t pos = 0;
for (uint8_t i = 0; i < RIDE_TYPE_COUNT; i++)
int32_t pos = 0;
for (int32_t i = 0; i < RIDE_TYPE_COUNT; i++)
{
if (RideDropdownData[i].ride_type_id == ride->type)
{
@@ -2159,8 +2159,8 @@ static void WindowRideShowVehicleTypeDropdown(rct_window* w, rct_widget* widget)
w->colours[1], 0, Dropdown::Flag::StayOpen, numItems, widget->right - dropdownWidget->left);
// Find the current vehicle type in the ordered list.
uint8_t pos = 0;
for (uint8_t i = 0; i < VehicleDropdownData.size(); i++)
int32_t pos = 0;
for (int32_t i = 0; i < static_cast<int32_t>(VehicleDropdownData.size()); i++)
{
if (VehicleDropdownData[i].subtype_id == ride->subtype)
{
@@ -2263,8 +2263,8 @@ static void WindowRideMainDropdown(rct_window* w, rct_widgetindex widgetIndex, i
case WIDX_RIDE_TYPE_DROPDOWN:
if (dropdownIndex != -1 && dropdownIndex < RIDE_TYPE_COUNT)
{
uint8_t rideLabelId = std::clamp(dropdownIndex, 0, RIDE_TYPE_COUNT - 1);
uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id;
auto rideLabelId = std::clamp(dropdownIndex, 0, RIDE_TYPE_COUNT - 1);
auto rideType = RideDropdownData[rideLabelId].ride_type_id;
if (rideType < RIDE_TYPE_COUNT)
{
auto rideSetSetting = RideSetSettingAction(w->rideId, RideSetSetting::RideType, rideType);

View File

@@ -31,7 +31,7 @@ constexpr static rct_string_id SetVehicleTypeErrorTitle[] = {
STR_RIDE_SET_VEHICLE_TYPE_FAIL,
};
RideSetVehicleAction::RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint8_t value, uint8_t colour)
RideSetVehicleAction::RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint16_t value, uint8_t colour)
: _rideIndex(rideIndex)
, _type(type)
, _value(value)
@@ -152,7 +152,8 @@ GameActions::Result RideSetVehicleAction::Execute() const
log_warning("Invalid ride entry, ride->subtype = %d", ride->subtype);
return GameActions::Result(GameActions::Status::InvalidParameters, errTitle, STR_NONE);
}
auto clampValue = _value;
uint8_t clampValue = _value;
static_assert(sizeof(clampValue) == sizeof(ride->proposed_num_cars_per_train));
if (!gCheatsDisableTrainLengthLimit)
{
clampValue = std::clamp(clampValue, rideEntry->min_cars_in_train, rideEntry->max_cars_in_train);

View File

@@ -24,12 +24,12 @@ class RideSetVehicleAction final : public GameActionBase<GameCommand::SetRideVeh
private:
RideId _rideIndex{ RideId::GetNull() };
RideSetVehicleType _type{};
uint8_t _value{};
uint16_t _value{};
uint8_t _colour{};
public:
RideSetVehicleAction() = default;
RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint8_t value, uint8_t colour = 0);
RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint16_t value, uint8_t colour = 0);
void AcceptParameters(GameActionParameterVisitor& visitor) override;
@@ -41,4 +41,6 @@ public:
private:
bool ride_is_vehicle_type_valid(Ride* ride) const;
static_assert(sizeof(_value) >= sizeof(ObjectEntryIndex));
};

View File

@@ -42,7 +42,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "14"
#define NETWORK_STREAM_VERSION "15"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static Peep* _pickup_peep = nullptr;

View File

@@ -5146,10 +5146,10 @@ void Ride::UpdateNumberOfCircuits()
}
}
void Ride::SetRideEntry(int32_t rideEntry)
void Ride::SetRideEntry(ObjectEntryIndex entryIndex)
{
auto colour = ride_get_unused_preset_vehicle_colour(rideEntry);
auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::RideEntry, rideEntry, colour);
auto colour = ride_get_unused_preset_vehicle_colour(entryIndex);
auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::RideEntry, entryIndex, colour);
GameActions::Execute(&rideSetVehicleAction);
}

View File

@@ -298,7 +298,7 @@ public:
void Delete();
void Crash(uint8_t vehicleIndex);
void SetToDefaultInspectionInterval();
void SetRideEntry(int32_t rideEntry);
void SetRideEntry(ObjectEntryIndex entryIndex);
void SetNumVehicles(int32_t numVehicles);
void SetNumCarsPerVehicle(int32_t numCarsPerVehicle);