use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseBuilderBL method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenBuilderBL != null) {
return State.SUCCESS;
}
Unit closestWorker = null;
Position chosen = ((GameState) this.handler).chosenBaseLocation.toPosition();
if (!((GameState) this.handler).workerIdle.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerIdle) {
double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
if (closestWorker == null) {
closestWorker = u;
} else {
double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
if (unitChosen < closestChosen) {
closestWorker = u;
}
}
}
}
if (!((GameState) this.handler).workerMining.isEmpty()) {
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
if (closestWorker == null) {
closestWorker = u;
} else {
double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
if (unitChosen < closestChosen) {
closestWorker = u;
}
}
}
}
if (closestWorker != null) {
if (!((GameState) this.handler).workerTask.isEmpty() && ((GameState) this.handler).workerIdle.contains(closestWorker)) {
((GameState) this.handler).workerIdle.remove(closestWorker);
} else if (!((GameState) this.handler).workerMining.isEmpty()) {
if (((GameState) this.handler).workerMining.containsKey(closestWorker)) {
Unit mineral = ((GameState) this.handler).workerMining.get(closestWorker);
((GameState) this.handler).workerMining.remove(closestWorker);
if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
((GameState) this.handler).mining--;
((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
}
}
}
if (((GameState) this.handler).chosenWorker != null && ((GameState) this.handler).chosenWorker.equals(closestWorker)) {
((GameState) this.handler).chosenWorker = null;
}
((GameState) this.handler).chosenBuilderBL = 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 Expand method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenBuilderBL;
if (!chosen.build(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)) {
((GameState) this.handler).movingToExpand = false;
((GameState) this.handler).expanding = false;
((GameState) this.handler).checkUnitsBL(((GameState) this.handler).chosenBaseLocation, chosen);
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
((GameState) this.handler).chosenBuilderBL.stop();
((GameState) this.handler).chosenBuilderBL = null;
((GameState) this.handler).deltaCash.first -= UnitType.Terran_Command_Center.mineralPrice();
((GameState) this.handler).deltaCash.second -= UnitType.Terran_Command_Center.gasPrice();
return State.FAILURE;
}
((GameState) this.handler).movingToExpand = false;
((GameState) this.handler).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)));
((GameState) this.handler).expanding = false;
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).chosenBuilderBL = null;
return State.SUCCESS;
} 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 Vulture method getUnitToAttack.
private Unit getUnitToAttack(Unit myUnit, Set<Unit> enemies) {
Unit chosen = null;
double distB = Double.MAX_VALUE;
for (Unit u : enemies) {
if (u.getType().isFlyer() || u.isCloaked()) {
continue;
}
double distA = getGs().broodWarDistance(myUnit.getPosition(), u.getPosition());
if (chosen == null || distA < distB) {
chosen = u;
distB = distA;
}
}
if (chosen != null) {
return chosen;
}
return null;
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class Vulture method retreat.
private void retreat() {
Unit CC = getGs().MainCC;
if (CC != null) {
unit.move(CC.getPosition());
} else {
unit.move(getGs().getPlayer().getStartLocation().toPosition());
}
attackPos = Position.None;
attackUnit = null;
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class Vulture method combat.
private void combat() {
Unit toAttack = getUnitToAttack(unit, closeEnemies);
if (toAttack != null) {
if (attackUnit != null) {
if (attackUnit.equals(toAttack)) {
return;
}
}
unit.attack(toAttack);
attackUnit = toAttack;
} else {
if (!closeWorkers.isEmpty()) {
toAttack = getUnitToAttack(unit, closeWorkers);
if (toAttack != null) {
if (attackUnit != null) {
if (attackUnit.equals(toAttack)) {
return;
}
}
}
}
unit.attack(toAttack);
attackUnit = toAttack;
}
attackPos = Position.None;
}
Aggregations