Search in sources :

Example 1 with ComsatStation

use of org.openbw.bwapi4j.unit.ComsatStation 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

Base (bwem.Base)1 UnitInfo (ecgberht.UnitInfo)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Attacker (org.openbw.bwapi4j.unit.Attacker)1 ComsatStation (org.openbw.bwapi4j.unit.ComsatStation)1