Skip to content

Commit 0674e50

Browse files
author
NoFantasy
committed
[1366] Convert escortAI to use escort states instead of explicit boolean variable for each different state.
Convert escortAI to use escort states instead of explicit boolean variable for each different state. Scripts updated accordingly and obsolete variables removed. git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@1366 5f9c896b-1e26-0410-94da-f77f675e2462
1 parent 10403a3 commit 0674e50

21 files changed

Lines changed: 53 additions & 61 deletions

File tree

base/escort_ai.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ enum
2121
};
2222

2323
npc_escortAI::npc_escortAI(Creature* pCreature) : ScriptedAI(pCreature),
24-
IsBeingEscorted(false),
25-
IsOnHold(false),
2624
m_uiPlayerGUID(0),
2725
m_uiPlayerCheckTimer(1000),
2826
m_uiWPWaitTimer(2500),
2927
m_uiEscortState(STATE_ESCORT_NONE),
30-
m_bIsReturning(false),
3128
m_bIsActiveAttacker(true),
3229
m_bIsRunning(false),
3330
m_pQuestForEscort(NULL),
@@ -116,7 +113,7 @@ void npc_escortAI::MoveInLineOfSight(Unit* pWho)
116113
{
117114
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED) && pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
118115
{
119-
if (IsBeingEscorted && AssistPlayerInCombat(pWho))
116+
if (HasEscortState(STATE_ESCORT_ESCORTING) && AssistPlayerInCombat(pWho))
120117
return;
121118

122119
if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
@@ -144,7 +141,7 @@ void npc_escortAI::MoveInLineOfSight(Unit* pWho)
144141

145142
void npc_escortAI::JustDied(Unit* pKiller)
146143
{
147-
if (!IsBeingEscorted || !m_uiPlayerGUID || !m_pQuestForEscort)
144+
if (!HasEscortState(STATE_ESCORT_ESCORTING) || !m_uiPlayerGUID || !m_pQuestForEscort)
148145
return;
149146

150147
if (Player* pPlayer = GetPlayerForEscort())
@@ -170,8 +167,7 @@ void npc_escortAI::JustDied(Unit* pKiller)
170167

171168
void npc_escortAI::JustRespawned()
172169
{
173-
IsBeingEscorted = false;
174-
IsOnHold = false;
170+
m_uiEscortState = STATE_ESCORT_NONE;
175171

176172
if (!IsCombatMovement())
177173
SetCombatMovement(true);
@@ -192,13 +188,13 @@ void npc_escortAI::EnterEvadeMode()
192188
m_creature->CombatStop(true);
193189
m_creature->SetLootRecipient(NULL);
194190

195-
if (IsBeingEscorted)
191+
if (HasEscortState(STATE_ESCORT_ESCORTING))
196192
{
197193
debug_log("SD2: EscortAI has left combat and is now returning to CombatStartPosition.");
198194

199195
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == TARGETED_MOTION_TYPE)
200196
{
201-
m_bIsReturning = true;
197+
AddEscortState(STATE_ESCORT_RETURNING);
202198

203199
float fPosX, fPosY, fPosZ;
204200
m_creature->GetCombatStartPosition(fPosX, fPosY, fPosZ);
@@ -243,7 +239,7 @@ bool npc_escortAI::IsPlayerOrGroupInRange()
243239
void npc_escortAI::UpdateAI(const uint32 uiDiff)
244240
{
245241
//Waypoint Updating
246-
if (IsBeingEscorted && !m_creature->getVictim() && m_uiWPWaitTimer && !m_bIsReturning)
242+
if (HasEscortState(STATE_ESCORT_ESCORTING) && !m_creature->getVictim() && m_uiWPWaitTimer && !HasEscortState(STATE_ESCORT_RETURNING))
247243
{
248244
if (m_uiWPWaitTimer <= uiDiff)
249245
{
@@ -276,7 +272,7 @@ void npc_escortAI::UpdateAI(const uint32 uiDiff)
276272
return;
277273
}
278274

279-
if (!IsOnHold)
275+
if (!HasEscortState(STATE_ESCORT_PAUSED))
280276
{
281277
m_creature->GetMotionMaster()->MovePoint(CurrentWP->id, CurrentWP->x, CurrentWP->y, CurrentWP->z);
282278
debug_log("SD2: EscortAI start waypoint %u (%f, %f, %f).", CurrentWP->id, CurrentWP->x, CurrentWP->y, CurrentWP->z);
@@ -291,7 +287,7 @@ void npc_escortAI::UpdateAI(const uint32 uiDiff)
291287
}
292288

293289
//Check if player or any member of his group is within range
294-
if (IsBeingEscorted && m_uiPlayerGUID && !m_creature->getVictim() && !m_bIsReturning)
290+
if (HasEscortState(STATE_ESCORT_ESCORTING) && m_uiPlayerGUID && !m_creature->getVictim() && !HasEscortState(STATE_ESCORT_RETURNING))
295291
{
296292
if (m_uiPlayerCheckTimer < uiDiff)
297293
{
@@ -330,7 +326,7 @@ void npc_escortAI::UpdateEscortAI(const uint32 uiDiff)
330326

331327
void npc_escortAI::MovementInform(uint32 uiMoveType, uint32 uiPointId)
332328
{
333-
if (uiMoveType != POINT_MOTION_TYPE || !IsBeingEscorted)
329+
if (uiMoveType != POINT_MOTION_TYPE || !HasEscortState(STATE_ESCORT_ESCORTING))
334330
return;
335331

336332
//Combat start position reached, continue waypoint movement
@@ -343,7 +339,7 @@ void npc_escortAI::MovementInform(uint32 uiMoveType, uint32 uiPointId)
343339
else if (!m_bIsRunning && !m_creature->HasMonsterMoveFlag(MONSTER_MOVE_WALK))
344340
m_creature->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
345341

346-
m_bIsReturning = false;
342+
RemoveEscortState(STATE_ESCORT_RETURNING);
347343

348344
if (!m_uiWPWaitTimer)
349345
m_uiWPWaitTimer = 1;
@@ -426,7 +422,7 @@ void npc_escortAI::Start(bool bIsActiveAttacker, bool bRun, uint64 uiPlayerGUID,
426422
return;
427423
}
428424

429-
if (IsBeingEscorted)
425+
if (HasEscortState(STATE_ESCORT_ESCORTING))
430426
{
431427
error_log("SD2: EscortAI attempt to Start while already escorting");
432428
return;
@@ -474,7 +470,7 @@ void npc_escortAI::Start(bool bIsActiveAttacker, bool bRun, uint64 uiPlayerGUID,
474470
if (m_bIsRunning)
475471
m_creature->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK);
476472

477-
IsBeingEscorted = true;
473+
AddEscortState(STATE_ESCORT_ESCORTING);
478474
}
479475

480476
void npc_escortAI::SetEscortPaused(bool bPaused)

base/escort_ai.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ struct MANGOS_DLL_DECL npc_escortAI : public ScriptedAI
7979
protected:
8080
Player* GetPlayerForEscort() { return (Player*)Unit::GetUnit(*m_creature, m_uiPlayerGUID); }
8181

82-
bool IsBeingEscorted;
83-
bool IsOnHold;
84-
8582
private:
8683
bool AssistPlayerInCombat(Unit* pWho);
8784
bool IsPlayerOrGroupInRange();
@@ -100,8 +97,7 @@ struct MANGOS_DLL_DECL npc_escortAI : public ScriptedAI
10097
std::list<Escort_Waypoint> WaypointList;
10198
std::list<Escort_Waypoint>::iterator CurrentWP;
10299

103-
bool m_bIsActiveAttacker; //possible obsolete, and should be determined with db only (civilian)
104-
bool m_bIsReturning; //in use when creature leave combat, and are returning to combat start position
100+
bool m_bIsActiveAttacker; //obsolete, determined by faction.
105101
bool m_bIsRunning; //all creatures are walking by default (has flag MONSTER_MOVE_WALK)
106102
bool m_bCanInstantRespawn; //if creature should respawn instantly after escort over (if not, database respawntime are used)
107103
bool m_bCanReturnToStart; //if creature can walk same path (loop) without despawn. Not for regular escort quests.

scripts/eastern_kingdoms/blackrock_depths/blackrock_depths.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ struct MANGOS_DLL_DECL npc_rocknotAI : public npc_escortAI
548548

549549
void Reset()
550550
{
551-
if (IsBeingEscorted)
551+
if (HasEscortState(STATE_ESCORT_ESCORTING))
552552
return;
553553

554554
BreakKeg_Timer = 0;

scripts/eastern_kingdoms/ghostlands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct MANGOS_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
124124

125125
void MoveInLineOfSight(Unit* pUnit)
126126
{
127-
if (IsBeingEscorted)
127+
if (HasEscortState(STATE_ESCORT_ESCORTING))
128128
{
129129
if (!m_uiHeliosGUID && pUnit->GetEntry() == NPC_CAPTAIN_HELIOS)
130130
{
@@ -195,7 +195,7 @@ struct MANGOS_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
195195

196196
void Reset()
197197
{
198-
if (!IsBeingEscorted)
198+
if (!HasEscortState(STATE_ESCORT_ESCORTING))
199199
{
200200
m_uiGoCageGUID = 0;
201201
m_uiHeliosGUID = 0;

scripts/eastern_kingdoms/hinterlands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ struct MANGOS_DLL_DECL npc_rinjiAI : public npc_escortAI
204204

205205
void Aggro(Unit* pWho)
206206
{
207-
if (IsBeingEscorted)
207+
if (HasEscortState(STATE_ESCORT_ESCORTING))
208208
{
209209
if (pWho->GetEntry() == NPC_OUTRUNNER && !m_bIsByOutrunner)
210210
{
@@ -279,7 +279,7 @@ struct MANGOS_DLL_DECL npc_rinjiAI : public npc_escortAI
279279
//Check if we have a current target
280280
if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
281281
{
282-
if (IsBeingEscorted && m_uiPostEventCount)
282+
if (HasEscortState(STATE_ESCORT_ESCORTING) && m_uiPostEventCount)
283283
{
284284
if (m_uiPostEventTimer < uiDiff)
285285
{

scripts/eastern_kingdoms/karazhan/karazhan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct MANGOS_DLL_DECL npc_barnesAI : public npc_escortAI
162162
break;
163163
case 4:
164164
TalkCount = 0;
165-
IsOnHold = true;
165+
SetEscortPaused(true);
166166

167167
if (Creature* pSpotlight = m_creature->SummonCreature(CREATURE_SPOTLIGHT,
168168
m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), 0.0f,
@@ -258,7 +258,7 @@ struct MANGOS_DLL_DECL npc_barnesAI : public npc_escortAI
258258
{
259259
npc_escortAI::UpdateAI(diff);
260260

261-
if (IsOnHold)
261+
if (HasEscortState(STATE_ESCORT_PAUSED))
262262
{
263263
if (TalkTimer < diff)
264264
{
@@ -267,7 +267,7 @@ struct MANGOS_DLL_DECL npc_barnesAI : public npc_escortAI
267267
if (Creature* pSpotlight = (Creature*)Unit::GetUnit(*m_creature, m_uiSpotlightGUID))
268268
pSpotlight->ForcedDespawn();
269269

270-
IsOnHold = false;
270+
SetEscortPaused(false);
271271
return;
272272
}
273273

scripts/eastern_kingdoms/scarlet_enclave/ebon_hold.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ struct MANGOS_DLL_DECL npc_koltira_deathweaverAI : public npc_escortAI
680680

681681
void Reset()
682682
{
683-
if (!IsBeingEscorted)
683+
if (!HasEscortState(STATE_ESCORT_ESCORTING))
684684
{
685685
m_uiWave = 0;
686686
m_uiWave_Timer = 3000;
@@ -704,7 +704,7 @@ struct MANGOS_DLL_DECL npc_koltira_deathweaverAI : public npc_escortAI
704704
DoCast(m_creature, SPELL_KOLTIRA_TRANSFORM);
705705
break;
706706
case 3:
707-
IsOnHold = true;
707+
SetEscortPaused(true);
708708
m_creature->SetStandState(UNIT_STAND_STATE_KNEEL);
709709
DoScriptText(SAY_BREAKOUT2, m_creature);
710710
DoCast(m_creature, SPELL_ANTI_MAGIC_ZONE); // cast again that makes bubble up
@@ -743,7 +743,7 @@ struct MANGOS_DLL_DECL npc_koltira_deathweaverAI : public npc_escortAI
743743
{
744744
npc_escortAI::UpdateAI(uiDiff);
745745

746-
if (IsOnHold)
746+
if (HasEscortState(STATE_ESCORT_PAUSED))
747747
{
748748
if (m_uiWave_Timer < uiDiff)
749749
{
@@ -792,7 +792,7 @@ struct MANGOS_DLL_DECL npc_koltira_deathweaverAI : public npc_escortAI
792792
break;
793793
case 6:
794794
DoScriptText(SAY_BREAKOUT10, m_creature);
795-
IsOnHold = false;
795+
SetEscortPaused(false);
796796
break;
797797
}
798798

scripts/eastern_kingdoms/silverpine_forest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct MANGOS_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
120120

121121
void MoveInLineOfSight(Unit* pUnit)
122122
{
123-
if (IsBeingEscorted)
123+
if (HasEscortState(STATE_ESCORT_ESCORTING))
124124
{
125125
if (!uiRaneGUID && pUnit->GetEntry() == NPC_RANE)
126126
{
@@ -178,7 +178,7 @@ struct MANGOS_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
178178

179179
void Reset()
180180
{
181-
if (!IsBeingEscorted)
181+
if (!HasEscortState(STATE_ESCORT_ESCORTING))
182182
{
183183
uiRaneGUID = 0;
184184
uiQuinnGUID = 0;

scripts/eastern_kingdoms/westfall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct MANGOS_DLL_DECL npc_daphne_stilwellAI : public npc_escortAI
6060

6161
void Reset()
6262
{
63-
if (IsBeingEscorted)
63+
if (HasEscortState(STATE_ESCORT_ESCORTING))
6464
{
6565
switch(m_uiWPHolder)
6666
{

scripts/eastern_kingdoms/wetlands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct MANGOS_DLL_DECL npc_tapoke_slim_jahnAI : public npc_escortAI
5151

5252
void Reset()
5353
{
54-
if (!IsBeingEscorted)
54+
if (!HasEscortState(STATE_ESCORT_ESCORTING))
5555
m_bFriendSummoned = false;
5656
}
5757

@@ -73,7 +73,7 @@ struct MANGOS_DLL_DECL npc_tapoke_slim_jahnAI : public npc_escortAI
7373
{
7474
Player* pPlayer = GetPlayerForEscort();
7575

76-
if (IsBeingEscorted && !m_bFriendSummoned && pPlayer)
76+
if (HasEscortState(STATE_ESCORT_ESCORTING) && !m_bFriendSummoned && pPlayer)
7777
{
7878
for(uint8 i = 0; i < 3; ++i)
7979
m_creature->CastSpell(m_creature, SPELL_CALL_FRIENDS, true);

0 commit comments

Comments
 (0)