/// <summary> /// Determines the allowed vehicle types that may approach the given node from the given segment (lane-wise). /// </summary> /// <param name="segmentId"></param> /// <param name="nodeId"></param> /// <returns></returns> internal static Dictionary <byte, ExtVehicleType> GetAllowedVehicleTypesAsDict(ushort segmentId, ushort nodeId) { #if TRACE Singleton <CodeProfiler> .instance.Start("VehicleRestrictionsManager.GetAllowedVehicleTypesAsDict"); #endif Dictionary <byte, ExtVehicleType> ret = new Dictionary <byte, ExtVehicleType>(); NetManager netManager = Singleton <NetManager> .instance; if (segmentId == 0 || (netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.None || nodeId == 0 || (netManager.m_nodes.m_buffer[nodeId].m_flags & NetNode.Flags.Created) == NetNode.Flags.None) { #if TRACE Singleton <CodeProfiler> .instance.Stop("VehicleRestrictionsManager.GetAllowedVehicleTypesAsDict"); #endif return(ret); } var dir = NetInfo.Direction.Forward; var dir2 = ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) ? dir : NetInfo.InvertDirection(dir); var dir3 = TrafficPriority.IsLeftHandDrive() ? NetInfo.InvertDirection(dir2) : dir2; NetInfo segmentInfo = netManager.m_segments.m_buffer[segmentId].Info; uint curLaneId = netManager.m_segments.m_buffer[segmentId].m_lanes; int numLanes = segmentInfo.m_lanes.Length; uint laneIndex = 0; while (laneIndex < numLanes && curLaneId != 0u) { NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex]; ushort toNodeId = (laneInfo.m_direction == dir3) ? netManager.m_segments.m_buffer[segmentId].m_endNode : netManager.m_segments.m_buffer[segmentId].m_startNode; if (toNodeId == nodeId) { ExtVehicleType vehicleTypes = GetAllowedVehicleTypes(segmentId, segmentInfo, laneIndex, laneInfo); if (vehicleTypes != ExtVehicleType.None) { ret[(byte)laneIndex] = vehicleTypes; } } curLaneId = netManager.m_lanes.m_buffer[curLaneId].m_nextLane; ++laneIndex; } #if TRACE Singleton <CodeProfiler> .instance.Stop("VehicleRestrictionsManager.GetAllowedVehicleTypesAsDict"); #endif return(ret); }
/// <summary> /// Determines the allowed vehicle types that may approach the given node from the given segment. /// </summary> /// <param name="segmentId"></param> /// <param name="nodeId"></param> /// <returns></returns> internal static HashSet <ExtVehicleType> GetAllowedVehicleTypesAsSet(ushort segmentId, ushort nodeId) { HashSet <ExtVehicleType> ret = new HashSet <ExtVehicleType>(); NetManager netManager = Singleton <NetManager> .instance; if (segmentId == 0 || (netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.None || nodeId == 0 || (netManager.m_nodes.m_buffer[nodeId].m_flags & NetNode.Flags.Created) == NetNode.Flags.None) { return(ret); } var dir = NetInfo.Direction.Forward; var dir2 = ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) ? dir : NetInfo.InvertDirection(dir); var dir3 = TrafficPriority.IsLeftHandDrive() ? NetInfo.InvertDirection(dir2) : dir2; NetInfo segmentInfo = netManager.m_segments.m_buffer[segmentId].Info; uint curLaneId = netManager.m_segments.m_buffer[segmentId].m_lanes; int numLanes = segmentInfo.m_lanes.Length; uint laneIndex = 0; while (laneIndex < numLanes && curLaneId != 0u) { NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex]; ushort toNodeId = (laneInfo.m_direction == dir3) ? netManager.m_segments.m_buffer[segmentId].m_endNode : netManager.m_segments.m_buffer[segmentId].m_startNode; if (toNodeId == nodeId) { ret.Add(GetAllowedVehicleTypes(segmentId, laneIndex, curLaneId, laneInfo)); } curLaneId = netManager.m_lanes.m_buffer[curLaneId].m_nextLane; ++laneIndex; } return(ret); }