Search in sources :

Example 41 with Position

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;
    }
}
Also used : Area(bwem.Area) Position(org.openbw.bwapi4j.Position) Worker(org.openbw.bwapi4j.unit.Worker)

Example 42 with Position

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;
    }
}
Also used : MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Position(org.openbw.bwapi4j.Position) Worker(org.openbw.bwapi4j.unit.Worker)

Example 43 with Position

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);
}
Also used : Position(org.openbw.bwapi4j.Position)

Example 44 with Position

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);
}
Also used : Position(org.openbw.bwapi4j.Position)

Example 45 with Position

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();
    }
}
Also used : Position(org.openbw.bwapi4j.Position) WeaponType(org.openbw.bwapi4j.type.WeaponType)

Aggregations

Position (org.openbw.bwapi4j.Position)55 TilePosition (org.openbw.bwapi4j.TilePosition)19 UnitInfo (ecgberht.UnitInfo)10 Worker (org.openbw.bwapi4j.unit.Worker)10 UnitType (org.openbw.bwapi4j.type.UnitType)9 SimInfo (ecgberht.Simulation.SimInfo)8 Util (ecgberht.Util.Util)8 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Ecgberht.getGs (ecgberht.Ecgberht.getGs)7 UtilMicro (ecgberht.Util.UtilMicro)7 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)7 Area (bwem.Area)6 Base (bwem.Base)6 Collectors (java.util.stream.Collectors)6 Order (org.openbw.bwapi4j.type.Order)6 java.util (java.util)5 WeaponType (org.openbw.bwapi4j.type.WeaponType)5 ArrayList (java.util.ArrayList)4 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 Squad (ecgberht.Squad)3