public void PreProcess(ref LaneInfo inLanes, ref JunctionInfo nodeInfo) { int inLaneCount = inLanes.GetLaneCount(); int inBusLaneCount = inLanes.GetBusLaneCount(); if (inLaneCount == inBusLaneCount) { //If all IN lanes are bus lanes, all IN and OUT lanes are treated as normal car lanes. return; } int outLaneCount = nodeInfo.GetLaneCount(); int outBusLaneCount = nodeInfo.GetBusLaneCount(); if (outLaneCount == outBusLaneCount) { //If all OUT lanes are bus lanes, all IN and OUT lanes are also treated as normal car lanes. return; } // If the number of IN car lanes is greater than OUT car lanes, then OUT bus lanes are also treated as normal car lanes. bool applyOutLaneRules = (inLaneCount - inBusLaneCount) <= (outLaneCount - outBusLaneCount); // Pre-process IN lanes int i = 0; var posToRemove = new List <float>(); foreach (var lane in inLanes.lanes) { if (inLanes.busLaneIds.Contains(lane.Value)) { inBusLanes.Add(lane.Key, lane.Value); inBusLaneIndices.Add(i); inLanes.busLaneIds.Remove(lane.Value); posToRemove.Add(lane.Key); } i += 1; } foreach (var pos in posToRemove) { inLanes.lanes.Remove(pos); } // Pre-process OUT lanes if (applyOutLaneRules) { outBusLaneIndices = nodeInfo.GetBusLaneIndices(); outBusLaneDirections = nodeInfo.RemoveLanes(outBusLaneIndices); } }
public static void AssignLanes(LaneInfo inLanes, Vector3 outVector, ushort segmentID, ushort nodeID, NetNode junctionNode, bool lht) { var nodeInfo = AnalyseNode(junctionNode, nodeID, segmentID, vehicleLaneTypes, VehicleInfo.VehicleType.Car, outVector); if (nodeInfo.GetLaneCount() == 0) { // This can happen if multiple one-way roads meet creating a dead end. return; } if (lht) { inLanes.Mirror(); nodeInfo.Mirror(); } var busLaneHandler = new BusLaneHandler(); busLaneHandler.PreProcess(ref inLanes, ref nodeInfo); AdjustSharpTurns(inLanes.GetLaneCount(), ref nodeInfo); List <LaneConnectionInfo> lanesInfo = AssignLanes(inLanes.lanes.Count, nodeInfo.laneCounts[Direction.Left], nodeInfo.laneCounts[Direction.Forward], nodeInfo.laneCounts[Direction.Right]); AccountForSharpTurnLanes(ref lanesInfo, (byte)nodeInfo.laneCounts[Direction.SharpLeft], (byte)nodeInfo.laneCounts[Direction.SharpRight]); busLaneHandler.PostProcess(ref inLanes, ref lanesInfo); if (lht) { inLanes.Mirror(); LHTHandler.Mirror(ref lanesInfo); } int i = 0; NetManager netManager = Singleton <NetManager> .instance; foreach (var lane in inLanes.lanes) { var laneInfo = lanesInfo[i]; var laneId = lane.Value; // Note: NetLane is a value type netManager.m_lanes.m_buffer[laneId].m_firstTarget = (byte)(laneInfo.firstTarget); netManager.m_lanes.m_buffer[laneId].m_lastTarget = (byte)(laneInfo.lastTarget + 1); NetLane.Flags flags = (NetLane.Flags)netManager.m_lanes.m_buffer[laneId].m_flags; flags &= noDirections; flags |= laneInfo.direction; netManager.m_lanes.m_buffer[laneId].m_flags = (ushort)flags; i += 1; } }