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

Function findAllUsableTrackPieces

src/OpenLoco/src/Vehicles/Routing.cpp:519–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517 // Iterates all individual tiles of a track piece to find tracks that need inspection
518 template<typename FilterFunction>
519 static void findAllUsableTrackPieces(LocationOfInterestQueue& additionalTrackToCheck, const TrackNetworkSearchFlags searchFlags, const LocationOfInterest& interest, FilterFunction&& filterFunction, RoutingResults& results)
520 {
521 if ((searchFlags & TrackNetworkSearchFlags::unk2) == TrackNetworkSearchFlags::none)
522 {
523 return;
524 }
525
526 const auto tad = interest.tad();
527 auto nextLoc = interest.loc;
528 if (tad.isReversed())
529 {
530 auto& trackSize = World::TrackData::getUnkTrack(tad._data);
531 nextLoc += trackSize.pos;
532 if (trackSize.rotationEnd < 12)
533 {
534 nextLoc -= World::Pos3{ World::kRotationOffset[trackSize.rotationEnd], 0 };
535 }
536 }
537
538 for (auto& piece : World::TrackData::getTrackPiece(tad.id()))
539 {
540 const auto connectFlags = piece.connectFlags[tad.cardinalDirection()];
541 const auto pieceLoc = nextLoc + World::Pos3{ Math::Vector::rotate(World::Pos2{ piece.x, piece.y }, tad.cardinalDirection()), piece.z };
542 auto tile = World::TileManager::get(pieceLoc);
543 for (auto& el : tile)
544 {
545 if (el.baseZ() != pieceLoc.z / 4)
546 {
547 continue;
548 }
549
550 auto* elTrack = el.as<TrackElement>();
551 if (elTrack == nullptr)
552 {
553 continue;
554 }
555
556 if (elTrack->isAiAllocated() || elTrack->isGhost())
557 {
558 continue;
559 }
560
561 const auto& targetPiece = World::TrackData::getTrackPiece(elTrack->trackId())[elTrack->sequenceIndex()];
562 const auto targetConnectFlags = targetPiece.connectFlags[elTrack->rotation()];
563 if ((targetConnectFlags & connectFlags) == 0)
564 {
565 continue;
566 }
567
568 // If identical then no need to keep checking
569 if (elTrack->rotation() == tad.cardinalDirection()
570 && elTrack->sequenceIndex() == piece.index
571 && elTrack->trackObjectId() == interest.trackType
572 && elTrack->trackId() == tad.id())
573 {
574 continue;
575 }
576

Callers 1

Calls 15

getTrackPieceFunction · 0.85
tadMethod · 0.80
baseZMethod · 0.80
isAiAllocatedMethod · 0.80
trackIdMethod · 0.80
trackObjectIdMethod · 0.80
baseHeightMethod · 0.80
tryAddMethod · 0.80
push_backMethod · 0.80
rotateFunction · 0.50
getFunction · 0.50
isReversedMethod · 0.45

Tested by

no test coverage detected