public bool SetTrafficLight(ushort nodeId, bool flag, ref NetNode node, out UnableReason reason)
        {
#if DEBUGTTL
            if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
            {
                Log._Debug($"TrafficLightManager.SetTrafficLight: called for node {nodeId}, flag={flag}");
            }
#endif
            if (!IsTrafficLightToggleable(nodeId, flag, ref node, out reason))
            {
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"TrafficLightManager.SetTrafficLight: Traffic light @ {nodeId} is not toggleable");
                }
#endif
                if (reason != UnableReason.HasTimedLight || !flag)
                {
#if DEBUGTTL
                    if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                    {
                        Log._Debug($"TrafficLightManager.SetTrafficLight: ... but has timed light and we want to enable it");
                    }
#endif
                    return(false);
                }
            }

            NetNode.Flags flags = node.m_flags | NetNode.Flags.CustomTrafficLights;
            if ((bool)flag)
            {
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"Adding traffic light @ node {nodeId}");
                }
#endif
                flags |= NetNode.Flags.TrafficLights;
                TrafficPriorityManager.Instance.RemovePrioritySignsFromNode(nodeId);
            }
            else
            {
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"Removing traffic light @ node {nodeId}");
                }
#endif
                flags &= ~NetNode.Flags.TrafficLights;
            }
#if DEBUGTTL
            if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
            {
                Log._Debug($"TrafficLightManager.SetTrafficLight: Setting traffic light at node {nodeId} -- flags={flags}");
            }
#endif
            node.m_flags = flags;
            Constants.ManagerFactory.GeometryManager.MarkAsUpdated(NodeGeometry.Get(nodeId), true);
            return(true);
        }
Esempio n. 2
0
        public bool IsTrafficLightEnablable(ushort nodeId, ref NetNode node, out UnableReason reason)
        {
            bool ret = IsTrafficLightToggleable(nodeId, ref node, out reason);

            if (reason == UnableReason.HasTimedLight)
            {
                reason = UnableReason.None;
                return(true);
            }
            return(ret);
        }
Esempio n. 3
0
 public bool AddTrafficLight(ushort nodeId, ref NetNode node, out UnableReason reason)
 {
     TrafficPriorityManager.Instance.RemovePrioritySignsFromNode(nodeId);
     return(SetTrafficLight(nodeId, true, ref node, out reason));
 }
Esempio n. 4
0
        public bool IsTrafficLightToggleable(ushort nodeId, ref NetNode node, out UnableReason reason)
        {
            if (TrafficLightSimulationManager.Instance.HasTimedSimulation(nodeId))
            {
                reason = UnableReason.HasTimedLight;
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Node has a timed traffic light");
                }
#endif
                return(false);
            }

            if (!LogicUtil.CheckFlags((uint)node.m_flags, (uint)(NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.Junction), (uint)(NetNode.Flags.Created | NetNode.Flags.Junction)))
            {
                reason = UnableReason.NoJunction;
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Node is not a junction");
                }
#endif
                return(false);
            }

            int numRoads          = 0;
            int numTrainTracks    = 0;
            int numMonorailTracks = 0;
            int numPedSegments    = 0;
            Services.NetService.IterateNodeSegments(nodeId, delegate(ushort segmentId, ref NetSegment segment) {
                NetInfo info = segment.Info;
                if (info.m_class.m_service == ItemClass.Service.Road)
                {
                    ++numRoads;
                }
                else if ((info.m_vehicleTypes & VehicleInfo.VehicleType.Train) != VehicleInfo.VehicleType.None)
                {
                    ++numTrainTracks;
                }
                else if ((info.m_vehicleTypes & VehicleInfo.VehicleType.Monorail) != VehicleInfo.VehicleType.None)
                {
                    ++numMonorailTracks;
                }
                if (info.m_hasPedestrianLanes)
                {
                    ++numPedSegments;
                }

                return(true);
            });

            if (numRoads >= 2 || numTrainTracks >= 2 || numMonorailTracks >= 2 || numPedSegments != 0)
            {
#if DEBUGTTL
                if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
                {
                    Log._Debug($"Can toggle traffic lights at node {nodeId}: numRoads={numRoads} numTrainTracks={numTrainTracks} numMonorailTracks={numMonorailTracks} numPedSegments={numPedSegments}");
                }
#endif
                reason = UnableReason.None;
                return(true);
            }

#if DEBUGTTL
            if (GlobalConfig.Instance.Debug.Switches[7] && GlobalConfig.Instance.Debug.NodeId == nodeId)
            {
                Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Insufficient segments. numRoads={numRoads} numTrainTracks={numTrainTracks} numMonorailTracks={numMonorailTracks} numPedSegments={numPedSegments}");
            }
#endif
            reason = UnableReason.InsufficientSegments;
            return(false);
        }
Esempio n. 5
0
 public bool ToggleTrafficLight(ushort nodeId, ref NetNode node, out UnableReason reason)
 {
     return(SetTrafficLight(nodeId, !HasTrafficLight(nodeId, ref node), ref node, out reason));
 }
Esempio n. 6
0
 public bool RemoveTrafficLight(ushort nodeId, ref NetNode node, out UnableReason reason)
 {
     return(SetTrafficLight(nodeId, false, ref node, out reason));
 }
 public bool IsTrafficLightEnablable(ushort nodeId, ref NetNode node, out UnableReason reason)
 {
     return(IsTrafficLightToggleable(nodeId, true, ref node, out reason));
 }