Merge [SD2]

r1088 Add grid searcher class PlayerAtMinimumRangeAway and create ScriptedAI function GetPlayerAtMinimumRange that return player in grid with at least the defined range away from m_creature.
r1089 Remove no longer needed grid search code and use function instead. - skip
r1090 Rename and clarify function variables - skip
r1091 Add two new grid search functions to return list of creature and gameobject. Remove unused class.
r1092 Remove more grid search code in scripts and use functions instead.
r1093 Remove obsolete grid search class and rename new to a more consistent name.
r1094 Speed up functions GetCreature/GameObjectListWithEntryInGrid a bit

--HG--
branch : trunk
This commit is contained in:
Kudlaty
2009-07-24 05:27:49 +02:00
parent ff1b2ed88c
commit 607dfaf8c9
9 changed files with 104 additions and 77 deletions
@@ -533,6 +533,25 @@ std::list<Creature*> ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 s
return pList;
}
Player* ScriptedAI::GetPlayerAtMinimumRange(float fMinimumRange)
{
Player* pPlayer = NULL;
CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
Trinity::PlayerAtMinimumRangeAway check(m_creature, fMinimumRange);
Trinity::PlayerSearcher<Trinity::PlayerAtMinimumRangeAway> searcher(m_creature, pPlayer, check);
TypeContainerVisitor<Trinity::PlayerSearcher<Trinity::PlayerAtMinimumRangeAway>, GridTypeMapContainer> visitor(searcher);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, visitor, *(m_creature->GetMap()));
return pPlayer;
}
void ScriptedAI::SetEquipmentSlots(bool bLoadDefault, int32 uiMainHand, int32 uiOffHand, int32 uiRanged)
{
if (bLoadDefault)
+3 -1
View File
@@ -169,6 +169,9 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
//Returns a list of all friendly units missing a specific buff within range
std::list<Creature*> DoFindFriendlyMissingBuff(float range, uint32 spellid);
//Return a player with at least minimumRange from m_creature
Player* GetPlayerAtMinimumRange(float fMinimumRange);
//Spawns a creature relative to m_creature
Creature* DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime);
Creature *DoSummon(uint32 entry, const float pos[4], uint32 despawntime = 30000, TempSummonType type = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
@@ -248,6 +251,5 @@ struct TRINITY_DLL_DECL BossAI : public ScriptedAI
//return closest creature alive in grid, with range from pSource
Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 Entry, float MaxSearchRange);
#endif
@@ -441,8 +441,6 @@ struct TRINITY_DLL_DECL npc_geezleAI : public ScriptedAI
{
npc_geezleAI(Creature *c) : ScriptedAI(c) {}
std::list<GameObject*> FlagList;
uint64 SparkGUID;
uint32 Step;
@@ -516,17 +514,8 @@ struct TRINITY_DLL_DECL npc_geezleAI : public ScriptedAI
void DespawnNagaFlag(bool despawn)
{
CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
Trinity::AllGameObjectsWithEntryInGrid go_check(GO_NAGA_FLAG);
Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInGrid> go_search(m_creature, FlagList, go_check);
TypeContainerVisitor
<Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInGrid>, GridTypeMapContainer> go_visit(go_search);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, go_visit, *(m_creature->GetMap()));
std::list<GameObject*> FlagList;
m_creature->GetGameObjectListWithEntryInGrid(FlagList,GO_NAGA_FLAG, 50.0f);
Player* player = NULL;
if (!FlagList.empty())
@@ -342,19 +342,8 @@ struct TRINITY_DLL_DECL boss_shade_of_akamaAI : public ScriptedAI
void FindChannelers()
{
CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<Creature*> ChannelerList;
Trinity::AllCreaturesOfEntryInRange check(m_creature, CREATURE_CHANNELER, 50);
Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(m_creature, ChannelerList, check);
TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> visitor(searcher);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, visitor, *(m_creature->GetMap()));
m_creature->GetCreatureListWithEntryInGrid(ChannelerList,CREATURE_CHANNELER,50.0f);
if(!ChannelerList.empty())
{
@@ -53,21 +53,6 @@ EndScriptData */
#define SPELL_STORM_BUFF 2148
#define SPELL_STORM 26546
class NearbyAQSentinel
{
public:
NearbyAQSentinel(Unit const* obj) : i_obj(obj) {}
bool operator()(Unit* u)
{
if (u->GetEntry() == 15264 && i_obj->IsWithinDistInMap(u, 70) && !u->isDead())
return true;
else
return false;
}
private:
Unit const* i_obj;
};
struct TRINITY_DLL_DECL aqsentinelAI;
class TRINITY_DLL_DECL SentinelAbilityAura : public Aura
{
@@ -166,18 +151,11 @@ struct TRINITY_DLL_DECL aqsentinelAI : public ScriptedAI
void AddSentinelsNear(Unit *nears)
{
CellPair p(Trinity::ComputeCellPair(nears->GetPositionX(), nears->GetPositionY()));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<Creature*> assistList;
m_creature->GetCreatureListWithEntryInGrid(assistList,15264,70.0f);
NearbyAQSentinel u_check(nears);
Trinity::CreatureListSearcher<NearbyAQSentinel> searcher(m_creature, assistList, u_check);
TypeContainerVisitor<Trinity::CreatureListSearcher<NearbyAQSentinel>, GridTypeMapContainer > grid_creature_searcher(searcher);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_creature_searcher, *(nears->GetMap()));
if (assistList.empty())
return;
for(std::list<Creature*>::iterator iter = assistList.begin(); iter != assistList.end(); ++iter)
AddBuddyToList((*iter));
+43 -22
View File
@@ -1135,19 +1135,57 @@ namespace Trinity
Unit const* pUnit;
};
class AllGameObjectsWithEntryInGrid
class AllGameObjectsWithEntryInRange
{
public:
AllGameObjectsWithEntryInGrid(uint32 ent) : entry(ent) {}
bool operator() (GameObject* g)
AllGameObjectsWithEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {}
bool operator() (GameObject* pGo)
{
if(g->GetEntry() == entry)
if (pGo->GetEntry() == m_uiEntry && m_pObject->IsWithinDist(pGo,m_fRange,false))
return true;
return false;
}
private:
uint32 entry;
const WorldObject* m_pObject;
uint32 m_uiEntry;
float m_fRange;
};
class AllCreaturesOfEntryInRange
{
public:
AllCreaturesOfEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {}
bool operator() (Unit* pUnit)
{
if (pUnit->GetEntry() == m_uiEntry && m_pObject->IsWithinDist(pUnit,m_fRange,false))
return true;
return false;
}
private:
const WorldObject* m_pObject;
uint32 m_uiEntry;
float m_fRange;
};
class PlayerAtMinimumRangeAway
{
public:
PlayerAtMinimumRangeAway(Unit const* unit, float fMinRange) : pUnit(unit), fRange(fMinRange) {}
bool operator() (Player* pPlayer)
{
//No threat list check, must be done explicit if expected to be in combat with creature
if (!pPlayer->isGameMaster() && pPlayer->isAlive() && !pUnit->IsWithinDist(pPlayer,fRange,false))
return true;
return false;
}
private:
Unit const* pUnit;
float fRange;
};
class GameObjectInRangeCheck
@@ -1162,23 +1200,6 @@ namespace Trinity
float x, y, z, range;
};
class AllCreaturesOfEntryInRange
{
public:
AllCreaturesOfEntryInRange(Unit const* obj, uint32 ent, float ran) : pUnit(obj), entry(ent), range(ran) {}
bool operator() (Unit* u)
{
if(u->GetEntry() == entry && pUnit->IsWithinDistInMap(u, range))
return true;
return false;
}
private:
Unit const* pUnit;
uint32 entry;
float range;
};
// Player checks and do
// Prepare using Builder localized packets with caching and send to player
+30
View File
@@ -1992,6 +1992,36 @@ GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range)
return go;
}
void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange)
{
CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
Trinity::AllGameObjectsWithEntryInRange check(this, uiEntry, fMaxSearchRange);
Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange> searcher(this, lList, check);
TypeContainerVisitor<Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange>, GridTypeMapContainer> visitor(searcher);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, visitor, *(this->GetMap()));
}
void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange)
{
CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
Trinity::AllCreaturesOfEntryInRange check(this, uiEntry, fMaxSearchRange);
Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(this, lList, check);
TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> visitor(searcher);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, visitor, *(this->GetMap()));
}
/*
namespace MaNGOS
{
+3
View File
@@ -548,6 +548,9 @@ class TRINITY_DLL_SPEC WorldObject : public Object
Creature* FindNearestCreature(uint32 entry, float range, bool alive = true);
GameObject* FindNearestGameObject(uint32 entry, float range);
void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange);
void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange);
bool isActiveObject() const { return m_isActive; }
void setActive(bool isActiveObject);
void SetWorldObject(bool apply);
-4
View File
@@ -23,10 +23,6 @@
#include "Common.h"
#ifndef HAVE_CONFIG_H
#define HAVE_ACE_STACK_TRACE_H 1
#endif
#ifdef HAVE_ACE_STACK_TRACE_H
#include "ace/Stack_Trace.h"
#endif