mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 15:40:45 +01:00
Core/Movement: implement a parameter override to force 2D wandering
MovePositionToFirstCollision implementation can cause Z coordinate modification, making flying units wander up and down unintentionally
This commit is contained in:
@@ -594,12 +594,12 @@ void MotionMaster::MoveTargetedHome()
|
||||
}
|
||||
}
|
||||
|
||||
void MotionMaster::MoveRandom(float wanderDistance)
|
||||
void MotionMaster::MoveRandom(float wanderDistance/* = 0.0f*/, bool force2DPositionRelocation/* = false*/)
|
||||
{
|
||||
if (_owner->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveRandom: '{}', started random movement (spawnDist: {})", _owner->GetGUID().ToString(), wanderDistance);
|
||||
Add(new RandomMovementGenerator<Creature>(wanderDistance), MOTION_SLOT_DEFAULT);
|
||||
Add(new RandomMovementGenerator<Creature>(wanderDistance, force2DPositionRelocation), MOTION_SLOT_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ class TC_GAME_API MotionMaster
|
||||
|
||||
void MoveIdle();
|
||||
void MoveTargetedHome();
|
||||
void MoveRandom(float wanderDistance = 0.0f);
|
||||
void MoveRandom(float wanderDistance = 0.0f, bool force2DPositionRelocation = false);
|
||||
void MoveFollow(Unit* target, float dist, ChaseAngle angle, MovementSlot slot = MOTION_SLOT_ACTIVE);
|
||||
void MoveChase(Unit* target, Optional<ChaseRange> dist = {}, Optional<ChaseAngle> angle = {});
|
||||
void MoveChase(Unit* target, float dist, float angle) { MoveChase(target, ChaseRange(dist), ChaseAngle(angle)); }
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "Random.h"
|
||||
|
||||
template<class T>
|
||||
RandomMovementGenerator<T>::RandomMovementGenerator(float distance) : _timer(0), _reference(), _wanderDistance(distance), _wanderSteps(0)
|
||||
RandomMovementGenerator<T>::RandomMovementGenerator(float distance/* = 0.0f*/, bool force2DPositionRelocation/* = false*/) : _timer(0), _reference(), _wanderDistance(distance), _wanderSteps(0), _force2DPositionRelocation(force2DPositionRelocation)
|
||||
{
|
||||
this->Mode = MOTION_MODE_DEFAULT;
|
||||
this->Priority = MOTION_PRIORITY_NORMAL;
|
||||
@@ -33,7 +33,7 @@ RandomMovementGenerator<T>::RandomMovementGenerator(float distance) : _timer(0),
|
||||
this->BaseUnitState = UNIT_STATE_ROAMING;
|
||||
}
|
||||
|
||||
template RandomMovementGenerator<Creature>::RandomMovementGenerator(float/* distance*/);
|
||||
template RandomMovementGenerator<Creature>::RandomMovementGenerator(float/* distance*/, bool/* force2DPositionRelocation*/);
|
||||
|
||||
template<class T>
|
||||
MovementGeneratorType RandomMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
@@ -124,7 +124,10 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
|
||||
Position position(_reference);
|
||||
float distance = frand(0.f, _wanderDistance);
|
||||
float angle = frand(0.f, float(M_PI * 2));
|
||||
owner->MovePositionToFirstCollision(position, distance, angle);
|
||||
if (_force2DPositionRelocation)
|
||||
owner->GetNearPoint2D(nullptr, position.m_positionX, position.m_positionY, distance, frand(0.f, 2.f * float(M_PI)));
|
||||
else
|
||||
owner->MovePositionToFirstCollision(position, distance, angle);
|
||||
|
||||
// Check if the destination is in LOS
|
||||
if (!owner->IsWithinLOS(position.GetPositionX(), position.GetPositionY(), position.GetPositionZ()))
|
||||
|
||||
@@ -28,7 +28,7 @@ template<class T>
|
||||
class RandomMovementGenerator : public MovementGeneratorMedium<T, RandomMovementGenerator<T>>
|
||||
{
|
||||
public:
|
||||
explicit RandomMovementGenerator(float distance = 0.0f);
|
||||
explicit RandomMovementGenerator(float distance = 0.0f, bool force2DPositionRelocation = false);
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
@@ -51,6 +51,7 @@ class RandomMovementGenerator : public MovementGeneratorMedium<T, RandomMovement
|
||||
Position _reference;
|
||||
float _wanderDistance;
|
||||
uint8 _wanderSteps;
|
||||
bool _force2DPositionRelocation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user