void setTargetNode()
    {
        if (currentNode.ways.Count != 0)
        {
            // have to randomize them later.
            Vector3 targetPosition = currentNode.ways[Random.Range(0, currentNode.ways.Count)];

            // if there are multiple path connect give less weightage to where car came from..
            if (currentNode.ways.Count > 1)
            {
                bool accept = false;
                while (!accept)
                {
                    if (targetPosition == previousLocation)
                    {
                        int chance = Random.Range(0, 5);
                        if (chance == 3)
                        {
                            accept = true;
                        }
                        else
                        {
                            targetPosition = currentNode.ways[Random.Range(0, currentNode.ways.Count)];
                        }
                    }
                    else
                    {
                        accept = true;
                    }
                }
            }
            List <Node> nodeList = SimController.nodeList;
            targetNode = nodeList.Find(node => (node.location == targetPosition));
        }
        else
        {
            targetNode = currentNode;
        }

        speedReductionFactor = SimController.getRoadTraffic(targetNode.location, currentNode.location);
    }
Beispiel #2
0
    void addCarToRoadAndNodeList()
    {
        MPACColonyRoadList = new List <Road> ();
        MPACColonyNodeList = new List <Node> ();
        foreach (Road road in SimController.roadList)
        {
            MPACColonyRoadList.Add(road);
        }

        //// NODE LIST
        foreach (Node node in SimController.nodeList)
        {
            Node      n    = new Node(node.location);
            Vector3[] ways = (Vector3[])node.ways.ToArray().Clone();
            n.ways.AddRange(ways);
            MPACColonyNodeList.Add(n);
        }

        // add all the cars on the map as seperate roads...
        foreach (GameObject car in CarGenerator.carList)
        {
            Vector3 carTarget  = car.transform.GetComponent <carController_new> ().targetNode.location;
            Vector3 carCurrent = car.transform.GetComponent <carController_new> ().currentNode.location;
            // add the road from car to target node....
            Road  r           = new Road(car.transform.position, carTarget);
            float trafficLoad = SimController.getRoadTraffic(carTarget, carCurrent);
            r.TrafficLoad = trafficLoad;
            MPACColonyRoadList.Add(r);

            // add a new node for car and set only one way to the target location.
            Node carNode = new Node(car.transform.position);
            carNode.ways.Add(carTarget);
            MPACColonyNodeList.Add(carNode);
            // add a new way to car in the target node...
            int carTargetIndex = MPACColonyNodeList.FindIndex(node => node.location == carTarget);
            MPACColonyNodeList [carTargetIndex].ways.Add(car.transform.position);
        }
    }