Search in sources :

Example 1 with WeaponType

use of org.openbw.bwapi4j.type.WeaponType in project Ecgberht by Jabbo16.

the class WraithAgent method chooseHarassTarget.

private UnitInfo chooseHarassTarget(Set<UnitInfo> mainTargets) {
    UnitInfo chosen = null;
    double maxScore = Double.MIN_VALUE;
    for (UnitInfo u : mainTargets) {
        // if (!u.unit.exists()) continue;
        double dist = unitInfo.getDistance(u);
        double score = u.unitType.isWorker() ? 5 : (u.unitType == UnitType.Zerg_Overlord ? 8 : 1);
        WeaponType weapon = Util.getWeapon(unitInfo, u);
        score *= dist <= weapon.maxRange() ? 1.4 : 0.9;
        score *= (double) u.unitType.maxHitPoints() / (double) u.health;
        if (chosen == null || maxScore < score) {
            chosen = u;
            maxScore = score;
        }
    }
    return chosen;
}
Also used : UnitInfo(ecgberht.UnitInfo) WeaponType(org.openbw.bwapi4j.type.WeaponType)

Example 2 with WeaponType

use of org.openbw.bwapi4j.type.WeaponType in project Ecgberht by Jabbo16.

the class Squad method microTank.

private void microTank(UnitInfo u) {
    SiegeTank st = (SiegeTank) u.unit;
    if (st.isAttackFrame() || st.isStartingAttack() || st.isSieged() && u.currentOrder == Order.Unsieging)
        return;
    if (!st.isSieged() && u.currentOrder == Order.Sieging)
        return;
    if (u.currentOrder == Order.Unsieging || u.currentOrder == Order.Sieging)
        return;
    switch(status) {
        case ATTACK:
        case DEFENSE:
            boolean found = false;
            boolean close = false;
            int threats = (int) squadSim.enemies.stream().filter(e -> e.unitType.canAttack() || e.unitType.isSpellcaster() || Util.isStaticDefense(e.unitType)).count();
            for (UnitInfo e : squadSim.enemies) {
                if (e.flying || e.unit instanceof Worker || e.unit instanceof Medic || (e.unitType.isBuilding() && !Util.isStaticDefense(e)))
                    continue;
                int distance = u.getDistance(e);
                if (!found && distance <= UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().maxRange() - 8 && (e.health + e.shields >= 60 || threats > 2)) {
                    found = true;
                }
                if (!close && distance < UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().minRange())
                    close = true;
                if (found && close)
                    break;
            }
            if (found && !close) {
                if (!st.isSieged()) {
                    st.siege();
                    return;
                }
            }
            if (status == Status.DEFENSE && st.isSieged() && getGs().defendPosition != null) {
                double range = u.groundRange - 8;
                if (u.getDistance(getGs().defendPosition) > range)
                    st.unsiege();
                return;
            }
            Set<UnitInfo> tankTargets = squadSim.enemies.stream().filter(e -> !e.flying).collect(Collectors.toSet());
            if (st.isSieged()) {
                tankTargets.removeIf(e -> u.getDistance(e) > UnitType.Terran_Siege_Tank_Siege_Mode.groundWeapon().maxRange() - 8 || (e.unitType.isBuilding() && !Util.isStaticDefense(e)) || (!e.unitType.isBuilding() && !e.unitType.canAttack() && !e.unitType.isSpellcaster()));
                if (tankTargets.isEmpty() && Math.random() * 10 <= 3) {
                    st.unsiege();
                    return;
                }
            }
            UnitInfo target = Util.getTankTarget(u, tankTargets);
            if (target != null)
                UtilMicro.attack(u, target);
            else if (attack != null && Math.random() * 10 <= 2.5) {
                if (st.isSieged())
                    st.unsiege();
                else
                    UtilMicro.move(st, attack);
            }
            break;
        case IDLE:
            Position move = null;
            if (getGs().defendPosition != null) {
                move = getGs().defendPosition;
            } else if (!getGs().DBs.isEmpty()) {
                Unit bunker = getGs().DBs.keySet().iterator().next();
                if (Util.broodWarDistance(bunker.getPosition(), center) >= 180 && getGs().getArmySize() < getGs().getStrat().armyForAttack && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
                    if (u.currentOrder != Order.Move)
                        move = bunker.getPosition();
                }
            } else if (getGs().mainChoke != null && !getGs().learningManager.isNaughty() && !getGs().getStrat().name.equals("ProxyBBS") && !getGs().getStrat().name.equals("ProxyEightRax")) {
                if (Util.broodWarDistance(getGs().mainChoke.getCenter().toPosition(), center) >= 200 && getGs().getArmySize() < getGs().getStrat().armyForAttack) {
                    if (u.currentOrder != Order.Move)
                        move = getGs().mainChoke.getCenter().toPosition();
                }
            } else if (Util.broodWarDistance(u.position, center) >= 180 && u.currentOrder != Order.Move) {
                if (getGs().getGame().getBWMap().isWalkable(center.toWalkPosition()))
                    move = center;
            }
            if (move != null) {
                WeaponType weapon = Util.getWeapon(u.unitType);
                int range = weapon.maxRange();
                if (u.currentOrder == Order.AttackMove || u.currentOrder == Order.PlayerGuard || u.currentOrder == Order.Move) {
                    if (u.getDistance(move) <= range * ((double) (new Random().nextInt((10 + 1) - 4) + 4)) / 10.0 && Util.shouldIStop(u.position)) {
                        if (!st.isSieged() && getGs().getPlayer().hasResearched(TechType.Tank_Siege_Mode)) {
                            st.siege();
                        } else
                            UtilMicro.stop(st);
                        return;
                    }
                } else if (u.getDistance(move) > range) {
                    if (st.isSieged() && !getGs().defense) {
                        st.unsiege();
                    } else
                        UtilMicro.attack(st, move);
                    return;
                }
            }
            break;
        case REGROUP:
            if (st.isDefenseMatrixed() || getGs().sim.farFromFight(u, squadSim, false))
                return;
            Position pos = getGs().getNearestCC(u.position, true);
            if (Util.broodWarDistance(pos, u.position) >= 400)
                UtilMicro.move(st, pos);
            break;
        case ADVANCE:
            if (st.isSieged() && Math.random() * 10 <= 6)
                st.unsiege();
            else {
                double dist = Util.broodWarDistance(u.position, center);
                if (dist >= 300) {
                    UtilMicro.attack(st, center);
                    return;
                } else if (attack != null) {
                    UtilMicro.move(st, 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 3 with WeaponType

use of org.openbw.bwapi4j.type.WeaponType in project Ecgberht by Jabbo16.

the class Squad method executeRangedAttackLogic.

private void executeRangedAttackLogic(UnitInfo u) {
    if (u.unit.isAttackFrame() || u.unit.isStartingAttack())
        return;
    UnitInfo target = Util.getRangedTarget(u, squadSim.enemies, attack);
    if (target == null) {
        if (attack != null)
            UtilMicro.attack((MobileUnit) u.unit, attack);
        return;
    }
    double distToTarget = u.getDistance(target);
    Optional<UnitInfo> bunker = squadSim.allies.stream().filter(ally -> ally.unitType == UnitType.Terran_Bunker).findFirst();
    if (status == Status.DEFENSE && IntelligenceAgency.enemyIsRushing() && bunker.isPresent() && u.getDistance(bunker.get()) > distToTarget) {
        UtilMicro.move((MobileUnit) u.unit, bunker.get().lastPosition);
    }
    double speed = u.speed;
    if (getGs().frameCount - u.unit.getLastCommandFrame() <= 10)
        return;
    WeaponType w = Util.getWeapon(u, target);
    double range = u.player.getUnitStatCalculator().weaponMaxRange(w);
    int cooldown = (target.flying ? ((AirAttacker) u.unit).getAirWeaponCooldown() : ((GroundAttacker) u.unit).getGroundWeaponCooldown()) - getGs().getIH().getRemainingLatencyFrames() - 2;
    int framesToFiringRange = (int) Math.ceil(Math.max(0, distToTarget - range) / speed);
    if (cooldown <= framesToFiringRange) {
        UtilMicro.attack(u, target);
        return;
    }
    Position predictedPosition = null;
    int targetRange = target.player.getUnitStatCalculator().weaponMaxRange(Util.getWeapon(target, u));
    boolean kite = true;
    boolean enemyTooClose = distToTarget <= 3 * 32 && targetRange <= 32;
    boolean moveCloser = target.unitType == UnitType.Terran_Siege_Tank_Siege_Mode || (target.unit instanceof SCV && ((SCV) target.unit).isRepairing() && target.unit.getOrderTarget() != null && target.unit.getOrderTarget().getType() == UnitType.Terran_Bunker) || (target.unitType.isBuilding() && !Util.canAttack(target, u));
    if (!moveCloser) {
        predictedPosition = UtilMicro.predictUnitPosition(target, 2);
        if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
            double distPredicted = u.getDistance(predictedPosition);
            double distCurrent = u.getDistance(target);
            if (distPredicted > distCurrent) {
                kite = false;
                if (distToTarget > (range - 24))
                    moveCloser = true;
            } else if (distCurrent == distPredicted && range >= (targetRange + 64) && distToTarget > (range - 48)) {
                moveCloser = true;
            }
        }
    }
    if (moveCloser && !enemyTooClose) {
        if (distToTarget > 32 && !u.unit.isStartingAttack() && !u.unit.isAttackFrame()) {
            if (predictedPosition != null)
                UtilMicro.move((MobileUnit) u.unit, predictedPosition);
            else
                UtilMicro.move((MobileUnit) u.unit, target.lastPosition);
        } else
            UtilMicro.attack(u, target);
        return;
    }
    if ((kite || enemyTooClose) && target.unitType.topSpeed() > 0) {
        Position kitePos = UtilMicro.kiteAwayAlt(u.position, target.lastPosition);
        if (kitePos != null)
            UtilMicro.move((MobileUnit) u.unit, kitePos);
        else {
            kitePos = UtilMicro.kiteAway(u.unit, squadSim.enemies);
            if (kitePos != null)
                UtilMicro.move((MobileUnit) u.unit, kitePos);
        }
    } else
        UtilMicro.attack(u, target);
}
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 4 with WeaponType

use of org.openbw.bwapi4j.type.WeaponType in project Ecgberht by Jabbo16.

the class UtilMicro method attack.

public static void attack(UnitInfo attacker, UnitInfo target) {
    try {
        Attacker attackerUnit = (Attacker) attacker.unit;
        if (attackerUnit == null || target == null || !attackerUnit.exists() || attackerUnit.isStartingAttack() || attackerUnit.isAttackFrame())
            return;
        if (getGs().frameCount == attackerUnit.getLastCommandFrame())
            return;
        Unit targetUnit = attackerUnit.getTargetUnit();
        if (target.unit.equals(targetUnit))
            return;
        if (target.visible) {
            WeaponType w = Util.getWeapon(attacker, target);
            double range = attacker.player.getUnitStatCalculator().weaponMaxRange(w);
            if (attacker.getDistance(target) <= range) {
                attackerUnit.attack(target.unit);
                return;
            }
            Position predicted = predictUnitPosition(target, 3);
            if (predicted != null)
                move((MobileUnit) attackerUnit, predicted);
        } else
            move((MobileUnit) attackerUnit, target.lastPosition);
    } catch (Exception e) {
        System.err.println("UtilMicro Attack Exception");
        e.printStackTrace();
    }
}
Also used : Position(org.openbw.bwapi4j.Position) WeaponType(org.openbw.bwapi4j.type.WeaponType)

Example 5 with WeaponType

use of org.openbw.bwapi4j.type.WeaponType 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)

Aggregations

WeaponType (org.openbw.bwapi4j.type.WeaponType)5 Position (org.openbw.bwapi4j.Position)4 Ecgberht.getGs (ecgberht.Ecgberht.getGs)3 SimInfo (ecgberht.Simulation.SimInfo)3 Util (ecgberht.Util.Util)3 UtilMicro (ecgberht.Util.UtilMicro)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Order (org.openbw.bwapi4j.type.Order)3 TechType (org.openbw.bwapi4j.type.TechType)3 UnitType (org.openbw.bwapi4j.type.UnitType)3 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)3 UnitInfo (ecgberht.UnitInfo)1