use of bwapi.Unit in project BWJSAL by RobinsonMann.
the class UnitsMutexTest method isUnitUnlocked_unitIsLocked_returnsFalse.
@Test
public void isUnitUnlocked_unitIsLocked_returnsFalse() {
final Unit unit = UnitBuilder.mockUnit();
this.target.lockUnit(unit);
assertThat(this.target.isUnitUnlocked(unit)).isFalse();
}
use of bwapi.Unit in project BWJSAL by RobinsonMann.
the class UnitsMutex method lockUnits.
/**
* Attempts to lock all of the given unit.
* @param units Units to lock.
* @return Returns true if locks were acquired for all of the units, false otherwise.
*/
public synchronized boolean lockUnits(final Iterable<Unit> units) {
nonNull(units, "units");
final Set<Unit> unitsWhereLockedAcquired = new HashSet<Unit>();
for (final Unit unitToLock : units) {
if (lockUnit(unitToLock)) {
// Acquired lock.
unitsWhereLockedAcquired.add(unitToLock);
} else {
// Failed to get lock. Rollback all acquired unit locks and return that we have failed.
unlockUnits(unitsWhereLockedAcquired);
return false;
}
}
// all locks acquired, return success.
return true;
}
use of bwapi.Unit in project BWJSAL by RobinsonMann.
the class BfsBuildingPlacer method canBuildHereWithSpace.
private boolean canBuildHereWithSpace(ReservedMap reservedMap, UnitType type, TilePosition position, Unit builder, int buildDist) {
if (type.isAddon()) {
type = type.whatBuilds().first;
}
if (builder != null) {
if (!reservedMap.canBuildHere(builder, position, type)) {
return false;
}
} else {
if (!reservedMap.canBuildHere(position, type)) {
return false;
}
}
if (type.isRefinery()) {
return true;
}
int width = type.tileWidth();
int height = type.tileHeight();
// make sure we leave space for add - ons. These types of units can have addons:
if (type == UnitType.Terran_Command_Center || type == UnitType.Terran_Factory || type == UnitType.Terran_Starport || type == UnitType.Terran_Science_Facility) {
width += 2;
}
int startx = position.getX() - buildDist;
if (startx < 0) {
return false;
}
int starty = position.getY() - buildDist;
if (starty < 0) {
return false;
}
int endx = position.getX() + width + buildDist;
if (endx > game.mapWidth()) {
return false;
}
int endy = position.getY() + height + buildDist;
if (endy > game.mapHeight()) {
return false;
}
for (int x = startx; x < endx; x++) {
for (int y = starty; y < endy; y++) {
if (!isBuildable(builder, x, y) || reservedMap.isReserved(x, y)) {
return false;
}
}
}
if (position.getX() > 3) {
int startx2 = Math.max(startx - 2, 0);
for (int x = startx2; x < startx; x++) {
for (int y = starty; y < endy; y++) {
for (Unit u : game.getUnitsOnTile(x, y)) {
if (!u.isLifted() && u != builder) {
UnitType type2 = u.getType();
if (type2 == UnitType.Terran_Command_Center || type2 == UnitType.Terran_Factory || type2 == UnitType.Terran_Starport || type2 == UnitType.Terran_Science_Facility) {
return false;
}
}
}
}
}
}
return true;
}
Aggregations