MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / updateTrackMotion

Function updateTrackMotion

src/OpenLoco/src/Vehicles/Vehicle.cpp:500–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498 }
499
500 static UpdateMotionResult updateTrackMotion(VehicleBase& component, int32_t distance, bool isVeh2UnkM15)
501 {
502 if (component.mode == TransportMode::road)
503 {
504 return updateRoadMotion(component, distance, isVeh2UnkM15);
505 }
506 else if (component.mode == TransportMode::rail)
507 {
508 UpdateMotionResult result{};
509 component.remainingDistance += distance;
510 bool hasMoved = false;
511 auto intermediatePosition = component.position;
512 while (component.remainingDistance >= 0x368A)
513 {
514 hasMoved = true;
515 auto newSubPosition = component.subPosition + 1U;
516 const auto subPositionDataSize = World::TrackData::getTrackSubPositon(component.trackAndDirection.track._data).size();
517 // This means we have moved forward by a track piece
518 if (newSubPosition >= subPositionDataSize)
519 {
520 if (!updateTrackMotionNewTrackPiece(component, result.flags, isVeh2UnkM15))
521 {
522 result.remainingDistance = component.remainingDistance - 0x3689;
523 component.remainingDistance = 0x3689;
524 result.flags |= UpdateVar1136114Flags::unk_m00;
525 break;
526 }
527 else
528 {
529 newSubPosition = 0;
530 }
531 }
532 // 0x004B1761
533 component.subPosition = newSubPosition;
534 const auto& moveData = World::TrackData::getTrackSubPositon(component.trackAndDirection.track._data)[newSubPosition];
535 const auto nextNewPosition = moveData.loc + World::Pos3(component.tileX, component.tileY, component.tileBaseZ * World::kSmallZStep);
536 component.remainingDistance -= kMovementNibbleToDistance[getMovementNibble(intermediatePosition, nextNewPosition)];
537 intermediatePosition = nextNewPosition;
538 component.spriteYaw = moveData.yaw;
539 component.spritePitch = moveData.pitch;
540 if (component.isVehicleBogie())
541 {
542 // collision checks
543 auto collideResult = checkForCollisions(*component.asVehicleBogie(), intermediatePosition);
544 if (collideResult != EntityId::null)
545 {
546 result.flags |= UpdateVar1136114Flags::crashed;
547 result.collidedEntityId = collideResult;
548 }
549 }
550 }
551 if (hasMoved)
552 {
553 component.moveTo(intermediatePosition);
554 }
555 return result;
556 }
557 else

Callers 5

updateMethod · 0.85
sub_4A9F20Method · 0.85
updateRailMethod · 0.85
updateTrackMotionMethod · 0.85
updateMethod · 0.85

Calls 9

updateRoadMotionFunction · 0.85
getTrackSubPositonFunction · 0.85
getMovementNibbleFunction · 0.85
checkForCollisionsFunction · 0.85
isVehicleBogieMethod · 0.80
asVehicleBogieMethod · 0.80
moveToMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected