Skip to content

Commit

Permalink
Merge pull request #233 from krzychu124/112-traffic-using-one-lane-on…
Browse files Browse the repository at this point in the history
…-highways

#112: Cars using only one lane on highways
  • Loading branch information
krzychu124 committed Mar 14, 2019
2 parents 2b7db7a + 81c3173 commit 3e25819
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
25 changes: 11 additions & 14 deletions TLM/TLM/Custom/PathFinding/CustomPathFind2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,12 @@ private enum LaneChangingCostCalculationMode {
prevIsCenterPlatform = prevLaneInfo.m_centerPlatform;
prevIsElevated = prevLaneInfo.m_elevated;

#if ADVANCEDAI && ROUTING
#if (ADVANCEDAI || PARKINGAI) && ROUTING
// NON-STOCK CODE START
if (Options.advancedAI) {
prevIsCarLane =
(prevLaneInfo.m_laneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle)) != NetInfo.LaneType.None &&
(prevLaneInfo.m_vehicleType & VehicleInfo.VehicleType.Car) != VehicleInfo.VehicleType.None
;
}
prevIsCarLane =
(prevLaneInfo.m_laneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle)) != NetInfo.LaneType.None &&
(prevLaneInfo.m_vehicleType & VehicleInfo.VehicleType.Car) != VehicleInfo.VehicleType.None
;
// NON-STOCK CODE END
#endif

Expand Down Expand Up @@ -1461,7 +1459,7 @@ private enum LaneChangingCostCalculationMode {
#if ADVANCEDAI
, enableAdvancedAI, laneChangingCost,
#endif
segmentSelectionCost, laneSelectionCost, nextNodeId, ref nextNode, false, m_routingManager.segmentRoutings[prevSegmentId], m_routingManager.laneEndBackwardRoutings[laneRoutingIndex], connectOffset
segmentSelectionCost, laneSelectionCost, nextNodeId, ref nextNode, false, m_routingManager.segmentRoutings[prevSegmentId], m_routingManager.laneEndBackwardRoutings[laneRoutingIndex], connectOffset, prevRelSimilarLaneIndex
)) {
exploreUturn = true; // allow exceptional u-turns
}
Expand Down Expand Up @@ -1954,7 +1952,7 @@ private enum LaneChangingCostCalculationMode {
offsetLength *= laneSelectionCost;
#if DEBUG
if (debug) {
Debug(unitId, item, nextSegmentId, $"ProcessItemCosts: Applyied custom selection cost factors\n"
Debug(unitId, item, nextSegmentId, $"ProcessItemCosts: Applied custom selection cost factors\n"
+ "\t" + $"offsetLength={offsetLength}"
);
}
Expand Down Expand Up @@ -2590,7 +2588,7 @@ private enum LaneChangingCostCalculationMode {
#if ADVANCEDAI
bool enableAdvancedAI, float laneChangingCost,
#endif
float segmentSelectionCost, float laneSelectionCost, ushort nextNodeId, ref NetNode nextNode, bool isMiddle, SegmentRoutingData prevSegmentRouting, LaneEndRoutingData prevLaneEndRouting, byte connectOffset
float segmentSelectionCost, float laneSelectionCost, ushort nextNodeId, ref NetNode nextNode, bool isMiddle, SegmentRoutingData prevSegmentRouting, LaneEndRoutingData prevLaneEndRouting, byte connectOffset, int prevInnerSimilarLaneIndex
) {

#if DEBUG
Expand All @@ -2609,6 +2607,7 @@ private enum LaneChangingCostCalculationMode {
+ "\t" + $"prevSegmentRouting={prevSegmentRouting}\n"
+ "\t" + $"prevLaneEndRouting={prevLaneEndRouting}\n"
+ "\t" + $"connectOffset={connectOffset}\n"
+ "\t" + $"prevInnerSimilarLaneIndex={prevInnerSimilarLaneIndex}\n"
);
}
#endif
Expand Down Expand Up @@ -2852,12 +2851,11 @@ private enum LaneChangingCostCalculationMode {
uturnExplored = true;
}

bool isStockUturnPoint = (nextNode.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None;
// allow vehicles to ignore strict lane routing when moving off
bool relaxedLaneRouting =
m_isRoadVehicle &&
((!m_queueItem.spawned || (m_queueItem.vehicleType & (ExtVehicleType.PublicTransport | ExtVehicleType.Emergency)) != ExtVehicleType.None) &&
(laneTransitions[k].laneId == m_startLaneA || laneTransitions[k].laneId == m_startLaneB)) || isStockUturnPoint;
(laneTransitions[k].laneId == m_startLaneA || laneTransitions[k].laneId == m_startLaneB));

#if DEBUG
if (debug) {
Expand Down Expand Up @@ -2902,7 +2900,6 @@ private enum LaneChangingCostCalculationMode {
}
#endif

int dummy = -1; // not required when using custom routing
if (
ProcessItemCosts(
#if DEBUG
Expand All @@ -2912,7 +2909,7 @@ private enum LaneChangingCostCalculationMode {
#if ADVANCEDAI
enableAdvancedAI, laneChangingCost,
#endif
nextNodeId, ref nextNode, isMiddle, nextSegmentId, ref netManager.m_segments.m_buffer[nextSegmentId], segmentSelectionCost, laneSelectionCost, laneTransitions[k], ref dummy, connectOffset, true, false
nextNodeId, ref nextNode, isMiddle, nextSegmentId, ref netManager.m_segments.m_buffer[nextSegmentId], segmentSelectionCost, laneSelectionCost, laneTransitions[k], ref prevInnerSimilarLaneIndex, connectOffset, true, false
)
) {
blocked = true;
Expand Down
16 changes: 9 additions & 7 deletions TLM/TLM/Manager/Impl/RoutingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,16 +1128,18 @@ public class RoutingManager : AbstractGeometryObservingManager, IRoutingManager
continue; // disregard lane since it has outgoing connections
}

if (nextIncomingDir == ArrowDirection.Turn) {
if (
nextIncomingDir == ArrowDirection.Turn && // u-turn
!nextIsEndOrOneWayOut && // not a dead end
nextCompatibleOuterSimilarIndex != maxNextCompatibleOuterSimilarIndex // incoming lane is not innermost lane
) {
// force u-turns to happen on the innermost lane
if (nextCompatibleOuterSimilarIndex != maxNextCompatibleOuterSimilarIndex) {
++compatibleLaneDist;
nextCompatibleTransitionDatas[nextTransitionIndex].type = LaneEndTransitionType.Relaxed;
++compatibleLaneDist;
nextCompatibleTransitionDatas[nextTransitionIndex].type = LaneEndTransitionType.Relaxed;
#if DEBUGROUTING
if (debugFine)
Log._Debug($"RoutingManager.RecalculateLaneEndRoutingData({segmentId}, {laneIndex}, {laneId}, {startNode}): Next lane ({nextCompatibleTransitionDatas[nextTransitionIndex].laneId}) is avoided u-turn. Incrementing compatible lane distance to {compatibleLaneDist}");
if (debugFine)
Log._Debug($"RoutingManager.RecalculateLaneEndRoutingData({segmentId}, {laneIndex}, {laneId}, {startNode}): Next lane ({nextCompatibleTransitionDatas[nextTransitionIndex].laneId}) is avoided u-turn. Incrementing compatible lane distance to {compatibleLaneDist}");
#endif
}
}

#if DEBUGROUTING
Expand Down

0 comments on commit 3e25819

Please sign in to comment.