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

Function findAllUsableRoadInNetwork

src/OpenLoco/src/Vehicles/Routing.cpp:791–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789 // 0x00479DB1
790 template<typename FilterFunction>
791 static void findAllUsableRoadInNetwork(LocationOfInterestQueue& additionalRoadToCheck, const TrackNetworkSearchFlags searchFlags, const LocationOfInterest& initialInterest, FilterFunction&& filterFunction, RoutingResults& results)
792 {
793 const auto [roadEndLoc, roadEndRotation] = World::Track::getRoadConnectionEnd(initialInterest.loc, initialInterest.rad()._data);
794 auto tc = World::Track::getRoadConnections(roadEndLoc, roadEndRotation, initialInterest.company, initialInterest.trackType, 0, 0);
795
796 if (!tc.connections.empty())
797 {
798 for (auto c : tc.connections)
799 {
800 uint16_t trackAndDirection2 = c & World::Track::AdditionalTaDFlags::basicRaDWithSignalMask;
801 LocationOfInterest interest{ roadEndLoc, trackAndDirection2, initialInterest.company, initialInterest.trackType };
802 if (results.reachableLocs.tryAdd(interest))
803 {
804 if (!filterFunction(interest))
805 {
806 findAllUsableRoadPieces(additionalRoadToCheck, searchFlags, interest, filterFunction, results);
807 additionalRoadToCheck.push_back(interest);
808 }
809 }
810 }
811 }
812 else
813 {
814 results.hasDeadEnd = true;
815 }
816
817 if ((searchFlags & TrackNetworkSearchFlags::excludeReverseDirection) == TrackNetworkSearchFlags::none)
818 {
819 // odd logic here clearing a flag in a branch that can never hit
820 auto nextLoc = initialInterest.loc;
821 auto& roadSize = World::TrackData::getUnkRoad(initialInterest.rad()._data);
822 nextLoc += roadSize.pos;
823 if (roadSize.rotationEnd < 12)
824 {
825 nextLoc -= World::Pos3{ World::kRotationOffset[roadSize.rotationEnd], 0 };
826 }
827
828 const auto rotation = World::kReverseRotation[roadSize.rotationEnd];
829 auto tc2 = World::Track::getRoadConnections(nextLoc, rotation, initialInterest.company, initialInterest.trackType, 0, 0);
830 for (auto c : tc2.connections)
831 {
832 uint16_t trackAndDirection2 = c & World::Track::AdditionalTaDFlags::basicRaDWithSignalMask;
833 LocationOfInterest interest{ nextLoc, trackAndDirection2, initialInterest.company, initialInterest.trackType };
834 if (results.reachableLocs.tryAdd(interest))
835 {
836 if (!filterFunction(interest))
837 {
838 findAllUsableRoadPieces(additionalRoadToCheck, searchFlags, interest, filterFunction, results);
839 additionalRoadToCheck.push_back(interest);
840 }
841 }
842 }
843 }
844 }
845
846 template<typename FilterFunction, typename TransformFunction>
847 static void findAllRoadsFilterTransform(RoutingResults& results, TrackNetworkSearchFlags searchFlags, const World::Pos3& loc, const TrackAndDirection::_RoadAndDirection trackAndDirection, const CompanyId company, const uint8_t trackType, FilterFunction&& filterFunction, TransformFunction&& transformFunction)

Callers 1

Calls 7

getRoadConnectionEndFunction · 0.85
getRoadConnectionsFunction · 0.85
findAllUsableRoadPiecesFunction · 0.85
radMethod · 0.80
tryAddMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected