diff --git a/src/ride/ride.c b/src/ride/ride.c index 964a60a9b6..2a63247381 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4571,12 +4571,9 @@ train_ref vehicle_create_train(int rideIndex, int x, int y, int z, int vehicleIn { rct_ride *ride = get_ride(rideIndex); - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN]; - ride_entry_get_train_layout(ride->subtype, ride->num_cars_per_train, trainLayout); - train_ref train = { NULL, NULL }; for (int carIndex = 0; carIndex < ride->num_cars_per_train; carIndex++) { - rct_vehicle *car = vehicle_create_car(rideIndex, trainLayout[carIndex], carIndex, vehicleIndex, x, y, z, remainingDistance, mapElement); + rct_vehicle *car = vehicle_create_car(rideIndex, ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,carIndex), carIndex, vehicleIndex, x, y, z, remainingDistance, mapElement); if (carIndex == 0) { train.head = car; } else { @@ -7363,6 +7360,22 @@ void ride_entry_get_train_layout(int rideEntryIndex, int numCarsPerTrain, uint8 } } +uint8 ride_entry_get_vehicle_at_position(int rideEntryIndex,int numCarsPerTrain,int position) +{ +rct_ride_entry *rideEntry = get_ride_entry(rideEntryIndex); + if (position == 0 && rideEntry->front_vehicle != 255) { + return rideEntry->front_vehicle; + } else if (position == 1 && rideEntry->second_vehicle != 255) { + return rideEntry->second_vehicle; + } else if (position == 2 && rideEntry->third_vehicle != 255) { + return rideEntry->third_vehicle; + } else if (position == numCarsPerTrain - 1 && rideEntry->rear_vehicle != 255) { + return rideEntry->rear_vehicle; + } else { + return rideEntry->default_vehicle; + } +} + int ride_get_smallest_station_length(rct_ride *ride) { uint32 result = -1; @@ -7437,7 +7450,7 @@ void ride_update_max_vehicles(int rideIndex) rct_ride *ride; rct_ride_entry *rideEntry; rct_ride_entry_vehicle *vehicleEntry; - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN], numCarsPerTrain, numVehicles; + uint8 numCarsPerTrain, numVehicles; int trainLength, maxNumTrains; ride = get_ride(rideIndex); @@ -7459,11 +7472,10 @@ void ride_update_max_vehicles(int rideIndex) int maxFriction = RideData5[ride->type].max_friction << 8; int maxCarsPerTrain = 1; for (int numCars = rideEntry->max_cars_in_train; numCars > 0; numCars--) { - ride_entry_get_train_layout(ride->subtype, numCars, trainLayout); trainLength = 0; int totalFriction = 0; for (int i = 0; i < numCars; i++) { - vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; + vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,numCars,i)]; trainLength += vehicleEntry->spacing; totalFriction += vehicleEntry->car_friction; } @@ -7494,10 +7506,9 @@ void ride_update_max_vehicles(int rideIndex) break; default: // Calculate maximum number of trains - ride_entry_get_train_layout(ride->subtype, newCarsPerTrain, trainLayout); trainLength = 0; for (int i = 0; i < newCarsPerTrain; i++) { - vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; + vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,newCarsPerTrain,i)]; trainLength += vehicleEntry->spacing; } @@ -7517,13 +7528,12 @@ void ride_update_max_vehicles(int rideIndex) ) { maxNumTrains = min(maxNumTrains, 31); } else { - ride_entry_get_train_layout(ride->subtype, newCarsPerTrain, trainLayout); - vehicleEntry = &rideEntry->vehicles[trainLayout[0]]; + vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,newCarsPerTrain,0)]; int speed = vehicleEntry->powered_max_speed; int totalSpacing = 0; for (int i = 0; i < newCarsPerTrain; i++) { - vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; + vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,newCarsPerTrain,i)]; totalSpacing += vehicleEntry->spacing; } diff --git a/src/ride/ride.h b/src/ride/ride.h index 6933e77b4b..16b842b53f 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -1038,6 +1038,7 @@ bool ride_are_all_possible_entrances_and_exits_built(rct_ride *ride); void ride_fix_breakdown(int rideIndex, int reliabilityIncreaseFactor); void ride_entry_get_train_layout(int rideEntryIndex, int numCarsPerTrain, uint8 *trainLayout); +uint8 ride_entry_get_vehicle_at_position(int rideEntryIndex, int numCarsPerTrain, int position); void ride_update_max_vehicles(int rideIndex); void ride_set_ride_entry(int rideIndex, int rideEntry); diff --git a/src/windows/ride.c b/src/windows/ride.c index 891b36b085..b6045e68bd 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -1047,10 +1047,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w) y = (widget->bottom - widget->top) - 12; ride = get_ride(w->number); - - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN]; - ride_entry_get_train_layout(ride->subtype, ride->num_cars_per_train, trainLayout); - + rideEntry = get_ride_entry_by_ride(ride); if (rideEntry->flags & RIDE_ENTRY_FLAG_0) { clipDPI.zoom_level = 1; @@ -1062,7 +1059,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w) clipDPI.y *= 2; } - rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[rideEntry->tab_vehicle]]; + rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,rideEntry->tab_vehicle)]; height += rideVehicleEntry->tab_height; vehicleColour = ride_get_vehicle_colour(ride, 0); @@ -2702,14 +2699,11 @@ static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dp // Background gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width, dpi->y + dpi->height, 12); - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN]; - ride_entry_get_train_layout(ride->subtype, ride->num_cars_per_train, trainLayout); - widget = &window_ride_vehicle_widgets[WIDX_VEHICLE_TRAINS_PREVIEW]; startX = max(2, ((widget->right - widget->left) - ((ride->num_vehicles - 1) * 36)) / 2 - 25); startY = widget->bottom - widget->top - 4; - rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[0]]; + rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,0)]; startY += rideVehicleEntry->tab_height; // For each train @@ -2720,7 +2714,7 @@ static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dp // For each car in train for (j = 0; j < ride->num_cars_per_train; j++) { - rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[j]]; + rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,j)]; x += rideVehicleEntry->spacing / 17432; y -= (rideVehicleEntry->spacing / 2) / 17432; @@ -4214,12 +4208,9 @@ static void window_ride_colour_invalidate(rct_window *w) window_ride_colour_widgets[WIDX_VEHICLE_MAIN_COLOUR].type = WWT_COLOURBTN; window_ride_colour_widgets[WIDX_VEHICLE_MAIN_COLOUR].image = window_ride_get_colour_button_image(vehicleColour.main); - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN]; - ride_entry_get_train_layout(ride->subtype, ride->num_cars_per_train, trainLayout); - uint32 colourFlags = 0; for (int i = 0; i < ride->num_cars_per_train; i++) { - uint8 vehicleTypeIndex = trainLayout[i]; + uint8 vehicleTypeIndex = ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,i); colourFlags |= rideEntry->vehicles[vehicleTypeIndex].flags_b; colourFlags = ror32(colourFlags, 16); @@ -4403,14 +4394,11 @@ static void window_ride_colour_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi x = (vehiclePreviewWidget->right - vehiclePreviewWidget->left) / 2; y = vehiclePreviewWidget->bottom - vehiclePreviewWidget->top - 15; - uint8 trainLayout[RIDE_MAX_CARS_PER_TRAIN]; - ride_entry_get_train_layout(ride->subtype, ride->num_cars_per_train, trainLayout); - // ? trainCarIndex = (ride->colour_scheme_type & 3) == RIDE_COLOUR_SCHEME_DIFFERENT_PER_CAR ? w->var_48C : rideEntry->tab_vehicle; - rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[trainCarIndex]]; + rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype,ride->num_cars_per_train,trainCarIndex)]; y += rideVehicleEntry->tab_height;