Search in sources :

Example 31 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class VultureAgent method getNewStatus.

private void getNewStatus() {
    if (mySim.enemies.isEmpty()) {
        status = Status.ATTACK;
    } else {
        boolean meleeOnly = checkOnlyMelees();
        if (!meleeOnly && getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND).lose) {
            status = Util.isInOurBases(unitInfo) ? Status.KITE : Status.RETREAT;
            return;
        }
        if (status == Status.PATROL && actualFrame - lastPatrolFrame > 5) {
            status = Status.COMBAT;
            return;
        }
        int cd = unit.getGroundWeapon().cooldown();
        UnitInfo closestAttacker = Util.getClosestUnit(unitInfo, mySim.enemies, true);
        if (closestAttacker != null && (cd != 0 || unitInfo.getDistance(closestAttacker) < unitInfo.groundRange * 0.6)) {
            status = Status.KITE;
            return;
        }
        if (status == Status.COMBAT || status == Status.ATTACK) {
            /*if (attackUnit != null) {
                    int weaponRange = attackUnit instanceof GroundAttacker ? ((GroundAttacker) attackUnit).getGroundWeaponMaxRange() : 0;
                    if (weaponRange > type.groundWeapon().maxRange()) return;
                }*/
            if (cd > 0) {
                if (attackUnit != null) {
                    Position predictedPosition = UtilMicro.predictUnitPosition(attackUnit, 2);
                    if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
                        double distPredicted = unit.getDistance(predictedPosition);
                        double distCurrent = unitInfo.getDistance(attackUnit);
                        if (distPredicted > distCurrent) {
                            status = Status.COMBAT;
                            return;
                        } else {
                            attackUnit = null;
                            attackPos = null;
                            status = Status.KITE;
                            return;
                        }
                    }
                }
                if (mySim.enemies.isEmpty()) {
                    status = Status.ATTACK;
                    return;
                }
                status = Status.COMBAT;
                return;
            }
        }
        if (status == Status.KITE) {
            UnitInfo closest = getUnitToAttack(mySim.enemies);
            if (closest != null) {
                double dist = unitInfo.getDistance(closest);
                double speed = type.topSpeed();
                double timeToEnter = 0.0;
                if (speed > .00001)
                    timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
                if (timeToEnter >= cd) {
                    // status = Status.COMBAT;
                    status = Status.PATROL;
                    attackUnit = closest;
                    return;
                }
            } else {
                status = Status.ATTACK;
                return;
            }
            if (cd == 0)
                status = Status.COMBAT;
        }
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) Position(org.openbw.bwapi4j.Position)

Example 32 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class CheckScan method execute.

@Override
public State execute() {
    try {
        if (gameState.CSs.isEmpty())
            return State.FAILURE;
        if (gameState.frameCount - gameState.startCount > 40 + gameState.getIH().getLatency()) {
            for (ComsatStation u : gameState.CSs) {
                if (u.getEnergy() < 50)
                    continue;
                for (UnitInfo e : gameState.unitStorage.getEnemyUnits().values()) {
                    if ((e.unit.isCloaked() || e.burrowed) && !e.unit.isDetected() && e.unit instanceof Attacker) {
                        if (gameState.sim.getSimulation(e, true).allies.stream().noneMatch(a -> a.unitType.canAttack()))
                            continue;
                        gameState.checkScan = new MutablePair<>(u, e.lastPosition);
                        return State.SUCCESS;
                    }
                }
            }
        }
        List<Base> valid = new ArrayList<>();
        for (Base b : gameState.enemyBLs) {
            if (gameState.getGame().getBWMap().isVisible(b.getLocation()) || b.getArea().getAccessibleNeighbors().isEmpty()) {
                continue;
            }
            if (gameState.enemyMainBase != null && gameState.enemyMainBase.getLocation().equals(b.getLocation())) {
                continue;
            }
            valid.add(b);
        }
        if (valid.isEmpty())
            return State.FAILURE;
        for (ComsatStation u : gameState.CSs) {
            if (u.getEnergy() == 200) {
                Random random = new Random();
                gameState.checkScan = new MutablePair<>(u, Util.getUnitCenterPosition(valid.get(random.nextInt(valid.size())).getLocation().toPosition(), gameState.enemyRace.getCenter()));
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) Attacker(org.openbw.bwapi4j.unit.Attacker) Random(java.util.Random) ComsatStation(org.openbw.bwapi4j.unit.ComsatStation) ArrayList(java.util.ArrayList) Base(bwem.Base)

Aggregations

UnitInfo (ecgberht.UnitInfo)32 Position (org.openbw.bwapi4j.Position)12 ArrayList (java.util.ArrayList)9 Base (bwem.Base)7 Util (ecgberht.Util.Util)7 Collectors (java.util.stream.Collectors)7 Ecgberht.getGs (ecgberht.Ecgberht.getGs)6 MutablePair (ecgberht.Util.MutablePair)6 List (java.util.List)6 Set (java.util.Set)6 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)6 Area (bwem.Area)5 SimInfo (ecgberht.Simulation.SimInfo)5 Squad (ecgberht.Squad)5 ChokePoint (bwem.ChokePoint)4 TreeSet (java.util.TreeSet)4 org.openbw.bwapi4j.type (org.openbw.bwapi4j.type)4 Cluster (ecgberht.Clustering.Cluster)3 ConfigManager (ecgberht.ConfigManager)3 GameState (ecgberht.GameState)3