Core/Movement: Fix LoS issue of NPCs chasing targets

Add Line of Sight checks to ChaseMovementGenerator::Update(), fixing to ChaseMovementGenerator not reaching a point with valid LoS to the target.

Fix re-implements 8927a04253 after 2a84562dc8 partially removed it.

Fix #23724

(cherry picked from commit 215a6cee24)
This commit is contained in:
jackpoz
2019-09-13 21:06:28 +02:00
committed by Shauren
parent 1e77bfe3ca
commit f012d4b7fc
2 changed files with 15 additions and 1 deletions

View File

@@ -44,7 +44,11 @@ static bool PositionOkay(Unit* owner, Unit* target, Optional<float> minDistance,
return false;
if (maxDistance && distSq > square(*maxDistance))
return false;
return !angle || angle->IsAngleOkay(target->GetRelativeAngle(owner));
if (angle && !angle->IsAngleOkay(target->GetRelativeAngle(owner)))
return false;
if (!owner->IsWithinLOSInMap(target))
return false;
return true;
}
static void DoMovementInform(Unit* owner, Unit* target)

View File

@@ -927,6 +927,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
return;
size_t i = _pathPoints.size()-1;
float x, y, z, collisionHeight = _sourceUnit->GetCollisionHeight();
// find the first i s.t.:
// - _pathPoints[i] is still too close
// - _pathPoints[i-1] is too far away
@@ -937,6 +938,15 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
if ((_pathPoints[i-1] - target).squaredLength() >= distSq)
break; // bingo!
// check if the shortened path is still in LoS with the target
_sourceUnit->GetHitSpherePointFor({ _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z + collisionHeight }, x, y, z);
if (!_sourceUnit->GetMap()->isInLineOfSight(_sourceUnit->GetPhaseShift(), x, y, z, _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z + collisionHeight, LINEOFSIGHT_ALL_CHECKS, VMAP::ModelIgnoreFlags::Nothing))
{
// whenver we find a point that is not in LoS anymore, simply use last valid path
_pathPoints.resize(i + 1);
return;
}
if (!--i)
{
// no point found that fulfills the condition