*Add function FindNearestCreature and FindNearestGameObject to replace old FindCreature and FindGameObject

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-29 16:49:28 -05:00
parent 3faa712d42
commit 89f4c1c444
22 changed files with 69 additions and 94 deletions
@@ -507,28 +507,6 @@ 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* FindCreature(uint32 entry, float range, Unit* Finder)
{
if(!Finder)
return NULL;
Creature* target = NULL;
Trinity::AllCreaturesOfEntryInRange check(Finder, entry, range);
Trinity::CreatureSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(Finder, target, check);
Finder->VisitNearbyObject(range, searcher);
return target;
}
GameObject* FindGameObject(uint32 entry, float range, Unit* Finder)
{
if(!Finder)
return NULL;
GameObject* target = NULL;
Trinity::AllGameObjectsWithEntryInGrid go_check(entry);
Trinity::GameObjectSearcher<Trinity::AllGameObjectsWithEntryInGrid> searcher(Finder, target, go_check);
Finder->VisitNearbyGridObject(range, searcher);
return target;
}
Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff)
{ {
Unit* pUnit = NULL; Unit* pUnit = NULL;
@@ -29,13 +29,6 @@ class SummonList : private std::list<uint64>
Creature *m_creature; Creature *m_creature;
}; };
//Get a single creature of given entry
Unit* FindCreature(uint32 entry, float range, Unit* Finder);
//Get a single gameobject of given entry
GameObject* FindGameObject(uint32 entry, float range, Unit* Finder);
struct PointMovement struct PointMovement
{ {
uint32 m_uiCreatureEntry; uint32 m_uiCreatureEntry;
@@ -183,7 +183,7 @@ struct TRINITY_DLL_DECL npc_ruul_snowhoofAI : public npc_escortAI
{ {
case 0: { case 0: {
m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature); GameObject* Cage = m_creature->FindNearestGameObject(GO_CAGE, 20);
if(Cage) if(Cage)
Cage->SetGoState(GO_STATE_ACTIVE); Cage->SetGoState(GO_STATE_ACTIVE);
break;} break;}
@@ -213,7 +213,7 @@ struct TRINITY_DLL_DECL npc_ruul_snowhoofAI : public npc_escortAI
if (!IsBeingEscorted) if (!IsBeingEscorted)
m_creature->setFaction(1602); m_creature->setFaction(1602);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature); GameObject* Cage = m_creature->FindNearestGameObject(GO_CAGE, 20);
if(Cage) if(Cage)
Cage->SetGoState(GO_STATE_READY); Cage->SetGoState(GO_STATE_READY);
} }
@@ -240,7 +240,7 @@ struct TRINITY_DLL_DECL mob_ethereal_beaconAI : public ScriptedAI
{ {
DoCast(m_creature->getVictim(),SPELL_ARCANE_BOLT); DoCast(m_creature->getVictim(),SPELL_ARCANE_BOLT);
ArcaneBolt_Timer = 2000 + rand()%2500; ArcaneBolt_Timer = 2000 + rand()%2500;
Unit *shaffar = FindCreature(ENTRY_SHAFFAR, 100, m_creature); Unit *shaffar = m_creature->FindNearestCreature(ENTRY_SHAFFAR, 100);
if(!shaffar || shaffar->isDead()) if(!shaffar || shaffar->isDead())
{ {
m_creature->SetVisibility(VISIBILITY_OFF); m_creature->SetVisibility(VISIBILITY_OFF);
@@ -121,7 +121,7 @@ struct TRINITY_DLL_DECL boss_elder_nadoxAI : public ScriptedAI
if(HeroicMode) if(HeroicMode)
if(rage_Timer < diff) if(rage_Timer < diff)
{ {
Unit* Swarmer = FindCreature(MOB_AHNKAHAR_SWARMER,35,m_creature); Unit* Swarmer = m_creature->FindNearestCreature(MOB_AHNKAHAR_SWARMER, 35);
if(Swarmer) if(Swarmer)
{ {
@@ -443,7 +443,7 @@ struct TRINITY_DLL_DECL npc_wizzlecrank_shredderAI : public npc_escortAI
case 10: DoScriptText(SAY_PROGRESS_3, m_creature, player); case 10: DoScriptText(SAY_PROGRESS_3, m_creature, player);
m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); break; m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); break;
case 20:{ case 20:{
Unit* Mercenary = FindCreature(MOB_MERCENARY, 99, m_creature); Unit* Mercenary = m_creature->FindNearestCreature(MOB_MERCENARY, 99);
if(Mercenary) if(Mercenary)
{ {
DoScriptText(SAY_MERCENARY_4, Mercenary); DoScriptText(SAY_MERCENARY_4, Mercenary);
@@ -266,7 +266,7 @@ void npc_unworthy_initiateAI::UpdateAI(const uint32 diff)
for(int i = 0; i < 12; i++) for(int i = 0; i < 12; i++)
{ {
GameObject* temp_prison; GameObject* temp_prison;
temp_prison = FindGameObject(acherus_soul_prison[i],30,m_creature); temp_prison = me->FindNearestGameObject(acherus_soul_prison[i],30);
if(!temp_prison) return; if(!temp_prison) return;
if(dist == 99 || dist > m_creature->GetDistance2d(temp_prison)) if(dist == 99 || dist > m_creature->GetDistance2d(temp_prison))
{ {
@@ -363,7 +363,7 @@ bool GOHello_go_acherus_soul_prison(Player *player, GameObject* _GO)
Creature* finder = player->SummonCreature(WORLD_TRIGGER,_GO->GetPositionX(),_GO->GetPositionY(),_GO->GetPositionZ(),0,TEMPSUMMON_TIMED_DESPAWN,2000); Creature* finder = player->SummonCreature(WORLD_TRIGGER,_GO->GetPositionX(),_GO->GetPositionY(),_GO->GetPositionZ(),0,TEMPSUMMON_TIMED_DESPAWN,2000);
if(!finder) return false; if(!finder) return false;
Unit* prison_anchor = FindCreature(29521,5,finder); Unit* prison_anchor = finder->FindNearestCreature(29521, 15);
if(!prison_anchor) return false; if(!prison_anchor) return false;
uint64 owner = ((npc_unworthy_initiate_anchorAI*)((Creature*)prison_anchor)->AI())->GetTarget(); uint64 owner = ((npc_unworthy_initiate_anchorAI*)((Creature*)prison_anchor)->AI())->GetTarget();
@@ -169,7 +169,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
case 0: case 0:
{ {
m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature); GameObject* Cage = me->FindNearestGameObject(GO_CAGE, 20);
if(Cage) if(Cage)
Cage->SetGoState(GO_STATE_ACTIVE); Cage->SetGoState(GO_STATE_ACTIVE);
DoScriptText(SAY_START, m_creature, player); DoScriptText(SAY_START, m_creature, player);
@@ -207,7 +207,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
case 33: case 33:
m_creature->SetOrientation(5.858011); m_creature->SetOrientation(5.858011);
DoScriptText(SAY_END2, m_creature, player); DoScriptText(SAY_END2, m_creature, player);
Unit* CaptainHelios = FindCreature(NPC_CAPTAIN_HELIOS, 50, m_creature); Unit* CaptainHelios = me->FindNearestCreature(NPC_CAPTAIN_HELIOS, 50);
if(CaptainHelios) if(CaptainHelios)
DoScriptText(SAY_CAPTAIN_ANSWER, CaptainHelios, player); DoScriptText(SAY_CAPTAIN_ANSWER, CaptainHelios, player);
break; break;
@@ -221,7 +221,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
if (!IsBeingEscorted) if (!IsBeingEscorted)
m_creature->setFaction(1602); m_creature->setFaction(1602);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature); GameObject* Cage = me->FindNearestGameObject(GO_CAGE, 20);
if(Cage) if(Cage)
Cage->SetGoState(GO_STATE_READY); Cage->SetGoState(GO_STATE_READY);
} }
@@ -291,7 +291,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
void EnterCombat(Unit* who) void EnterCombat(Unit* who)
{ {
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature)) if(Creature *Kelidan = me->FindNearestCreature(ENTRY_KELIDAN, 100))
((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerEngaged(who); ((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerEngaged(who);
if (m_creature->IsNonMeleeSpellCasted(false)) if (m_creature->IsNonMeleeSpellCasted(false))
m_creature->InterruptNonMeleeSpells(true); m_creature->InterruptNonMeleeSpells(true);
@@ -300,7 +300,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
void JustDied(Unit* Killer) void JustDied(Unit* Killer)
{ {
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature)) if(Creature *Kelidan = me->FindNearestCreature(ENTRY_KELIDAN, 100))
((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerDied(Killer); ((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerDied(Killer);
} }
@@ -311,7 +311,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
if(check_Timer < diff) if(check_Timer < diff)
{ {
if (!m_creature->IsNonMeleeSpellCasted(false)) if (!m_creature->IsNonMeleeSpellCasted(false))
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature)) if(Creature *Kelidan = me->FindNearestCreature(ENTRY_KELIDAN, 100))
{ {
uint64 channeler = ((boss_kelidan_the_breakerAI*)Kelidan->AI())->GetChanneled(m_creature); uint64 channeler = ((boss_kelidan_the_breakerAI*)Kelidan->AI())->GetChanneled(m_creature);
if(Unit *channeled = Unit::GetUnit(*m_creature, channeler)) if(Unit *channeled = Unit::GetUnit(*m_creature, channeler))
@@ -281,7 +281,7 @@ struct TRINITY_DLL_DECL boss_vazruden_the_heraldAI : public ScriptedAI
{ {
Creature *Nazan = Unit::GetCreature(*m_creature, NazanGUID); Creature *Nazan = Unit::GetCreature(*m_creature, NazanGUID);
Creature *Vazruden = Unit::GetCreature(*m_creature, VazrudenGUID); Creature *Vazruden = Unit::GetCreature(*m_creature, VazrudenGUID);
if(Nazan || (Nazan = (Creature *)FindCreature(ENTRY_NAZAN, 5000, m_creature))) if(Nazan || (Nazan = me->FindNearestCreature(ENTRY_NAZAN, 5000)))
{ {
Nazan->SetLootRecipient(NULL); Nazan->SetLootRecipient(NULL);
Nazan->SetVisibility(VISIBILITY_OFF); Nazan->SetVisibility(VISIBILITY_OFF);
@@ -289,7 +289,7 @@ struct TRINITY_DLL_DECL boss_vazruden_the_heraldAI : public ScriptedAI
Nazan->RemoveCorpse(); Nazan->RemoveCorpse();
NazanGUID = 0; NazanGUID = 0;
} }
if(Vazruden || (Vazruden = (Creature *)FindCreature(ENTRY_VAZRUDEN, 5000, m_creature))) if(Vazruden || (Vazruden = me->FindNearestCreature(ENTRY_VAZRUDEN, 5000)))
{ {
Vazruden->SetLootRecipient(NULL); Vazruden->SetLootRecipient(NULL);
Vazruden->SetVisibility(VISIBILITY_OFF); Vazruden->SetVisibility(VISIBILITY_OFF);
@@ -423,7 +423,7 @@ struct TRINITY_DLL_DECL mob_hellfire_sentryAI : public ScriptedAI
void JustDied(Unit* who) void JustDied(Unit* who)
{ {
if(Creature *herald = (Creature *)FindCreature(ENTRY_VAZRUDEN_HERALD,150, m_creature)) if(Creature *herald = me->FindNearestCreature(ENTRY_VAZRUDEN_HERALD,150))
((boss_vazruden_the_heraldAI *)herald->AI())->SentryDownBy(who); ((boss_vazruden_the_heraldAI *)herald->AI())->SentryDownBy(who);
} }
@@ -115,7 +115,7 @@ struct TRINITY_DLL_DECL npc_greengill_slaveAI : public ScriptedAI
((Player*)plr)->KilledMonster(25086, m_creature->GetGUID()); ((Player*)plr)->KilledMonster(25086, m_creature->GetGUID());
} }
DoCast(m_creature, ENRAGE); DoCast(m_creature, ENRAGE);
Unit* Myrmidon = FindCreature(DM, 70, m_creature); Unit* Myrmidon = me->FindNearestCreature(DM, 70);
if(Myrmidon) if(Myrmidon)
{ {
m_creature->AddThreat(Myrmidon, 100000.0f); m_creature->AddThreat(Myrmidon, 100000.0f);
@@ -881,11 +881,11 @@ struct TRINITY_DLL_DECL npc_bessyAI : public npc_escortAI
((Player*)player)->GroupEventHappens(Q_ALMABTRIEB, m_creature); ((Player*)player)->GroupEventHappens(Q_ALMABTRIEB, m_creature);
Completed = true; Completed = true;
} }
{Unit* Thadell = FindCreature(N_THADELL, 30, m_creature); {Unit* Thadell = me->FindNearestCreature(N_THADELL, 30);
if(Thadell) if(Thadell)
DoScriptText(SAY_THADELL_1, m_creature);}break; DoScriptText(SAY_THADELL_1, m_creature);}break;
case 13: case 13:
{Unit* Thadell = FindCreature(N_THADELL, 30, m_creature); {Unit* Thadell = me->FindNearestCreature(N_THADELL, 30);
if(Thadell) if(Thadell)
DoScriptText(SAY_THADELL_2, m_creature, player);}break; DoScriptText(SAY_THADELL_2, m_creature, player);}break;
} }
@@ -215,7 +215,7 @@ struct TRINITY_DLL_DECL mob_enslaved_netherwing_drakeAI : public ScriptedAI
m_creature->setFaction(FACTION_FRIENDLY); m_creature->setFaction(FACTION_FRIENDLY);
DoCast(caster, SPELL_FORCE_OF_NELTHARAKU, true); DoCast(caster, SPELL_FORCE_OF_NELTHARAKU, true);
Unit* Dragonmaw = FindCreature(CREATURE_DRAGONMAW_SUBJUGATOR, 50, m_creature); Unit* Dragonmaw = me->FindNearestCreature(CREATURE_DRAGONMAW_SUBJUGATOR, 50);
if(Dragonmaw) if(Dragonmaw)
{ {
@@ -275,7 +275,7 @@ struct TRINITY_DLL_DECL mob_enslaved_netherwing_drakeAI : public ScriptedAI
float dx, dy, dz; float dx, dy, dz;
Unit* EscapeDummy = FindCreature(CREATURE_ESCAPE_DUMMY, 30, m_creature); Unit* EscapeDummy = me->FindNearestCreature(CREATURE_ESCAPE_DUMMY, 30);
if(EscapeDummy) if(EscapeDummy)
EscapeDummy->GetPosition(dx, dy, dz); EscapeDummy->GetPosition(dx, dy, dz);
else else
@@ -773,7 +773,7 @@ struct TRINITY_DLL_DECL npc_overlord_morghorAI : public ScriptedAI
return 6000; break; return 6000; break;
case 27: case 27:
{ {
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature); Unit* Yarzill = me->FindNearestCreature(C_YARZILL, 50);
if (Yarzill) if (Yarzill)
Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, PlayerGUID); Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, PlayerGUID);
return 500; }break; return 500; }break;
@@ -785,19 +785,19 @@ struct TRINITY_DLL_DECL npc_overlord_morghorAI : public ScriptedAI
return 1000; break; return 1000; break;
case 29: case 29:
{ {
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature); Unit* Yarzill = me->FindNearestCreature(C_YARZILL, 50);
if(Yarzill) if(Yarzill)
DoScriptText(YARZILL_THE_MERC_SAY, Yarzill, plr); DoScriptText(YARZILL_THE_MERC_SAY, Yarzill, plr);
return 5000; }break; return 5000; }break;
case 30: case 30:
{ {
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature); Unit* Yarzill = me->FindNearestCreature(C_YARZILL, 50);
if (Yarzill) if (Yarzill)
Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, 0); Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, 0);
return 5000; }break; return 5000; }break;
case 31: case 31:
{ {
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature); Unit* Yarzill = me->FindNearestCreature(C_YARZILL, 50);
if (Yarzill) if (Yarzill)
Yarzill->CastSpell(plr, 41540, true); Yarzill->CastSpell(plr, 41540, true);
return 1000;}break; return 1000;}break;
@@ -1616,7 +1616,7 @@ bool GOQuestAccept_GO_crystal_prison(Player* plr, GameObject* go, Quest const* q
{ {
if(quest->GetQuestId() == QUEST_BATTLE_OF_THE_CRIMSON_WATCH ) if(quest->GetQuestId() == QUEST_BATTLE_OF_THE_CRIMSON_WATCH )
{ {
Unit* Illidan = FindCreature(22083, 50, plr); Unit* Illidan = plr->FindNearestCreature(22083, 50);
if(Illidan && !(((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->EventStarted)) if(Illidan && !(((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->EventStarted))
{ {
@@ -1736,7 +1736,7 @@ struct TRINITY_DLL_DECL npc_enraged_spiritAI : public ScriptedAI
// FIND TOTEM, PROCESS QUEST // FIND TOTEM, PROCESS QUEST
if (Summoned) if (Summoned)
{ {
totemOspirits = FindCreature(ENTRY_TOTEM_OF_SPIRITS, RADIUS_TOTEM_OF_SPIRITS, m_creature); totemOspirits = me->FindNearestCreature(ENTRY_TOTEM_OF_SPIRITS, RADIUS_TOTEM_OF_SPIRITS);
if (totemOspirits) if (totemOspirits)
{ {
Summoned->setFaction(ENRAGED_SOUL_FRIENDLY); Summoned->setFaction(ENRAGED_SOUL_FRIENDLY);
@@ -397,14 +397,14 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
m_creature->setFaction(1194); m_creature->setFaction(1194);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature); Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20);
if(Creepjack) if(Creepjack)
{ {
((Creature*)Creepjack)->AI()->EnterEvadeMode(); ((Creature*)Creepjack)->AI()->EnterEvadeMode();
Creepjack->setFaction(1194); Creepjack->setFaction(1194);
Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
} }
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature); Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20);
if(Malone) if(Malone)
{ {
((Creature*)Malone)->AI()->EnterEvadeMode(); ((Creature*)Malone)->AI()->EnterEvadeMode();
@@ -420,10 +420,10 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
switch(Step) switch(Step)
{ {
case 0:{ m_creature->SetInFront(player); case 0:{ m_creature->SetInFront(player);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature); Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20);
if(Creepjack) if(Creepjack)
Creepjack->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); Creepjack->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature); Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20);
if(Malone) if(Malone)
Malone->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); Malone->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
m_creature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); }return 2000; m_creature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); }return 2000;
@@ -454,7 +454,7 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
if(player) if(player)
{ {
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature); Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20);
if(Creepjack) if(Creepjack)
{ {
Creepjack->Attack(player, true); Creepjack->Attack(player, true);
@@ -462,7 +462,7 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
Creepjack->GetMotionMaster()->MoveChase(player); Creepjack->GetMotionMaster()->MoveChase(player);
Creepjack->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); Creepjack->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
} }
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature); Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20);
if(Malone) if(Malone)
{ {
Malone->Attack(player, true); Malone->Attack(player, true);
@@ -478,7 +478,7 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
if((m_creature->GetHealth()*100)/m_creature->GetMaxHealth() < 1 && !Done) if((m_creature->GetHealth()*100)/m_creature->GetMaxHealth() < 1 && !Done)
{ {
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature); Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20);
if(Creepjack) if(Creepjack)
{ {
((Creature*)Creepjack)->AI()->EnterEvadeMode(); ((Creature*)Creepjack)->AI()->EnterEvadeMode();
@@ -486,7 +486,7 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
Creepjack->GetMotionMaster()->MoveTargetedHome(); Creepjack->GetMotionMaster()->MoveTargetedHome();
Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
} }
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature); Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20);
if(Malone) if(Malone)
{ {
((Creature*)Malone)->AI()->EnterEvadeMode(); ((Creature*)Malone)->AI()->EnterEvadeMode();
@@ -132,7 +132,7 @@ struct TRINITY_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
player->GroupEventHappens(QUEST_ESCORTING, m_creature);break; player->GroupEventHappens(QUEST_ESCORTING, m_creature);break;
case 14: DoScriptText(SAY_THANKS, m_creature, player);break; case 14: DoScriptText(SAY_THANKS, m_creature, player);break;
case 15: { case 15: {
Unit* Rane = FindCreature(NPC_RANE, 20, m_creature); Unit* Rane = me->FindNearestCreature(NPC_RANE, 20);
if(Rane) if(Rane)
DoScriptText(SAY_RANE, Rane); DoScriptText(SAY_RANE, Rane);
break;} break;}
@@ -140,7 +140,7 @@ struct TRINITY_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
case 17: DoScriptText(SAY_MOVE_QUINN, m_creature); break; case 17: DoScriptText(SAY_MOVE_QUINN, m_creature); break;
case 24: DoScriptText(SAY_GREETINGS, m_creature);break; case 24: DoScriptText(SAY_GREETINGS, m_creature);break;
case 25: { case 25: {
Unit* Quinn = FindCreature(NPC_QUINN, 20, m_creature); Unit* Quinn = me->FindNearestCreature(NPC_QUINN, 20);
if(Quinn) if(Quinn)
DoScriptText(SAY_QUINN, Quinn); DoScriptText(SAY_QUINN, Quinn);
break;} break;}
@@ -378,9 +378,8 @@ struct TRINITY_DLL_DECL npc_OOX17AI : public npc_escortAI
m_creature->SummonCreature(SPAWN_SECOND_2, -7515.07, -4797.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); m_creature->SummonCreature(SPAWN_SECOND_2, -7515.07, -4797.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000);
m_creature->SummonCreature(SPAWN_SECOND_2, -7518.07, -4792.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); m_creature->SummonCreature(SPAWN_SECOND_2, -7518.07, -4792.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000);
DoScriptText(SAY_CHICKEN_AMB, m_creature); DoScriptText(SAY_CHICKEN_AMB, m_creature);
{Unit* scoff = FindCreature(SPAWN_SECOND_2, 30, m_creature); if(Unit* scoff = me->FindNearestCreature(SPAWN_SECOND_2, 30))
if(scoff) DoScriptText(SAY_SCOFF, scoff);
DoScriptText(SAY_SCOFF, scoff);}break;
break; break;
case 86: case 86:
@@ -358,7 +358,7 @@ struct TRINITY_DLL_DECL npc_isla_starmaneAI : public npc_escortAI
{ {
case 0: case 0:
{ {
GameObject* Cage = FindGameObject(GO_CAGE, 10, m_creature); GameObject* Cage = me->FindNearestGameObject(GO_CAGE, 10);
if(Cage) if(Cage)
Cage->SetGoState(GO_STATE_ACTIVE); Cage->SetGoState(GO_STATE_ACTIVE);
}break; }break;
@@ -399,7 +399,7 @@ struct TRINITY_DLL_DECL mob_ingvar_throw_dummyAI : public ScriptedAI
void Reset() void Reset()
{ {
Unit* target = FindCreature(ENTRY_THROW_TARGET,50,m_creature); Unit* target = m_creature->FindNearestCreature(ENTRY_THROW_TARGET,50);
if(target) if(target)
{ {
DoCast(m_creature, HeroicMode ? H_SPELL_SHADOW_AXE_DAMAGE : SPELL_SHADOW_AXE_DAMAGE); DoCast(m_creature, HeroicMode ? H_SPELL_SHADOW_AXE_DAMAGE : SPELL_SHADOW_AXE_DAMAGE);
@@ -111,7 +111,7 @@ struct TRINITY_DLL_DECL npc_dragonflayer_forge_masterAI : public ScriptedAI
for(int i = 0; i < 3 ; i++) for(int i = 0; i < 3 ; i++)
{ {
GameObject* temp; GameObject* temp;
temp = FindGameObject(entry_search[i],30,m_creature); temp = m_creature->FindNearestGameObject(entry_search[i],30);
if(temp) if(temp)
{ {
if(diff > m_creature->GetDistance2d(temp)) if(diff > m_creature->GetDistance2d(temp))
+18
View File
@@ -2041,6 +2041,24 @@ Creature* WorldObject::SummonTrigger(float x, float y, float z, float ang, uint3
return summon; return summon;
} }
Creature* WorldObject::FindNearestCreature(uint32 entry, float range, bool alive)
{
Creature *creature = NULL;
Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck checker(*this, entry, alive, range);
Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(this, creature, checker);
VisitNearbyObject(range, searcher);
return creature;
}
GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range)
{
GameObject *go = NULL;
Trinity::NearestGameObjectEntryInObjectRangeCheck checker(*this, entry, range);
Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectEntryInObjectRangeCheck> searcher(this, go, checker);
VisitNearbyGridObject(range, searcher);
return go;
}
/* /*
namespace MaNGOS namespace MaNGOS
{ {
+5
View File
@@ -537,10 +537,15 @@ class TRINITY_DLL_SPEC WorldObject : public Object
Map * GetMap() const { return m_map ? m_map : const_cast<WorldObject*>(this)->_getMap(); } Map * GetMap() const { return m_map ? m_map : const_cast<WorldObject*>(this)->_getMap(); }
Map * FindMap() const { return m_map ? m_map : const_cast<WorldObject*>(this)->_findMap(); } Map * FindMap() const { return m_map ? m_map : const_cast<WorldObject*>(this)->_findMap(); }
Map const* GetBaseMap() const; Map const* GetBaseMap() const;
TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0,TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN,uint32 despwtime = 0); TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0,TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN,uint32 despwtime = 0);
Vehicle* SummonVehicle(uint32 entry, float x, float y, float z, float ang = 0); Vehicle* SummonVehicle(uint32 entry, float x, float y, float z, float ang = 0);
GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime); GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime);
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL); Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
Creature* FindNearestCreature(uint32 entry, float range, bool alive = true);
GameObject* FindNearestGameObject(uint32 entry, float range);
bool isActiveObject() const { return m_isActive; } bool isActiveObject() const { return m_isActive; }
void setActive(bool isActiveObject); void setActive(bool isActiveObject);
void SetWorldObject(bool apply); void SetWorldObject(bool apply);
+4 -22
View File
@@ -1642,21 +1642,13 @@ WorldObject* Spell::SearchNearbyTarget(float range, SpellTargets TargetType)
switch(i_spellST->second.type) switch(i_spellST->second.type)
{ {
case SPELL_TARGET_TYPE_GAMEOBJECT: case SPELL_TARGET_TYPE_GAMEOBJECT:
{
GameObject* p_GameObject = NULL;
if(i_spellST->second.targetEntry) if(i_spellST->second.targetEntry)
{ {
Trinity::NearestGameObjectEntryInObjectRangeCheck go_check(*m_caster,i_spellST->second.targetEntry,range); if(goScriptTarget = m_caster->FindNearestGameObject(i_spellST->second.targetEntry, range))
Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectEntryInObjectRangeCheck> checker(m_caster,p_GameObject,go_check);
m_caster->VisitNearbyGridObject(range, checker);
if(p_GameObject)
{ {
// remember found target and range, next attempt will find more near target with another entry // remember found target and range, next attempt will find more near target with another entry
creatureScriptTarget = NULL; creatureScriptTarget = NULL;
goScriptTarget = p_GameObject; range = m_caster->GetDistance(goScriptTarget);
range = go_check.GetLastRange();
} }
} }
else if( focusObject ) //Focus Object else if( focusObject ) //Focus Object
@@ -1670,27 +1662,17 @@ WorldObject* Spell::SearchNearbyTarget(float range, SpellTargets TargetType)
} }
} }
break; break;
}
case SPELL_TARGET_TYPE_CREATURE: case SPELL_TARGET_TYPE_CREATURE:
if(m_targets.getUnitTarget() && m_targets.getUnitTarget()->GetEntry() == i_spellST->second.targetEntry) if(m_targets.getUnitTarget() && m_targets.getUnitTarget()->GetEntry() == i_spellST->second.targetEntry)
return m_targets.getUnitTarget(); return m_targets.getUnitTarget();
case SPELL_TARGET_TYPE_DEAD: case SPELL_TARGET_TYPE_DEAD:
default: default:
{ if(creatureScriptTarget = m_caster->FindNearestCreature(i_spellST->second.targetEntry, range, i_spellST->second.type != SPELL_TARGET_TYPE_DEAD))
Creature *p_Creature = NULL;
Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*m_caster,i_spellST->second.targetEntry,i_spellST->second.type!=SPELL_TARGET_TYPE_DEAD,range);
Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(m_caster,p_Creature, u_check);
m_caster->VisitNearbyObject(range, searcher);
if(p_Creature )
{ {
creatureScriptTarget = p_Creature;
goScriptTarget = NULL; goScriptTarget = NULL;
range = u_check.GetLastRange(); range = m_caster->GetDistance(creatureScriptTarget);
} }
break; break;
}
} }
} }