Changeset 69 for trunk/src/game/Unit.cpp

Show
Ignore:
Timestamp:
11/19/08 13:31:22 (17 years ago)
Author:
yumileroy
Message:

[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).

Original author: megamage
Date: 2008-10-19 14:42:12-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Unit.cpp

    r63 r69  
    407407        reach = 1.0f; 
    408408    return IsWithinDistInMap(pVictim, reach); 
     409} 
     410 
     411bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const 
     412{ 
     413    if (!obj || !IsInMap(obj)) return false; 
     414 
     415    float dx = GetPositionX() - obj->GetPositionX(); 
     416    float dy = GetPositionY() - obj->GetPositionY(); 
     417    float dz = GetPositionZ() - obj->GetPositionZ(); 
     418    float distsq = dx*dx + dy*dy + dz*dz; 
     419    //not sure here, or combatreach + combatreach? 
     420    float sizefactor = GetObjectSize() + obj->GetFloatValue(UNIT_FIELD_COMBATREACH); 
     421    float maxdist = dist2compare + sizefactor; 
     422 
     423    return distsq < maxdist * maxdist; 
    409424} 
    410425