From da5c1bca546028d310bbf12340ca721146dc02f0 Mon Sep 17 00:00:00 2001 From: maximius Date: Sun, 22 Nov 2009 00:46:38 -0800 Subject: *Cleanup, fix a few warnings, and make the SD2 grid searchers just pass through to the standard Trinity grid searchers, as they have identical functionality. Thanks thmarth. Closes #387, #388 --HG-- branch : trunk --- src/bindings/scripts/include/sc_creature.cpp | 96 ++++++---------------------- src/bindings/scripts/include/sc_creature.h | 12 ++-- 2 files changed, 25 insertions(+), 83 deletions(-) (limited to 'src/bindings/scripts/include') diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 9f643eae30d..bb4d3e68888 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -637,50 +637,50 @@ void BossAI::TeleportCheaters() float x, y, z; me->GetPosition(x, y, z); std::list &m_threatlist = me->getThreatManager().getThreatList(); - for (std::list::iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr) + for (std::list::iterator itr = m_threatlist.begin(); itr != m_threatlist.end(); ++itr) if((*itr)->getTarget()->GetTypeId() == TYPEID_PLAYER && !CheckBoundary((*itr)->getTarget())) (*itr)->getTarget()->NearTeleportTo(x, y, z, 0); } bool BossAI::CheckBoundary(Unit *who) { - if(!boundary || !who) + if (!boundary || !who) return true; for (BossBoundaryMap::const_iterator itr = boundary->begin(); itr != boundary->end(); ++itr) { - switch(itr->first) + switch (itr->first) { case BOUNDARY_N: - if(me->GetPositionX() > itr->second) + if (me->GetPositionX() > itr->second) return false; break; case BOUNDARY_S: - if(me->GetPositionX() < itr->second) + if (me->GetPositionX() < itr->second) return false; break; case BOUNDARY_E: - if(me->GetPositionY() < itr->second) + if (me->GetPositionY() < itr->second) return false; break; case BOUNDARY_W: - if(me->GetPositionY() > itr->second) + if (me->GetPositionY() > itr->second) return false; break; case BOUNDARY_NW: - if(me->GetPositionX() + me->GetPositionY() > itr->second) + if (me->GetPositionX() + me->GetPositionY() > itr->second) return false; break; case BOUNDARY_SE: - if(me->GetPositionX() + me->GetPositionY() < itr->second) + if (me->GetPositionX() + me->GetPositionY() < itr->second) return false; break; case BOUNDARY_NE: - if(me->GetPositionX() - me->GetPositionY() > itr->second) + if (me->GetPositionX() - me->GetPositionY() > itr->second) return false; break; case BOUNDARY_SW: - if(me->GetPositionX() - me->GetPositionY() < itr->second) + if (me->GetPositionX() - me->GetPositionY() < itr->second) return false; break; } @@ -752,76 +752,20 @@ void LoadOverridenDBCData() } } -//return closest GO in grid, with range from pSource -GameObject* GetClosestGameObjectWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) +// SD2 grid searchers. +Creature *GetClosestCreatureWithEntry(WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange, bool bAlive) { - GameObject* pGo = NULL; - - CellPair pair(MaNGOS::ComputeCellPair(pSource->GetPositionX(), pSource->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - MaNGOS::NearestGameObjectEntryInObjectRangeCheck go_check(*pSource, uiEntry, fMaxSearchRange); - MaNGOS::GameObjectLastSearcher searcher(pSource, pGo, go_check); - - TypeContainerVisitor, GridTypeMapContainer> go_searcher(searcher); - - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, go_searcher, *pSource->GetMap(), *pSource, fMaxSearchRange); - - return pGo; + return pSource->FindNearestCreature(uiEntry, fMaxSearchRange, bAlive); } - -//return closest creature alive in grid, with range from pSource -Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) +GameObject *GetClosestGameObjectWithEntry(WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange) { - Creature* pCreature = NULL; - - CellPair pair(MaNGOS::ComputeCellPair(pSource->GetPositionX(), pSource->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, uiEntry, true, fMaxSearchRange); - MaNGOS::CreatureLastSearcher searcher(pSource, pCreature, creature_check); - - TypeContainerVisitor, GridTypeMapContainer> creature_searcher(searcher); - - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, creature_searcher,*(pSource->GetMap()), *pSource, fMaxSearchRange); - - return pCreature; + return pSource->FindNearestGameObject(uiEntry, fMaxSearchRange); } - -/* -void GetGameObjectListWithEntryInGrid(std::list& lList , WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) +void GetCreatureListWithEntryInGrid(std::list& lList, WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange) { - CellPair pair(MaNGOS::ComputeCellPair(pSource->GetPositionX(), pSource->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - AllGameObjectsWithEntryInRange check(pSource, uiEntry, fMaxSearchRange); - MaNGOS::GameObjectListSearcher searcher(pSource, lList, check); - TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); - - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, visitor, *(pSource->GetMap()), *pSource, fMaxSearchRange); + return pSource->GetCreatureListWithEntryInGrid(lList, uiEntry, fMaxSearchRange); } - -void GetCreatureListWithEntryInGrid(std::list& lList, WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) +void GetGameObjectListWithEntryInGrid(std::list& lList, WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange) { - CellPair pair(MaNGOS::ComputeCellPair(pSource->GetPositionX(), pSource->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - AllCreaturesOfEntryInRange check(pSource, uiEntry, fMaxSearchRange); - MaNGOS::CreatureListSearcher searcher(pSource, lList, check); - TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); - - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, visitor, *(pSource->GetMap()), *pSource, fMaxSearchRange); + return pSource->GetGameObjectListWithEntryInGrid(lList, uiEntry, fMaxSearchRange); } -*/ diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 4b461296775..fdeea02997c 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -221,13 +221,11 @@ struct TRINITY_DLL_DECL BossAI : public ScriptedAI void TeleportCheaters(); }; -// SD2's grid searchers - -//return closest gameobject in grid, with range from pSource -GameObject* GetClosestGameObjectWithEntry(WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange); - -//return closest creature alive in grid, with range from pSource -Creature* GetClosestCreatureWithEntry(WorldObject *pSource, uint32 Entry, float fMaxSearchRange); +// SD2 grid searchers. +Creature *GetClosestCreatureWithEntry(WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange, bool bAlive = true); +GameObject *GetClosestGameObjectWithEntry(WorldObject *pSource, uint32 uiEntry, float fMaxSearchRange); +void GetCreatureListWithEntryInGrid(std::list& lList, WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange); +void GetGameObjectListWithEntryInGrid(std::list& lList, WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange); #endif -- cgit v1.2.3