1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Eliminate Loc6DAEB9 (#22899)

This commit is contained in:
Michael Steenbeek
2024-10-04 13:49:21 +02:00
committed by GitHub
parent 99d9adc9b2
commit 01cd900a1c

View File

@@ -7062,234 +7062,237 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, const Rid
bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& curRide, const RideObjectEntry& rideEntry)
{
EntityId otherVehicleIndex = EntityId::GetNull();
Loc6DAEB9:
auto trackType = GetTrackType();
if (trackType == TrackElemType::HeartLineTransferUp || trackType == TrackElemType::HeartLineTransferDown)
while (true)
{
if (track_progress == 80)
auto trackType = GetTrackType();
if (trackType == TrackElemType::HeartLineTransferUp || trackType == TrackElemType::HeartLineTransferDown)
{
vehicle_type ^= 1;
carEntry = Entry();
}
if (_vehicleVelocityF64E08 >= 0x40000)
{
acceleration = -_vehicleVelocityF64E08 * 8;
}
else if (_vehicleVelocityF64E08 < 0x20000)
{
acceleration = 0x50000;
}
}
else if (TrackTypeIsBrakes(trackType))
{
bool hasBrakesFailure = curRide.lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN
&& curRide.breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE;
if (!hasBrakesFailure || curRide.mechanic_status == RIDE_MECHANIC_STATUS_HAS_FIXED_STATION_BRAKES)
{
auto brakeSpeed = ChooseBrakeSpeed();
if ((brakeSpeed << 16) < _vehicleVelocityF64E08)
if (track_progress == 80)
{
acceleration = -_vehicleVelocityF64E08 * 16;
}
else if (!(GetGameState().CurrentTicks & 0x0F))
{
if (_vehicleF64E2C == 0)
{
_vehicleF64E2C++;
OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::BrakeRelease, { x, y, z });
}
}
}
}
else if (TrackTypeIsBooster(trackType))
{
auto boosterSpeed = GetBoosterSpeed(curRide.type, (brake_speed << 16));
if (boosterSpeed > _vehicleVelocityF64E08)
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.BoosterAcceleration
<< 16; //_vehicleVelocityF64E08 * 1.2;
}
}
else if (rideEntry.flags & RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED && num_peeps > 0)
{
acceleration += CalculateRiderBraking();
}
if ((trackType == TrackElemType::Flat && curRide.GetRideTypeDescriptor().HasFlag(RtdFlag::hasLsmBehaviourOnFlat))
|| (trackType == TrackElemType::PoweredLift))
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.PoweredLiftAcceleration << 16;
}
if (trackType == TrackElemType::BrakeForDrop)
{
if (IsHead())
{
if (!HasFlag(VehicleFlags::StoppedOnHoldingBrake))
{
if (track_progress >= 8)
{
acceleration = -_vehicleVelocityF64E08 * 16;
if (track_progress >= 24)
{
SetFlag(VehicleFlags::StoppedOnHoldingBrake);
vertical_drop_countdown = 90;
}
}
}
}
}
if (trackType == TrackElemType::LogFlumeReverser)
{
if (track_progress != 16 || velocity < 4.0_mph)
{
if (track_progress == 32)
{
vehicle_type = carEntry->ReversedCarIndex;
vehicle_type ^= 1;
carEntry = Entry();
}
}
else
{
track_progress += 17;
}
}
uint16_t newTrackProgress = track_progress + 1;
// Track Total Progress is in the two bytes before the move info list
uint16_t trackTotalProgress = GetTrackProgress();
if (newTrackProgress >= trackTotalProgress)
{
UpdateCrossings();
if (!UpdateTrackMotionForwardsGetNewTrack(trackType, curRide, rideEntry))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
return false;
}
newTrackProgress = 0;
}
track_progress = newTrackProgress;
UpdateHandleWaterSplash();
// Loc6DB706
const auto moveInfo = GetMoveInfo();
trackType = GetTrackType();
uint8_t moveInfovehicleAnimationGroup;
{
auto nextVehiclePosition = TrackLocation
+ CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset };
uint8_t remainingDistanceFlags = 0;
if (nextVehiclePosition.x != _vehicleCurPosition.x)
{
remainingDistanceFlags |= 1;
}
if (nextVehiclePosition.y != _vehicleCurPosition.y)
{
remainingDistanceFlags |= 2;
}
if (nextVehiclePosition.z != _vehicleCurPosition.z)
{
remainingDistanceFlags |= 4;
}
if (TrackSubposition == VehicleTrackSubposition::ReverserRCFrontBogie
&& (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser) && track_progress >= 30
&& track_progress <= 66)
{
remainingDistanceFlags |= 8;
}
if (TrackSubposition == VehicleTrackSubposition::ReverserRCRearBogie
&& (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser) && track_progress == 96)
{
ReverseReverserCar();
const VehicleInfo* moveInfo2 = GetMoveInfo();
nextVehiclePosition.x = x + moveInfo2->x;
nextVehiclePosition.y = y + moveInfo2->y;
}
// Loc6DB8A5
remaining_distance -= SubpositionTranslationDistances[remainingDistanceFlags];
_vehicleCurPosition = nextVehiclePosition;
Orientation = moveInfo->direction;
bank_rotation = moveInfo->bank_rotation;
Pitch = moveInfo->Pitch;
moveInfovehicleAnimationGroup = moveInfo->Pitch;
if ((carEntry->flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) && moveInfo->Pitch != 0)
{
SwingSprite = 0;
SwingPosition = 0;
SwingSpeed = 0;
}
// this == frontVehicle
if (this == _vehicleFrontVehicle)
{
if (_vehicleVelocityF64E08 >= 0)
if (_vehicleVelocityF64E08 >= 0x40000)
{
otherVehicleIndex = prev_vehicle_on_ride;
if (UpdateMotionCollisionDetection(nextVehiclePosition, &otherVehicleIndex))
acceleration = -_vehicleVelocityF64E08 * 8;
}
else if (_vehicleVelocityF64E08 < 0x20000)
{
acceleration = 0x50000;
}
}
else if (TrackTypeIsBrakes(trackType))
{
bool hasBrakesFailure = curRide.lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN
&& curRide.breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE;
if (!hasBrakesFailure || curRide.mechanic_status == RIDE_MECHANIC_STATUS_HAS_FIXED_STATION_BRAKES)
{
auto brakeSpeed = ChooseBrakeSpeed();
if ((brakeSpeed << 16) < _vehicleVelocityF64E08)
{
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
// Might need to be bp rather than this, but hopefully not
auto otherVeh = GetEntity<Vehicle>(otherVehicleIndex);
if (otherVeh == nullptr)
acceleration = -_vehicleVelocityF64E08 * 16;
}
else if (!(GetGameState().CurrentTicks & 0x0F))
{
if (_vehicleF64E2C == 0)
{
// This can never happen as prev_vehicle_on_ride will always be set to a vehicle
LOG_ERROR("Failed to get next vehicle during update!");
return true;
_vehicleF64E2C++;
OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::BrakeRelease, { x, y, z });
}
auto head = otherVeh->TrainHead();
auto velocityDelta = abs(velocity - head->velocity);
if (!(rideEntry.flags & RIDE_ENTRY_FLAG_DISABLE_COLLISION_CRASHES))
{
if (velocityDelta > 14.0_mph)
{
if (!(carEntry->flags & CAR_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION;
}
}
}
if (carEntry->flags & CAR_ENTRY_FLAG_GO_KART)
{
velocity -= velocity >> 2;
}
else
{
int32_t newHeadVelocity = velocity >> 1;
velocity = head->velocity >> 1;
head->velocity = newHeadVelocity;
}
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1;
return false;
}
}
}
}
else if (TrackTypeIsBooster(trackType))
{
auto boosterSpeed = GetBoosterSpeed(curRide.type, (brake_speed << 16));
if (boosterSpeed > _vehicleVelocityF64E08)
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.BoosterAcceleration
<< 16; //_vehicleVelocityF64E08 * 1.2;
}
}
else if (rideEntry.flags & RIDE_ENTRY_FLAG_RIDER_CONTROLS_SPEED && num_peeps > 0)
{
acceleration += CalculateRiderBraking();
}
// Loc6DB928
if (remaining_distance < 0x368A)
{
return true;
}
if ((trackType == TrackElemType::Flat && curRide.GetRideTypeDescriptor().HasFlag(RtdFlag::hasLsmBehaviourOnFlat))
|| (trackType == TrackElemType::PoweredLift))
{
acceleration = GetRideTypeDescriptor(curRide.type).LegacyBoosterSettings.PoweredLiftAcceleration << 16;
}
if (trackType == TrackElemType::BrakeForDrop)
{
if (IsHead())
{
if (!HasFlag(VehicleFlags::StoppedOnHoldingBrake))
{
if (track_progress >= 8)
{
acceleration = -_vehicleVelocityF64E08 * 16;
if (track_progress >= 24)
{
SetFlag(VehicleFlags::StoppedOnHoldingBrake);
vertical_drop_countdown = 90;
}
}
}
}
}
if (trackType == TrackElemType::LogFlumeReverser)
{
if (track_progress != 16 || velocity < 4.0_mph)
{
if (track_progress == 32)
{
vehicle_type = carEntry->ReversedCarIndex;
carEntry = Entry();
}
}
else
{
track_progress += 17;
}
}
acceleration += AccelerationFromPitch[moveInfovehicleAnimationGroup];
_vehicleUnkF64E10++;
goto Loc6DAEB9;
uint16_t newTrackProgress = track_progress + 1;
// Track Total Progress is in the two bytes before the move info list
uint16_t trackTotalProgress = GetTrackProgress();
if (newTrackProgress >= trackTotalProgress)
{
UpdateCrossings();
if (!UpdateTrackMotionForwardsGetNewTrack(trackType, curRide, rideEntry))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
return false;
}
newTrackProgress = 0;
}
track_progress = newTrackProgress;
UpdateHandleWaterSplash();
// Loc6DB706
const auto moveInfo = GetMoveInfo();
trackType = GetTrackType();
uint8_t moveInfovehicleAnimationGroup;
{
auto nextVehiclePosition = TrackLocation
+ CoordsXYZ{ moveInfo->x, moveInfo->y,
moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset };
uint8_t remainingDistanceFlags = 0;
if (nextVehiclePosition.x != _vehicleCurPosition.x)
{
remainingDistanceFlags |= 1;
}
if (nextVehiclePosition.y != _vehicleCurPosition.y)
{
remainingDistanceFlags |= 2;
}
if (nextVehiclePosition.z != _vehicleCurPosition.z)
{
remainingDistanceFlags |= 4;
}
if (TrackSubposition == VehicleTrackSubposition::ReverserRCFrontBogie
&& (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser)
&& track_progress >= 30 && track_progress <= 66)
{
remainingDistanceFlags |= 8;
}
if (TrackSubposition == VehicleTrackSubposition::ReverserRCRearBogie
&& (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser)
&& track_progress == 96)
{
ReverseReverserCar();
const VehicleInfo* moveInfo2 = GetMoveInfo();
nextVehiclePosition.x = x + moveInfo2->x;
nextVehiclePosition.y = y + moveInfo2->y;
}
// Loc6DB8A5
remaining_distance -= SubpositionTranslationDistances[remainingDistanceFlags];
_vehicleCurPosition = nextVehiclePosition;
Orientation = moveInfo->direction;
bank_rotation = moveInfo->bank_rotation;
Pitch = moveInfo->Pitch;
moveInfovehicleAnimationGroup = moveInfo->Pitch;
if ((carEntry->flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) && moveInfo->Pitch != 0)
{
SwingSprite = 0;
SwingPosition = 0;
SwingSpeed = 0;
}
// this == frontVehicle
if (this == _vehicleFrontVehicle)
{
if (_vehicleVelocityF64E08 >= 0)
{
otherVehicleIndex = prev_vehicle_on_ride;
if (UpdateMotionCollisionDetection(nextVehiclePosition, &otherVehicleIndex))
{
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
// Might need to be bp rather than this, but hopefully not
auto otherVeh = GetEntity<Vehicle>(otherVehicleIndex);
if (otherVeh == nullptr)
{
// This can never happen as prev_vehicle_on_ride will always be set to a vehicle
LOG_ERROR("Failed to get next vehicle during update!");
return true;
}
auto head = otherVeh->TrainHead();
auto velocityDelta = abs(velocity - head->velocity);
if (!(rideEntry.flags & RIDE_ENTRY_FLAG_DISABLE_COLLISION_CRASHES))
{
if (velocityDelta > 14.0_mph)
{
if (!(carEntry->flags & CAR_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION;
}
}
}
if (carEntry->flags & CAR_ENTRY_FLAG_GO_KART)
{
velocity -= velocity >> 2;
}
else
{
int32_t newHeadVelocity = velocity >> 1;
velocity = head->velocity >> 1;
head->velocity = newHeadVelocity;
}
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1;
return false;
}
}
}
}
// Loc6DB928
if (remaining_distance < 0x368A)
{
return true;
}
acceleration += AccelerationFromPitch[moveInfovehicleAnimationGroup];
_vehicleUnkF64E10++;
}
}
static PitchAndRoll PitchAndRollEnd(const Ride& curRide, bool useInvertedSprites, uint16_t trackType, TileElement* tileElement)