-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core/AI: Do not expose internal storage of SummonList
- Loading branch information
Showing
11 changed files
with
127 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,33 +30,89 @@ | |
|
||
class InstanceScript; | ||
|
||
class SummonList : public std::list<uint64> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
DDuarte
Contributor
|
||
class SummonList | ||
{ | ||
public: | ||
explicit SummonList(Creature* creature) : me(creature) {} | ||
void Summon(Creature* summon) { push_back(summon->GetGUID()); } | ||
void Despawn(Creature* summon) { remove(summon->GetGUID()); } | ||
void DespawnEntry(uint32 entry); | ||
void DespawnAll(); | ||
public: | ||
typedef std::list<uint64> StorageType; | ||
typedef StorageType::iterator iterator; | ||
typedef StorageType::const_iterator const_iterator; | ||
typedef StorageType::size_type size_type; | ||
typedef StorageType::value_type value_type; | ||
|
||
explicit SummonList(Creature* creature) | ||
: me(creature) | ||
{ } | ||
|
||
// And here we see a problem of original inheritance approach. People started | ||
// to exploit presence of std::list members, so I have to provide wrappers | ||
|
||
iterator begin() | ||
{ | ||
return storage_.begin(); | ||
} | ||
|
||
const_iterator begin() const | ||
{ | ||
return storage_.begin(); | ||
} | ||
|
||
template <class Predicate> void DoAction(int32 info, Predicate& predicate, uint16 max = 0) | ||
iterator end() | ||
{ | ||
return storage_.end(); | ||
} | ||
|
||
const_iterator end() const | ||
{ | ||
return storage_.end(); | ||
} | ||
|
||
iterator erase(iterator i) | ||
{ | ||
return storage_.erase(i); | ||
} | ||
|
||
bool empty() const | ||
{ | ||
return storage_.empty(); | ||
} | ||
|
||
size_type size() const | ||
{ | ||
return storage_.size(); | ||
} | ||
|
||
void Summon(Creature const* summon) { storage_.push_back(summon->GetGUID()); } | ||
void Despawn(Creature const* summon) { storage_.remove(summon->GetGUID()); } | ||
void DespawnEntry(uint32 entry); | ||
void DespawnAll(); | ||
|
||
template <typename T> | ||
void DespawnIf(T const &predicate) | ||
{ | ||
storage_.remove_if(predicate); | ||
} | ||
|
||
template <class Predicate> | ||
void DoAction(int32 info, Predicate& predicate, uint16 max = 0) | ||
{ | ||
// We need to use a copy of SummonList here, otherwise original SummonList would be modified | ||
StorageType listCopy = storage_; | ||
Trinity::Containers::RandomResizeList<uint64, Predicate>(listCopy, predicate, max); | ||
for (StorageType::iterator i = listCopy.begin(); i != listCopy.end(); ) | ||
{ | ||
// We need to use a copy of SummonList here, otherwise original SummonList would be modified | ||
std::list<uint64> listCopy = *this; | ||
Trinity::Containers::RandomResizeList<uint64, Predicate>(listCopy, predicate, max); | ||
for (iterator i = listCopy.begin(); i != listCopy.end(); ) | ||
{ | ||
Creature* summon = Unit::GetCreature(*me, *i++); | ||
if (summon && summon->IsAIEnabled) | ||
summon->AI()->DoAction(info); | ||
} | ||
Creature* summon = Unit::GetCreature(*me, *i++); | ||
if (summon && summon->IsAIEnabled) | ||
summon->AI()->DoAction(info); | ||
} | ||
} | ||
|
||
void DoZoneInCombat(uint32 entry = 0); | ||
void RemoveNotExisting(); | ||
bool HasEntry(uint32 entry) const; | ||
private: | ||
Creature* me; | ||
void DoZoneInCombat(uint32 entry = 0); | ||
void RemoveNotExisting(); | ||
bool HasEntry(uint32 entry) const; | ||
|
||
private: | ||
Creature* me; | ||
StorageType storage_; | ||
}; | ||
|
||
class EntryCheckPredicate | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Or, you could have just made inheritance private here :P