refactor(Core/SmartScripts): GetTargets returns ObjectList instead of ObjectList* (#11950)

This commit is contained in:
IntelligentQuantum
2022-07-18 13:45:57 +04:30
committed by GitHub
parent cc52712ac1
commit 6ac7dfa26f
5 changed files with 2505 additions and 3309 deletions

View File

@@ -49,6 +49,16 @@ struct WayPoint
uint32 delay;
};
enum eSmartAI
{
SMART_EVENT_PARAM_COUNT = 4,
SMART_ACTION_PARAM_COUNT = 6,
SMART_SUMMON_COUNTER = 0xFFFFFF,
SMART_ESCORT_LAST_OOC_POINT = 0xFFFFFF,
SMART_RANDOM_POINT = 0xFFFFFE,
SMART_ESCORT_TARGETS = 0xFFFFFF
};
enum SMART_EVENT_PHASE
{
SMART_EVENT_PHASE_ALWAYS = 0,
@@ -758,12 +768,7 @@ struct SmartAction
struct
{
uint32 emote1;
uint32 emote2;
uint32 emote3;
uint32 emote4;
uint32 emote5;
uint32 emote6;
std::array<uint32, SMART_ACTION_PARAM_COUNT> emotes;
} randomEmote;
struct
@@ -858,12 +863,7 @@ struct SmartAction
struct
{
uint32 phase1;
uint32 phase2;
uint32 phase3;
uint32 phase4;
uint32 phase5;
uint32 phase6;
std::array<uint32, SMART_ACTION_PARAM_COUNT> phases;
} randomPhase;
struct
@@ -1049,9 +1049,7 @@ struct SmartAction
{
uint32 entry;
uint32 mask;
uint32 slot1;
uint32 slot2;
uint32 slot3;
std::array<uint32, MAX_EQUIPMENT_ITEMS> slots;
} equip;
struct
@@ -1086,12 +1084,7 @@ struct SmartAction
struct
{
uint32 entry1;
uint32 entry2;
uint32 entry3;
uint32 entry4;
uint32 entry5;
uint32 entry6;
std::array<uint32, SMART_ACTION_PARAM_COUNT> actionLists;
} randTimedActionList;
struct
@@ -1209,12 +1202,7 @@ struct SmartAction
struct
{
uint32 wp1;
uint32 wp2;
uint32 wp3;
uint32 wp4;
uint32 wp5;
uint32 wp6;
std::array<uint32, SMART_ACTION_PARAM_COUNT> wps;
} closestWaypointFromList;
struct
@@ -1584,16 +1572,6 @@ enum SmartTargetRoleFlags
SMART_TARGET_ROLE_FLAG_DAMAGERS = 0x004
};
enum eSmartAI
{
SMART_EVENT_PARAM_COUNT = 4,
SMART_ACTION_PARAM_COUNT = 6,
SMART_SUMMON_COUNTER = 0xFFFFFF,
SMART_ESCORT_LAST_OOC_POINT = 0xFFFFFF,
SMART_RANDOM_POINT = 0xFFFFFE,
SMART_ESCORT_TARGETS = 0xFFFFFF
};
enum SmartScriptType
{
SMART_SCRIPT_TYPE_CREATURE = 0, //done
@@ -1802,60 +1780,43 @@ public:
typedef std::unordered_map<uint32, WayPoint*> WPPath;
typedef std::list<WorldObject*> ObjectList;
typedef std::vector<WorldObject*> ObjectVector;
class ObjectGuidList
class ObjectGuidVector
{
ObjectList* m_objectList;
GuidList* m_guidList;
WorldObject* m_baseObject;
public:
ObjectGuidList(ObjectList* objectList, WorldObject* baseObject)
ObjectGuidVector(WorldObject* baseObject, ObjectVector const& objectVector) : _baseObject(baseObject), _objectVector(objectVector)
{
ASSERT(objectList);
m_objectList = objectList;
m_baseObject = baseObject;
m_guidList = new GuidList();
for (ObjectList::iterator itr = objectList->begin(); itr != objectList->end(); ++itr)
{
m_guidList->push_back((*itr)->GetGUID());
}
_guidVector.reserve(_objectVector.size());
for (WorldObject* obj : _objectVector)
_guidVector.push_back(obj->GetGUID());
}
ObjectList* GetObjectList()
ObjectVector const* GetObjectVector() const
{
if (m_baseObject)
{
//sanitize list using m_guidList
m_objectList->clear();
for (GuidList::iterator itr = m_guidList->begin(); itr != m_guidList->end(); ++itr)
{
if (WorldObject* obj = ObjectAccessor::GetWorldObject(*m_baseObject, *itr))
m_objectList->push_back(obj);
//else
// LOG_DEBUG("scripts.ai", "SmartScript::mTargetStorage stores a guid to an invalid object: {}", (*itr).ToString());
}
}
return m_objectList;
UpdateObjects();
return &_objectVector;
}
bool Equals(ObjectList* objectList)
{
return m_objectList == objectList;
}
~ObjectGuidVector() { }
~ObjectGuidList()
private:
WorldObject* const _baseObject;
mutable ObjectVector _objectVector;
GuidVector _guidVector;
//sanitize vector using _guidVector
void UpdateObjects() const
{
delete m_objectList;
delete m_guidList;
_objectVector.clear();
for (ObjectGuid const& guid : _guidVector)
if (WorldObject* obj = ObjectAccessor::GetWorldObject(*_baseObject, guid))
_objectVector.push_back(obj);
}
};
typedef std::unordered_map<uint32, ObjectGuidList*> ObjectListMap;
typedef std::unordered_map<uint32, ObjectGuidVector> ObjectVectorMap;
class SmartWaypointMgr
{