use of bwapi.Unit in project Ecgberht by Jabbo16.
the class CollectMineral method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenWorker;
if (!((GameState) this.handler).mineralsAssigned.isEmpty()) {
Unit closestMineral = null;
for (Entry<Unit, Integer> m : ((GameState) this.handler).mineralsAssigned.entrySet()) {
if ((closestMineral == null || chosen.getDistance(m.getKey()) < chosen.getDistance(closestMineral)) && m.getValue() < 2) {
closestMineral = m.getKey();
}
}
if (closestMineral != null) {
((GameState) this.handler).mineralsAssigned.put(closestMineral, ((GameState) this.handler).mineralsAssigned.get(closestMineral) + 1);
((GameState) this.handler).workerIdle.remove(chosen);
((GameState) this.handler).workerMining.put(chosen, closestMineral);
chosen.gather(closestMineral, false);
((GameState) this.handler).chosenWorker = null;
((GameState) this.handler).mining++;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseRepairer method execute.
@Override
public State execute() {
try {
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).chosenBuildingRepair.getPosition();
int frame = ((GameState) this.handler).frameCount;
for (Unit u : ((GameState) this.handler).workerIdle) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
if (closestWorker != null) {
((GameState) this.handler).chosenRepairer = closestWorker;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class Repair method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenRepairer.repair(((GameState) this.handler).chosenBuildingRepair)) {
if (((GameState) this.handler).workerIdle.contains(((GameState) this.handler).chosenRepairer)) {
((GameState) this.handler).workerIdle.remove(((GameState) this.handler).chosenRepairer);
} else {
if (((GameState) this.handler).workerMining.containsKey(((GameState) this.handler).chosenRepairer)) {
Unit mineral = ((GameState) this.handler).workerMining.get(((GameState) this.handler).chosenRepairer);
((GameState) this.handler).workerMining.remove(((GameState) this.handler).chosenRepairer);
if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
((GameState) this.handler).mining--;
((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
}
}
}
((GameState) this.handler).repairerTask.add(new Pair<Unit, Unit>(((GameState) this.handler).chosenRepairer, ((GameState) this.handler).chosenBuildingRepair));
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class CheckScan method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).CSs.isEmpty()) {
return State.FAILURE;
}
if (((GameState) this.handler).getGame().elapsedTime() - ((GameState) this.handler).startCount > 1) {
for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
if ((u.isCloaked() || u.isBurrowed()) && !u.isDetected() && u.getType().canAttack()) {
((GameState) this.handler).checkScan = u.getTilePosition();
return State.SUCCESS;
}
}
}
List<BaseLocation> valid = new ArrayList<>();
for (BaseLocation b : ((GameState) this.handler).EnemyBLs) {
if (((GameState) this.handler).getGame().isVisible(b.getTilePosition()) || b.isIsland()) {
continue;
}
if (((GameState) this.handler).enemyBase != null) {
if (((GameState) this.handler).enemyBase.getTilePosition().equals(b.getTilePosition())) {
continue;
}
}
valid.add(b);
}
if (valid.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).CSs) {
if (u.getEnergy() == 200) {
Random random = new Random();
((GameState) this.handler).checkScan = valid.get(random.nextInt(valid.size())).getTilePosition();
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseWorker method execute.
@Override
public State execute() {
try {
Unit closestWorker = null;
int frame = ((GameState) this.handler).frameCount;
Position chosen = ((GameState) this.handler).chosenPosition.toPosition();
if (!((GameState) this.handler).workerIdle.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerIdle) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
}
if (!((GameState) this.handler).workerMining.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (u.getLastCommandFrame() == frame) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
}
if (closestWorker != null) {
((GameState) this.handler).chosenWorker = closestWorker;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations