--------------------------------------------- IS IN WEAPON RANGE -----------------------------------------
| 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 | { |