private void getFrontAndRearNewLane(LaneProperties.direction dir, int newLane)
    {
        switch (dir)
        {
        case LaneProperties.direction.East:
            switch (newLane)
            {
            case 1:
                infrontVehicleNewLane = neighbours.neighbours[0];
                behindVehicleNewLane  = neighbours.neighbours[5];
                break;

            case -1:
                infrontVehicleNewLane = neighbours.neighbours[2];
                behindVehicleNewLane  = neighbours.neighbours[3];
                break;
            }
            break;

        case LaneProperties.direction.West:
            switch (newLane)
            {
            case 1:
                infrontVehicleNewLane = neighbours.neighbours[5];
                behindVehicleNewLane  = neighbours.neighbours[0];
                break;

            case -1:
                infrontVehicleNewLane = neighbours.neighbours[3];
                behindVehicleNewLane  = neighbours.neighbours[2];
                break;
            }
            break;
        }
    }
Example #2
0
    private string getVehicleNumText(LaneProperties.direction dir)
    {
        sb = new StringBuilder("Number of Vehicles: ");
        switch (dir)
        {
        case LaneProperties.direction.East:
            sb.AppendFormat("{0} Vehicles", motorwayStats.eastboundVehicleNum);
            break;

        case LaneProperties.direction.West:
            sb.AppendFormat("{0} Vehicles", motorwayStats.westboundVehicleNum);
            break;
        }
        return(sb.ToString());
    }
Example #3
0
    private string getAverageSpeedText(LaneProperties.direction dir)
    {
        sb = new StringBuilder("Average Speed: ");
        switch (dir)
        {
        case LaneProperties.direction.East:
            sb.AppendFormat("{0:F2} {1}", convertSpeed(motorwayStats.eastboundAverageSpeed), motorwayParameters.speedUnits);
            break;

        case LaneProperties.direction.West:
            sb.AppendFormat("{0:F2} {1}", convertSpeed(motorwayStats.westboundAverageSpeed), motorwayParameters.speedUnits);
            break;
        }
        return(sb.ToString());
    }
Example #4
0
    private string getDepartureRateText(LaneProperties.direction dir)
    {
        sb = new StringBuilder("Departure Rate: ");
        switch (dir)
        {
        case LaneProperties.direction.East:
            sb.AppendFormat("{0:F0} Vehicles Per Minute", motorwayStats.eastboundDepartureRate * 60f);
            break;

        case LaneProperties.direction.West:
            sb.AppendFormat("{0:F0} Vehicles Per Minute", motorwayStats.westboundDepartureRate * 60f);
            break;
        }
        return(sb.ToString());
    }
    private void getFrontAndRear(LaneProperties.direction dir)
    {
        switch (dir)
        {
        case LaneProperties.direction.East:
            infrontVehicle = neighbours.neighbours[1];
            behindVehicle  = neighbours.neighbours[4];

            break;

        case LaneProperties.direction.West:
            infrontVehicle = neighbours.neighbours[4];
            behindVehicle  = neighbours.neighbours[1];
            break;
        }
    }
Example #6
0
    private float startVel(LaneProperties.direction dir, int laneIndex)
    {
        switch (dir)
        {
        case LaneProperties.direction.East:
            if (laneProperties.vehicles.eastVehicles[laneIndex].Count > 0)
            {
                closestVehicle = laneProperties.vehicles.eastVehicles[laneIndex][0];
                for (int i = 1; i < laneProperties.vehicles.eastVehicles[laneIndex].Count; i++)
                {
                    if (laneProperties.vehicles.eastVehicles[laneIndex][i].transform.position.x <
                        closestVehicle.transform.position.x)
                    {
                        closestVehicle = laneProperties.vehicles.eastVehicles[laneIndex][i];
                    }
                }
            }
            else
            {
                return(Random.Range(motorwayParameters.speedLimit * 0.8f, motorwayParameters.speedLimit * 1.2f));
            }
            break;

        case LaneProperties.direction.West:
            if (laneProperties.vehicles.westVehicles[laneIndex].Count > 0)
            {
                closestVehicle = laneProperties.vehicles.westVehicles[laneIndex][0];
                for (int i = 1; i < laneProperties.vehicles.westVehicles[laneIndex].Count; i++)
                {
                    if (laneProperties.vehicles.westVehicles[laneIndex][i].transform.position.x <
                        closestVehicle.transform.position.x)
                    {
                        closestVehicle = laneProperties.vehicles.westVehicles[laneIndex][i];
                    }
                }
            }
            else
            {
                return(Random.Range(motorwayParameters.speedLimit * 0.8f, motorwayParameters.speedLimit * 1.2f));
            }
            break;
        }

        return(closestVehicle.GetComponent <VehicleProperties>().currentVel);
    }
    private GameObject getNorthEast(LaneProperties.direction dir, int lane)
    {
        closestVehicle   = null;
        possibleVehicles = new List <GameObject>();

        // Gets list of all vehicles
        if (parameters.lanesNum > 1)
        {
            switch (dir)
            {
            case LaneProperties.direction.East:
                allVehicles = vehicles.eastVehicles[lane + 1];
                break;

            case LaneProperties.direction.West:
                allVehicles = vehicles.westVehicles[lane - 1];
                break;
            }

            // Finds all vehicles with x >= to itself
            foreach (var vehicle in allVehicles)
            {
                if (vehicle.transform.position.x >= gameObject.transform.position.x)
                {
                    possibleVehicles.Add(vehicle);
                }
            }

            // Finds the closest of the vehicles with x >= than itself
            if (possibleVehicles.Count > 0)
            {
                closestVehicle = possibleVehicles[0];
                for (var i = 1; i < possibleVehicles.Count; i++)
                {
                    if (possibleVehicles[i].transform.position.x < closestVehicle.transform.position.x)
                    {
                        closestVehicle = possibleVehicles[i];
                    }
                }
            }
        }
        return(closestVehicle);
    }
    private GameObject getNorthWest(LaneProperties.direction dir, int lane)
    {
        closestVehicle   = null;
        possibleVehicles = new List <GameObject>();

        if (parameters.lanesNum > 1)
        {
            switch (dir)
            {
            case LaneProperties.direction.East:
                allVehicles = vehicles.eastVehicles[lane + 1];
                break;

            case LaneProperties.direction.West:
                allVehicles = vehicles.westVehicles[lane - 1];
                break;
            }

            foreach (var vehicle in allVehicles)
            {
                if (vehicle.transform.position.x < gameObject.transform.position.x)
                {
                    possibleVehicles.Add(vehicle);
                }
            }

            if (possibleVehicles.Count > 0)
            {
                closestVehicle = possibleVehicles[0];
                for (var i = 1; i < possibleVehicles.Count; i++)
                {
                    if (possibleVehicles[i].transform.position.x > closestVehicle.transform.position.x)
                    {
                        closestVehicle = possibleVehicles[i];
                    }
                }
            }
        }

        return(closestVehicle);
    }
    private void changeLane(int laneIndex, LaneProperties.direction dir)
    {
        switch (dir)
        {
        case LaneProperties.direction.East:
            vehicles.eastVehicles[vehicleProperties.currentLane].Remove(gameObject);
            vehicles.eastVehicles[laneIndex].Add(gameObject);
            vehicleProperties.currentLane = laneIndex;
            newYPos      = lanes.eastLanes[laneIndex].GetComponent <LaneProperties>().yPos;
            changingLane = true;
            break;

        case LaneProperties.direction.West:
            vehicles.westVehicles[vehicleProperties.currentLane].Remove(gameObject);
            vehicles.westVehicles[laneIndex].Add(gameObject);
            vehicleProperties.currentLane = laneIndex;
            newYPos      = lanes.westLanes[laneIndex].GetComponent <LaneProperties>().yPos;
            changingLane = true;
            break;
        }
    }