Skip to content

Commit

Permalink
add BoosterMode
Browse files Browse the repository at this point in the history
  • Loading branch information
spacek531 committed Jun 5, 2024
1 parent 3bd13da commit b1a9c21
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/openrct2/ride/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constexpr uint32_t RideConstructionSpecialPieceSelected = 0x10000;
constexpr uint8_t kRCT2DefaultBlockBrakeSpeed = 2;
constexpr int32_t kBlockBrakeBaseSpeed = 0x20364;
constexpr int32_t kBlockBrakeSpeedOffset = kBlockBrakeBaseSpeed - (kRCT2DefaultBlockBrakeSpeed << 16);

constexpr uint8_t kLegacyBrakeSpeedMask = 0b00011110;
constexpr uint8_t kMaximumBrakeSpeed = 30;

using track_type_t = uint16_t;
Expand Down
105 changes: 80 additions & 25 deletions src/openrct2/ride/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ constexpr int16_t VEHICLE_MAX_SPIN_SPEED_FOR_STOPPING = 700;
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 TrackSpeedShiftAmount = 16;
constexpr uint8_t BoosterAccelerationShiftAmount = 16;

constexpr uint8_t kTrackSpeedShiftAmount = 16;
constexpr uint8_t kBoosterAccelerationShiftAmount = 16;
constexpr int32_t kFrictionBrakePower = 16;
constexpr int32_t kLSMBrakePower = 2;
constexpr uint8_t kLSMBrakeSpeed = 8;

Vehicle* gCurrentVehicle;

Expand Down Expand Up @@ -6822,6 +6826,35 @@ void Vehicle::Sub6DBF3E()
}
}

void Vehicle::PopulateBoosterSpeed(TrackElement& trackElement)
{
auto trackType = trackElement.GetTrackType();
auto rawSpeed = trackElement.GetBrakeBoosterSpeed();

auto vehicleRTD = GetRide()->GetRideTypeDescriptor();
auto poweredLiftAcceleration = vehicleRTD.LegacyBoosterSettings.PoweredLiftAcceleration;
auto boosterAcceleration = vehicleRTD.LegacyBoosterSettings.BoosterAcceleration;
auto useReverseFreefallBehaviour = trackType == TrackElemType::Flat
&& vehicleRTD.HasFlag(RIDE_TYPE_FLAG_LSM_BEHAVIOUR_ON_FLAT);
if (TrackTypeIsBooster(trackType))
{
rawSpeed = vehicleRTD.GetAbsoluteBoosterSpeed(rawSpeed);
TrackAccelerationMode = VehicleTrackAccelerationMode::BoosterTrack;
}
if ((trackType == TrackElemType::PoweredLift) || useReverseFreefallBehaviour)
{
TrackAccelerationMode = useReverseFreefallBehaviour ? VehicleTrackAccelerationMode::ReverseFreefallTrack
: VehicleTrackAccelerationMode::LaunchedLifthillTrack;
BoosterAcceleration = poweredLiftAcceleration;
brake_speed = trackElement.GetBrakeBoosterSpeed();
BlockBrakeSpeed = trackElement.GetBrakeBoosterSpeed();
return;
}
BoosterAcceleration = boosterAcceleration;
brake_speed = rawSpeed;
BlockBrakeSpeed = brake_speed;
}

/**
* Determine whether to use block brake speed or brake speed. If block brake is closed or no block brake present, use the
* brake's speed; if block brake is open, use maximum of brake speed or block brake speed.
Expand All @@ -6848,11 +6881,13 @@ void Vehicle::PopulateBrakeSpeed(const CoordsXYZ& vehicleTrackLocation, TrackEle
{
auto trackSpeed = brake.GetBrakeBoosterSpeed();
brake_speed = trackSpeed;
TrackAccelerationMode = VehicleTrackAccelerationMode::None;
if (!TrackTypeIsBrakes(brake.GetTrackType()))
{
BlockBrakeSpeed = trackSpeed;
PopulateBoosterSpeed(brake);
return;
}
TrackAccelerationMode = VehicleTrackAccelerationMode::BrakesTrack;

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / macOS (x64) using CMake

no member named 'BrakesTrack' in namespace 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / macOS (arm64) using CMake

no member named 'BrakesTrack' in namespace 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu Linux (jammy, debug, [http, network, flac, vorbis OpenGL] disabled) using clang

no member named 'BrakesTrack' in namespace 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu Linux (debug) using clang, coverage enabled

no member named 'BrakesTrack' in namespace 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu Linux (jammy, x86_64, portable)

'BrakesTrack' is not a member of 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (win32)

'BrakesTrack': is not a member of 'VehicleTrackAccelerationMode' [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (win32)

'BrakesTrack': undeclared identifier [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (win32) using mingw

‘BrakesTrack’ is not a member of ‘VehicleTrackAccelerationMode’

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (x64)

'BrakesTrack': is not a member of 'VehicleTrackAccelerationMode' [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (x64)

'BrakesTrack': undeclared identifier [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu Linux (jammy, i686, portable)

'BrakesTrack' is not a member of 'VehicleTrackAccelerationMode'

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'BrakesTrack': is not a member of 'VehicleTrackAccelerationMode' [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]

Check failure on line 6890 in src/openrct2/ride/Vehicle.cpp

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'BrakesTrack': undeclared identifier [D:\a\OpenRCT2\OpenRCT2\src\openrct2\libopenrct2.vcxproj]
// As soon as feasible, encode block brake speed into track element so the lookforward can be skipped here.

CoordsXYE output = CoordsXYE(vehicleTrackLocation.x, vehicleTrackLocation.y, reinterpret_cast<TileElement*>(&brake));
Expand Down Expand Up @@ -7060,6 +7095,44 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, const Rid
return true;
}

int32_t static GetAccelerationFromTrack(const Vehicle& vehicle, const int32_t& vehicleVelocity)
{
auto velocitySign = vehicleVelocity < 0 ? 1 : -1;
auto relativeVelocity = vehicleVelocity * velocitySign;
auto relativeAccelerationMode = vehicleVelocity < 0
? (vehicle.TrackAccelerationMode << 8) | (vehicle.TrackAccelerationMode >> 8)
: vehicle.TrackAccelerationMode;
int32_t totalAcceleration = 0;
if ((relativeAccelerationMode & VehicleTrackAccelerationMode::BrakeFrictionForwardsReverseWhenSlow)
&& relativeVelocity > (kLSMBrakeSpeed << kTrackSpeedShiftAmount))
{
totalAcceleration -= (vehicle.BoosterAcceleration << kBoosterAccelerationShiftAmount) * velocitySign;
}
else if (relativeAccelerationMode & VehicleTrackAccelerationMode::BrakeFrictionForwards)
{
if (relativeVelocity > (vehicle.brake_speed << kTrackSpeedShiftAmount))
{
totalAcceleration -= relativeVelocity * kFrictionBrakePower * velocitySign;
}
}
if (relativeAccelerationMode & VehicleTrackAccelerationMode::BrakeLSMForwards)
{
if (relativeVelocity > (kLSMBrakeSpeed << kTrackSpeedShiftAmount))
{
totalAcceleration -= relativeVelocity * kLSMBrakePower * velocitySign;
}
}
if (relativeAccelerationMode & VehicleTrackAccelerationMode::BoostForwards)
{
if ((relativeAccelerationMode & VehicleTrackAccelerationMode::BoostForwardsNoSpeedLimit)
|| (relativeVelocity < (vehicle.brake_speed << kTrackSpeedShiftAmount)))
{
totalAcceleration += (vehicle.BoosterAcceleration << kBoosterAccelerationShiftAmount) * velocitySign;
}
}
return totalAcceleration;
}

/**
*
* rct2: 0x006DAEB9
Expand Down Expand Up @@ -7091,7 +7164,7 @@ 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() << TrackSpeedShiftAmount;
auto brakeSpeed = ChooseBrakeSpeed() << kTrackSpeedShiftAmount;
if ((brakeSpeed) < _vehicleVelocityF64E08)
{
acceleration = -_vehicleVelocityF64E08 * 16;
Expand All @@ -7108,11 +7181,11 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu
}
else if (TrackTypeIsBooster(trackType))
{
auto boosterSpeed = GetAbsoluteBoosterSpeed(curRide.type, brake_speed) << TrackSpeedShiftAmount;
auto boosterSpeed = GetAbsoluteBoosterSpeed(curRide.type, brake_speed) << kTrackSpeedShiftAmount;
if (boosterSpeed > _vehicleVelocityF64E08)
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.BoosterAcceleration
<< BoosterAccelerationShiftAmount;
<< kBoosterAccelerationShiftAmount;
}
}
else if (rideEntry.flags & RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED && num_peeps > 0)
Expand Down Expand Up @@ -7468,25 +7541,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c
while (true)
{
auto trackType = GetTrackType();
if (trackType == TrackElemType::Flat && curRide.GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_LSM_BEHAVIOUR_ON_FLAT))
{
int32_t unkVelocity = _vehicleVelocityF64E08;
if (unkVelocity < -524288)
{
unkVelocity = abs(unkVelocity);
acceleration = unkVelocity * 2;
}
}

if (TrackTypeIsBrakes(trackType))
{
auto brakeSpeed = ChooseBrakeSpeed();

if (-(brakeSpeed << TrackSpeedShiftAmount) > _vehicleVelocityF64E08)
{
acceleration = _vehicleVelocityF64E08 * -16;
}
}
acceleration = GetAccelerationFromTrack(*this, _vehicleVelocityF64E08);

uint16_t newTrackProgress = track_progress - 1;
if (newTrackProgress == 0xFFFF)
Expand Down
24 changes: 24 additions & 0 deletions src/openrct2/ride/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ struct Vehicle : EntityBase
uint8_t target_seat_rotation;
CoordsXY BoatLocation;
uint8_t BlockBrakeSpeed;
uint8_t BoosterAcceleration;
uint16_t TrackAccelerationMode;

constexpr bool IsHead() const
{
Expand Down Expand Up @@ -376,6 +378,7 @@ struct Vehicle : EntityBase
int32_t CalculateRiderBraking() const;
uint8_t ChooseBrakeSpeed() const;
void PopulateBrakeSpeed(const CoordsXYZ& vehicleTrackLocation, TrackElement& brake);
void PopulateBoosterSpeed(TrackElement& trackElement);

void Loc6DCE02(const Ride& curRide);
void Loc6DCDE4(const Ride& curRide);
Expand Down Expand Up @@ -456,6 +459,27 @@ namespace VehicleFlags
constexpr uint32_t CarIsReversed = (1 << 16); // Car is displayed running backwards
} // namespace VehicleFlags

namespace VehicleTrackAccelerationMode
{
constexpr uint16_t BrakeFrictionForwards = (1 << 0);
constexpr uint16_t BoostForwards = (1 << 1);
constexpr uint16_t BoostForwardsNoSpeedLimit = (1 << 2);
constexpr uint16_t BrakeLSMForwards = (1 << 3);
constexpr uint16_t BrakeFrictionForwardsReverseWhenSlow = (1 << 4);

constexpr uint16_t BrakeFrictionBackwards = (1 << 8);
constexpr uint16_t BoostBackwards = (1 << 9);
constexpr uint16_t BoostBackwardsNoSpeedLimit = (1 << 10);
constexpr uint16_t BrakeLSMBackwards = (1 << 11);
constexpr uint16_t BrakeHardBackwardsReverseWhenSlow = (1 << 12);

constexpr uint16_t None = 0;
constexpr uint16_t ReverseFreefallTrack = BoostForwards | BoostForwardsNoSpeedLimit | BrakeLSMBackwards;
constexpr uint16_t LaunchedLifthillTrack = BoostForwards | BoostForwardsNoSpeedLimit;
constexpr uint16_t BoosterTrack = BoostForwards;

} // namespace VehicleTrackAccelerationMode

enum
{
VEHICLE_VISUAL_DEFAULT,
Expand Down

0 comments on commit b1a9c21

Please sign in to comment.