movement for narrow room

This commit is contained in:
Yunfan Li
2023-09-05 15:11:40 +08:00
parent 560ec3cc9f
commit d053ac6850
2 changed files with 35 additions and 18 deletions

View File

@@ -148,23 +148,6 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// if (bot->Unit::IsFalling()) {
// bot->Say("I'm falling", LANG_UNIVERSAL);
// }
float modified_z;
float delta;
for (delta = -5.0f; delta <= 10.0f; delta++) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL) {
break;
}
}
if (delta > 10.0f) {
delta = 0.5f;
}
// if (delta > 10.0f) {
// return false;
// }
// z += 0.5f;
float distance = bot->GetDistance2d(x, y);
if (distance > sPlayerbotAIConfig->contactDistance)
{
@@ -183,7 +166,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
MotionMaster &mm = *bot->GetMotionMaster();
mm.Clear();
mm.MovePoint(mapId, x, y, modified_z, generatePath);
mm.MovePoint(mapId, x, y, SearchBestGroundZForPath(x, y, z), generatePath);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation());
return true;
}
@@ -1285,6 +1268,38 @@ 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, float range)
{
float modified_z;
float delta;
for (delta = 0.0f; delta <= range / 2; delta++) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL) {
return modified_z;
}
}
for (delta = -1.0f; delta >= -range / 2; delta--) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL) {
return modified_z;
}
}
for (delta = range / 2 + 1.0f; delta <= range; delta++) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL) {
return modified_z;
}
}
return z;
}
bool FleeAction::Execute(Event event)
{
// return Flee(AI_VALUE(Unit*, "current target"));

View File

@@ -40,6 +40,8 @@ class MovementAction : public Action
bool MoveAway(Unit* target);
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, float range = 10.0f);
};
class FleeAction : public MovementAction