Search in sources :

Example 1 with MobileUnit

use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.

the class DropShipAgent method setCargo.

public void setCargo(Set<Unit> cargo) {
    this.cargoWanted = cargo;
    for (Unit u : this.cargoWanted) {
        if (u instanceof Worker && (((Worker) u).isCarryingMinerals() || ((Worker) u).isCarryingGas())) {
            ((Worker) u).returnCargo();
            ((MobileUnit) u).rightClick(unit, true);
        } else
            ((MobileUnit) u).rightClick(unit, false);
    }
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) Worker(org.openbw.bwapi4j.unit.Worker) MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) Unit(org.openbw.bwapi4j.unit.Unit)

Example 2 with MobileUnit

use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.

the class DropShipAgent method checkLoaded.

private void checkLoaded() {
    if (pickingUp == null)
        return;
    Unit transport = ((MobileUnit) pickingUp).getTransport();
    if (transport != null && transport.equals(unit)) {
        cargoLoaded.add(pickingUp);
        cargoWanted.remove(pickingUp);
        pickingUp = null;
    }
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) Unit(org.openbw.bwapi4j.unit.Unit)

Example 3 with MobileUnit

use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.

the class DropShipAgent method retreat.

protected void retreat() {
    Position CC = getGs().getNearestCC(myUnit.getPosition(), false);
    if (CC != null)
        target = CC;
    else
        target = getGs().getPlayer().getStartLocation().toPosition();
    ((MobileUnit) myUnit).move(target);
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) Position(org.openbw.bwapi4j.Position)

Example 4 with MobileUnit

use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.

the class DropShipAgent method picking.

private void picking() {
    if (cargoWanted.isEmpty())
        return;
    if (pickingUp == null) {
        double distB = Double.MAX_VALUE;
        for (Unit u : cargoWanted) {
            double distA = Util.broodWarDistance(unit.getPosition(), u.getPosition());
            if (pickingUp == null || distA < distB) {
                pickingUp = u;
                distB = distA;
            }
        }
        if (pickingUp != null) {
            unit.load((MobileUnit) pickingUp);
        }
    } else {
        if (unit.getOrderTarget() != null && unit.getOrderTarget().equals(pickingUp))
            return;
        checkLoaded();
    }
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) Unit(org.openbw.bwapi4j.unit.Unit)

Example 5 with MobileUnit

use of org.openbw.bwapi4j.unit.MobileUnit in project Ecgberht by Jabbo16.

the class Repair method execute.

@Override
public State execute() {
    try {
        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;
        if (cheesed || fastExpanding) {
            if (gameState.chosenRepairer.move(gameState.chosenUnitRepair.getPosition())) {
                if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
                    gameState.workerIdle.remove(gameState.chosenRepairer);
                } else {
                    if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
                        MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
                        gameState.workerMining.remove(gameState.chosenRepairer);
                        if (gameState.mineralsAssigned.containsKey(mineral)) {
                            gameState.mining--;
                            gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
                        }
                    }
                }
                gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
                gameState.chosenUnitRepair = null;
                gameState.chosenRepairer = null;
                return State.SUCCESS;
            }
        } else if (gameState.chosenRepairer.repair(gameState.chosenUnitRepair)) {
            if (gameState.workerIdle.contains(gameState.chosenRepairer)) {
                gameState.workerIdle.remove(gameState.chosenRepairer);
            } else {
                if (gameState.workerMining.containsKey(gameState.chosenRepairer)) {
                    MineralPatch mineral = gameState.workerMining.get(gameState.chosenRepairer);
                    gameState.workerMining.remove(gameState.chosenRepairer);
                    if (gameState.mineralsAssigned.containsKey(mineral)) {
                        gameState.mining--;
                        gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
                    }
                }
            }
            gameState.repairerTask.put(gameState.chosenRepairer, gameState.chosenUnitRepair);
            if (gameState.chosenUnitRepair instanceof MobileUnit) {
                ((MobileUnit) gameState.chosenUnitRepair).move(gameState.chosenRepairer.getPosition());
            }
            gameState.chosenUnitRepair = null;
            gameState.chosenRepairer = null;
            return State.SUCCESS;
        }
        gameState.chosenUnitRepair = null;
        gameState.chosenRepairer = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MobileUnit(org.openbw.bwapi4j.unit.MobileUnit) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch)

Aggregations

MobileUnit (org.openbw.bwapi4j.unit.MobileUnit)6 Unit (org.openbw.bwapi4j.unit.Unit)3 Base (bwem.Base)1 ArrayList (java.util.ArrayList)1 Position (org.openbw.bwapi4j.Position)1 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)1 Worker (org.openbw.bwapi4j.unit.Worker)1