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

Function updateRoadMotion

src/OpenLoco/src/Vehicles/Vehicle.cpp:448–498  ·  view source on GitHub ↗

0x0047C7FA

Source from the content-addressed store, hash-verified

446
447 // 0x0047C7FA
448 static UpdateMotionResult updateRoadMotion(VehicleBase& component, int32_t distance, bool isVeh2UnkM15)
449 {
450 UpdateMotionResult result{};
451 component.remainingDistance += distance;
452 bool hasMoved = false;
453 auto intermediatePosition = component.position;
454 while (component.remainingDistance >= 0x368A)
455 {
456 hasMoved = true;
457 auto newSubPosition = component.subPosition + 1U;
458 const auto subPositionDataSize = World::TrackData::getRoadSubPositon(component.trackAndDirection.road._data).size();
459 // This means we have moved forward by a road piece
460 if (newSubPosition >= subPositionDataSize)
461 {
462 if (!updateRoadMotionNewRoadPiece(component, result.flags, isVeh2UnkM15))
463 {
464 result.remainingDistance = component.remainingDistance - 0x3689;
465 component.remainingDistance = 0x3689;
466 result.flags |= UpdateVar1136114Flags::unk_m00;
467 break;
468 }
469 else
470 {
471 newSubPosition = 0;
472 }
473 }
474 // 0x0047C95B
475 component.subPosition = newSubPosition;
476 const auto& moveData = World::TrackData::getRoadSubPositon(component.trackAndDirection.road._data)[newSubPosition];
477 const auto nextNewPosition = moveData.loc + World::Pos3(component.tileX, component.tileY, component.tileBaseZ * World::kSmallZStep);
478 component.remainingDistance -= kMovementNibbleToDistance[getMovementNibble(intermediatePosition, nextNewPosition)];
479 intermediatePosition = nextNewPosition;
480 component.spriteYaw = moveData.yaw;
481 component.spritePitch = moveData.pitch;
482 if (component.isVehicleBogie())
483 {
484 // collision checks
485 auto collideResult = checkForCollisions(*component.asVehicleBogie(), intermediatePosition);
486 if (collideResult != EntityId::null)
487 {
488 result.flags |= UpdateVar1136114Flags::crashed;
489 result.collidedEntityId = collideResult;
490 }
491 }
492 }
493 if (hasMoved)
494 {
495 component.moveTo(intermediatePosition);
496 }
497 return result;
498 }
499
500 static UpdateMotionResult updateTrackMotion(VehicleBase& component, int32_t distance, bool isVeh2UnkM15)
501 {

Callers 2

updateRoadMethod · 0.85
updateTrackMotionFunction · 0.85

Calls 8

getRoadSubPositonFunction · 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