Skip to content

Commit 6436450

Browse files
author
NoFantasy
committed
[1329] Remove use of old uint64 variable for player guid in escortAI and use function to retrieve pointer to player instead.
Remove use of old uint64 variable for player guid in escortAI and use function to retrieve pointer to player instead. git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@1329 5f9c896b-1e26-0410-94da-f77f675e2462
1 parent 35bc898 commit 6436450

25 files changed

Lines changed: 161 additions & 219 deletions

base/escort_ai.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ enum
2424
npc_escortAI::npc_escortAI(Creature* pCreature) : ScriptedAI(pCreature),
2525
IsBeingEscorted(false),
2626
IsOnHold(false),
27-
PlayerGUID(0),
2827
m_uiPlayerGUID(0),
2928
m_uiPlayerCheckTimer(1000),
3029
m_uiWPWaitTimer(2500),
@@ -105,10 +104,10 @@ void npc_escortAI::MoveInLineOfSight(Unit* pWho)
105104

106105
void npc_escortAI::JustDied(Unit* pKiller)
107106
{
108-
if (!IsBeingEscorted || !PlayerGUID || !m_pQuestForEscort)
107+
if (!IsBeingEscorted || !m_uiPlayerGUID || !m_pQuestForEscort)
109108
return;
110109

111-
if (Player* pPlayer = (Player*)Unit::GetUnit(*m_creature, PlayerGUID))
110+
if (Player* pPlayer = GetPlayerForEscort())
112111
{
113112
if (Group* pGroup = pPlayer->GetGroup())
114113
{
@@ -177,7 +176,7 @@ void npc_escortAI::EnterEvadeMode()
177176

178177
bool npc_escortAI::IsPlayerOrGroupInRange()
179178
{
180-
if (Player* pPlayer = (Player*)Unit::GetUnit(*m_creature, PlayerGUID))
179+
if (Player* pPlayer = GetPlayerForEscort())
181180
{
182181
if (Group* pGroup = pPlayer->GetGroup())
183182
{
@@ -252,7 +251,7 @@ void npc_escortAI::UpdateAI(const uint32 uiDiff)
252251
}
253252

254253
//Check if player or any member of his group is within range
255-
if (IsBeingEscorted && PlayerGUID && !m_creature->getVictim() && !m_bIsReturning)
254+
if (IsBeingEscorted && m_uiPlayerGUID && !m_creature->getVictim() && !m_bIsReturning)
256255
{
257256
if (m_uiPlayerCheckTimer < uiDiff)
258257
{
@@ -408,8 +407,6 @@ void npc_escortAI::Start(bool bIsActiveAttacker, bool bRun, uint64 uiPlayerGUID,
408407
m_bIsActiveAttacker = bIsActiveAttacker;
409408
m_bIsRunning = bRun;
410409

411-
PlayerGUID = uiPlayerGUID;
412-
413410
m_uiPlayerGUID = uiPlayerGUID;
414411
m_pQuestForEscort = pQuest;
415412

@@ -429,7 +426,7 @@ void npc_escortAI::Start(bool bIsActiveAttacker, bool bRun, uint64 uiPlayerGUID,
429426
//disable npcflags
430427
m_creature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
431428

432-
debug_log("SD2: EscortAI started with %d waypoints. ActiveAttacker = %d, Run = %d, PlayerGUID = %d", WaypointList.size(), m_bIsActiveAttacker, m_bIsRunning, PlayerGUID);
429+
debug_log("SD2: EscortAI started with %d waypoints. ActiveAttacker = %d, Run = %d, PlayerGUID = %d", WaypointList.size(), m_bIsActiveAttacker, m_bIsRunning, m_uiPlayerGUID);
433430

434431
CurrentWP = WaypointList.begin();
435432

base/escort_ai.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct MANGOS_DLL_DECL npc_escortAI : public ScriptedAI
7575

7676
// EscortAI variables
7777
protected:
78-
uint64 PlayerGUID;
7978
bool IsBeingEscorted;
8079
bool IsOnHold;
8180

scripts/eastern_kingdoms/arathi_highlands.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,30 @@ struct MANGOS_DLL_DECL npc_professor_phizzlethorpeAI : public npc_escortAI
5858

5959
void WaypointReached(uint32 uiPointId)
6060
{
61-
Unit* pUnit = Unit::GetUnit((*m_creature), PlayerGUID);
61+
Player* pPlayer = GetPlayerForEscort();
6262

63-
if (!pUnit || pUnit->GetTypeId() != TYPEID_PLAYER)
63+
if (!pPlayer)
6464
return;
6565

6666
switch(uiPointId)
6767
{
68-
case 4: DoScriptText(SAY_PROGRESS_2, m_creature, pUnit); break;
69-
case 5: DoScriptText(SAY_PROGRESS_3, m_creature, pUnit); break;
68+
case 4: DoScriptText(SAY_PROGRESS_2, m_creature, pPlayer); break;
69+
case 5: DoScriptText(SAY_PROGRESS_3, m_creature, pPlayer); break;
7070
case 8: DoScriptText(EMOTE_PROGRESS_4, m_creature); break;
7171
case 9:
7272
m_creature->SummonCreature(ENTRY_VENGEFUL_SURGE, -2056.41, -2144.01, 20.59, 5.70, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 600000);
7373
m_creature->SummonCreature(ENTRY_VENGEFUL_SURGE, -2050.17, -2140.02, 19.54, 5.17, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 600000);
7474
break;
75-
case 10: DoScriptText(SAY_PROGRESS_5, m_creature, pUnit); break;
75+
case 10: DoScriptText(SAY_PROGRESS_5, m_creature, pPlayer); break;
7676
case 11:
77-
DoScriptText(SAY_PROGRESS_6, m_creature, pUnit);
77+
DoScriptText(SAY_PROGRESS_6, m_creature, pPlayer);
7878
SetRun();
7979
break;
80-
case 19: DoScriptText(SAY_PROGRESS_7, m_creature, pUnit); break;
80+
case 19: DoScriptText(SAY_PROGRESS_7, m_creature, pPlayer); break;
8181
case 20:
8282
DoScriptText(EMOTE_PROGRESS_8, m_creature);
83-
DoScriptText(SAY_PROGRESS_9, m_creature, pUnit);
84-
((Player*)pUnit)->GroupEventHappens(QUEST_SUNKEN_TREASURE, m_creature);
83+
DoScriptText(SAY_PROGRESS_9, m_creature, pPlayer);
84+
pPlayer->GroupEventHappens(QUEST_SUNKEN_TREASURE, m_creature);
8585
break;
8686
}
8787
}

scripts/eastern_kingdoms/eversong_woods.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct MANGOS_DLL_DECL npc_prospector_anvilwardAI : public npc_escortAI
258258
// Pure Virtual Functions
259259
void WaypointReached(uint32 i)
260260
{
261-
Unit* pPlayer = Unit::GetUnit((*m_creature), PlayerGUID);
261+
Player* pPlayer = GetPlayerForEscort();
262262

263263
if (!pPlayer)
264264
return;
@@ -288,12 +288,6 @@ struct MANGOS_DLL_DECL npc_prospector_anvilwardAI : public npc_escortAI
288288
//Default npc faction
289289
m_creature->setFaction(35);
290290
}
291-
292-
void UpdateAI(const uint32 diff)
293-
{
294-
npc_escortAI::UpdateAI(diff); //Must update npc_escortAI
295-
296-
}
297291
};
298292

299293
CreatureAI* GetAI_npc_prospector_anvilward(Creature* pCreature)

scripts/eastern_kingdoms/ghostlands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ struct MANGOS_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
138138

139139
void WaypointReached(uint32 i)
140140
{
141-
Unit* pPlayer = Unit::GetUnit((*m_creature), PlayerGUID);
141+
Player* pPlayer = GetPlayerForEscort();
142142

143-
if (!pPlayer || pPlayer->GetTypeId() != TYPEID_PLAYER)
143+
if (!pPlayer)
144144
return;
145145

146146
switch(i)
@@ -180,7 +180,7 @@ struct MANGOS_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
180180
SetRun(false);
181181
break;
182182
case 30:
183-
((Player*)pPlayer)->GroupEventHappens(QUEST_CATACOMBS,m_creature);
183+
pPlayer->GroupEventHappens(QUEST_CATACOMBS, m_creature);
184184
break;
185185
case 32:
186186
DoScriptText(SAY_END1, m_creature, pPlayer);

scripts/eastern_kingdoms/hinterlands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct MANGOS_DLL_DECL npc_00x09hlAI : public npc_escortAI
6767
break;
6868
case 64:
6969
DoScriptText(SAY_OOX_COMPLETE, m_creature);
70-
if (Player* pPlayer = (Player*)Unit::GetUnit(*m_creature, PlayerGUID))
70+
if (Player* pPlayer = GetPlayerForEscort())
7171
pPlayer->GroupEventHappens(QUEST_RESQUE_OOX_09, m_creature);
7272
break;
7373
}
@@ -248,7 +248,7 @@ struct MANGOS_DLL_DECL npc_rinjiAI : public npc_escortAI
248248

249249
void WaypointReached(uint32 uiPointId)
250250
{
251-
Player* pPlayer = (Player*)Unit::GetUnit(*m_creature, PlayerGUID);
251+
Player* pPlayer = GetPlayerForEscort();
252252

253253
if (!pPlayer)
254254
return;
@@ -284,7 +284,7 @@ struct MANGOS_DLL_DECL npc_rinjiAI : public npc_escortAI
284284
{
285285
m_uiPostEventTimer = 3000;
286286

287-
if (Unit* pPlayer = Unit::GetUnit(*m_creature, PlayerGUID))
287+
if (Player* pPlayer = GetPlayerForEscort())
288288
{
289289
switch(m_uiPostEventCount)
290290
{

scripts/eastern_kingdoms/scarlet_enclave/ebon_hold.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ struct MANGOS_DLL_DECL npc_koltira_deathweaverAI : public npc_escortAI
723723

724724
void JustSummoned(Creature* pSummoned)
725725
{
726-
if (Unit* pPlayer = Unit::GetUnit(*m_creature, PlayerGUID))
726+
if (Player* pPlayer = GetPlayerForEscort())
727727
{
728728
pSummoned->AI()->AttackStart(pPlayer);
729729
pSummoned->AddThreat(m_creature, 0.0f);

scripts/eastern_kingdoms/silverpine_forest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,19 @@ struct MANGOS_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
139139

140140
void WaypointReached(uint32 i)
141141
{
142-
Unit* pUnit = Unit::GetUnit(*m_creature, PlayerGUID);
142+
Player* pPlayer = GetPlayerForEscort();
143143

144-
if (!pUnit || pUnit->GetTypeId() != TYPEID_PLAYER)
144+
if (!pPlayer)
145145
return;
146146

147147
switch(i)
148148
{
149149
case 0:
150-
DoScriptText(SAY_START_2, m_creature, pUnit);
150+
DoScriptText(SAY_START_2, m_creature, pPlayer);
151151
break;
152152
case 13:
153-
DoScriptText(SAY_END, m_creature, pUnit);
154-
((Player*)pUnit)->GroupEventHappens(QUEST_ERLAND, m_creature);
153+
DoScriptText(SAY_END, m_creature, pPlayer);
154+
pPlayer->GroupEventHappens(QUEST_ERLAND, m_creature);
155155
break;
156156
case 14:
157157
if (Unit* pRane = Unit::GetUnit(*m_creature, uiRaneGUID))

scripts/eastern_kingdoms/westfall.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ struct MANGOS_DLL_DECL npc_daphne_stilwellAI : public npc_escortAI
7777

7878
void WaypointReached(uint32 uiPoint)
7979
{
80-
Unit* pUnit = Unit::GetUnit(*m_creature, PlayerGUID);
81-
82-
if (!pUnit || pUnit->GetTypeId() != TYPEID_PLAYER)
83-
return;
84-
8580
m_uiWPHolder = uiPoint;
8681

8782
switch(uiPoint)
@@ -123,7 +118,8 @@ struct MANGOS_DLL_DECL npc_daphne_stilwellAI : public npc_escortAI
123118
m_creature->HandleEmoteCommand(EMOTE_STATE_USESTANDING_NOSHEATHE);
124119
break;
125120
case 17:
126-
((Player*)pUnit)->GroupEventHappens(QUEST_TOME_VALOR, m_creature);
121+
if (Player* pPlayer = GetPlayerForEscort())
122+
pPlayer->GroupEventHappens(QUEST_TOME_VALOR, m_creature);
127123
break;
128124
}
129125
}
@@ -148,10 +144,8 @@ struct MANGOS_DLL_DECL npc_daphne_stilwellAI : public npc_escortAI
148144
pSummoned->AI()->AttackStart(m_creature);
149145
}
150146

151-
void UpdateAI(const uint32 uiDiff)
147+
void UpdateEscortAI(const uint32 uiDiff)
152148
{
153-
npc_escortAI::UpdateAI(uiDiff);
154-
155149
if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
156150
return;
157151

@@ -162,7 +156,11 @@ struct MANGOS_DLL_DECL npc_daphne_stilwellAI : public npc_escortAI
162156
if (!m_creature->IsWithinDist(m_creature->getVictim(), ATTACK_DISTANCE))
163157
DoCast(m_creature->getVictim(), SPELL_SHOOT);
164158

165-
}else m_uiShootTimer -= uiDiff;
159+
}
160+
else
161+
m_uiShootTimer -= uiDiff;
162+
163+
DoMeleeAttackIfReady();
166164
}
167165
};
168166

@@ -202,22 +200,21 @@ struct MANGOS_DLL_DECL npc_defias_traitorAI : public npc_escortAI
202200

203201
void WaypointReached(uint32 i)
204202
{
205-
Unit* pPlayer = Unit::GetUnit((*m_creature), PlayerGUID);
206-
207-
if (!pPlayer || pPlayer->GetTypeId() != TYPEID_PLAYER)
208-
return;
209-
210203
switch (i)
211204
{
212205
case 35:
213206
SetRun(false);
214207
break;
215208
case 36:
216-
DoScriptText(SAY_PROGRESS, m_creature, pPlayer);
209+
if (Player* pPlayer = GetPlayerForEscort())
210+
DoScriptText(SAY_PROGRESS, m_creature, pPlayer);
217211
break;
218212
case 44:
219-
DoScriptText(SAY_END, m_creature, pPlayer);
220-
((Player*)pPlayer)->GroupEventHappens(QUEST_DEFIAS_BROTHERHOOD,m_creature);
213+
if (Player* pPlayer = GetPlayerForEscort())
214+
{
215+
DoScriptText(SAY_END, m_creature, pPlayer);
216+
pPlayer->GroupEventHappens(QUEST_DEFIAS_BROTHERHOOD, m_creature);
217+
}
221218
break;
222219
}
223220
}

scripts/eastern_kingdoms/wetlands.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct MANGOS_DLL_DECL npc_tapoke_slim_jahnAI : public npc_escortAI
7070

7171
void Aggro(Unit* pWho)
7272
{
73-
Unit* pPlayer = Unit::GetUnit(*m_creature, PlayerGUID);
73+
Player* pPlayer = GetPlayerForEscort();
7474

7575
if (IsBeingEscorted && !m_bFriendSummoned && pPlayer)
7676
{
@@ -83,7 +83,7 @@ struct MANGOS_DLL_DECL npc_tapoke_slim_jahnAI : public npc_escortAI
8383

8484
void JustSummoned(Creature* pSummoned)
8585
{
86-
if (Unit* pPlayer = Unit::GetUnit(*m_creature, PlayerGUID))
86+
if (Player* pPlayer = GetPlayerForEscort())
8787
pSummoned->AI()->AttackStart(pPlayer);
8888
}
8989

@@ -102,10 +102,9 @@ struct MANGOS_DLL_DECL npc_tapoke_slim_jahnAI : public npc_escortAI
102102
{
103103
if (m_creature->GetHealth()*100 < m_creature->GetMaxHealth()*20)
104104
{
105-
if (Unit* pPlayer = Unit::GetUnit(*m_creature, PlayerGUID))
105+
if (Player* pPlayer = GetPlayerForEscort())
106106
{
107-
if (pPlayer->GetTypeId() == TYPEID_PLAYER)
108-
((Player*)pPlayer)->GroupEventHappens(QUEST_MISSING_DIPLO_PT11, m_creature);
107+
pPlayer->GroupEventHappens(QUEST_MISSING_DIPLO_PT11, m_creature);
109108

110109
uiDamage = 0;
111110

0 commit comments

Comments
 (0)