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

Fix stay-in-lane for MOM tracks #919

Merged
merged 1 commit into from
Jun 2, 2020
Merged
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
28 changes: 21 additions & 7 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public static bool GetSortedSegments(ushort nodeId, out List<ushort> segments) {
/// </summary>
/// <param name="nodeId"></param>
/// <param name="mode">determines for which side to connect lanes.</param>
/// <returns><c>false</c> if there is only one incomming/outgoing lane, <c>true</c> otherwise</returns>
/// <returns><c>true</c> if any lanes were connectde, <c>false</c> otherwise</returns>
public static bool StayInLane(ushort nodeId, StayInLaneMode mode = StayInLaneMode.None) {
Log._Debug($"Stay In Lane called node:{nodeId} mode:{mode}");
LaneConnectionManager.Instance.RemoveLaneConnectionsFromNode(nodeId);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down