Search in sources :

Example 46 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class UtilMicro method move.

public static void move(MobileUnit u, Position pos) {
    if (pos == null || u == null || !u.exists())
        return;
    if (getGs().frameCount == u.getLastCommandFrame())
        return;
    Position targetPos = u.getTargetPosition();
    if (pos.equals(targetPos) || (targetPos != null && pos.toTilePosition().equals(targetPos.toTilePosition())))
        return;
    if (!getGs().getGame().getBWMap().isValidPosition(pos))
        return;
    if (!u.isFlying() && !getGs().getGame().getBWMap().isWalkable(pos.toWalkPosition()))
        return;
    u.move(pos);
}
Also used : Position(org.openbw.bwapi4j.Position)

Example 47 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class Squad method microRanged.

// Based on @Locutus micro logic
private void microRanged(UnitInfo u) {
    switch(status) {
        case ATTACK:
        case DEFENSE:
            executeRangedAttackLogic(u);
            break;
        case IDLE:
            if (getGs().getStrat().proxy)
                return;
            Position move = null;
            if (getGs().defendPosition != null) {
                if (u.currentOrder != Order.Stop)
                    move = getGs().defendPosition;
            } else if (!getGs().DBs.isEmpty()) {
                Unit bunker = getGs().DBs.keySet().iterator().next();
                if (u.currentOrder != Order.Stop)
                    move = bunker.getPosition();
            } else if (getGs().mainChoke != null && !getGs().learningManager.isNaughty() && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
                if (u.currentOrder != Order.Stop)
                    move = getGs().mainChoke.getCenter().toPosition();
            } else if (Util.broodWarDistance(u.position, center) >= 190 && u.currentOrder != Order.Move) {
                if (getGs().getGame().getBWMap().isWalkable(center.toWalkPosition()))
                    move = center;
            }
            if (move != null) {
                WeaponType weapon = Util.getWeapon(u.unitType);
                int range2 = weapon == WeaponType.None ? UnitType.Terran_Marine.groundWeapon().maxRange() : weapon.maxRange();
                if (u.currentOrder == Order.AttackMove) {
                    if (u.getDistance(move) <= range2 * ((double) (new Random().nextInt((10 + 1) - 4) + 4)) / 10.0 && Util.shouldIStop(u.position)) {
                        UtilMicro.stop((MobileUnit) u.unit);
                        return;
                    }
                } else if (u.getDistance(move) > range2) {
                    UtilMicro.attack((MobileUnit) u.unit, move);
                    return;
                }
            }
            break;
        case REGROUP:
            if (((MobileUnit) u.unit).isDefenseMatrixed() || getGs().sim.farFromFight(u, squadSim, false) || squadSim.enemies.stream().noneMatch(e -> Util.getWeapon(e, u).maxRange() > 32)) {
                executeRangedAttackLogic(u);
                return;
            }
            Position pos = getGs().getNearestCC(u.position, true);
            if (Util.broodWarDistance(pos, u.position) >= 400) {
                UtilMicro.move((MobileUnit) u.unit, pos);
            }
            break;
        case ADVANCE:
            double dist = Util.broodWarDistance(u.position, center);
            if (dist >= 240) {
                UtilMicro.move((MobileUnit) u.unit, center);
                return;
            } else if (attack != null)
                UtilMicro.move((MobileUnit) u.unit, attack);
            break;
    }
}
Also used : java.util(java.util) Util(ecgberht.Util.Util) TechType(org.openbw.bwapi4j.type.TechType) Ecgberht.getGs(ecgberht.Ecgberht.getGs) UnitType(org.openbw.bwapi4j.type.UnitType) SimInfo(ecgberht.Simulation.SimInfo) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) UtilMicro(ecgberht.Util.UtilMicro) Order(org.openbw.bwapi4j.type.Order) Position(org.openbw.bwapi4j.Position) WeaponType(org.openbw.bwapi4j.type.WeaponType) Collectors(java.util.stream.Collectors) Position(org.openbw.bwapi4j.Position) WeaponType(org.openbw.bwapi4j.type.WeaponType)

Example 48 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class SquadManager method createSquads.

public void createSquads(List<Cluster> friendly) {
    squads.clear();
    int counter = 0;
    for (Cluster c : friendly) {
        Squad s = new Squad(counter, new Position((int) c.modeX, (int) c.modeY), getGs().sim.getSimulation(c));
        squads.put(counter, s);
        counter++;
    }
}
Also used : Position(org.openbw.bwapi4j.Position) Cluster(ecgberht.Clustering.Cluster)

Example 49 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class CheckMineralWalkGoldRush method getCloserMineral.

private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
    double bestDist = Double.MAX_VALUE;
    MineralPatch closerMineral = null;
    SCV scv = entry.getKey();
    Position buildTarget = entry.getValue().second.toPosition();
    for (MineralPatch mineralPatch : gameState.walkingMinerals) {
        if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
            continue;
        double dist = mineralPatch.getDistance(buildTarget) * 1.2;
        if (dist > scv.getDistance(buildTarget))
            continue;
        Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
        Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
        if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
            continue;
        if (dist < bestDist) {
            bestDist = dist;
            closerMineral = mineralPatch;
        }
    }
    return closerMineral;
}
Also used : Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV)

Example 50 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class CheckHarasserAttacked method execute.

@Override
public State execute() {
    try {
        if (gameState.enemyMainBase == null) {
            gameState.chosenUnitToHarass = null;
            gameState.chosenHarasser = null;
            return State.FAILURE;
        }
        if (gameState.chosenUnitToHarass != null) {
            if (!gameState.bw.getBWMap().isValidPosition(gameState.chosenUnitToHarass.getPosition())) {
                gameState.chosenUnitToHarass = null;
            }
        }
        UnitInfo attacker = null;
        int workers = 0;
        Set<UnitInfo> attackers = new TreeSet<>();
        // Thanks to @N00byEdge for cleaner code
        for (UnitInfo u : gameState.unitStorage.getAllyUnits().get(gameState.chosenHarasser).attackers) {
            if (!(u.unit instanceof Building) && u.unit instanceof Attacker && u.unit.exists()) {
                if (u.unit instanceof Worker) {
                    workers++;
                    attacker = u;
                }
                attackers.add(u);
            }
        }
        if (workers > 1) {
            gameState.learningManager.setHarass(true);
            gameState.chosenUnitToHarass = null;
            return State.FAILURE;
        }
        if (attackers.isEmpty()) {
            if (!gameState.getGame().getBWMap().isVisible(gameState.enemyMainBase.getLocation()) && gameState.chosenUnitToHarass == null) {
                gameState.chosenHarasser.move(gameState.enemyMainBase.getLocation().toPosition());
            }
            return State.SUCCESS;
        } else {
            boolean winHarass = gameState.sim.simulateHarass(gameState.chosenHarasser, attackers, 70);
            if (winHarass) {
                if (workers == 1 && !attacker.unit.equals(gameState.chosenUnitToHarass)) {
                    UtilMicro.attack(gameState.chosenHarasser, attacker);
                    gameState.chosenUnitToHarass = attacker.unit;
                    return State.SUCCESS;
                }
            } else {
                if (IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.Unknown) {
                    gameState.explore = true;
                    gameState.chosenUnitToHarass = null;
                    gameState.chosenHarasser.stop(false);
                    return State.FAILURE;
                } else if (gameState.chosenHarasser.getHitPoints() <= 15) {
                    gameState.workerIdle.add(gameState.chosenHarasser);
                    gameState.chosenHarasser.stop(false);
                    gameState.chosenHarasser = null;
                    gameState.chosenUnitToHarass = null;
                } else {
                    // Position kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
                    Optional<UnitInfo> closestUnit = attackers.stream().min(Comparator.comparing(u -> u.getDistance(gameState.chosenHarasser)));
                    Position kite = closestUnit.map(unit1 -> UtilMicro.kiteAwayAlt(gameState.chosenHarasser.getPosition(), unit1.position)).orElse(null);
                    if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
                        UtilMicro.move(gameState.chosenHarasser, kite);
                        gameState.chosenUnitToHarass = null;
                    } else {
                        kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
                        if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
                            UtilMicro.move(gameState.chosenHarasser, kite);
                            gameState.chosenUnitToHarass = null;
                        }
                    }
                }
                return State.FAILURE;
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Building(org.openbw.bwapi4j.unit.Building) UnitInfo(ecgberht.UnitInfo) Attacker(org.openbw.bwapi4j.unit.Attacker) Optional(java.util.Optional) Position(org.openbw.bwapi4j.Position) TreeSet(java.util.TreeSet) Worker(org.openbw.bwapi4j.unit.Worker)

Aggregations

Position (org.openbw.bwapi4j.Position)55 TilePosition (org.openbw.bwapi4j.TilePosition)19 UnitInfo (ecgberht.UnitInfo)10 Worker (org.openbw.bwapi4j.unit.Worker)10 UnitType (org.openbw.bwapi4j.type.UnitType)9 SimInfo (ecgberht.Simulation.SimInfo)8 Util (ecgberht.Util.Util)8 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Ecgberht.getGs (ecgberht.Ecgberht.getGs)7 UtilMicro (ecgberht.Util.UtilMicro)7 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)7 Area (bwem.Area)6 Base (bwem.Base)6 Collectors (java.util.stream.Collectors)6 Order (org.openbw.bwapi4j.type.Order)6 java.util (java.util)5 WeaponType (org.openbw.bwapi4j.type.WeaponType)5 ArrayList (java.util.ArrayList)4 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 Squad (ecgberht.Squad)3