diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f5aa319539..0a9f05e8ed 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -9226,6 +9226,83 @@ static constexpr int32_t GetAccelerationDecrease2(const int32_t velocity, const } } +int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const rct_ride_entry_vehicle& vehicleEntry) +{ + int32_t sumAcceleration = 0; + int32_t numVehicles = 0; + uint16_t totalMass = 0; + + for (Vehicle* vehicle = this; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) + { + numVehicles++; + totalMass += vehicle->mass; + sumAcceleration += vehicle->acceleration; + } + + int32_t newAcceleration = ((sumAcceleration / numVehicles) * 21) >> 9; + newAcceleration -= velocity >> 12; + newAcceleration -= GetAccelerationDecrease2(velocity, totalMass); + + if (!(vehicleEntry.flags & VEHICLE_ENTRY_FLAG_POWERED)) + { + return newAcceleration; + } + if (vehicleEntry.flags & VEHICLE_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY) + { + if (speed * 0x4000 < velocity) + { + return newAcceleration; + } + } + { + int32_t poweredAcceleration = speed << 14; + int32_t quarterForce = (speed * totalMass) >> 2; + if (HasUpdateFlag(VEHICLE_UPDATE_FLAG_REVERSING_SHUTTLE)) + { + poweredAcceleration = -poweredAcceleration; + } + poweredAcceleration -= velocity; + poweredAcceleration *= powered_acceleration << 1; + if (quarterForce != 0) + poweredAcceleration /= quarterForce; + + if (vehicleEntry.flags & VEHICLE_ENTRY_FLAG_WATER_RIDE) + { + if (poweredAcceleration < 0) + { + poweredAcceleration >>= 4; + } + + if (vehicleEntry.flags & VEHICLE_ENTRY_FLAG_SPINNING) + { + spin_speed = std::clamp(spin_speed, VEHICLE_MIN_SPIN_SPEED_WATER_RIDE, VEHICLE_MAX_SPIN_SPEED_WATER_RIDE); + } + + if (Pitch != 0) + { + poweredAcceleration = std::max(0, poweredAcceleration); + if (vehicleEntry.flags & VEHICLE_ENTRY_FLAG_SPINNING) + { + if (Pitch == 2) + { + spin_speed = 0; + } + } + newAcceleration += poweredAcceleration; + return newAcceleration; + } + } + + if (abs(velocity) > 0x10000) + { + newAcceleration = 0; + } + newAcceleration += poweredAcceleration; + } + + return newAcceleration; +} + int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation) { auto curRide = GetRide(); @@ -9269,79 +9346,7 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation) } } - int32_t sumAcceleration = 0; - int32_t numVehicles = 0; - uint16_t totalMass = 0; - - for (Vehicle* vehicle = this; vehicle != nullptr; vehicle = GetEntity(vehicle->next_vehicle_on_train)) - { - numVehicles++; - totalMass += vehicle->mass; - sumAcceleration += vehicle->acceleration; - } - - int32_t newAcceleration = ((sumAcceleration / numVehicles) * 21) >> 9; - newAcceleration -= velocity >> 12; - newAcceleration -= GetAccelerationDecrease2(velocity, totalMass); - - if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED)) - { - goto loc_6DD069; - } - if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY) - { - if (speed * 0x4000 < velocity) - { - goto loc_6DD069; - } - } - { - int32_t poweredAcceleration = speed << 14; - int32_t quarterForce = (speed * totalMass) >> 2; - if (HasUpdateFlag(VEHICLE_UPDATE_FLAG_REVERSING_SHUTTLE)) - { - poweredAcceleration = -poweredAcceleration; - } - poweredAcceleration -= velocity; - poweredAcceleration *= powered_acceleration << 1; - if (quarterForce != 0) - poweredAcceleration /= quarterForce; - - if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE) - { - if (poweredAcceleration < 0) - { - poweredAcceleration >>= 4; - } - - if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) - { - spin_speed = std::clamp(spin_speed, VEHICLE_MIN_SPIN_SPEED_WATER_RIDE, VEHICLE_MAX_SPIN_SPEED_WATER_RIDE); - } - - if (Pitch != 0) - { - poweredAcceleration = std::max(0, poweredAcceleration); - if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) - { - if (Pitch == 2) - { - spin_speed = 0; - } - } - newAcceleration += poweredAcceleration; - goto loc_6DD069; - } - } - - if (abs(velocity) > 0x10000) - { - newAcceleration = 0; - } - newAcceleration += poweredAcceleration; - } -loc_6DD069: - acceleration = newAcceleration; + acceleration = UpdateTrackMotionMiniGolfCalculateAcceleration(*vehicleEntry); if (outStation != nullptr) *outStation = _vehicleStationIndex; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index b513184235..d9fa5b711e 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -356,6 +356,7 @@ private: void KillAllPassengersInTrain(); void KillPassengers(Ride* curRide); void TrainReadyToDepart(uint8_t num_peeps_on_train, uint8_t num_used_seats); + int32_t UpdateTrackMotionMiniGolfCalculateAcceleration(const rct_ride_entry_vehicle& vehicleEntry); int32_t UpdateTrackMotionMiniGolf(int32_t* outStation); void UpdateTrackMotionMiniGolfVehicle(Ride* curRide, rct_ride_entry* rideEntry, rct_ride_entry_vehicle* vehicleEntry); bool UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* curRide, rct_ride_entry* rideEntry);