Skip to content

Commit

Permalink
Move most of Loc6DC462 into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Oct 10, 2024
1 parent 8f6197a commit 634f109
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 106 deletions.
215 changes: 109 additions & 106 deletions src/openrct2/ride/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7889,113 +7889,76 @@ void Vehicle::UpdateMiniGolfFlagsAndProgress(const Ride& curRide, CoordsXYZ& tra
Pitch = moveInfo->Pitch;
}

/**
* rct2: 0x006DC3A7
*
*
*/

void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry)
{
EntityId otherVehicleIndex = EntityId::GetNull();
TileElement* tileElement = nullptr;
CoordsXYZ trackPos;
int32_t direction{};

_vehicleUnkF64E10 = 1;
acceleration = AccelerationFromPitch[Pitch];
if (!HasFlag(VehicleFlags::MoveSingleCar))
{
remaining_distance = _vehicleVelocityF64E0C + remaining_distance;
}
if (remaining_distance >= 0 && remaining_distance < 0x368A)
{
Loc6DCE02(curRide);
return;
}
sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL;
_vehicleCurPosition.x = x;
_vehicleCurPosition.y = y;
_vehicleCurPosition.z = z;
Invalidate();
if (remaining_distance < 0)
goto Loc6DCA9A;

Loc6DC462:
Vehicle::Loc6DC462Status Vehicle::Loc6DC462(const Ride& curRide, CoordsXYZ& trackPos)
{
Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart;
while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart)
{
flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide);
}
if (flagsStatus == UpdateMiniGolfFlagsStatus::stop)
return;
};
return Loc6DC462Status::stop;

TileElement* tileElement;
uint16_t trackTotalProgress = GetTrackProgress();
if (track_progress + 1 >= trackTotalProgress)
{
uint16_t trackTotalProgress = GetTrackProgress();
if (track_progress + 1 >= trackTotalProgress)
tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0);
CoordsXYE output;
int32_t outZ{};
int32_t outDirection{};
CoordsXYE input = { TrackLocation, tileElement };
if (!TrackBlockGetNext(&input, &output, &outZ, &outDirection))
{
tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0);
{
CoordsXYE output;
int32_t outZ{};
int32_t outDirection{};
CoordsXYE input = { TrackLocation, tileElement };
if (!TrackBlockGetNext(&input, &output, &outZ, &outDirection))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
acceleration += AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
goto Loc6DCA9A;
}
tileElement = output.element;
trackPos = { output.x, output.y, outZ };
direction = outDirection;
}
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
acceleration += AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
return Loc6DC462Status::carryOn;
}
tileElement = output.element;
trackPos = { output.x, output.y, outZ };
auto direction = outDirection;

if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType()))
if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType()))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
if (remaining_distance >= 0)
{
_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;
Loc6DCDE4(curRide);
}
acceleration += AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
return Loc6DC462Status::carryOn;
}

TrackLocation = trackPos;
TrackLocation = trackPos;

if (!IsHead())
if (!IsHead())
{
Vehicle* prevVehicle = GetEntity<Vehicle>(prev_vehicle_on_ride);
if (prevVehicle != nullptr)
{
Vehicle* prevVehicle = GetEntity<Vehicle>(prev_vehicle_on_ride);
if (prevVehicle != nullptr)
{
TrackSubposition = prevVehicle->TrackSubposition;
}
if (TrackSubposition != VehicleTrackSubposition::MiniGolfStart9)
{
TrackSubposition = VehicleTrackSubposition{ static_cast<uint8_t>(
static_cast<uint8_t>(TrackSubposition) - 1u) };
}
TrackSubposition = prevVehicle->TrackSubposition;
}
if (TrackSubposition != VehicleTrackSubposition::MiniGolfStart9)
{
TrackSubposition = VehicleTrackSubposition{ static_cast<uint8_t>(static_cast<uint8_t>(TrackSubposition) - 1u) };
}

ClearFlag(VehicleFlags::OnLiftHill);
SetTrackType(tileElement->AsTrack()->GetTrackType());
SetTrackDirection(direction);
brake_speed = tileElement->AsTrack()->GetBrakeBoosterSpeed();
track_progress = 0;
}
else
{
track_progress += 1;
}

ClearFlag(VehicleFlags::OnLiftHill);
SetTrackType(tileElement->AsTrack()->GetTrackType());
SetTrackDirection(direction);
brake_speed = tileElement->AsTrack()->GetBrakeBoosterSpeed();
track_progress = 0;
}
else
{
track_progress += 1;
}

if (!IsHead())
Expand All @@ -8013,38 +7976,78 @@ void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideOb
{
if (_vehicleVelocityF64E08 >= 0)
{
otherVehicleIndex = prev_vehicle_on_ride;
auto otherVehicleIndex = prev_vehicle_on_ride;
UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex);
}
}
if (remaining_distance < 0x368A)
{
Loc6DCDE4(curRide);
return;
return Loc6DC462Status::stop;
}
acceleration = AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
goto Loc6DC462;
return Loc6DC462Status::restart;
}

/**
* rct2: 0x006DC3A7
*
*
*/

void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry)
{
TileElement* tileElement = nullptr;
CoordsXYZ trackPos;

_vehicleUnkF64E10 = 1;
acceleration = AccelerationFromPitch[Pitch];
if (!HasFlag(VehicleFlags::MoveSingleCar))
{
remaining_distance = _vehicleVelocityF64E0C + remaining_distance;
}
if (remaining_distance >= 0 && remaining_distance < 0x368A)
{
Loc6DCE02(curRide);
return;
}
sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL;
_vehicleCurPosition.x = x;
_vehicleCurPosition.y = y;
_vehicleCurPosition.z = z;
Invalidate();
if (remaining_distance < 0)
goto Loc6DCA9A;

Loc6DC462:
{
Vehicle::Loc6DC462Status flagsStatus = Vehicle::Loc6DC462Status::restart;
while (flagsStatus == Vehicle::Loc6DC462Status::restart)
{
flagsStatus = Loc6DC462(curRide, trackPos);
}
if (flagsStatus == Loc6DC462Status::stop)
return;
}

Loc6DCA9A:
if (track_progress == 0)
{
tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0);
TrackBeginEnd trackBeginEnd;
if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd))
{
TrackBeginEnd trackBeginEnd;
if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd))
{
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
acceleration += AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
goto Loc6DCA9A;
}
trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z };
direction = trackBeginEnd.begin_direction;
tileElement = trackBeginEnd.begin_element;
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance + 1;
remaining_distance = -1;
acceleration += AccelerationFromPitch[Pitch];
_vehicleUnkF64E10++;
goto Loc6DCA9A;
}
trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z };
auto direction = trackBeginEnd.begin_direction;
tileElement = trackBeginEnd.begin_element;

if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType()))
{
Expand Down Expand Up @@ -8101,7 +8104,7 @@ void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideOb
{
if (_vehicleVelocityF64E08 >= 0)
{
otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?.
auto otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?.
if (UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex))
{
_vehicleVelocityF64E0C -= remaining_distance - 0x368A;
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/ride/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,12 @@ struct Vehicle : EntityBase
restart,
stop,
};
using Loc6DC462Status = UpdateMiniGolfFlagsStatus;
UpdateMiniGolfFlagsStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide);
void UpdateTrackMotionPreUpdate(
Vehicle& car, const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry);
void UpdateMiniGolfFlagsAndProgress(const Ride& curRide, CoordsXYZ& trackPos);
Loc6DC462Status Loc6DC462(const Ride& curRide, CoordsXYZ& trackPos);
};
static_assert(sizeof(Vehicle) <= 512);

Expand Down

0 comments on commit 634f109

Please sign in to comment.