Ejemplo n.º 1
0
    IEnumerator buildPaths()
    {
        while (!mapIsReady)
        {
            yield return(null);
        }
        Unit requestee = null;
        bool building  = false;

        while (true)
        {
            if (vPath == null && !building && pathRequestQueue.Count > 0)
            {
                print("Queue count: " + pathRequestQueue.Count);
                building = true;
                PathRequest req = pathRequestQueue[0];
                requestee = req.requestee;
                pathRequestQueue.RemoveAt(0);
                //aStar = new PathFinder(req.start, req.end, req.occupied, req.size);

                if (req.specialCode == 0)
                {
                    //print("Starting regular");
                    aStarA2 = null;
                    aStar   = new PathFinderV2(req);
                    StartCoroutine(RunAStar());
                }
                else if (req.specialCode == 1)
                {
                    //print("Starting A1");
                    aStar   = null;
                    aStarA2 = new PathFinderA2(req);
                    //aStarA1.requestPath(req.start, req.end, req.requestee.size, req.requestee.occCode);
                    StartCoroutine(RunAStarA1());
                }
                else
                {
                    print("Req attribute code: " + req.specialCode);
                }
                yield return(null);
            }
            else if (building && vPath != null)
            {
                building = false;
                requestee.getPath(vPath);

                /*foreach (Node n in testList)
                 * {
                 *  GameObject g = Instantiate(nodeMarker);
                 *  g.transform.position = n.position;
                 *  g.transform.localScale = Vector3.one * length;
                 * }*/
                vPath   = null;
                aStar   = null;
                aStarA2 = null;
                yield return(null);
            }
            else if (building)
            {
                if (aStar != null && aStar.failed)
                {
                    //print("Failed to find path a1");
                    vPath    = null;
                    building = false;
                    aStar    = null;
                }
                else if (aStarA2 != null && aStarA2.failed)
                {
                    //print("Failed to find path a2");
                    vPath    = null;
                    building = false;
                    aStarA2  = null;
                }
            }
            yield return(null);
        }
    }
Ejemplo n.º 2
0
    IEnumerator buildPathsV2()
    {
        while (!mapIsReady)
        {
            yield return(null);
        }
        //print("Started building paths");
        while (true)
        {
            if (pathRequests.Count > 0)
            {
                List <List <Vector3> > destinations = new List <List <Vector3> >();
                for (int i = 0; i < pathRequests[0].requests.Count; i++)
                {
                    PathRequest req = pathRequests[0].requests[i];

                    //Start pathfinding
                    if (req.specialCode == 0)
                    {
                        PathFinderV2 astar = new PathFinderV2(req);
                        while (!astar.done && !astar.failed)
                        {
                            yield return(null);
                        }
                        if (astar.failed)
                        {
                            pathRequests[0].requests.Remove(req);
                            print("Pathfinding failed");
                            continue;
                        }
                        else
                        {
                            destinations.Add(astar.vPath);
                        }
                    }
                    else if (req.specialCode == 1)
                    {
                        PathFinderA1 astar = new PathFinderA1(req);
                        while (!astar.done && !astar.failed)
                        {
                            yield return(null);
                        }
                        if (astar.failed)
                        {
                            pathRequests[0].requests.Remove(req);
                            print("Pathfinding failed");
                            continue;
                        }
                        else
                        {
                            destinations.Add(astar.vPath);
                        }
                    }
                }
                for (int i = 0; i < destinations.Count; i++)
                {
                    //print(destinations[i].Count);
                    pathRequests[0].requestees[i].getPath(destinations[i]);
                }
                pathRequests.RemoveAt(0);
                yield return(null);
            }
            yield return(null);
        }
    }
Ejemplo n.º 3
0
 private void Awake()
 {
     main = this;
 }