mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Misc: movement header cleanup
This commit is contained in:
@@ -28,8 +28,6 @@
|
||||
#include "TotemAI.h"
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
|
||||
namespace AIRegistry
|
||||
{
|
||||
@@ -55,7 +53,7 @@ namespace AIRegistry
|
||||
(new GameObjectAIFactory<SmartGameObjectAI>("SmartGameObjectAI"))->RegisterSelf();
|
||||
|
||||
(new IdleMovementFactory())->RegisterSelf();
|
||||
(new MovementGeneratorFactory<RandomMovementGenerator<Creature>>(RANDOM_MOTION_TYPE))->RegisterSelf();
|
||||
(new MovementGeneratorFactory<WaypointMovementGenerator<Creature>>(WAYPOINT_MOTION_TYPE))->RegisterSelf();
|
||||
(new RandomMovementFactory())->RegisterSelf();
|
||||
(new WaypointMovementFactory())->RegisterSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@ namespace FactorySelector
|
||||
|
||||
MovementGenerator* SelectMovementGenerator(Unit* unit)
|
||||
{
|
||||
MovementGeneratorType type = IDLE_MOTION_TYPE;
|
||||
MovementGeneratorType type = unit->GetDefaultMovementType();
|
||||
if (Creature* creature = unit->ToCreature())
|
||||
if (!creature->GetPlayerMovingMe())
|
||||
type = unit->ToCreature()->GetDefaultMovementType();
|
||||
type = creature->GetDefaultMovementType();
|
||||
|
||||
MovementGeneratorCreator const* mv_factory = sMovementGeneratorRegistry->GetRegistryItem(type);
|
||||
return ASSERT_NOTNULL(mv_factory)->Create(unit);
|
||||
|
||||
@@ -241,7 +241,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
|
||||
bool CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction = true) const;
|
||||
bool _IsTargetAcceptable(Unit const* target) const;
|
||||
|
||||
MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
|
||||
MovementGeneratorType GetDefaultMovementType() const override { return m_defaultMovementType; }
|
||||
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
|
||||
|
||||
void RemoveCorpse(bool setSpawnTime = true, bool destroyForNearbyPlayers = true);
|
||||
|
||||
@@ -8542,10 +8542,9 @@ void Unit::UpdateSpeed(UnitMoveType mtype)
|
||||
|
||||
if (creature->HasUnitTypeMask(UNIT_MASK_MINION) && !creature->IsInCombat())
|
||||
{
|
||||
MovementGenerator* top = creature->GetMotionMaster()->topOrNull();
|
||||
if (top && top->GetMovementGeneratorType() == FOLLOW_MOTION_TYPE)
|
||||
if (GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE)
|
||||
{
|
||||
Unit* followed = ASSERT_NOTNULL(dynamic_cast<AbstractFollower*>(top))->GetTarget();
|
||||
Unit* followed = ASSERT_NOTNULL(dynamic_cast<AbstractFollower*>(GetMotionMaster()->top()))->GetTarget();
|
||||
if (followed && followed->GetGUID() == GetOwnerGUID() && !followed->IsInCombat())
|
||||
{
|
||||
float ownerSpeed = followed->GetSpeedRate(mtype);
|
||||
@@ -10164,6 +10163,11 @@ void Unit::PropagateSpeedChange()
|
||||
GetMotionMaster()->PropagateSpeedChange();
|
||||
}
|
||||
|
||||
MovementGeneratorType Unit::GetDefaultMovementType() const
|
||||
{
|
||||
return IDLE_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void Unit::StopMoving()
|
||||
{
|
||||
ClearUnitState(UNIT_STATE_MOVING);
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
#include "Util.h"
|
||||
#include <map>
|
||||
|
||||
#define WORLD_TRIGGER 12999
|
||||
#define VISUAL_WAYPOINT 1 // Creature Entry ID used for waypoints show, visible only for GMs
|
||||
#define WORLD_TRIGGER 12999
|
||||
|
||||
#define MAX_SPELL_CHARM 4
|
||||
#define MAX_SPELL_VEHICLE 6
|
||||
@@ -90,6 +91,7 @@ class Vehicle;
|
||||
class VehicleJoinEvent;
|
||||
|
||||
enum ZLiquidStatus : uint32;
|
||||
enum MovementGeneratorType : uint8;
|
||||
|
||||
typedef std::list<Unit*> UnitList;
|
||||
|
||||
@@ -1532,6 +1534,7 @@ class TC_GAME_API Unit : public WorldObject
|
||||
|
||||
MotionMaster* GetMotionMaster() { return i_motionMaster; }
|
||||
MotionMaster const* GetMotionMaster() const { return i_motionMaster; }
|
||||
virtual MovementGeneratorType GetDefaultMovementType() const;
|
||||
|
||||
bool IsStopped() const { return !(HasUnitState(UNIT_STATE_MOVING)); }
|
||||
void StopMoving();
|
||||
|
||||
@@ -17,29 +17,31 @@
|
||||
*/
|
||||
|
||||
#include "MotionMaster.h"
|
||||
#include "ChaseMovementGenerator.h"
|
||||
#include "ConfusedMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAISelector.h"
|
||||
#include "DBCStores.h"
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptSystem.h"
|
||||
#include "Unit.h"
|
||||
#include "WaypointDefines.h"
|
||||
|
||||
#include "ChaseMovementGenerator.h"
|
||||
#include "ConfusedMovementGenerator.h"
|
||||
#include "FleeingMovementGenerator.h"
|
||||
#include "FlightPathMovementGenerator.h"
|
||||
#include "FollowMovementGenerator.h"
|
||||
#include "FormationMovementGenerator.h"
|
||||
#include "HomeMovementGenerator.h"
|
||||
#include "IdleMovementGenerator.h"
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "Player.h"
|
||||
#include "PointMovementGenerator.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
#include "ScriptSystem.h"
|
||||
#include "SplineChainMovementGenerator.h"
|
||||
#include "Unit.h"
|
||||
#include "WaypointDefines.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
|
||||
inline MovementGenerator* GetIdleMovementGenerator()
|
||||
@@ -70,6 +72,13 @@ MotionMaster::~MotionMaster()
|
||||
}
|
||||
}
|
||||
|
||||
MovementGenerator* MotionMaster::top() const
|
||||
{
|
||||
ASSERT(!empty());
|
||||
|
||||
return _slot[_top];
|
||||
}
|
||||
|
||||
void MotionMaster::Initialize()
|
||||
{
|
||||
// clear ALL movement generators (including default)
|
||||
@@ -97,14 +106,14 @@ void MotionMaster::UpdateMotion(uint32 diff)
|
||||
|
||||
ASSERT(!empty());
|
||||
|
||||
_cleanFlag |= MMCF_UPDATE;
|
||||
_cleanFlag |= MOTIONMMASTER_CLEANFLAG_UPDATE;
|
||||
if (!top()->Update(_owner, diff))
|
||||
{
|
||||
_cleanFlag &= ~MMCF_UPDATE;
|
||||
_cleanFlag &= ~MOTIONMMASTER_CLEANFLAG_UPDATE;
|
||||
MovementExpired();
|
||||
}
|
||||
else
|
||||
_cleanFlag &= ~MMCF_UPDATE;
|
||||
_cleanFlag &= ~MOTIONMMASTER_CLEANFLAG_UPDATE;
|
||||
|
||||
if (!_expireList.empty())
|
||||
ClearExpireList();
|
||||
@@ -112,12 +121,12 @@ void MotionMaster::UpdateMotion(uint32 diff)
|
||||
|
||||
void MotionMaster::Clear(bool reset /*= true*/)
|
||||
{
|
||||
if (_cleanFlag & MMCF_UPDATE)
|
||||
if (_cleanFlag & MOTIONMMASTER_CLEANFLAG_UPDATE)
|
||||
{
|
||||
if (reset)
|
||||
_cleanFlag |= MMCF_RESET;
|
||||
_cleanFlag |= MOTIONMMASTER_CLEANFLAG_RESET;
|
||||
else
|
||||
_cleanFlag &= ~MMCF_RESET;
|
||||
_cleanFlag &= ~MOTIONMMASTER_CLEANFLAG_RESET;
|
||||
DelayedClean();
|
||||
}
|
||||
else
|
||||
@@ -129,7 +138,7 @@ void MotionMaster::Clear(MovementSlot slot)
|
||||
if (empty() || slot >= MAX_MOTION_SLOT)
|
||||
return;
|
||||
|
||||
if (_cleanFlag & MMCF_UPDATE)
|
||||
if (_cleanFlag & MOTIONMMASTER_CLEANFLAG_UPDATE)
|
||||
DelayedClean(slot);
|
||||
else
|
||||
DirectClean(slot);
|
||||
@@ -137,12 +146,12 @@ void MotionMaster::Clear(MovementSlot slot)
|
||||
|
||||
void MotionMaster::MovementExpired(bool reset /*= true*/)
|
||||
{
|
||||
if (_cleanFlag & MMCF_UPDATE)
|
||||
if (_cleanFlag & MOTIONMMASTER_CLEANFLAG_UPDATE)
|
||||
{
|
||||
if (reset)
|
||||
_cleanFlag |= MMCF_RESET;
|
||||
_cleanFlag |= MOTIONMMASTER_CLEANFLAG_RESET;
|
||||
else
|
||||
_cleanFlag &= ~MMCF_RESET;
|
||||
_cleanFlag &= ~MOTIONMMASTER_CLEANFLAG_RESET;
|
||||
DelayedExpire();
|
||||
}
|
||||
else
|
||||
@@ -308,6 +317,11 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
|
||||
}
|
||||
}
|
||||
|
||||
void MotionMaster::MovePoint(uint32 id, Position const& pos, bool generatePath/* = true*/, Optional<float> finalOrient/* = {}*/)
|
||||
{
|
||||
MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath, finalOrient);
|
||||
}
|
||||
|
||||
void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath, Optional<float> finalOrient)
|
||||
{
|
||||
if (_owner->GetTypeId() == TYPEID_PLAYER)
|
||||
@@ -444,6 +458,11 @@ void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ)
|
||||
MoveJump(x, y, z, 0.0f, speedXY, speedZ);
|
||||
}
|
||||
|
||||
void MotionMaster::MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id/* = EVENT_JUMP*/, bool hasOrientation/* = false*/)
|
||||
{
|
||||
MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), speedXY, speedZ, id, hasOrientation);
|
||||
}
|
||||
|
||||
void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id, bool hasOrientation /* = false*/)
|
||||
{
|
||||
TC_LOG_DEBUG("misc", "Unit (GUID: %u) jumps to point (X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), x, y, z);
|
||||
@@ -725,7 +744,7 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
|
||||
if (MovementGenerator* curr = _slot[slot])
|
||||
{
|
||||
_slot[slot] = nullptr; // in case a new one is generated in this slot during directdelete
|
||||
if (_top == slot && (_cleanFlag & MMCF_UPDATE))
|
||||
if (_top == slot && (_cleanFlag & MOTIONMMASTER_CLEANFLAG_UPDATE))
|
||||
DelayedDelete(curr);
|
||||
else
|
||||
DirectDelete(curr);
|
||||
@@ -865,8 +884,8 @@ void MotionMaster::ClearExpireList()
|
||||
Initialize();
|
||||
else if (NeedInitTop())
|
||||
InitTop();
|
||||
else if (_cleanFlag & MMCF_RESET)
|
||||
else if (_cleanFlag & MOTIONMMASTER_CLEANFLAG_RESET)
|
||||
top()->Reset(_owner);
|
||||
|
||||
_cleanFlag &= ~MMCF_RESET;
|
||||
_cleanFlag &= ~MOTIONMMASTER_CLEANFLAG_RESET;
|
||||
}
|
||||
|
||||
@@ -20,104 +20,23 @@
|
||||
#define MOTIONMASTER_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Errors.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "Optional.h"
|
||||
#include "Position.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "SharedDefines.h"
|
||||
#include <vector>
|
||||
|
||||
class MovementGenerator;
|
||||
class Unit;
|
||||
class PathGenerator;
|
||||
struct Position;
|
||||
struct SplineChainLink;
|
||||
struct SplineChainResumeInfo;
|
||||
struct WaypointPath;
|
||||
|
||||
// Creature Entry ID used for waypoints show, visible only for GMs
|
||||
#define VISUAL_WAYPOINT 1
|
||||
// assume it is 25 yard per 0.6 second
|
||||
#define SPEED_CHARGE 42.0f
|
||||
|
||||
enum MovementGeneratorType : uint8
|
||||
{
|
||||
IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
|
||||
RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
|
||||
WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
|
||||
MAX_DB_MOTION_TYPE = 3, // Below motion types can't be set in DB.
|
||||
CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
|
||||
CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h
|
||||
HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
|
||||
FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
|
||||
POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
|
||||
FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
|
||||
DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
|
||||
ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h
|
||||
ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h
|
||||
TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h
|
||||
FOLLOW_MOTION_TYPE = 14,
|
||||
ROTATE_MOTION_TYPE = 15,
|
||||
EFFECT_MOTION_TYPE = 16,
|
||||
SPLINE_CHAIN_MOTION_TYPE = 17, // SplineChainMovementGenerator.h
|
||||
FORMATION_MOTION_TYPE = 18, // FormationMovementGenerator.h
|
||||
MAX_MOTION_TYPE // limit
|
||||
};
|
||||
|
||||
enum MovementSlot : uint8
|
||||
{
|
||||
MOTION_SLOT_IDLE = 0,
|
||||
MOTION_SLOT_ACTIVE,
|
||||
MOTION_SLOT_CONTROLLED,
|
||||
MAX_MOTION_SLOT
|
||||
};
|
||||
|
||||
enum MMCleanFlag
|
||||
{
|
||||
MMCF_NONE = 0,
|
||||
MMCF_UPDATE = 1, // Clear or Expire called from update
|
||||
MMCF_RESET = 2 // Flag if need top()->Reset()
|
||||
};
|
||||
|
||||
enum RotateDirection
|
||||
{
|
||||
ROTATE_DIRECTION_LEFT,
|
||||
ROTATE_DIRECTION_RIGHT
|
||||
};
|
||||
|
||||
struct ChaseRange
|
||||
{
|
||||
ChaseRange(float range) : MinRange(range > CONTACT_DISTANCE ? 0 : range - CONTACT_DISTANCE), MinTolerance(range), MaxRange(range + CONTACT_DISTANCE), MaxTolerance(range) {}
|
||||
ChaseRange(float min, float max) : MinRange(min), MinTolerance(std::min(min + CONTACT_DISTANCE, (min + max) / 2)), MaxRange(max), MaxTolerance(std::max(max - CONTACT_DISTANCE, MinTolerance)) {}
|
||||
ChaseRange(float min, float tMin, float tMax, float max) : MinRange(min), MinTolerance(tMin), MaxRange(max), MaxTolerance(tMax) {}
|
||||
|
||||
// this contains info that informs how we should path!
|
||||
float MinRange; // we have to move if we are within this range... (min. attack range)
|
||||
float MinTolerance; // ...and if we are, we will move this far away
|
||||
float MaxRange; // we have to move if we are outside this range... (max. attack range)
|
||||
float MaxTolerance; // ...and if we are, we will move into this range
|
||||
};
|
||||
|
||||
struct ChaseAngle
|
||||
{
|
||||
ChaseAngle(float angle, float tol = M_PI_4) : RelativeAngle(Position::NormalizeOrientation(angle)), Tolerance(tol) {}
|
||||
|
||||
float RelativeAngle; // we want to be at this angle relative to the target (0 = front, M_PI = back)
|
||||
float Tolerance; // but we'll tolerate anything within +- this much
|
||||
|
||||
float UpperBound() const { return Position::NormalizeOrientation(RelativeAngle + Tolerance); }
|
||||
float LowerBound() const { return Position::NormalizeOrientation(RelativeAngle - Tolerance); }
|
||||
bool IsAngleOkay(float relAngle) const
|
||||
{
|
||||
float const diff = std::abs(relAngle - RelativeAngle);
|
||||
return (std::min(diff, float(2 * M_PI) - diff) <= Tolerance);
|
||||
}
|
||||
};
|
||||
|
||||
class TC_GAME_API MotionMaster
|
||||
{
|
||||
public:
|
||||
explicit MotionMaster(Unit* unit) : _owner(unit), _top(-1), _cleanFlag(MMCF_NONE)
|
||||
explicit MotionMaster(Unit* unit) : _owner(unit), _top(-1), _cleanFlag(MOTIONMMASTER_CLEANFLAG_NONE)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i)
|
||||
{
|
||||
@@ -129,8 +48,7 @@ class TC_GAME_API MotionMaster
|
||||
|
||||
bool empty() const { return (_top < 0); }
|
||||
int size() const { return _top + 1; }
|
||||
MovementGenerator* topOrNull() const { return empty() ? nullptr : top(); }
|
||||
MovementGenerator* top() const { ASSERT(!empty()); return _slot[_top]; }
|
||||
MovementGenerator* top() const;
|
||||
|
||||
void Initialize();
|
||||
void InitDefault();
|
||||
@@ -157,10 +75,7 @@ class TC_GAME_API MotionMaster
|
||||
void MoveChase(Unit* target, float dist, float angle = 0.0f) { MoveChase(target, Optional<ChaseRange>(dist), Optional<ChaseAngle>(angle)); }
|
||||
void MoveConfused();
|
||||
void MoveFleeing(Unit* enemy, uint32 time = 0);
|
||||
void MovePoint(uint32 id, Position const& pos, bool generatePath = true, Optional<float> finalOrient = {})
|
||||
{
|
||||
MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath, finalOrient);
|
||||
}
|
||||
void MovePoint(uint32 id, Position const& pos, bool generatePath = true, Optional<float> finalOrient = {});
|
||||
void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true, Optional<float> finalOrient = {});
|
||||
|
||||
/* Makes the unit move toward the target until it is at a certain distance from it. The unit then stops.
|
||||
@@ -177,10 +92,7 @@ class TC_GAME_API MotionMaster
|
||||
void MoveCharge(PathGenerator const& path, float speed = SPEED_CHARGE);
|
||||
void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ);
|
||||
void MoveJumpTo(float angle, float speedXY, float speedZ);
|
||||
void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false)
|
||||
{
|
||||
MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), speedXY, speedZ, id, hasOrientation);
|
||||
}
|
||||
void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false);
|
||||
void MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false);
|
||||
void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount);
|
||||
void MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk);
|
||||
|
||||
49
src/server/game/Movement/MovementDefines.cpp
Normal file
49
src/server/game/Movement/MovementDefines.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "Position.h"
|
||||
#include <algorithm>
|
||||
|
||||
// ---- ChaseRange ---- //
|
||||
|
||||
ChaseRange::ChaseRange(float range) : MinRange(range > CONTACT_DISTANCE ? 0 : range - CONTACT_DISTANCE), MinTolerance(range), MaxRange(range + CONTACT_DISTANCE), MaxTolerance(range) { }
|
||||
ChaseRange::ChaseRange(float _minRange, float _maxRange) : MinRange(_minRange), MinTolerance(std::min(_minRange + CONTACT_DISTANCE, (_minRange + _maxRange) / 2)), MaxRange(_maxRange), MaxTolerance(std::max(_maxRange - CONTACT_DISTANCE, MinTolerance)) { }
|
||||
ChaseRange::ChaseRange(float _minRange, float _minTolerance, float _maxTolerance, float _maxRange) : MinRange(_minRange), MinTolerance(_minTolerance), MaxRange(_maxRange), MaxTolerance(_maxTolerance) { }
|
||||
|
||||
// ---- ChaseAngle ---- //
|
||||
|
||||
ChaseAngle::ChaseAngle(float angle, float _tolerance/* = M_PI_4*/) : RelativeAngle(Position::NormalizeOrientation(angle)), Tolerance(_tolerance) { }
|
||||
|
||||
float ChaseAngle::UpperBound() const
|
||||
{
|
||||
return Position::NormalizeOrientation(RelativeAngle + Tolerance);
|
||||
}
|
||||
|
||||
float ChaseAngle::LowerBound() const
|
||||
{
|
||||
return Position::NormalizeOrientation(RelativeAngle - Tolerance);
|
||||
}
|
||||
|
||||
bool ChaseAngle::IsAngleOkay(float relativeAngle) const
|
||||
{
|
||||
float const diff = std::abs(relativeAngle - RelativeAngle);
|
||||
|
||||
return (std::min(diff, float(2 * M_PI) - diff) <= Tolerance);
|
||||
}
|
||||
95
src/server/game/Movement/MovementDefines.h
Normal file
95
src/server/game/Movement/MovementDefines.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_MOVEMENTDEFINES_H
|
||||
#define TRINITY_MOVEMENTDEFINES_H
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define SPEED_CHARGE 42.0f // assume it is 25 yard per 0.6 second
|
||||
|
||||
enum MovementGeneratorType : uint8
|
||||
{
|
||||
IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
|
||||
RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
|
||||
WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
|
||||
MAX_DB_MOTION_TYPE = 3, // Below motion types can't be set in DB.
|
||||
CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
|
||||
CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h
|
||||
HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
|
||||
FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
|
||||
POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
|
||||
FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
|
||||
DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
|
||||
ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h
|
||||
ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h
|
||||
TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h
|
||||
FOLLOW_MOTION_TYPE = 14,
|
||||
ROTATE_MOTION_TYPE = 15,
|
||||
EFFECT_MOTION_TYPE = 16,
|
||||
SPLINE_CHAIN_MOTION_TYPE = 17, // SplineChainMovementGenerator.h
|
||||
FORMATION_MOTION_TYPE = 18, // FormationMovementGenerator.h
|
||||
MAX_MOTION_TYPE // limit
|
||||
};
|
||||
|
||||
enum MovementSlot : uint8
|
||||
{
|
||||
MOTION_SLOT_IDLE = 0,
|
||||
MOTION_SLOT_ACTIVE,
|
||||
MOTION_SLOT_CONTROLLED,
|
||||
MAX_MOTION_SLOT
|
||||
};
|
||||
|
||||
enum MotionMasterCleanFlags
|
||||
{
|
||||
MOTIONMMASTER_CLEANFLAG_NONE = 0,
|
||||
MOTIONMMASTER_CLEANFLAG_UPDATE = 1, // Clear or Expire called from update
|
||||
MOTIONMMASTER_CLEANFLAG_RESET = 2 // Flag if need top()->Reset()
|
||||
};
|
||||
|
||||
enum RotateDirection : uint8
|
||||
{
|
||||
ROTATE_DIRECTION_LEFT = 0,
|
||||
ROTATE_DIRECTION_RIGHT
|
||||
};
|
||||
|
||||
struct ChaseRange
|
||||
{
|
||||
ChaseRange(float range);
|
||||
ChaseRange(float _minRange, float _maxRange);
|
||||
ChaseRange(float _minRange, float _minTolerance, float _maxTolerance, float _maxRange);
|
||||
|
||||
// this contains info that informs how we should path!
|
||||
float MinRange; // we have to move if we are within this range... (min. attack range)
|
||||
float MinTolerance; // ...and if we are, we will move this far away
|
||||
float MaxRange; // we have to move if we are outside this range... (max. attack range)
|
||||
float MaxTolerance; // ...and if we are, we will move into this range
|
||||
};
|
||||
|
||||
struct ChaseAngle
|
||||
{
|
||||
ChaseAngle(float angle, float _tolerance = M_PI_4);
|
||||
|
||||
float RelativeAngle; // we want to be at this angle relative to the target (0 = front, M_PI = back)
|
||||
float Tolerance; // but we'll tolerate anything within +- this much
|
||||
|
||||
float UpperBound() const;
|
||||
float LowerBound() const;
|
||||
bool IsAngleOkay(float relativeAngle) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -17,12 +17,33 @@
|
||||
*/
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "IdleMovementGenerator.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
|
||||
MovementGenerator::~MovementGenerator() { }
|
||||
|
||||
IdleMovementFactory::IdleMovementFactory() : MovementGeneratorCreator(IDLE_MOTION_TYPE) { }
|
||||
|
||||
MovementGenerator* IdleMovementFactory::Create(Unit* /*object*/) const
|
||||
{
|
||||
static IdleMovementGenerator instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
RandomMovementFactory::RandomMovementFactory() : MovementGeneratorCreator(RANDOM_MOTION_TYPE) { }
|
||||
|
||||
MovementGenerator* RandomMovementFactory::Create(Unit* /*object*/) const
|
||||
{
|
||||
return new RandomMovementGenerator<Creature>();
|
||||
}
|
||||
|
||||
WaypointMovementFactory::WaypointMovementFactory() : MovementGeneratorCreator(WAYPOINT_MOTION_TYPE) { }
|
||||
|
||||
MovementGenerator* WaypointMovementFactory::Create(Unit* /*object*/) const
|
||||
{
|
||||
return new WaypointMovementGenerator<Creature>();
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#define TRINITY_MOVEMENTGENERATOR_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "ObjectRegistry.h"
|
||||
#include "FactoryHolder.h"
|
||||
#include "Common.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "ObjectRegistry.h"
|
||||
|
||||
class Creature;
|
||||
class Unit;
|
||||
|
||||
enum MovementGeneratorType : uint8;
|
||||
|
||||
class TC_GAME_API MovementGenerator
|
||||
{
|
||||
public:
|
||||
@@ -42,32 +43,31 @@ class TC_GAME_API MovementGenerator
|
||||
virtual void Pause(uint32/* timer = 0*/) { } // timer in ms
|
||||
virtual void Resume(uint32/* overrideTimer = 0*/) { } // timer in ms
|
||||
|
||||
// used by Evade code for select point to evade with expected restart default movement
|
||||
virtual bool GetResetPosition(Unit*, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
|
||||
virtual bool GetResetPosition(Unit*, float&/* x*/, float&/* y*/, float&/* z*/) { return false; } // used by Evade code for select point to evade with expected restart default movement
|
||||
};
|
||||
|
||||
template<class T, class D>
|
||||
class MovementGeneratorMedium : public MovementGenerator
|
||||
{
|
||||
public:
|
||||
void Initialize(Unit* u) override
|
||||
void Initialize(Unit* owner) override
|
||||
{
|
||||
(static_cast<D*>(this))->DoInitialize(static_cast<T*>(u));
|
||||
(static_cast<D*>(this))->DoInitialize(static_cast<T*>(owner));
|
||||
}
|
||||
|
||||
void Finalize(Unit* u) override
|
||||
void Finalize(Unit* owner) override
|
||||
{
|
||||
(static_cast<D*>(this))->DoFinalize(static_cast<T*>(u));
|
||||
(static_cast<D*>(this))->DoFinalize(static_cast<T*>(owner));
|
||||
}
|
||||
|
||||
void Reset(Unit* u) override
|
||||
void Reset(Unit* owner) override
|
||||
{
|
||||
(static_cast<D*>(this))->DoReset(static_cast<T*>(u));
|
||||
(static_cast<D*>(this))->DoReset(static_cast<T*>(owner));
|
||||
}
|
||||
|
||||
bool Update(Unit* u, uint32 time_diff) override
|
||||
bool Update(Unit* owner, uint32 diff) override
|
||||
{
|
||||
return (static_cast<D*>(this))->DoUpdate(static_cast<T*>(u), time_diff);
|
||||
return (static_cast<D*>(this))->DoUpdate(static_cast<T*>(owner), diff);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,7 +86,21 @@ struct MovementGeneratorFactory : public MovementGeneratorCreator
|
||||
|
||||
struct IdleMovementFactory : public MovementGeneratorCreator
|
||||
{
|
||||
IdleMovementFactory() : MovementGeneratorCreator(IDLE_MOTION_TYPE) { }
|
||||
IdleMovementFactory();
|
||||
|
||||
MovementGenerator* Create(Unit* object) const override;
|
||||
};
|
||||
|
||||
struct RandomMovementFactory : public MovementGeneratorCreator
|
||||
{
|
||||
RandomMovementFactory();
|
||||
|
||||
MovementGenerator* Create(Unit* object) const override;
|
||||
};
|
||||
|
||||
struct WaypointMovementFactory : public MovementGeneratorCreator
|
||||
{
|
||||
WaypointMovementFactory();
|
||||
|
||||
MovementGenerator* Create(Unit* object) const override;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "ChaseMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "G3DPosition.hpp"
|
||||
#include "MotionMaster.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "PathGenerator.h"
|
||||
@@ -26,10 +27,10 @@
|
||||
|
||||
static bool IsMutualChase(Unit* owner, Unit* target)
|
||||
{
|
||||
MovementGenerator const* gen = target->GetMotionMaster()->topOrNull();
|
||||
if (!gen || gen->GetMovementGeneratorType() != CHASE_MOTION_TYPE)
|
||||
if (target->GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE)
|
||||
return false;
|
||||
return (static_cast<ChaseMovementGenerator const*>(gen)->GetTarget() == owner);
|
||||
|
||||
return (static_cast<ChaseMovementGenerator const*>(target->GetMotionMaster()->top())->GetTarget() == owner);
|
||||
}
|
||||
|
||||
static bool PositionOkay(Unit* owner, Unit* target, Optional<float> minDistance, Optional<float> maxDistance, Optional<ChaseAngle> angle)
|
||||
@@ -49,6 +50,7 @@ void ChaseMovementGenerator::Initialize(Unit* owner)
|
||||
{
|
||||
owner->AddUnitState(UNIT_STATE_CHASE);
|
||||
owner->SetWalk(false);
|
||||
_path = nullptr;
|
||||
}
|
||||
|
||||
bool ChaseMovementGenerator::Update(Unit* owner, uint32 diff)
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
#define TRINITY_CHASEMOVEMENTGENERATOR_H
|
||||
|
||||
#include "AbstractFollower.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "Optional.h"
|
||||
#include "Position.h"
|
||||
|
||||
class PathGenerator;
|
||||
class Unit;
|
||||
@@ -28,17 +30,16 @@ class Unit;
|
||||
class ChaseMovementGenerator : public MovementGenerator, public AbstractFollower
|
||||
{
|
||||
public:
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return CHASE_MOTION_TYPE; }
|
||||
|
||||
ChaseMovementGenerator(Unit* target, Optional<ChaseRange> range = {}, Optional<ChaseAngle> angle = {});
|
||||
explicit ChaseMovementGenerator(Unit* target, Optional<ChaseRange> range = {}, Optional<ChaseAngle> angle = {});
|
||||
~ChaseMovementGenerator();
|
||||
|
||||
void Initialize(Unit* owner) override;
|
||||
void Reset(Unit* owner) override { Initialize(owner); }
|
||||
bool Update(Unit* owner, uint32 diff) override;
|
||||
void Finalize(Unit* owner) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return CHASE_MOTION_TYPE; }
|
||||
|
||||
void UnitSpeedChanged() override { _lastTargetPosition.Relocate(0.0f,0.0f,0.0f); }
|
||||
void UnitSpeedChanged() override { _lastTargetPosition.Relocate(0.0f, 0.0f, 0.0f); }
|
||||
|
||||
private:
|
||||
static constexpr uint32 RANGE_CHECK_INTERVAL = 100; // time (ms) until we attempt to recalculate
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "ConfusedMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "PathGenerator.h"
|
||||
@@ -25,9 +26,12 @@
|
||||
#include "Random.h"
|
||||
|
||||
template<class T>
|
||||
ConfusedMovementGenerator<T>::~ConfusedMovementGenerator()
|
||||
ConfusedMovementGenerator<T>::~ConfusedMovementGenerator() = default;
|
||||
|
||||
template<class T>
|
||||
MovementGeneratorType ConfusedMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
{
|
||||
delete _path;
|
||||
return CONFUSED_MOTION_TYPE;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -42,6 +46,7 @@ void ConfusedMovementGenerator<T>::DoInitialize(T* owner)
|
||||
|
||||
_timer.Reset(0);
|
||||
owner->GetPosition(_x, _y, _z);
|
||||
_path = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -60,6 +65,7 @@ bool ConfusedMovementGenerator<T>::DoUpdate(T* owner, uint32 diff)
|
||||
{
|
||||
_interrupt = true;
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -78,9 +84,11 @@ bool ConfusedMovementGenerator<T>::DoUpdate(T* owner, uint32 diff)
|
||||
owner->MovePositionToFirstCollision(destination, distance, angle);
|
||||
|
||||
if (!_path)
|
||||
_path = new PathGenerator(owner);
|
||||
{
|
||||
_path = std::make_unique<PathGenerator>(owner);
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
}
|
||||
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
bool result = _path->CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH))
|
||||
{
|
||||
@@ -120,6 +128,8 @@ void ConfusedMovementGenerator<Creature>::DoFinalize(Creature* unit)
|
||||
|
||||
template ConfusedMovementGenerator<Player>::~ConfusedMovementGenerator();
|
||||
template ConfusedMovementGenerator<Creature>::~ConfusedMovementGenerator();
|
||||
template MovementGeneratorType ConfusedMovementGenerator<Player>::GetMovementGeneratorType() const;
|
||||
template MovementGeneratorType ConfusedMovementGenerator<Creature>::GetMovementGeneratorType() const;
|
||||
template void ConfusedMovementGenerator<Player>::DoInitialize(Player*);
|
||||
template void ConfusedMovementGenerator<Creature>::DoInitialize(Creature*);
|
||||
template void ConfusedMovementGenerator<Player>::DoReset(Player*);
|
||||
|
||||
@@ -22,14 +22,17 @@
|
||||
#include "MovementGenerator.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class PathGenerator;
|
||||
|
||||
template<class T>
|
||||
class ConfusedMovementGenerator : public MovementGeneratorMedium< T, ConfusedMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
explicit ConfusedMovementGenerator() : _path(nullptr), _timer(0), _x(0.f), _y(0.f), _z(0.f), _interrupt(false) { }
|
||||
explicit ConfusedMovementGenerator() : _timer(0), _x(0.f), _y(0.f), _z(0.f), _interrupt(false) { }
|
||||
~ConfusedMovementGenerator();
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return CONFUSED_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void UnitSpeedChanged() override { } //TODO
|
||||
|
||||
void DoInitialize(T*);
|
||||
void DoFinalize(T*);
|
||||
@@ -37,7 +40,7 @@ class ConfusedMovementGenerator : public MovementGeneratorMedium< T, ConfusedMov
|
||||
bool DoUpdate(T*, uint32);
|
||||
|
||||
private:
|
||||
PathGenerator* _path;
|
||||
std::unique_ptr<PathGenerator> _path;
|
||||
TimeTracker _timer;
|
||||
float _x, _y, _z;
|
||||
bool _interrupt;
|
||||
|
||||
@@ -17,22 +17,26 @@
|
||||
*/
|
||||
|
||||
#include "FleeingMovementGenerator.h"
|
||||
#include "VMapFactory.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Creature.h"
|
||||
#include "Player.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "Player.h"
|
||||
#include "Unit.h"
|
||||
|
||||
#define MIN_QUIET_DISTANCE 28.0f
|
||||
#define MAX_QUIET_DISTANCE 43.0f
|
||||
|
||||
template<class T>
|
||||
FleeingMovementGenerator<T>::~FleeingMovementGenerator()
|
||||
FleeingMovementGenerator<T>::~FleeingMovementGenerator() = default;
|
||||
|
||||
template<class T>
|
||||
MovementGeneratorType FleeingMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
{
|
||||
delete _path;
|
||||
return FLEEING_MOTION_TYPE;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -44,6 +48,7 @@ void FleeingMovementGenerator<T>::DoInitialize(T* owner)
|
||||
owner->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
|
||||
owner->AddUnitState(UNIT_STATE_FLEEING);
|
||||
SetTargetLocation(owner);
|
||||
_path = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -84,6 +89,7 @@ bool FleeingMovementGenerator<T>::DoUpdate(T* owner, uint32 diff)
|
||||
{
|
||||
_interrupt = true;
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -106,6 +112,7 @@ void FleeingMovementGenerator<T>::SetTargetLocation(T* owner)
|
||||
{
|
||||
_interrupt = true;
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,9 +129,11 @@ void FleeingMovementGenerator<T>::SetTargetLocation(T* owner)
|
||||
}
|
||||
|
||||
if (!_path)
|
||||
_path = new PathGenerator(owner);
|
||||
{
|
||||
_path = std::make_unique<PathGenerator>(owner);
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
}
|
||||
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
bool result = _path->CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH))
|
||||
{
|
||||
@@ -168,7 +177,7 @@ void FleeingMovementGenerator<T>::GetPoint(T* owner, Position &position)
|
||||
distance = frand(0.4f, 1.0f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
|
||||
angle = -casterAngle + frand(-float(M_PI) / 4.0f, float(M_PI) / 4.0f);
|
||||
}
|
||||
else // we are inside quiet range
|
||||
else // we are inside quiet range
|
||||
{
|
||||
distance = frand(0.6f, 1.2f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
|
||||
angle = frand(0.0f, 2.0f * float(M_PI));
|
||||
@@ -179,6 +188,8 @@ void FleeingMovementGenerator<T>::GetPoint(T* owner, Position &position)
|
||||
|
||||
template FleeingMovementGenerator<Player>::~FleeingMovementGenerator();
|
||||
template FleeingMovementGenerator<Creature>::~FleeingMovementGenerator();
|
||||
template MovementGeneratorType FleeingMovementGenerator<Player>::GetMovementGeneratorType() const;
|
||||
template MovementGeneratorType FleeingMovementGenerator<Creature>::GetMovementGeneratorType() const;
|
||||
template void FleeingMovementGenerator<Player>::DoInitialize(Player*);
|
||||
template void FleeingMovementGenerator<Creature>::DoInitialize(Creature*);
|
||||
template void FleeingMovementGenerator<Player>::DoReset(Player*);
|
||||
@@ -192,6 +203,11 @@ template void FleeingMovementGenerator<Creature>::GetPoint(Creature*, Position &
|
||||
|
||||
//---- TimedFleeingMovementGenerator
|
||||
|
||||
MovementGeneratorType TimedFleeingMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return TIMED_FLEEING_MOTION_TYPE;
|
||||
}
|
||||
|
||||
bool TimedFleeingMovementGenerator::Update(Unit* owner, uint32 time_diff)
|
||||
{
|
||||
if (!owner->IsAlive())
|
||||
|
||||
@@ -20,18 +20,22 @@
|
||||
#define TRINITY_FLEEINGMOVEMENTGENERATOR_H
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class Creature;
|
||||
class PathGenerator;
|
||||
struct Position;
|
||||
|
||||
template<class T>
|
||||
class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
explicit FleeingMovementGenerator(ObjectGuid fleeTargetGUID) : _path(nullptr), _fleeTargetGUID(fleeTargetGUID), _timer(0), _interrupt(false) { }
|
||||
explicit FleeingMovementGenerator(ObjectGuid fleeTargetGUID) : _fleeTargetGUID(fleeTargetGUID), _timer(0), _interrupt(false) { }
|
||||
~FleeingMovementGenerator();
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return FLEEING_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void UnitSpeedChanged() override { } //TODO
|
||||
|
||||
void DoInitialize(T*);
|
||||
void DoFinalize(T*);
|
||||
@@ -42,7 +46,7 @@ class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovem
|
||||
void SetTargetLocation(T*);
|
||||
void GetPoint(T*, Position &position);
|
||||
|
||||
PathGenerator* _path;
|
||||
std::unique_ptr<PathGenerator> _path;
|
||||
ObjectGuid _fleeTargetGUID;
|
||||
TimeTracker _timer;
|
||||
bool _interrupt;
|
||||
@@ -53,7 +57,7 @@ class TimedFleeingMovementGenerator : public FleeingMovementGenerator<Creature>
|
||||
public:
|
||||
explicit TimedFleeingMovementGenerator(ObjectGuid fleeTargetGUID, uint32 time) : FleeingMovementGenerator<Creature>(fleeTargetGUID), _totalFleeTime(time) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return TIMED_FLEEING_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
bool Update(Unit*, uint32) override;
|
||||
void Finalize(Unit*) override;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "DBCStores.h"
|
||||
#include "Log.h"
|
||||
#include "MapManager.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "ObjectMgr.h"
|
||||
@@ -177,6 +178,11 @@ bool FlightPathMovementGenerator::DoUpdate(Player* player, uint32 /*diff*/)
|
||||
return _currentNode < (_path.size() - 1);
|
||||
}
|
||||
|
||||
MovementGeneratorType FlightPathMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return FLIGHT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport()
|
||||
{
|
||||
if (_path.empty() || _currentNode >= _path.size())
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "DBCStructure.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "PathMovementBase.h"
|
||||
#include <deque>
|
||||
|
||||
class Player;
|
||||
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
void DoReset(Player*);
|
||||
void DoFinalize(Player*);
|
||||
bool DoUpdate(Player*, uint32);
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return FLIGHT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
TaxiPathNodeList const& GetPath() { return _path; }
|
||||
uint32 GetPathAtMapEnd() const;
|
||||
|
||||
@@ -18,18 +18,20 @@
|
||||
#include "FollowMovementGenerator.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "Optional.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "Pet.h"
|
||||
#include "Unit.h"
|
||||
#include "Util.h"
|
||||
|
||||
FollowMovementGenerator::FollowMovementGenerator(Unit* target, float range, ChaseAngle angle) : AbstractFollower(ASSERT_NOTNULL(target)), _range(range), _angle(angle) {}
|
||||
FollowMovementGenerator::~FollowMovementGenerator() {}
|
||||
FollowMovementGenerator::~FollowMovementGenerator() = default;
|
||||
|
||||
static bool PositionOkay(Unit* owner, Unit* target, float range, Optional<ChaseAngle> angle = {})
|
||||
{
|
||||
if (owner->GetExactDistSq(target) > square(owner->GetCombatReach() + target->GetCombatReach() + range))
|
||||
return false;
|
||||
|
||||
return !angle || angle->IsAngleOkay(target->GetRelativeAngle(owner));
|
||||
}
|
||||
|
||||
@@ -37,6 +39,7 @@ void FollowMovementGenerator::Initialize(Unit* owner)
|
||||
{
|
||||
owner->AddUnitState(UNIT_STATE_FOLLOW);
|
||||
UpdatePetSpeed(owner);
|
||||
_path = nullptr;
|
||||
}
|
||||
|
||||
bool FollowMovementGenerator::Update(Unit* owner, uint32 diff)
|
||||
@@ -142,10 +145,12 @@ void FollowMovementGenerator::Finalize(Unit* owner)
|
||||
void FollowMovementGenerator::UpdatePetSpeed(Unit* owner)
|
||||
{
|
||||
if (Pet* oPet = owner->ToPet())
|
||||
{
|
||||
if (!GetTarget() || GetTarget()->GetGUID() == owner->GetOwnerGUID())
|
||||
{
|
||||
oPet->UpdateSpeed(MOVE_RUN);
|
||||
oPet->UpdateSpeed(MOVE_WALK);
|
||||
oPet->UpdateSpeed(MOVE_SWIM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,30 +19,31 @@
|
||||
#define TRINITY_FOLLOWMOVEMENTGENERATOR_H
|
||||
|
||||
#include "AbstractFollower.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "Position.h"
|
||||
|
||||
class PathGenerator;
|
||||
class Unit;
|
||||
|
||||
#define FOLLOW_RANGE_TOLERANCE 1.0f
|
||||
|
||||
class FollowMovementGenerator : public MovementGenerator, public AbstractFollower
|
||||
{
|
||||
public:
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return FOLLOW_MOTION_TYPE; }
|
||||
|
||||
FollowMovementGenerator(Unit* target, float range, ChaseAngle angle);
|
||||
explicit FollowMovementGenerator(Unit* target, float range, ChaseAngle angle);
|
||||
~FollowMovementGenerator();
|
||||
|
||||
void Initialize(Unit* owner) override;
|
||||
void Reset(Unit* owner) override { Initialize(owner); }
|
||||
bool Update(Unit* owner, uint32 diff) override;
|
||||
void Finalize(Unit* owner) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return FOLLOW_MOTION_TYPE; }
|
||||
|
||||
void UnitSpeedChanged() override { _lastTargetPosition.Relocate(0.0f, 0.0f, 0.0f); }
|
||||
|
||||
private:
|
||||
static constexpr uint32 CHECK_INTERVAL = 500;
|
||||
// static inline const when?
|
||||
#define FOLLOW_RANGE_TOLERANCE 1.0f
|
||||
|
||||
void UpdatePetSpeed(Unit* owner);
|
||||
|
||||
|
||||
@@ -18,9 +18,15 @@
|
||||
#include "FormationMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
|
||||
MovementGeneratorType FormationMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return FORMATION_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void FormationMovementGenerator::DoInitialize(Creature* owner)
|
||||
{
|
||||
owner->AddUnitState(UNIT_STATE_ROAMING);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define TRINITY_FORMATIONMOVEMENTGENERATOR_H
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "Position.h"
|
||||
|
||||
class Creature;
|
||||
|
||||
@@ -27,7 +28,7 @@ class FormationMovementGenerator : public MovementGeneratorMedium< Creature, For
|
||||
public:
|
||||
explicit FormationMovementGenerator(uint32 id, Position destination, uint32 moveType, bool run, bool orientation) : _movementId(id), _destination(destination), _moveType(moveType), _run(run), _orientation(orientation), _recalculateSpeed(false), _interrupt(false) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return FORMATION_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
void DoInitialize(Creature*);
|
||||
void DoFinalize(Creature*);
|
||||
|
||||
@@ -19,19 +19,20 @@
|
||||
#include "HomeMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "PathGenerator.h"
|
||||
|
||||
template<class T>
|
||||
HomeMovementGenerator<T>::~HomeMovementGenerator() { }
|
||||
|
||||
template<>
|
||||
HomeMovementGenerator<Creature>::~HomeMovementGenerator()
|
||||
MovementGeneratorType HomeMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
{
|
||||
delete _path;
|
||||
return HOME_MOTION_TYPE;
|
||||
}
|
||||
|
||||
template MovementGeneratorType HomeMovementGenerator<Creature>::GetMovementGeneratorType() const;
|
||||
|
||||
template<class T>
|
||||
void HomeMovementGenerator<T>::SetTargetLocation(T*) { }
|
||||
|
||||
|
||||
@@ -25,10 +25,9 @@ template <class T>
|
||||
class HomeMovementGenerator : public MovementGeneratorMedium< T, HomeMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
explicit HomeMovementGenerator() : _path(nullptr), _arrived(false), _skipToHome(false) { }
|
||||
~HomeMovementGenerator();
|
||||
explicit HomeMovementGenerator() : _arrived(false), _skipToHome(false) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return HOME_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
void DoInitialize(T*);
|
||||
void DoFinalize(T*);
|
||||
@@ -38,7 +37,6 @@ class HomeMovementGenerator : public MovementGeneratorMedium< T, HomeMovementGen
|
||||
private:
|
||||
void SetTargetLocation(T*);
|
||||
|
||||
PathGenerator* _path;
|
||||
bool _arrived;
|
||||
bool _skipToHome;
|
||||
};
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "IdleMovementGenerator.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "MovementDefines.h"
|
||||
|
||||
// StopMoving is needed to make unit stop if its last movement generator expires
|
||||
// But it should not be sent otherwise there are many redundent packets
|
||||
@@ -33,6 +34,11 @@ void IdleMovementGenerator::Reset(Unit* owner)
|
||||
owner->StopMoving();
|
||||
}
|
||||
|
||||
MovementGeneratorType IdleMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return IDLE_MOTION_TYPE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------//
|
||||
|
||||
void RotateMovementGenerator::Initialize(Unit* owner)
|
||||
@@ -74,6 +80,11 @@ bool RotateMovementGenerator::Update(Unit* owner, uint32 diff)
|
||||
return true;
|
||||
}
|
||||
|
||||
MovementGeneratorType RotateMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return ROTATE_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void RotateMovementGenerator::Finalize(Unit* owner)
|
||||
{
|
||||
owner->ClearUnitState(UNIT_STATE_ROTATING);
|
||||
@@ -113,8 +124,18 @@ bool DistractMovementGenerator::Update(Unit* /*owner*/, uint32 diff)
|
||||
return true;
|
||||
}
|
||||
|
||||
MovementGeneratorType DistractMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return DISTRACT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------//
|
||||
|
||||
MovementGeneratorType AssistanceDistractMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return ASSISTANCE_DISTRACT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void AssistanceDistractMovementGenerator::Finalize(Unit* owner)
|
||||
{
|
||||
owner->ClearUnitState(UNIT_STATE_DISTRACTED);
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "MovementGenerator.h"
|
||||
#include "Timer.h"
|
||||
|
||||
enum RotateDirection : uint8;
|
||||
|
||||
class IdleMovementGenerator : public MovementGenerator
|
||||
{
|
||||
public:
|
||||
@@ -29,7 +31,7 @@ class IdleMovementGenerator : public MovementGenerator
|
||||
void Finalize(Unit*) override { }
|
||||
void Reset(Unit*) override;
|
||||
bool Update(Unit*, uint32) override { return true; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return IDLE_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
};
|
||||
|
||||
class RotateMovementGenerator : public MovementGenerator
|
||||
@@ -41,7 +43,7 @@ class RotateMovementGenerator : public MovementGenerator
|
||||
void Finalize(Unit*) override;
|
||||
void Reset(Unit* owner) override { Initialize(owner); }
|
||||
bool Update(Unit*, uint32) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return ROTATE_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
private:
|
||||
uint32 _duration, _maxDuration;
|
||||
@@ -57,7 +59,7 @@ class DistractMovementGenerator : public MovementGenerator
|
||||
void Finalize(Unit*) override;
|
||||
void Reset(Unit* owner) override { Initialize(owner); }
|
||||
bool Update(Unit*, uint32) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return DISTRACT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
private:
|
||||
uint32 _timer;
|
||||
@@ -68,7 +70,7 @@ class AssistanceDistractMovementGenerator : public DistractMovementGenerator
|
||||
public:
|
||||
explicit AssistanceDistractMovementGenerator(uint32 timer) : DistractMovementGenerator(timer) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return ASSISTANCE_DISTRACT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void Finalize(Unit*) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,15 +17,23 @@
|
||||
*/
|
||||
|
||||
#include "PointMovementGenerator.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "Player.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "World.h"
|
||||
|
||||
//----- Point Movement Generator
|
||||
|
||||
template<class T>
|
||||
MovementGeneratorType PointMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
{
|
||||
return POINT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void PointMovementGenerator<T>::DoInitialize(T* owner)
|
||||
{
|
||||
@@ -124,6 +132,8 @@ void PointMovementGenerator<Creature>::MovementInform(Creature* owner)
|
||||
owner->AI()->MovementInform(POINT_MOTION_TYPE, _movementId);
|
||||
}
|
||||
|
||||
template MovementGeneratorType PointMovementGenerator<Player>::GetMovementGeneratorType() const;
|
||||
template MovementGeneratorType PointMovementGenerator<Creature>::GetMovementGeneratorType() const;
|
||||
template void PointMovementGenerator<Player>::DoInitialize(Player*);
|
||||
template void PointMovementGenerator<Creature>::DoInitialize(Creature*);
|
||||
template void PointMovementGenerator<Player>::DoFinalize(Player*);
|
||||
@@ -135,6 +145,11 @@ template bool PointMovementGenerator<Creature>::DoUpdate(Creature*, uint32);
|
||||
|
||||
//---- AssistanceMovementGenerator
|
||||
|
||||
MovementGeneratorType AssistanceMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return ASSISTANCE_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void AssistanceMovementGenerator::Finalize(Unit* owner)
|
||||
{
|
||||
owner->ClearUnitState(UNIT_STATE_ROAMING);
|
||||
@@ -152,6 +167,11 @@ bool EffectMovementGenerator::Update(Unit* owner, uint32 /*diff*/)
|
||||
return !owner->movespline->Finalized();
|
||||
}
|
||||
|
||||
MovementGeneratorType EffectMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return EFFECT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void EffectMovementGenerator::Finalize(Unit* owner)
|
||||
{
|
||||
MovementInform(owner);
|
||||
|
||||
@@ -28,9 +28,9 @@ template<class T>
|
||||
class PointMovementGenerator : public MovementGeneratorMedium< T, PointMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, float speed = 0.0f, Optional<float> finalOrient = {}) : _movementId(id), _x(x), _y(y), _z(z), _speed(speed), _generatePath(generatePath), _recalculateSpeed(false), _interrupt(false), _finalOrient(finalOrient) { }
|
||||
explicit PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, float speed = 0.0f, Optional<float> finalOrient = {}) : _movementId(id), _x(x), _y(y), _z(z), _speed(speed), _generatePath(generatePath), _recalculateSpeed(false), _interrupt(false), _finalOrient(finalOrient) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return POINT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
void DoInitialize(T*);
|
||||
void DoFinalize(T*);
|
||||
@@ -55,9 +55,9 @@ class PointMovementGenerator : public MovementGeneratorMedium< T, PointMovementG
|
||||
class AssistanceMovementGenerator : public PointMovementGenerator<Creature>
|
||||
{
|
||||
public:
|
||||
AssistanceMovementGenerator(float x, float y, float z) : PointMovementGenerator<Creature>(0, x, y, z, true) { }
|
||||
explicit AssistanceMovementGenerator(float x, float y, float z) : PointMovementGenerator<Creature>(0, x, y, z, true) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return ASSISTANCE_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void Finalize(Unit*) override;
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ class EffectMovementGenerator : public MovementGenerator
|
||||
void Finalize(Unit*) override;
|
||||
void Reset(Unit*) override { }
|
||||
bool Update(Unit*, uint32) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return EFFECT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
private:
|
||||
void MovementInform(Unit*);
|
||||
|
||||
@@ -19,20 +19,25 @@
|
||||
#include "RandomMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "Map.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "Random.h"
|
||||
|
||||
template<class T>
|
||||
RandomMovementGenerator<T>::~RandomMovementGenerator() { }
|
||||
RandomMovementGenerator<T>::~RandomMovementGenerator() = default;
|
||||
|
||||
template<>
|
||||
RandomMovementGenerator<Creature>::~RandomMovementGenerator()
|
||||
template RandomMovementGenerator<Creature>::~RandomMovementGenerator();
|
||||
|
||||
template<class T>
|
||||
MovementGeneratorType RandomMovementGenerator<T>::GetMovementGeneratorType() const
|
||||
{
|
||||
delete _path;
|
||||
return RANDOM_MOTION_TYPE;
|
||||
}
|
||||
|
||||
template MovementGeneratorType RandomMovementGenerator<Creature>::GetMovementGeneratorType() const;
|
||||
|
||||
template<class T>
|
||||
void RandomMovementGenerator<T>::DoInitialize(T*) { }
|
||||
|
||||
@@ -50,6 +55,7 @@ void RandomMovementGenerator<Creature>::DoInitialize(Creature* owner)
|
||||
_wanderDistance = owner->GetRespawnRadius();
|
||||
|
||||
_timer.Reset(0);
|
||||
_path = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -85,6 +91,7 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
|
||||
{
|
||||
_interrupt = true;
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,9 +105,11 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
|
||||
uint32 resetTimer = roll_chance_i(50) ? urand(5000, 10000) : urand(1000, 2000);
|
||||
|
||||
if (!_path)
|
||||
_path = new PathGenerator(owner);
|
||||
{
|
||||
_path = std::make_unique<PathGenerator>(owner);
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
}
|
||||
|
||||
_path->SetPathLengthLimit(30.0f);
|
||||
bool result = _path->CalculatePath(position.GetPositionX(), position.GetPositionY(), position.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH))
|
||||
{
|
||||
@@ -134,6 +143,7 @@ bool RandomMovementGenerator<Creature>::DoUpdate(Creature* owner, uint32 diff)
|
||||
{
|
||||
_interrupt = true;
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -20,16 +20,20 @@
|
||||
#define TRINITY_RANDOMMOTIONGENERATOR_H
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "Position.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class PathGenerator;
|
||||
|
||||
template<class T>
|
||||
class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
explicit RandomMovementGenerator(float distance = 0.0f) : _path(nullptr), _timer(0), _reference(), _wanderDistance(distance), _interrupt(false) { }
|
||||
explicit RandomMovementGenerator(float distance = 0.0f) : _timer(0), _reference(), _wanderDistance(distance), _interrupt(false) { }
|
||||
~RandomMovementGenerator();
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return RANDOM_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void UnitSpeedChanged() override { } //TODO
|
||||
|
||||
void DoInitialize(T*);
|
||||
void DoFinalize(T*);
|
||||
@@ -39,7 +43,7 @@ class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovemen
|
||||
private:
|
||||
void SetRandomLocation(T*);
|
||||
|
||||
PathGenerator* _path;
|
||||
std::unique_ptr<PathGenerator> _path;
|
||||
TimeTracker _timer;
|
||||
Position _reference;
|
||||
float _wanderDistance;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "SplineChainMovementGenerator.h"
|
||||
#include "Creature.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "Log.h"
|
||||
@@ -132,6 +134,11 @@ bool SplineChainMovementGenerator::Update(Unit* me, uint32 diff)
|
||||
return true;
|
||||
}
|
||||
|
||||
MovementGeneratorType SplineChainMovementGenerator::GetMovementGeneratorType() const
|
||||
{
|
||||
return SPLINE_CHAIN_MOTION_TYPE;
|
||||
}
|
||||
|
||||
SplineChainResumeInfo SplineChainMovementGenerator::GetResumeInfo(Unit const* me) const
|
||||
{
|
||||
if (!_nextIndex)
|
||||
@@ -148,11 +155,11 @@ SplineChainResumeInfo SplineChainMovementGenerator::GetResumeInfo(Unit const* me
|
||||
|
||||
/* static */ void SplineChainMovementGenerator::GetResumeInfo(Unit const* me, SplineChainResumeInfo& info)
|
||||
{
|
||||
if (MovementGenerator const* activeGen = me->GetMotionMaster()->GetMotionSlot(MOTION_SLOT_ACTIVE))
|
||||
if (MovementGenerator const* activeGenerator = me->GetMotionMaster()->GetMotionSlot(MOTION_SLOT_ACTIVE))
|
||||
{
|
||||
if (activeGen->GetMovementGeneratorType() == SPLINE_CHAIN_MOTION_TYPE)
|
||||
if (activeGenerator->GetMovementGeneratorType() == SPLINE_CHAIN_MOTION_TYPE)
|
||||
{
|
||||
info = reinterpret_cast<SplineChainMovementGenerator const*>(activeGen)->GetResumeInfo(me);
|
||||
info = reinterpret_cast<SplineChainMovementGenerator const*>(activeGenerator)->GetResumeInfo(me);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,22 @@
|
||||
|
||||
#include "SplineChain.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include <vector>
|
||||
|
||||
class Unit;
|
||||
|
||||
class TC_GAME_API SplineChainMovementGenerator : public MovementGenerator
|
||||
{
|
||||
public:
|
||||
explicit SplineChainMovementGenerator(uint32 id, std::vector<SplineChainLink> const& chain, bool walk = false) : _id(id), _chain(chain), _chainSize(chain.size()), _walk(walk), finished(false), _nextIndex(0), _nextFirstWP(0), _msToNext(0) { }
|
||||
explicit SplineChainMovementGenerator(SplineChainResumeInfo const& info) : _id(info.PointID), _chain(*info.Chain), _chainSize(info.Chain->size()), _walk(info.IsWalkMode), finished(info.SplineIndex >= info.Chain->size()), _nextIndex(info.SplineIndex), _nextFirstWP(info.PointIndex), _msToNext(info.TimeToNext) { }
|
||||
|
||||
void Initialize(Unit* me) override;
|
||||
void Finalize(Unit* me) override;
|
||||
void Reset(Unit* /*me*/) override { };
|
||||
bool Update(Unit* me, uint32 diff) override;
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return SPLINE_CHAIN_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
|
||||
// Builds info that can later be used to resume this spline chain movement at the current position
|
||||
static void GetResumeInfo(Unit const* me, SplineChainResumeInfo& info);
|
||||
// Leaving the object method public for people that know what they're doing to use
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "CreatureAI.h"
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "ObjectMgr.h"
|
||||
@@ -38,6 +39,11 @@ WaypointMovementGenerator<Creature>::WaypointMovementGenerator(WaypointPath& pat
|
||||
_path = &path;
|
||||
}
|
||||
|
||||
MovementGeneratorType WaypointMovementGenerator<Creature>::GetMovementGeneratorType() const
|
||||
{
|
||||
return WAYPOINT_MOTION_TYPE;
|
||||
}
|
||||
|
||||
void WaypointMovementGenerator<Creature>::DoInitialize(Creature* creature)
|
||||
{
|
||||
_done = false;
|
||||
@@ -257,7 +263,7 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
|
||||
// check if there is a wait time for the next movement
|
||||
if (!_nextMoveTime.Passed())
|
||||
{
|
||||
// dont update wait timer while moving
|
||||
// update timer since it's not moving
|
||||
_nextMoveTime.Update(diff);
|
||||
if (_nextMoveTime.Passed())
|
||||
{
|
||||
@@ -268,7 +274,7 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
|
||||
else // if it's not moving and there is no timer, assume node is reached
|
||||
{
|
||||
OnArrived(creature); // hooks and wait timer reset (if necessary)
|
||||
_isArrivalDone = true; // signals that the next move will happen after reaching a node
|
||||
_isArrivalDone = true; // signals to future StartMove that it reached a node
|
||||
|
||||
if (_nextMoveTime.Passed())
|
||||
StartMove(creature); // check path status, get next point and move if necessary & can
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
* packets for the players.
|
||||
*/
|
||||
|
||||
#include "DBCStructure.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "PathMovementBase.h"
|
||||
#include "Timer.h"
|
||||
@@ -51,7 +50,7 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium<Creat
|
||||
void DoReset(Creature*);
|
||||
bool DoUpdate(Creature*, uint32 diff);
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() const override { return WAYPOINT_MOTION_TYPE; }
|
||||
MovementGeneratorType GetMovementGeneratorType() const override;
|
||||
void UnitSpeedChanged() override { _recalculateSpeed = true; }
|
||||
void Pause(uint32 timer = 0) override;
|
||||
void Resume(uint32 overrideTimer = 0) override;
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "LFG.h"
|
||||
#include "Log.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "MovementGenerator.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
|
||||
@@ -32,6 +32,8 @@ EndScriptData */
|
||||
#include "Language.h"
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Pet.h"
|
||||
|
||||
Reference in New Issue
Block a user