From ff1698bcb9230c1bfd3ff87fa74ef0a057c35e17 Mon Sep 17 00:00:00 2001 From: aw20368 Date: Sat, 28 Sep 2019 14:51:13 -0400 Subject: [PATCH] Improve #9987: Minimum load rounding (#9987) Refactor code for vehicles waiting for a specific load level. Original code rounded the target load down, changed to round up. --- distribution/changelog.txt | 1 + src/openrct2/network/Network.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 58 ++++++-------------------------- 3 files changed, 13 insertions(+), 48 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f3b0858bf1..9ea2f23ba9 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -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) ------------------------------------------------------------------------ diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 38539574e3..8176696298 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -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; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 990c3c3430..14c87a4280 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -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) - { + // 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 == 4) // take care of "any load" special case + peepTarget = 1; + + 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 == 2) - { - train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); - return; - } - - if (num_seats_on_train / 2 != 0 && num_peeps_on_train >= num_seats_on_train / 2) - { - 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;