diff options
author | megamage <none@none> | 2008-10-19 14:42:12 -0500 |
---|---|---|
committer | megamage <none@none> | 2008-10-19 14:42:12 -0500 |
commit | 672d304a4478afa58d6e094b1bf53ae25b176356 (patch) | |
tree | 6c8524a714d9885415249a20274e773be71a10d6 /src/game/Unit.cpp | |
parent | e7519059c93476d2ea78225d3785ddbf6d607900 (diff) |
[svn] Add Unit::IsWithinCombatDist function to check melee range and spell range (now range is related to the attacker's bounding_radius and target's combat_reach, not sure if both should be combat_reach).
--HG--
branch : trunk
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r-- | src/game/Unit.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index ddce852a728..f7a3d96c00d 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -408,6 +408,21 @@ bool Unit::canReachWithAttack(Unit *pVictim) const return IsWithinDistInMap(pVictim, reach); } +bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const +{ + if (!obj || !IsInMap(obj)) return false; + + float dx = GetPositionX() - obj->GetPositionX(); + float dy = GetPositionY() - obj->GetPositionY(); + float dz = GetPositionZ() - obj->GetPositionZ(); + float distsq = dx*dx + dy*dy + dz*dz; + //not sure here, or combatreach + combatreach? + float sizefactor = GetObjectSize() + obj->GetFloatValue(UNIT_FIELD_COMBATREACH); + float maxdist = dist2compare + sizefactor; + + return distsq < maxdist * maxdist; +} + void Unit::RemoveSpellsCausingAura(AuraType auraType) { if (auraType >= TOTAL_AURAS) return; |