Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/bwapi/BuildingPlacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ private static void ReserveAllStructures(final PlacementReserve reserve, final U
}

private static void ReserveExistingAddonPlacement(final PlacementReserve reserve, final TilePosition desiredPosition, final Game game) {
final TilePosition start = desiredPosition.subtract(new TilePosition(MAX_RANGE, MAX_RANGE)).divide(2);

final TilePosition start = desiredPosition.subtract(new TilePosition(MAX_RANGE, MAX_RANGE).divide(2));
//Exclude addon placement locations
reserve.backup();
game.self().getUnits().stream()
Expand Down Expand Up @@ -274,15 +273,14 @@ private static void ReserveDefault(final PlacementReserve reserve, final UnitTyp
case Terran_Missile_Turret:
case Protoss_Robotics_Facility:
case Protoss_Gateway:
case Protoss_Photon_Cannon:
default:
ReserveStructure(reserve, it, 2, type, desiredPosition);
break;
case Terran_Barracks:
case Terran_Bunker:
case Zerg_Creep_Colony:
ReserveStructure(reserve, it, 1, type, desiredPosition);
break;
default:
ReserveStructure(reserve, it, 2, type, desiredPosition);
break;
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/bwapi/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,12 @@ public List<Unit> getUnitsOnTile(final int tileX, final int tileY) {
* given build tile.
*/
public List<Unit> getUnitsOnTile(final int tileX, final int tileY, final UnitFilter pred) {
return getAllUnits().stream().filter(u -> {
final TilePosition tp = u.getTilePosition();
return tp.x == tileX && tp.y == tileY && pred.test(u);
}).collect(Collectors.toList());
final TilePosition tile = new TilePosition(tileX, tileY);
if (!tile.isValid(this)) {
return Collections.emptyList();
}
final Position p = tile.toPosition();
return getUnitsInRectangle(p.x, p.y, p.x + 32, p.y + 32, pred);
}

public List<Unit> getUnitsInRectangle(final int left, final int top, final int right, final int bottom) {
Expand Down Expand Up @@ -740,7 +742,7 @@ public List<Unit> getUnitsInRadius(final Position center, final int radius) {

public List<Unit> getUnitsInRadius(final Position center, final int radius, final UnitFilter pred) {
return getAllUnits().stream()
.filter(u -> center.getApproxDistance(u.getPosition()) <= radius && pred.test(u))
.filter(u -> u.getDistance(center) <= radius && pred.test(u))
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -2380,10 +2382,9 @@ public int getLastEventTime() {
* parameter.
*/
final public boolean setMap(final String mapFileName) {
if (mapFileName == null || mapFileName.length() >= 260 || mapFileName.charAt(0) == 0) {
if (mapFileName == null || mapFileName.isEmpty() || mapFileName.length() >= 260 || mapFileName.charAt(0) == 0) {
return false;
}

addCommand(CommandType.SetMap, mapFileName, 0);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bwapi/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public Text getTextColor() {
return Text.Blue;
case 159: // teal
return Text.Teal;
case 164: // purp
case 164: // purple
return Text.Purple;
case 156: // orange with fix from @n00byEdge
return Text.Orange;
Expand All @@ -561,7 +561,7 @@ public Text getTextColor() {
return Text.PlayerWhite;
case 135: // yellow
return Text.PlayerYellow;
case 185: // green p9
case 117: // green
return Text.DarkGreen;
case 136: // p10
return Text.LightYellow;
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/bwapi/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ public List<Unit> getUnitsInRadius(final int radius, final UnitFilter pred) {
getTop() - radius,
getRight() + radius,
getBottom() + radius,
u -> getDistance(u) <= radius && pred.test(u));
u -> u != this && getDistance(u) <= radius && pred.test(u));
}

public List<Unit> getUnitsInWeaponRange(final WeaponType weapon) {
Expand Down Expand Up @@ -1301,30 +1301,28 @@ public List<Unit> getUnitsInWeaponRange(final WeaponType weapon, final UnitFilte
getRight() + max,
getBottom() + max,
u -> {
if (!pred.test(u)) {
return false;
}
// Unit check and unit status
if (u == this || u.isInvincible()) {
return false;
}

// Weapon distance check
final int dist = getDistance(u);
if ((weapon.minRange() != 0 && dist < weapon.minRange()) || dist > max) {
return false;
}

// Weapon behavioural checks
final UnitType ut = u.getType();
return (!weapon.targetsOwn() || u.getPlayer().equals(getPlayer())) &&
(weapon.targetsAir() || u.isFlying()) &&
(weapon.targetsGround() || !u.isFlying()) &&
(!weapon.targetsMechanical() || !ut.isMechanical()) &&
(!weapon.targetsOrganic() || !ut.isOrganic()) &&
(!weapon.targetsNonBuilding() || ut.isBuilding()) &&
(!weapon.targetsNonRobotic() || ut.isRobotic()) &&
(!weapon.targetsOrgOrMech() || (!ut.isOrganic() && !ut.isMechanical()));
if ((weapon.targetsOwn() && !u.getPlayer().equals(getPlayer())) ||
(!weapon.targetsAir() && !u.isFlying()) ||
(!weapon.targetsGround() && u.isFlying()) ||
(weapon.targetsMechanical() && ut.isMechanical()) ||
(weapon.targetsOrganic() && ut.isOrganic()) ||
(weapon.targetsNonBuilding() && !ut.isBuilding()) ||
(weapon.targetsNonRobotic() && !ut.isRobotic()) ||
(weapon.targetsOrgOrMech() && (ut.isOrganic() || ut.isMechanical()))) {
return false;
}
return pred.test(u);
});
}

Expand Down Expand Up @@ -3879,7 +3877,7 @@ public boolean canAttackUnitGrouped(Unit targetUnit, boolean checkCanTargetUnit,
return false;
}

if (isInvincible()) {
if (targetUnit.isInvincible()) {
return false;
}

Expand Down Expand Up @@ -4687,12 +4685,10 @@ public boolean canGather(Unit targetUnit, boolean checkCanTargetUnit, boolean ch
return false;
}

if (!hasPath(getPosition())) {
if (!hasPath(targetUnit.getPosition())) {
return false;
}

return !uType.isRefinery() || getPlayer().equals(game.self());

return !targetUnit.getType().isRefinery() || targetUnit.getPlayer().equals(game.self());
}

public boolean canReturnCargo() {
Expand Down Expand Up @@ -6137,7 +6133,7 @@ public boolean canUseTechUnit(TechType tech, Unit targetUnit, boolean checkCanTa
if (!targetType.isOrganic() || targetType.isFlyer()) {
return false;
}
if (!targetUnit.getPlayer().isNeutral() && getPlayer().isEnemy(getPlayer())) {
if (!targetUnit.getPlayer().isNeutral() && getPlayer().isEnemy(targetUnit.getPlayer())) {
return false;
}
break;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/bwapi/UnitFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.function.Predicate;

public interface UnitFilter extends Predicate<Unit> {
UnitFilter IsTransPort = u -> u.getType().spaceProvided() > 0 && u.getType() != UnitType.Terran_Bunker;
UnitFilter IsTransport = u -> u.getType().spaceProvided() > 0 && u.getType() != UnitType.Terran_Bunker;
@Deprecated // backwards compatible
UnitFilter IsTransPort = IsTransport;
UnitFilter CanProduce = u -> u.getType().canProduce();
UnitFilter CanAttack = u -> u.getType().canAttack();
UnitFilter CanMove = u -> u.getType().canMove();
Expand Down
Loading