use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class ChooseWorker method execute.
@Override
public State execute() {
try {
Worker closestWorker = null;
int frame = gameState.frameCount;
Position chosen = gameState.chosenPosition.toPosition();
Area posArea = gameState.bwem.getMap().getArea(gameState.chosenPosition);
if (!gameState.workerIdle.isEmpty()) {
for (Worker u : gameState.workerIdle) {
if (u.getLastCommandFrame() == frame)
continue;
Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (workerArea == null)
continue;
if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)))
closestWorker = u;
}
}
if (!gameState.workerMining.isEmpty()) {
for (Worker u : gameState.workerMining.keySet()) {
if (u.getLastCommandFrame() == frame)
continue;
Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (workerArea == null)
continue;
if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
}
if (closestWorker != null) {
gameState.chosenWorker = closestWorker;
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.Position in project Ecgberht by Jabbo16.
the class ChooseBlotWorker method execute.
@Override
public State execute() {
try {
Worker closestWorker = null;
Position chosen = gameState.chosenBuildingLot.getPosition();
if (!gameState.workerIdle.isEmpty()) {
for (Worker u : gameState.workerIdle) {
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
}
if (!gameState.workerMining.isEmpty()) {
for (Entry<Worker, MineralPatch> u : gameState.workerMining.entrySet()) {
if ((closestWorker == null || u.getKey().getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.getKey().isCarryingMinerals()) {
closestWorker = u.getKey();
}
}
}
if (closestWorker != null) {
gameState.chosenWorker = closestWorker;
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.Position in project Ecgberht by Jabbo16.
the class UtilMicro method attack.
public static void attack(MobileUnit attacker, Position pos) {
if (pos == null || attacker == null || !attacker.exists() || attacker.isAttackFrame() || attacker.isStartingAttack())
return;
if (getGs().frameCount == attacker.getLastCommandFrame())
return;
Position targetPos = attacker.getTargetPosition();
if (pos.equals(targetPos) || (targetPos != null && pos.toTilePosition().equals(targetPos.toTilePosition())))
return;
if (!getGs().getGame().getBWMap().isValidPosition(pos))
return;
if (!attacker.isFlying() && !getGs().getGame().getBWMap().isWalkable(pos.toWalkPosition()))
return;
attacker.attack(pos);
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class UtilMicro method heal.
public static void heal(Medic u, Position heal) {
if (u == null || heal == null || !getGs().bw.getBWMap().isValidPosition(heal))
return;
if (u.getLastCommandFrame() == getGs().frameCount)
return;
Position targetPos = u.getTargetPosition();
if (heal.equals(targetPos) || (targetPos != null && heal.toTilePosition().equals(targetPos.toTilePosition())))
return;
u.heal(heal);
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class UtilMicro method attack.
public static void attack(UnitInfo attacker, UnitInfo target) {
try {
Attacker attackerUnit = (Attacker) attacker.unit;
if (attackerUnit == null || target == null || !attackerUnit.exists() || attackerUnit.isStartingAttack() || attackerUnit.isAttackFrame())
return;
if (getGs().frameCount == attackerUnit.getLastCommandFrame())
return;
Unit targetUnit = attackerUnit.getTargetUnit();
if (target.unit.equals(targetUnit))
return;
if (target.visible) {
WeaponType w = Util.getWeapon(attacker, target);
double range = attacker.player.getUnitStatCalculator().weaponMaxRange(w);
if (attacker.getDistance(target) <= range) {
attackerUnit.attack(target.unit);
return;
}
Position predicted = predictUnitPosition(target, 3);
if (predicted != null)
move((MobileUnit) attackerUnit, predicted);
} else
move((MobileUnit) attackerUnit, target.lastPosition);
} catch (Exception e) {
System.err.println("UtilMicro Attack Exception");
e.printStackTrace();
}
}
Aggregations