use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseBuildingLot method execute.
@Override
public State execute() {
try {
Unit savedTurret = null;
List<Unit> aux = new ArrayList<Unit>();
for (Unit b : ((GameState) this.handler).buildingLot) {
if (!b.isUnderAttack()) {
if (b.getType() == UnitType.Terran_Bunker) {
((GameState) this.handler).chosenBuildingLot = b;
return State.SUCCESS;
}
if (b.getType() == UnitType.Terran_Missile_Turret) {
savedTurret = b;
}
((GameState) this.handler).chosenBuildingLot = b;
} else {
if ((double) b.getHitPoints() / (double) b.getType().maxHitPoints() <= 0.1) {
b.cancelConstruction();
aux.add(b);
}
}
}
((GameState) this.handler).buildingLot.removeAll(aux);
if (savedTurret != null) {
((GameState) this.handler).chosenBuildingLot = savedTurret;
return State.SUCCESS;
}
if (((GameState) this.handler).chosenBuildingLot != null) {
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 FinishBuilding method execute.
@Override
public State execute() {
try {
Unit chosen = ((GameState) this.handler).chosenWorker;
if (chosen.rightClick(((GameState) this.handler).chosenBuildingLot)) {
if (((GameState) this.handler).workerIdle.contains(chosen)) {
((GameState) this.handler).workerIdle.remove(chosen);
} else {
if (((GameState) this.handler).workerMining.containsKey(chosen)) {
Unit mineral = ((GameState) this.handler).workerMining.get(chosen);
((GameState) this.handler).workerMining.remove(chosen);
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).workerTask.add(new Pair<Unit, Unit>(chosen, ((GameState) this.handler).chosenBuildingLot));
((GameState) this.handler).chosenWorker = null;
((GameState) this.handler).buildingLot.remove(((GameState) this.handler).chosenBuildingLot);
((GameState) this.handler).chosenBuildingLot = null;
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 CheckHarasserAttacked method execute.
@Override
public State execute() {
try {
Unit attacker = null;
int workers = 0;
Set<Unit> attackers = new HashSet<>();
// Thanks to @N00byEdge to the cleaner code
for (Unit u : ((GameState) this.handler).getGame().enemy().getUnits()) {
if (!u.getType().isBuilding() && u.getType().canAttack()) {
Unit target = (u.getTarget() == null ? u.getOrderTarget() : u.getTarget());
if (target != null && target.equals(((GameState) this.handler).chosenHarasser)) {
if (u.getType().isWorker()) {
workers++;
attacker = u;
}
attackers.add(u);
continue;
}
}
}
if (workers > 1) {
((GameState) this.handler).EI.defendHarass = true;
}
if (attackers.isEmpty()) {
if (!((GameState) this.handler).getGame().isVisible(((GameState) this.handler).enemyBase.getTilePosition()) && ((GameState) this.handler).chosenUnitToHarass == null) {
((GameState) this.handler).chosenHarasser.move(((GameState) this.handler).enemyBase.getPosition());
}
return State.SUCCESS;
} else {
boolean winHarass = ((GameState) this.handler).simulateHarass(((GameState) this.handler).chosenHarasser, attackers, 70);
if (winHarass) {
if (workers == 1 && !attacker.equals(((GameState) this.handler).chosenUnitToHarass)) {
((GameState) this.handler).chosenHarasser.attack(attacker);
((GameState) this.handler).chosenUnitToHarass = attacker;
return State.SUCCESS;
}
} else {
if (((GameState) this.handler).chosenHarasser.getHitPoints() <= 15) {
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
((GameState) this.handler).chosenHarasser.stop();
((GameState) this.handler).chosenHarasser = null;
((GameState) this.handler).chosenUnitToHarass = null;
} else {
Position kite = getGs().kiteAway(((GameState) this.handler).chosenHarasser, attackers);
((GameState) this.handler).chosenHarasser.move(kite);
((GameState) this.handler).chosenUnitToHarass = null;
}
return State.FAILURE;
}
}
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 CheckResourcesBuilding method execute.
@Override
public State execute() {
try {
Pair<Integer, Integer> cash = ((GameState) this.handler).getCash();
Unit chosen = ((GameState) this.handler).chosenWorker;
TilePosition start = chosen.getTilePosition();
TilePosition end = ((GameState) this.handler).chosenPosition;
Position realEnd = ((GameState) this.handler).getCenterFromBuilding(end.toPosition(), ((GameState) this.handler).chosenToBuild);
if (cash.first + ((GameState) this.handler).getMineralsWhenReaching(chosen, start, realEnd.toTilePosition()) >= (((GameState) this.handler).chosenToBuild.mineralPrice() + ((GameState) this.handler).deltaCash.first) && cash.second >= (((GameState) this.handler).chosenToBuild.gasPrice()) + ((GameState) this.handler).deltaCash.second) {
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 ChooseScout method execute.
@Override
public State execute() {
try {
for (Unit u : ((GameState) this.handler).workerIdle) {
((GameState) this.handler).chosenScout = u;
((GameState) this.handler).workerIdle.remove(u);
break;
}
if (((GameState) this.handler).chosenScout == null) {
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (!u.isCarryingMinerals()) {
((GameState) this.handler).chosenScout = u;
((GameState) this.handler).workerMining.remove(u);
}
break;
}
}
if (((GameState) this.handler).chosenScout != null) {
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations