Search in sources :

Example 1 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class VesselAgent method kite.

private void kite() {
    Set<UnitInfo> airThreats = airAttackers.stream().filter(u -> u.unitType == UnitType.Zerg_Scourge || u.unitType == UnitType.Zerg_Spore_Colony).collect(Collectors.toSet());
    if (!airThreats.isEmpty()) {
        Position kite = UtilMicro.kiteAway(unit, airThreats);
        if (kite != null) {
            UtilMicro.move(unit, kite);
            return;
        }
    }
    Position kite = UtilMicro.kiteAway(unit, airAttackers);
    if (kite == null || !getGs().getGame().getBWMap().isValidPosition(kite))
        return;
    UtilMicro.move(unit, kite);
}
Also used : Util(ecgberht.Util.Util) UnitInfo(ecgberht.UnitInfo) UtilMicro(ecgberht.Util.UtilMicro) Squad(ecgberht.Squad) Set(java.util.Set) Collectors(java.util.stream.Collectors) TreeSet(java.util.TreeSet) Objects(java.util.Objects) Ecgberht.getGs(ecgberht.Ecgberht.getGs) SimInfo(ecgberht.Simulation.SimInfo) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) org.openbw.bwapi4j.type(org.openbw.bwapi4j.type) Position(org.openbw.bwapi4j.Position) UnitInfo(ecgberht.UnitInfo) Position(org.openbw.bwapi4j.Position)

Example 2 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class WorkerScoutAgent method disrupt.

private void disrupt() {
    if (disrupter == null) {
        if (unit.getBuildUnit() != null) {
            disrupter = (Building) unit.getBuildUnit();
            return;
        }
        if (unit.getOrder() != Order.PlaceBuilding) {
            unit.build(getGs().enemyNaturalBase.getLocation(), UnitType.Terran_Engineering_Bay);
        }
    } else if (disrupter.getRemainingBuildTime() <= 25) {
        unit.haltConstruction();
        finishedDisrupting = true;
        stoppedDisrupting = true;
        removedIndex = true;
    } else if (!stoppedDisrupting) {
        if (mySim.enemies.stream().anyMatch(u -> unitInfo.getDistance(u) <= 4 * 32)) {
            if (mySim.enemies.stream().anyMatch(u -> u.unit instanceof Zergling)) {
                unit.haltConstruction();
                stoppedDisrupting = true;
                if (!removedIndex) {
                    enemyBaseBorders.remove(enemyNaturalIndex);
                    enemyNaturalIndex = -1;
                    removedIndex = true;
                }
                return;
            }
            if (mySim.enemies.size() == 1) {
                UnitInfo closest = mySim.enemies.iterator().next();
                Area enemyArea = getGs().bwem.getMap().getArea(closest.tileposition);
                if (closest.unit instanceof Drone && enemyArea != null && enemyArea.equals(getGs().enemyNaturalArea)) {
                    if (mySim.lose) {
                        unit.haltConstruction();
                        stoppedDisrupting = true;
                        if (!removedIndex) {
                            enemyBaseBorders.remove(enemyNaturalIndex);
                            enemyNaturalIndex = -1;
                            removedIndex = true;
                        }
                    }
                }
            }
        }
    } else if (mySim.enemies.isEmpty() && disrupter != null && !finishedDisrupting)
        unit.resumeBuilding(disrupter);
    else if (!mySim.enemies.isEmpty() && (unitInfo.attackers.isEmpty() || !mySim.lose)) {
        UnitInfo target = Util.getRangedTarget(unitInfo, mySim.enemies);
        if (target != null)
            UtilMicro.attack(unitInfo, target);
        else if (disrupter != null && !finishedDisrupting)
            unit.resumeBuilding(disrupter);
    }
    if (disrupter != null && !finishedDisrupting)
        unit.resumeBuilding(disrupter);
}
Also used : UnitInfo(ecgberht.UnitInfo) Area(bwem.Area)

Example 3 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class WorkerScoutAgent method runAgent.

public boolean runAgent() {
    if (unit == null || !unit.exists() || unitInfo == null || !getGs().firstScout) {
        if (disrupter != null)
            getGs().disrupterBuilding = disrupter;
        getGs().firstScout = false;
        if (getGs().proxyBuilding != null && !getGs().proxyBuilding.isCompleted())
            getGs().proxyBuilding.cancelConstruction();
        return true;
    }
    if (status == Status.EXPLORE && getGs().getStrat().proxy && mySim.allies.stream().anyMatch(u -> u.unit instanceof Marine)) {
        getGs().myArmy.add(unitInfo);
        getGs().firstScout = false;
        if (getGs().proxyBuilding != null && !getGs().proxyBuilding.isCompleted())
            getGs().proxyBuilding.cancelConstruction();
        return true;
    }
    if (enemyBaseBorders.isEmpty())
        updateBorders();
    mySim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND);
    if (enemyNaturalIndex != -1 && (IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.EarlyPool || IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush || getGs().learningManager.isNaughty() || getGs().basicCombatUnitsDetected(mySim.enemies) || IntelligenceAgency.getNumEnemyBases(getGs().getIH().enemy()) > 1)) {
        enemyBaseBorders.remove(enemyNaturalIndex);
        enemyNaturalIndex = -1;
        removedIndex = true;
    }
    status = chooseNewStatus();
    cancelDisrupter();
    switch(status) {
        case EXPLORE:
            followPerimeter();
            break;
        case DISRUPTING:
            disrupt();
            break;
        case PROXYING:
            proxy();
        case IDLE:
            break;
    }
    if (disrupter != null)
        getGs().getGame().getMapDrawer().drawTextMap(disrupter.getPosition().add(new Position(0, -16)), ColorUtil.formatText("BM!", ColorUtil.White));
    return false;
}
Also used : Result(org.bk.ass.path.Result) BuildingMap(ecgberht.BuildingMap) Util(ecgberht.Util.Util) ColorUtil(ecgberht.Util.ColorUtil) WalkPosition(org.openbw.bwapi4j.WalkPosition) Area(bwem.Area) UnitInfo(ecgberht.UnitInfo) UtilMicro(ecgberht.Util.UtilMicro) Set(java.util.Set) TilePosition(org.openbw.bwapi4j.TilePosition) IntelligenceAgency(ecgberht.IntelligenceAgency) ArrayList(java.util.ArrayList) Race(org.openbw.bwapi4j.type.Race) List(java.util.List) Ecgberht.getGs(ecgberht.Ecgberht.getGs) UnitType(org.openbw.bwapi4j.type.UnitType) SimInfo(ecgberht.Simulation.SimInfo) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) Order(org.openbw.bwapi4j.type.Order) Base(bwem.Base) Position(org.openbw.bwapi4j.Position) WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 4 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class CheckBuildingFlames method execute.

@Override
public State execute() {
    try {
        List<SCV> toRemove = new ArrayList<>();
        for (Entry<SCV, Mechanical> u : gameState.repairerTask.entrySet()) {
            if (u.getValue().maxHitPoints() != u.getValue().getHitPoints()) {
                if (u.getKey().getOrder() != Order.Follow && u.getKey().getOrder() != Order.Repair) {
                    u.getKey().rightClick(u.getValue(), false);
                }
            } else if (Util.countBuildingAll(UnitType.Terran_Command_Center) < 2 && u.getValue() instanceof Bunker && IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2) {
                if (u.getKey().getDistance(u.getValue()) > 3 * 32)
                    u.getKey().move(u.getValue().getPosition());
            } else if (Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && u.getValue() instanceof Bunker) {
                if (u.getKey().getDistance(u.getValue()) > 3 * 32)
                    u.getKey().move(u.getValue().getPosition());
            } else {
                u.getKey().stop(false);
                gameState.workerIdle.add(u.getKey());
                toRemove.add(u.getKey());
            }
        }
        for (SCV s : toRemove) gameState.repairerTask.remove(s);
        boolean isBeingRepaired;
        boolean cheesed = IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2;
        boolean fastExpanding = gameState.getStrat().name.contains("GreedyFE") && Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && gameState.firstExpand;
        for (Bunker w : gameState.DBs.keySet()) {
            int count = 0;
            if (UnitType.Terran_Bunker.maxHitPoints() != w.getHitPoints() || (cheesed && Util.countBuildingAll(UnitType.Terran_Command_Center) < 2) || fastExpanding) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (w.equals(r))
                        count++;
                }
                if (count < 2 && (gameState.defense || cheesed || fastExpanding)) {
                    gameState.chosenUnitRepair = w;
                    return State.SUCCESS;
                }
                if (count == 0) {
                    gameState.chosenUnitRepair = w;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (MissileTurret b : gameState.Ts) {
            if (UnitType.Terran_Missile_Turret.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        // TODO check to add break?
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Squad s : gameState.sqManager.squads.values()) {
            if (s.status != Squad.Status.IDLE)
                continue;
            for (UnitInfo u : s.members) {
                if (u.unit instanceof Mechanical && u.health != u.unitType.maxHitPoints()) {
                    Area unitArea = gameState.bwem.getMap().getArea(u.tileposition);
                    for (Base b : gameState.CCs.keySet()) {
                        if (unitArea != null && b.getArea().equals(unitArea)) {
                            for (Mechanical r : gameState.repairerTask.values()) {
                                if (u.unit.equals(r)) {
                                    isBeingRepaired = true;
                                }
                            }
                            if (!isBeingRepaired) {
                                gameState.chosenUnitRepair = (Mechanical) u.unit;
                                return State.SUCCESS;
                            }
                        }
                    }
                }
            }
        }
        if (!gameState.getStrat().proxy) {
            isBeingRepaired = false;
            for (Barracks b : gameState.MBs) {
                if (UnitType.Terran_Barracks.maxHitPoints() != b.getHitPoints()) {
                    for (Mechanical r : gameState.repairerTask.values()) {
                        if (b.equals(r)) {
                            isBeingRepaired = true;
                        }
                    }
                    if (!isBeingRepaired) {
                        gameState.chosenUnitRepair = b;
                        return State.SUCCESS;
                    }
                }
            }
        }
        isBeingRepaired = false;
        for (Factory b : gameState.Fs) {
            if (b.equals(gameState.proxyBuilding))
                continue;
            if (UnitType.Terran_Factory.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (ResearchingFacility b : gameState.UBs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = (Mechanical) b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (SupplyDepot b : gameState.SBs) {
            if (UnitType.Terran_Supply_Depot.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (CommandCenter b : gameState.CCs.values()) {
            if (UnitType.Terran_Command_Center.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (ComsatStation b : gameState.CSs) {
            if (UnitType.Terran_Comsat_Station.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Starport b : gameState.Ps) {
            if (UnitType.Terran_Starport.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : ArrayList(java.util.ArrayList) Base(bwem.Base) UnitInfo(ecgberht.UnitInfo) Area(bwem.Area) Squad(ecgberht.Squad)

Example 5 with UnitInfo

use of ecgberht.UnitInfo 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)

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