void HandleIntersectionRouting() { FastList <NodeLaneMarker> nodeMarkers; if (m_nodeMarkers.TryGetValue(m_selectedNode, out nodeMarkers)) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); NodeLaneMarker hoveredMarker = null; Bounds bounds = new Bounds(Vector3.zero, Vector3.one); for (int i = 0; i < nodeMarkers.m_size; i++) { NodeLaneMarker marker = nodeMarkers.m_buffer[i]; if (!IsActive(marker)) { continue; } bounds.center = marker.m_position; if (bounds.IntersectRay(mouseRay)) { hoveredMarker = marker; marker.m_size = 2f; } else { marker.m_size = 1f; } } if (hoveredMarker != null && Input.GetMouseButtonUp(0)) { if (m_selectedMarker == null) { m_selectedMarker = hoveredMarker; } else if (LaneManager.RemoveLaneConnection(m_selectedMarker.m_lane, hoveredMarker.m_lane)) { m_selectedMarker.m_connections.Remove(hoveredMarker); } else if (LaneManager.AddLaneConnection(m_selectedMarker.m_lane, hoveredMarker.m_lane)) { m_selectedMarker.m_connections.Add(hoveredMarker); } } } if (Input.GetMouseButtonUp(1)) { if (m_selectedMarker != null) { m_selectedMarker = null; } else { m_selectedNode = 0; } } }
public float GetCurrentSpeedRestrictions() { if (!AnyLaneSelected) { return(-1f); } return(LaneManager.GetLaneSpeedRestriction(m_selectedLaneMarkers[0].m_lane)); }
public ExtendedVehicleType GetCurrentVehicleRestrictions() { if (!AnyLaneSelected) { return(ExtendedVehicleType.None); } return(LaneManager.GetVehicleRestrictions(m_selectedLaneMarkers[0].m_lane)); }
public void SetSpeedRestrictions(int speed) { if (!AnyLaneSelected) { return; } foreach (SegmentLaneMarker lane in m_selectedLaneMarkers) { LaneManager.SetLaneSpeedRestriction(lane.m_lane, speed); } }
protected override void CalculateSegmentPosition(ushort vehicleID, ref Vehicle vehicleData, PathUnit.Position position, uint laneID, byte offset, out Vector3 pos, out Vector3 dir, out float maxSpeed) { NetManager instance = Singleton <NetManager> .instance; instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection((float)offset * 0.003921569f, out pos, out dir); NetInfo info = instance.m_segments.m_buffer[(int)position.m_segment].Info; if (info.m_lanes != null && info.m_lanes.Length > (int)position.m_lane) { maxSpeed = this.CalculateTargetSpeed(vehicleID, ref vehicleData, LaneManager.GetLaneSpeed(laneID, info.m_lanes[(int)position.m_lane]), instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_curve); } else { maxSpeed = this.CalculateTargetSpeed(vehicleID, ref vehicleData, 1f, 0f); } }
public ExtendedVehicleType ToggleRestriction(ExtendedVehicleType vehicleType) { if (!AnyLaneSelected) { return(ExtendedVehicleType.None); } ExtendedVehicleType vehicleRestrictions = LaneManager.GetVehicleRestrictions(m_selectedLaneMarkers[0].m_lane); vehicleRestrictions ^= vehicleType; foreach (SegmentLaneMarker lane in m_selectedLaneMarkers) { LaneManager.SetVehicleRestrictions(lane.m_lane, vehicleRestrictions); } return(vehicleRestrictions); }
protected override void CalculateSegmentPosition(ushort vehicleID, ref Vehicle vehicleData, PathUnit.Position nextPosition, PathUnit.Position position, uint laneID, byte offset, PathUnit.Position prevPos, uint prevLaneID, byte prevOffset, int index, out Vector3 pos, out Vector3 dir, out float maxSpeed) { NetManager instance = Singleton <NetManager> .instance; instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection((float)offset * 0.003921569f, out pos, out dir); Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData(); Vector3 position2 = lastFrameData.m_position; Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].CalculatePosition((float)prevOffset * 0.003921569f); float num = 0.5f * lastFrameData.m_velocity.sqrMagnitude / this.m_info.m_braking + this.m_info.m_generatedInfo.m_size.z * 0.5f; if (Vector3.Distance(position2, b) >= num - 1f) { Segment3 segment; segment.a = pos; ushort num2; ushort num3; if (offset < position.m_offset) { segment.b = pos + dir.normalized * this.m_info.m_generatedInfo.m_size.z; num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode; num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode; } else { segment.b = pos - dir.normalized * this.m_info.m_generatedInfo.m_size.z; num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode; num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode; } ushort num4; if (prevOffset == 0) { num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_startNode; } else { num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_endNode; } if (num2 == num4) { NetNode.Flags flags = instance.m_nodes.m_buffer[(int)num2].m_flags; NetLane.Flags flags2 = (NetLane.Flags)instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_flags; bool flag = (flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None; bool flag2 = (flags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None; bool flag3 = (flags2 & NetLane.Flags.JoinedJunction) != NetLane.Flags.None; if ((flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) == NetNode.Flags.Junction && instance.m_nodes.m_buffer[(int)num2].CountSegments() != 2) { float len = vehicleData.CalculateTotalLength(vehicleID) + 2f; if (!instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CheckSpace(len)) { bool flag4 = false; if (nextPosition.m_segment != 0 && instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_length < 30f) { NetNode.Flags flags3 = instance.m_nodes.m_buffer[(int)num3].m_flags; if ((flags3 & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) != NetNode.Flags.Junction || instance.m_nodes.m_buffer[(int)num3].CountSegments() == 2) { uint laneID2 = PathManager.GetLaneID(nextPosition); if (laneID2 != 0u) { flag4 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID2)].CheckSpace(len); } } } if (!flag4) { maxSpeed = 0f; return; } } } if (flag && (!flag3 || flag2)) { uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex; uint num5 = (uint)(((int)num4 << 8) / 32768); uint num6 = currentFrameIndex - num5 & 255u; NetInfo info = instance.m_nodes.m_buffer[(int)num2].Info; RoadBaseAI.TrafficLightState vehicleLightState; RoadBaseAI.TrafficLightState pedestrianLightState; bool flag5; bool pedestrians; RoadBaseAI.GetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, out vehicleLightState, out pedestrianLightState, out flag5, out pedestrians); if (!flag5 && num6 >= 196u) { flag5 = true; RoadBaseAI.SetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, vehicleLightState, pedestrianLightState, flag5, pedestrians); } if ((vehicleData.m_flags & Vehicle.Flags.Emergency2) == 0 || info.m_class.m_service != ItemClass.Service.Road) { switch (vehicleLightState) { case RoadBaseAI.TrafficLightState.RedToGreen: if (num6 < 60u) { maxSpeed = 0f; return; } break; case RoadBaseAI.TrafficLightState.Red: maxSpeed = 0f; return; case RoadBaseAI.TrafficLightState.GreenToRed: if (num6 >= 30u) { maxSpeed = 0f; return; } break; } } } } } NetInfo info2 = instance.m_segments.m_buffer[(int)position.m_segment].Info; if (info2.m_lanes != null && info2.m_lanes.Length > (int)position.m_lane) { maxSpeed = this.CalculateTargetSpeed(vehicleID, ref vehicleData, LaneManager.GetLaneSpeed(laneID, info2.m_lanes[(int)position.m_lane]), instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_curve); } else { maxSpeed = this.CalculateTargetSpeed(vehicleID, ref vehicleData, 1f, 0f); } if (instance.m_treatWetAsSnow) { DistrictManager instance2 = Singleton <DistrictManager> .instance; byte district = instance2.GetDistrict(pos); DistrictPolicies.CityPlanning cityPlanningPolicies = instance2.m_districts.m_buffer[(int)district].m_cityPlanningPolicies; if ((cityPlanningPolicies & DistrictPolicies.CityPlanning.StuddedTires) != DistrictPolicies.CityPlanning.None) { maxSpeed *= 1f - (float)instance.m_segments.m_buffer[(int)position.m_segment].m_wetness * 0.0005882353f; District[] expr_5C2_cp_0 = instance2.m_districts.m_buffer; byte expr_5C2_cp_1 = district; expr_5C2_cp_0[(int)expr_5C2_cp_1].m_cityPlanningPoliciesEffect = (expr_5C2_cp_0[(int)expr_5C2_cp_1].m_cityPlanningPoliciesEffect | DistrictPolicies.CityPlanning.StuddedTires); } else { maxSpeed *= 1f - (float)instance.m_segments.m_buffer[(int)position.m_segment].m_wetness * 0.00117647066f; } } else { maxSpeed *= 1f - (float)instance.m_segments.m_buffer[(int)position.m_segment].m_wetness * 0.0005882353f; } maxSpeed *= 1f + (float)instance.m_segments.m_buffer[(int)position.m_segment].m_condition * 0.0005882353f; }
void SetNodeMarkers(ushort nodeId, FastList <NodeLaneMarker> nodeMarkers) { NetNode node = NetManager.instance.m_nodes.m_buffer[nodeId]; int offsetMultiplier = node.CountSegments() <= 2 ? 3 : 1; ushort segmentId = node.m_segment0; for (int i = 0; i < 8 && segmentId != 0; i++) { NetSegment segment = NetManager.instance.m_segments.m_buffer[segmentId]; bool isEndNode = segment.m_endNode == nodeId; Vector3 offset = segment.FindDirection(segmentId, nodeId) * offsetMultiplier; NetInfo.Lane[] lanes = segment.Info.m_lanes; uint laneId = segment.m_lanes; for (int j = 0; j < lanes.Length && laneId != 0; j++) { //if ((lanes[j].m_laneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle)) != NetInfo.LaneType.None) if ((lanes[j].m_laneType & NetInfo.LaneType.Vehicle) == NetInfo.LaneType.Vehicle) { Vector3 pos = Vector3.zero; NetInfo.Direction laneDir = ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) ? lanes[j].m_finalDirection : NetInfo.InvertDirection(lanes[j].m_finalDirection); bool isSource = false; if (isEndNode) { if ((laneDir & (NetInfo.Direction.Forward | NetInfo.Direction.Avoid)) == NetInfo.Direction.Forward) { isSource = true; } pos = NetManager.instance.m_lanes.m_buffer[laneId].m_bezier.d; } else { if ((laneDir & (NetInfo.Direction.Backward | NetInfo.Direction.Avoid)) == NetInfo.Direction.Backward) { isSource = true; } pos = NetManager.instance.m_lanes.m_buffer[laneId].m_bezier.a; } nodeMarkers.Add(new NodeLaneMarker() { m_lane = laneId, m_node = nodeId, m_position = pos + offset, m_color = colors[nodeMarkers.m_size], m_isSource = isSource, }); } laneId = NetManager.instance.m_lanes.m_buffer[laneId].m_nextLane; } segmentId = segment.GetRightSegment(nodeId); if (segmentId == node.m_segment0) { segmentId = 0; } } for (int i = 0; i < nodeMarkers.m_size; i++) { if (!nodeMarkers.m_buffer[i].m_isSource) { continue; } uint[] connections = LaneManager.GetLaneConnections(nodeMarkers.m_buffer[i].m_lane); if (connections == null || connections.Length == 0) { continue; } for (int j = 0; j < nodeMarkers.m_size; j++) { if (nodeMarkers.m_buffer[j].m_isSource) { continue; } if (connections.Contains(nodeMarkers.m_buffer[j].m_lane)) { nodeMarkers.m_buffer[i].m_connections.Add(nodeMarkers.m_buffer[j]); } } } }