| 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 |
no test coverage detected