Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
MotionMaster.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRE_MOTIONMASTER_H
7#define SKYFIRE_MOTIONMASTER_H
8
9#include "Common.h"
10#include "Object.h"
11#include "SharedDefines.h"
12#include <vector>
13
15class Unit;
16class PathGenerator;
17
18// Creature Entry ID used for waypoints show, visible only for GMs
19#define VISUAL_WAYPOINT 1
20
21// values 0 ... MAX_DB_MOTION_TYPE-1 used in DB
23{
24 IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
25 RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
26 WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
27 MAX_DB_MOTION_TYPE = 3, // *** this and below motion types can't be set in DB.
28 ANIMAL_RANDOM_MOTION_TYPE = MAX_DB_MOTION_TYPE, // AnimalRandomMovementGenerator.h
29 CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
30 CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h
31 HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
32 FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
33 POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
34 FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
35 DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
36 ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h (first part of flee for assistance)
37 ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance)
38 TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance)
43};
44
52
54{
56 MMCF_UPDATE = 1, // Clear or Expire called from update
57 MMCF_RESET = 2 // Flag if need top()->Reset()
58};
59
65
66// assume it is 25 yard per 0.6 second
67#define SPEED_CHARGE 42.0f
68
69class MotionMaster //: private std::stack<MovementGenerator *>
70{
71private:
72 //typedef std::stack<MovementGenerator *> Impl;
74
75 void pop()
76 {
77 Impl[_top] = NULL;
78 while (!top())
79 --_top;
80 }
81 void push(_Ty _Val) { ++_top; Impl[_top] = _Val; }
82
83 bool needInitTop() const { return _needInit[_top]; }
84 void InitTop();
85
86public:
87 explicit MotionMaster(Unit* unit) : _expList(NULL), _top(-1), _owner(unit), _cleanFlag(MMCF_NONE) { }
89
90 void Initialize();
91 void InitDefault();
92
93 bool empty() const { return (_top < 0); }
94 int size() const { return _top + 1; }
95 _Ty top() const { return Impl[_top]; }
96 _Ty GetMotionSlot(int slot) const { return Impl[slot]; }
97
98 void DirectDelete(_Ty curr);
99 void DelayedDelete(_Ty curr);
100
101 void UpdateMotion(uint32 diff);
102 void Clear(bool reset = true)
103 {
105 {
106 if (reset)
108 else
110 DelayedClean();
111 }
112 else
113 DirectClean(reset);
114 }
115 void MovementExpired(bool reset = true)
116 {
118 {
119 if (reset)
121 else
124 }
125 else
126 DirectExpire(reset);
127 }
128
129 void MoveIdle();
130 void MoveTargetedHome();
131 void MoveRandom(float spawndist = 0.0f);
132 void MoveFollow(Unit* target, float dist, float angle, MovementSlot slot = MOTION_SLOT_ACTIVE);
133 void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
134 void MoveConfused();
135 void MoveFleeing(Unit* enemy, uint32 time = 0);
136 void MovePoint(uint32 id, Position const& pos, bool generatePath = true)
137 {
138 MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath);
139 }
140 void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true);
141
142 // These two movement types should only be used with creatures having landing/takeoff animations
143 void MoveLand(uint32 id, Position const& pos);
144 void MoveTakeoff(uint32 id, Position const& pos);
145
146 void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool generatePath = false);
147 void MoveCharge(PathGenerator const& path);
148 void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ);
149 void MoveJumpTo(float angle, float speedXY, float speedZ);
150 void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP)
151 {
152 MoveJump(pos.m_positionX, pos.m_positionY, pos.m_positionZ, speedXY, speedZ, id);
153 };
154 void MoveJump(float x, float y, float z, float speedXY, float speedZ, uint32 id = EVENT_JUMP);
155 void MoveFall(uint32 id = 0);
156
157 void MoveSeekAssistance(float x, float y, float z);
159 void MoveTaxiFlight(uint32 path, uint32 pathnode);
160 void MoveDistract(uint32 time);
161 void MovePath(uint32 path_id, bool repeatable);
162 void MoveRotate(uint32 time, RotateDirection direction);
163
166
168
169 bool GetDestination(float& x, float& y, float& z);
170
171private:
172 void Mutate(MovementGenerator* m, MovementSlot slot); // use Move* functions instead
173
174 void DirectClean(bool reset);
175 void DelayedClean();
176
177 void DirectExpire(bool reset);
178 void DelayedExpire();
179
180 typedef std::vector<_Ty> ExpireList;
183 int _top;
185 bool _needInit[MAX_MOTION_SLOT] = { true };
187};
188#endif
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
RotateDirection
@ ROTATE_DIRECTION_RIGHT
@ ROTATE_DIRECTION_LEFT
MMCleanFlag
@ MMCF_RESET
@ MMCF_NONE
@ MMCF_UPDATE
MovementSlot
@ MOTION_SLOT_CONTROLLED
@ MOTION_SLOT_ACTIVE
@ MOTION_SLOT_IDLE
@ MAX_MOTION_SLOT
MovementGeneratorType
@ TIMED_FLEEING_MOTION_TYPE
@ MAX_DB_MOTION_TYPE
@ ASSISTANCE_MOTION_TYPE
@ DISTRACT_MOTION_TYPE
@ IDLE_MOTION_TYPE
@ CHASE_MOTION_TYPE
@ ROTATE_MOTION_TYPE
@ WAYPOINT_MOTION_TYPE
@ FLEEING_MOTION_TYPE
@ NULL_MOTION_TYPE
@ CONFUSED_MOTION_TYPE
@ HOME_MOTION_TYPE
@ POINT_MOTION_TYPE
@ FLIGHT_MOTION_TYPE
@ FOLLOW_MOTION_TYPE
@ ANIMAL_RANDOM_MOTION_TYPE
@ RANDOM_MOTION_TYPE
@ ASSISTANCE_DISTRACT_MOTION_TYPE
@ EFFECT_MOTION_TYPE
#define SPEED_CHARGE
@ EVENT_CHARGE
@ EVENT_JUMP
MovementGenerator * _Ty
void UpdateMotion(uint32 diff)
void MoveTaxiFlight(uint32 path, uint32 pathnode)
void MoveJump(Position const &pos, float speedXY, float speedZ, uint32 id=EVENT_JUMP)
void DirectDelete(_Ty curr)
_Ty top() const
MovementGeneratorType GetMotionSlotType(int slot) const
std::vector< _Ty > ExpireList
MovementGeneratorType GetCurrentMovementGeneratorType() const
void push(_Ty _Val)
void propagateSpeedChange()
void MoveRotate(uint32 time, RotateDirection direction)
void DirectExpire(bool reset)
bool _needInit[MAX_MOTION_SLOT]
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
void DirectClean(bool reset)
ExpireList * _expList
int size() const
_Ty GetMotionSlot(int slot) const
void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ)
void MovementExpired(bool reset=true)
void MoveChase(Unit *target, float dist=0.0f, float angle=0.0f)
void MoveCharge(float x, float y, float z, float speed=SPEED_CHARGE, uint32 id=EVENT_CHARGE, bool generatePath=false)
void Mutate(MovementGenerator *m, MovementSlot slot)
void MoveRandom(float spawndist=0.0f)
bool empty() const
void MoveSeekAssistance(float x, float y, float z)
void MoveSeekAssistanceDistract(uint32 timer)
void MoveLand(uint32 id, Position const &pos)
_Ty Impl[MAX_MOTION_SLOT]
void MovePoint(uint32 id, Position const &pos, bool generatePath=true)
bool GetDestination(float &x, float &y, float &z)
void DelayedDelete(_Ty curr)
void MoveTargetedHome()
void MovePath(uint32 path_id, bool repeatable)
void MoveDistract(uint32 time)
MotionMaster(Unit *unit)
bool needInitTop() const
void MoveJumpTo(float angle, float speedXY, float speedZ)
void MoveFall(uint32 id=0)
void MoveTakeoff(uint32 id, Position const &pos)
void Clear(bool reset=true)
void MoveFleeing(Unit *enemy, uint32 time=0)
Definition Unit.h:1367
float m_positionZ
Definition Object.h:289
float m_positionX
Definition Object.h:287
float m_positionY
Definition Object.h:288