mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
feat(Core/Travel): Travel-node graph routing for long-distance pathing
This commit is contained in:
parent
75493b5f89
commit
c7175d67c2
@ -343,10 +343,6 @@ AiPlayerbot.MaxWaitForMove = 5000
|
|||||||
# 2 - MoveSplinePath disabled everywhere
|
# 2 - MoveSplinePath disabled everywhere
|
||||||
AiPlayerbot.DisableMoveSplinePath = 0
|
AiPlayerbot.DisableMoveSplinePath = 0
|
||||||
|
|
||||||
# Max search time for movement (higher for better movement on slopes)
|
|
||||||
# Default: 3
|
|
||||||
AiPlayerbot.MaxMovementSearchTime = 3
|
|
||||||
|
|
||||||
# Action expiration time
|
# Action expiration time
|
||||||
AiPlayerbot.ExpireActionTime = 5000
|
AiPlayerbot.ExpireActionTime = 5000
|
||||||
|
|
||||||
@ -1065,6 +1061,12 @@ AiPlayerbot.RestrictedHealerDPSMaps = "33,34,36,43,47,48,70,90,109,129,209,229,2
|
|||||||
# Default: 1 (enabled)
|
# Default: 1 (enabled)
|
||||||
AiPlayerbot.EnableNewRpgStrategy = 1
|
AiPlayerbot.EnableNewRpgStrategy = 1
|
||||||
|
|
||||||
|
# Use pre-computed travel node paths for long-distance movement (>300 yards).
|
||||||
|
# When enabled, bots use the travel node graph (A*, flight paths, transports)
|
||||||
|
# instead of repeated mmap hops. Experimental.
|
||||||
|
# Default: 0 (disabled)
|
||||||
|
AiPlayerbot.EnableTravelNodes = 0
|
||||||
|
|
||||||
# Control probability weights for RPG status of bots. Takes effect only when the status meets its premise.
|
# Control probability weights for RPG status of bots. Takes effect only when the status meets its premise.
|
||||||
# Sum of weights need not be 100. Set to 0 to disable the status.
|
# Sum of weights need not be 100. Set to 0 to disable the status.
|
||||||
#
|
#
|
||||||
|
|||||||
@ -19,83 +19,8 @@
|
|||||||
#include "Transport.h"
|
#include "Transport.h"
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
|
||||||
namespace
|
// Transport helpers (GetTransportForPosTolerant, FindBoardingPointOnTransport,
|
||||||
{
|
// BoardTransport) are now on MovementAction — inherited by FollowAction.
|
||||||
Transport* GetTransportForPosTolerant(Map* map, WorldObject* ref, uint32 phaseMask, float x, float y, float z)
|
|
||||||
{
|
|
||||||
if (!map || !ref)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
std::array<float, 4> const probes = { z, z + 0.5f, z + 1.5f, z - 0.5f };
|
|
||||||
for (float const pz : probes)
|
|
||||||
{
|
|
||||||
if (Transport* t = map->GetTransportForPos(phaseMask, x, y, pz, ref))
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempts to find a point on the leader's transport that is closer to the bot,
|
|
||||||
// by probing along the segment from master -> bot and returning the last point
|
|
||||||
// that is still detected as being on the expected transport.
|
|
||||||
bool FindBoardingPointOnTransport(Map* map, Transport* expectedTransport, WorldObject* ref,
|
|
||||||
float masterX, float masterY, float masterZ,
|
|
||||||
float botX, float botY, float botZ,
|
|
||||||
float& outX, float& outY, float& outZ)
|
|
||||||
{
|
|
||||||
if (!map || !expectedTransport || !ref)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32 const phaseMask = ref->GetPhaseMask();
|
|
||||||
|
|
||||||
// Ensure master is actually detected on that transport (tolerant).
|
|
||||||
if (GetTransportForPosTolerant(map, ref, phaseMask, masterX, masterY, masterZ) != expectedTransport)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// The raycast in GetTransportForPos starts at (z + 2). Probe with a safe Z.
|
|
||||||
float const probeZ = std::max(masterZ, botZ);
|
|
||||||
|
|
||||||
// Adaptive step count: small platforms need tighter sampling.
|
|
||||||
float const dx2 = botX - masterX;
|
|
||||||
float const dy2 = botY - masterY;
|
|
||||||
float const dist2d = std::sqrt(dx2 * dx2 + dy2 * dy2);
|
|
||||||
int32 const steps = std::clamp(static_cast<int32>(dist2d / 0.75f), 10, 28);
|
|
||||||
|
|
||||||
float const dx = (botX - masterX) / static_cast<float>(steps);
|
|
||||||
float const dy = (botY - masterY) / static_cast<float>(steps);
|
|
||||||
|
|
||||||
// Master must actually be on the expected transport for this to work.
|
|
||||||
if (map->GetTransportForPos(ref->GetPhaseMask(), masterX, masterY, probeZ, ref) != expectedTransport)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
float lastX = masterX;
|
|
||||||
float lastY = masterY;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
for (int32 i = 1; i <= steps; ++i)
|
|
||||||
{
|
|
||||||
float const px = masterX + dx * i;
|
|
||||||
float const py = masterY + dy * i;
|
|
||||||
|
|
||||||
Transport* const t = GetTransportForPosTolerant(map, ref, phaseMask, px, py, probeZ);
|
|
||||||
if (t != expectedTransport)
|
|
||||||
break;
|
|
||||||
|
|
||||||
lastX = px;
|
|
||||||
lastY = py;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
outX = lastX;
|
|
||||||
outY = lastY;
|
|
||||||
outZ = masterZ; // keep deck-level Z to encourage stepping onto the platform/boat
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FollowAction::Execute(Event /*event*/)
|
bool FollowAction::Execute(Event /*event*/)
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
#include "LastMovementValue.h"
|
#include "LastMovementValue.h"
|
||||||
|
#include "PathGenerator.h"
|
||||||
#include "PlayerbotAIConfig.h"
|
#include "PlayerbotAIConfig.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
@ -22,12 +23,33 @@ class Position;
|
|||||||
#define ANGLE_90_DEG M_PI_2
|
#define ANGLE_90_DEG M_PI_2
|
||||||
#define ANGLE_120_DEG (2.f * static_cast<float>(M_PI) / 3.f)
|
#define ANGLE_120_DEG (2.f * static_cast<float>(M_PI) / 3.f)
|
||||||
|
|
||||||
|
// Default acceptable path types for GeneratePath
|
||||||
|
constexpr uint32 DEFAULT_PATH_ACCEPT_MASK = PATHFIND_NORMAL | PATHFIND_INCOMPLETE;
|
||||||
|
constexpr uint32 RELAXED_PATH_ACCEPT_MASK = PATHFIND_NORMAL | PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY;
|
||||||
|
|
||||||
|
struct PathResult
|
||||||
|
{
|
||||||
|
Movement::PointsArray points;
|
||||||
|
G3D::Vector3 actualEnd;
|
||||||
|
G3D::Vector3 end;
|
||||||
|
PathType pathType;
|
||||||
|
bool reachable;
|
||||||
|
};
|
||||||
|
|
||||||
class MovementAction : public Action
|
class MovementAction : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MovementAction(PlayerbotAI* botAI, std::string const name);
|
MovementAction(PlayerbotAI* botAI, std::string const name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Emit a one-line trace describing the imminent movement. No-op
|
||||||
|
// unless the bot has the "debug move" non-combat strategy.
|
||||||
|
// Subclasses (e.g. NewRpgBaseAction) may override to append richer
|
||||||
|
// context such as RPG status and target name. Optional `extra`
|
||||||
|
// is appended verbatim (use it to attach hop labels like
|
||||||
|
// "node:Stormwind innkeeper" or fallback reasons).
|
||||||
|
virtual void EmitDebugMove(char const* method, char const* generator, float x, float y, float z, char const* extra = nullptr);
|
||||||
|
|
||||||
bool JumpTo(uint32 mapId, float x, float y, float z, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
|
bool JumpTo(uint32 mapId, float x, float y, float z, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
|
||||||
bool MoveNear(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig.contactDistance,
|
bool MoveNear(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig.contactDistance,
|
||||||
MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
|
MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
|
||||||
@ -66,6 +88,31 @@ protected:
|
|||||||
bool FleePosition(Position pos, float radius, uint32 minInterval = 1000);
|
bool FleePosition(Position pos, float radius, uint32 minInterval = 1000);
|
||||||
bool CheckLastFlee(float curAngle, std::list<FleeInfo>& infoList);
|
bool CheckLastFlee(float curAngle, std::list<FleeInfo>& infoList);
|
||||||
|
|
||||||
|
PathResult GeneratePath(float x, float y, float z, uint32 acceptMask = DEFAULT_PATH_ACCEPT_MASK, bool forceDestination = false);
|
||||||
|
|
||||||
|
bool GetTravelPlan(TravelPlan& plan, WorldPosition destination);
|
||||||
|
bool ExecuteTravelPlan(TravelPlan& state);
|
||||||
|
|
||||||
|
// Transport boarding helpers (shared by FollowAction and travel plan)
|
||||||
|
static Transport* GetTransportForPosTolerant(Map* map, WorldObject* ref,
|
||||||
|
uint32 phaseMask, float x, float y, float z);
|
||||||
|
static bool FindBoardingPointOnTransport(Map* map, Transport* transport,
|
||||||
|
WorldObject* ref, float refX, float refY, float refZ,
|
||||||
|
float botX, float botY, float botZ,
|
||||||
|
float& outX, float& outY, float& outZ);
|
||||||
|
bool BoardTransport(Transport* transport);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool LaunchWalkSpline(TravelPlan& state);
|
||||||
|
bool CheckSplineProgress(TravelPlan& state);
|
||||||
|
bool MoveToSpline(TravelPlan& state, WorldPosition target);
|
||||||
|
// Per-segment mmap refinement of a travel-node-graph walk batch.
|
||||||
|
// The graph stores offline-baked coords whose straight-line
|
||||||
|
// interpolation may pass through geometry the bot can't actually
|
||||||
|
// traverse. Returns false if any segment is unwalkable per the
|
||||||
|
// live navmesh, in which case the caller should abort the plan.
|
||||||
|
bool RefineWalkPoints(std::vector<G3D::Vector3>& walkPoints);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct CheckAngle
|
struct CheckAngle
|
||||||
{
|
{
|
||||||
@ -74,10 +121,6 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool
|
|
||||||
// normal_only = false, float step = 8.0f);
|
|
||||||
const Movement::PointsArray SearchForBestPath(float x, float y, float z, float& modified_z, int maxSearchCount = 5,
|
|
||||||
bool normal_only = false, float step = 8.0f);
|
|
||||||
bool wasMovementRestricted = false;
|
bool wasMovementRestricted = false;
|
||||||
void DoMovePoint(Unit* unit, float x, float y, float z, bool generatePath, bool backwards);
|
void DoMovePoint(Unit* unit, float x, float y, float z, bool generatePath, bool backwards);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -767,6 +767,21 @@ void PlayerbotAI::HandleCommand(uint32 type, const std::string& text, Player& fr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerbotAI::TeleportTo(WorldLocation loc, bool resetAI)
|
||||||
|
{
|
||||||
|
if (!bot || bot->IsBeingTeleported() || !bot->IsInWorld())
|
||||||
|
return;
|
||||||
|
|
||||||
|
bot->GetMotionMaster()->Clear();
|
||||||
|
if (resetAI)
|
||||||
|
Reset(true);
|
||||||
|
else
|
||||||
|
InterruptSpell();
|
||||||
|
bot->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TELEPORTED | AURA_INTERRUPT_FLAG_CHANGE_MAP);
|
||||||
|
bot->TeleportTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), 0);
|
||||||
|
bot->SendMovementFlagUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerbotAI::HandleTeleportAck()
|
void PlayerbotAI::HandleTeleportAck()
|
||||||
{
|
{
|
||||||
if (!bot || !bot->GetSession())
|
if (!bot || !bot->GetSession())
|
||||||
@ -809,7 +824,7 @@ void PlayerbotAI::HandleTeleportAck()
|
|||||||
bot->StopMoving();
|
bot->StopMoving();
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulate far teleport latency (cmangos-style)
|
// simulate far teleport latency
|
||||||
SetNextCheckDelay(urand(2000, 5000));
|
SetNextCheckDelay(urand(2000, 5000));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -396,6 +396,7 @@ public:
|
|||||||
void HandleMasterIncomingPacket(WorldPacket const& packet);
|
void HandleMasterIncomingPacket(WorldPacket const& packet);
|
||||||
void HandleMasterOutgoingPacket(WorldPacket const& packet);
|
void HandleMasterOutgoingPacket(WorldPacket const& packet);
|
||||||
void HandleTeleportAck();
|
void HandleTeleportAck();
|
||||||
|
void TeleportTo(WorldLocation loc, bool resetAI = false);
|
||||||
void ChangeEngine(BotState type);
|
void ChangeEngine(BotState type);
|
||||||
void ChangeEngineOnCombat();
|
void ChangeEngineOnCombat();
|
||||||
void ChangeEngineOnNonCombat();
|
void ChangeEngineOnNonCombat();
|
||||||
|
|||||||
@ -1697,14 +1697,7 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector<WorldLocation>&
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bot->GetMotionMaster()->Clear();
|
botAI->TeleportTo(WorldLocation(loc.GetMapId(), x, y, z, 0), true);
|
||||||
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
|
|
||||||
if (botAI)
|
|
||||||
botAI->Reset(true);
|
|
||||||
bot->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TELEPORTED | AURA_INTERRUPT_FLAG_CHANGE_MAP);
|
|
||||||
bot->TeleportTo(loc.GetMapId(), x, y, z, 0);
|
|
||||||
bot->SendMovementFlagUpdate();
|
|
||||||
|
|
||||||
if (pmo)
|
if (pmo)
|
||||||
pmo->finish();
|
pmo->finish();
|
||||||
|
|
||||||
|
|||||||
@ -681,93 +681,6 @@ std::vector<WorldPosition> WorldPosition::frommGridCoord(mGridCoord GridCoord)
|
|||||||
return retVec;
|
return retVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cleanup — make this actually work.
|
|
||||||
void WorldPosition::loadMapAndVMap(uint32 mapId, uint8 x, uint8 y)
|
|
||||||
{
|
|
||||||
std::string const fileName = "load_map_grid.csv";
|
|
||||||
/*
|
|
||||||
if (isOverworld() && false || false)
|
|
||||||
{
|
|
||||||
if (!MMAP::MMapFactory::createOrGetMMapMgr()->loadMap(mapId, x, y))
|
|
||||||
if (sPlayerbotAIConfig.hasLog(fileName))
|
|
||||||
{
|
|
||||||
std::ostringstream out;
|
|
||||||
out << sPlayerbotAIConfig.GetTimestampStr();
|
|
||||||
out << "+00,\"mmap\", " << x << "," << y << "," << (TravelMgr::instance().isBadMmap(mapId, x, y) ? "0" : "1")
|
|
||||||
<< ",";
|
|
||||||
printWKT(fromGridCoord(GridCoord(x, y)), out, 1, true);
|
|
||||||
sPlayerbotAIConfig.log(fileName, out.str().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// This needs to be disabled or maps will not load.
|
|
||||||
// Needs more testing to check for impact on movement.
|
|
||||||
if (false)
|
|
||||||
if (!TravelMgr::instance().isBadVmap(mapId, x, y))
|
|
||||||
{
|
|
||||||
// load VMAPs for current map/grid...
|
|
||||||
const MapEntry* i_mapEntry = sMapStore.LookupEntry(mapId);
|
|
||||||
//const char* mapName = i_mapEntry ? i_mapEntry->name[sWorld->GetDefaultDbcLocale()] : "UNNAMEDMAP\x0"; //not used, (usage are commented out below), line marked for removal.
|
|
||||||
|
|
||||||
int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapMgr()->loadMap(
|
|
||||||
(sWorld->GetDataPath() + "vmaps").c_str(), mapId, x, y);
|
|
||||||
switch (vmapLoadResult)
|
|
||||||
{
|
|
||||||
case VMAP::VMAP_LOAD_RESULT_OK:
|
|
||||||
// LOG_ERROR("playerbots", "VMAP loaded name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})",
|
|
||||||
// mapName, mapId, x, y, x, y);
|
|
||||||
break;
|
|
||||||
case VMAP::VMAP_LOAD_RESULT_ERROR:
|
|
||||||
// LOG_ERROR("playerbots", "Could not load VMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{},
|
|
||||||
// y:{})", mapName, mapId, x, y, x, y);
|
|
||||||
TravelMgr::instance().addBadVmap(mapId, x, y);
|
|
||||||
break;
|
|
||||||
case VMAP::VMAP_LOAD_RESULT_IGNORED:
|
|
||||||
TravelMgr::instance().addBadVmap(mapId, x, y);
|
|
||||||
// LOG_INFO("playerbots", "Ignored VMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})",
|
|
||||||
// mapName, mapId, x, y, x, y);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sPlayerbotAIConfig.hasLog(fileName))
|
|
||||||
{
|
|
||||||
std::ostringstream out;
|
|
||||||
out << sPlayerbotAIConfig.GetTimestampStr();
|
|
||||||
out << "+00,\"vmap\", " << x << "," << y << ", " << (TravelMgr::instance().isBadVmap(mapId, x, y) ? "0" : "1")
|
|
||||||
<< ",";
|
|
||||||
printWKT(frommGridCoord(mGridCoord(x, y)), out, 1, true);
|
|
||||||
sPlayerbotAIConfig.log(fileName, out.str().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (!TravelMgr::instance().isBadMmap(mapId, x, y))
|
|
||||||
{
|
|
||||||
// load navmesh
|
|
||||||
Map* map = getMap();
|
|
||||||
if (map && map->GetMapCollisionData().LoadMMapTile(x, y) == MMAP::MMAP_LOAD_RESULT_ERROR)
|
|
||||||
TravelMgr::instance().addBadMmap(mapId, x, y);
|
|
||||||
|
|
||||||
if (sPlayerbotAIConfig.hasLog(fileName))
|
|
||||||
{
|
|
||||||
std::ostringstream out;
|
|
||||||
out << sPlayerbotAIConfig.GetTimestampStr();
|
|
||||||
out << "+00,\"mmap\", " << x << "," << y << "," << (TravelMgr::instance().isBadMmap(mapId, x, y) ? "0" : "1")
|
|
||||||
<< ",";
|
|
||||||
printWKT(fromGridCoord(GridCoord(x, y)), out, 1, true);
|
|
||||||
sPlayerbotAIConfig.log(fileName, out.str().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldPosition::loadMapAndVMaps(WorldPosition secondPos)
|
|
||||||
{
|
|
||||||
for (auto& grid : getmGridCoords(secondPos))
|
|
||||||
{
|
|
||||||
loadMapAndVMap(GetMapId(), grid.first, grid.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<WorldPosition> WorldPosition::fromPointsArray(std::vector<G3D::Vector3> path)
|
std::vector<WorldPosition> WorldPosition::fromPointsArray(std::vector<G3D::Vector3> path)
|
||||||
{
|
{
|
||||||
std::vector<WorldPosition> retVec;
|
std::vector<WorldPosition> retVec;
|
||||||
@ -780,36 +693,69 @@ std::vector<WorldPosition> WorldPosition::fromPointsArray(std::vector<G3D::Vecto
|
|||||||
// A single pathfinding attempt from one position to another. Returns pathfinding status and path.
|
// A single pathfinding attempt from one position to another. Returns pathfinding status and path.
|
||||||
std::vector<WorldPosition> WorldPosition::getPathStepFrom(WorldPosition startPos, Unit* bot)
|
std::vector<WorldPosition> WorldPosition::getPathStepFrom(WorldPosition startPos, Unit* bot)
|
||||||
{
|
{
|
||||||
if (!bot)
|
Unit* pathUnit = bot;
|
||||||
return {};
|
Creature* tempCreature = nullptr;
|
||||||
|
|
||||||
// Load mmaps and vmaps between the two points.
|
if (!pathUnit)
|
||||||
loadMapAndVMaps(startPos);
|
{
|
||||||
|
// Create a temporary creature for PathGenerator (same entry as DebugAction "show node")
|
||||||
|
Map* map = sMapMgr->FindBaseMap(startPos.GetMapId());
|
||||||
|
if (!map)
|
||||||
|
return {};
|
||||||
|
|
||||||
PathGenerator path(bot);
|
tempCreature = new Creature();
|
||||||
path.CalculatePath(startPos.GetPositionX(), startPos.GetPositionY(), startPos.GetPositionZ());
|
if (!tempCreature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map,
|
||||||
|
PHASEMASK_NORMAL, 1 /*entry*/, 0,
|
||||||
|
startPos.GetPositionX(), startPos.GetPositionY(),
|
||||||
|
startPos.GetPositionZ(), 0))
|
||||||
|
{
|
||||||
|
delete tempCreature;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
pathUnit = tempCreature;
|
||||||
|
|
||||||
|
// Ensure grids are created at both endpoints so mmap tiles are available.
|
||||||
|
// EnsureGridCreated loads terrain + vmaps + mmaps but NOT objects,
|
||||||
|
// which is all PathGenerator needs.
|
||||||
|
map->EnsureGridCreated(Acore::ComputeGridCoord(startPos.GetPositionX(), startPos.GetPositionY()));
|
||||||
|
map->EnsureGridCreated(Acore::ComputeGridCoord(GetPositionX(), GetPositionY()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicit-start overload (PathGenerator.h:67). Without this,
|
||||||
|
// CalculatePath(destX,destY,destZ) defaults to the unit's
|
||||||
|
// current position as start — which means every iteration of
|
||||||
|
// getPathFromPath's "chain" begins from the bot's same real
|
||||||
|
// location and produces the same ~296y partial path. The chain
|
||||||
|
// never advances. With explicit start, each step extends from
|
||||||
|
// the previous step's endpoint, giving the 40-attempt walker
|
||||||
|
// its intended multi-tile reach.
|
||||||
|
PathGenerator path(pathUnit);
|
||||||
|
path.CalculatePath(startPos.GetPositionX(), startPos.GetPositionY(), startPos.GetPositionZ(),
|
||||||
|
GetPositionX(), GetPositionY(), GetPositionZ(), false);
|
||||||
|
|
||||||
Movement::PointsArray points = path.GetPath();
|
Movement::PointsArray points = path.GetPath();
|
||||||
PathType type = path.GetPathType();
|
PathType type = path.GetPathType();
|
||||||
|
|
||||||
if (sPlayerbotAIConfig.hasLog("pathfind_attempt_point.csv"))
|
if (tempCreature)
|
||||||
{
|
delete tempCreature;
|
||||||
std::ostringstream out;
|
|
||||||
out << std::fixed << std::setprecision(1);
|
|
||||||
printWKT({startPos, *this}, out);
|
|
||||||
sPlayerbotAIConfig.log("pathfind_attempt_point.csv", out.str().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sPlayerbotAIConfig.hasLog("pathfind_attempt.csv") && (type == PATHFIND_INCOMPLETE || type == PATHFIND_NORMAL))
|
// PathType is a bitmask. Two things to handle:
|
||||||
{
|
//
|
||||||
std::ostringstream out;
|
// 1. AC's PathGenerator can return INCOMPLETE | FARFROMPOLY_END
|
||||||
out << sPlayerbotAIConfig.GetTimestampStr() << "+00,";
|
// (0x84) etc. — strict `== PATHFIND_INCOMPLETE` would reject
|
||||||
out << std::fixed << std::setprecision(1) << type << ",";
|
// these perfectly usable partial paths. Use bitwise to accept
|
||||||
printWKT(fromPointsArray(points), out, 1);
|
// NORMAL/INCOMPLETE plus auxiliary flags.
|
||||||
sPlayerbotAIConfig.log("pathfind_attempt.csv", out.str().c_str());
|
//
|
||||||
}
|
// 2. AC's PathGenerator at PathGenerator.cpp:177-188 returns
|
||||||
|
// NORMAL | NOT_USING_PATH for player units when start or end
|
||||||
if (type == PATHFIND_INCOMPLETE || type == PATHFIND_NORMAL)
|
// polygon is INVALID_POLYREF (BuildShortcut → 2-point straight
|
||||||
|
// line through whatever's in the way). cmangos by contrast
|
||||||
|
// returns NOPATH for the same case (PathFinder.cpp:437-441).
|
||||||
|
// To match cmangos's intent (never silently dispatch a
|
||||||
|
// geometry-ignoring shortcut), reject any path with the
|
||||||
|
// NOT_USING_PATH bit set.
|
||||||
|
if ((type & (PATHFIND_NORMAL | PATHFIND_INCOMPLETE))
|
||||||
|
&& !(type & PATHFIND_NOT_USING_PATH))
|
||||||
return fromPointsArray(points);
|
return fromPointsArray(points);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@ -1073,6 +1019,14 @@ GuidPosition::GuidPosition(GameObjectData const& goData)
|
|||||||
loadedFromDB = true;
|
loadedFromDB = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TravelDestination::~TravelDestination()
|
||||||
|
{
|
||||||
|
for (WorldPosition* point : points)
|
||||||
|
delete point;
|
||||||
|
|
||||||
|
points.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<WorldPosition*> TravelDestination::getPoints(bool ignoreFull)
|
std::vector<WorldPosition*> TravelDestination::getPoints(bool ignoreFull)
|
||||||
{
|
{
|
||||||
if (ignoreFull)
|
if (ignoreFull)
|
||||||
@ -2379,9 +2333,7 @@ void TravelMgr::LoadQuestTravelTable()
|
|||||||
sPlayerbotAIConfig.openLog("unload_grid.csv", "w");
|
sPlayerbotAIConfig.openLog("unload_grid.csv", "w");
|
||||||
sPlayerbotAIConfig.openLog("unload_obj.csv", "w");
|
sPlayerbotAIConfig.openLog("unload_obj.csv", "w");
|
||||||
|
|
||||||
TravelNodeMap::instance().loadNodeStore();
|
// Node loading/generation is handled by TravelNodeMap::Init() called from TravelMgr::Init().
|
||||||
|
|
||||||
TravelNodeMap::instance().generateAll();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool fullNavPointReload = false;
|
bool fullNavPointReload = false;
|
||||||
@ -2772,7 +2724,7 @@ void TravelMgr::LoadQuestTravelTable()
|
|||||||
//if (preloadUnlinkedPaths && !startNode->hasLinkTo(endNode) && startNode->isUselessLink(endNode))
|
//if (preloadUnlinkedPaths && !startNode->hasLinkTo(endNode) && startNode->isUselessLink(endNode))
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
startNode->buildPath(endNode, nullptr, false);
|
startNode->BuildPath(endNode, nullptr, false);
|
||||||
|
|
||||||
//if (startNode->hasLinkTo(endNode) && !startNode->getPathTo(endNode)->getComplete())
|
//if (startNode->hasLinkTo(endNode) && !startNode->getPathTo(endNode)->getComplete())
|
||||||
//startNode->removeLinkTo(endNode);
|
//startNode->removeLinkTo(endNode);
|
||||||
@ -2896,7 +2848,7 @@ void TravelMgr::LoadQuestTravelTable()
|
|||||||
|
|
||||||
TravelNodePath nodePath = *path.second;
|
TravelNodePath nodePath = *path.second;
|
||||||
|
|
||||||
std::vector<WorldPosition> pPath = nodePath.getPath();
|
std::vector<WorldPosition> pPath = nodePath.GetPath();
|
||||||
std::reverse(pPath.begin(), pPath.end());
|
std::reverse(pPath.begin(), pPath.end());
|
||||||
|
|
||||||
nodePath.setPath(pPath);
|
nodePath.setPath(pPath);
|
||||||
@ -4359,8 +4311,7 @@ void TravelMgr::Init()
|
|||||||
PrepareZone2LevelBracket();
|
PrepareZone2LevelBracket();
|
||||||
PrepareDestinationCache();
|
PrepareDestinationCache();
|
||||||
}
|
}
|
||||||
sTravelNodeMap.InitTaxiGraph();
|
sTravelNodeMap.Init();
|
||||||
LOG_INFO("playerbots", "Playerbots Taxi graph and destination cache built.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelMgr::FlightMasterInfo const* TravelMgr::GetNearestFlightMasterInfo(Player* bot) const
|
TravelMgr::FlightMasterInfo const* TravelMgr::GetNearestFlightMasterInfo(Player* bot) const
|
||||||
@ -4407,7 +4358,7 @@ std::vector<std::vector<uint32>> TravelMgr::GetOptimalFlightDestinations(Player*
|
|||||||
std::vector<std::vector<uint32>> validDestinations;
|
std::vector<std::vector<uint32>> validDestinations;
|
||||||
|
|
||||||
FlightMasterInfo const* nearestFlightMaster = GetNearestFlightMasterInfo(bot);
|
FlightMasterInfo const* nearestFlightMaster = GetNearestFlightMasterInfo(bot);
|
||||||
if (!nearestFlightMaster || bot->GetDistance(nearestFlightMaster->pos) > 500.0f)
|
if (!nearestFlightMaster)
|
||||||
return validDestinations;
|
return validDestinations;
|
||||||
|
|
||||||
uint32 fromNode = nearestFlightMaster->taxiNodeId;
|
uint32 fromNode = nearestFlightMaster->taxiNodeId;
|
||||||
@ -4426,9 +4377,9 @@ std::vector<std::vector<uint32>> TravelMgr::GetOptimalFlightDestinations(Player*
|
|||||||
if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(bot->GetZoneId()))
|
if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(bot->GetZoneId()))
|
||||||
botInCapital = (area->flags & AREA_FLAG_CAPITAL) != 0;
|
botInCapital = (area->flags & AREA_FLAG_CAPITAL) != 0;
|
||||||
|
|
||||||
//Simplify destination delection. Its either target cities (Based on config value) or target world.
|
|
||||||
std::vector<uint32> candidateZones;
|
std::vector<uint32> candidateZones;
|
||||||
if (botLevel >= 10 && !botInCapital && urand(0, 100) < sPlayerbotAIConfig.probTeleToBankers * 100)
|
if (botLevel >= 10 && !botInCapital &&
|
||||||
|
urand(0, 100) < sPlayerbotAIConfig.probTeleToBankers * 100)
|
||||||
{
|
{
|
||||||
TeamId botTeam = bot->GetTeamId();
|
TeamId botTeam = bot->GetTeamId();
|
||||||
for (Capital const& capital : capitals)
|
for (Capital const& capital : capitals)
|
||||||
@ -4555,6 +4506,34 @@ std::vector<WorldLocation> TravelMgr::GetCityLocations(Player* bot)
|
|||||||
return fallbackLocations;
|
return fallbackLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TravelMgr::SelectAuctioneerByMap(Player* bot, NpcLocation& outAuctioneer)
|
||||||
|
{
|
||||||
|
uint16 botMapId = bot->GetMapId();
|
||||||
|
auto const& cache = (bot->GetTeamId() == TEAM_HORDE) ? hordeAuctioneerCache : allianceAuctioneerCache;
|
||||||
|
|
||||||
|
auto mapIt = cache.find(botMapId);
|
||||||
|
if (mapIt == cache.end() || mapIt->second.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Collect all areas on this map that have auctioneers
|
||||||
|
std::vector<uint32> areaIds;
|
||||||
|
areaIds.reserve(mapIt->second.size());
|
||||||
|
for (auto const& [areaId, npcs] : mapIt->second)
|
||||||
|
{
|
||||||
|
if (!npcs.empty())
|
||||||
|
areaIds.push_back(areaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (areaIds.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Pick a random area, then a random auctioneer in that area
|
||||||
|
uint32 selectedArea = areaIds[urand(0, areaIds.size() - 1)];
|
||||||
|
auto const& auctioneers = mapIt->second.at(selectedArea);
|
||||||
|
outAuctioneer = auctioneers[urand(0, auctioneers.size() - 1)];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void TravelMgr::PrepareZone2LevelBracket()
|
void TravelMgr::PrepareZone2LevelBracket()
|
||||||
{
|
{
|
||||||
// Classic WoW - starter zones
|
// Classic WoW - starter zones
|
||||||
@ -4641,6 +4620,7 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
uint32 flightMastersCount = 0;
|
uint32 flightMastersCount = 0;
|
||||||
uint32 innkeepersCount = 0;
|
uint32 innkeepersCount = 0;
|
||||||
uint32 bankerCount = 0;
|
uint32 bankerCount = 0;
|
||||||
|
uint32 auctioneerCount = 0;
|
||||||
|
|
||||||
LOG_INFO("playerbots", "Preparing destination caches for {} levels...", maxLevel);
|
LOG_INFO("playerbots", "Preparing destination caches for {} levels...", maxLevel);
|
||||||
// Temporary map to group creatures by entry and area
|
// Temporary map to group creatures by entry and area
|
||||||
@ -4687,18 +4667,18 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
(creatureTemplate->unit_flags & 4096) == 0 &&
|
(creatureTemplate->unit_flags & 4096) == 0 &&
|
||||||
creatureTemplate->rank == 0)
|
creatureTemplate->rank == 0)
|
||||||
{
|
{
|
||||||
int32 roundX = static_cast<int32>(std::lround(x / 50.0f));
|
uint32 roundX = static_cast<uint32>(std::round(x / 50.0f));
|
||||||
int32 roundY = static_cast<int32>(std::lround(y / 50.0f));
|
uint32 roundY = static_cast<uint32>(std::round(y / 50.0f));
|
||||||
int32 roundZ = static_cast<int32>(std::lround(z / 50.0f));
|
uint32 roundZ = static_cast<uint32>(std::round(z / 50.0f));
|
||||||
tempLocsCache[std::make_tuple(mapId, roundX, roundY, roundZ)].push_back(creatureData);
|
tempLocsCache[std::make_tuple(mapId, roundX, roundY, roundZ)].push_back(creatureData);
|
||||||
tempCreatureCache[templateEntry][areaId].push_back(WorldLocation(mapId, x, y, z));
|
tempCreatureCache[templateEntry][areaId].push_back(WorldLocation(mapId, x, y, z));
|
||||||
}
|
}
|
||||||
// FLIGHT MASTERS
|
// FLIGHT MASTERS
|
||||||
// Entry 29480 is Grimwing (Storm Peaks)
|
// Entry 29480 is Grimwing (Storm Peaks) — has FLIGHTMASTER flag but
|
||||||
// Entry 3838 is Vesprystus in Rut'Theran. Need Travel Node system to resolve this one.
|
// isn't a real usable flight master; skip it.
|
||||||
else if ((creatureTemplate->npcflag & UNIT_NPC_FLAG_FLIGHTMASTER ||
|
else if ((creatureTemplate->npcflag & UNIT_NPC_FLAG_FLIGHTMASTER ||
|
||||||
creatureTemplate->npcflag & UNIT_NPC_FLAG_INNKEEPER) &&
|
creatureTemplate->npcflag & UNIT_NPC_FLAG_INNKEEPER) &&
|
||||||
creatureTemplate->Entry != 3838 && creatureTemplate->Entry != 29480)
|
creatureTemplate->Entry != 29480)
|
||||||
{
|
{
|
||||||
FactionTemplateEntry const* factionEntry = sFactionTemplateStore.LookupEntry(creatureTemplate->faction);
|
FactionTemplateEntry const* factionEntry = sFactionTemplateStore.LookupEntry(creatureTemplate->faction);
|
||||||
bool forHorde = !(factionEntry->hostileMask & 4);
|
bool forHorde = !(factionEntry->hostileMask & 4);
|
||||||
@ -4783,7 +4763,7 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
creatureTemplate->Entry != 30606 && creatureTemplate->Entry != 30608 &&
|
creatureTemplate->Entry != 30606 && creatureTemplate->Entry != 30608 &&
|
||||||
creatureTemplate->Entry != 29282)
|
creatureTemplate->Entry != 29282)
|
||||||
{
|
{
|
||||||
BankerLocation bLoc;
|
NpcLocation bLoc;
|
||||||
bLoc.loc = WorldLocation(mapId, x + cos(orient) * 6.0f, y + sin(orient) * 6.0f, z + 2.0f, orient + M_PI);
|
bLoc.loc = WorldLocation(mapId, x + cos(orient) * 6.0f, y + sin(orient) * 6.0f, z + 2.0f, orient + M_PI);
|
||||||
bLoc.entry = templateEntry;
|
bLoc.entry = templateEntry;
|
||||||
uint32 level = (creatureTemplate->minlevel + creatureTemplate->maxlevel + 1) / 2;
|
uint32 level = (creatureTemplate->minlevel + creatureTemplate->maxlevel + 1) / 2;
|
||||||
@ -4806,6 +4786,31 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
}
|
}
|
||||||
bankerCount++;
|
bankerCount++;
|
||||||
}
|
}
|
||||||
|
// === AUCTIONEERS ===
|
||||||
|
else if (creatureTemplate->npcflag & UNIT_NPC_FLAG_AUCTIONEER)
|
||||||
|
{
|
||||||
|
FactionTemplateEntry const* factionEntry = sFactionTemplateStore.LookupEntry(creatureTemplate->faction);
|
||||||
|
if (!factionEntry)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool forHorde = !(factionEntry->hostileMask & 4);
|
||||||
|
bool forAlliance = !(factionEntry->hostileMask & 2);
|
||||||
|
|
||||||
|
if (!forHorde && !forAlliance)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
NpcLocation aLoc;
|
||||||
|
aLoc.loc = WorldLocation(mapId, x + cos(orient) * 3.0f, y + sin(orient) * 3.0f, z + 0.5f, orient + M_PI);
|
||||||
|
aLoc.entry = templateEntry;
|
||||||
|
|
||||||
|
if (forHorde)
|
||||||
|
hordeAuctioneerCache[mapId][areaId].push_back(aLoc);
|
||||||
|
|
||||||
|
if (forAlliance)
|
||||||
|
allianceAuctioneerCache[mapId][areaId].push_back(aLoc);
|
||||||
|
|
||||||
|
auctioneerCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process temporary caches
|
// Process temporary caches
|
||||||
@ -4815,16 +4820,29 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
{
|
{
|
||||||
CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(creatureDataList[0].id1);
|
CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(creatureDataList[0].id1);
|
||||||
uint32 level = (creatureTemplate->minlevel + creatureTemplate->maxlevel + 1) / 2;
|
uint32 level = (creatureTemplate->minlevel + creatureTemplate->maxlevel + 1) / 2;
|
||||||
|
|
||||||
|
float totalX = 0.0f;
|
||||||
|
float totalY = 0.0f;
|
||||||
|
float totalZ = 0.0f;
|
||||||
|
for (CreatureData const& creatureData : creatureDataList)
|
||||||
|
{
|
||||||
|
totalX += creatureData.posX;
|
||||||
|
totalY += creatureData.posY;
|
||||||
|
totalZ += creatureData.posZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
float avgX = totalX / creatureDataList.size();
|
||||||
|
float avgY = totalY / creatureDataList.size();
|
||||||
|
float avgZ = totalZ / creatureDataList.size();
|
||||||
|
uint32 mapId = std::get<0>(gridTuple);
|
||||||
|
|
||||||
for (int32 l = (int32)level - (int32)sPlayerbotAIConfig.randomBotTeleLowerLevel;
|
for (int32 l = (int32)level - (int32)sPlayerbotAIConfig.randomBotTeleLowerLevel;
|
||||||
l <= (int32)level + (int32)sPlayerbotAIConfig.randomBotTeleHigherLevel; l++)
|
l <= (int32)level + (int32)sPlayerbotAIConfig.randomBotTeleHigherLevel; l++)
|
||||||
{
|
{
|
||||||
if (l < 1 || l > maxLevel)
|
if (l < 1 || l > maxLevel)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
locsPerLevelCache[(uint8)l].push_back(WorldLocation(std::get<0>(gridTuple),
|
locsPerLevelCache[(uint8)l].push_back(WorldLocation(mapId, avgX, avgY, avgZ, 0.0f));
|
||||||
static_cast<float>(std::get<1>(gridTuple)) * 50.0f,
|
|
||||||
static_cast<float>(std::get<2>(gridTuple)) * 50.0f,
|
|
||||||
static_cast<float>(std::get<3>(gridTuple)) * 50.0f));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4870,5 +4888,5 @@ void TravelMgr::PrepareDestinationCache()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_INFO("playerbots", ">> {} flight masters and {} innkeepers and {} banker locations for level collected.", flightMastersCount, innkeepersCount, bankerCount);
|
LOG_INFO("playerbots", ">> {} flight masters, {} innkeepers, {} bankers, {} auctioneers collected.", flightMastersCount, innkeepersCount, bankerCount, auctioneerCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#define _PLAYERBOT_TRAVELMGR_H
|
#define _PLAYERBOT_TRAVELMGR_H
|
||||||
|
|
||||||
#include <boost/functional/hash.hpp>
|
#include <boost/functional/hash.hpp>
|
||||||
|
#include <cmath>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@ -268,12 +269,6 @@ public:
|
|||||||
std::vector<mGridCoord> getmGridCoords(WorldPosition secondPos);
|
std::vector<mGridCoord> getmGridCoords(WorldPosition secondPos);
|
||||||
std::vector<WorldPosition> frommGridCoord(mGridCoord GridCoord);
|
std::vector<WorldPosition> frommGridCoord(mGridCoord GridCoord);
|
||||||
|
|
||||||
void loadMapAndVMap(uint32 mapId, uint8 x, uint8 y);
|
|
||||||
|
|
||||||
void loadMapAndVMap() { loadMapAndVMap(GetMapId(), getmGridCoord().first, getmGridCoord().second); }
|
|
||||||
|
|
||||||
void loadMapAndVMaps(WorldPosition secondPos);
|
|
||||||
|
|
||||||
// Display functions
|
// Display functions
|
||||||
WorldPosition getDisplayLocation();
|
WorldPosition getDisplayLocation();
|
||||||
float getDisplayX() { return getDisplayLocation().GetPositionY() * -1.0; }
|
float getDisplayX() { return getDisplayLocation().GetPositionY() * -1.0; }
|
||||||
@ -297,10 +292,26 @@ public:
|
|||||||
|
|
||||||
std::vector<WorldPosition> getPathTo(WorldPosition endPos, Unit* bot) { return endPos.getPathFrom(*this, bot); }
|
std::vector<WorldPosition> getPathTo(WorldPosition endPos, Unit* bot) { return endPos.getPathFrom(*this, bot); }
|
||||||
|
|
||||||
bool isPathTo(std::vector<WorldPosition> path, float maxDistance = sPlayerbotAIConfig.targetPosRecalcDistance)
|
// The path "reaches" this position when its last point is on
|
||||||
|
// the same map, within maxDistance horizontally, and within
|
||||||
|
// maxZDistance vertically. 3D Euclidean distance would falsely
|
||||||
|
// accept paths that end the right horizontal distance from us
|
||||||
|
// but on a roof/floor below. maxDistance == 0 falls back to
|
||||||
|
// targetPosRecalcDistance (0.1y).
|
||||||
|
bool isPathTo(std::vector<WorldPosition> const& path, float const maxDistance = 0.0f,
|
||||||
|
float const maxZDistance = 2.0f) const
|
||||||
{
|
{
|
||||||
return !path.empty() && distance(path.back()) < maxDistance;
|
if (path.empty())
|
||||||
};
|
return false;
|
||||||
|
WorldPosition const& back = path.back();
|
||||||
|
if (back.GetMapId() != GetMapId())
|
||||||
|
return false;
|
||||||
|
float const realMax = maxDistance > 0.0f ? maxDistance
|
||||||
|
: sPlayerbotAIConfig.targetPosRecalcDistance;
|
||||||
|
if (GetExactDist2dSq(&back) >= realMax * realMax)
|
||||||
|
return false;
|
||||||
|
return std::fabs(back.GetPositionZ() - GetPositionZ()) < maxZDistance;
|
||||||
|
}
|
||||||
bool cropPathTo(std::vector<WorldPosition>& path, float maxDistance = sPlayerbotAIConfig.targetPosRecalcDistance);
|
bool cropPathTo(std::vector<WorldPosition>& path, float maxDistance = sPlayerbotAIConfig.targetPosRecalcDistance);
|
||||||
bool canPathTo(WorldPosition endPos, Unit* bot) { return endPos.isPathTo(getPathTo(endPos, bot)); }
|
bool canPathTo(WorldPosition endPos, Unit* bot) { return endPos.isPathTo(getPathTo(endPos, bot)); }
|
||||||
|
|
||||||
@ -507,9 +518,15 @@ public:
|
|||||||
radiusMin = radiusMin1;
|
radiusMin = radiusMin1;
|
||||||
radiusMax = radiusMax1;
|
radiusMax = radiusMax1;
|
||||||
}
|
}
|
||||||
virtual ~TravelDestination() = default;
|
virtual ~TravelDestination();
|
||||||
|
|
||||||
void addPoint(WorldPosition* pos) { points.push_back(pos); }
|
void addPoint(WorldPosition* pos)
|
||||||
|
{
|
||||||
|
if (!pos)
|
||||||
|
return;
|
||||||
|
|
||||||
|
points.push_back(new WorldPosition(*pos));
|
||||||
|
}
|
||||||
|
|
||||||
void setExpireDelay(uint32 delay) { expireDelay = delay; }
|
void setExpireDelay(uint32 delay) { expireDelay = delay; }
|
||||||
|
|
||||||
@ -673,7 +690,7 @@ public:
|
|||||||
bool isActive(Player* bot) override;
|
bool isActive(Player* bot) override;
|
||||||
virtual CreatureTemplate const* GetCreatureTemplate();
|
virtual CreatureTemplate const* GetCreatureTemplate();
|
||||||
std::string const getName() override { return "RpgTravelDestination"; }
|
std::string const getName() override { return "RpgTravelDestination"; }
|
||||||
int32 getEntry() override { return 0; }
|
int32 getEntry() override { return entry; }
|
||||||
std::string const getTitle() override;
|
std::string const getTitle() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -985,18 +1002,14 @@ private:
|
|||||||
bool InsideBracket(uint32 val) const { return val >= low && val <= high; }
|
bool InsideBracket(uint32 val) const { return val >= low && val <= high; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BankerLocation
|
|
||||||
{
|
|
||||||
WorldLocation loc;
|
|
||||||
uint32 entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Navigation caches
|
// Navigation caches
|
||||||
std::map<uint32, FlightMasterInfo> allianceFlightMasterCache;
|
std::map<uint32, FlightMasterInfo> allianceFlightMasterCache;
|
||||||
std::map<uint32, FlightMasterInfo> hordeFlightMasterCache;
|
std::map<uint32, FlightMasterInfo> hordeFlightMasterCache;
|
||||||
std::map<uint8, std::vector<WorldLocation>> allianceHubsPerLevelCache;
|
std::map<uint8, std::vector<WorldLocation>> allianceHubsPerLevelCache;
|
||||||
std::map<uint8, std::vector<WorldLocation>> hordeHubsPerLevelCache;
|
std::map<uint8, std::vector<WorldLocation>> hordeHubsPerLevelCache;
|
||||||
std::map<uint8, std::vector<BankerLocation>> bankerLocsPerLevelCache;
|
std::map<uint8, std::vector<NpcLocation>> bankerLocsPerLevelCache;
|
||||||
|
std::unordered_map<uint16, std::unordered_map<uint32, std::vector<NpcLocation>>> hordeAuctioneerCache;
|
||||||
|
std::unordered_map<uint16, std::unordered_map<uint32, std::vector<NpcLocation>>> allianceAuctioneerCache;
|
||||||
std::unordered_map<uint32, WorldLocation> bankerEntryToLocation;
|
std::unordered_map<uint32, WorldLocation> bankerEntryToLocation;
|
||||||
std::map<uint8, std::vector<WorldLocation>> locsPerLevelCache;
|
std::map<uint8, std::vector<WorldLocation>> locsPerLevelCache;
|
||||||
std::unordered_map<uint32, std::vector<WorldLocation>> creatureSpawnsByTemplate;
|
std::unordered_map<uint32, std::vector<WorldLocation>> creatureSpawnsByTemplate;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -8,11 +8,12 @@
|
|||||||
|
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
|
||||||
|
#include "G3D/Vector3.h"
|
||||||
#include "TravelMgr.h"
|
#include "TravelMgr.h"
|
||||||
|
|
||||||
// THEORY
|
// THEORY
|
||||||
//
|
//
|
||||||
// Pathfinding in (c)mangos is based on detour recast an opensource nashmesh creation and pathfinding codebase.
|
// Pathfinding in (c)mangos is based on detour recast, an opensource navmesh creation and pathfinding codebase.
|
||||||
// This system is used for mob and npc pathfinding and in this codebase also for bots.
|
// 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
|
||||||
@ -24,33 +25,68 @@
|
|||||||
// <S> ---> [N1] ---> [N2] ---> [N3] ---> <E>
|
// <S> ---> [N1] ---> [N2] ---> [N3] ---> <E>
|
||||||
//
|
//
|
||||||
// Bot at <S> wants to move to <E>
|
// Bot at <S> wants to move to <E>
|
||||||
// [N1],[N2],[N3] are predefined nodes for wich we know we can move from [N1] to [N2] and from [N2] to [N3] but not
|
// [N1],[N2],[N3] are predefined nodes for which we know we can move from [N1] to [N2] and from [N2] to [N3] but not
|
||||||
// from [N1] to [N3] If we can move fom [S] to [N1] and from [N3] to [E] we have a complete route to travel.
|
// from [N1] to [N3]. If we can move from [S] to [N1] and from [N3] to [E] we have a complete route to travel.
|
||||||
//
|
//
|
||||||
// Termonology:
|
// Terminology:
|
||||||
// Node: a location on a map for which we know bots are likely to want to travel to or need to travel past to reach
|
// Node: A location on a map for which we know bots are likely to want to travel to or need to travel past to reach
|
||||||
// other nodes. Link: the connection between two nodes. A link signifies that the bot can travel from one node to
|
// other nodes. Stored in DB table `playerbots_travelnode`.
|
||||||
// another. A link is one-directional. Path: the waypointpath returned by the standard PathGenerator to move from one
|
// Link: The connection between two nodes. A link signifies that the bot can travel from one node to another.
|
||||||
// node (or position) to another. A path can be imcomplete or empty which means there is no link. Route: the list of
|
// A link is one-directional. Stored in `playerbots_travelnode_link`.
|
||||||
// nodes that give the shortest route from a node to a distant node. Routes are calculated using a standard A* search
|
// Path: The waypoint path returned by the standard PathGenerator to move from one node (or position) to another.
|
||||||
// based on links.
|
// A path can be incomplete or empty which means there is no link. Stored in `playerbots_travelnode_path`.
|
||||||
|
// Route: The list of nodes that give the shortest route from a node to a distant node. Routes are calculated using
|
||||||
|
// a standard A* search based on links.
|
||||||
//
|
//
|
||||||
// On server start saved nodes and links are loaded. Paths and routes are calculated on the fly but saved for future
|
// Edge types (TravelNodePathType):
|
||||||
// use. Nodes can be added and removed realtime however because bots access the nodes from different threads this
|
// walk(1) — Walk via navmesh waypoints (stored in DB)
|
||||||
// requires a locking mechanism.
|
// portal(2) — AreaTrigger teleport (auto-discovered at startup)
|
||||||
|
// transport(3) — Boat/zeppelin (auto-discovered from MO_TRANSPORT)
|
||||||
|
// flightPath(4) — Taxi flight between flight masters
|
||||||
|
// teleportSpell(5) — Spell-based teleport (e.g. mage portals)
|
||||||
|
// staticPortal(6) — Manually defined teleport link (DB only, not pruned by generation)
|
||||||
|
// flyingMount (7) — Use Bots Flying mount to travel (Not currently enabled)
|
||||||
|
//
|
||||||
|
// On server start saved nodes and links are loaded via TravelNodeMap::Init(). An index of nodes by zone is prepared
|
||||||
|
// (instead of scanning all ~4000 nodes), precomputes connected components for O(1) reachability checks, and builds
|
||||||
|
// a taxi BFS graph. Paths and routes are calculated on the fly and saved for future use. Nodes are only added at
|
||||||
|
// startup or via the console `.generate` command — runtime mutation was removed because taking a unique_lock
|
||||||
|
// caused 100-250ms contention spikes against bot threads.
|
||||||
//
|
//
|
||||||
// Initially the current nodes have been made:
|
// Initially the current nodes have been made:
|
||||||
// Flightmasters and Inns (Bots can use these to fast-travel so eventually they will be included in the route
|
// Flightmasters and Inns (Bots can use these to fast-travel so eventually they will be included in the route
|
||||||
// calculation) WorldBosses and Unique bosses in instances (These are a logical places bots might want to go in
|
// calculation) WorldBosses and Unique bosses in instances (These are logical places bots might want to go in
|
||||||
// instances) Player start spawns (Obviously all lvl1 bots will spawn and move from here) Area triggers locations with
|
// instances) Player start spawns (Obviously all lvl1 bots will spawn and move from here) Area triggers locations with
|
||||||
// teleport and their teleport destinations (These used to travel in or between maps) Transports including elevators
|
// teleport and their teleport destinations (These used to travel in or between maps) Transports including elevators
|
||||||
// (Again used to travel in and in maps) (sub)Zone means (These are the center most point for each sub-zone which is
|
// (Again used to travel in and in maps) (sub)Zone means (These are the center most point for each sub-zone which is
|
||||||
// good for global coverage)
|
// good for global coverage).
|
||||||
//
|
//
|
||||||
// To increase coverage/linking extra nodes can be automatically be created.
|
// To increase coverage/linking extra nodes must be manually created via the "playerbot travel generatenode"
|
||||||
// Current implentation places nodes on paths (including complete) at sub-zone transitions or randomly.
|
// console command after importing the specified node. Current implementation places nodes on paths (including
|
||||||
// After calculating possible links the node is removed if it does not create local coverage.
|
// complete) at sub-zone transitions or randomly. After calculating possible links the node is removed if it
|
||||||
|
// does not create local coverage (.fullgenerate only).
|
||||||
//
|
//
|
||||||
|
// Travel Flow:
|
||||||
|
//
|
||||||
|
// GetFullPath finds nearest nodes (zone-indexed), runs A* to get a node route, then
|
||||||
|
// BuildPath assembles a flat TravelPath with typed waypoints (walk, portal, transport, flight).
|
||||||
|
// ExecuteTravelPlan iterates the path by stepIdx, dispatching on each point's PathNodeType.
|
||||||
|
// Cross-map travel is handled naturally by portal/transport edges in the A* graph.
|
||||||
|
//
|
||||||
|
// If setup cannot resolve (no node, no route, no flight), the bot teleports directly to the destination
|
||||||
|
// as a fallback.
|
||||||
|
//
|
||||||
|
// The use of hearthstones and mage teleporting was removed — it caused route mutations requiring locking that no longer made sense. Mage portals may be future item.
|
||||||
|
//
|
||||||
|
// Thread Safety:
|
||||||
|
//
|
||||||
|
// The node graph is immutable at runtime (no adds/removes after Init). A shared_timed_mutex (m_nMapMtx) still
|
||||||
|
// exists and shared_locks are taken in GetFullPath and GenerateWalkPath for safety, but since there are no
|
||||||
|
// runtime mutations these are effectively uncontested. The only exclusive locks are taken at startup
|
||||||
|
// (saveNodeStore) and by the debug dump command.
|
||||||
|
//
|
||||||
|
|
||||||
|
constexpr float MAX_PATHFINDING_DISTANCE = 296.0f;
|
||||||
|
|
||||||
enum class TravelNodePathType : uint8
|
enum class TravelNodePathType : uint8
|
||||||
{
|
{
|
||||||
@ -59,21 +95,20 @@ enum class TravelNodePathType : uint8
|
|||||||
portal = 2,
|
portal = 2,
|
||||||
transport = 3,
|
transport = 3,
|
||||||
flightPath = 4,
|
flightPath = 4,
|
||||||
teleportSpell = 5
|
teleportSpell = 5,
|
||||||
|
staticPortal = 6,
|
||||||
|
flyingMount = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
// A connection between two nodes.
|
// A connection between two nodes.
|
||||||
class TravelNodePath
|
class TravelNodePath
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Legacy Constructor for travelnodestore
|
|
||||||
// TravelNodePath(float distance1, float extraCost1, bool portal1 = false, uint32 portalId1 = 0, bool transport1 =
|
|
||||||
// false, bool calculated = false, uint8 maxLevelMob1 = 0, uint8 maxLevelAlliance1 = 0, uint8 maxLevelHorde1 = 0,
|
|
||||||
// float swimDistance1 = 0, bool flightPath1 = false);
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
TravelNodePath(float distance = 0.1f, float extraCost = 0, uint8 pathType = (uint8)TravelNodePathType::walk,
|
TravelNodePath(float distance = 0.1f, float extraCost = 0,
|
||||||
uint32 pathObject = 0, bool calculated = false, std::vector<uint8> maxLevelCreature = {0, 0, 0},
|
uint8 pathType = (uint8)TravelNodePathType::walk,
|
||||||
|
uint32 pathObject = 0, bool calculated = false,
|
||||||
|
std::vector<uint8> maxLevelCreature = {0, 0, 0},
|
||||||
float swimDistance = 0)
|
float swimDistance = 0)
|
||||||
: extraCost(extraCost),
|
: extraCost(extraCost),
|
||||||
calculated(calculated),
|
calculated(calculated),
|
||||||
@ -85,7 +120,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (pathType != (uint8)TravelNodePathType::walk)
|
if (pathType != (uint8)TravelNodePathType::walk)
|
||||||
complete = true;
|
complete = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
TravelNodePath(TravelNodePath* basePath)
|
TravelNodePath(TravelNodePath* basePath)
|
||||||
{
|
{
|
||||||
@ -98,11 +133,11 @@ public:
|
|||||||
swimDistance = basePath->swimDistance;
|
swimDistance = basePath->swimDistance;
|
||||||
pathType = basePath->pathType;
|
pathType = basePath->pathType;
|
||||||
pathObject = basePath->pathObject;
|
pathObject = basePath->pathObject;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
bool getComplete() { return complete || pathType != TravelNodePathType::walk; }
|
bool getComplete() { return complete || pathType != TravelNodePathType::walk; }
|
||||||
std::vector<WorldPosition> getPath() { return path; }
|
std::vector<WorldPosition> GetPath() { return path; }
|
||||||
|
|
||||||
TravelNodePathType getPathType() { return pathType; }
|
TravelNodePathType getPathType() { return pathType; }
|
||||||
uint32 getPathObject() { return pathObject; }
|
uint32 getPathObject() { return pathObject; }
|
||||||
@ -130,9 +165,6 @@ public:
|
|||||||
extraCost = distance / speed;
|
extraCost = distance / speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void setPortal(bool portal1, uint32 portalId1 = 0) { portal = portal1; portalId = portalId1; }
|
|
||||||
// void setTransport(bool transport1) { transport = transport1; }
|
|
||||||
|
|
||||||
void setPathType(TravelNodePathType pathType1) { pathType = pathType1; }
|
void setPathType(TravelNodePathType pathType1) { pathType = pathType1; }
|
||||||
|
|
||||||
void setPathObject(uint32 pathObject1) { pathObject = pathObject1; }
|
void setPathObject(uint32 pathObject1) { pathObject = pathObject1; }
|
||||||
@ -186,9 +218,10 @@ class TravelNode
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructors
|
// Constructors
|
||||||
TravelNode(){};
|
TravelNode() {}
|
||||||
|
|
||||||
TravelNode(WorldPosition point1, std::string const nodeName1 = "Travel Node", bool important1 = false)
|
TravelNode(WorldPosition point1, std::string const nodeName1 = "Travel Node",
|
||||||
|
bool important1 = false)
|
||||||
{
|
{
|
||||||
nodeName = nodeName1;
|
nodeName = nodeName1;
|
||||||
point = point1;
|
point = point1;
|
||||||
@ -207,11 +240,11 @@ public:
|
|||||||
void setPoint(WorldPosition point1) { point = point1; }
|
void setPoint(WorldPosition point1) { point = point1; }
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
std::string const getName() { return nodeName; };
|
std::string const getName() { return nodeName; }
|
||||||
WorldPosition* getPosition() { return &point; };
|
WorldPosition* getPosition() { return &point; }
|
||||||
std::unordered_map<TravelNode*, TravelNodePath>* getPaths() { return &paths; }
|
std::unordered_map<TravelNode*, TravelNodePath>* getPaths() { return &paths; }
|
||||||
std::unordered_map<TravelNode*, TravelNodePath*>* getLinks() { return &links; }
|
std::unordered_map<TravelNode*, TravelNodePath*>* getLinks() { return &links; }
|
||||||
bool isImportant() { return important; };
|
bool isImportant() { return important; }
|
||||||
bool isLinked() { return linked; }
|
bool isLinked() { return linked; }
|
||||||
|
|
||||||
bool isTransport()
|
bool isTransport()
|
||||||
@ -235,7 +268,8 @@ public:
|
|||||||
bool isPortal()
|
bool isPortal()
|
||||||
{
|
{
|
||||||
for (auto const& link : *getLinks())
|
for (auto const& link : *getLinks())
|
||||||
if (link.second->getPathType() == TravelNodePathType::portal)
|
if (link.second->getPathType() == TravelNodePathType::portal ||
|
||||||
|
link.second->getPathType() == TravelNodePathType::staticPortal)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -251,17 +285,25 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorldLocation shortcuts
|
// WorldLocation shortcuts
|
||||||
uint32 getMapId() { return point.GetMapId(); }
|
uint32 GetMapId() { return point.GetMapId(); }
|
||||||
float getX() { return point.GetPositionX(); }
|
float getX() { return point.GetPositionX(); }
|
||||||
float getY() { return point.GetPositionY(); }
|
float getY() { return point.GetPositionY(); }
|
||||||
float getZ() { return point.GetPositionZ(); }
|
float getZ() { return point.GetPositionZ(); }
|
||||||
float getO() { return point.GetOrientation(); }
|
float getO() { return point.GetOrientation(); }
|
||||||
float getDistance(WorldPosition pos) { return point.distance(pos); }
|
float getDistance(WorldPosition pos) { return point.distance(pos); }
|
||||||
float getDistance(TravelNode* node) { return point.distance(node->getPosition()); }
|
float getDistance(TravelNode* node)
|
||||||
float fDist(TravelNode* node) { return point.fDist(node->getPosition()); }
|
{
|
||||||
|
return point.distance(node->getPosition());
|
||||||
|
}
|
||||||
|
float fDist(TravelNode* node)
|
||||||
|
{
|
||||||
|
return point.fDist(node->getPosition());
|
||||||
|
}
|
||||||
float fDist(WorldPosition pos) { return point.fDist(pos); }
|
float fDist(WorldPosition pos) { return point.fDist(pos); }
|
||||||
|
|
||||||
TravelNodePath* setPathTo(TravelNode* node, TravelNodePath path = TravelNodePath(), bool isLink = true)
|
TravelNodePath* setPathTo(TravelNode* node,
|
||||||
|
TravelNodePath path = TravelNodePath(),
|
||||||
|
bool isLink = true)
|
||||||
{
|
{
|
||||||
if (this != node)
|
if (this != node)
|
||||||
{
|
{
|
||||||
@ -275,10 +317,20 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPathTo(TravelNode* node) { return paths.find(node) != paths.end(); }
|
bool hasPathTo(TravelNode* node)
|
||||||
TravelNodePath* getPathTo(TravelNode* node) { return &paths[node]; }
|
{
|
||||||
bool hasCompletePathTo(TravelNode* node) { return hasPathTo(node) && getPathTo(node)->getComplete(); }
|
return paths.find(node) != paths.end();
|
||||||
TravelNodePath* buildPath(TravelNode* endNode, Unit* bot, bool postProcess = false);
|
}
|
||||||
|
TravelNodePath* getPathTo(TravelNode* node)
|
||||||
|
{
|
||||||
|
return &paths[node];
|
||||||
|
}
|
||||||
|
bool hasCompletePathTo(TravelNode* node)
|
||||||
|
{
|
||||||
|
return hasPathTo(node) && getPathTo(node)->getComplete();
|
||||||
|
}
|
||||||
|
TravelNodePath* BuildPath(TravelNode* endNode, Unit* bot,
|
||||||
|
bool postProcess = false);
|
||||||
|
|
||||||
void setLinkTo(TravelNode* node, float distance = 0.1f)
|
void setLinkTo(TravelNode* node, float distance = 0.1f)
|
||||||
{
|
{
|
||||||
@ -291,9 +343,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLinkTo(TravelNode* node) { return links.find(node) != links.end(); }
|
bool hasLinkTo(TravelNode* node)
|
||||||
float linkCostTo(TravelNode* node) { return paths.find(node)->second.getDistance(); }
|
{
|
||||||
float linkDistanceTo(TravelNode* node) { return paths.find(node)->second.getDistance(); }
|
return links.find(node) != links.end();
|
||||||
|
}
|
||||||
|
float linkCostTo(TravelNode* node)
|
||||||
|
{
|
||||||
|
return paths.find(node)->second.getDistance();
|
||||||
|
}
|
||||||
|
float linkDistanceTo(TravelNode* node)
|
||||||
|
{
|
||||||
|
return paths.find(node)->second.getDistance();
|
||||||
|
}
|
||||||
void removeLinkTo(TravelNode* node, bool removePaths = false);
|
void removeLinkTo(TravelNode* node, bool removePaths = false);
|
||||||
|
|
||||||
bool isEqual(TravelNode* compareNode);
|
bool isEqual(TravelNode* compareNode);
|
||||||
@ -304,7 +365,8 @@ public:
|
|||||||
bool cropUselessLinks();
|
bool cropUselessLinks();
|
||||||
|
|
||||||
// Returns all nodes that can be reached from this node.
|
// Returns all nodes that can be reached from this node.
|
||||||
std::vector<TravelNode*> getNodeMap(bool importantOnly = false, std::vector<TravelNode*> ignoreNodes = {});
|
std::vector<TravelNode*> getNodeMap(bool importantOnly = false,
|
||||||
|
std::vector<TravelNode*> ignoreNodes = {});
|
||||||
|
|
||||||
// Checks if it is even possible to route to this node.
|
// Checks if it is even possible to route to this node.
|
||||||
bool hasRouteTo(TravelNode* node)
|
bool hasRouteTo(TravelNode* node)
|
||||||
@ -314,7 +376,10 @@ public:
|
|||||||
routes[mNode] = true;
|
routes[mNode] = true;
|
||||||
|
|
||||||
return routes.find(node) != routes.end();
|
return routes.find(node) != routes.end();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
void clearRoutes() { routes.clear(); }
|
||||||
|
void setRouteTo(TravelNode* node) { routes[node] = true; }
|
||||||
|
|
||||||
void print(bool printFailed = true);
|
void print(bool printFailed = true);
|
||||||
|
|
||||||
@ -344,24 +409,8 @@ protected:
|
|||||||
// uint32 transportId = 0;
|
// uint32 transportId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PortalNode : public TravelNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PortalNode(TravelNode* baseNode) : TravelNode(baseNode){};
|
|
||||||
|
|
||||||
void SetPortal(TravelNode* baseNode, TravelNode* endNode, uint32 portalSpell)
|
|
||||||
{
|
|
||||||
nodeName = baseNode->getName();
|
|
||||||
point = *baseNode->getPosition();
|
|
||||||
paths.clear();
|
|
||||||
links.clear();
|
|
||||||
TravelNodePath path(0.1f, 0.1f, (uint8)TravelNodePathType::teleportSpell, portalSpell, true);
|
|
||||||
setPathTo(endNode, path);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Route step type
|
// Route step type
|
||||||
enum PathNodeType
|
enum class PathNodeType : uint8
|
||||||
{
|
{
|
||||||
NODE_PREPATH = 0,
|
NODE_PREPATH = 0,
|
||||||
NODE_PATH = 1,
|
NODE_PATH = 1,
|
||||||
@ -369,38 +418,56 @@ enum PathNodeType
|
|||||||
NODE_PORTAL = 3,
|
NODE_PORTAL = 3,
|
||||||
NODE_TRANSPORT = 4,
|
NODE_TRANSPORT = 4,
|
||||||
NODE_FLIGHTPATH = 5,
|
NODE_FLIGHTPATH = 5,
|
||||||
NODE_TELEPORT = 6
|
NODE_TELEPORT = 6,
|
||||||
|
NODE_FLYING_MOUNT = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PathNodePoint
|
struct PathNodePoint
|
||||||
{
|
{
|
||||||
WorldPosition point;
|
WorldPosition point;
|
||||||
PathNodeType type = NODE_PATH;
|
PathNodeType type = PathNodeType::NODE_PATH;
|
||||||
uint32 entry = 0;
|
uint32 entry = 0;
|
||||||
|
|
||||||
|
bool operator==(const PathNodePoint& p1) const
|
||||||
|
{
|
||||||
|
return point == p1.point && type == p1.type && entry == p1.entry;
|
||||||
|
}
|
||||||
|
// A "walkable" node is one we traverse on foot. Portals/transports/
|
||||||
|
// taxis/teleports are entry/exit hops, not points to anchor a
|
||||||
|
// shortcut on. Used by makeShortCut to skip them when picking the
|
||||||
|
// closest-point-on-path to the bot.
|
||||||
|
bool isWalkable() const { return (uint8)type <= (uint8)PathNodeType::NODE_NODE; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// A complete list of points the bots has to walk to or teleport to.
|
// A complete list of points the bots has to walk to or teleport to.
|
||||||
class TravelPath
|
class TravelPath
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TravelPath(){};
|
TravelPath() {}
|
||||||
TravelPath(std::vector<PathNodePoint> fullPath1) { fullPath = fullPath1; }
|
TravelPath(std::vector<PathNodePoint> fullPath1)
|
||||||
TravelPath(std::vector<WorldPosition> path, PathNodeType type = NODE_PATH, uint32 entry = 0)
|
{
|
||||||
|
fullPath = fullPath1;
|
||||||
|
}
|
||||||
|
TravelPath(std::vector<WorldPosition> path,
|
||||||
|
PathNodeType type = PathNodeType::NODE_PATH,
|
||||||
|
uint32 entry = 0)
|
||||||
{
|
{
|
||||||
addPath(path, type, entry);
|
addPath(path, type, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPoint(PathNodePoint point) { fullPath.push_back(point); }
|
void addPoint(PathNodePoint point) { fullPath.push_back(point); }
|
||||||
void addPoint(WorldPosition point, PathNodeType type = NODE_PATH, uint32 entry = 0)
|
void addPoint(WorldPosition point,
|
||||||
|
PathNodeType type = PathNodeType::NODE_PATH,
|
||||||
|
uint32 entry = 0)
|
||||||
{
|
{
|
||||||
fullPath.push_back(PathNodePoint{point, type, entry});
|
fullPath.push_back(PathNodePoint{point, type, entry});
|
||||||
}
|
}
|
||||||
void addPath(std::vector<WorldPosition> path, PathNodeType type = NODE_PATH, uint32 entry = 0)
|
void addPath(std::vector<WorldPosition> path,
|
||||||
|
PathNodeType type = PathNodeType::NODE_PATH,
|
||||||
|
uint32 entry = 0)
|
||||||
{
|
{
|
||||||
for (auto& p : path)
|
for (auto& p : path)
|
||||||
{
|
|
||||||
fullPath.push_back(PathNodePoint{p, type, entry});
|
fullPath.push_back(PathNodePoint{p, type, entry});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
void addPath(std::vector<PathNodePoint> newPath)
|
void addPath(std::vector<PathNodePoint> newPath)
|
||||||
{
|
{
|
||||||
@ -408,8 +475,11 @@ public:
|
|||||||
}
|
}
|
||||||
void clear() { fullPath.clear(); }
|
void clear() { fullPath.clear(); }
|
||||||
|
|
||||||
bool empty() { return fullPath.empty(); }
|
bool empty() const { return fullPath.empty(); }
|
||||||
std::vector<PathNodePoint> getPath() { return fullPath; }
|
size_t size() const { return fullPath.size(); }
|
||||||
|
const PathNodePoint& operator[](size_t idx) const { return fullPath[idx]; }
|
||||||
|
std::vector<PathNodePoint> GetPath() { return fullPath; }
|
||||||
|
const std::vector<PathNodePoint>& GetPathRef() const { return fullPath; }
|
||||||
WorldPosition getFront() { return fullPath.front().point; }
|
WorldPosition getFront() { return fullPath.front().point; }
|
||||||
WorldPosition getBack() { return fullPath.back().point; }
|
WorldPosition getBack() { return fullPath.back().point; }
|
||||||
|
|
||||||
@ -419,13 +489,22 @@ public:
|
|||||||
for (auto const& p : fullPath)
|
for (auto const& p : fullPath)
|
||||||
retVec.push_back(p.point);
|
retVec.push_back(p.point);
|
||||||
return retVec;
|
return retVec;
|
||||||
};
|
}
|
||||||
|
|
||||||
bool makeShortCut(WorldPosition startPos, float maxDist);
|
bool makeShortCut(WorldPosition startPos, float maxDist, Unit* bot = nullptr);
|
||||||
bool shouldMoveToNextPoint(WorldPosition startPos, std::vector<PathNodePoint>::iterator beg,
|
|
||||||
std::vector<PathNodePoint>::iterator ed, std::vector<PathNodePoint>::iterator p,
|
// Detect "pathfinder cheating" — paths that PathGenerator accepts
|
||||||
float& moveDist, float maxDist);
|
// but a player can't actually walk:
|
||||||
WorldPosition getNextPoint(WorldPosition startPos, float maxDist, TravelNodePathType& pathType, uint32& entry);
|
// * 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,
|
||||||
|
float endpointDistance);
|
||||||
|
|
||||||
std::ostringstream const print();
|
std::ostringstream const print();
|
||||||
|
|
||||||
@ -438,17 +517,25 @@ class TravelNodeRoute
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TravelNodeRoute() {}
|
TravelNodeRoute() {}
|
||||||
TravelNodeRoute(std::vector<TravelNode*> nodes1) { nodes = nodes1; /*currentNode = route.begin();*/ }
|
TravelNodeRoute(std::vector<TravelNode*> nodes1)
|
||||||
|
{
|
||||||
|
nodes = nodes1;
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty() { return nodes.empty(); }
|
bool isEmpty() { return nodes.empty(); }
|
||||||
|
|
||||||
bool hasNode(TravelNode* node) { return findNode(node) != nodes.end(); }
|
bool hasNode(TravelNode* node)
|
||||||
|
{
|
||||||
|
return findNode(node) != nodes.end();
|
||||||
|
}
|
||||||
float getTotalDistance();
|
float getTotalDistance();
|
||||||
|
|
||||||
std::vector<TravelNode*> getNodes() { return nodes; }
|
std::vector<TravelNode*> getNodes() { return nodes; }
|
||||||
|
|
||||||
TravelPath buildPath(std::vector<WorldPosition> pathToStart = {}, std::vector<WorldPosition> pathToEnd = {},
|
TravelPath BuildPath(
|
||||||
Unit* bot = nullptr);
|
std::vector<WorldPosition> pathToStart = {},
|
||||||
|
std::vector<WorldPosition> pathToEnd = {},
|
||||||
|
Unit* bot = nullptr);
|
||||||
|
|
||||||
std::ostringstream const print();
|
std::ostringstream const print();
|
||||||
|
|
||||||
@ -467,12 +554,47 @@ public:
|
|||||||
TravelNodeStub(TravelNode* dataNode1) { dataNode = dataNode1; }
|
TravelNodeStub(TravelNode* dataNode1) { dataNode = dataNode1; }
|
||||||
|
|
||||||
TravelNode* dataNode;
|
TravelNode* dataNode;
|
||||||
float m_f = 0.0, m_g = 0.0, m_h = 0.0;
|
float totalCost = 0.0;
|
||||||
bool open = false, close = false;
|
float costFromStart = 0.0;
|
||||||
|
float heuristic = 0.0;
|
||||||
|
bool open = false;
|
||||||
|
bool closed = false;
|
||||||
TravelNodeStub* parent = nullptr;
|
TravelNodeStub* parent = nullptr;
|
||||||
uint32 currentGold = 0;
|
uint32 currentGold = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TravelPlan
|
||||||
|
{
|
||||||
|
WorldPosition destination;
|
||||||
|
|
||||||
|
// Flat waypoint path built upfront by GetFullPath:
|
||||||
|
TravelPath steps;
|
||||||
|
uint32 stepIdx{0};
|
||||||
|
|
||||||
|
// Spline scratch (used by executor):
|
||||||
|
std::vector<G3D::Vector3> walkPoints;
|
||||||
|
bool splineActive{false};
|
||||||
|
uint32 splineStartTime{0};
|
||||||
|
uint32 expectedDuration{0};
|
||||||
|
|
||||||
|
// Taxi scratch:
|
||||||
|
std::vector<uint32> route;
|
||||||
|
|
||||||
|
bool IsActive() const { return !steps.empty(); }
|
||||||
|
|
||||||
|
void Reset()
|
||||||
|
{
|
||||||
|
destination = WorldPosition();
|
||||||
|
steps.clear();
|
||||||
|
stepIdx = 0;
|
||||||
|
walkPoints.clear();
|
||||||
|
splineActive = false;
|
||||||
|
splineStartTime = 0;
|
||||||
|
expectedDuration = 0;
|
||||||
|
route.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// The container of all nodes.
|
// The container of all nodes.
|
||||||
class TravelNodeMap
|
class TravelNodeMap
|
||||||
{
|
{
|
||||||
@ -484,14 +606,18 @@ public:
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelNode* addNode(WorldPosition pos, std::string const preferedName = "Travel Node", bool isImportant = false,
|
TravelNode* addNode(WorldPosition pos,
|
||||||
bool checkDuplicate = true, bool transport = false, uint32 transportId = 0);
|
std::string const preferedName = "Travel Node",
|
||||||
|
bool isImportant = false,
|
||||||
|
bool checkDuplicate = true,
|
||||||
|
bool transport = false,
|
||||||
|
uint32 transportId = 0);
|
||||||
void removeNode(TravelNode* node);
|
void removeNode(TravelNode* node);
|
||||||
bool removeNodes()
|
bool removeNodes()
|
||||||
{
|
{
|
||||||
if (m_nMapMtx.try_lock_for(std::chrono::seconds(10)))
|
if (m_nMapMtx.try_lock_for(std::chrono::seconds(10)))
|
||||||
{
|
{
|
||||||
for (auto& node : m_nodes)
|
for (auto& node : nodes)
|
||||||
removeNode(node);
|
removeNode(node);
|
||||||
|
|
||||||
m_nMapMtx.unlock();
|
m_nMapMtx.unlock();
|
||||||
@ -499,28 +625,32 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
void fullLinkNode(TravelNode* startNode, Unit* bot);
|
void fullLinkNode(TravelNode* startNode, Unit* bot);
|
||||||
|
|
||||||
// Get all nodes
|
// Get all nodes
|
||||||
std::vector<TravelNode*> getNodes() { return m_nodes; }
|
std::vector<TravelNode*> getNodes() { return nodes; }
|
||||||
std::vector<TravelNode*> getNodes(WorldPosition pos, float range = -1);
|
std::vector<TravelNode*> getNodes(WorldPosition pos, float range = -1);
|
||||||
|
|
||||||
// Find nearest node.
|
// Find nearest node.
|
||||||
TravelNode* getNode(TravelNode* sameNode)
|
TravelNode* getNode(TravelNode* sameNode)
|
||||||
{
|
{
|
||||||
for (auto& node : m_nodes)
|
for (auto& node : nodes)
|
||||||
{
|
{
|
||||||
if (node->getName() == sameNode->getName() && node->getPosition() == sameNode->getPosition())
|
if (node->getName() == sameNode->getName()
|
||||||
|
&& node->getPosition() == sameNode->getPosition())
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelNode* getNode(WorldPosition pos, std::vector<WorldPosition>& ppath, Unit* bot = nullptr, float range = -1);
|
TravelNode* getNode(WorldPosition pos,
|
||||||
TravelNode* getNode(WorldPosition pos, Unit* bot = nullptr, float range = -1)
|
std::vector<WorldPosition>& ppath,
|
||||||
|
Unit* bot = nullptr, float range = -1);
|
||||||
|
TravelNode* getNode(WorldPosition pos, Unit* bot = nullptr,
|
||||||
|
float range = -1)
|
||||||
{
|
{
|
||||||
std::vector<WorldPosition> ppath;
|
std::vector<WorldPosition> ppath;
|
||||||
return getNode(pos, ppath, bot, range);
|
return getNode(pos, ppath, bot, range);
|
||||||
@ -536,18 +666,16 @@ public:
|
|||||||
return rNodes[urand(0, rNodes.size() - 1)];
|
return rNodes[urand(0, rNodes.size() - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds the best nodePath between two nodes
|
// Finds the best nodePath between two nodes (A* over the node graph)
|
||||||
TravelNodeRoute getRoute(TravelNode* start, TravelNode* goal, Player* bot = nullptr);
|
TravelNodeRoute GetNodeRoute(TravelNode* start, TravelNode* goal,
|
||||||
|
Player* bot);
|
||||||
|
|
||||||
// Find the best node between two positions
|
// Picks the nearest start/end nodes for two world positions and runs A*
|
||||||
TravelNodeRoute getRoute(WorldPosition startPos, WorldPosition endPos, std::vector<WorldPosition>& startPath,
|
// over the node graph to return a full route between them.
|
||||||
Player* bot = nullptr);
|
TravelNodeRoute FindRouteNearestNodes(WorldPosition startPos,
|
||||||
|
WorldPosition endPos,
|
||||||
// Find the full path between those locations
|
std::vector<WorldPosition>& startPath,
|
||||||
static TravelPath getFullPath(WorldPosition startPos, WorldPosition endPos, Player* bot = nullptr);
|
Player* bot = nullptr);
|
||||||
|
|
||||||
// Manage/update nodes
|
|
||||||
void manageNodes(Unit* bot, bool mapFull = false);
|
|
||||||
|
|
||||||
void setHasToGen() { hasToGen = true; }
|
void setHasToGen() { hasToGen = true; }
|
||||||
|
|
||||||
@ -563,15 +691,17 @@ public:
|
|||||||
void removeUselessPaths();
|
void removeUselessPaths();
|
||||||
void calculatePathCosts();
|
void calculatePathCosts();
|
||||||
void generateTaxiPaths();
|
void generateTaxiPaths();
|
||||||
void generatePaths();
|
void generatePaths(bool fullGen = false);
|
||||||
|
|
||||||
void generateAll();
|
void generateAll();
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
|
||||||
void printMap();
|
void printMap();
|
||||||
|
|
||||||
void printNodeStore();
|
void printNodeStore();
|
||||||
void saveNodeStore();
|
void saveNodeStore();
|
||||||
void loadNodeStore();
|
void LoadNodeStore();
|
||||||
|
|
||||||
bool cropUselessNode(TravelNode* startNode);
|
bool cropUselessNode(TravelNode* startNode);
|
||||||
TravelNode* addZoneLinkNode(TravelNode* startNode);
|
TravelNode* addZoneLinkNode(TravelNode* startNode);
|
||||||
@ -584,8 +714,28 @@ public:
|
|||||||
void InitTaxiGraph();
|
void InitTaxiGraph();
|
||||||
std::vector<uint32> FindTaxiPath(uint32 fromNode, uint32 toNode);
|
std::vector<uint32> FindTaxiPath(uint32 fromNode, uint32 toNode);
|
||||||
|
|
||||||
|
void BuildZoneIndex();
|
||||||
|
void PrecomputeReachability();
|
||||||
|
|
||||||
|
TravelNode* GetNearestNodeInZone(WorldPosition pos, uint32 zoneId);
|
||||||
|
TravelNode* GetNearestNodeOnMap(WorldPosition pos);
|
||||||
|
|
||||||
|
// All nodes registered to a zone (post-BuildZoneIndex). Returns an
|
||||||
|
// empty static vector for unknown zones.
|
||||||
|
std::vector<TravelNode*> const& GetNodesInZone(uint32 zoneId) const;
|
||||||
|
|
||||||
|
bool GetFullPath(TravelPlan& plan, WorldPosition botPos,
|
||||||
|
uint32 botZoneId, WorldPosition destination);
|
||||||
|
|
||||||
|
// Resolve A* route between two world positions (returns node vector)
|
||||||
|
std::vector<TravelNode*> ResolveRoute(WorldPosition startPos,
|
||||||
|
WorldPosition endPos);
|
||||||
|
|
||||||
|
// Get stored walk points for one edge (from→to). Empty if no path.
|
||||||
|
std::vector<G3D::Vector3> GetEdgeWalkPoints(TravelNode* from,
|
||||||
|
TravelNode* to);
|
||||||
|
|
||||||
std::shared_timed_mutex m_nMapMtx;
|
std::shared_timed_mutex m_nMapMtx;
|
||||||
std::unordered_map<ObjectGuid, std::unordered_map<uint32, TravelNode*>> teleportNodes;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TravelNodeMap() = default;
|
TravelNodeMap() = default;
|
||||||
@ -601,13 +751,18 @@ private:
|
|||||||
void BuildTaxiGraph();
|
void BuildTaxiGraph();
|
||||||
void ComputeAllPaths();
|
void ComputeAllPaths();
|
||||||
std::unordered_map<uint32, uint32> BFS(uint32 startNode);
|
std::unordered_map<uint32, uint32> BFS(uint32 startNode);
|
||||||
std::vector<uint32> BuildPath(uint32 fromNode, uint32 toNode,
|
std::vector<uint32> BuildPath(
|
||||||
const std::unordered_map<uint32, uint32>& parentMap);
|
uint32 fromNode, uint32 toNode,
|
||||||
|
const std::unordered_map<uint32, uint32>& parentMap);
|
||||||
|
|
||||||
std::unordered_map<uint32, std::vector<uint32>> taxiGraph;
|
std::unordered_map<uint32, std::vector<uint32>> m_taxiGraph;
|
||||||
std::map<uint32, std::map<uint32, std::vector<uint32>>> taxiPathCache;
|
std::map<uint32, std::map<uint32, std::vector<uint32>>>
|
||||||
|
m_taxiPathCache;
|
||||||
|
|
||||||
std::vector<TravelNode*> m_nodes;
|
std::vector<TravelNode*> nodes;
|
||||||
|
|
||||||
|
std::unordered_map<uint32, std::vector<TravelNode*>> m_zoneIndex;
|
||||||
|
std::unordered_map<uint32, std::vector<TravelNode*>> m_mapIndex;
|
||||||
|
|
||||||
std::vector<std::pair<uint32, WorldPosition>> mapOffsets;
|
std::vector<std::pair<uint32, WorldPosition>> mapOffsets;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user