예제 #1
0
    /// <summary>
    /// returns the nearest storage
    /// </summary>
    public void findNearestStorage()
    {
        closestStorage = pathFinderManager.FindNearestGrid(workGrid, mapGrid.getStorages(), mapGrid);

        List <GameObject> workers = getSelectedWorkers();

        foreach (GameObject worker in workers)
        {
            if (worker.GetComponent <Worker>().isLumberjack())
            {
                worker.GetComponent <Worker>().setClosestStorage(closestStorage);
                worker.GetComponent <Worker>().startWorking(true);
            }
        }
    }
예제 #2
0
    /// <summary>
    /// finds the closest iron and sends current workers to it, and destroys itself
    /// </summary>
    public void findNearestIronOre()
    {
        mapGrid.removeIronOres(gridOn);

        PathFinderManager pathFinderManager = player.getSpawner().getPathFinderManager().GetComponent <PathFinderManager>();

        Grid nextIronOre = pathFinderManager.FindNearestGrid(gridOn, mapGrid.getIronOres(), mapGrid);

        List <Unit> unitsC = new List <Unit>(units);

        for (int i = 0; i < unitsC.Count; i++)
        {
            nextIronOre.getBlockingObject().GetComponent <IronOre>().addUnit(unitsC[i]);
            if (unitsC[i].GetComponent <Worker>().isIronOreMiner())
            {
                unitsC[i].GetComponent <Worker>().setWorkGrid(nextIronOre, "ironOre");
                if (unitsC[i].GetComponent <Worker>().getWorkPhase() == 1 && !unitsC[i].GetComponent <Worker>().isIronOreFull())
                {
                    unitsC[i].GetComponent <Worker>().startWorking(false);
                    unitsC[i].GetComponent <Worker>().startWorking(true);
                }
            }
        }

        destroyIronOre();
    }
예제 #3
0
파일: Tree.cs 프로젝트: LionKirchler/Spiel
    /// <summary>
    /// finds the closest tree, sends the workers to it, and destroyes this tree
    /// </summary>
    public void findNearestTree()
    {
        mapGrid.removeTree(gridOn);

        PathFinderManager pathFinderManager = player.getSpawner().getPathFinderManager().GetComponent <PathFinderManager>();

        nextTree = pathFinderManager.FindNearestGrid(gridOn, mapGrid.getTrees(), mapGrid);

        List <Unit> unitsC = new List <Unit>(units);

        for (int i = 0; i < unitsC.Count; i++)
        {
            nextTree.getBlockingObject().GetComponent <Tree>().addUnit(unitsC[i]);
            if (unitsC[i].GetComponent <Worker>().isLumberjack())
            {
                unitsC[i].GetComponent <Worker>().setWorkGrid(nextTree, "wood");
                if (unitsC[i].GetComponent <Worker>().getWorkPhase() == 1 && !unitsC[i].GetComponent <Worker>().isWoodFull())
                {
                    unitsC[i].GetComponent <Worker>().startWorking(false);
                    unitsC[i].GetComponent <Worker>().startWorking(true);
                }
            }
        }

        destroyTree();
    }