diff --git a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs index 07ba97e50..9f074950b 100644 --- a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs +++ b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs @@ -553,7 +553,7 @@ public static bool GetSortedSegments(ushort nodeId, out List segments) { /// /// /// determines for which side to connect lanes. - /// false if there is only one incomming/outgoing lane, true otherwise + /// true if any lanes were connectde, false otherwise public static bool StayInLane(ushort nodeId, StayInLaneMode mode = StayInLaneMode.None) { Log._Debug($"Stay In Lane called node:{nodeId} mode:{mode}"); LaneConnectionManager.Instance.RemoveLaneConnectionsFromNode(nodeId); @@ -629,12 +629,12 @@ private static bool StayInLane( // count relavent source(going toward the junction) lanes and // target (going aginst the junction) lanes on each segment. - int laneCountMinorSource = minorSegmentId == 0 ? 0 : PriorityRoad.CountLanesTowardJunction(minorSegmentId, nodeId); - int laneCountMinorTarget = minorSegmentId == 0 ? 0 : PriorityRoad.CountLanesAgainstJunction(minorSegmentId, nodeId); - int laneCountMinor2Source = minorSegment2Id == 0 ? 0 : PriorityRoad.CountLanesTowardJunction(minorSegment2Id, nodeId); - int laneCountMinor2Target = minorSegment2Id == 0 ? 0 : PriorityRoad.CountLanesAgainstJunction(minorSegment2Id, nodeId); - int laneCountMainSource = PriorityRoad.CountLanesTowardJunction(mainSegmentSourceId, nodeId); - int laneCountMainTarget = PriorityRoad.CountLanesAgainstJunction(mainSegmentTargetId, nodeId); + int laneCountMinorSource = minorSegmentId == 0 ? 0 : CountLanesTowardJunction(minorSegmentId, nodeId); + int laneCountMinorTarget = minorSegmentId == 0 ? 0 : CountLanesAgainstJunction(minorSegmentId, nodeId); + int laneCountMinor2Source = minorSegment2Id == 0 ? 0 : CountLanesTowardJunction(minorSegment2Id, nodeId); + int laneCountMinor2Target = minorSegment2Id == 0 ? 0 : CountLanesAgainstJunction(minorSegment2Id, nodeId); + int laneCountMainSource = CountLanesTowardJunction(mainSegmentSourceId, nodeId); + int laneCountMainTarget = CountLanesAgainstJunction(mainSegmentTargetId, nodeId); int totalSource = laneCountMinorSource + laneCountMainSource + laneCountMinor2Source; int totalTarget = laneCountMinorTarget + laneCountMainTarget + laneCountMinor2Target; @@ -779,6 +779,20 @@ bool ConnectToMinor2(int sourceIdx, int targetIdx) { return true; } + private static int CountLanes(ushort segmentId, ushort nodeId, bool toward) { + return netService.GetSortedLanes( + segmentId, + ref segmentId.ToSegment(), + netService.IsStartNode(segmentId, nodeId) ^ (!toward), + LaneConnectionManager.LANE_TYPES, + LaneConnectionManager.VEHICLE_TYPES, + true + ).Count; + } + internal static int CountLanesTowardJunction(ushort segmentId, ushort nodeId) => CountLanes(segmentId, nodeId, true); + internal static int CountLanesAgainstJunction(ushort segmentId, ushort nodeId) => CountLanes(segmentId, nodeId, false); + + public override void OnPrimaryClickOverlay() { #if DEBUG bool logLaneConn = DebugSwitch.LaneConnections.Get();