private IEnumerator StartRetrieval()
    {
        GameObject   gameController = GameObject.FindWithTag("GameController");
        ScenarioMgr  scenarioMgr    = gameController.GetComponent("ScenarioMgr") as ScenarioMgr;
        ScenarioData scenarioInfo   = scenarioMgr.GetInfo();

        // first lets find the possible places to go
        GameObject[] stores = GameObject.FindGameObjectsWithTag("Store");
        if (stores.Length > 0)
        {
            //Debug.Log("found some stores");
            List <IntPoint2D> startTiles = scenarioInfo.GetAdjacentRoadTiles(myData.GetLoc());
            List <IntPoint2D> endTiles;
            //bestPath;// = new Stack<IntPoint2D>();

            StoreManager bestmgr = null;
            foreach (GameObject store in stores)
            {
                //  get the store manager
                StoreManager mgr = store.GetComponent("StoreManager") as StoreManager;
                // see if there's available capacity
                if (mgr.GetGoodsAmt() > 0)
                {
                    // get adjacent roads
                    endTiles = scenarioInfo.GetAdjacentRoadTiles(mgr.GetLoc());
                    Stack <IntPoint2D> path = scenarioInfo.ShortestPath(startTiles, endTiles);
                    if (path.Count > 0 && (bestPath.Count == 0 || path.Count < bestPath.Count))
                    {
                        bestPath = path;
                        bestmgr  = mgr;
                    }
                }
                yield return(null);
            }

            gettingResource2 = false;
            if (bestPath.Count > 0)
            {
                IntPoint2D start = bestPath.Pop();
                GetGoods(start, bestPath, bestmgr, scenarioInfo);
                gettingResource2 = true;
            }
        }
        yield return(null);
    }
Beispiel #2
0
    private bool GetPathToStore()
    {
        List <IntPoint2D> startTiles = new List <IntPoint2D> ();

        startTiles.Add(curTile);
        List <IntPoint2D>  endTiles = scenarioInfo.GetAdjacentRoadTiles(destStore.GetLoc());
        Stack <IntPoint2D> newPath  = scenarioInfo.ShortestPath(startTiles, endTiles);

        if (newPath.Count > 0)
        {
            newPath.Pop();
            path = newPath;
            return(true);
        }
        else
        {
            return(GetPathToAllStores());
        }
    }
    private bool StartDelivery()
    {
        // first lets find the possible places to go
        GameObject[] stores = GameObject.FindGameObjectsWithTag("Store");
        if (stores.Length > 0)
        {
            Debug.Log("found some stores");
            List <IntPoint2D>  startTiles = scenarioInfo.GetAdjacentRoadTiles(centerTile);
            List <IntPoint2D>  endTiles;
            Stack <IntPoint2D> bestPath = new Stack <IntPoint2D> ();
            StoreManager       bestmgr  = null;
            foreach (GameObject store in stores)
            {
                //  get the store manager
                StoreManager mgr = store.GetComponent("StoreManager") as StoreManager;
                // see if there's available capacity
                if (mgr.GetRoom() > 0)
                {
                    // get adjacent roads
                    endTiles = scenarioInfo.GetAdjacentRoadTiles(mgr.GetLoc());
                    Stack <IntPoint2D> path = scenarioInfo.ShortestPath(startTiles, endTiles);
                    if (path.Count > 0 && (bestPath.Count == 0 || path.Count < bestPath.Count))
                    {
                        bestPath = path;
                        bestmgr  = mgr;
                    }
                }
            }

            bool deliveryStarted = false;
            if (bestPath.Count > 0)
            {
                IntPoint2D start = bestPath.Pop();
                DoDelivery(start, bestPath, bestmgr);
                deliveryStarted = true;
            }
            return(deliveryStarted);
        }
        else
        {
            return(false);
        }
    }