From caad293b2db92076dfa0c21be010d3cf94a93e1c Mon Sep 17 00:00:00 2001 From: Sjoerd de Bruin Date: Tue, 22 Sep 2026 22:19:40 +0200 Subject: [PATCH] Fix #26222: "Follow this on Main View" follows invisible first car instead of the actual car (#27068) Add getFirstVisibleCar(), which walks a train from the head to the first car with CarEntry::isVisible(). The main-view follow used the train head directly, and the ride window's own viewport focus skipped exactly one car when rideEntry->TabCar != 0, which names the car drawn on the vehicle tab rather than the first visible one. Both now use the helper. --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Ride.cpp | 42 +++++++++++++++++--------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index b63db16076..64f0726372 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -17,6 +17,7 @@ - Fix: [#21576] RCT1 Wooden wild mouse track designs with 2-car trains are not imported correctly. - Fix: [#22298] [Plugin] Crash when changing a large scenery element whose object is not loaded. - Fix: [#24457] Yellow is always rendered as third remap in Ride window. +- Fix: [#26222] ‘Follow this on Main View’ follows the invisible first car on ride types that have one, making the view turn too early. - Fix: [#26754] Switching window tabs by touch could crash the game on some Linux builds. - Fix: [#26998] Crash when generating a `Simplex Height Map` with a higher width than height. - Fix: [#27052] Unnamed rides in RCT2 base and Wacky Worlds scenarios have hardcoded English names. diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 333fff4e50..7d92d3e093 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -764,6 +764,24 @@ namespace OpenRCT2::Ui::Windows return selectedCarIndex; } + static Vehicle* getFirstVisibleCar(EntityId trainHead) + { + auto& entities = getGameState().entities; + auto* head = entities.getEntity(trainHead); + + auto* vehicle = head; + for (auto remaining = Limits::kMaxCarsPerTrain; vehicle != nullptr && remaining > 0; remaining--) + { + const auto* carEntry = vehicle->Entry(); + if (carEntry == nullptr || carEntry->isVisible()) + return vehicle; + + vehicle = entities.getEntity(vehicle->next_vehicle_on_train); + } + + return head; + } + public: RideWindow(const Ride& ride) { @@ -1551,23 +1569,10 @@ namespace OpenRCT2::Ui::Windows if (viewSelectionIndex >= 0 && viewSelectionIndex < ride->numTrains && ride->flags.has(RideFlag::onTrack)) { - auto vehId = ride->vehicles[viewSelectionIndex]; - const auto* rideEntry = ride->getRideEntry(); - if (rideEntry != nullptr && rideEntry->TabCar != 0) + const auto* vehicle = getFirstVisibleCar(ride->vehicles[viewSelectionIndex]); + if (vehicle != nullptr) { - Vehicle* vehicle = getGameState().entities.getEntity(vehId); - if (vehicle == nullptr) - { - vehId = EntityId::GetNull(); - } - else if (!vehicle->next_vehicle_on_train.IsNull()) - { - vehId = vehicle->next_vehicle_on_train; - } - } - if (!vehId.IsNull()) - { - newFocus = Focus(vehId); + newFocus = Focus(vehicle->id); } } else if (viewSelectionIndex >= ride->numTrains && viewSelectionIndex < (ride->numTrains + ride->numStations)) @@ -2035,12 +2040,11 @@ namespace OpenRCT2::Ui::Windows { if (_viewIndex <= ride->numTrains) { - Vehicle* vehicle = getGameState().entities.getEntity(ride->vehicles[_viewIndex - 1]); + const auto* vehicle = getFirstVisibleCar(ride->vehicles[_viewIndex - 1]); if (vehicle != nullptr) { - auto headVehicleSpriteIndex = vehicle->id; WindowBase* w_main = WindowGetMain(); - WindowFollowSprite(*w_main, headVehicleSpriteIndex); + WindowFollowSprite(*w_main, vehicle->id); } } }