Search in sources :

Example 11 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class Vulture method getNewStatus.

private void getNewStatus() {
    Position myPos = unit.getPosition();
    if (getGs().enemyCombatUnitMemory.isEmpty()) {
        status = Status.ATTACK;
        return;
    }
    for (Unit u : getGs().enemyCombatUnitMemory) {
        if (u.getType().isWorker() && !u.isAttacking()) {
            closeWorkers.add(u);
        }
        if (getGs().broodWarDistance(u.getPosition(), myPos) < 600) {
            closeEnemies.add(u);
        }
    }
    for (EnemyBuilding u : getGs().enemyBuildingMemory.values()) {
        if ((u.type.canAttack() || u.type == UnitType.Terran_Bunker) && u.unit.isCompleted()) {
            if (getGs().broodWarDistance(myPos, u.pos.toPosition()) <= 600) {
                closeEnemies.add(u.unit);
            }
        }
    }
    if (closeEnemies.isEmpty()) {
        status = Status.ATTACK;
        return;
    } else {
        boolean meleeOnly = checkOnlyMelees();
        int sim = 80;
        if (meleeOnly) {
            sim = 5;
        }
        if (!getGs().simulateHarass(unit, closeEnemies, sim)) {
            status = Status.RETREAT;
            return;
        }
        int cd = unit.getGroundWeaponCooldown();
        if (status == Status.COMBAT || status == Status.ATTACK) {
            if (attackUnit != null) {
                if (attackUnit.getType().groundWeapon().maxRange() > type.groundWeapon().maxRange()) {
                    return;
                }
            }
            if (cd > 0) {
                status = Status.KITE;
                return;
            }
        }
        if (status == Status.KITE) {
            if (attackUnit == null) {
                Unit closest = getUnitToAttack(unit, closeEnemies);
                if (closest != null) {
                    double dist = getGs().broodWarDistance(unit.getPosition(), closest.getPosition());
                    double speed = type.topSpeed();
                    double timeToEnter = 0.0;
                    if (speed > .00001) {
                        timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
                    }
                    if (timeToEnter >= cd) {
                        status = Status.COMBAT;
                        return;
                    }
                }
            } else {
                double dist = getGs().broodWarDistance(unit.getPosition(), attackUnit.getPosition());
                double speed = type.topSpeed();
                double timeToEnter = 0.0;
                if (speed > .00001) {
                    timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
                }
                if (timeToEnter >= cd) {
                    status = Status.COMBAT;
                    return;
                }
            }
            if (cd == 0) {
                status = Status.COMBAT;
                return;
            }
        }
    }
}
Also used : Position(bwapi.Position) Unit(bwapi.Unit) EnemyBuilding(ecgberht.EnemyBuilding)

Example 12 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class ChooseBlotWorker method execute.

@Override
public State execute() {
    try {
        Unit closestWorker = null;
        Position chosen = ((GameState) this.handler).chosenBuildingLot.getPosition();
        if (!((GameState) this.handler).workerIdle.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerIdle) {
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                    closestWorker = u;
                }
            }
        }
        if (!((GameState) this.handler).workerTask.isEmpty()) {
            for (Pair<Unit, Unit> u : ((GameState) this.handler).workerTask) {
                if ((closestWorker == null || u.first.getDistance(chosen) < closestWorker.getDistance(chosen)) && u.second.getType().isMineralField() && !u.first.isCarryingMinerals()) {
                    closestWorker = u.first;
                }
            }
        }
        if (closestWorker != null) {
            ((GameState) this.handler).chosenWorker = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Position(bwapi.Position) GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 13 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class ChooseRepairer method execute.

@Override
public State execute() {
    try {
        Unit closestWorker = null;
        Position chosen = ((GameState) this.handler).chosenBuildingRepair.getPosition();
        int frame = ((GameState) this.handler).frameCount;
        for (Unit u : ((GameState) this.handler).workerIdle) {
            if (u.getLastCommandFrame() == frame) {
                continue;
            }
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                closestWorker = u;
            }
        }
        for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
            if (u.getLastCommandFrame() == frame) {
                continue;
            }
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                closestWorker = u;
            }
        }
        if (closestWorker != null) {
            ((GameState) this.handler).chosenRepairer = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Position(bwapi.Position) GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 14 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class ChooseWorker method execute.

@Override
public State execute() {
    try {
        Unit closestWorker = null;
        int frame = ((GameState) this.handler).frameCount;
        Position chosen = ((GameState) this.handler).chosenPosition.toPosition();
        if (!((GameState) this.handler).workerIdle.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerIdle) {
                if (u.getLastCommandFrame() == frame) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                    closestWorker = u;
                }
            }
        }
        if (!((GameState) this.handler).workerMining.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
                if (u.getLastCommandFrame() == frame) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                    closestWorker = u;
                }
            }
        }
        if (closestWorker != null) {
            ((GameState) this.handler).chosenWorker = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Position(bwapi.Position) GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 15 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class Move method execute.

@Override
public State execute() {
    try {
        Unit chosen = ((GameState) this.handler).chosenWorker;
        if (!chosen.canMove()) {
            return State.FAILURE;
        }
        boolean success = false;
        if (((GameState) this.handler).chosenToBuild == UnitType.Terran_Refinery) {
            success = chosen.build(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition);
        } else {
            Position realEnd = ((GameState) this.handler).getCenterFromBuilding(((GameState) this.handler).chosenPosition.toPosition(), ((GameState) this.handler).chosenToBuild);
            success = chosen.move(realEnd);
        }
        if (success) {
            if (((GameState) this.handler).workerIdle.contains(chosen)) {
                ((GameState) this.handler).workerIdle.remove(chosen);
            } else {
                if (((GameState) this.handler).workerMining.containsKey(chosen)) {
                    Unit mineral = ((GameState) this.handler).workerMining.get(chosen);
                    ((GameState) this.handler).workerMining.remove(chosen);
                    if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
                        ((GameState) this.handler).mining--;
                        ((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
                    }
                }
            }
            ((GameState) this.handler).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition)));
            ((GameState) this.handler).deltaCash.first += ((GameState) this.handler).chosenToBuild.mineralPrice();
            ((GameState) this.handler).deltaCash.second += ((GameState) this.handler).chosenToBuild.gasPrice();
            ((GameState) this.handler).chosenWorker = null;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : TilePosition(bwapi.TilePosition) Position(bwapi.Position) GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Aggregations

Position (bwapi.Position)18 Unit (bwapi.Unit)14 GameState (ecgberht.GameState)9 TilePosition (bwapi.TilePosition)4 HashSet (java.util.HashSet)3 Pair (bwapi.Pair)2 EnemyBuilding (ecgberht.EnemyBuilding)2 Squad (ecgberht.Squad)2 UnitCommand (bwapi.UnitCommand)1 BaseLocation (bwta.BaseLocation)1 Region (bwta.Region)1 ArrayList (java.util.ArrayList)1