0x004B1876
| 376 | |
| 377 | // 0x004B1876 |
| 378 | EntityId checkForCollisions(VehicleBogie& bogie, World::Pos3& loc) |
| 379 | { |
| 380 | if (bogie.mode != TransportMode::rail) |
| 381 | { |
| 382 | return EntityId::null; |
| 383 | } |
| 384 | |
| 385 | Vehicle srcTrain(bogie.head); |
| 386 | |
| 387 | for (const auto& nearby : kMooreNeighbourhood) |
| 388 | { |
| 389 | const auto inspectionPos = World::toTileSpace(loc) + nearby; |
| 390 | for (auto* entity : EntityManager::EntityTileList(World::toWorldSpace(inspectionPos))) |
| 391 | { |
| 392 | auto* vehicleBase = entity->asBase<VehicleBase>(); |
| 393 | if (vehicleBase == nullptr || vehicleBase == &bogie) |
| 394 | { |
| 395 | continue; |
| 396 | } |
| 397 | if (vehicleBase->getTransportMode() != TransportMode::rail) |
| 398 | { |
| 399 | continue; |
| 400 | } |
| 401 | |
| 402 | const auto zDiff = std::abs(loc.z - vehicleBase->position.z); |
| 403 | if (zDiff > 16) |
| 404 | { |
| 405 | continue; |
| 406 | } |
| 407 | |
| 408 | // vanilla did some overflow checks here but since we promote to int it shouldn't be needed |
| 409 | const auto distance = Math::Vector::manhattanDistance2D(vehicleBase->position, loc); |
| 410 | if (distance >= 12) |
| 411 | { |
| 412 | continue; |
| 413 | } |
| 414 | |
| 415 | const auto subType = vehicleBase->getSubType(); |
| 416 | // Does it actually have a collidable body |
| 417 | if (subType != VehicleEntityType::body_continued && subType != VehicleEntityType::body_start && subType != VehicleEntityType::bogie) |
| 418 | { |
| 419 | continue; |
| 420 | } |
| 421 | |
| 422 | if (vehicleBase->owner != bogie.owner) |
| 423 | { |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | // This is an optimisation compared to vanilla |
| 428 | if (vehicleBase->getHead() != bogie.head) |
| 429 | { |
| 430 | return vehicleBase->id; |
| 431 | } |
| 432 | |
| 433 | if (ignoreSelfCollision(bogie, *vehicleBase)) |
| 434 | { |
| 435 | continue; |
no test coverage detected