public bool HasTrafficLight(ushort nodeId, ref NetNode node) { return(LogicUtil.CheckFlags( (uint)node.m_flags, (uint)(NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.TrafficLights), (uint)(NetNode.Flags.Created | NetNode.Flags.TrafficLights))); }
public void TestCheckFlags1() { Assert.IsTrue( LogicUtil.CheckFlags( (uint)(NetSegment.Flags.Created | NetSegment.Flags.Deleted), (uint)NetSegment.Flags.Created)); }
public void TestCheckFlags2() { Assert.IsFalse( LogicUtil.CheckFlags( (uint)(NetSegment.Flags.Created | NetSegment.Flags.Deleted), (uint)NetSegment.Flags.Collapsed)); }
public bool CheckLaneFlags(uint laneId, NetLane.Flags flagMask, NetLane.Flags?expectedResult = null) { bool ret = false; ProcessLane(laneId, delegate(uint lId, ref NetLane lane) { ret = LogicUtil.CheckFlags((uint)lane.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckSegmentFlags(ushort segmentId, NetSegment.Flags flagMask, NetSegment.Flags?expectedResult = null) { bool ret = false; ProcessSegment(segmentId, delegate(ushort sId, ref NetSegment segment) { ret = LogicUtil.CheckFlags((uint)segment.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckNodeFlags(ushort nodeId, NetNode.Flags flagMask, NetNode.Flags?expectedResult = null) { bool ret = false; ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) { ret = LogicUtil.CheckFlags((uint)node.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckVehicleFlags2(ushort vehicleId, Vehicle.Flags2 flagMask, Vehicle.Flags2?expectedResult = default(Vehicle.Flags2?)) { bool ret = false; ProcessVehicle(vehicleId, delegate(ushort vId, ref Vehicle vehicle) { ret = LogicUtil.CheckFlags((uint)vehicle.m_flags2, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckCitizenInstanceFlags(ushort citizenInstanceId, CitizenInstance.Flags flagMask, CitizenInstance.Flags?expectedResult = default(CitizenInstance.Flags?)) { bool ret = false; ProcessCitizenInstance(citizenInstanceId, delegate(ushort ciId, ref CitizenInstance citizenInstance) { ret = LogicUtil.CheckFlags((uint)citizenInstance.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckCitizenFlags(uint citizenId, Citizen.Flags flagMask, Citizen.Flags?expectedResult = default(Citizen.Flags?)) { bool ret = false; ProcessCitizen(citizenId, delegate(uint cId, ref Citizen citizen) { ret = LogicUtil.CheckFlags((uint)citizen.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckBuildingFlags(ushort buildingId, Building.Flags flagMask, Building.Flags?expectedResult = default(Building.Flags?)) { bool ret = false; ProcessBuilding(buildingId, delegate(ushort bId, ref Building building) { ret = LogicUtil.CheckFlags((uint)building.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CheckUnitFlags(uint unitId, byte flagMask, byte?expectedResult = null) { bool ret = false; ProcessUnit(unitId, delegate(uint uId, ref PathUnit unit) { ret = LogicUtil.CheckFlags((uint)unit.m_pathFindFlags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool MayHaveJunctionRestrictions(ushort nodeId) { NetNode.Flags flags = NetNode.Flags.None; Services.NetService.ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) { flags = node.m_flags; return(true); }); if (LogicUtil.CheckFlags((uint)flags, (uint)(NetNode.Flags.Created | NetNode.Flags.Deleted), (uint)NetNode.Flags.Created)) { return(false); } return(LogicUtil.CheckFlags((uint)flags, (uint)(NetNode.Flags.Junction | NetNode.Flags.Bend))); }
public bool CheckVehicleFlags(ushort vehicleId, Vehicle.Flags flagMask, Vehicle.Flags?expectedResult = default) { bool ret = false; ProcessVehicle( vehicleId, (ushort vId, ref Vehicle vehicle) => { ret = LogicUtil.CheckFlags( (uint)vehicle.m_flags, (uint)flagMask, (uint?)expectedResult); return(true); }); return(ret); }
public bool CanToggleTrafficLight(ushort nodeId, bool flag, ref NetNode node, out ToggleTrafficLightError reason) { #if DEBUG bool logTrafficLights = DebugSwitch.TimedTrafficLights.Get() && DebugSettings.NodeId == nodeId; #else const bool logTrafficLights = false; #endif if (!flag && TrafficLightSimulationManager.Instance.HasTimedSimulation(nodeId)) { reason = ToggleTrafficLightError.HasTimedLight; if (logTrafficLights) { Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Node has a timed traffic light"); } return(false); } if (flag && !LogicUtil.CheckFlags( (uint)node.m_flags, (uint)(NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.Junction), (uint)(NetNode.Flags.Created | NetNode.Flags.Junction))) { reason = ToggleTrafficLightError.NoJunction; if (logTrafficLights) { Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Node is not a junction"); } return(false); } if (!flag && LogicUtil.CheckFlags( (uint)node.m_flags, (uint)NetNode.Flags.LevelCrossing, (uint)NetNode.Flags.LevelCrossing)) { reason = ToggleTrafficLightError.IsLevelCrossing; if (logTrafficLights) { Log._Debug($"Cannot toggle traffic lights at node {nodeId}: Node is a level crossing"); } return(false); } int numRoads = 0; int numTrainTracks = 0; int numMonorailTracks = 0; int numPedSegments = 0; Services.NetService.IterateNodeSegments( nodeId, (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 (logTrafficLights) { Log._DebugFormat( "Can toggle traffic lights at node {0}: numRoads={1} numTrainTracks={2} " + "numMonorailTracks={3} numPedSegments={4}", nodeId, numRoads, numTrainTracks, numMonorailTracks, numPedSegments); } reason = ToggleTrafficLightError.None; return(true); } if (logTrafficLights) { Log._DebugFormat( "Cannot toggle traffic lights at node {0}: Insufficient segments. numRoads={1} " + "numTrainTracks={2} numMonorailTracks={3} numPedSegments={4}", nodeId, numRoads, numTrainTracks, numMonorailTracks, numPedSegments); } reason = ToggleTrafficLightError.InsufficientSegments; return(false); }
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); }