Search in sources :

Example 1 with BaseLocationComparator

use of ecgberht.Util.BaseLocationComparator in project Ecgberht by Jabbo16.

the class CheckEnemyBaseVisible method execute.

@Override
public State execute() {
    try {
        List<PlayerUnit> enemies = gameState.getGame().getUnits(gameState.getIH().enemy());
        if (!enemies.isEmpty()) {
            for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
                if (Util.broodWarDistance(gameState.chosenScout.getPosition(), u.lastPosition) <= 500) {
                    gameState.enemyMainBase = Util.getClosestBaseLocation(u.lastPosition);
                    gameState.scoutSLs = new HashSet<>();
                    if (!gameState.getStrat().name.equals("PlasmaWraithHell")) {
                        gameState.chosenHarasser = (Worker) gameState.chosenScout;
                    }
                    gameState.chosenScout = null;
                    Util.sendText("!");
                    gameState.playSound("gearthere.mp3");
                    if (gameState.enemyStartBase == null) {
                        gameState.enemyBLs.clear();
                        gameState.enemyBLs.addAll(gameState.BLs);
                        gameState.enemyBLs.sort(new BaseLocationComparator(gameState.enemyMainBase));
                        if (gameState.firstScout) {
                            gameState.enemyStartBase = gameState.enemyMainBase;
                            gameState.enemyMainArea = gameState.enemyStartBase.getArea();
                            gameState.enemyNaturalBase = gameState.enemyBLs.get(1);
                            gameState.enemyNaturalArea = gameState.enemyNaturalBase.getArea();
                        }
                    }
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : HashSet(java.util.HashSet) List(java.util.List) Util(ecgberht.Util.Util) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit) UnitInfo(ecgberht.UnitInfo) GameState(ecgberht.GameState) State(org.iaie.btree.BehavioralTree.State) Worker(org.openbw.bwapi4j.unit.Worker) Action(org.iaie.btree.task.leaf.Action) BaseLocationComparator(ecgberht.Util.BaseLocationComparator) Collectors(java.util.stream.Collectors) UnitInfo(ecgberht.UnitInfo) BaseLocationComparator(ecgberht.Util.BaseLocationComparator) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 2 with BaseLocationComparator

use of ecgberht.Util.BaseLocationComparator in project Ecgberht by Jabbo16.

the class CheckVisibleBase method execute.

@Override
public State execute() {
    try {
        if (gameState.chosenScout == null)
            return State.FAILURE;
        if (gameState.scoutSLs.size() == 1 && gameState.enemyMainBase == null) {
            gameState.enemyMainBase = gameState.scoutSLs.iterator().next();
            gameState.enemyBLs.clear();
            gameState.enemyBLs.addAll(gameState.BLs);
            gameState.enemyBLs.sort(new BaseLocationComparator(gameState.enemyMainBase));
            if (gameState.firstScout) {
                gameState.enemyStartBase = gameState.enemyMainBase;
                gameState.enemyMainArea = gameState.enemyStartBase.getArea();
                gameState.enemyNaturalBase = gameState.enemyBLs.get(1);
                gameState.enemyNaturalArea = gameState.enemyNaturalBase.getArea();
            }
        }
        if (!gameState.scoutSLs.isEmpty()) {
            for (Base b : gameState.scoutSLs) {
                if ((gameState.getGame().getBWMap().isVisible(b.getLocation()))) {
                    gameState.scoutSLs.remove(b);
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : BaseLocationComparator(ecgberht.Util.BaseLocationComparator) Base(bwem.Base)

Aggregations

BaseLocationComparator (ecgberht.Util.BaseLocationComparator)2 Base (bwem.Base)1 GameState (ecgberht.GameState)1 UnitInfo (ecgberht.UnitInfo)1 Util (ecgberht.Util.Util)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 State (org.iaie.btree.BehavioralTree.State)1 Action (org.iaie.btree.task.leaf.Action)1 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)1 Worker (org.openbw.bwapi4j.unit.Worker)1