From d42e67ddfecd442b650a1b35c41b7e8ee44a80b0 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Fri, 1 Jul 2022 23:26:40 +0200 Subject: [PATCH] Reformat the ifs, remove unnecessary parameter --- src/openrct2/ride/Vehicle.cpp | 43 +++++++++++++++++++++-------------- src/openrct2/ride/Vehicle.h | 2 +- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 06847b9a1f..40bba46aa4 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3011,25 +3011,34 @@ void Vehicle::TestReset() test_reset(*curRide, current_station); } -bool Vehicle::CurrentTowerElementIsTop(RideId currentRideId) +// The result of this function is used to decide whether a vehicle on a tower ride should go further up or not. +// Therefore, it will return true if anything is amiss. +bool Vehicle::CurrentTowerElementIsTop() { TileElement* tileElement = map_get_track_element_at_of_type(TrackLocation, GetTrackType()); - if (tileElement != nullptr) + if (tileElement == nullptr) + return true; + + while (!tileElement->IsLastForTile()) { - while (!tileElement->IsLastForTile()) - { - tileElement++; - if (tileElement->GetType() == TileElementType::Track && !tileElement->IsGhost()) - { - const auto* trackElement = tileElement->AsTrack(); - if (trackElement->GetRideIndex() == currentRideId - && trackElement->GetTrackType() == TrackElemType::TowerSection) - { - return false; - } - } - } + tileElement++; + + if (tileElement->IsGhost()) + continue; + + if (tileElement->GetType() != TileElementType::Track) + continue; + + const auto* trackElement = tileElement->AsTrack(); + if (trackElement->GetRideIndex() != ride) + continue; + + if (trackElement->GetTrackType() != TrackElemType::TowerSection) + continue; + + return false; } + return true; } @@ -3306,7 +3315,7 @@ void Vehicle::UpdateDeparting() } } - if (!CurrentTowerElementIsTop(ride)) + if (!CurrentTowerElementIsTop()) { if (curRide->mode == RideMode::FreefallDrop) Invalidate(); @@ -3697,7 +3706,7 @@ void Vehicle::UpdateTravelling() } else { - if (CurrentTowerElementIsTop(ride)) + if (CurrentTowerElementIsTop()) { velocity = 0; sub_state = 2; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 4f432aed32..8d144f5f15 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -329,7 +329,7 @@ private: void UpdateAnimationAnimalFlying(); void UpdateAdditionalAnimation(); void CheckIfMissing(); - bool CurrentTowerElementIsTop(RideId currentRideId); + bool CurrentTowerElementIsTop(); bool UpdateTrackMotionForwards(CarEntry* vehicleEntry, Ride* curRide, rct_ride_entry* rideEntry); bool UpdateTrackMotionBackwards(CarEntry* vehicleEntry, Ride* curRide, rct_ride_entry* rideEntry); int32_t UpdateTrackMotionPoweredRideAcceleration(CarEntry* vehicleEntry, uint32_t totalMass, const int32_t curAcceleration);