diff options
author | Spp <spp@jorge.gr> | 2012-10-26 14:30:52 +0200 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2012-10-26 14:31:19 +0200 |
commit | 876ad50dcde63eb29c51d54e126c9d66508183ac (patch) | |
tree | 604b0e9f6166dad9ca34cfe088709e11b05010c5 /src/server/game/Combat/ThreatManager.h | |
parent | 6d55ac8c58117de36143be76d6dc8d806ac9abe7 (diff) |
Core/Misc: Tweaked ThreatContainer internals
(and many cosmetic changes here and there)
Diffstat (limited to 'src/server/game/Combat/ThreatManager.h')
-rwxr-xr-x | src/server/game/Combat/ThreatManager.h | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index e5badcd24ce..665acd6d751 100755 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -142,39 +142,57 @@ class ThreatManager; class ThreatContainer { - private: - std::list<HostileReference*> iThreatList; - bool iDirty; - protected: friend class ThreatManager; - void remove(HostileReference* hostileRef) { iThreatList.remove(hostileRef); } - void addReference(HostileReference* hostileRef) { iThreatList.push_back(hostileRef); } - void clearReferences(); - - // Sort the list if necessary - void update(); public: - ThreatContainer() { iDirty = false; } + typedef std::list<HostileReference*> StorageType; + + ThreatContainer(): iDirty(false) { } + ~ThreatContainer() { clearReferences(); } HostileReference* addThreat(Unit* victim, float threat); void modifyThreatPercent(Unit* victim, int32 percent); - HostileReference* selectNextVictim(Creature* attacker, HostileReference* currentVictim); + HostileReference* selectNextVictim(Creature* attacker, HostileReference* currentVictim) const; void setDirty(bool isDirty) { iDirty = isDirty; } bool isDirty() const { return iDirty; } - bool empty() const { return iThreatList.empty(); } + bool empty() const + { + return iThreatList.empty(); + } - HostileReference* getMostHated() { return iThreatList.empty() ? NULL : iThreatList.front(); } + HostileReference* getMostHated() const + { + return iThreatList.empty() ? NULL : iThreatList.front(); + } + + HostileReference* getReferenceByTarget(Unit* victim) const; - HostileReference* getReferenceByTarget(Unit* victim); + StorageType const & getThreatList() const { return iThreatList; } - std::list<HostileReference*>& getThreatList() { return iThreatList; } + private: + void remove(HostileReference* hostileRef) + { + iThreatList.remove(hostileRef); + } + + void addReference(HostileReference* hostileRef) + { + iThreatList.push_back(hostileRef); + } + + void clearReferences(); + + // Sort the list if necessary + void update(); + + StorageType iThreatList; + bool iDirty; }; //================================================= @@ -198,15 +216,15 @@ class ThreatManager float getThreat(Unit* victim, bool alsoSearchOfflineList = false); - bool isThreatListEmpty() { return iThreatContainer.empty(); } + bool isThreatListEmpty() const { return iThreatContainer.empty(); } void processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent); bool isNeedUpdateToClient(uint32 time); - HostileReference* getCurrentVictim() { return iCurrentVictim; } + HostileReference* getCurrentVictim() const { return iCurrentVictim; } - Unit* getOwner() { return iOwner; } + Unit* getOwner() const { return iOwner; } Unit* getHostilTarget(); @@ -223,11 +241,11 @@ class ThreatManager // Reset all aggro of unit in threadlist satisfying the predicate. template<class PREDICATE> void resetAggro(PREDICATE predicate) { - std::list<HostileReference*> &threatList = getThreatList(); + ThreatContainer::StorageType &threatList = iThreatContainer.iThreatList; if (threatList.empty()) return; - for (std::list<HostileReference*>::iterator itr = threatList.begin(); itr != threatList.end(); ++itr) + for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr) { HostileReference* ref = (*itr); @@ -241,8 +259,8 @@ class ThreatManager // methods to access the lists from the outside to do some dirty manipulation (scriping and such) // I hope they are used as little as possible. - std::list<HostileReference*>& getThreatList() { return iThreatContainer.getThreatList(); } - std::list<HostileReference*>& getOfflineThreatList() { return iThreatOfflineContainer.getThreatList(); } + ThreatContainer::StorageType const & getThreatList() const { return iThreatContainer.getThreatList(); } + ThreatContainer::StorageType const & getOfflineThreatList() const { return iThreatOfflineContainer.getThreatList(); } ThreatContainer& getOnlineContainer() { return iThreatContainer; } ThreatContainer& getOfflineContainer() { return iThreatOfflineContainer; } private: @@ -273,4 +291,3 @@ namespace Trinity }; } #endif - |