diff --git a/TLM/TLM/Custom/PathFinding/CustomPathFind2.cs b/TLM/TLM/Custom/PathFinding/CustomPathFind2.cs index df8e513b3..02438bf50 100644 --- a/TLM/TLM/Custom/PathFinding/CustomPathFind2.cs +++ b/TLM/TLM/Custom/PathFinding/CustomPathFind2.cs @@ -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 @@ -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 } @@ -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}" ); } @@ -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 @@ -2609,6 +2607,7 @@ private enum LaneChangingCostCalculationMode { + "\t" + $"prevSegmentRouting={prevSegmentRouting}\n" + "\t" + $"prevLaneEndRouting={prevLaneEndRouting}\n" + "\t" + $"connectOffset={connectOffset}\n" + + "\t" + $"prevInnerSimilarLaneIndex={prevInnerSimilarLaneIndex}\n" ); } #endif @@ -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) { @@ -2902,7 +2900,6 @@ private enum LaneChangingCostCalculationMode { } #endif - int dummy = -1; // not required when using custom routing if ( ProcessItemCosts( #if DEBUG @@ -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; diff --git a/TLM/TLM/Manager/Impl/RoutingManager.cs b/TLM/TLM/Manager/Impl/RoutingManager.cs index eb5fd5eca..a4fc04c40 100644 --- a/TLM/TLM/Manager/Impl/RoutingManager.cs +++ b/TLM/TLM/Manager/Impl/RoutingManager.cs @@ -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