Skip to content

Commit

Permalink
Improve PathFinder and TargetedMovementGenerator (vmangos#2853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoabrogga authored Jan 12, 2025
1 parent 94e65d2 commit 35e9f80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/game/Maps/GridMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ float TerrainInfo::GetWaterOrGroundLevel(float x, float y, float z, float* pGrou
GridMapLiquidData liquid_status;

GridMapLiquidStatus res = getLiquidStatus(x, y, ground_z, MAP_ALL_LIQUIDS, &liquid_status);
return res ? (swim ? liquid_status.level - 2.0f : liquid_status.level) : ground_z;
return std::max(res ? (swim ? liquid_status.level - 2.0f : liquid_status.level) : ground_z, ground_z);
}

return VMAP_INVALID_HEIGHT_VALUE;
Expand Down
6 changes: 5 additions & 1 deletion src/game/Maps/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,11 @@ void PathInfo::BuildPointPath(float const* startPoint, float const* endPoint, fl

m_pathPoints.resize(pointCount);
for (uint32 i = 0; i < pointCount; ++i)
m_pathPoints[i] = Vector3(pathPoints[i * VERTEX_SIZE + 2], pathPoints[i * VERTEX_SIZE], pathPoints[i * VERTEX_SIZE + 1]);
{
Vector3 p = Vector3(pathPoints[i * VERTEX_SIZE + 2], pathPoints[i * VERTEX_SIZE], pathPoints[i * VERTEX_SIZE + 1]);
m_sourceUnit->UpdateAllowedPositionZ(p.x, p.y, p.z);
m_pathPoints[i] = p;
}

// first point is always our current location - we need the next one
setActualEndPosition(m_pathPoints[pointCount - 1]);
Expand Down
16 changes: 8 additions & 8 deletions src/game/Movement/TargetedMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,21 @@ void TargetedMovementGeneratorMedium<T, D>::_setTargetLocation(T &owner)
if (petFollowing)
{
float dist = path.Length();
float speed = i_target->GetSpeedForMovementInfo(i_target->m_movementInfo);
if (!speed)
speed = owner.GetSpeedForMovementInfo(owner.m_movementInfo);

init.SetWalk(false);
float speedupDistance = m_fOffset * 2.0f + owner.GetObjectBoundingRadius() + i_target->GetObjectBoundingRadius();
if (dist > speedupDistance)
init.SetVelocity(speed);
if (dist > speed)
{
Unit* pOwner = owner.GetCharmerOrOwner();
if (pOwner && (!pOwner->IsInCombat() && !owner.IsInCombat() || pOwner->IsPlayer() && pOwner->IsMounted()))
{
float distFactor = 1.0f;
if (pOwner->IsMounted())
distFactor += 0.04f * (dist - speedupDistance * 2);
else
distFactor += 0.04f * (dist - speedupDistance);
float distFactor = 1.0f + 0.04f * (dist - speed);
if (distFactor < 1.0f) distFactor = 1.0f;
if (distFactor > 2.1f) distFactor = 2.1f;
init.SetVelocity(distFactor * owner.GetSpeed(MOVE_RUN));
init.SetVelocity(distFactor * speed);
}
}
else if (dist < 2.0f)
Expand Down
5 changes: 1 addition & 4 deletions src/game/Movement/spline/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static thread_local uint32 splineCounter = 1;

int32 MoveSplineInit::Launch()
{
float realSpeedRun = 0.0f;
MoveSpline& move_spline = *unit.movespline;

GenericTransport* newTransport = nullptr;
Expand Down Expand Up @@ -119,9 +118,7 @@ int32 MoveSplineInit::Launch()
moveFlags &= ~MOVEFLAG_ONTRANSPORT;

if (args.velocity == 0.f)
realSpeedRun = args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags));
else
realSpeedRun = unit.GetSpeed(MOVE_RUN);
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags));

if (!args.Validate(&unit))
return 0;
Expand Down

0 comments on commit 35e9f80

Please sign in to comment.