diff options
author | Blaymoira <none@none> | 2008-12-26 13:30:46 +0100 |
---|---|---|
committer | Blaymoira <none@none> | 2008-12-26 13:30:46 +0100 |
commit | ec865f7916ab03675f9cc1b1a344a2f706a7a493 (patch) | |
tree | 81b9ad73b1066a0feb69f14198a69f3180487313 /src | |
parent | 3cfb1e0870e6eefd31b0cbb0144de657209b302b (diff) |
*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
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/scripts/include/sc_creature.cpp | 50 | ||||
-rw-r--r-- | src/bindings/scripts/include/sc_creature.h | 6 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index e3bcc2129cc..cd1e5788ebd 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -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); } +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) { diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index c0c09d70e34..b45fc5fda77 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -148,6 +148,12 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI void DoTeleportPlayer(Unit* pUnit, 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 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1); |