diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index bfdc11cb64..bb4f1fa83f 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1703,7 +1703,7 @@ rct_window* window_ride_open_vehicle(rct_vehicle* vehicle) // Get view index int32_t view = 1; - for (int32_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { if (ride->vehicles[i] == headVehicleSpriteIndex) break; diff --git a/src/openrct2/actions/TrackDesignAction.cpp b/src/openrct2/actions/TrackDesignAction.cpp index 57ff90b2d0..c940c1712e 100644 --- a/src/openrct2/actions/TrackDesignAction.cpp +++ b/src/openrct2/actions/TrackDesignAction.cpp @@ -261,7 +261,7 @@ GameActionResult::Ptr TrackDesignAction::Execute() const ride->track_colour[i].supports = _td.track_support_colour[i]; } - for (int32_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { ride->vehicle_colours[i].Body = _td.vehicle_colours[i].body_colour; ride->vehicle_colours[i].Trim = _td.vehicle_colours[i].trim_colour; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 70fdf3d7bc..0a12558998 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -856,7 +856,7 @@ private: { dst->vehicles[i] = src->vehicles[i]; } - for (int32_t i = RCT1_MAX_TRAINS_PER_RIDE; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = RCT1_MAX_TRAINS_PER_RIDE; i <= MAX_VEHICLES_PER_RIDE; i++) { dst->vehicles[i] = SPRITE_INDEX_NULL; } diff --git a/src/openrct2/rct1/T4Importer.cpp b/src/openrct2/rct1/T4Importer.cpp index 094f0fe272..0589307788 100644 --- a/src/openrct2/rct1/T4Importer.cpp +++ b/src/openrct2/rct1/T4Importer.cpp @@ -211,7 +211,7 @@ private: } } // Set remaining vehicles to same colour as first vehicle - for (int32_t i = RCT1_MAX_TRAINS_PER_RIDE; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = RCT1_MAX_TRAINS_PER_RIDE; i <= MAX_VEHICLES_PER_RIDE; i++) { td->vehicle_colours[i] = td->vehicle_colours[0]; td->vehicle_additional_colour[i] = td->vehicle_additional_colour[0]; diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index 25dbb0c462..b6b2f53506 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -29,7 +29,6 @@ #define RCT12_PATROL_AREA_SIZE 128 #define RCT12_STAFF_TYPE_COUNT 4 #define RCT12_NUM_COLOUR_SCHEMES 4 -#define RCT12_MAX_VEHICLES_PER_RIDE 32 #define RCT12_MAX_VEHICLE_COLOURS 32 #define RCT12_SOUND_ID_NULL 0xFF diff --git a/src/openrct2/rct2/RCT2.h b/src/openrct2/rct2/RCT2.h index c26f52d091..14bd6c9419 100644 --- a/src/openrct2/rct2/RCT2.h +++ b/src/openrct2/rct2/RCT2.h @@ -19,7 +19,7 @@ #define RCT2_MAX_STAFF 200 #define RCT2_MAX_BANNERS_IN_PARK 250 -#define RCT2_MAX_VEHICLES_PER_RIDE 32 +#define RCT2_MAX_VEHICLES_PER_RIDE 31 #define RCT2_MAX_CARS_PER_TRAIN 32 #define RCT2_MAX_CATEGORIES_PER_RIDE 2 #define RCT2_MAX_RIDE_TYPES_PER_RIDE_ENTRY 3 @@ -85,9 +85,9 @@ struct rct2_ride LocationXY8 entrances[RCT12_MAX_STATIONS_PER_RIDE]; // 0x06A LocationXY8 exits[RCT12_MAX_STATIONS_PER_RIDE]; // 0x072 uint16_t last_peep_in_queue[RCT12_MAX_STATIONS_PER_RIDE]; // 0x07A - uint8_t pad_082[RCT12_MAX_STATIONS_PER_RIDE]; // 0x082, Used to be number of peeps in queue in RCT1, but this has moved. - uint16_t vehicles[RCT2_MAX_VEHICLES_PER_RIDE]; // 0x086, Points to the first car in the train - uint8_t depart_flags; // 0x0C6 + uint8_t pad_082[RCT12_MAX_STATIONS_PER_RIDE]; // 0x082, Used to be number of peeps in queue in RCT1, but this has moved. + uint16_t vehicles[RCT2_MAX_VEHICLES_PER_RIDE + 1]; // 0x086, Points to the first car in the train + uint8_t depart_flags; // 0x0C6 // Not sure if these should be uint or sint. uint8_t num_stations; // 0x0C7 diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 02cfb17c61..3d05900a22 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -569,7 +569,7 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src) dst->queue_length[i] = src->stations[i].QueueLength; } - for (uint8_t i = 0; i < RCT2_MAX_VEHICLES_PER_RIDE; i++) + for (uint8_t i = 0; i <= RCT2_MAX_VEHICLES_PER_RIDE; i++) { dst->vehicles[i] = src->vehicles[i]; } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 97199c8b2a..fab561ddfa 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -571,11 +571,11 @@ public: dst->stations[i].LastPeepInQueue = SPRITE_INDEX_NULL; } - for (int32_t i = 0; i < RCT2_MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i <= RCT2_MAX_VEHICLES_PER_RIDE; i++) { dst->vehicles[i] = src->vehicles[i]; } - for (int32_t i = RCT2_MAX_VEHICLES_PER_RIDE; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = RCT2_MAX_VEHICLES_PER_RIDE; i <= MAX_VEHICLES_PER_RIDE; i++) { dst->vehicles[i] = SPRITE_INDEX_NULL; } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c8bc435f6e..a8c21393fb 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1031,7 +1031,7 @@ static void ride_remove_vehicles(Ride* ride) ride->lifecycle_flags &= ~RIDE_LIFECYCLE_ON_TRACK; ride->lifecycle_flags &= ~(RIDE_LIFECYCLE_TEST_IN_PROGRESS | RIDE_LIFECYCLE_HAS_STALLED_VEHICLE); - for (size_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (size_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { uint16_t spriteIndex = ride->vehicles[i]; while (spriteIndex != SPRITE_INDEX_NULL) @@ -3109,10 +3109,7 @@ vehicle_colour ride_get_vehicle_colour(Ride* ride, int32_t vehicleIndex) vehicle_colour result; // Prevent indexing array out of bounds - if (vehicleIndex > 31) - { - vehicleIndex = 31; - } + vehicleIndex = std::min(vehicleIndex, MAX_CARS_PER_TRAIN); result.main = ride->vehicle_colours[vehicleIndex].Body; result.additional_1 = ride->vehicle_colours[vehicleIndex].Trim; @@ -4643,7 +4640,7 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int // Add train to ride vehicle list move_sprite_to_list((rct_sprite*)train.head, SPRITE_LIST_VEHICLE_HEAD); - for (int32_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { if (ride->vehicles[i] == SPRITE_INDEX_NULL) { @@ -6499,7 +6496,7 @@ void ride_update_vehicle_colours(Ride* ride) gfx_invalidate_screen(); } - for (int32_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { int32_t carIndex = 0; uint16_t spriteIndex = ride->vehicles[i]; @@ -7531,7 +7528,7 @@ void fix_invalid_vehicle_sprite_sizes() { for (const auto& ride : GetRideManager()) { - for (uint16_t j = 0; j < MAX_VEHICLES_PER_RIDE; j++) + for (uint16_t j = 0; j <= MAX_VEHICLES_PER_RIDE; j++) { uint16_t rideSpriteIndex = ride.vehicles[j]; while (rideSpriteIndex != SPRITE_INDEX_NULL) diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index d13a83c463..0aa284ab32 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -31,7 +31,7 @@ struct Staff; // The max number of different types of vehicle. // Examples of vehicles here are the locomotive, tender and carriage of the Miniature Railway. #define MAX_VEHICLES_PER_RIDE_ENTRY 4 -#define MAX_VEHICLES_PER_RIDE 32 +#define MAX_VEHICLES_PER_RIDE 31 #define RIDE_ENTRY_INDEX_NULL 255 #define NUM_COLOUR_SCHEMES 4 #define MAX_CATEGORIES_PER_RIDE 2 @@ -228,7 +228,7 @@ struct Ride std::string custom_name; uint16_t default_name_number; TileCoordsXY overall_view; - uint16_t vehicles[MAX_VEHICLES_PER_RIDE]; // Points to the first car in the train + uint16_t vehicles[MAX_VEHICLES_PER_RIDE + 1]; // Points to the first car in the train uint8_t depart_flags; uint8_t num_stations; uint8_t num_vehicles; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index eee7fbbba6..e8bce795d3 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -110,7 +110,7 @@ rct_string_id TrackDesign::CreateTrackDesign(const Ride& ride) ride_mode = ride.mode; colour_scheme = ride.colour_scheme_type & 3; - for (int32_t i = 0; i < RCT12_MAX_VEHICLES_PER_RIDE; i++) + for (int32_t i = 0; i < RCT2_MAX_CARS_PER_TRAIN; i++) { vehicle_colours[i].body_colour = ride.vehicle_colours[i].Body; vehicle_colours[i].trim_colour = ride.vehicle_colours[i].Trim;