mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-21 22:13:07 +01:00
Merge pull request #11837 from hdpoliveira/vehicle_update_9473_a
Create Vehicle::CableLiftUpdateTrackMotion
This commit is contained in:
@@ -124,7 +124,7 @@ void Vehicle::CableLiftUpdateMovingToEndOfStation()
|
||||
acceleration = 0;
|
||||
}
|
||||
|
||||
if (!(cable_lift_update_track_motion(this) & VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION))
|
||||
if (!(CableLiftUpdateTrackMotion() & VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION))
|
||||
return;
|
||||
|
||||
velocity = 0;
|
||||
@@ -147,7 +147,7 @@ void Vehicle::CableLiftUpdateWaitingToDepart()
|
||||
acceleration = 0;
|
||||
}
|
||||
|
||||
cable_lift_update_track_motion(this);
|
||||
CableLiftUpdateTrackMotion();
|
||||
|
||||
// Next check to see if the second part of the cable lift
|
||||
// is at the front of the passenger vehicle to simulate the
|
||||
@@ -194,7 +194,7 @@ void Vehicle::CableLiftUpdateTravelling()
|
||||
if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN)
|
||||
return;
|
||||
|
||||
if (!(cable_lift_update_track_motion(this) & VEHICLE_UPDATE_MOTION_TRACK_FLAG_1))
|
||||
if (!(CableLiftUpdateTrackMotion() & VEHICLE_UPDATE_MOTION_TRACK_FLAG_1))
|
||||
return;
|
||||
|
||||
velocity = 0;
|
||||
@@ -213,35 +213,35 @@ void Vehicle::CableLiftUpdateArriving()
|
||||
SetState(VEHICLE_STATUS_MOVING_TO_END_OF_STATION, sub_state);
|
||||
}
|
||||
|
||||
static bool sub_6DF01A_loop(Vehicle* vehicle)
|
||||
bool Vehicle::CableLiftUpdateTrackMotionForwards()
|
||||
{
|
||||
auto ride = get_ride(vehicle->ride);
|
||||
if (ride == nullptr)
|
||||
auto curRide = get_ride(ride);
|
||||
if (curRide == nullptr)
|
||||
return false;
|
||||
|
||||
for (; vehicle->remaining_distance >= 13962; _vehicleUnkF64E10++)
|
||||
for (; remaining_distance >= 13962; _vehicleUnkF64E10++)
|
||||
{
|
||||
uint8_t trackType = vehicle->track_type >> 2;
|
||||
if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle->track_progress == 160)
|
||||
uint8_t trackType = track_type >> 2;
|
||||
if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && track_progress == 160)
|
||||
{
|
||||
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1;
|
||||
}
|
||||
|
||||
uint16_t trackProgress = vehicle->track_progress + 1;
|
||||
uint16_t trackProgress = track_progress + 1;
|
||||
|
||||
const rct_vehicle_info* moveInfo = vehicle_get_move_info(vehicle->TrackSubposition, vehicle->track_type, 0);
|
||||
uint16_t trackTotalProgress = vehicle_get_move_info_size(vehicle->TrackSubposition, vehicle->track_type);
|
||||
const rct_vehicle_info* moveInfo = vehicle_get_move_info(TrackSubposition, track_type, 0);
|
||||
uint16_t trackTotalProgress = vehicle_get_move_info_size(TrackSubposition, track_type);
|
||||
if (trackProgress >= trackTotalProgress)
|
||||
{
|
||||
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end;
|
||||
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
|
||||
TileElement* trackElement = map_get_track_element_at_of_type_seq(vehicle->TrackLocation, trackType, 0);
|
||||
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
|
||||
|
||||
CoordsXYE output;
|
||||
int32_t outputZ;
|
||||
int32_t outputDirection;
|
||||
|
||||
auto input = CoordsXYE{ vehicle->TrackLocation, trackElement };
|
||||
auto input = CoordsXYE{ TrackLocation, trackElement };
|
||||
|
||||
if (!track_block_get_next(&input, &output, &outputZ, &outputDirection))
|
||||
return false;
|
||||
@@ -250,18 +250,18 @@ static bool sub_6DF01A_loop(Vehicle* vehicle)
|
||||
|| TrackDefinitions[output.element->AsTrack()->GetTrackType()].bank_start != _vehicleBankEndF64E37)
|
||||
return false;
|
||||
|
||||
vehicle->TrackLocation = { output, outputZ };
|
||||
vehicle->track_direction = outputDirection;
|
||||
vehicle->track_type |= output.element->AsTrack()->GetTrackType() << 2;
|
||||
TrackLocation = { output, outputZ };
|
||||
track_direction = outputDirection;
|
||||
track_type |= output.element->AsTrack()->GetTrackType() << 2;
|
||||
trackProgress = 0;
|
||||
}
|
||||
|
||||
vehicle->track_progress = trackProgress;
|
||||
moveInfo = vehicle_get_move_info(vehicle->TrackSubposition, vehicle->track_type, trackProgress);
|
||||
auto unk = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + vehicle->TrackLocation;
|
||||
track_progress = trackProgress;
|
||||
moveInfo = vehicle_get_move_info(TrackSubposition, track_type, trackProgress);
|
||||
auto unk = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + TrackLocation;
|
||||
|
||||
uint8_t bx = 0;
|
||||
unk.z += RideData5[ride->type].z_offset;
|
||||
unk.z += RideData5[curRide->type].z_offset;
|
||||
if (unk.x != unk_F64E20.x)
|
||||
bx |= (1 << 0);
|
||||
if (unk.y != unk_F64E20.y)
|
||||
@@ -269,43 +269,43 @@ static bool sub_6DF01A_loop(Vehicle* vehicle)
|
||||
if (unk.z != unk_F64E20.z)
|
||||
bx |= (1 << 2);
|
||||
|
||||
vehicle->remaining_distance -= dword_9A2930[bx];
|
||||
remaining_distance -= dword_9A2930[bx];
|
||||
unk_F64E20.x = unk.x;
|
||||
unk_F64E20.y = unk.y;
|
||||
unk_F64E20.z = unk.z;
|
||||
|
||||
vehicle->sprite_direction = moveInfo->direction;
|
||||
vehicle->bank_rotation = moveInfo->bank_rotation;
|
||||
vehicle->vehicle_sprite_type = moveInfo->vehicle_sprite_type;
|
||||
sprite_direction = moveInfo->direction;
|
||||
bank_rotation = moveInfo->bank_rotation;
|
||||
vehicle_sprite_type = moveInfo->vehicle_sprite_type;
|
||||
|
||||
if (vehicle->remaining_distance >= 13962)
|
||||
if (remaining_distance >= 13962)
|
||||
{
|
||||
vehicle->acceleration += dword_9A2970[vehicle->vehicle_sprite_type];
|
||||
acceleration += dword_9A2970[vehicle_sprite_type];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool sub_6DF21B_loop(Vehicle* vehicle)
|
||||
bool Vehicle::CableLiftUpdateTrackMotionBackwards()
|
||||
{
|
||||
auto ride = get_ride(vehicle->ride);
|
||||
if (ride == nullptr)
|
||||
auto curRide = get_ride(ride);
|
||||
if (curRide == nullptr)
|
||||
return false;
|
||||
|
||||
for (; vehicle->remaining_distance < 0; _vehicleUnkF64E10++)
|
||||
for (; remaining_distance < 0; _vehicleUnkF64E10++)
|
||||
{
|
||||
uint16_t trackProgress = vehicle->track_progress - 1;
|
||||
uint16_t trackProgress = track_progress - 1;
|
||||
const rct_vehicle_info* moveInfo;
|
||||
|
||||
if (static_cast<int16_t>(trackProgress) == -1)
|
||||
{
|
||||
uint8_t trackType = vehicle->track_type >> 2;
|
||||
uint8_t trackType = track_type >> 2;
|
||||
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_start;
|
||||
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_start;
|
||||
|
||||
TileElement* trackElement = map_get_track_element_at_of_type_seq(vehicle->TrackLocation, trackType, 0);
|
||||
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
|
||||
|
||||
auto input = CoordsXYE{ vehicle->TrackLocation, trackElement };
|
||||
auto input = CoordsXYE{ TrackLocation, trackElement };
|
||||
track_begin_end output;
|
||||
|
||||
if (!track_block_get_previous(input, &output))
|
||||
@@ -315,26 +315,26 @@ static bool sub_6DF21B_loop(Vehicle* vehicle)
|
||||
|| TrackDefinitions[output.begin_element->AsTrack()->GetTrackType()].bank_end != _vehicleBankEndF64E37)
|
||||
return false;
|
||||
|
||||
vehicle->TrackLocation = { output.begin_x, output.begin_y, output.begin_z };
|
||||
vehicle->track_direction = output.begin_direction;
|
||||
vehicle->track_type |= output.begin_element->AsTrack()->GetTrackType() << 2;
|
||||
TrackLocation = { output.begin_x, output.begin_y, output.begin_z };
|
||||
track_direction = output.begin_direction;
|
||||
track_type |= output.begin_element->AsTrack()->GetTrackType() << 2;
|
||||
|
||||
if (output.begin_element->AsTrack()->GetTrackType() == TRACK_ELEM_END_STATION)
|
||||
{
|
||||
_vehicleMotionTrackFlags = VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION;
|
||||
}
|
||||
|
||||
moveInfo = vehicle_get_move_info(vehicle->TrackSubposition, vehicle->track_type, 0);
|
||||
uint16_t trackTotalProgress = vehicle_get_move_info_size(vehicle->TrackSubposition, vehicle->track_type);
|
||||
moveInfo = vehicle_get_move_info(TrackSubposition, track_type, 0);
|
||||
uint16_t trackTotalProgress = vehicle_get_move_info_size(TrackSubposition, track_type);
|
||||
trackProgress = trackTotalProgress - 1;
|
||||
}
|
||||
vehicle->track_progress = trackProgress;
|
||||
track_progress = trackProgress;
|
||||
|
||||
moveInfo = vehicle_get_move_info(vehicle->TrackSubposition, vehicle->track_type, trackProgress);
|
||||
auto unk = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + vehicle->TrackLocation;
|
||||
moveInfo = vehicle_get_move_info(TrackSubposition, track_type, trackProgress);
|
||||
auto unk = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + TrackLocation;
|
||||
|
||||
uint8_t bx = 0;
|
||||
unk.z += RideData5[ride->type].z_offset;
|
||||
unk.z += RideData5[curRide->type].z_offset;
|
||||
if (unk.x != unk_F64E20.x)
|
||||
bx |= (1 << 0);
|
||||
if (unk.y != unk_F64E20.y)
|
||||
@@ -342,18 +342,18 @@ static bool sub_6DF21B_loop(Vehicle* vehicle)
|
||||
if (unk.z != unk_F64E20.z)
|
||||
bx |= (1 << 2);
|
||||
|
||||
vehicle->remaining_distance += dword_9A2930[bx];
|
||||
remaining_distance += dword_9A2930[bx];
|
||||
unk_F64E20.x = unk.x;
|
||||
unk_F64E20.y = unk.y;
|
||||
unk_F64E20.z = unk.z;
|
||||
|
||||
vehicle->sprite_direction = moveInfo->direction;
|
||||
vehicle->bank_rotation = moveInfo->bank_rotation;
|
||||
vehicle->vehicle_sprite_type = moveInfo->vehicle_sprite_type;
|
||||
sprite_direction = moveInfo->direction;
|
||||
bank_rotation = moveInfo->bank_rotation;
|
||||
vehicle_sprite_type = moveInfo->vehicle_sprite_type;
|
||||
|
||||
if (vehicle->remaining_distance < 0)
|
||||
if (remaining_distance < 0)
|
||||
{
|
||||
vehicle->acceleration += dword_9A2970[vehicle->vehicle_sprite_type];
|
||||
acceleration += dword_9A2970[vehicle_sprite_type];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -363,21 +363,21 @@ static bool sub_6DF21B_loop(Vehicle* vehicle)
|
||||
*
|
||||
* rct2: 0x006DEF56
|
||||
*/
|
||||
int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
int32_t Vehicle::CableLiftUpdateTrackMotion()
|
||||
{
|
||||
_vehicleF64E2C = 0;
|
||||
gCurrentVehicle = cableLift;
|
||||
gCurrentVehicle = this;
|
||||
_vehicleMotionTrackFlags = 0;
|
||||
_vehicleStationIndex = STATION_INDEX_NULL;
|
||||
|
||||
cableLift->velocity += cableLift->acceleration;
|
||||
_vehicleVelocityF64E08 = cableLift->velocity;
|
||||
_vehicleVelocityF64E0C = (cableLift->velocity / 1024) * 42;
|
||||
velocity += acceleration;
|
||||
_vehicleVelocityF64E08 = velocity;
|
||||
_vehicleVelocityF64E0C = (velocity / 1024) * 42;
|
||||
|
||||
Vehicle* frontVehicle = cableLift;
|
||||
if (cableLift->velocity < 0)
|
||||
Vehicle* frontVehicle = this;
|
||||
if (velocity < 0)
|
||||
{
|
||||
frontVehicle = cableLift->TrainTail();
|
||||
frontVehicle = TrainTail();
|
||||
}
|
||||
|
||||
_vehicleFrontVehicle = frontVehicle;
|
||||
@@ -399,7 +399,7 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
{
|
||||
if (vehicle->remaining_distance < 0)
|
||||
{
|
||||
if (sub_6DF21B_loop(vehicle))
|
||||
if (vehicle->CableLiftUpdateTrackMotionBackwards())
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -415,7 +415,7 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sub_6DF01A_loop(vehicle))
|
||||
if (vehicle->CableLiftUpdateTrackMotionForwards())
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -442,7 +442,7 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vehicle == cableLift)
|
||||
if (vehicle == this)
|
||||
break;
|
||||
vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride);
|
||||
}
|
||||
@@ -452,7 +452,7 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
uint16_t massTotal = 0;
|
||||
int32_t accelerationTotal = 0;
|
||||
|
||||
for (uint16_t spriteId = cableLift->sprite_index; spriteId != SPRITE_INDEX_NULL;)
|
||||
for (uint16_t spriteId = sprite_index; spriteId != SPRITE_INDEX_NULL;)
|
||||
{
|
||||
Vehicle* vehicle = GET_VEHICLE(spriteId);
|
||||
vehicleCount++;
|
||||
@@ -464,17 +464,17 @@ int32_t cable_lift_update_track_motion(Vehicle* cableLift)
|
||||
}
|
||||
|
||||
int32_t newAcceleration = (accelerationTotal / vehicleCount) >> 9;
|
||||
newAcceleration -= cableLift->velocity >> 12;
|
||||
newAcceleration -= velocity >> 12;
|
||||
|
||||
int32_t edx = cableLift->velocity >> 8;
|
||||
int32_t edx = velocity >> 8;
|
||||
edx *= edx;
|
||||
if (cableLift->velocity < 0)
|
||||
if (velocity < 0)
|
||||
{
|
||||
edx = -edx;
|
||||
}
|
||||
edx >>= 4;
|
||||
newAcceleration -= edx / massTotal;
|
||||
|
||||
cableLift->acceleration = newAcceleration;
|
||||
acceleration = newAcceleration;
|
||||
return _vehicleMotionTrackFlags;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,5 @@
|
||||
|
||||
Vehicle* cable_lift_segment_create(
|
||||
Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head);
|
||||
int32_t cable_lift_update_track_motion(Vehicle* cableLift);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5002,7 +5002,7 @@ static bool ride_create_cable_lift(ride_id_t rideIndex, bool isApplying)
|
||||
tail->next_vehicle_on_ride = head->sprite_index;
|
||||
|
||||
ride->lifecycle_flags |= RIDE_LIFECYCLE_CABLE_LIFT;
|
||||
cable_lift_update_track_motion(head);
|
||||
head->CableLiftUpdateTrackMotion();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -313,6 +313,7 @@ struct Vehicle : SpriteBase
|
||||
void UpdateSoundParams(std::vector<rct_vehicle_sound_params>& vehicleSoundParamsList) const;
|
||||
bool DodgemsCarWouldCollideAt(const CoordsXY& coords, uint16_t* spriteId) const;
|
||||
int32_t UpdateTrackMotion(int32_t* outStation);
|
||||
int32_t CableLiftUpdateTrackMotion();
|
||||
GForces GetGForces() const;
|
||||
void SetMapToolbar() const;
|
||||
int32_t IsUsedInPairs() const;
|
||||
@@ -325,6 +326,8 @@ private:
|
||||
uint16_t GetSoundPriority() const;
|
||||
rct_vehicle_sound_params CreateSoundParam(uint16_t priority) const;
|
||||
void CableLiftUpdate();
|
||||
bool CableLiftUpdateTrackMotionForwards();
|
||||
bool CableLiftUpdateTrackMotionBackwards();
|
||||
void CableLiftUpdateMovingToEndOfStation();
|
||||
void CableLiftUpdateWaitingToDepart();
|
||||
void CableLiftUpdateDeparting();
|
||||
|
||||
Reference in New Issue
Block a user