Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#112: Cars using only one lane on highways #233

Merged
merged 3 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2569,7 +2567,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 @@ -2588,6 +2586,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 @@ -2831,12 +2830,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 @@ -2881,7 +2879,6 @@ private enum LaneChangingCostCalculationMode {
}
#endif

int dummy = -1; // not required when using custom routing
if (
ProcessItemCosts(
#if DEBUG
Expand All @@ -2891,7 +2888,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 @@ -1121,16 +1121,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