From eb5fe27495caedf99fd9d7bf6eb9704c36b89675 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Fri, 20 Jan 2023 13:24:16 +0100 Subject: [PATCH] Fix #474: Mini Golf window allows selecting nonexistent players --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Ride.cpp | 49 +++++++++++++++++++++--------- src/openrct2/object/RideObject.cpp | 1 + src/openrct2/ride/Ride.h | 1 + 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 33b1aa6835..f5b30ce64f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -14,6 +14,7 @@ - Improved: [#19044] Added special thanks to RMC and Wiegand to the About page. - Change: [#19018] Renamed actions to fit the naming scheme. - Change: [#19091] [Plugin] Add game action information to callback arguments of custom actions. +- Fix: [#474] Mini golf window shows more players than there actually are (original bug). - Fix: [#18467] “Selected only” Object Selection filter is active in Track Designs Manager, and cannot be toggled. - Fix: [#18905] Ride Construction window theme is not applied correctly. - Fix: [#18911] Mini Golf station does not draw correctly from all angles. diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 4219018a84..cd30ed58b5 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1724,6 +1724,33 @@ static void WindowRideMainResize(rct_window* w) WindowRideInitViewport(w); } +static size_t GetNumPeepsInTrain(const Ride& ride, int32_t trainIndex) +{ + auto numPeepsInTrain = 0; + const auto* vehicle = TryGetVehicle(ride.vehicles[trainIndex]); + while (vehicle != nullptr) + { + numPeepsInTrain += vehicle->num_peeps; + vehicle = TryGetVehicle(vehicle->next_vehicle_on_train); + } + return numPeepsInTrain; +} + +static bool TrainMustBeHidden(const Ride& ride, int32_t trainIndex) +{ + if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) + return true; + + const auto* rideEntry = ride.GetRideEntry(); + if (rideEntry == nullptr) + return false; + + if (!(rideEntry->flags & RIDE_ENTRY_FLAG_HIDE_EMPTY_TRAINS)) + return false; + + return GetNumPeepsInTrain(ride, trainIndex) == 0; +} + /** * * rct2: 0x006AF825 @@ -1735,8 +1762,10 @@ static void WindowRideShowViewDropdown(rct_window* w, Widget* widget) if (ride == nullptr) return; + const auto& rtd = ride->GetRideTypeDescriptor(); + int32_t numItems = 1; - if (!ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) + if (!rtd.HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) { numItems += ride->num_stations; numItems += ride->NumTrains; @@ -1751,14 +1780,16 @@ static void WindowRideShowViewDropdown(rct_window* w, Widget* widget) gDropdownItems[0].Args = STR_OVERALL_VIEW; int32_t currentItem = 1; - const auto& rtd = ride->GetRideTypeDescriptor(); - // Vehicles int32_t name = GetRideComponentName(rtd.NameConvention.vehicle).number; - for (int32_t i = 1; i <= ride->NumTrains; i++) + for (int32_t i = 0; i < ride->NumTrains; i++) { gDropdownItems[currentItem].Format = STR_DROPDOWN_MENU_LABEL; gDropdownItems[currentItem].Args = name | (currentItem << 16); + if (TrainMustBeHidden(*ride, i)) + { + Dropdown::SetDisabled(currentItem, true); + } currentItem++; } @@ -1771,16 +1802,6 @@ static void WindowRideShowViewDropdown(rct_window* w, Widget* widget) currentItem++; } - // Set highlighted item - if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) - { - for (int32_t i = 0; i < ride->NumTrains; i++) - { - // The +1 is to skip 'Overall view' - Dropdown::SetDisabled(i + 1, true); - } - } - // Set checked item Dropdown::SetChecked(w->ride.view, true); } diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 7444ca71a7..fda94fddde 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -561,6 +561,7 @@ void RideObject::ReadJson(IReadObjectContext* context, json_t& root) { "noCollisionCrashes", RIDE_ENTRY_FLAG_DISABLE_COLLISION_CRASHES }, { "disablePainting", RIDE_ENTRY_FLAG_DISABLE_COLOUR_TAB }, { "riderControlsSpeed", RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED }, + { "hideEmptyTrains", RIDE_ENTRY_FLAG_HIDE_EMPTY_TRAINS }, }); } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 3e65b176ff..0d836d3311 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -492,6 +492,7 @@ enum // Must be set with swing mode 1 as well. RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_2 = 1 << 20, RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED = 1 << 21, + RIDE_ENTRY_FLAG_HIDE_EMPTY_TRAINS = 1 << 22, }; enum