use of org.openbw.bwapi4j.unit.UnitImpl in project BWAPI4J by OpenBW.
the class MainTest method testMineralMining.
private void testMineralMining() throws AssertionError {
boolean commandSuccessful = false;
Player self = this.bw.getInteractionHandler().self();
Collection<UnitImpl> allUnits = this.bw.getAllUnits();
MineralPatch patch = null;
for (Unit unit : allUnits) {
if (unit instanceof MineralPatch) {
patch = (MineralPatch) unit;
}
}
List<PlayerUnit> units = this.bw.getUnits(self);
SCV scv = null;
for (PlayerUnit unit : units) {
if (unit instanceof SCV) {
scv = (SCV) unit;
}
}
if (patch != null && scv != null) {
commandSuccessful = scv.gather(patch);
} else {
logger.error("no scv and patch found.");
}
assertTrue("gather command failed.", commandSuccessful);
}
use of org.openbw.bwapi4j.unit.UnitImpl in project BWAPI4J by OpenBW.
the class BW method updateAllUnits.
private void updateAllUnits(int frame) {
for (UnitImpl unit : this.units.values()) {
unitDataBridge.preUpdate(unit);
}
int[] unitData = this.getAllUnitsData();
for (int index = 0; index < unitData.length; index += UnitDataBridge.TOTAL_PROPERTIES) {
// TODO: Use the enum from the Unit class.
int unitId = unitData[index + 0];
// TODO: Use the enum from the Unit class.
int typeId = unitData[index + 3];
UnitImpl unit = this.units.get(unitId);
if (unit == null || typeChanged(unit.getType(), UnitType.values()[typeId])) {
if (unit != null) {
logger.debug("unit {} changed type from {} to {}.", unit.getId(), unit.getType(), 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);
unitDataBridge.initialize(unit, unitData, index, frame);
unitDataBridge.update(unit, unitData, index, frame);
logger.trace("initial pos: {}", unit.getInitialTilePosition());
logger.trace("current pos: {}", unit.getTilePosition());
logger.trace(" done.");
}
} else {
unitDataBridge.update(unit, unitData, index, frame);
}
}
}
Aggregations