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

@@ -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)
{

View File

@@ -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);
};