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);
}
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);
}
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;
}
}
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);
}
}
}
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);
}
Aggregations