aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2016-10-13 01:23:02 -0300
committerjoschiwald <joschiwald.trinity@gmail.com>2017-09-06 13:12:41 +0200
commit0d22e4f3f4b2c1f289d6f5d860dbaeb66766644e (patch)
treed3a08870feb61b682f4fdad0a8fb439152ade46d
parenta6c0bf00999a624f1e13f474f9ec1f935661916c (diff)
Core/Entities: extend available containers for WorldObject::GetxxxInGrid
(cherry picked from commit 1667dd3b7ad93b67298d27d0b759f886188ebcfa)
-rw-r--r--src/server/game/Entities/Object/Object.cpp102
-rw-r--r--src/server/game/Entities/Object/Object.h11
2 files changed, 29 insertions, 84 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index b2daeff5900..bbf28651921 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -2616,102 +2616,30 @@ GameObject* WorldObject::FindNearestGameObjectOfType(GameobjectTypes type, float
return go;
}
-void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>& gameobjectList, uint32 entry, float maxSearchRange) const
+template <typename Container>
+void WorldObject::GetGameObjectListWithEntryInGrid(Container& gameObjectContainer, uint32 entry, float maxSearchRange /*= 250.0f*/) const
{
Trinity::AllGameObjectsWithEntryInRange check(this, entry, maxSearchRange);
- Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange> searcher(this, gameobjectList, check);
+ Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange> searcher(this, gameObjectContainer, check);
Cell::VisitGridObjects(this, searcher, maxSearchRange);
}
-void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>& creatureList, uint32 entry, float maxSearchRange) const
+template <typename Container>
+void WorldObject::GetCreatureListWithEntryInGrid(Container& creatureContainer, uint32 entry, float maxSearchRange /*= 250.0f*/) const
{
Trinity::AllCreaturesOfEntryInRange check(this, entry, maxSearchRange);
- Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(this, creatureList, check);
+ Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(this, creatureContainer, check);
Cell::VisitGridObjects(this, searcher, maxSearchRange);
}
-void WorldObject::GetPlayerListInGrid(std::list<Player*>& playerList, float maxSearchRange) const
+template <typename Container>
+void WorldObject::GetPlayerListInGrid(Container& playerContainer, float maxSearchRange) const
{
Trinity::AnyPlayerInObjectRangeCheck checker(this, maxSearchRange);
- Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(this, playerList, checker);
+ Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(this, playerContainer, checker);
Cell::VisitWorldObjects(this, searcher, maxSearchRange);
}
-/*
-namespace Trinity
-{
- class NearUsedPosDo
- {
- public:
- NearUsedPosDo(WorldObject const& obj, WorldObject const* searcher, float angle, ObjectPosSelector& selector)
- : i_object(obj), i_searcher(searcher), i_angle(angle), i_selector(selector) { }
-
- void operator()(Corpse*) const { }
- void operator()(DynamicObject*) const { }
-
- void operator()(Creature* c) const
- {
- // skip self or target
- if (c == i_searcher || c == &i_object)
- return;
-
- float x, y, z;
-
- if (!c->IsAlive() || c->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED) ||
- !c->GetMotionMaster()->GetDestination(x, y, z))
- {
- x = c->GetPositionX();
- y = c->GetPositionY();
- }
-
- add(c, x, y);
- }
-
- template<class T>
- void operator()(T* u) const
- {
- // skip self or target
- if (u == i_searcher || u == &i_object)
- return;
-
- float x, y;
-
- x = u->GetPositionX();
- y = u->GetPositionY();
-
- add(u, x, y);
- }
-
- // we must add used pos that can fill places around center
- void add(WorldObject* u, float x, float y) const
- {
- // u is too nearest/far away to i_object
- if (!i_object.IsInRange2d(x, y, i_selector.m_dist - i_selector.m_size, i_selector.m_dist + i_selector.m_size))
- return;
-
- float angle = i_object.GetAngle(u)-i_angle;
-
- // move angle to range -pi ... +pi
- while (angle > M_PI)
- angle -= 2.0f * M_PI;
- while (angle < -M_PI)
- angle += 2.0f * M_PI;
-
- // dist include size of u
- float dist2d = i_object.GetDistance2d(x, y);
- i_selector.AddUsedPos(u->GetObjectSize(), angle, dist2d + i_object.GetObjectSize());
- }
- private:
- WorldObject const& i_object;
- WorldObject const* i_searcher;
- float i_angle;
- ObjectPosSelector& i_selector;
- };
-} // namespace Trinity
-*/
-
-//===================================================================================================
-
void WorldObject::GetNearPoint2D(float &x, float &y, float distance2d, float absAngle) const
{
x = GetPositionX() + (GetObjectSize() + distance2d) * std::cos(absAngle);
@@ -3307,3 +3235,15 @@ void WorldObject::RebuildWorldMapAreaSwaps()
for (uint32 worldMapAreaId : *uiMapSwaps)
_worldMapAreaSwaps.insert(worldMapAreaId);
}
+
+template void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;
+template void WorldObject::GetGameObjectListWithEntryInGrid(std::deque<GameObject*>&, uint32, float) const;
+template void WorldObject::GetGameObjectListWithEntryInGrid(std::vector<GameObject*>&, uint32, float) const;
+
+template void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>&, uint32, float) const;
+template void WorldObject::GetCreatureListWithEntryInGrid(std::deque<Creature*>&, uint32, float) const;
+template void WorldObject::GetCreatureListWithEntryInGrid(std::vector<Creature*>&, uint32, float) const;
+
+template void WorldObject::GetPlayerListInGrid(std::list<Player*>&, float) const;
+template void WorldObject::GetPlayerListInGrid(std::deque<Player*>&, float) const;
+template void WorldObject::GetPlayerListInGrid(std::vector<Player*>&, float) const;
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 80fa6b298bc..c2a51563133 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -524,9 +524,14 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
GameObject* FindNearestGameObject(uint32 entry, float range) const;
GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const;
- void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry = 0, float fMaxSearchRange = 250.0f) const;
- void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry = 0, float fMaxSearchRange = 250.0f) const;
- void GetPlayerListInGrid(std::list<Player*>& lList, float fMaxSearchRange) const;
+ template <typename Container>
+ void GetGameObjectListWithEntryInGrid(Container& gameObjectContainer, uint32 entry, float maxSearchRange = 250.0f) const;
+
+ template <typename Container>
+ void GetCreatureListWithEntryInGrid(Container& creatureContainer, uint32 entry, float maxSearchRange = 250.0f) const;
+
+ template <typename Container>
+ void GetPlayerListInGrid(Container& playerContainer, float maxSearchRange) const;
void DestroyForNearbyPlayers();
virtual void UpdateObjectVisibility(bool forced = true);