Search in sources :

Example 6 with SCV

use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.

the class ChooseRepairer method execute.

@Override
public State execute() {
    try {
        SCV closestWorker = null;
        Position chosen = gameState.chosenUnitRepair.getPosition();
        int frame = gameState.frameCount;
        for (Worker u : gameState.workerIdle) {
            if (u.getLastCommandFrame() == frame)
                continue;
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                closestWorker = (SCV) u;
            }
        }
        for (Worker u : gameState.workerMining.keySet()) {
            if (u.getLastCommandFrame() == frame)
                continue;
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                closestWorker = (SCV) u;
            }
        }
        if (closestWorker != null) {
            gameState.chosenRepairer = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV) Worker(org.openbw.bwapi4j.unit.Worker)

Aggregations

SCV (org.openbw.bwapi4j.unit.SCV)6 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 MutablePair (ecgberht.Util.MutablePair)3 Position (org.openbw.bwapi4j.Position)3 TilePosition (org.openbw.bwapi4j.TilePosition)3 Area (bwem.Area)2 Unit (org.openbw.bwapi4j.unit.Unit)2 Base (bwem.Base)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)1 Worker (org.openbw.bwapi4j.unit.Worker)1