TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ThreatContainer Class Reference

#include <ThreatManager.h>

Public Types

typedef std::list
< HostileReference * > 
StorageType
 

Public Member Functions

 ThreatContainer ()
 
 ~ThreatContainer ()
 
HostileReferenceaddThreat (Unit *victim, float threat)
 
void modifyThreatPercent (Unit *victim, int32 percent)
 
HostileReferenceselectNextVictim (Creature *attacker, HostileReference *currentVictim) const
 
void setDirty (bool isDirty)
 
bool isDirty () const
 
bool empty () const
 
HostileReferencegetMostHated () const
 
HostileReferencegetReferenceByTarget (Unit *victim) const
 
StorageType constgetThreatList () const
 

Private Member Functions

void remove (HostileReference *hostileRef)
 
void addReference (HostileReference *hostileRef)
 
void clearReferences ()
 
void update ()
 

Private Attributes

StorageType iThreatList
 
bool iDirty
 

Friends

class ThreatManager
 

Member Typedef Documentation

Constructor & Destructor Documentation

ThreatContainer::ThreatContainer ( )
inline
151 : iDirty(false) { }
bool iDirty
Definition: ThreatManager.h:196
ThreatContainer::~ThreatContainer ( )
inline
153 { clearReferences(); }
void clearReferences()
Definition: ThreatManager.cpp:253

+ Here is the call graph for this function:

Member Function Documentation

void ThreatContainer::addReference ( HostileReference hostileRef)
inlineprivate
186  {
187  iThreatList.push_back(hostileRef);
188  }
StorageType iThreatList
Definition: ThreatManager.h:195

+ Here is the caller graph for this function:

HostileReference * ThreatContainer::addThreat ( Unit victim,
float  threat 
)
286 {
287  HostileReference* ref = getReferenceByTarget(victim);
288  if (ref)
289  ref->addThreat(threat);
290  return ref;
291 }
HostileReference * getReferenceByTarget(Unit *victim) const
Definition: ThreatManager.cpp:266
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
Definition: ThreatManager.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatContainer::clearReferences ( )
private
254 {
255  for (ThreatContainer::StorageType::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
256  {
257  (*i)->unlink();
258  delete (*i);
259  }
260 
261  iThreatList.clear();
262 }
StorageType iThreatList
Definition: ThreatManager.h:195

+ Here is the caller graph for this function:

bool ThreatContainer::empty ( ) const
inline
166  {
167  return iThreatList.empty();
168  }
StorageType iThreatList
Definition: ThreatManager.h:195

+ Here is the caller graph for this function:

HostileReference* ThreatContainer::getMostHated ( ) const
inline
171  {
172  return iThreatList.empty() ? NULL : iThreatList.front();
173  }
StorageType iThreatList
Definition: ThreatManager.h:195
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

HostileReference * ThreatContainer::getReferenceByTarget ( Unit victim) const
267 {
268  if (!victim)
269  return NULL;
270 
271  ObjectGuid guid = victim->GetGUID();
272  for (ThreatContainer::StorageType::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
273  {
274  HostileReference* ref = (*i);
275  if (ref && ref->getUnitGuid() == guid)
276  return ref;
277  }
278 
279  return NULL;
280 }
StorageType iThreatList
Definition: ThreatManager.h:195
arena_t NULL
Definition: jemalloc_internal.h:624
ObjectGuid getUnitGuid() const
Definition: ThreatManager.h:107
Definition: ThreatManager.h:49
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: ObjectGuid.h:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

StorageType const& ThreatContainer::getThreatList ( ) const
inline
177 { return iThreatList; }
StorageType iThreatList
Definition: ThreatManager.h:195
bool ThreatContainer::isDirty ( ) const
inline
163 { return iDirty; }
bool iDirty
Definition: ThreatManager.h:196
void ThreatContainer::modifyThreatPercent ( Unit victim,
int32  percent 
)
296 {
297  if (HostileReference* ref = getReferenceByTarget(victim))
298  ref->addThreatPercent(percent);
299 }
HostileReference * getReferenceByTarget(Unit *victim) const
Definition: ThreatManager.cpp:266
Definition: ThreatManager.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatContainer::remove ( HostileReference hostileRef)
inlineprivate
181  {
182  iThreatList.remove(hostileRef);
183  }
StorageType iThreatList
Definition: ThreatManager.h:195

+ Here is the caller graph for this function:

HostileReference * ThreatContainer::selectNextVictim ( Creature attacker,
HostileReference currentVictim 
) const
317 {
318  HostileReference* currentRef = NULL;
319  bool found = false;
320  bool noPriorityTargetFound = false;
321 
322  ThreatContainer::StorageType::const_iterator lastRef = iThreatList.end();
323  --lastRef;
324 
325  for (ThreatContainer::StorageType::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)
326  {
327  currentRef = (*iter);
328 
329  Unit* target = currentRef->getTarget();
330  ASSERT(target); // if the ref has status online the target must be there !
331 
332  // some units are prefered in comparison to others
333  if (!noPriorityTargetFound && (target->IsImmunedToDamage(attacker->GetMeleeDamageSchoolMask()) || target->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE)))
334  {
335  if (iter != lastRef)
336  {
337  // current victim is a second choice target, so don't compare threat with it below
338  if (currentRef == currentVictim)
339  currentVictim = NULL;
340  ++iter;
341  continue;
342  }
343  else
344  {
345  // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked.
346  noPriorityTargetFound = true;
347  iter = iThreatList.begin();
348  continue;
349  }
350  }
351 
352  if (attacker->CanCreatureAttack(target)) // skip non attackable currently targets
353  {
354  if (currentVictim) // select 1.3/1.1 better target in comparison current target
355  {
356  // list sorted and and we check current target, then this is best case
357  if (currentVictim == currentRef || currentRef->getThreat() <= 1.1f * currentVictim->getThreat())
358  {
359  if (currentVictim != currentRef && attacker->CanCreatureAttack(currentVictim->getTarget()))
360  currentRef = currentVictim; // for second case, if currentvictim is attackable
361 
362  found = true;
363  break;
364  }
365 
366  if (currentRef->getThreat() > 1.3f * currentVictim->getThreat() ||
367  (currentRef->getThreat() > 1.1f * currentVictim->getThreat() &&
368  attacker->IsWithinMeleeRange(target)))
369  { //implement 110% threat rule for targets in melee range
370  found = true; //and 130% rule for targets in ranged distances
371  break; //for selecting alive targets
372  }
373  }
374  else // select any
375  {
376  found = true;
377  break;
378  }
379  }
380  ++iter;
381  }
382  if (!found)
383  currentRef = NULL;
384 
385  return currentRef;
386 }
StorageType iThreatList
Definition: ThreatManager.h:195
float getThreat() const
Definition: ThreatManager.h:61
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Unit.h:55
bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask) const
Definition: Unit.cpp:9214
bool HasNegativeAuraWithInterruptFlag(uint32 flag, ObjectGuid guid=ObjectGuid::Empty) const
Definition: Unit.cpp:4288
Definition: ThreatManager.h:49
bool IsWithinMeleeRange(const Unit *obj, float dist=MELEE_RANGE) const
Definition: Unit.cpp:508
bool CanCreatureAttack(Unit const *victim, bool force=true) const
Definition: Creature.cpp:2170
SpellSchoolMask GetMeleeDamageSchoolMask() const override
Definition: Creature.h:527
#define ASSERT
Definition: Errors.h:55
Definition: Unit.h:1305
TO * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatContainer::setDirty ( bool  isDirty)
inline
161 { iDirty = isDirty; }
bool iDirty
Definition: ThreatManager.h:196
bool isDirty() const
Definition: ThreatManager.h:163
void ThreatContainer::update ( )
private
305 {
306  if (iDirty && iThreatList.size() > 1)
308 
309  iDirty = false;
310 }
StorageType iThreatList
Definition: ThreatManager.h:195
Definition: ThreatManager.h:282
bool iDirty
Definition: ThreatManager.h:196

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ThreatManager
friend

Member Data Documentation

bool ThreatContainer::iDirty
private
StorageType ThreatContainer::iThreatList
private

The documentation for this class was generated from the following files: