Fix movement on slope

This commit is contained in:
Yunfan Li
2024-01-07 19:10:06 +08:00
parent 3372bee04f
commit b3c9f8d796
2 changed files with 33 additions and 15 deletions

View File

@@ -166,11 +166,11 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
!bot->IsFlying() && !bot->HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !bot->IsInWater(); !bot->IsFlying() && !bot->HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !bot->IsInWater();
MotionMaster &mm = *bot->GetMotionMaster(); MotionMaster &mm = *bot->GetMotionMaster();
mm.Clear(); float modifiedZ = SearchBestGroundZForPath(x, y, z, generatePath, 20.0f, normal_only);
float modifiedZ = SearchBestGroundZForPath(x, y, z, generatePath, normal_only);
if (modifiedZ == INVALID_HEIGHT) { if (modifiedZ == INVALID_HEIGHT) {
return false; return false;
} }
// mm.Clear();
mm.MovePoint(mapId, x, y, modifiedZ, generatePath); mm.MovePoint(mapId, x, y, modifiedZ, generatePath);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation()); AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation());
return true; return true;
@@ -1294,37 +1294,55 @@ float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool g
if (!generatePath) { if (!generatePath) {
return z; return z;
} }
float min_length = MAX_PATH_LENGTH;
float current_z = INVALID_HEIGHT;
float modified_z; float modified_z;
float delta; float delta;
for (delta = 0.0f; delta <= range / 2; delta++) { for (delta = 0.0f; delta <= range / 2; 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) {
return 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.1f) {
// return current_z;
// }
} }
} }
for (delta = -1.0f; delta >= -range / 2; delta--) { for (delta = -1.0f; delta >= -range / 2; 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) { if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
return modified_z; min_length = gen.getPathLength();
current_z = modified_z;
// if (abs(current_z - z) < 0.1f) {
// return current_z;
// }
} }
} }
for (delta = range / 2 + 1.0f; delta <= range; delta++) { for (delta = range / 2 + 1.0f; 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) { if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
return modified_z; min_length = gen.getPathLength();
current_z = modified_z;
// if (abs(current_z - z) < 0.1f) {
// return current_z;
// }
} }
} }
if (normal_only) { if (current_z == INVALID_HEIGHT && normal_only) {
return INVALID_HEIGHT; return INVALID_HEIGHT;
} }
if (current_z == INVALID_HEIGHT && !normal_only) {
return z; return z;
} }
return current_z;
}
bool FleeAction::Execute(Event event) bool FleeAction::Execute(Event event)
@@ -1395,7 +1413,7 @@ bool SetFacingTargetAction::Execute(Event event)
return true; return true;
sServerFacade->SetFacingTo(bot, target); sServerFacade->SetFacingTo(bot, target);
botAI->SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown); botAI->SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
return true; return true;
} }

View File

@@ -41,7 +41,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 = 10.0f, bool normal_only = false); float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool normal_only = false);
}; };
class FleeAction : public MovementAction class FleeAction : public MovementAction