use of org.openbw.bwapi4j.unit.Unit in project Ecgberht by Jabbo16.
the class VultureAgent method kite.
private void kite() {
// Position kite = UtilMicro.kiteAway(unit, closeEnemies);
Optional<UnitInfo> closestUnit = mySim.enemies.stream().min(Comparator.comparing(u -> unitInfo.getDistance(u)));
Position kite = closestUnit.map(unit1 -> UtilMicro.kiteAwayAlt(unit.getPosition(), unit1.position)).orElse(null);
if (kite == null || !getGs().getGame().getBWMap().isValidPosition(kite)) {
kite = UtilMicro.kiteAway(unit, mySim.enemies);
if (kite == null || !getGs().getGame().getBWMap().isValidPosition(kite)) {
retreat();
return;
}
}
UtilMicro.move(unit, kite);
}
use of org.openbw.bwapi4j.unit.Unit in project Ecgberht by Jabbo16.
the class VultureAgent method runAgent.
@Override
public boolean runAgent() {
try {
if (!unit.exists() || unitInfo == null)
return true;
if (unit.getHitPoints() <= 20) {
MutablePair<Base, Unit> cc = getGs().mainCC;
if (cc != null && cc.second != null) {
Position ccPos = cc.second.getPosition();
if (getGs().getGame().getBWMap().isValidPosition(ccPos)) {
unit.move(ccPos);
getGs().myArmy.add(unitInfo);
return true;
}
}
unit.move(getGs().getPlayer().getStartLocation().toPosition());
getGs().myArmy.add(unitInfo);
return true;
}
mySim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND);
actualFrame = getGs().frameCount;
frameLastOrder = unit.getLastCommandFrame();
if (frameLastOrder == actualFrame)
return false;
// Status old = status;
getNewStatus();
// if (old == status && status != Status.COMBAT && status != Status.ATTACK) return false;
if (status != Status.COMBAT && status != Status.PATROL)
attackUnit = null;
if ((status == Status.ATTACK || status == Status.IDLE) && (unit.isIdle() || unit.getOrder() == Order.PlayerGuard)) {
Position pos = Util.chooseAttackPosition(unit.getPosition(), false);
if (pos == null || !getGs().getGame().getBWMap().isValidPosition(pos))
return false;
UtilMicro.move(unit, pos);
status = Status.ATTACK;
return false;
}
switch(status) {
case ATTACK:
attack();
break;
case COMBAT:
combat();
break;
case KITE:
kite();
break;
case RETREAT:
retreat();
break;
case PATROL:
patrol();
break;
}
return false;
} catch (Exception e) {
System.err.println("Exception VultureAgent");
e.printStackTrace();
}
return false;
}
use of org.openbw.bwapi4j.unit.Unit in project Ecgberht by Jabbo16.
the class CheckDropped method execute.
@Override
public State execute() {
try {
Worker scv = gameState.chosenWorkerDrop;
DropShipAgent ship = gameState.chosenDropShip;
if (ship == null)
return State.SUCCESS;
if (scv != null && ship.statusToString().equals("RETREAT")) {
Unit transport = scv.getTransport();
if (transport == null) {
gameState.chosenDropShip = null;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.unit.Unit in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method execute.
@Override
public State execute() {
try {
if (gameState.walkingMinerals.isEmpty())
return State.SUCCESS;
for (Map.Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
if (u.getValue().first != UnitType.Terran_Command_Center)
continue;
SCV scv = u.getKey();
Unit movingMineral = u.getKey().getTargetUnit();
if (movingMineral == null) {
MineralPatch target = getCloserMineral(u);
if (target == null) {
if (scv.getOrderTarget() != null && scv.getOrder() != Order.Move) {
scv.move(u.getValue().second.toPosition());
}
continue;
}
if (!target.equals(scv.getTargetUnit()))
scv.rightClick(target, false);
} else if (scv.getDistance(movingMineral) < 32) {
scv.move(u.getValue().second.toPosition());
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations