示例#1
0
    // check lights during an emergency
    private void CheckMoveInEmergency()
    {
        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
            {
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("East to West") &&
                    zEast.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnZ.Remove(vehicle);
                    break;
                }
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("West to East") &&
                    zWest.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnZ.Remove(vehicle);
                    break;
                }
                vehicle.Stop();
            }
        }

        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
            {
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("South to North") &&
                    xSouth.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnX.Remove(vehicle);
                    break;
                }
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("North to South") &&
                    xNorth.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnX.Remove(vehicle);
                    break;
                }
                vehicle.Stop();
            }
        }
    }
示例#2
0
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.GetComponent <CarBackCollider>() == null)
     {
         return;
     }
     _parent.Continue();
 }
示例#3
0
 // make sure that vehicle has been removed from list
 public void CheckRemoveZ(VehicleBehaviour vehicle)
 {
     if (!_vehiclesOnZ.Contains(vehicle))
     {
         return;
     }
     print(vehicle.gameObject.name + " not removed from Z list in " + gameObject.name);
     if (vehicle.CompareTag("firebrigade"))
     {
         vehicle.Continue();
     }
     _vehiclesOnX.Remove(vehicle);
 }
示例#4
0
 // stop traffic on X but allow right crossing cars to pass
 // if they have been waiting
 private void StopTrafficOnX()
 {
     if (GetComponentInChildren <TrafficLightControl>().GetAllRed() && GetComponentInChildren <TrafficLightControl>().PreviousLightGreenX)
     {
         for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
         {
             VehicleBehaviour vehicle = _vehiclesOnX[i];
             if (!vehicle.RightCross)
             {
                 continue;
             }
             vehicle.Continue();
             _vehiclesOnX.Remove(vehicle);
         }
     }
     foreach (VehicleBehaviour vehicle in _vehiclesOnX)
     {
         vehicle.Stop();
     }
 }
    // move vehicles if able
    private void MoveVehicles()
    {
        for (int i = _vehiclesTurning.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesTurning[i];
            if (Handler.IsSomethingOnFire && vehicle.CompareTag("firebrigade"))
            {
                vehicle.SetNextRoad();
                vehicle.Continue();
                _vehiclesTurning.Remove(vehicle);
                continue;
            }
            if (vehicle.NextRoad == null)
            {
                vehicle.SetNextRoad();
            }

            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    vehicle.SetNextRoad();
                }
            }

            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            else if (vehicle.LeftJunctionLeave || vehicle.IsGoingStraightAtJunction)
            {
                _vehiclesTurning.Remove(vehicle);
            }
            else if (vehicle.RightJunctionCrossing)
            {
                if (_rightLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
            else if (vehicle.RightJunctionJoin)
            {
                if (_rightLane.TrafficInLane || _leftLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
            else if (vehicle.LeftJunctionJoin)
            {
                if (_rightLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
        }
    }
示例#6
0
    // move traffic on Z if the coast is clear
    private void MoveTrafficOnZ()
    {
        int vehiclesTurningRight = 0;

        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            if (vehicle.NextRoad == null)
            {
                vehicle.SetNextRoad();
            }
            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    print(vehicle.gameObject.name + " setting another road on " + gameObject.name);
                    vehicle.SetNextRoad();
                }
            }
            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            else if (vehicle.IsGoingStraightAtCross || vehicle.LeftCross ||
                     vehicle.IsGoingStraightAtJunction || vehicle.LeftJunctionLeave)
            {
                foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
                {
                    if (!ReferenceEquals(lightStop.VehicleAtLight, vehicle))
                    {
                        continue;
                    }
                    if (((vehicle.IsGoingStraightAtCross || vehicle.IsGoingStraightAtJunction) && !lightStop.StraightOn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        ((vehicle.LeftCross || vehicle.LeftJunctionLeave) && !lightStop.LeftTurn.TrafficInLane && !lightStop.Front.TrafficInLane)
                        )
                    {
                        vehicle.Continue();
                        _vehiclesOnZ.Remove(vehicle);
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
            else
            {
                foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
                {
                    if (lightStop.CrossLane == null)
                    {
                        continue;
                    }
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && !lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehicle.Continue();
                        _vehiclesOnZ.Remove(vehicle);
                        break;
                    }

                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehiclesTurningRight++;
                        vehicle.Stop();
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
        }

        if (vehiclesTurningRight != 2)
        {
            return;
        }
        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            vehicle.Continue();
            _vehiclesOnZ.Remove(vehicle);
        }
    }
示例#7
0
    // move traffic on X if the coast is clear
    private void MoveTrafficOnX()
    {
        int vehiclesTurningRight = 0;

        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            if (vehicle.NextRoad == null && !vehicle.IsUnableToMove)
            {
                vehicle.SetNextRoad();
            }
            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    vehicle.SetNextRoad();
                }
            }
            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            if (!vehicle.RightCross)
            {
                foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
                {
                    if (!ReferenceEquals(lightStop.VehicleAtLight, vehicle))
                    {
                        continue;
                    }
                    if ((vehicle.IsGoingStraightAtCross && !lightStop.StraightOn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        (vehicle.LeftCross && !lightStop.LeftTurn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        (vehicle.LeftJunctionJoin && !lightStop.LeftTurn.TrafficInLane) ||
                        (vehicle.RightJunctionJoin && !lightStop.RightTurn.TrafficInLane)
                        )
                    {
                        vehicle.Continue();
                        _vehiclesOnX.Remove(vehicle);
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
            else
            {
                foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
                {
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && !lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehicle.Continue();
                        _vehiclesOnX.Remove(vehicle);
                        break;
                    }
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehiclesTurningRight++;
                        vehicle.Stop();
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
        }

        if (vehiclesTurningRight != 2)
        {
            return;
        }
        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            vehicle.Continue();
            _vehiclesOnX.Remove(vehicle);
        }
    }