aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bindings/scripts/include/sc_creature.cpp57
-rw-r--r--src/bindings/scripts/include/sc_creature.h4
-rw-r--r--src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp4
3 files changed, 17 insertions, 48 deletions
diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp
index fad8c631e5e..d46d5b68716 100644
--- a/src/bindings/scripts/include/sc_creature.cpp
+++ b/src/bindings/scripts/include/sc_creature.cpp
@@ -740,55 +740,24 @@ 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, uint32 district)
+Unit* ScriptedAI::FindCreature(uint32 entry, float range)
{
- CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
- Cell cell(pair);
- cell.data.Part.reserved = district;
- cell.SetNoCreate();
-
- std::list<Creature*> NPCList;
-
+ Creature* target = NULL;
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;
+ Trinity::CreatureSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(target, check);
+ m_creature->VisitNearbyGridObject(range, searcher);
+ if(!target) error_log("SD2 ERROR: Entry: %u not found!", entry);
+ return target;
}
-GameObject* ScriptedAI::FindGameObject(uint32 entry, uint32 district)
+GameObject* ScriptedAI::FindGameObject(uint32 entry, float range)
{
- CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
- Cell cell(pair);
- cell.data.Part.reserved = 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;
+ GameObject* target = NULL;
+ Trinity::AllGameObjectsWithEntryInGrid go_check(entry);
+ Trinity::GameObjectSearcher<Trinity::AllGameObjectsWithEntryInGrid> searcher(target, go_check);
+ m_creature->VisitNearbyGridObject(range, searcher);
+ if(!target) error_log("SD2 ERROR: Entry: %u not found!", entry);
+ return target;
}
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 3ece26bdb6f..9c7ffc022eb 100644
--- a/src/bindings/scripts/include/sc_creature.h
+++ b/src/bindings/scripts/include/sc_creature.h
@@ -149,10 +149,10 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
void DoTeleportAll(float x, float y, float z, float o);
//Get a single creature of given entry
- Unit* FindCreature(uint32 entry, uint32 range, uint32 district = ALL_DISTRICT);
+ Unit* FindCreature(uint32 entry, float range);
//Get a single gameobject of given entry
- GameObject* FindGameObject(uint32 entry, uint32 district = ALL_DISTRICT);
+ GameObject* FindGameObject(uint32 entry, float range);
//Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1);
diff --git a/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp b/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp
index b38e21687da..6350040cfe4 100644
--- a/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp
+++ b/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp
@@ -161,7 +161,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
case 0:
{
m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
- GameObject* Cage = FindGameObject(GO_CAGE);
+ GameObject* Cage = FindGameObject(GO_CAGE, 99);
if(Cage)
Cage->SetGoState(0);
DoScriptText(SAY_START, m_creature, player);
@@ -212,7 +212,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
if (!IsBeingEscorted)
m_creature->setFaction(1602);
- GameObject* Cage = FindGameObject(GO_CAGE);
+ GameObject* Cage = FindGameObject(GO_CAGE, 99);
if(Cage)
Cage->SetGoState(1);
}