From 02474353e380f5a1a85e1bc2071f5f60a4108e79 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Sun, 11 Feb 2018 16:50:44 +0100 Subject: [PATCH] Reduce duplicate code Fix two cases of duplicated code --- src/openrct2/Cheats.cpp | 5 +---- src/openrct2/management/Finance.cpp | 3 +-- src/openrct2/ride/Ride.cpp | 24 ++++++++++-------------- src/openrct2/ride/Ride.h | 1 + 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index d092201587..4f0ddf24d8 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -176,10 +176,7 @@ static void cheat_renew_rides() FOR_ALL_RIDES(i, ride) { - // Set build date to current date (so the ride is brand new) - ride->build_date = gDateMonthsElapsed; - // Set reliability to 100 - ride->reliability = RIDE_INITIAL_RELIABILITY; + ride_renew(ride); } window_invalidate_by_class(WC_RIDE); } diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 3dab1a25d1..72b9dfd5c7 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -163,8 +163,7 @@ void finance_pay_ride_upkeep() { if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)) { - ride->build_date = gDateMonthsElapsed; - ride->reliability = RIDE_INITIAL_RELIABILITY; + ride_renew(ride); } if (ride->status != RIDE_STATUS_CLOSED && !(gParkFlags & PARK_FLAGS_NO_MONEY)) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 778d1093fc..a1007a3095 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6947,20 +6947,9 @@ static void ride_update_vehicle_colours(sint32 rideIndex) */ void ride_entry_get_train_layout(sint32 rideEntryIndex, sint32 numCarsPerTrain, uint8 *trainLayout) { - rct_ride_entry *rideEntry = get_ride_entry(rideEntryIndex); - - for (sint32 i = 0; i < numCarsPerTrain; i++) { - uint8 vehicleType = rideEntry->default_vehicle; - if (i == 0 && rideEntry->front_vehicle != 255) { - vehicleType = rideEntry->front_vehicle; - } else if (i == 1 && rideEntry->second_vehicle != 255) { - vehicleType = rideEntry->second_vehicle; - } else if (i == 2 && rideEntry->third_vehicle != 255) { - vehicleType = rideEntry->third_vehicle; - } else if (i == numCarsPerTrain - 1 && rideEntry->rear_vehicle != 255) { - vehicleType = rideEntry->rear_vehicle; - } - trainLayout[i] = vehicleType; + for (sint32 i = 0; i < numCarsPerTrain; i++) + { + trainLayout[i] = ride_entry_get_vehicle_at_position(rideEntryIndex, numCarsPerTrain, i); } } @@ -7853,6 +7842,13 @@ void ride_delete(uint8 rideIndex) ride->type = RIDE_TYPE_NULL; } +void ride_renew(Ride * ride) +{ + // Set build date to current date (so the ride is brand new) + ride->build_date = gDateMonthsElapsed; + ride->reliability = RIDE_INITIAL_RELIABILITY; +} + static bool ride_is_ride(Ride * ride) { switch (ride->type) { diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 1821e54dc3..8c4d7ddb97 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1172,6 +1172,7 @@ void window_ride_construction_do_entrance_exit_check(); void game_command_callback_place_ride_entrance_or_exit(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp); void ride_delete(uint8 rideIndex); +void ride_renew(Ride * ride); money16 ride_get_price(Ride * ride); rct_tile_element *get_station_platform(sint32 x, sint32 y, sint32 z, sint32 z_tolerance);