MCPcopy Create free account
hub / github.com/bwapi/bwapi / isInWeaponRange

Method isInWeaponRange

bwapi/BWAPILIB/Source/Unit.cpp:264–288  ·  view source on GitHub ↗

--------------------------------------------- IS IN WEAPON RANGE -----------------------------------------

Source from the content-addressed store, hash-verified

262
263 //--------------------------------------------- IS IN WEAPON RANGE -----------------------------------------
264 bool UnitInterface::isInWeaponRange(Unit target) const
265 {
266 // Preliminary checks
267 if ( !this->exists() || !target || !target->exists() || this == target )
268 return false;
269
270 // Store the types as locals
271 UnitType thisType = getType();
272 UnitType targType = target->getType();
273
274 // Obtain the weapon type
275 WeaponType wpn = target->isFlying() ? thisType.airWeapon() : thisType.groundWeapon();
276
277 // Return if there is no weapon type
278 if ( wpn == WeaponTypes::None || wpn == WeaponTypes::Unknown )
279 return false;
280
281 // Retrieve the min and max weapon ranges
282 int minRange = wpn.minRange();
283 int maxRange = getPlayer()->weaponMaxRange(wpn);
284
285 // Check if the distance to the unit is within the weapon range
286 int distance = this->getDistance(target);
287 return (minRange ? minRange < distance : true) && distance <= maxRange;
288 }
289
290 bool UnitInterface::isIrradiated() const
291 {

Callers 5

canAttackUnitFunction · 0.80
canAttackUnitGroupedFunction · 0.80
HasEnemyTargetMethod · 0.80
FindNewAttackTargetMethod · 0.80
onFrameMethod · 0.80

Calls 8

getDistanceMethod · 0.95
isFlyingMethod · 0.80
airWeaponMethod · 0.80
groundWeaponMethod · 0.80
minRangeMethod · 0.80
weaponMaxRangeMethod · 0.80
existsMethod · 0.45
getTypeMethod · 0.45

Tested by 1

onFrameMethod · 0.64