Compare commits

...

11 Commits

6 changed files with 131 additions and 144 deletions

View File

@ -173,7 +173,7 @@ std::vector<uint32> const vFlagsIC = {GO_HORDE_BANNER,
GO_HORDE_BANNER_GRAVEYARD_H, GO_HORDE_BANNER_GRAVEYARD_H,
GO_HORDE_BANNER_GRAVEYARD_H_CONT}; GO_HORDE_BANNER_GRAVEYARD_H_CONT};
// BG Waypoints (vmangos) // BG Waypoints
// Horde Flag Room to Horde Graveyard // Horde Flag Room to Horde Graveyard
BattleBotPath vPath_WSG_HordeFlagRoom_to_HordeGraveyard = { BattleBotPath vPath_WSG_HordeFlagRoom_to_HordeGraveyard = {

View File

@ -386,14 +386,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
else else
{ {
// Direct dispatch — engine MovePoint(generatePath=true) handles // Direct dispatch — engine MovePoint(generatePath=true) handles
// path-finding internally. Previously called SearchForBestPath // pathfinding. Avoid ±z probes: their "shortest path" preference
// here to probe ±step around the target z; that helped find // can pick an unreachable ledge and air-walk via NOPATH fallback.
// polygons when the input z was several yards off the navmesh,
// but its "shortest path" preference would shift modifiedZ to
// an unreachable nearby polygon (upper terrace, ledge above)
// and then the engine's straight-spline NOPATH fallback would
// air-walk the bot up to it. cmangos doesn't have an
// equivalent — single-z PathFinder call is sufficient.
float distance = bot->GetExactDist(x, y, z); float distance = bot->GetExactDist(x, y, z);
if (distance > 0.01f) if (distance > 0.01f)
{ {
@ -1179,7 +1173,7 @@ void MovementAction::UpdateMovementState()
// { // {
// bot->SetSpeedRate(MOVE_RUN, 1.0f); // bot->SetSpeedRate(MOVE_RUN, 1.0f);
// } // }
// check if target is not reachable (from Vmangos) // check if target is not reachable
// if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() && // if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && bot->CanNotReachTarget() &&
// !bot->InBattleground()) // !bot->InBattleground())
// { // {
@ -3221,22 +3215,12 @@ bool MovementAction::RefineWalkPoints(std::vector<G3D::Vector3>& walkPoints)
WorldPosition aPos(mapId, a.x, a.y, a.z); WorldPosition aPos(mapId, a.x, a.y, a.z);
WorldPosition bPos(mapId, b.x, b.y, b.z); WorldPosition bPos(mapId, b.x, b.y, b.z);
// Per-segment mmap query against the live navmesh. The // Per-segment mmap query: routes around geometry the offline
// travel-node graph stores offline-baked waypoints; if the // graph didn't account for, or returns empty if unreachable.
// straight line A->B crosses geometry the live navmesh has
// (mountain, ledge, model edit since offline gen), this
// returns either an mmap-routed path around it (NORMAL/
// INCOMPLETE) or empty (NOT_USING_PATH was rejected as
// "would walk through walls").
std::vector<WorldPosition> segPath = bPos.getPathStepFrom(aPos, bot); std::vector<WorldPosition> segPath = bPos.getPathStepFrom(aPos, bot);
// Travelnode waypoints are authoritative once a plan is // Trust the raw waypoint pair when mmap can't validate it —
// active. When AC mmap can't validate the segment (empty // navmesh gaps/tile-edge artifacts shouldn't kill an active plan.
// result, or IsPathCheating rejects a 2-point shortcut /
// steep hop), fall back to dispatching the raw (A, B) pair
// instead of aborting the plan. Common cases: cmangos
// waypoints landing in 1y navmesh gaps from AC extractor
// differences, tile-edge artifacts at zone borders.
bool const trustRaw = segPath.empty() || bool const trustRaw = segPath.empty() ||
TravelPath::IsPathCheating(segPath, aPos.distance(bPos)); TravelPath::IsPathCheating(segPath, aPos.distance(bPos));
@ -3248,9 +3232,8 @@ bool MovementAction::RefineWalkPoints(std::vector<G3D::Vector3>& walkPoints)
continue; continue;
} }
// First segment: include its start point so the spline // Include the first segment's start; skip subsequent starts
// begins from the original A. Later segments: skip the first // to avoid duplicating the prior segment's tail.
// point — it duplicates the previous segment's tail.
size_t startK = (i == 0) ? 0 : 1; size_t startK = (i == 0) ? 0 : 1;
for (size_t k = startK; k < segPath.size(); ++k) for (size_t k = startK; k < segPath.size(); ++k)
refined.emplace_back(segPath[k].GetPositionX(), refined.emplace_back(segPath[k].GetPositionX(),
@ -3301,15 +3284,6 @@ bool MovementAction::GetTravelPlan(TravelPlan& plan, WorldPosition destination)
{ {
WorldPosition botPos(bot->GetMapId(), bot->GetPositionX(), WorldPosition botPos(bot->GetMapId(), bot->GetPositionX(),
bot->GetPositionY(), bot->GetPositionZ()); bot->GetPositionY(), bot->GetPositionZ());
LOG_DEBUG("playerbots",
"[TravelPlan] {} requesting plan: from ({:.0f},{:.0f},{:.0f}) map={} zone={} → "
"({:.0f},{:.0f},{:.0f}) map={} (straight={:.0f}yd)",
bot->GetName(), botPos.GetPositionX(), botPos.GetPositionY(), botPos.GetPositionZ(),
bot->GetMapId(), bot->GetZoneId(),
destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ(),
destination.GetMapId(), botPos.fDist(destination));
return sTravelNodeMap.GetFullPath(plan, botPos, bot->GetZoneId(), destination, bot); return sTravelNodeMap.GetFullPath(plan, botPos, bot->GetZoneId(), destination, bot);
} }
@ -3473,14 +3447,8 @@ bool MovementAction::ExecuteTravelPlan(TravelPlan& state)
return true; return true;
} }
// Re-validate each consecutive (A, B) pair against the // Re-validate each segment against the live navmesh and
// live navmesh. The graph's offline-baked coords can // substitute mmap-routed sub-paths where needed.
// produce a chain whose straight-line interpolation
// passes through geometry (mountains, ledges, model
// edits). RefineWalkPoints substitutes mmap-routed
// sub-paths between each pair; if any segment is
// unwalkable, abort the plan so MoveFarTo's own probe
// can re-derive a route.
if (!RefineWalkPoints(state.walkPoints)) if (!RefineWalkPoints(state.walkPoints))
{ {
G3D::Vector3 const& failPt = state.walkPoints.empty() G3D::Vector3 const& failPt = state.walkPoints.empty()
@ -3639,8 +3607,7 @@ bool MovementAction::ExecuteTravelPlan(TravelPlan& state)
if (bot->IsMounted()) if (bot->IsMounted())
bot->Dismount(); bot->Dismount();
if (bot->ActivateTaxiPathTo(state.route, flightMaster, 0)) bot->ActivateTaxiPathTo(state.route, flightMaster, 0);
LOG_DEBUG("playerbots","[TravelPlan] Bot {} taking flight ({} nodes)", bot->GetName(), state.route.size());
state.route.clear(); state.route.clear();
state.stepIdx += 2; state.stepIdx += 2;

View File

@ -433,6 +433,45 @@ bool NewRpgDoQuestAction::DoIncompleteQuest(NewRpgInfo::DoQuest& data)
return MoveRandomNear(20.0f); return MoveRandomNear(20.0f);
} }
// Kill-quest scout: at POI for 30s+ with no quest mob in sight
// means this cluster is empty. Switch to a different POI candidate
// (>50y away) if one exists; otherwise roam in place.
constexpr uint32 scoutTimeoutMs = 30 * 1000;
if (data.lastReachPOI && GetMSTimeDiffToNow(data.lastReachPOI) >= scoutTimeoutMs &&
!HasNearbyQuestMob(30.0f))
{
std::vector<POIInfo> poiInfo;
if (GetQuestPOIPosAndObjectiveIdx(questId, poiInfo))
{
std::vector<size_t> alternatives;
for (size_t i = 0; i < poiInfo.size(); ++i)
{
float dx = poiInfo[i].pos.x - data.pos.GetPositionX();
float dy = poiInfo[i].pos.y - data.pos.GetPositionY();
if (dx * dx + dy * dy > 50.0f * 50.0f)
alternatives.push_back(i);
}
if (!alternatives.empty())
{
size_t pickIdx = alternatives[urand(0, alternatives.size() - 1)];
G3D::Vector2 newPoi = poiInfo[pickIdx].pos;
float dz = std::max(bot->GetMap()->GetHeight(newPoi.x, newPoi.y, MAX_HEIGHT),
bot->GetMap()->GetWaterLevel(newPoi.x, newPoi.y));
if (dz != INVALID_HEIGHT && dz != VMAP_INVALID_HEIGHT_VALUE)
{
data.pos = WorldPosition(bot->GetMapId(), newPoi.x, newPoi.y, dz);
data.objectiveIdx = poiInfo[pickIdx].objectiveIdx;
data.lastReachPOI = 0;
data.pursuedLootGO.Clear();
data.pursuedUseGO.Clear();
data.pursuedUseTarget.Clear();
return true;
}
}
}
return MoveRandomNear(20.0f);
}
// kill quest: walk toward the marker before handing off to grind. // kill quest: walk toward the marker before handing off to grind.
// lastReachPOI trips at ~10y so without this the bot fights on the // lastReachPOI trips at ~10y so without this the bot fights on the
// edge and never reaches the dense cluster. Skip if a quest mob is // edge and never reaches the dense cluster. Skip if a quest mob is

View File

@ -70,11 +70,8 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
} }
} }
// Let previously committed movement finish before recomputing. // Let an in-flight spline finish before recomputing — prevents
// If the bot is still actively walking toward its last committed // oscillation when re-resolve produces a slightly different endpoint.
// point on the same map, just let the current spline finish.
// Prevents oscillation when a re-resolve produces a slightly
// different partial-path endpoint mid-walk.
{ {
LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement"); LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement");
if (bot->isMoving() && lastMove.lastMoveToMapId == bot->GetMapId()) if (bot->isMoving() && lastMove.lastMoveToMapId == bot->GetMapId())
@ -92,9 +89,9 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
// 10% lastPath reuse — if the cached path's endpoint is still // 10% lastPath reuse — if the cached path's endpoint is still
// close (within 10%) to the new dest, trim the cached path to // close (within 10%) to the new dest, trim the cached path to
// the bot's current position via makeShortCut and re-dispatch. // the bot's current position via makeShortCut and re-dispatch.
// Mirrors cmangos ResolveMovePath: per-tick re-dispatch of the // Per-tick re-dispatch of the (trimmed) last path keeps the bot
// (trimmed) last path keeps the bot on-route after interrupts // on-route after interrupts (knockback, combat, manual move)
// (knockback, combat, manual move) without needing a full replan. // without needing a full replan.
{ {
LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement"); LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement");
if (!lastMove.lastPath.empty()) if (!lastMove.lastPath.empty())
@ -139,26 +136,16 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
float disToDest = bot->GetDistance(dest); float disToDest = bot->GetDistance(dest);
float dis = bot->GetExactDist(dest); float dis = bot->GetExactDist(dest);
// Decision tree: // Try the travel-node graph first for cross-map or > 50y moves;
// 1. Active node plan with matching dest → ride it. // fall back to chained mmap probe otherwise. BGs skip the graph.
// 2. Long-distance / cross-map: try the node graph FIRST. constexpr float TRAVELNODE_THRESHOLD = 50.0f;
// Graph internally probes mmap and falls back to A* route.
// 3. Else: 40-step chained mmap probe + regression guard.
// 4. Empty / non-progressing probe: single-waypoint MoveTo.
//
// needsLongPath gate — cross-map or > 75y go to graph.
// BG gating: graph holds open-world routes only.
constexpr float TRAVELNODE_THRESHOLD = 75.0f;
bool tryNodes = sPlayerbotAIConfig.enableTravelNodes && bool tryNodes = sPlayerbotAIConfig.enableTravelNodes &&
!bot->InBattleground() && !bot->InBattleground() &&
((bot->GetMapId() != dest.GetMapId()) || ((bot->GetMapId() != dest.GetMapId()) ||
(dis > TRAVELNODE_THRESHOLD)); (dis > TRAVELNODE_THRESHOLD));
// If a node plan is already active, ride it — but only if its // Ride the active node plan only if its dest still matches.
// destination still matches the requested dest. Otherwise the // A stale plan would steer the bot past a new target.
// old plan (e.g. built toward a quest objective POI) would keep
// driving the bot after the caller switched targets (e.g. to a
// turn-in NPC).
if (tryNodes && botAI->rpgInfo.HasActiveTravelPlan()) if (tryNodes && botAI->rpgInfo.HasActiveTravelPlan())
{ {
if (botAI->rpgInfo.travelPlan.destination.distance(dest) > 10.0f) if (botAI->rpgInfo.travelPlan.destination.distance(dest) > 10.0f)
@ -174,8 +161,6 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
StartTravelPlan(dest); StartTravelPlan(dest);
if (botAI->rpgInfo.HasActiveTravelPlan()) if (botAI->rpgInfo.HasActiveTravelPlan())
{ {
LOG_INFO("playerbots", "[MoveFar] {} nodetravel | dis={:.0f}",
bot->GetName(), dis);
EmitDebugMove("MoveFar", "travelplan", EmitDebugMove("MoveFar", "travelplan",
dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ()); dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
return UpdateTravelPlan(); return UpdateTravelPlan();
@ -193,13 +178,8 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
WorldPosition botPos(bot); WorldPosition botPos(bot);
std::vector<WorldPosition> probe = botPos.getPathTo(dest, bot); std::vector<WorldPosition> probe = botPos.getPathTo(dest, bot);
// Regression guard (cmangos ResolveMovePath parity): if a cached // Regression guard: prefer cached lastPath if it still ends closer
// lastPath ends at least as close to dest as the new probe's // to dest than the new probe — catches probes blocked by geometry.
// endpoint, prefer the cached path. The 10% reuse block above
// already returned early when cached was within 10% of dest;
// this catches "cached is far (>10%) but still better than the
// probe" — typically when the probe got blocked by geometry and
// ended much farther from dest than where cached had reached.
{ {
LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement"); LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement");
if (!lastMove.lastPath.empty() && !probe.empty() && probe.size() >= 2) if (!lastMove.lastPath.empty() && !probe.empty() && probe.size() >= 2)
@ -247,9 +227,6 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
if (points.size() >= 2) if (points.size() >= 2)
{ {
LOG_INFO("playerbots", "[MoveFar] {} mmap-path | dis={:.0f} | endDist={:.0f} | wp={}",
bot->GetName(), dis, endDistToDest, (uint32)points.size());
// Mount up if outdoors and not in combat. // Mount up if outdoors and not in combat.
if (!bot->IsMounted() && !bot->IsInCombat() && bot->IsOutdoors() && bot->IsAlive()) if (!bot->IsMounted() && !bot->IsInCombat() && bot->IsOutdoors() && bot->IsAlive())
botAI->DoSpecificAction("check mount state", Event(), true); botAI->DoSpecificAction("check mount state", Event(), true);
@ -274,13 +251,20 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
} }
} }
// Empty-probe fallback — single-waypoint MoveTo. Engine // Empty-probe fallback: single-waypoint MoveTo via engine PathGenerator.
// MovePoint(generatePath=true) does the local PathGenerator // Cross-map can't be served by a single-map spline — bail.
// resolution. Cross-map can't be served by a single-map spline
// — bail rather than dispatching toward unreachable coords.
if (bot->GetMapId() != dest.GetMapId()) if (bot->GetMapId() != dest.GetMapId())
return false; return false;
// LOS gate: don't air-walk through trees/walls when the engine
// would otherwise drop to a straight-line BuildShortcut spline.
if (!bot->IsWithinLOS(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ()))
{
EmitDebugMove("MoveFar", "spline-blocked",
dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
return false;
}
EmitDebugMove("MoveFar", "spline", EmitDebugMove("MoveFar", "spline",
dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ()); dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
return MoveTo(dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), return MoveTo(dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(),
@ -294,9 +278,30 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
if (points.size() < 2) if (points.size() < 2)
return false; return false;
// Save planner output BEFORE any clip/fixup mutation so next-tick // LOS gate: reject paths whose segments pass through visual
// reuse/regress branches see the original intent, not a clip- // geometry. mmap is blind to M2 models (trees, decorative props)
// truncated tail. // and will route through them; vmap LOS catches the cases that
// matter — solid trunks, walls, terrain features.
if (Map* map = bot->GetMap())
{
float const eye = bot->GetCollisionHeight();
for (size_t i = 0; i + 1 < points.size(); ++i)
{
if (!map->isInLineOfSight(points[i].x, points[i].y, points[i].z + eye,
points[i + 1].x, points[i + 1].y, points[i + 1].z + eye,
bot->GetPhaseMask(),
LINEOFSIGHT_ALL_CHECKS,
VMAP::ModelIgnoreFlags::Nothing))
{
EmitDebugMove("MoveFar", "blocked",
dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
return false;
}
}
}
// Save planner output before clip/fixup so next-tick reuse sees
// the original intent, not a truncated tail.
{ {
LastMovement& lm = AI_VALUE(LastMovement&, "last movement"); LastMovement& lm = AI_VALUE(LastMovement&, "last movement");
std::vector<WorldPosition> wpts; std::vector<WorldPosition> wpts;
@ -306,9 +311,8 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
lm.setPath(TravelPath(wpts)); lm.setPath(TravelPath(wpts));
} }
// Underwater fixup — push waypoints submerged below the water // Underwater fixup: lift submerged waypoints to the surface,
// surface up to the surface itself, unless the destination is // unless the destination is itself underwater.
// itself underwater.
if (Map* map = bot->GetMap()) if (Map* map = bot->GetMap())
{ {
WorldPosition destWp = dest; WorldPosition destWp = dest;
@ -378,10 +382,8 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement"); LastMovement& lastMove = AI_VALUE(LastMovement&, "last movement");
// Inactive-bot teleport — when the path is longer than reactDistance // Skip cosmetic walking for random bots with no nearby player —
// and no real player is around to witness, jump to the path tail and // teleport to the path tail and schedule a cooldown instead.
// schedule a cooldown. Skips cosmetic walking for unobserved random
// bots. Self-bots are excluded so observed sessions always walk.
if (sRandomPlayerbotMgr.IsRandomBot(bot)) if (sRandomPlayerbotMgr.IsRandomBot(bot))
{ {
WorldPosition tail(dest.GetMapId(), last.x, last.y, last.z); WorldPosition tail(dest.GetMapId(), last.x, last.y, last.z);
@ -404,9 +406,7 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
} }
} }
// masterWalking — match the master's walk pace when they're nearby // Match master's walk pace when they're nearby and walking.
// and walking. Lets a follower bot trail at walk speed instead of
// sprinting past. No-op for masterless RPG bots.
ForcedMovement moveMode = FORCED_MOVEMENT_RUN; ForcedMovement moveMode = FORCED_MOVEMENT_RUN;
if (sPlayerbotAIConfig.walkDistance > 0.0f) if (sPlayerbotAIConfig.walkDistance > 0.0f)
{ {
@ -420,8 +420,7 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
} }
} }
// Pre-dispatch state cleanup. Clear emote / stand up / interrupt // Clear emote/sit/cast so the spline can begin cleanly.
// any non-melee cast so the spline can begin without state conflicts.
bot->ClearEmoteState(); bot->ClearEmoteState();
if (!bot->IsStandState()) if (!bot->IsStandState())
bot->SetStandState(UNIT_STAND_STATE_STAND); bot->SetStandState(UNIT_STAND_STATE_STAND);
@ -433,9 +432,7 @@ bool NewRpgBaseAction::DispatchPathPoints(WorldPosition const& dest,
EmitDebugMove("MoveFar", label, last.x, last.y, last.z); EmitDebugMove("MoveFar", label, last.x, last.y, last.z);
// WaitForReach scheduling. // WaitForReach: leave ~10y headroom on long paths.
// waitDist = (totalDist > reactDistance) ? totalDist - 10 : totalDist
// duration = 1000 * (waitDist / speed) + reactDelay, capped at maxWaitForMove
float waitDist = totalDist > sPlayerbotAIConfig.reactDistance float waitDist = totalDist > sPlayerbotAIConfig.reactDistance
? std::max(totalDist - 10.0f, 0.0f) : totalDist; ? std::max(totalDist - 10.0f, 0.0f) : totalDist;
UnitMoveType const speedType = (moveMode == FORCED_MOVEMENT_WALK) ? MOVE_WALK : MOVE_RUN; UnitMoveType const speedType = (moveMode == FORCED_MOVEMENT_WALK) ? MOVE_WALK : MOVE_RUN;
@ -456,9 +453,6 @@ void NewRpgBaseAction::StartTravelPlan(WorldPosition dest)
{ {
TravelPlan& plan = botAI->rpgInfo.travelPlan; TravelPlan& plan = botAI->rpgInfo.travelPlan;
GetTravelPlan(plan, dest); GetTravelPlan(plan, dest);
LOG_DEBUG("playerbots","[New RPG] Bot {} starting travel plan to ({:.0f},{:.0f},{:.0f}) map={}, {} points",
bot->GetName(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), dest.GetMapId(), plan.steps.size());
} }
bool NewRpgBaseAction::UpdateTravelPlan() bool NewRpgBaseAction::UpdateTravelPlan()
@ -490,7 +484,9 @@ bool NewRpgBaseAction::MoveWorldObjectTo(ObjectGuid guid, float distance)
angle = object->GetOrientation() + angle = object->GetOrientation() +
(M_PI * irand(-25, 25) / 100.0); // 45 degrees infront of target (leading it's movement) (M_PI * irand(-25, 25) / 100.0); // 45 degrees infront of target (leading it's movement)
float rnd = rand_norm(); // Bias toward the full radius so the bot stops next to the object,
// not on top of it. Uniform rnd would put dest anywhere in [0, distance].
float rnd = 0.85f + 0.15f * rand_norm();
x += cos(angle) * distance * rnd; x += cos(angle) * distance * rnd;
y += sin(angle) * distance * rnd; y += sin(angle) * distance * rnd;
if (!object->GetMap()->CheckCollisionAndGetValidCoords(object, object->GetPositionX(), object->GetPositionY(), if (!object->GetMap()->CheckCollisionAndGetValidCoords(object, object->GetPositionX(), object->GetPositionY(),
@ -500,11 +496,8 @@ bool NewRpgBaseAction::MoveWorldObjectTo(ObjectGuid guid, float distance)
y = object->GetPositionY(); y = object->GetPositionY();
z = object->GetPositionZ(); z = object->GetPositionZ();
} }
// Delegate to MoveFarTo so every approach gets the chained mmap // Route through MoveFarTo so every approach gets the full probe
// probe + spellDistance shortcut + travel-node fallback instead // + travel-node fallback (and a precise debug label).
// of a single direct MoveTo. The debug-move trace then labels
// the actual mechanism (spline / mmap / nodetravel) rather than
// a generic "MoveWorldObjectTo:spline".
return MoveFarTo(WorldPosition(object->GetMapId(), x, y, z)); return MoveFarTo(WorldPosition(object->GetMapId(), x, y, z));
} }
@ -517,11 +510,7 @@ bool NewRpgBaseAction::MoveRandomNear(float moveStep, MovementPriority priority,
const float x = bot->GetPositionX(); const float x = bot->GetPositionX();
const float y = bot->GetPositionY(); const float y = bot->GetPositionY();
const float z = bot->GetPositionZ(); const float z = bot->GetPositionZ();
// Previously: attempts = 1. A single random sample often landed in // Retry random samples so one bad roll doesn't lock the bot in place.
// water / blocked geometry / unreachable poly, the function returned
// false, and the caller had no fallback — bot stood still. Retry a
// handful of times with a fresh distance each loop so a bad roll
// doesn't lock the bot in place.
for (int attempt = 0; attempt < 8; ++attempt) for (int attempt = 0; attempt < 8; ++attempt)
{ {
float distance = (0.4f + rand_norm() * 0.6f) * moveStep; float distance = (0.4f + rand_norm() * 0.6f) * moveStep;
@ -541,6 +530,13 @@ bool NewRpgBaseAction::MoveRandomNear(float moveStep, MovementPriority priority,
if (map->IsInWater(bot->GetPhaseMask(), dx, dy, dz, bot->GetCollisionHeight())) if (map->IsInWater(bot->GetPhaseMask(), dx, dy, dz, bot->GetCollisionHeight()))
continue; continue;
// Reject samples whose straight-line passes through visual
// obstacles (trees, models) that aren't in the navmesh. The
// smooth-path step can otherwise interpolate a waypoint inside
// a tree, making the bot visibly walk through it.
if (!bot->IsWithinLOS(dx, dy, dz))
continue;
bool moved = MoveTo(bot->GetMapId(), dx, dy, dz, false, false, false, true, priority); bool moved = MoveTo(bot->GetMapId(), dx, dy, dz, false, false, false, true, priority);
if (moved) if (moved)
{ {

View File

@ -226,11 +226,8 @@ TravelNodePath* TravelNode::BuildPath(TravelNode* endNode, Unit* bot, bool postP
bool canPath = endPos->isPathTo(path); // Check if we reached our destination. bool canPath = endPos->isPathTo(path); // Check if we reached our destination.
// Reject "pathfinder cheating" — too-short or too-steep results // Reject too-short or too-steep results — geometry shortcut that
// that mmap accepts but a player can't actually walk. Without this, // mmap returns but a player can't actually walk.
// the segment gets cached + saved to playerbots_travelnode_path
// and dispatched at runtime as straight-line spline through whatever
// mountain/cliff sat between A and B (cmangos parity).
if (canPath && TravelPath::IsPathCheating(path, getPosition()->distance(endNode->getPosition()))) if (canPath && TravelPath::IsPathCheating(path, getPosition()->distance(endNode->getPosition())))
canPath = false; canPath = false;
@ -732,9 +729,9 @@ bool TravelPath::makeShortCut(WorldPosition startPos, float maxDist, Unit* bot)
for (auto& p : fullPath) // cycle over the full path for (auto& p : fullPath) // cycle over the full path
{ {
// Walkability filter (cmangos parity): portals/transports/taxis // Walkability filter: portals/transports/taxis aren't valid
// aren't valid anchor points — picking one as the new start of // anchor points — picking one as the new start of the trimmed
// the trimmed path would leave the bot anchored on a hop. // path would leave the bot anchored on a hop.
if (p.point.GetMapId() == startPos.GetMapId() && p.isWalkable()) if (p.point.GetMapId() == startPos.GetMapId() && p.isWalkable())
{ {
float curDist = p.point.sqDistance(startPos); float curDist = p.point.sqDistance(startPos);
@ -792,9 +789,8 @@ bool TravelPath::makeShortCut(WorldPosition startPos, float maxDist, Unit* bot)
} }
// Pass the bot into getPathTo so PathGenerator picks up its // Pass the bot into getPathTo so PathGenerator picks up its
// collision / swimming / flying flags. cmangos parity — passing // collision/swim/fly state. nullptr defaults to a generic mover
// nullptr here drops to a default mover and can produce a path // which can produce paths the bot can't actually walk.
// the bot itself can't actually walk.
std::vector<WorldPosition> toPath = startPos.getPathTo(beginPos, bot); std::vector<WorldPosition> toPath = startPos.getPathTo(beginPos, bot);
// We can not reach the new begin position. Follow the complete path. // We can not reach the new begin position. Follow the complete path.
@ -1290,10 +1286,8 @@ bool TravelNodeMap::GetFullPath(TravelPlan& plan,
plan.Reset(); plan.Reset();
plan.destination = destination; plan.destination = destination;
// mmap-probe-first. Run a 40-step chained probe; if it gets within // mmap-probe first: if a 40-step probe reaches dest, skip the
// spellDistance of dest, emit it as plan steps and skip the graph // graph entirely — a direct walk beats a node hop.
// entirely (a short walk is always better than a node hop). When
// the probe falls short, fall through to graph routing.
if (botPos.GetMapId() == destination.GetMapId()) if (botPos.GetMapId() == destination.GetMapId())
{ {
std::vector<WorldPosition> probe = destination.getPathFromPath({botPos}, bot, 40); std::vector<WorldPosition> probe = destination.getPathFromPath({botPos}, bot, 40);

View File

@ -13,8 +13,7 @@
// THEORY // THEORY
// //
// Pathfinding in (c)mangos is based on detour recast, an opensource navmesh creation and pathfinding codebase. // Pathfinding uses the detour recast navmesh engine for mob, npc, and bot movement.
// This system is used for mob and npc pathfinding and in this codebase also for bots.
// Because mobs and npc movement is based on following a player or a set path the PathGenerator is limited to 296y. // Because mobs and npc movement is based on following a player or a set path the PathGenerator is limited to 296y.
// This means that when trying to find a path from A to B distances beyond 296y will be a best guess often moving in a // This means that when trying to find a path from A to B distances beyond 296y will be a best guess often moving in a
// straight path. Bots would get stuck moving from Northshire to Stormwind because there is no 296y path that doesn't // straight path. Bots would get stuck moving from Northshire to Stormwind because there is no 296y path that doesn't
@ -493,16 +492,8 @@ public:
bool makeShortCut(WorldPosition startPos, float maxDist, Unit* bot = nullptr); bool makeShortCut(WorldPosition startPos, float maxDist, Unit* bot = nullptr);
// Detect "pathfinder cheating" — paths that PathGenerator accepts // Reject paths the navmesh accepts but a player can't walk:
// but a player can't actually walk: // 2-point shortcut over 5y, or > 10y vertical drop with slope steeper than 2:1.
// * a 2-point path for an endpoint distance > 5y means navmesh
// gave up and returned the straight A->B line.
// * a vertical drop > 10y combined with a slope steeper than
// 2:1 at either start or end means the pathfinder hopped
// through a near-vertical step the navmesh permits but a
// player wouldn't survive.
// cmangos applies the same two checks in TravelNode::buildPath
// before caching a node-to-node segment.
static bool IsPathCheating(std::vector<WorldPosition> const& path, static bool IsPathCheating(std::vector<WorldPosition> const& path,
float endpointDistance); float endpointDistance);