use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.
the class DropShipAgent method setCargo.
public void setCargo(Set<Unit> cargo) {
this.cargoWanted = cargo;
for (Unit u : this.cargoWanted) {
if (u instanceof Worker && (((Worker) u).isCarryingMinerals() || ((Worker) u).isCarryingGas())) {
((Worker) u).returnCargo();
((MobileUnit) u).rightClick(unit, true);
} else
((MobileUnit) u).rightClick(unit, false);
}
}
use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.
the class DropShipAgent method checkLoaded.
private void checkLoaded() {
if (pickingUp == null)
return;
Unit transport = ((MobileUnit) pickingUp).getTransport();
if (transport != null && transport.equals(unit)) {
cargoLoaded.add(pickingUp);
cargoWanted.remove(pickingUp);
pickingUp = null;
}
}
use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.
the class DropShipAgent method retreat.
protected void retreat() {
Position CC = getGs().getNearestCC(myUnit.getPosition(), false);
if (CC != null)
target = CC;
else
target = getGs().getPlayer().getStartLocation().toPosition();
((MobileUnit) myUnit).move(target);
}
use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.
the class DropShipAgent method picking.
private void picking() {
if (cargoWanted.isEmpty())
return;
if (pickingUp == null) {
double distB = Double.MAX_VALUE;
for (Unit u : cargoWanted) {
double distA = Util.broodWarDistance(unit.getPosition(), u.getPosition());
if (pickingUp == null || distA < distB) {
pickingUp = u;
distB = distA;
}
}
if (pickingUp != null) {
unit.load((MobileUnit) pickingUp);
}
} else {
if (unit.getOrderTarget() != null && unit.getOrderTarget().equals(pickingUp))
return;
checkLoaded();
}
}
use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.
the class Repair method execute.
@Override
public State execute() {
try {
boolean cheesed = IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2;
boolean fastExpanding = gameState.getStrat().name.contains("GreedyFE") && Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && gameState.firstExpand;
if (cheesed || fastExpanding) {
if (gameState.chosenRepairer.move(gameState.chosenUnitRepair.getPosition())) {
if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
gameState.workerIdle.remove(gameState.chosenRepairer);
} else {
if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
gameState.workerMining.remove(gameState.chosenRepairer);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
}
}
gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.SUCCESS;
}
} else if (gameState.chosenRepairer.repair(gameState.chosenUnitRepair)) {
if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
gameState.workerIdle.remove(gameState.chosenRepairer);
} else {
if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
gameState.workerMining.remove(gameState.chosenRepairer);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
}
}
gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
if (gameState.chosenUnitRepair instanceof MobileUnit) {
((MobileUnit) gameState.chosenUnitRepair).move(gameState.chosenRepairer.getPosition());
}
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.SUCCESS;
}
gameState.chosenUnitRepair = null;
gameState.chosenRepairer = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations