Use journey-stable distance costs for clientless travel routes

This commit is contained in:
Nico committed 2026-11-02 06:26:58 +01:00
1 parent 3c361e435a
commit 2778cf9bdd
19 files changed
+1375 -95

No files matched your search

@@ -6,6 +6,9 @@
#include "ClientlessLuaEngine.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "Config.h"
#include "Random.h"
#include "Log.h"
#include "Player.h"
#include "ClientlessTravelMgr.h"
@@ -317,6 +320,7 @@ bool ClientlessTravelGraphMgr::Reload()
while (pointResult->NextRow());
}
RebuildEdgeDistances();
_loaded = true;
TC_LOG_INFO("server.adventurebot",
@@ -326,6 +330,61 @@ bool ClientlessTravelGraphMgr::Reload()
return !_nodes.empty();
}
ClientlessTravelCost::Profile ClientlessTravelGraphMgr::NewJourneyCosts() const
{
ClientlessTravelCost::Profile base;
for(unsigned mode=0;mode<ClientlessTravelCost::Count;++mode)
base.Factors[mode]=sConfigMgr->GetFloatDefault(
std::string("Clientless.Travel.CostMultiplier.")+ClientlessTravelCost::Name(ClientlessTravelCost::Mode(mode)),1.0f);
return ClientlessTravelCost::Sample(base,urand(1,0xffffffffu),
sConfigMgr->GetFloatDefault("Clientless.Travel.CostVariation",0.20f));
}
void ClientlessTravelGraphMgr::RebuildEdgeDistances()
{
for(auto& outgoing:_edges)for(auto& edge:outgoing.second)
{
auto const& from=_nodes.at(edge.FromNode);auto const& to=_nodes.at(edge.ToNode);
float length=0;
auto segment=[&](uint32 map,float x,float y,float z,uint32 otherMap,float a,float b,float c)
{if(map==otherMap)length+=std::hypot(std::hypot(x-a,y-b),z-c);};
if(edge.Type=="portal" || edge.Type=="portal_use")length=1;
else if(edge.Type=="taxi")
{
if(edge.FromNode.rfind("taxi_",0)==0 && edge.ToNode.rfind("taxi_",0)==0)
{
uint32 path=0,fare=0;
sObjectMgr->GetTaxiPath(uint32(std::strtoul(edge.FromNode.c_str()+5,nullptr,10)),
uint32(std::strtoul(edge.ToNode.c_str()+5,nullptr,10)),path,fare);
if(path<sTaxiPathNodesByPath.size())
{
auto const& nodes=sTaxiPathNodesByPath[path];
for(size_t i=1;i<nodes.size();++i)
segment(nodes[i-1]->ContinentID,nodes[i-1]->Loc.X,nodes[i-1]->Loc.Y,nodes[i-1]->Loc.Z,
nodes[i]->ContinentID,nodes[i]->Loc.X,nodes[i]->Loc.Y,nodes[i]->Loc.Z);
}
}
}
else if(ClientlessTransportMgr::IsTransportEdge(edge.Type))
length=sClientlessTransportMgr->ConnectionDistance(edge.FromNode,edge.ToNode);
else if(auto points=GetEdgePoints(edge.DatabaseId);points && !points->empty())
{
auto const& first=edge.Reverse?points->back():points->front();
auto const& last=edge.Reverse?points->front():points->back();
segment(from.MapId,from.X,from.Y,from.Z,first.MapId,first.X,first.Y,first.Z);
for(size_t i=1;i<points->size();++i)
segment((*points)[i-1].MapId,(*points)[i-1].X,(*points)[i-1].Y,(*points)[i-1].Z,
(*points)[i].MapId,(*points)[i].X,(*points)[i].Y,(*points)[i].Z);
segment(last.MapId,last.X,last.Y,last.Z,to.MapId,to.X,to.Y,to.Z);
}
if(length<=0 && from.MapId==to.MapId)
segment(from.MapId,from.X,from.Y,from.Z,to.MapId,to.X,to.Y,to.Z);
edge.Cost=std::isfinite(length)&&length>0?length:std::numeric_limits<float>::infinity();
TC_LOG_DEBUG("server.adventurebot.navigation","TRAVEL_EDGE_DISTANCE edge=%u type='%s' reverse=%u distance=%.2f",
edge.DatabaseId,edge.Type.c_str(),edge.Reverse?1u:0u,edge.Cost);
}
}
std::string ClientlessTravelGraphMgr::FindNearestStartNode(
Player const* player,
float maxDistance) const
@@ -364,8 +423,11 @@ bool ClientlessTravelGraphMgr::PlanRoute(
float startRadius,
std::vector<ClientlessTravelRouteStep>& route,
std::string& error,
std::unordered_set<uint32> const* blockedEdgeIds)
std::unordered_set<uint32> const* blockedEdgeIds,
ClientlessTravelCost::Profile const* journeyCosts)
{
ClientlessTravelCost::Profile const defaults;
auto const& costs=journeyCosts?*journeyCosts:defaults;
route.clear();
error.clear();
@@ -448,7 +510,7 @@ bool ClientlessTravelGraphMgr::PlanRoute(
blockedEdgeIds->find(edge.DatabaseId) != blockedEdgeIds->end())
continue;
float const candidate = current.Cost + edge.Cost;
float const candidate = current.Cost + costs.Cost(edge.Type,edge.Cost);
if (candidate >= distance[edge.ToNode])
continue;
@@ -575,7 +637,8 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
std::string& error,
std::unordered_set<uint32> const* blockedEdgeIds,
std::unordered_set<std::string> const* blockedBridgeKeys,
ClientlessTravelLocationGoal const* locationGoal)
ClientlessTravelLocationGoal const* locationGoal,
ClientlessTravelCost::Profile const* journeyCosts)
{
struct Trace
{
@@ -639,6 +702,11 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (!sAdventureAreaMgr->AllowsPosition(player,locationGoal->MapId,goal))
{ error="destination location denied by area catalog"; return false; }
}
ClientlessTravelCost::Profile const defaults;
auto const& costs=journeyCosts?*journeyCosts:defaults;
auto groundCost=[&](float length){return costs.Cost(ClientlessTravelCost::Ground,length);};
auto flightDistanceCost=[&](float length){return costs.Cost(ClientlessTravelCost::Flight,length);};
auto edgeCost=[&](ClientlessTravelEdge const& edge){return costs.Cost(edge.Type,edge.Cost);};
bool const flightEnabled = sClientlessFlightMgr->Enabled(player);
constexpr std::uint64_t MaxFlightEstimatesPerPlan = 16;
// Preserve part of the global budget for nodes reached later in the
@@ -666,12 +734,10 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
return std::numeric_limits<float>::infinity();
auto begin=std::chrono::steady_clock::now();++trace.FlightCalls;
float result=sClientlessFlightMgr->Estimate(player,map,a,b,access);
if(access && std::isfinite(result))
if(std::isfinite(result))
{
float distance=a.GetExactDist(&b);
if(distance<20)result=std::numeric_limits<float>::infinity();
else result=(sClientlessFlightMgr->Preferred(player,map,a) || sClientlessFlightMgr->Preferred(player,map,b))?
40+distance*0.4f:180+distance*1.5f;
float length=a.GetExactDist(&b);
result=access && length<20?std::numeric_limits<float>::infinity():flightDistanceCost(length);
}
trace.FlightUs+=std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()-begin).count();
flightEstimates.emplace(estimateKey, result);
@@ -687,45 +753,38 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
bridgeRadius = MaxVirtualNodeBridge;
bridgeRadius = std::min(bridgeRadius, MaxVirtualNodeBridge);
// The overwhelmingly common free-flight case is a same-map Location. Do
// not construct a macro graph first: Estimate already enforces licenses,
// mount flags, area policy, distance and the complete catalog segment.
// Native departure/landing validation still happens in FlightMgr::Start.
if (locationGoal && locationGoal->MapId == player->GetMapId())
float directFlightCost=std::numeric_limits<float>::infinity();
auto directFlightRoute=[&]()
{
ClientlessTravelNode departureNode;
departureNode.Key = "flight_departure";
departureNode.MapId = player->GetMapId();
departureNode.X = player->GetPositionX();
departureNode.Y = player->GetPositionY();
departureNode.Z = player->GetPositionZ();
float const directFlight = flightCost(departureNode, locationGoal->MapId,
locationGoal->X, locationGoal->Y, locationGoal->Z);
if (std::isfinite(directFlight))
{
ClientlessTravelRouteStep departure;
departure.NodeKey = "flight_departure";
departure.NodeType = "ground";
departure.EdgeType = "start";
departure.MapId = player->GetMapId();
departure.X = player->GetPositionX();
departure.Y = player->GetPositionY();
departure.Z = player->GetPositionZ();
route.push_back(std::move(departure));
ClientlessTravelRouteStep departure;
departure.NodeKey = "flight_departure";
departure.NodeType = "ground";
departure.EdgeType = "start";
departure.MapId = player->GetMapId();
departure.X = player->GetPositionX();
departure.Y = player->GetPositionY();
departure.Z = player->GetPositionZ();
route.push_back(std::move(departure));
ClientlessTravelRouteStep flight;
flight.NodeKey = "flight_location";
flight.NodeType = "location";
flight.EdgeType = "free_flight";
flight.MapId = locationGoal->MapId;
flight.X = locationGoal->X;
flight.Y = locationGoal->Y;
flight.Z = locationGoal->Z;
route.push_back(std::move(flight));
complete = true;
reachedNode = "flight_location";
return true;
}
ClientlessTravelRouteStep flight;
flight.NodeKey = "flight_location";
flight.NodeType = "location";
flight.EdgeType = "free_flight";
flight.MapId = locationGoal->MapId;
flight.X = locationGoal->X;
flight.Y = locationGoal->Y;
flight.Z = locationGoal->Z;
route.push_back(std::move(flight));
complete = true;
reachedNode = "flight_location";
return true;
};
if(locationGoal && locationGoal->MapId==player->GetMapId())
{
ClientlessTravelNode departure;
departure.Key="flight_departure";departure.MapId=player->GetMapId();
departure.X=player->GetPositionX();departure.Y=player->GetPositionY();departure.Z=player->GetPositionZ();
directFlightCost=flightCost(departure,locationGoal->MapId,locationGoal->X,locationGoal->Y,locationGoal->Z);
}
struct State
@@ -807,6 +866,10 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
std::unordered_set<std::string> flightRoots;
uint32 startCount = 0;
// Unreachable nearby pavement/indoor anchors must not consume the entire
// flight budget before graph search can consider flight-only connections.
std::uint64_t startFlightProbes = 0;
constexpr std::uint64_t MaxStartFlightProbes = 4;
for (auto const& pair : _nodes)
{
ClientlessTravelNode const& node = pair.second;
@@ -820,7 +883,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
float const localDistance = std::sqrt(dx * dx + dy * dy + dz * dz);
if (localDistance > startRadius)
continue;
float startCost = localDistance;
float startCost = groundCost(localDistance);
// VCORE_VIRTUAL_EDGE_V11_PORTAL_APPROACH: never seed an unreachable node.
if (blockedBridgeKeys && blockedBridgeKeys->count("start:" + node.Key))
@@ -842,9 +905,12 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
// the recovery/re-entry mode for nodes that local navigation cannot
// reach, not a shortcut racing every nearby pavement node.
float air = std::numeric_limits<float>::infinity();
if (!reachable && !(blockedBridgeKeys &&
if (!reachable && startFlightProbes < MaxStartFlightProbes && !(blockedBridgeKeys &&
blockedBridgeKeys->count("flight:flight_departure->"+node.Key)))
{
++startFlightProbes;
air=flightCost(departure,node.MapId,node.X,node.Y,node.Z,true);
}
if(std::isfinite(air) && !reachable)
{flightRoots.insert(node.Key);startCost=air;}
else
@@ -870,7 +936,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
node.Key.c_str(), localDistance, entryNav.Reason.c_str());
continue;
}
startCost = entryNav.PathLength;
startCost = groundCost(entryNav.PathLength);
if (!reachable)
startCost += 100000.0f; // Tier 2 only: deferred roots rank after reachable roots
}
@@ -988,9 +1054,9 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
continue;
uint32 const startIndex = candidate.Edge.Reverse
? candidate.Count - 1 - candidate.Index : candidate.Index;
float newCost = (alreadyThere ? 0.0f : nav.PathLength) +
float newCost = (alreadyThere ? 0.0f : groundCost(nav.PathLength)) +
roadSectionCost(candidate.Edge.DatabaseId, candidate.Edge.Reverse,
startIndex, candidate.Count - 1, candidate.Edge.Cost);
startIndex, candidate.Count - 1, edgeCost(candidate.Edge));
auto old = distance.find(key);
if (old != distance.end() && old->second <= newCost)
continue;
@@ -1000,7 +1066,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
previous.erase(key);
virtualRoots[key] = { candidate.Edge.DatabaseId, candidate.Index,
candidate.Edge.Reverse, candidate.Point,
alreadyThere ? 0.0f : nav.PathLength };
alreadyThere ? 0.0f : groundCost(nav.PathLength) };
open.push({ newCost, state });
++accepted;
}
@@ -1011,10 +1077,92 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (!startCount && !accepted)
{
if(std::isfinite(directFlightCost))return directFlightRoute();
error = "no reachable travel node or recorded ground edge near current position";
return false;
}
// Reserve a bounded part of the flight budget for complete local portal
// connections before speculative road exits spend it. Nearby ground roots
// are entry options, not a reason to overlook flight-only portal islands.
if (flightEnabled && !locationGoal)
{
struct PortalConnection
{
float Rank;
std::string Root;
ClientlessTravelEdge Edge;
};
std::vector<PortalConnection> connections;
auto const& goal = destinationItr->second;
for (auto const& outgoing : _edges)
for (auto const& edge : outgoing.second)
{
if (edge.Type != "portal" && edge.Type != "portal_use") continue;
if (!RescueEdgeAllowed(edge) || !sAdventureAreaMgr->AllowsEdge(player,edge) ||
(blockedEdgeIds && edge.DatabaseId && blockedEdgeIds->count(edge.DatabaseId))) continue;
auto const& source = _nodes.at(edge.FromNode);
auto const& target = _nodes.at(edge.ToNode);
if (target.MapId != goal.MapId) continue;
float dx=goal.X-target.X,dy=goal.Y-target.Y,dz=goal.Z-target.Z;
float finish = flightDistanceCost(std::sqrt(dx*dx+dy*dy+dz*dz));
for (auto const& root : states)
{
auto const& origin = _nodes.at(root.second.Node);
if (origin.MapId != source.MapId || origin.Key == source.Key) continue;
auto originEdges = _edges.find(origin.Key);
if (originEdges != _edges.end() && std::any_of(originEdges->second.begin(),originEdges->second.end(),
[](ClientlessTravelEdge const& e){return e.Type=="portal" || e.Type=="portal_use";})) continue;
dx=source.X-origin.X;dy=source.Y-origin.Y;dz=source.Z-origin.Z;
float direct=std::sqrt(dx*dx+dy*dy+dz*dz);
if (direct > 1500.0f) continue;
connections.push_back({distance.at(root.first)+flightDistanceCost(direct)+edgeCost(edge)+finish,root.first,edge});
}
}
std::sort(connections.begin(),connections.end(),[](PortalConnection const& a,PortalConnection const& b)
{
if(a.Rank!=b.Rank)return a.Rank<b.Rank;
if(a.Edge.DatabaseId!=b.Edge.DatabaseId)return a.Edge.DatabaseId<b.Edge.DatabaseId;
return a.Root<b.Root;
});
auto const callsBefore = trace.FlightCalls;
unsigned attempts=0;
for (auto const& candidate : connections)
{
if (++attempts>8 || trace.FlightCalls-callsBefore>=6) break;
auto const edge=candidate.Edge;
auto const& origin=_nodes.at(states.at(candidate.Root).Node);
auto const& source=_nodes.at(edge.FromNode);
auto const& target=_nodes.at(edge.ToNode);
if (blockedBridgeKeys && (blockedBridgeKeys->count("flight:"+origin.Key+"->"+source.Key) ||
blockedBridgeKeys->count("flight:"+target.Key+"->"+goal.Key))) continue;
float entry=flightCost(origin,source.MapId,source.X,source.Y,source.Z,true);
if (!std::isfinite(entry)) continue;
float finish=target.Key==goal.Key?0.0f:flightCost(target,goal.MapId,goal.X,goal.Y,goal.Z,true);
if (!std::isfinite(finish)) continue;
auto relax=[&](std::string const& from,ClientlessTravelNode const& to,
std::string const& type,uint32 id,bool reverse,float cost)
{
State next{to.Key,false};auto key=stateKey(next);
float score=distance.at(from)+cost;
auto old=distance.find(key);
if(old==distance.end() || score<old->second)
{
distance[key]=score;states[key]=next;persistentHops[key]=persistentHops[from]+1;
previous[key]={from,states.at(from).Node,type,id,reverse};
open.push({score,next});
}
return key;
};
auto sourceKey=relax(candidate.Root,source,"free_flight",0,false,entry);
auto targetKey=relax(sourceKey,target,edge.Type,edge.DatabaseId,edge.Reverse,edgeCost(edge));
if(target.Key!=goal.Key)relax(targetKey,goal,"free_flight",0,false,finish);
TC_LOG_INFO("server.adventurebot.navigation",
"PORTAL_FLIGHT_CONNECTION from='%s' source='%s' target='%s' goal='%s' entry=%.1f finish=%.1f",
origin.Key.c_str(),source.Key.c_str(),target.Key.c_str(),goal.Key.c_str(),entry,finish);
}
}
// C8.20: virtual node bridges are equal-cost ground alternatives and
// participate even when stored graph routes also exist.
bool const repairRequired = true;
@@ -1163,13 +1311,13 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
candidate.EdgeId = edge.DatabaseId;
candidate.Reverse = edge.Reverse;
candidate.EndIndex = i;
candidate.RoadCost = edge.Cost * (travelled / totalLength);
candidate.RoadCost = edgeCost(edge) * (travelled / totalLength);
candidate.DistanceSq = dsq;
candidate.Point = point;
bool const groundExitExhausted = blockedBridgeKeys &&
blockedBridgeKeys->count("ground_exit_edge:" + identity);
candidate.LocalCost = locationGoal && !groundExitExhausted && dsq <= locationAccessRadius*locationAccessRadius
? std::sqrt(dsq) : std::numeric_limits<float>::infinity();
? groundCost(std::sqrt(dsq)) : std::numeric_limits<float>::infinity();
// A recorded edge can contain hundreds of samples. Calling
// FlightMgr::Estimate for every sample made the synchronous
@@ -1186,10 +1334,9 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (flightEnabled && !(blockedBridgeKeys && blockedBridgeKeys->count("flight_exit:" + exitKey)))
{
float const direct = std::sqrt(dsq);
// Forty plus 0.4 * distance is the cheapest possible
// free-flight cost. It is an admissible ordering key;
// rejected area segments simply advance to the next item.
rankedFlightExits.push_back({ candidate.RoadCost + 40.0f + direct * 0.4f,
// Use this journey's flight factor for both candidate
// ordering and execution cost, including expensive modes.
rankedFlightExits.push_back({ candidate.RoadCost + flightDistanceCost(direct),
std::move(candidate) });
}
}
@@ -1245,7 +1392,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
uint32 StartIndex = 0;
ClientlessTravelEdgePoint EntryPoint;
} bestExit;
float bestGoalCost = std::numeric_limits<float>::infinity();
float bestGoalCost = directFlightCost;
std::string bestGoalState;
bool bestFinalFlight = false;
// Every permitted node is a potential way back into the persistent graph.
@@ -1261,7 +1408,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (node.MapId != destination.MapId)
return std::numeric_limits<float>::infinity();
float dx = destination.X-node.X, dy = destination.Y-node.Y, dz = destination.Z-node.Z;
return 40.0f + std::sqrt(dx*dx+dy*dy+dz*dz)*0.4f;
return flightDistanceCost(std::sqrt(dx*dx+dy*dy+dz*dz));
};
float best = lowerBoundToGoal(candidate);
auto edges = _edges.find(candidate.Key);
@@ -1275,7 +1422,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
auto next = _nodes.find(edge.ToNode);
if (next == _nodes.end())
continue;
best = std::min(best, edge.Cost + lowerBoundToGoal(next->second));
best = std::min(best, edgeCost(edge) + lowerBoundToGoal(next->second));
}
return best;
};
@@ -1308,7 +1455,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (fromNodeItr != _edges.end())
for (ClientlessTravelEdge const& edge : fromNodeItr->second)
if (edge.DatabaseId == exit.EdgeId && edge.Reverse == exit.Reverse)
fullEdgeCost = edge.Cost;
fullEdgeCost = edgeCost(edge);
if (fullEdgeCost <= 0.0f)
continue;
float const partialCost = roadSectionCost(exit.EdgeId,
@@ -1371,7 +1518,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
std::string const finishKey = "finish:" + candidateNode.Key;
float const finalCost = blockedBridgeKeys && blockedBridgeKeys->count(finishKey)
? std::numeric_limits<float>::infinity() :
std::min(direct<=locationAccessRadius ? direct : std::numeric_limits<float>::infinity(),air);
std::min(direct<=locationAccessRadius ? groundCost(direct) : std::numeric_limits<float>::infinity(),air);
if (current.Cost + finalCost < bestGoalCost)
{
bestGoalCost = current.Cost + finalCost;
@@ -1420,7 +1567,17 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
std::any_of(sourceEdges->second.begin(), sourceEdges->second.end(),
[](ClientlessTravelEdge const& edge)
{ return edge.Type == "portal" || edge.Type == "portal_use"; });
bool const portalArrival = isPortalSource && previous.find(currentKey) != previous.end();
// Root states are physical arrivals too: replanning while standing at
// a portal must not turn its source into an indoor flight departure.
// If the portal failed or is forbidden, retain its recorded escape roads.
bool const portalArrival = isPortalSource &&
std::any_of(sourceEdges->second.begin(), sourceEdges->second.end(),
[&](ClientlessTravelEdge const& edge)
{
return (edge.Type == "portal" || edge.Type == "portal_use") &&
RescueEdgeAllowed(edge) && sAdventureAreaMgr->AllowsEdge(player,edge) &&
!(blockedEdgeIds && edge.DatabaseId && blockedEdgeIds->count(edge.DatabaseId));
});
// Persistent TravelGraph edges always reset the bridge guard.
auto edgeItr = _edges.find(current.Value.Node);
@@ -1438,7 +1595,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
State next{ edge.ToNode, false };
std::string const nextKey = stateKey(next);
float const candidate = current.Cost + edge.Cost;
float const candidate = current.Cost + edgeCost(edge);
auto old = distance.find(nextKey);
if (old != distance.end() && candidate >= old->second)
@@ -1474,7 +1631,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
// Even a preferred legal flight costs at least this much.
// Skip expensive terrain sampling when it cannot improve the
// route already found; this preserves the full graph search.
float lowerBound=40.0f+std::sqrt(dx*dx+dy*dy+dz*dz)*0.4f;
float lowerBound=flightDistanceCost(std::sqrt(dx*dx+dy*dy+dz*dz));
if(old!=distance.end() && old->second<=current.Cost+lowerBound)continue;
if ((!RescueNodeAllowed(target) || !sAdventureAreaMgr->AllowsNode(player,target))) continue;
if (blockedBridgeKeys && blockedBridgeKeys->count("flight:"+origin.Key+"->"+target.Key)) continue;
@@ -1637,9 +1794,9 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
if (exit.EdgeId != entry.Edge->DatabaseId ||
exit.Reverse != entry.Edge->Reverse || exit.EndIndex <= entryIndex)
continue;
float const score = current.Cost + probe.PathLength + exit.LocalCost +
float const score = current.Cost + groundCost(probe.PathLength) + exit.LocalCost +
roadSectionCost(exit.EdgeId, exit.Reverse, entryIndex,
exit.EndIndex, entry.Edge->Cost);
exit.EndIndex, edgeCost(*entry.Edge));
if (score >= bestGoalCost)
continue;
bestGoalCost = score;
@@ -1651,9 +1808,9 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
std::string const nextKey = stateKey(next);
uint32 const begin = entry.Edge->Reverse
? entry.PointCount - 1 - entry.Index : entry.Index;
float const cost = current.Cost + probe.PathLength +
float const cost = current.Cost + groundCost(probe.PathLength) +
roadSectionCost(entry.Edge->DatabaseId, entry.Edge->Reverse,
begin, entry.PointCount - 1, entry.Edge->Cost);
begin, entry.PointCount - 1, edgeCost(*entry.Edge));
auto old = distance.find(nextKey);
if (old != distance.end() && cost >= old->second)
continue;
@@ -1767,7 +1924,7 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
// C8.20: dynamic node-to-node MMAP bridges are ordinary local
// ground connections, not penalized fallback routes.
float const candidate = current.Cost + measuredLength;
float const candidate = current.Cost + groundCost(measuredLength);
auto old = distance.find(nextKey);
if (old != distance.end() && candidate >= old->second)
continue;
@@ -1782,6 +1939,8 @@ bool ClientlessTravelGraphMgr::PlanAdaptiveRoute(
}
}
if(bestGoalState.empty() && std::isfinite(directFlightCost))return directFlightRoute();
if ((locationGoal || flightEnabled) && bestExit.Active && bestExit.RootPartial &&
!bestGoalState.empty())
previous.erase(bestGoalState);
@@ -2132,8 +2291,11 @@ bool ClientlessTravelGraphMgr::PlanRouteToPosition(
std::vector<ClientlessTravelRouteStep>& route,
std::string& anchorNode,
std::string& error,
std::unordered_set<uint32> const* blockedEdgeIds)
std::unordered_set<uint32> const* blockedEdgeIds,
ClientlessTravelCost::Profile const* journeyCosts)
{
ClientlessTravelCost::Profile const defaults;
auto const& costs=journeyCosts?*journeyCosts:defaults;
route.clear();
anchorNode.clear();
error.clear();
@@ -2202,8 +2364,8 @@ bool ClientlessTravelGraphMgr::PlanRouteToPosition(
if (localStartDistance > startRadius)
continue;
distance[node.Key] = localStartDistance;
open.push({ localStartDistance, node.Key });
distance[node.Key] = costs.Cost(ClientlessTravelCost::Ground,localStartDistance);
open.push({ distance[node.Key], node.Key });
++startCandidateCount;
}
@@ -2233,7 +2395,7 @@ bool ClientlessTravelGraphMgr::PlanRouteToPosition(
blockedEdgeIds->find(edge.DatabaseId) != blockedEdgeIds->end())
continue;
float const candidate = current.Cost + edge.Cost;
float const candidate = current.Cost + costs.Cost(edge.Type,edge.Cost);
if (candidate >= distance[edge.ToNode])
continue;