Booster code cleanups/unified booster speed preparation

This commit is contained in:
spacek531 2025-01-19 07:43:26 -08:00 committed by GitHub
parent 5fbe8d0ae1
commit bf413b2ab7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 27 additions and 21 deletions

View file

@ -1545,7 +1545,7 @@ namespace OpenRCT2::Ui::Windows
uint16_t brakeSpeed2 = ((_currentBrakeSpeed * 9) >> 2) & 0xFFFF;
if (TrackTypeIsBooster(_selectedTrackType) || TrackTypeIsBooster(_currentlySelectedTrack.trackType))
{
brakeSpeed2 = GetBoosterSpeed(currentRide->type, brakeSpeed2);
brakeSpeed2 = GetUnifiedBoosterSpeed(currentRide->type, brakeSpeed2);
}
ft.Add<uint16_t>(brakeSpeed2);
}

View file

@ -5463,10 +5463,9 @@ bool RideHasRatings(const Ride& ride)
return !ride.ratings.isNull();
}
int32_t GetBoosterSpeed(ride_type_t rideType, int32_t rawSpeed)
int32_t GetUnifiedBoosterSpeed(ride_type_t rideType, int32_t relativeSpeed)
{
// BoosterSpeedFactor has valid values of 1, 2, 4 representing a 1/2, 1, and 2 multiplier.
return rawSpeed * GetRideTypeDescriptor(rideType).LegacyBoosterSettings.BoosterSpeedFactor / 2;
return GetRideTypeDescriptor(rideType).GetUnifiedBoosterSpeed(relativeSpeed);
}
void FixInvalidVehicleSpriteSizes()

View file

@ -993,7 +993,7 @@ bool RideHasAdjacentStation(const Ride& ride);
bool RideHasStationShelter(const Ride& ride);
bool RideHasRatings(const Ride& ride);
int32_t GetBoosterSpeed(ride_type_t rideType, int32_t rawSpeed);
int32_t GetUnifiedBoosterSpeed(ride_type_t rideType, int32_t relativeSpeed);
void FixInvalidVehicleSpriteSizes();
bool RideEntryHasCategory(const RideObjectEntry& rideEntry, uint8_t category);

View file

@ -456,3 +456,10 @@ TrackDrawerEntry getTrackDrawerEntry(const RideTypeDescriptor& rtd, bool isInver
return descriptor.Regular;
}
int32_t RideTypeDescriptor::GetUnifiedBoosterSpeed(int32_t compressedSpeed) const
{
// BoosterSpeedFactor has valid values of 1, 2, 4 representing a 1/2, 1, and 2 multiplier of legacy speed to unified
// speed.
return compressedSpeed * LegacyBoosterSettings.BoosterSpeedFactor / 2;
}

View file

@ -536,6 +536,11 @@ struct RideTypeDescriptor
bool SupportsTrackGroup(const TrackGroup trackGroup) const;
ResearchCategory GetResearchCategory() const;
bool SupportsRideMode(RideMode rideMode) const;
/**
* Converts booster speed from the ride type's speed regime (Junior, Default, Giga) to to the unified values used by the
* vehicle. See https://github.com/OpenRCT2/OpenRCT2/discussions/23119 for more information about unified speed.
*/
int32_t GetUnifiedBoosterSpeed(int32_t relativeSpeed) const;
};
extern const RideTypeDescriptor RideTypeDescriptors[RIDE_TYPE_COUNT];

View file

@ -79,6 +79,9 @@ constexpr int16_t VEHICLE_MAX_SPIN_SPEED_WATER_RIDE = 512;
constexpr int16_t VEHICLE_MIN_SPIN_SPEED_WATER_RIDE = -VEHICLE_MAX_SPIN_SPEED_WATER_RIDE;
constexpr int16_t VEHICLE_STOPPING_SPIN_SPEED = 600;
constexpr uint8_t kTrackSpeedShiftAmount = 16;
constexpr uint8_t kBoosterAccelerationShiftAmount = 16;
Vehicle* gCurrentVehicle;
static uint8_t _vehicleBreakdown;
@ -5457,7 +5460,7 @@ void Vehicle::ApplyNonStopBlockBrake()
velocity = kBlockBrakeBaseSpeed;
acceleration = 0;
}
else if (velocity > (brake_speed << 16) + kBlockBrakeSpeedOffset)
else if (velocity > (brake_speed << kTrackSpeedShiftAmount) + kBlockBrakeSpeedOffset)
{
velocity -= velocity >> 4;
acceleration = 0;
@ -7108,9 +7111,9 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu
&& curRide.breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE;
if (!hasBrakesFailure || curRide.mechanic_status == RIDE_MECHANIC_STATUS_HAS_FIXED_STATION_BRAKES)
{
auto brakeSpeed = ChooseBrakeSpeed();
auto brakeSpeed = ChooseBrakeSpeed() << kTrackSpeedShiftAmount;
if ((brakeSpeed << 16) < _vehicleVelocityF64E08)
if ((brakeSpeed) < _vehicleVelocityF64E08)
{
acceleration = -_vehicleVelocityF64E08 * 16;
}
@ -7126,11 +7129,11 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu
}
else if (TrackTypeIsBooster(trackType))
{
auto boosterSpeed = GetBoosterSpeed(curRide.type, (brake_speed << 16));
auto boosterSpeed = GetUnifiedBoosterSpeed(curRide.type, brake_speed) << kTrackSpeedShiftAmount;
if (boosterSpeed > _vehicleVelocityF64E08)
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.BoosterAcceleration
<< 16; //_vehicleVelocityF64E08 * 1.2;
<< kBoosterAccelerationShiftAmount;
}
}
else if (rideEntry.flags & RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED && num_peeps > 0)
@ -7141,7 +7144,8 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu
if ((trackType == TrackElemType::Flat && curRide.GetRideTypeDescriptor().HasFlag(RtdFlag::hasLsmBehaviourOnFlat))
|| (trackType == TrackElemType::PoweredLift))
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.PoweredLiftAcceleration << 16;
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.PoweredLiftAcceleration
<< kBoosterAccelerationShiftAmount;
}
if (trackType == TrackElemType::BrakeForDrop)
{
@ -7506,21 +7510,12 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c
{
auto brakeSpeed = ChooseBrakeSpeed();
if (-(brakeSpeed << 16) > _vehicleVelocityF64E08)
if (-(brakeSpeed << kTrackSpeedShiftAmount) > _vehicleVelocityF64E08)
{
acceleration = _vehicleVelocityF64E08 * -16;
}
}
if (trackType == TrackElemType::Booster)
{
auto boosterSpeed = GetBoosterSpeed(curRide.type, (brake_speed << 16));
if (boosterSpeed < _vehicleVelocityF64E08)
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.BoosterAcceleration << 16;
}
}
uint16_t newTrackProgress = track_progress - 1;
if (newTrackProgress == 0xFFFF)
{