2929#include " ScriptMgr.h"
3030#include " SpellAuras.h"
3131#include " Vehicle.h"
32+ #include " WaypointManager.h"
3233
3334SmartAI::SmartAI (Creature* creature) : CreatureAI(creature), _charmed(false ), _followCreditType(0 ), _followArrivedTimer(0 ), _followCredit(0 ), _followArrivedEntry(0 ), _followDistance(0 .f), _followAngle(0 .f),
3435 _escortState(SMART_ESCORT_NONE), _escortNPCFlags(0 ), _escortInvokerCheckTimer(1000 ), _currentWaypointNode(0 ), _waypointReached(false ), _waypointPauseTimer(0 ), _waypointPauseForced(false ), _repeatWaypointPath(false ),
@@ -43,20 +44,16 @@ bool SmartAI::IsAIControlled() const
4344 return !_charmed;
4445}
4546
46- void SmartAI::StartPath (bool run /* = false */ , uint32 pathId/* = 0*/ , bool repeat/* = false*/ , Unit* invoker/* = nullptr*/ , uint32 nodeId/* = 1*/ )
47+ void SmartAI::StartPath (uint32 pathId/* = 0*/ , bool repeat/* = false*/ , Unit* invoker/* = nullptr*/ , uint32 nodeId/* = 1*/ )
4748{
4849 if (HasEscortState (SMART_ESCORT_ESCORTING))
4950 StopPath ();
5051
51- SetRun (run);
52-
53- if (pathId)
54- {
55- if (!LoadPath (pathId))
56- return ;
57- }
52+ if (!pathId)
53+ return ;
5854
59- if (_path.nodes .empty ())
55+ WaypointPath const * path = LoadPath (pathId);
56+ if (!path)
6057 return ;
6158
6259 _currentWaypointNode = nodeId;
@@ -73,32 +70,23 @@ void SmartAI::StartPath(bool run/* = false*/, uint32 pathId/* = 0*/, bool repeat
7370 me->ReplaceAllNpcFlags (UNIT_NPC_FLAG_NONE);
7471 }
7572
76- me->GetMotionMaster ()->MovePath (_path , _repeatWaypointPath);
73+ me->GetMotionMaster ()->MovePath (pathId , _repeatWaypointPath);
7774}
7875
79- bool SmartAI::LoadPath (uint32 entry)
76+ WaypointPath const * SmartAI::LoadPath (uint32 entry)
8077{
8178 if (HasEscortState (SMART_ESCORT_ESCORTING))
82- return false ;
79+ return nullptr ;
8380
84- WaypointPath const * path = sSmartWaypointMgr ->GetPath (entry);
81+ WaypointPath const * path = sWaypointMgr ->GetPath (entry);
8582 if (!path || path->nodes .empty ())
8683 {
8784 GetScript ()->SetPathId (0 );
88- return false ;
89- }
90-
91- _path.id = path->id ;
92- _path.nodes = path->nodes ;
93- for (WaypointNode& waypoint : _path.nodes )
94- {
95- Trinity::NormalizeMapCoord (waypoint.x );
96- Trinity::NormalizeMapCoord (waypoint.y );
97- waypoint.moveType = _run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
85+ return nullptr ;
9886 }
9987
10088 GetScript ()->SetPathId (entry);
101- return true ;
89+ return path ;
10290}
10391
10492void SmartAI::PausePath (uint32 delay, bool forced)
@@ -189,7 +177,7 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
189177void SmartAI::EndPath (bool fail)
190178{
191179 RemoveEscortState (SMART_ESCORT_ESCORTING | SMART_ESCORT_PAUSED | SMART_ESCORT_RETURNING);
192- _path. nodes . clear ();
180+
193181 _waypointPauseTimer = 0 ;
194182
195183 if (_escortNPCFlags)
@@ -251,7 +239,7 @@ void SmartAI::EndPath(bool fail)
251239 if (_repeatWaypointPath)
252240 {
253241 if (IsAIControlled ())
254- StartPath (_run, GetScript ()->GetPathId (), _repeatWaypointPath);
242+ StartPath (GetScript ()->GetPathId (), _repeatWaypointPath);
255243 }
256244 else if (pathid == GetScript ()->GetPathId ()) // if it's not the same pathid, our script wants to start another path; don't override it
257245 GetScript ()->SetPathId (0 );
@@ -373,7 +361,8 @@ void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId)
373361 }
374362 else if (HasEscortState (SMART_ESCORT_ESCORTING) && me->GetMotionMaster ()->GetCurrentMovementGeneratorType () == WAYPOINT_MOTION_TYPE)
375363 {
376- if (_currentWaypointNode == _path.nodes .size ())
364+ WaypointPath const * path = sWaypointMgr ->GetPath (pathId);
365+ if (path && _currentWaypointNode == path->nodes .size ())
377366 _waypointPathEnded = true ;
378367 else
379368 SetRun (_run);
@@ -713,7 +702,7 @@ void SmartAI::OnCharmed(bool isNew)
713702 if (!charmed && !me->IsInEvadeMode ())
714703 {
715704 if (_repeatWaypointPath)
716- StartPath (_run, GetScript ()->GetPathId (), true );
705+ StartPath (GetScript ()->GetPathId (), true );
717706 else
718707 me->SetWalk (!_run);
719708
@@ -761,8 +750,6 @@ void SmartAI::SetRun(bool run)
761750{
762751 me->SetWalk (!run);
763752 _run = run;
764- for (auto & node : _path.nodes )
765- node.moveType = run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK;
766753}
767754
768755void SmartAI::SetDisableGravity (bool fly)
0 commit comments