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

Method getUnitsInWeaponRange

bwapi/BWAPILIB/Source/Unit.cpp:45–82  ·  view source on GitHub ↗

--------------------------------------------- GET UNITS IN WEAPON RANGE ----------------------------------

Source from the content-addressed store, hash-verified

43 }
44 //--------------------------------------------- GET UNITS IN WEAPON RANGE ----------------------------------
45 Unitset UnitInterface::getUnitsInWeaponRange(WeaponType weapon, const UnitFilter &pred) const
46 {
47 // Return if this unit does not exist
48 if ( !this->exists() )
49 return Unitset::none;
50
51 int max = this->getPlayer()->weaponMaxRange(weapon);
52
53 return Broodwar->getUnitsInRectangle(this->getLeft() - max,
54 this->getTop() - max,
55 this->getRight() + max,
56 this->getBottom() + max,
57 [&](Unit u)->bool
58 {
59 // Unit check and unit status
60 if ( u == this || u->isInvincible() )
61 return false;
62
63 // Weapon distance check
64 int dist = this->getDistance(u);
65 if ( (weapon.minRange() && dist < weapon.minRange()) || dist > max )
66 return false;
67
68 // Weapon behavioural checks
69 UnitType ut = u->getType();
70 if ( (( weapon.targetsOwn() && u->getPlayer() != this->getPlayer() ) ||
71 ( !weapon.targetsAir() && !u->isFlying() ) ||
72 ( !weapon.targetsGround() && u->isFlying() ) ||
73 ( weapon.targetsMechanical() && ut.isMechanical() ) ||
74 ( weapon.targetsOrganic() && ut.isOrganic() ) ||
75 ( weapon.targetsNonBuilding() && !ut.isBuilding() ) ||
76 ( weapon.targetsNonRobotic() && !ut.isRobotic() ) ||
77 ( weapon.targetsOrgOrMech() && (ut.isOrganic() || ut.isMechanical()) )) )
78 return false;
79
80 return pred(u);
81 });
82 }
83 //--------------------------------------------- GET TILE POSITION ------------------------------------------
84 TilePosition UnitInterface::getTilePosition() const
85 {

Callers

nothing calls this directly

Calls 15

getLeftMethod · 0.95
getTopMethod · 0.95
getRightMethod · 0.95
getBottomMethod · 0.95
getDistanceMethod · 0.95
weaponMaxRangeMethod · 0.80
minRangeMethod · 0.80
targetsOwnMethod · 0.80
targetsAirMethod · 0.80
isFlyingMethod · 0.80
targetsGroundMethod · 0.80
targetsMechanicalMethod · 0.80

Tested by

no test coverage detected