diff options
author | Trazom62 <none@none> | 2010-04-10 13:52:33 +0200 |
---|---|---|
committer | Trazom62 <none@none> | 2010-04-10 13:52:33 +0200 |
commit | 9d3c7c4ab0c9eb55970c12f6818c7f8e6d9ec2f2 (patch) | |
tree | 77d74e3ae2ee35540e6663688c86d6382a506bc0 /src/game/UnitAI.cpp | |
parent | 4a8bf5900dbd3fa9b7d9d71989d46dad8112fd7f (diff) |
Fix Crash in FoS.
Fixes issue #1566.
+ add support of minimum distance criteria in SelectTarget.
--HG--
branch : trunk
Diffstat (limited to 'src/game/UnitAI.cpp')
-rw-r--r-- | src/game/UnitAI.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/game/UnitAI.cpp b/src/game/UnitAI.cpp index 0404a284b29..7ff4a74b522 100644 --- a/src/game/UnitAI.cpp +++ b/src/game/UnitAI.cpp @@ -83,23 +83,34 @@ bool UnitAI::DoSpellAttackIfReady(uint32 spell) } // default predicate function to select target based on distance, player and/or aura criteria -struct DefaultTargetSelector : public std::unary_function<Unit *, bool> { +struct DefaultTargetSelector : public std::unary_function<Unit *, bool> +{ const Unit *me; float m_dist; bool m_playerOnly; int32 m_aura; // pUnit: the reference unit - // dist: if 0: ignored, if not 0: maximum distance to the reference unit + // dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit // playerOnly: self explaining // aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura DefaultTargetSelector(const Unit *pUnit, float dist, bool playerOnly, int32 aura) : me(pUnit), m_dist(dist), m_playerOnly(playerOnly), m_aura(aura) {} - bool operator() (const Unit *pTarget) { - if (m_playerOnly && (!pTarget || pTarget->GetTypeId() != TYPEID_PLAYER)) + bool operator() (const Unit *pTarget) + { + if (!me) + return false; + + if (!pTarget) + return false; + + if (m_playerOnly && (pTarget->GetTypeId() != TYPEID_PLAYER)) + return false; + + if (m_dist > 0.0f && !me->IsWithinCombatRange(pTarget, m_dist)) return false; - if (m_dist && (!me || !pTarget || !me->IsWithinCombatRange(pTarget, m_dist))) + if (m_dist < 0.0f && me->IsWithinCombatRange(pTarget, -m_dist)) return false; if (m_aura) |