Search in sources :

Example 16 with Unit

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);
}
Also used : Util(ecgberht.Util.Util) UnitInfo(ecgberht.UnitInfo) UtilMicro(ecgberht.Util.UtilMicro) Bunker(org.openbw.bwapi4j.unit.Bunker) Set(java.util.Set) Objects(java.util.Objects) Unit(org.openbw.bwapi4j.unit.Unit) Ecgberht.getGs(ecgberht.Ecgberht.getGs) UnitType(org.openbw.bwapi4j.type.UnitType) SimInfo(ecgberht.Simulation.SimInfo) Order(org.openbw.bwapi4j.type.Order) Vulture(org.openbw.bwapi4j.unit.Vulture) MutablePair(ecgberht.Util.MutablePair) Base(bwem.Base) Optional(java.util.Optional) Position(org.openbw.bwapi4j.Position) Comparator(java.util.Comparator) UnitInfo(ecgberht.UnitInfo) Position(org.openbw.bwapi4j.Position)

Example 17 with Unit

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

Example 18 with Unit

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;
    }
}
Also used : DropShipAgent(ecgberht.Agents.DropShipAgent) Worker(org.openbw.bwapi4j.unit.Worker) Unit(org.openbw.bwapi4j.unit.Unit)

Example 19 with Unit

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;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) Unit(org.openbw.bwapi4j.unit.Unit) Map(java.util.Map)

Aggregations

Unit (org.openbw.bwapi4j.unit.Unit)19 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)11 MobileUnit (org.openbw.bwapi4j.unit.MobileUnit)3 Base (bwem.Base)2 MutablePair (ecgberht.Util.MutablePair)2 Position (org.openbw.bwapi4j.Position)2 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)2 SCV (org.openbw.bwapi4j.unit.SCV)2 Worker (org.openbw.bwapi4j.unit.Worker)2 DropShipAgent (ecgberht.Agents.DropShipAgent)1 Ecgberht.getGs (ecgberht.Ecgberht.getGs)1 SimInfo (ecgberht.Simulation.SimInfo)1 UnitInfo (ecgberht.UnitInfo)1 Util (ecgberht.Util.Util)1 UtilMicro (ecgberht.Util.UtilMicro)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1