mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Movement overhead
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MovementActions.h"
|
#include "MovementActions.h"
|
||||||
|
#include "Map.h"
|
||||||
#include "MotionMaster.h"
|
#include "MotionMaster.h"
|
||||||
|
#include "MoveSplineInitArgs.h"
|
||||||
#include "MovementGenerator.h"
|
#include "MovementGenerator.h"
|
||||||
#include "ObjectDefines.h"
|
#include "ObjectDefines.h"
|
||||||
#include "ObjectGuid.h"
|
#include "ObjectGuid.h"
|
||||||
@@ -151,13 +153,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
|
|||||||
// }
|
// }
|
||||||
bool generatePath = !bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) &&
|
bool generatePath = !bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) &&
|
||||||
!bot->IsFlying() && !bot->HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !bot->IsInWater();
|
!bot->IsFlying() && !bot->HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !bot->IsInWater();
|
||||||
float modifiedZ = SearchBestGroundZForPath(x, y, z, generatePath, 20.0f, normal_only, 8.0f);
|
if (!generatePath) {
|
||||||
if (modifiedZ == INVALID_HEIGHT) {
|
float distance = bot->GetExactDist(x, y, z);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
float distance = bot->GetExactDist(x, y, modifiedZ);
|
|
||||||
if (distance > sPlayerbotAIConfig->contactDistance)
|
|
||||||
{
|
|
||||||
WaitForReach(distance);
|
WaitForReach(distance);
|
||||||
|
|
||||||
if (bot->IsSitState())
|
if (bot->IsSitState())
|
||||||
@@ -171,9 +168,36 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
|
|||||||
MotionMaster &mm = *bot->GetMotionMaster();
|
MotionMaster &mm = *bot->GetMotionMaster();
|
||||||
|
|
||||||
mm.Clear();
|
mm.Clear();
|
||||||
mm.MovePoint(mapId, x, y, modifiedZ, generatePath);
|
mm.MovePoint(mapId, x, y, z, 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;
|
||||||
|
} else {
|
||||||
|
float modifiedZ;
|
||||||
|
Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ);
|
||||||
|
if (modifiedZ == INVALID_HEIGHT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
float distance = bot->GetExactDist(x, y, modifiedZ);
|
||||||
|
if (distance > sPlayerbotAIConfig->contactDistance)
|
||||||
|
{
|
||||||
|
WaitForReach(distance);
|
||||||
|
|
||||||
|
if (bot->IsSitState())
|
||||||
|
bot->SetStandState(UNIT_STAND_STATE_STAND);
|
||||||
|
|
||||||
|
if (bot->IsNonMeleeSpellCast(true))
|
||||||
|
{
|
||||||
|
bot->CastStop();
|
||||||
|
botAI->InterruptSpell();
|
||||||
|
}
|
||||||
|
MotionMaster &mm = *bot->GetMotionMaster();
|
||||||
|
|
||||||
|
mm.Clear();
|
||||||
|
mm.MoveSplinePath(&path);
|
||||||
|
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -1378,6 +1402,55 @@ float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool g
|
|||||||
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)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
modified_z = INVALID_HEIGHT;
|
||||||
|
float tempZ = bot->GetMapWaterOrGroundLevel(x, y, z);
|
||||||
|
PathGenerator gen(bot);
|
||||||
|
gen.CalculatePath(x, y, tempZ);
|
||||||
|
Movement::PointsArray result = gen.GetPath();
|
||||||
|
float min_length = gen.getPathLength();
|
||||||
|
if (gen.GetPathType() == PATHFIND_NORMAL && abs(tempZ - z) < 0.5f) {
|
||||||
|
modified_z = tempZ;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Start searching
|
||||||
|
if (gen.GetPathType() == PATHFIND_NORMAL) {
|
||||||
|
found = true;
|
||||||
|
modified_z = tempZ;
|
||||||
|
}
|
||||||
|
int count = 1;
|
||||||
|
for (float delta = step; count < maxSearchCount / 2 + 1; count++, delta += step) {
|
||||||
|
tempZ = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
|
||||||
|
PathGenerator gen(bot);
|
||||||
|
gen.CalculatePath(x, y, tempZ);
|
||||||
|
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
||||||
|
found = true;
|
||||||
|
min_length = gen.getPathLength();
|
||||||
|
result = gen.GetPath();
|
||||||
|
modified_z = tempZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (float delta = -step; count < maxSearchCount; count++, delta -= step) {
|
||||||
|
tempZ = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
|
||||||
|
PathGenerator gen(bot);
|
||||||
|
gen.CalculatePath(x, y, tempZ);
|
||||||
|
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
||||||
|
found = true;
|
||||||
|
min_length = gen.getPathLength();
|
||||||
|
result = gen.GetPath();
|
||||||
|
modified_z = tempZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found && normal_only) {
|
||||||
|
return Movement::PointsArray{};
|
||||||
|
}
|
||||||
|
if (!found && !normal_only) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool FleeAction::Execute(Event event)
|
bool FleeAction::Execute(Event event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class MovementAction : public Action
|
|||||||
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FleeAction : public MovementAction
|
class FleeAction : public MovementAction
|
||||||
|
|||||||
Reference in New Issue
Block a user