Search in sources :

Example 6 with Unit

use of org.openbw.bwapi4j.unit.Unit in project BWAPI4J by OpenBW.

the class BW method onUnitCreate.

private void onUnitCreate(int unitId) {
    Unit unit = this.units.get(unitId);
    if (unit == null) {
        logger.error("onUnitCreate: no unit found for ID {}.", unitId);
    }
    listener.onUnitCreate(unit);
}
Also used : Unit(org.openbw.bwapi4j.unit.Unit) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 7 with Unit

use of org.openbw.bwapi4j.unit.Unit in project BWAPI4J by OpenBW.

the class BW method onUnitDiscover.

private void onUnitDiscover(int unitId) {
    Unit unit = this.units.get(unitId);
    if (unit == null) {
        logger.error("onUnitDiscover: no unit found for ID {}.", unitId);
    }
    listener.onUnitDiscover(unit);
}
Also used : Unit(org.openbw.bwapi4j.unit.Unit) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 8 with Unit

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

the class ChooseGoliath method execute.

@Override
public State execute() {
    try {
        if (gameState.UBs.stream().filter(unit -> unit instanceof Armory).count() < 1)
            return State.FAILURE;
        int count = 0;
        for (Unit u : gameState.getGame().getUnits(gameState.getPlayer())) {
            if (!u.exists())
                continue;
            if (u.getType() == UnitType.Terran_Goliath)
                count++;
            if (count >= gameState.maxGoliaths)
                return State.FAILURE;
        }
        if (!gameState.Fs.isEmpty()) {
            for (Factory b : gameState.Fs) {
                if (!b.isTraining() && b.canTrain(UnitType.Terran_Goliath)) {
                    gameState.chosenUnit = UnitType.Terran_Goliath;
                    gameState.chosenTrainingFacility = b;
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Factory(org.openbw.bwapi4j.unit.Factory) Unit(org.openbw.bwapi4j.unit.Unit) Armory(org.openbw.bwapi4j.unit.Armory)

Example 9 with Unit

use of org.openbw.bwapi4j.unit.Unit in project BWAPI4J by OpenBW.

the class BW method updateAllUnits.

private void updateAllUnits(int frame) {
    for (Unit unit : this.units.values()) {
        unit.preUpdate();
    }
    int[] unitData = this.getAllUnitsData();
    for (int index = 0; index < unitData.length; index += Unit.TOTAL_PROPERTIES) {
        int unitId = unitData[index + 0];
        int typeId = unitData[index + 3];
        Unit unit = this.units.get(unitId);
        if (unit == null || typeChanged(unit.getInitialType(), UnitType.values()[typeId])) {
            if (unit != null) {
                logger.debug("unit {} changed type from {} to {}.", unit.getId(), unit.getInitialType(), UnitType.values()[typeId]);
            }
            logger.trace("creating unit for id {} and type {} ({}) ...", unitId, typeId, UnitType.values()[typeId]);
            unit = unitFactory.createUnit(unitId, UnitType.values()[typeId], frame);
            if (unit == null) {
                logger.error("could not create unit for id {} and type {}.", unitId, UnitType.values()[typeId]);
            } else {
                logger.trace("state: {}", unit.exists() ? "completed" : "created");
                this.units.put(unitId, unit);
                unit.initialize(unitData, index, frame);
                unit.update(unitData, index, frame);
                logger.trace("initial pos: {}", unit.getInitialTilePosition());
                logger.trace("current pos: {}", unit.getTilePosition());
                logger.trace(" done.");
            }
        } else {
            unit.update(unitData, index, frame);
        }
    }
}
Also used : Unit(org.openbw.bwapi4j.unit.Unit) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 10 with Unit

use of org.openbw.bwapi4j.unit.Unit in project BWAPI4J by OpenBW.

the class BW method onUnitHide.

private void onUnitHide(int unitId) {
    Unit unit = this.units.get(unitId);
    if (unit == null) {
        logger.error("onUnitHide: no unit found for ID {}.", unitId);
    }
    listener.onUnitHide(unit);
}
Also used : Unit(org.openbw.bwapi4j.unit.Unit) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Aggregations

Unit (org.openbw.bwapi4j.unit.Unit)19 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)11 MobileUnit (org.openbw.bwapi4j.unit.MobileUnit)3 Base (bwem.Base)2 MutablePair (ecgberht.Util.MutablePair)2 Position (org.openbw.bwapi4j.Position)2 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)2 SCV (org.openbw.bwapi4j.unit.SCV)2 Worker (org.openbw.bwapi4j.unit.Worker)2 DropShipAgent (ecgberht.Agents.DropShipAgent)1 Ecgberht.getGs (ecgberht.Ecgberht.getGs)1 SimInfo (ecgberht.Simulation.SimInfo)1 UnitInfo (ecgberht.UnitInfo)1 Util (ecgberht.Util.Util)1 UtilMicro (ecgberht.Util.UtilMicro)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1