--------------------------------------------- GET DISTANCE -----------------------------------------------
| 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 |