Core/Movement: waypoint movement (#20121)

Following the work done in #19361 this is the cleanup and improvement of the related logic of waypoint management.

Ref 28050f3 #18020
(taking the good parts and ignoring the incomplete work)
This commit is contained in:
ccrs
2017-08-12 01:40:25 +02:00
committed by GitHub
parent 00329fe9a5
commit 7fff83d675
98 changed files with 1357 additions and 1457 deletions

View File

@@ -39,6 +39,7 @@
#include "SpellMgr.h"
#include "TemporarySummon.h"
#include "Vehicle.h"
#include "WaypointDefines.h"
#include <G3D/Quat.h>
SmartScript::SmartScript()
@@ -1990,7 +1991,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
std::back_inserter(waypoints), [](uint32 wp) { return wp != 0; });
float distanceToClosest = std::numeric_limits<float>::max();
WayPoint* closestWp = nullptr;
std::pair<uint32, uint32> closest = { 0, 0 };
for (WorldObject* target : targets)
{
@@ -1998,29 +1999,27 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsSmart(creature))
{
for (uint32 wp : waypoints)
for (uint32 pathId : waypoints)
{
WPPath* path = sSmartWaypointMgr->GetPath(wp);
if (!path || path->empty())
WaypointPath const* path = sSmartWaypointMgr->GetPath(pathId);
if (!path || path->nodes.empty())
continue;
auto itrWp = path->find(0);
if (itrWp != path->end())
for (auto itr = path->nodes.begin(); itr != path->nodes.end(); ++itr)
{
if (WayPoint* wp = itrWp->second)
WaypointNode const waypoint = *itr;
float distamceToThisNode = creature->GetDistance(waypoint.x, waypoint.y, waypoint.z);
if (distamceToThisNode < distanceToClosest)
{
float distToThisPath = creature->GetDistance(wp->x, wp->y, wp->z);
if (distToThisPath < distanceToClosest)
{
distanceToClosest = distToThisPath;
closestWp = wp;
}
distanceToClosest = distamceToThisNode;
closest.first = pathId;
closest.second = waypoint.id;
}
}
}
if (closestWp)
CAST_AI(SmartAI, creature->AI())->StartPath(false, closestWp->id, true);
if (closest.first != 0)
CAST_AI(SmartAI, creature->AI())->StartPath(false, closest.first, true, nullptr, closest.second);
}
}
}