Skip to content

fix(CORE/SAI): Properly Implement START_CLOSEST_WAYPOINT #22256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,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;
uint32 closestWp = 0;

for (WorldObject* target : targets)
{
Expand All @@ -2522,12 +2522,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!path || path->empty())
continue;

auto itrWp = path->find(0);
auto itrWp = path->find(1);
if (itrWp != path->end())
{
if (WayPoint* wp = itrWp->second)
if (WayPoint* wpData = itrWp->second)
{
float distToThisPath = creature->GetDistance(wp->x, wp->y, wp->z);
float distToThisPath = creature->GetDistance(wpData->x, wpData->y, wpData->z);
if (distToThisPath < distanceToClosest)
{
distanceToClosest = distToThisPath;
Expand All @@ -2538,7 +2538,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}

if (closestWp)
CAST_AI(SmartAI, creature->AI())->StartPath(false, closestWp->id, true);
CAST_AI(SmartAI, creature->AI())->StartPath(false, closestWp, true);
}
}
}
Expand Down