diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7c30157c8d..24ccefca8b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7604,6 +7604,183 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c } } +Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide) +{ + if (var_D3 != 0) + { + var_D3--; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + + if (mini_golf_flags & MiniGolfFlag::Flag2) + { + uint8_t nextFrame = animation_frame + 1; + if (nextFrame < MiniGolfPeepAnimationLengths[EnumValue(mini_golf_current_animation)]) + { + animation_frame = nextFrame; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + mini_golf_flags &= ~MiniGolfFlag::Flag2; + } + + if (mini_golf_flags & MiniGolfFlag::Flag0) + { + auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; + Vehicle* vEDI = GetEntity(vehicleIdx); + if (vEDI == nullptr) + { + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag0) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + if (vEDI->var_D3 != 0) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag0; + mini_golf_flags &= ~MiniGolfFlag::Flag0; + } + + if (mini_golf_flags & MiniGolfFlag::Flag1) + { + auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; + Vehicle* vEDI = GetEntity(vehicleIdx); + if (vEDI == nullptr) + { + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag1) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + if (vEDI->var_D3 != 0) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag1; + mini_golf_flags &= ~MiniGolfFlag::Flag1; + } + + if (mini_golf_flags & MiniGolfFlag::Flag3) + { + Vehicle* vEDI = this; + + for (;;) + { + vEDI = GetEntity(vEDI->prev_vehicle_on_ride); + if (vEDI == this || vEDI == nullptr) + { + break; + } + if (vEDI->IsHead()) + continue; + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag4)) + continue; + if (vEDI->TrackLocation != TrackLocation) + continue; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + + mini_golf_flags |= MiniGolfFlag::Flag4; + mini_golf_flags &= ~MiniGolfFlag::Flag3; + } + + return Vehicle::UpdateMiniGolfFlagsStatus::carryOn; +} + /** * rct2: 0x006DC3A7 * @@ -7637,177 +7814,15 @@ void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideOb goto Loc6DCA9A; Loc6DC462: - if (var_D3 != 0) +{ + Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart; + while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart) { - var_D3--; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - - if (mini_golf_flags & MiniGolfFlag::Flag2) - { - uint8_t nextFrame = animation_frame + 1; - if (nextFrame < MiniGolfPeepAnimationLengths[EnumValue(mini_golf_current_animation)]) - { - animation_frame = nextFrame; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - mini_golf_flags &= ~MiniGolfFlag::Flag2; - } - - if (mini_golf_flags & MiniGolfFlag::Flag0) - { - auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); - if (vEDI == nullptr) - { - return; - } - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag0) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - if (vEDI->var_D3 != 0) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag0; - mini_golf_flags &= ~MiniGolfFlag::Flag0; - } - - if (mini_golf_flags & MiniGolfFlag::Flag1) - { - auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); - if (vEDI == nullptr) - { - return; - } - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag1) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - if (vEDI->var_D3 != 0) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag1; - mini_golf_flags &= ~MiniGolfFlag::Flag1; - } - - if (mini_golf_flags & MiniGolfFlag::Flag3) - { - Vehicle* vEDI = this; - - for (;;) - { - vEDI = GetEntity(vEDI->prev_vehicle_on_ride); - if (vEDI == this || vEDI == nullptr) - { - break; - } - if (vEDI->IsHead()) - continue; - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag4)) - continue; - if (vEDI->TrackLocation != TrackLocation) - continue; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - - mini_golf_flags |= MiniGolfFlag::Flag4; - mini_golf_flags &= ~MiniGolfFlag::Flag3; + flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide); } + if (flagsStatus == UpdateMiniGolfFlagsStatus::stop) + return; +}; { uint16_t trackTotalProgress = GetTrackProgress(); @@ -7824,10 +7839,6 @@ Loc6DC462: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - if (remaining_distance >= 0) - { - Loc6DCDE4(curRide); - } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DCA9A; @@ -7837,7 +7848,7 @@ Loc6DC462: direction = outDirection; } - if (PitchAndRollStart(HasFlag(VehicleFlags::CarIsInverted), tileElement) != TrackPitchAndRollEnd(GetTrackType())) + if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; @@ -7851,18 +7862,6 @@ Loc6DC462: goto Loc6DCA9A; } - { - int32_t rideType = ::GetRide(tileElement->AsTrack()->GetRideIndex())->type; - ClearFlag(VehicleFlags::CarIsInverted); - if (GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::hasInvertedVariant)) - { - if (tileElement->AsTrack()->IsInverted()) - { - SetFlag(VehicleFlags::CarIsInverted); - } - } - } - TrackLocation = trackPos; if (!IsHead()) @@ -8004,16 +8003,6 @@ Loc6DC462: bank_rotation = moveInfo->bank_rotation; Pitch = moveInfo->Pitch; - if (rideEntry.Cars[0].flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) - { - if (Pitch != 0) - { - SwingSprite = 0; - SwingPosition = 0; - SwingSpeed = 0; - } - } - if (this == _vehicleFrontVehicle) { if (_vehicleVelocityF64E08 >= 0) @@ -8042,10 +8031,6 @@ Loc6DCA9A: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - if (remaining_distance >= 0) - { - Loc6DCDE4(curRide); - } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DCA9A; @@ -8055,33 +8040,16 @@ Loc6DCA9A: tileElement = trackBeginEnd.begin_element; } - if (PitchAndRollStart(HasFlag(VehicleFlags::CarIsInverted), tileElement) != TrackPitchAndRollEnd(GetTrackType())) + if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DC462; } - { - int32_t rideType = ::GetRide(tileElement->AsTrack()->GetRideIndex())->type; - ClearFlag(VehicleFlags::CarIsInverted); - if (GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::hasInvertedVariant)) - { - if (tileElement->AsTrack()->IsInverted()) - { - SetFlag(VehicleFlags::CarIsInverted); - } - } - } - TrackLocation = trackPos; if (HasFlag(VehicleFlags::OnLiftHill)) @@ -8123,16 +8091,6 @@ Loc6DCA9A: bank_rotation = moveInfo->bank_rotation; Pitch = moveInfo->Pitch; - if (rideEntry.Cars[0].flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) - { - if (Pitch != 0) - { - SwingSprite = 0; - SwingPosition = 0; - SwingSpeed = 0; - } - } - if (this == _vehicleFrontVehicle) { if (_vehicleVelocityF64E08 >= 0) @@ -8151,20 +8109,12 @@ Loc6DCA9A: Vehicle* vEDI = gCurrentVehicle; if (abs(vEDI->velocity - vEBP->velocity) > 14.0_mph) { - if (!(carEntry->flags & CAR_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION)) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; - } + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } vEDI->velocity = vEBP->velocity >> 1; vEBP->velocity = vEDI->velocity >> 1; } _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DC462; @@ -8275,17 +8225,6 @@ int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const CarEntry& newAcceleration -= velocity >> 12; newAcceleration -= GetAccelerationDecrease2(velocity, totalMass); - if (!(carEntry.flags & CAR_ENTRY_FLAG_POWERED)) - { - return newAcceleration; - } - if (carEntry.flags & CAR_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY) - { - if (speed * 0x4000 < velocity) - { - return newAcceleration; - } - } { int32_t poweredAcceleration = speed << 14; int32_t quarterForce = (speed * totalMass) >> 2; @@ -8298,33 +8237,6 @@ int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const CarEntry& if (quarterForce != 0) poweredAcceleration /= quarterForce; - if (carEntry.flags & CAR_ENTRY_FLAG_WATER_RIDE) - { - if (poweredAcceleration < 0) - { - poweredAcceleration >>= 4; - } - - if (carEntry.flags & CAR_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 (carEntry.flags & CAR_ENTRY_FLAG_SPINNING) - { - if (Pitch == 2) - { - spin_speed = 0; - } - } - newAcceleration += poweredAcceleration; - return newAcceleration; - } - } - if (abs(velocity) > 1.0_mph) { newAcceleration = 0; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index b2299c063c..7f2ec05343 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -379,6 +379,14 @@ private: void Loc6DCE02(const Ride& curRide); void Loc6DCDE4(const Ride& curRide); + + enum class UpdateMiniGolfFlagsStatus + { + carryOn, + restart, + stop, + }; + UpdateMiniGolfFlagsStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide); }; static_assert(sizeof(Vehicle) <= 512);