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;
}
}
Aggregations