mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
Compare commits
5 Commits
ba1b429bc5
...
6cf10c5057
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cf10c5057 | ||
|
|
13dba79982 | ||
|
|
4f193cb0cb | ||
|
|
0ba9908007 | ||
|
|
c5435f15c1 |
@ -3142,6 +3142,29 @@ bool MovementAction::LaunchWalkSpline(TravelPlan& state)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sparse-segment clip (cmangos parity): truncate the chain at the
|
||||||
|
// first segment longer than ~11.18y. Spline interpolation between
|
||||||
|
// sparse waypoints can cut corners through visual obstacles (trees,
|
||||||
|
// walls) the navmesh routed around. Bot re-plans from a closer
|
||||||
|
// position next tick where the resolved poly chain is denser.
|
||||||
|
{
|
||||||
|
constexpr float SPARSE_SEG_SQ = 125.0f; // sqrt(125) ≈ 11.18y
|
||||||
|
for (size_t i = 1; i < state.walkPoints.size(); ++i)
|
||||||
|
{
|
||||||
|
G3D::Vector3 d = state.walkPoints[i] - state.walkPoints[i - 1];
|
||||||
|
if (d.squaredLength() > SPARSE_SEG_SQ)
|
||||||
|
{
|
||||||
|
state.walkPoints.resize(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state.walkPoints.size() < 2)
|
||||||
|
{
|
||||||
|
state.walkPoints.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Re-clamp cached waypoints to current valid Z. Rows in
|
// Re-clamp cached waypoints to current valid Z. Rows in
|
||||||
// playerbots_travelnode_path store absolute coords baked at
|
// playerbots_travelnode_path store absolute coords baked at
|
||||||
// offline generation; if the live navmesh has shifted since
|
// offline generation; if the live navmesh has shifted since
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "NewRpgBaseAction.h"
|
#include "NewRpgBaseAction.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "BroadcastHelper.h"
|
#include "BroadcastHelper.h"
|
||||||
@ -220,6 +221,21 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
|
|||||||
stepDest.GetPositionY(), stepDest.GetPositionZ());
|
stepDest.GetPositionY(), stepDest.GetPositionZ());
|
||||||
if (endDistToDest + 5.0f < disToDest)
|
if (endDistToDest + 5.0f < disToDest)
|
||||||
{
|
{
|
||||||
|
// Z gap check: if the probe's last waypoint is well below
|
||||||
|
// the requested destination Z, the chain walked the ground
|
||||||
|
// polygon graph toward an elevated target it can't reach
|
||||||
|
// (quest giver on top of Aldrassil etc.). Refuse to dispatch
|
||||||
|
// — bot waits instead of tunneling into the visual model.
|
||||||
|
// 10y tolerates normal terrain variation (ramp ends, hill
|
||||||
|
// tops) while still catching clearly unreachable elevations.
|
||||||
|
if (std::fabs(stepDest.GetPositionZ() - dest.GetPositionZ()) > 10.0f)
|
||||||
|
{
|
||||||
|
EmitDebugMove("MoveFar", "z-mismatch",
|
||||||
|
dest.GetPositionX(), dest.GetPositionY(),
|
||||||
|
dest.GetPositionZ());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Movement::PointsArray points;
|
Movement::PointsArray points;
|
||||||
points.reserve(probe.size());
|
points.reserve(probe.size());
|
||||||
for (auto const& wp : probe)
|
for (auto const& wp : probe)
|
||||||
@ -278,6 +294,57 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
|
|||||||
if (points.size() < 2)
|
if (points.size() < 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Prefix trim (cmangos parity: makeShortCut on every dispatch).
|
||||||
|
// Drop leading waypoints behind the bot's current position so the
|
||||||
|
// spline begins from where the bot actually is, not from a stale
|
||||||
|
// planner-start. Picks the waypoint closest to the bot in 3D and
|
||||||
|
// erases everything before it.
|
||||||
|
{
|
||||||
|
float const bx = bot->GetPositionX();
|
||||||
|
float const by = bot->GetPositionY();
|
||||||
|
float const bz = bot->GetPositionZ();
|
||||||
|
float minSq = std::numeric_limits<float>::max();
|
||||||
|
size_t closest = 0;
|
||||||
|
for (size_t i = 0; i < points.size(); ++i)
|
||||||
|
{
|
||||||
|
float dx = points[i].x - bx;
|
||||||
|
float dy = points[i].y - by;
|
||||||
|
float dz = points[i].z - bz;
|
||||||
|
float sq = dx * dx + dy * dy + dz * dz;
|
||||||
|
if (sq < minSq)
|
||||||
|
{
|
||||||
|
minSq = sq;
|
||||||
|
closest = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (closest > 0)
|
||||||
|
points.erase(points.begin(), points.begin() + closest);
|
||||||
|
if (points.size() < 2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sparse-segment clip (cmangos parity): if any consecutive segment
|
||||||
|
// is longer than ~11.18y, truncate the path at that point. Short,
|
||||||
|
// dense waypoints reduce spline interpolation across visual
|
||||||
|
// obstacles between sparse points; bot re-plans from a closer
|
||||||
|
// position next tick.
|
||||||
|
{
|
||||||
|
constexpr float SPARSE_SEG_SQ = 125.0f; // sqrt(125) ≈ 11.18y
|
||||||
|
for (size_t i = 1; i < points.size(); ++i)
|
||||||
|
{
|
||||||
|
float dx = points[i].x - points[i - 1].x;
|
||||||
|
float dy = points[i].y - points[i - 1].y;
|
||||||
|
float dz = points[i].z - points[i - 1].z;
|
||||||
|
if (dx * dx + dy * dy + dz * dz > SPARSE_SEG_SQ)
|
||||||
|
{
|
||||||
|
points.resize(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (points.size() < 2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// LOS gate: reject paths whose segments pass through visual
|
// LOS gate: reject paths whose segments pass through visual
|
||||||
// geometry. mmap is blind to M2 models (trees, decorative props)
|
// geometry. mmap is blind to M2 models (trees, decorative props)
|
||||||
// and will route through them; vmap LOS catches the cases that
|
// and will route through them; vmap LOS catches the cases that
|
||||||
@ -473,32 +540,61 @@ bool NewRpgBaseAction::MoveWorldObjectTo(ObjectGuid guid, float distance)
|
|||||||
if (!object)
|
if (!object)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float x = object->GetPositionX();
|
Map* map = bot->GetMap();
|
||||||
float y = object->GetPositionY();
|
if (!map)
|
||||||
float z = object->GetPositionZ();
|
return false;
|
||||||
float angle = 0.f;
|
|
||||||
|
|
||||||
if (!object->ToUnit() || !object->ToUnit()->isMoving())
|
// 8-angle deterministic iteration around the target. For each angle,
|
||||||
angle = object->GetAngle(bot) + (M_PI * irand(-25, 25) / 100.0); // Closest 45 degrees towards the target
|
// validate the candidate against the navmesh with a strict ground-only
|
||||||
else
|
// filter (NAV_GROUND, exclude STEEP/WATER/MAGMA/SLIME). Reject if no
|
||||||
angle = object->GetOrientation() +
|
// valid poly within 5y XY+Z or if the snap drifts the Z by >10y.
|
||||||
(M_PI * irand(-25, 25) / 100.0); // 45 degrees infront of target (leading it's movement)
|
// First angle that passes both LOS and navmesh-snap wins.
|
||||||
|
dtNavMeshQuery const* navMeshQuery =
|
||||||
|
map->GetMapCollisionData().GetMMapData().GetNavMeshQuery();
|
||||||
|
float const baseAngle = object->GetAngle(bot);
|
||||||
|
|
||||||
// Bias toward the full radius so the bot stops next to the object,
|
for (float step = 0.0f; step < 2.0f * static_cast<float>(M_PI);
|
||||||
// not on top of it. Uniform rnd would put dest anywhere in [0, distance].
|
step += static_cast<float>(M_PI) / 4.0f)
|
||||||
float rnd = 0.85f + 0.15f * rand_norm();
|
|
||||||
x += cos(angle) * distance * rnd;
|
|
||||||
y += sin(angle) * distance * rnd;
|
|
||||||
if (!object->GetMap()->CheckCollisionAndGetValidCoords(object, object->GetPositionX(), object->GetPositionY(),
|
|
||||||
object->GetPositionZ(), x, y, z))
|
|
||||||
{
|
{
|
||||||
x = object->GetPositionX();
|
float const angle = baseAngle + step;
|
||||||
y = object->GetPositionY();
|
float x = object->GetPositionX() + std::cos(angle) * distance;
|
||||||
z = object->GetPositionZ();
|
float y = object->GetPositionY() + std::sin(angle) * distance;
|
||||||
|
float z = object->GetPositionZ();
|
||||||
|
|
||||||
|
// LOS check at eye height.
|
||||||
|
if (!bot->IsWithinLOS(x, y, z + bot->GetCollisionHeight()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Strict navmesh-snap validation (cmangos ClosestCorrectPoint port).
|
||||||
|
if (navMeshQuery)
|
||||||
|
{
|
||||||
|
dtQueryFilter filter;
|
||||||
|
filter.setIncludeFlags(NAV_GROUND);
|
||||||
|
filter.setExcludeFlags(NAV_GROUND_STEEP | NAV_WATER | NAV_MAGMA | NAV_SLIME);
|
||||||
|
|
||||||
|
float const point[VERTEX_SIZE] = { y, z, x };
|
||||||
|
float const extents[VERTEX_SIZE] = { 5.0f, 5.0f, 5.0f };
|
||||||
|
float closest[VERTEX_SIZE] = { 0.0f, 0.0f, 0.0f };
|
||||||
|
dtPolyRef polyRef = INVALID_POLYREF;
|
||||||
|
|
||||||
|
if (!dtStatusSucceed(navMeshQuery->findNearestPoly(
|
||||||
|
point, extents, &filter, &polyRef, closest)) ||
|
||||||
|
polyRef == INVALID_POLYREF)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float const snappedZ = closest[1];
|
||||||
|
if (std::fabs(snappedZ - z) > 10.0f)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
x = closest[2];
|
||||||
|
y = closest[0];
|
||||||
|
z = snappedZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MoveFarTo(WorldPosition(object->GetMapId(), x, y, z));
|
||||||
}
|
}
|
||||||
// Route through MoveFarTo so every approach gets the full probe
|
|
||||||
// + travel-node fallback (and a precise debug label).
|
return false;
|
||||||
return MoveFarTo(WorldPosition(object->GetMapId(), x, y, z));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NewRpgBaseAction::MoveRandomNear(float moveStep, MovementPriority priority, WorldObject* center)
|
bool NewRpgBaseAction::MoveRandomNear(float moveStep, MovementPriority priority, WorldObject* center)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user