Skip to content

Commit

Permalink
Improve #9987: Minimum load rounding (#9987)
Browse files Browse the repository at this point in the history
Refactor code for vehicles waiting for a specific load level.
Original code rounded the target load down, changed to round up.
  • Loading branch information
aw20368 authored and Gymnasiast committed Sep 28, 2019
1 parent b82d1bb commit ff1698b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 46 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Expand Up @@ -24,6 +24,7 @@
- Fix: [#9970] Wait for quarter load fails.
- Fix: [#10017] Ghost elements influencing ride excitement.
- Improved: [#9466] Add the rain weather effect to the OpenGL renderer.
- Improved: [#9987] Minimum load rounding.

0.2.3 (2019-07-10)
------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/network/Network.cpp
Expand Up @@ -34,7 +34,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 "15"
#define NETWORK_STREAM_VERSION "16"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION

static Peep* _pickup_peep = nullptr;
Expand Down
54 changes: 9 additions & 45 deletions src/openrct2/ride/Vehicle.cpp
Expand Up @@ -2363,60 +2363,24 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle)
return;
}

// any load: load=4 , full: load=3 , 3/4s: load=2 , half: load=1 , quarter: load=0
uint8_t load = ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD_MASK;
if (load == 3)
{
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

uint8_t three_quater_seats = (3 * num_seats_on_train) / 4;
if (three_quater_seats != 0 && num_peeps_on_train >= three_quater_seats)
{
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART;
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}
// We want to wait for ceiling((load+1)/4 * num_seats_on_train) peeps, the +3 below is used instead of
// ceil() to prevent issues on different cpus/platforms with floats. Note that vanilla RCT1/2 rounded
// down here; our change reflects the expected behaviour for waiting for a minimum load target (see #9987)
uint8_t peepTarget = ((load + 1) * num_seats_on_train + 3) / 4;

if (load == 2)
{
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}
if (load == 4) // take care of "any load" special case
peepTarget = 1;

if (num_seats_on_train / 2 != 0 && num_peeps_on_train >= num_seats_on_train / 2)
{
if (num_peeps_on_train >= peepTarget)
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART;
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

if (load == 1)
{
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

if (num_seats_on_train / 4 != 0 && num_peeps_on_train >= num_seats_on_train / 4)
{
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART;
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

if (load == 0)
{
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

if (num_peeps_on_train != 0)
{
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART;
}
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
}

vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART;
train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train);
return;
Expand Down

0 comments on commit ff1698b

Please sign in to comment.