From ad4fa111759cd7d55352a2e16a63c9b204741fd0 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 19:47:20 +0800 Subject: [PATCH] Movement search time config --- conf/playerbots.conf.dist | 4 + src/PlayerbotAIConfig.cpp | 1 + src/PlayerbotAIConfig.h | 3 +- src/strategy/actions/MovementActions.cpp | 108 +++++++++++------------ src/strategy/actions/MovementActions.h | 2 +- 5 files changed, 62 insertions(+), 56 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 18ff5b1b..e883c56e 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -256,6 +256,10 @@ AiPlayerbot.GlobalCooldown = 500 # Max wait time when moving AiPlayerbot.MaxWaitForMove = 5000 +# Max search time for movement (higher for better movement on slopes) +# default: 3 +AiPlayerbot.MaxMovementSearchTime = 3 + # Action expiration time AiPlayerbot.ExpireActionTime = 5000 diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 28f43817..bf168bf6 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -53,6 +53,7 @@ bool PlayerbotAIConfig::Initialize() globalCoolDown = sConfigMgr->GetOption("AiPlayerbot.GlobalCooldown", 1500); maxWaitForMove = sConfigMgr->GetOption("AiPlayerbot.MaxWaitForMove", 5000); + maxMovementSearch = sConfigMgr->GetOption("AiPlayerbot.MaxMovementSearchTime", 3); expireActionTime = sConfigMgr->GetOption("AiPlayerbot.ExpireActionTime", 5000); dispelAuraDuration = sConfigMgr->GetOption("AiPlayerbot.DispelAuraDuration", 7000); reactDelay = sConfigMgr->GetOption("AiPlayerbot.ReactDelay", 500); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index b3e5fdd7..22930b86 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -54,7 +54,8 @@ class PlayerbotAIConfig bool enabled; bool allowGuildBots, allowPlayerBots; - uint32 globalCoolDown, reactDelay, maxWaitForMove, expireActionTime, dispelAuraDuration, passiveDelay, repeatDelay, + uint32 globalCoolDown, reactDelay, maxWaitForMove, maxMovementSearchTime, expireActionTime, + dispelAuraDuration, passiveDelay, repeatDelay, errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay; float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, fleeDistance, tooCloseDistance, meleeDistance, followDistance, whisperDistance, contactDistance, diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 92a7cf3c..faf6a328 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -173,7 +173,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, return true; } else { float modifiedZ; - Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ); + Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ, sPlayerbotAIConfig->maxMovementSearchTime); if (modifiedZ == INVALID_HEIGHT) { return false; } @@ -1348,59 +1348,59 @@ bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float d return MoveNear(mapId, x, y, z, distance); } -float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step) -{ - if (!generatePath) { - return z; - } - float min_length = 100000.0f; - float current_z = INVALID_HEIGHT; - float modified_z; - float delta; - for (delta = 0.0f; delta <= range / 2; delta += step) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - for (delta = -step; delta >= -range / 2; delta -= step) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - for (delta = range / 2 + step; delta <= range; delta += 2) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - if (current_z == INVALID_HEIGHT && normal_only) { - return INVALID_HEIGHT; - } - if (current_z == INVALID_HEIGHT && !normal_only) { - return z; - } - return current_z; -} +// float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step) +// { +// if (!generatePath) { +// return z; +// } +// float min_length = 100000.0f; +// float current_z = INVALID_HEIGHT; +// float modified_z; +// float delta; +// for (delta = 0.0f; delta <= range / 2; delta += step) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// for (delta = -step; delta >= -range / 2; delta -= step) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// for (delta = range / 2 + step; delta <= range; delta += 2) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// if (current_z == INVALID_HEIGHT && normal_only) { +// return INVALID_HEIGHT; +// } +// if (current_z == INVALID_HEIGHT && !normal_only) { +// return z; +// } +// return current_z; +// } const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount, bool normal_only, float step) { diff --git a/src/strategy/actions/MovementActions.h b/src/strategy/actions/MovementActions.h index 93fc242b..2a605cb1 100644 --- a/src/strategy/actions/MovementActions.h +++ b/src/strategy/actions/MovementActions.h @@ -42,7 +42,7 @@ class MovementAction : public Action bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance); void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false); private: - float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool normal_only = false, float step = 8.0f); + // 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); };