/// <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); } } }
/// <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(); }
/// <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(); }