diff options
| author | megamage <none@none> | 2008-12-26 16:27:41 -0600 |
|---|---|---|
| committer | megamage <none@none> | 2008-12-26 16:27:41 -0600 |
| commit | 7346ed5951822d5b8f61817ff1ad95d2c4e2cd73 (patch) | |
| tree | 3a6c59366f445379b9709df26afd05173eed1531 /src/bindings/scripts/include | |
| parent | 8d79395783e6dfb59777ce5fcedf722a99580765 (diff) | |
| parent | 07e2410ed830a620a0749e4039e0e544278267d7 (diff) | |
*Merge to Trinity 673.
--HG--
branch : trunk
Diffstat (limited to 'src/bindings/scripts/include')
| -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..90a66911ac7 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* FindGameObject(uint32 entry); + //Returns friendly unit with the most amount of hp missing from max hp Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1); |
