| 303 | } |
| 304 | |
| 305 | static bool updateTrackMotionNewTrackPiece(VehicleBase& component, UpdateVar1136114Flags& flags, bool isVeh2UnkM15) |
| 306 | { |
| 307 | auto newRoutingHandle = component.routingHandle; |
| 308 | auto newIndex = newRoutingHandle.getIndex() + 1; |
| 309 | newRoutingHandle.setIndex(newIndex); |
| 310 | const auto routing = RoutingManager::getRouting(newRoutingHandle); |
| 311 | if (routing != RoutingManager::kAllocatedButFreeRouting) |
| 312 | { |
| 313 | Vehicle train(component.head); |
| 314 | if (isVeh2UnkM15) |
| 315 | { |
| 316 | if (train.veh1->routingHandle == component.routingHandle) |
| 317 | { |
| 318 | flags |= UpdateVar1136114Flags::unk_m03; |
| 319 | return false; |
| 320 | } |
| 321 | } |
| 322 | World::Pos3 pos(component.tileX, component.tileY, component.tileBaseZ * World::kSmallZStep); |
| 323 | |
| 324 | auto [nextPos, nextRot] = World::Track::getTrackConnectionEnd(pos, component.trackAndDirection.track._data); |
| 325 | const auto tc = World::Track::getTrackConnections(nextPos, nextRot, component.owner, component.trackType, train.head->var_53, 0); |
| 326 | if (tc.hasLevelCrossing) |
| 327 | { |
| 328 | flags |= UpdateVar1136114Flags::approachingGradeCrossing; |
| 329 | } |
| 330 | bool routingFound = false; |
| 331 | for (auto& connection : tc.connections) |
| 332 | { |
| 333 | if ((connection & World::Track::AdditionalTaDFlags::basicTaDMask) == (routing & World::Track::AdditionalTaDFlags::basicTaDMask)) |
| 334 | { |
| 335 | routingFound = true; |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | if (!routingFound) |
| 340 | { |
| 341 | flags |= UpdateVar1136114Flags::noRouteFound; |
| 342 | return false; |
| 343 | } |
| 344 | component.routingHandle = newRoutingHandle; |
| 345 | const auto oldTaD = component.trackAndDirection.track._data; |
| 346 | component.trackAndDirection.track._data = routing & World::Track::AdditionalTaDFlags::basicTaDMask; |
| 347 | pos += World::TrackData::getUnkTrack(oldTaD).pos; |
| 348 | component.tileX = pos.x; |
| 349 | component.tileY = pos.y; |
| 350 | component.tileBaseZ = pos.z / World::kSmallZStep; |
| 351 | return true; |
| 352 | } |
| 353 | |
| 354 | return false; |
| 355 | } |
| 356 | |
| 357 | // If candidate within 8 vehicle components of src we ignore a self collision |
| 358 | // TODO: If we stored the car index this could be simplified |
no test coverage detected