aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/ScriptedAI
diff options
context:
space:
mode:
authorSpp <spp@jorge.gr>2013-03-21 11:06:05 +0100
committerSpp <spp@jorge.gr>2013-03-21 11:06:05 +0100
commitd0910974336115be1dd06577c63fe3703e8170d2 (patch)
treee656319942795130e33fb7829aae9f5e027a96b6 /src/server/game/AI/ScriptedAI
parent64cffa1271e852f88abd45519fdca301d9c887f2 (diff)
Core/AI: Do not expose internal storage of SummonList
Diffstat (limited to 'src/server/game/AI/ScriptedAI')
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.cpp30
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.h100
2 files changed, 92 insertions, 38 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
index e36916decae..d2c62176daf 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
@@ -24,26 +24,28 @@ struct TSpellSummary
void SummonList::DoZoneInCombat(uint32 entry)
{
- for (iterator i = begin(); i != end();)
+ for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
{
Creature* summon = Unit::GetCreature(*me, *i);
++i;
if (summon && summon->IsAIEnabled
- && (!entry || summon->GetEntry() == entry))
+ && (!entry || summon->GetEntry() == entry))
+ {
summon->AI()->DoZoneInCombat();
+ }
}
}
void SummonList::DespawnEntry(uint32 entry)
{
- for (iterator i = begin(); i != end();)
+ for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
{
Creature* summon = Unit::GetCreature(*me, *i);
if (!summon)
- erase(i++);
+ i = storage_.erase(i);
else if (summon->GetEntry() == entry)
{
- erase(i++);
+ i = storage_.erase(i);
summon->DespawnOrUnsummon();
}
else
@@ -53,33 +55,29 @@ void SummonList::DespawnEntry(uint32 entry)
void SummonList::DespawnAll()
{
- while (!empty())
+ while (!storage_.empty())
{
- Creature* summon = Unit::GetCreature(*me, *begin());
- if (!summon)
- erase(begin());
- else
- {
- erase(begin());
+ Creature* summon = Unit::GetCreature(*me, storage_.front());
+ storage_.pop_front();
+ if (summon)
summon->DespawnOrUnsummon();
- }
}
}
void SummonList::RemoveNotExisting()
{
- for (iterator i = begin(); i != end();)
+ for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
{
if (Unit::GetCreature(*me, *i))
++i;
else
- erase(i++);
+ i = storage_.erase(i);
}
}
bool SummonList::HasEntry(uint32 entry) const
{
- for (const_iterator i = begin(); i != end(); ++i)
+ for (StorageType::const_iterator i = storage_.begin(); i != storage_.end(); ++i)
{
Creature* summon = Unit::GetCreature(*me, *i);
if (summon && summon->GetEntry() == entry)
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
index 8d7a28d4e6f..5e612b0cbda 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
@@ -30,33 +30,89 @@
class InstanceScript;
-class SummonList : public std::list<uint64>
+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