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

Method getDistance

bwapi/BWAPILIB/Source/Unit.cpp:90–117  ·  view source on GitHub ↗

--------------------------------------------- GET DISTANCE -----------------------------------------------

Source from the content-addressed store, hash-verified

88 }
89 //--------------------------------------------- GET DISTANCE -----------------------------------------------
90 int UnitInterface::getDistance(Position target) const
91 {
92 // If this unit does not exist or target is invalid
93 if (!exists() || !target)
94 return std::numeric_limits<int>::max();
95
96 /////// Compute distance
97 // compute x distance
98 int xDist = this->getLeft() - target.x;
99 if (xDist < 0)
100 {
101 xDist = target.x - (this->getRight() + 1);
102 if (xDist < 0)
103 xDist = 0;
104 }
105
106 // compute y distance
107 int yDist = this->getTop() - target.y;
108 if (yDist < 0)
109 {
110 yDist = target.y - (this->getBottom() + 1);
111 if (yDist < 0)
112 yDist = 0;
113 }
114
115 // compute actual distance
116 return Positions::Origin.getApproxDistance(Position(xDist, yDist));
117 }
118 int UnitInterface::getDistance(Unit target) const
119 {
120 // If this unit does not exist or target is invalid

Callers 14

getUnitsInRadiusMethod · 0.95
getClosestUnitMethod · 0.95
getUnitsInWeaponRangeMethod · 0.95
isInWeaponRangeMethod · 0.95
getUnitsInRadiusMethod · 0.45
getClosestUnitMethod · 0.45
mainFunction · 0.45
updateMethod · 0.45
updateMethod · 0.45
updateMethod · 0.45
checkPositionMethod · 0.45

Calls 7

getLeftMethod · 0.95
getRightMethod · 0.95
getTopMethod · 0.95
getBottomMethod · 0.95
getApproxDistanceMethod · 0.80
PositionClass · 0.50
existsMethod · 0.45

Tested by 5

updateMethod · 0.36
updateMethod · 0.36
updateMethod · 0.36
checkPositionMethod · 0.36
updateMethod · 0.36