*Implemented new function for Creature and Gameobject searching with gridsearchers - patch provided by Lightguard

*Names:
*Unit* FindCreature(uint32 entry, uint32 range);
*GameObject* ScriptedAI::FindGameObject(uint32 entry);

--HG--
branch : trunk
This commit is contained in:
Blaymoira
2008-12-26 13:30:46 +01:00
parent 3cfb1e0870
commit ec865f7916
2 changed files with 56 additions and 0 deletions
@@ -735,6 +735,56 @@ void ScriptedAI::DoTeleportAll(float x, float y, float z, float o)
i_pl->TeleportTo(m_creature->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT); i_pl->TeleportTo(m_creature->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
} }
Unit* ScriptedAI::FindCreature(uint32 entry, uint32 range)
{
CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<Creature*> NPCList;
Trinity::AllCreaturesOfEntryInRange check(m_creature, entry, range);
Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(NPCList, check);
TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> visitor(searcher);
CellLock<GridReadGuard> cell_lock(cell, pair);
cell_lock->Visit(cell_lock, visitor, *(m_creature->GetMap()));
if (!NPCList.empty())
{
for(std::list<Creature*>::iterator itr = NPCList.begin(); itr != NPCList.end(); ++itr)
{
return Creature::GetUnit((*m_creature), (*itr)->GetGUID());
}
}else error_log("SD2 ERROR: Entry: %u not found!", entry); return NULL;
}
GameObject* ScriptedAI::FindGameObject(uint32 entry)
{
CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(pair);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<GameObject*> GOList;
Trinity::AllGameObjectsWithEntryInGrid go_check(entry);
Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInGrid> go_search(GOList, 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()));
if (!GOList.empty())
{
for(std::list<GameObject*>::iterator itr = GOList.begin(); itr != GOList.end(); ++itr)
{
return (*itr);
}
}
else error_log("SD2 ERROR: GameObject Entry: %u not found!", entry); return NULL;
}
Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff)
{ {
@@ -148,6 +148,12 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o); void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o);
void DoTeleportAll(float x, float y, float z, float o); void DoTeleportAll(float x, float y, float z, float o);
//Get a single creature of given entry
Unit* FindCreature(uint32 entry, uint32 range);
//Get a single gameobject of given entry
GameObject* ScriptedAI::FindGameObject(uint32 entry);
//Returns friendly unit with the most amount of hp missing from max hp //Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1); Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1);