Skip to content

Commit bc54ecd

Browse files
committed
more manual fixes
1 parent e3f8446 commit bc54ecd

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/main/java/bwapi/Unit.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,10 @@ public List<Unit> getLarva() {
11711171
.collect(Collectors.toList());
11721172
}
11731173

1174+
public List<Unit> getUnitsInRadius(final int radius) {
1175+
return getUnitsInRadius(radius, u -> true);
1176+
}
1177+
11741178
/**
11751179
* Retrieves the set of all units in a given radius of the current unit.
11761180
*
@@ -1185,7 +1189,7 @@ public List<Unit> getLarva() {
11851189
*
11861190
* @see getClosestUnit, getUnitsInWeaponRange, Game#getUnitsInRadius, Game#getUnitsInRectangle
11871191
*/
1188-
public List<Unit> getUnitsInRadius(final int radius) {
1192+
public List<Unit> getUnitsInRadius(final int radius, final UnitFilter pred) {
11891193
if (!exists()) {
11901194
return Collections.emptyList();
11911195
}
@@ -1194,7 +1198,11 @@ public List<Unit> getUnitsInRadius(final int radius) {
11941198
getTop() - radius,
11951199
getRight() + radius,
11961200
getBottom() + radius,
1197-
u -> getDistance(u) <= radius);
1201+
u -> getDistance(u) <= radius && pred.operation(u));
1202+
}
1203+
1204+
public List<Unit> getUnitsInWeaponRange(final WeaponType weapon) {
1205+
return getUnitsInWeaponRange(weapon, u -> true);
11981206
}
11991207

12001208
/**
@@ -1205,7 +1213,7 @@ public List<Unit> getUnitsInRadius(final int radius) {
12051213
*
12061214
* @see getUnitsInRadius, getClosestUnit, Game#getUnitsInRadius, Game#getUnitsInRectangle
12071215
*/
1208-
public List<Unit> getUnitsInWeaponRange(final WeaponType weapon) {
1216+
public List<Unit> getUnitsInWeaponRange(final WeaponType weapon, final UnitFilter pred) {
12091217
// Return if this unit does not exist
12101218
if (!exists()) {
12111219
return Collections.emptyList();
@@ -1219,6 +1227,9 @@ public List<Unit> getUnitsInWeaponRange(final WeaponType weapon) {
12191227
getRight() + max,
12201228
getBottom() + max,
12211229
u -> {
1230+
if (!pred.operation(u)) {
1231+
return false;
1232+
}
12221233
// Unit check and unit status
12231234
if (u == this || u.isInvincible()) {
12241235
return false;
@@ -2435,6 +2446,19 @@ public boolean load(final Unit target) {
24352446
return issueCommand(UnitCommand.load(this, target));
24362447
}
24372448

2449+
/**
2450+
* Orders the unit to load the target unit. Only works if this unit is a
2451+
* @Transport or @Bunker type.
2452+
*
2453+
* @param target The target unit to load into this @Transport or @Bunker.
2454+
* @param shiftQueueCommand If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
2455+
*
2456+
* @return true if the command was passed to Broodwar, and false if BWAPI determined that
2457+
* the command would fail.
2458+
* @note There is a small chance for a command to fail after it has been passed to Broodwar.
2459+
*
2460+
* @see unload, unloadAll, getLoadedUnits, isLoaded
2461+
*/
24382462
public boolean load(final Unit target, final boolean shiftQueueCommand) {
24392463
return issueCommand(UnitCommand.load(this, target, shiftQueueCommand));
24402464
}
@@ -5049,19 +5073,6 @@ public boolean canUnload(Unit targetUnit) {
50495073
return canUnload(targetUnit, true);
50505074
}
50515075

5052-
/**
5053-
* Orders the unit to load the target unit. Only works if this unit is a
5054-
* @Transport or @Bunker type.
5055-
*
5056-
* @param target The target unit to load into this @Transport or @Bunker.
5057-
* @param shiftQueueCommand If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
5058-
*
5059-
* @return true if the command was passed to Broodwar, and false if BWAPI determined that
5060-
* the command would fail.
5061-
* @note There is a small chance for a command to fail after it has been passed to Broodwar.
5062-
*
5063-
* @see unload, unloadAll, getLoadedUnits, isLoaded
5064-
*/
50655076
/**
50665077
* Cheap checks for whether the unit is able to execute an unload command.
50675078
*

0 commit comments

Comments
 (0)