Movement search time config

This commit is contained in:
Yunfan Li
2024-04-11 19:47:20 +08:00
parent f2884d94e6
commit ad4fa11175
5 changed files with 62 additions and 56 deletions

View File

@@ -256,6 +256,10 @@ AiPlayerbot.GlobalCooldown = 500
# Max wait time when moving # Max wait time when moving
AiPlayerbot.MaxWaitForMove = 5000 AiPlayerbot.MaxWaitForMove = 5000
# 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

View File

@@ -53,6 +53,7 @@ bool PlayerbotAIConfig::Initialize()
globalCoolDown = sConfigMgr->GetOption<int32>("AiPlayerbot.GlobalCooldown", 1500); globalCoolDown = sConfigMgr->GetOption<int32>("AiPlayerbot.GlobalCooldown", 1500);
maxWaitForMove = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxWaitForMove", 5000); maxWaitForMove = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxWaitForMove", 5000);
maxMovementSearch = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxMovementSearchTime", 3);
expireActionTime = sConfigMgr->GetOption<int32>("AiPlayerbot.ExpireActionTime", 5000); expireActionTime = sConfigMgr->GetOption<int32>("AiPlayerbot.ExpireActionTime", 5000);
dispelAuraDuration = sConfigMgr->GetOption<int32>("AiPlayerbot.DispelAuraDuration", 7000); dispelAuraDuration = sConfigMgr->GetOption<int32>("AiPlayerbot.DispelAuraDuration", 7000);
reactDelay = sConfigMgr->GetOption<int32>("AiPlayerbot.ReactDelay", 500); reactDelay = sConfigMgr->GetOption<int32>("AiPlayerbot.ReactDelay", 500);

View File

@@ -54,7 +54,8 @@ class PlayerbotAIConfig
bool enabled; bool enabled;
bool allowGuildBots, allowPlayerBots; 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; errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay;
float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance,
fleeDistance, tooCloseDistance, meleeDistance, followDistance, whisperDistance, contactDistance, fleeDistance, tooCloseDistance, meleeDistance, followDistance, whisperDistance, contactDistance,

View File

@@ -173,7 +173,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
return true; return true;
} else { } else {
float modifiedZ; float modifiedZ;
Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ); Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ, sPlayerbotAIConfig->maxMovementSearchTime);
if (modifiedZ == INVALID_HEIGHT) { if (modifiedZ == INVALID_HEIGHT) {
return false; 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); 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) // float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step)
{ // {
if (!generatePath) { // if (!generatePath) {
return z; // return z;
} // }
float min_length = 100000.0f; // float min_length = 100000.0f;
float current_z = INVALID_HEIGHT; // float current_z = INVALID_HEIGHT;
float modified_z; // float modified_z;
float delta; // float delta;
for (delta = 0.0f; delta <= range / 2; delta += step) { // for (delta = 0.0f; delta <= range / 2; delta += step) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); // modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot); // PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z); // gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { // if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength(); // min_length = gen.getPathLength();
current_z = modified_z; // current_z = modified_z;
if (abs(current_z - z) < 0.5f) { // if (abs(current_z - z) < 0.5f) {
return current_z; // return current_z;
} // }
} // }
} // }
for (delta = -step; delta >= -range / 2; delta -= step) { // for (delta = -step; delta >= -range / 2; delta -= step) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); // modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot); // PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z); // gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { // if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength(); // min_length = gen.getPathLength();
current_z = modified_z; // current_z = modified_z;
if (abs(current_z - z) < 0.5f) { // if (abs(current_z - z) < 0.5f) {
return current_z; // return current_z;
} // }
} // }
} // }
for (delta = range / 2 + step; delta <= range; delta += 2) { // for (delta = range / 2 + step; delta <= range; delta += 2) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); // modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot); // PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z); // gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { // if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength(); // min_length = gen.getPathLength();
current_z = modified_z; // current_z = modified_z;
if (abs(current_z - z) < 0.5f) { // if (abs(current_z - z) < 0.5f) {
return current_z; // return current_z;
} // }
} // }
} // }
if (current_z == INVALID_HEIGHT && normal_only) { // if (current_z == INVALID_HEIGHT && normal_only) {
return INVALID_HEIGHT; // return INVALID_HEIGHT;
} // }
if (current_z == INVALID_HEIGHT && !normal_only) { // if (current_z == INVALID_HEIGHT && !normal_only) {
return z; // return z;
} // }
return current_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) const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount, bool normal_only, float step)
{ {

View File

@@ -42,7 +42,7 @@ class MovementAction : public Action
bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance); 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); void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false);
private: 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); const Movement::PointsArray SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount = 5, bool normal_only = false, float step = 8.0f);
}; };