Skip to content

Commit

Permalink
Reduce duplicate code
Browse files Browse the repository at this point in the history
Fix two cases of duplicated code
  • Loading branch information
jensj12 authored and Gymnasiast committed Feb 12, 2018
1 parent c8b5cbb commit 0247435
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/openrct2/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/openrct2/management/Finance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 10 additions & 14 deletions src/openrct2/ride/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/ride/Ride.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0247435

Please sign in to comment.