OregonCore  revision be9e804-git
Your Favourite TBC server
MotionMaster.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_MOTIONMASTER_H
19 #define OREGON_MOTIONMASTER_H
20 
21 #include "Common.h"
22 #include <vector>
23 #include "SharedDefines.h"
24 #include "Object.h"
25 
26 class MovementGenerator;
27 class Unit;
28 
29 // Creature Entry ID used for waypoints show, visible only for GMs
30 #define VISUAL_WAYPOINT 1
31 
32 // values 0 ... MAX_DB_MOTION_TYPE-1 used in DB
34 {
35  IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
36  RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
37  WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
38  MAX_DB_MOTION_TYPE = 3, // *** this and below motion types can't be set in DB.
39  ANIMAL_RANDOM_MOTION_TYPE = MAX_DB_MOTION_TYPE, // AnimalRandomMovementGenerator.h
40 
41  CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
42  CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h
43  HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
44  FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
45  POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
46  FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
47  DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
48  ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h (first part of flee for assistance)
49  ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance)
50  TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance)
52  FOLLOW_MOTION_TYPE = 15, // TargetedMovementGenerator.h
56 };
57 
59 {
64 };
65 
67 {
68  MMCF_NONE = 0,
69  MMCF_UPDATE = 1, // Clear or Expire called from update
70  MMCF_RESET = 2 // Flag if need top()->Reset()
71 };
72 
74 {
77 };
78 
79 // assume it is 25 yard per 0.6 second
80 #define SPEED_CHARGE 42.0f
81 
82 class MotionMaster //: private std::stack<MovementGenerator *>
83 {
84  private:
85  //typedef std::stack<MovementGenerator *> Impl;
89  typedef std::vector<_Ty> ExpireList;
90  int i_top;
91 
92  void pop()
93  {
94  Impl[i_top] = NULL;
95  --i_top;
96  }
97  void push(_Ty _Val)
98  {
99  ++i_top;
100  Impl[i_top] = _Val;
101  }
102 
103  bool needInitTop() const
104  {
105  return needInit[i_top];
106  }
107  void InitTop();
108 
109  public:
110 
111  explicit MotionMaster(Unit* unit) : i_top(-1), i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE)
112  {
113  for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i)
114  {
115  Impl[i] = NULL;
116  needInit[i] = true;
117  }
118  }
119  ~MotionMaster();
120 
121  void Initialize();
122  void InitDefault();
123 
124  int size() const
125  {
126  return i_top + 1;
127  }
128  bool empty() const
129  {
130  return i_top < 0;
131  }
132  _Ty top() const
133  {
134  return Impl[i_top];
135  }
136  _Ty GetMotionSlot(int slot) const
137  {
138  return Impl[slot];
139  }
140 
141  void DirectDelete(_Ty curr);
142  void DelayedDelete(_Ty curr);
143 
144  void UpdateMotion(uint32 diff);
145  void Clear(bool reset = true)
146  {
147  if (m_cleanFlag & MMCF_UPDATE)
148  {
149  if (reset)
151  else
153  DelayedClean();
154  }
155  else
156  DirectClean(reset);
157  }
158  void MovementExpired(bool reset = true)
159  {
160  if (m_cleanFlag & MMCF_UPDATE)
161  {
162  if (reset)
164  else
166  DelayedExpire();
167  }
168  else
169  DirectExpire(reset);
170  }
171 
173  void MoveTargetedHome();
174  void MoveRandom(float spawndist = 0.0f);
175  void MoveFollow(Unit* target, float dist, float angle, MovementSlot slot = MOTION_SLOT_ACTIVE);
176  void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
177  void MoveConfused();
178  void MoveFleeing(Unit* enemy, uint32 time = 0);
179  void MovePoint(uint32 id, const Position& pos, bool usePathfinding = true)
180  {
181  MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, usePathfinding);
182  }
183  void MovePoint(uint32 id, float x, float y, float z, bool usePathfinding = true);
184  void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool usePathfinding = true);
185  void MoveFall(float z = 0, uint32 id = 0);
186  void MoveSeekAssistance(float x, float y, float z);
188  void MoveTaxiFlight(uint32 path, uint32 pathnode);
189  void MoveDistract(uint32 time);
190  void MovePath(uint32 path_id, bool repeatable);
191  void MoveRotate(uint32 time, RotateDirection direction);
192 
193  // given destination unreachable? due to pathfinding or other
194  virtual bool isReachable() const
195  {
196  return true;
197  }
198 
201 
202  void propagateSpeedChange();
203 
204  bool GetDestination(float& x, float& y, float& z);
205  private:
206  void Mutate(MovementGenerator* m, MovementSlot slot); // use Move* functions instead
207 
208  void DirectClean(bool reset);
209  void DelayedClean();
210 
211  void DirectExpire(bool reset);
212  void DelayedExpire();
213 
215  ExpireList* m_expList;
217 };
218 #endif
219 
void MoveTaxiFlight(uint32 path, uint32 pathnode)
MMCleanFlag
Definition: MotionMaster.h:66
void DirectClean(bool reset)
void MoveRandom(float spawndist=0.0f)
void push(_Ty _Val)
Definition: MotionMaster.h:97
void MoveIdle(MovementSlot slot=MOTION_SLOT_ACTIVE)
void Clear(bool reset=true)
Definition: MotionMaster.h:145
void MoveFleeing(Unit *enemy, uint32 time=0)
float m_positionY
Definition: Position.h:51
virtual bool isReachable() const
Definition: MotionMaster.h:194
void MoveSeekAssistanceDistract(uint32 timer)
void MoveChase(Unit *target, float dist=0.0f, float angle=0.0f)
void DirectExpire(bool reset)
void MoveTargetedHome()
void propagateSpeedChange()
MovementGeneratorType GetCurrentMovementGeneratorType() const
bool needInit[MAX_MOTION_SLOT]
Definition: MotionMaster.h:88
float m_positionX
Definition: Position.h:50
void MovePoint(uint32 id, const Position &pos, bool usePathfinding=true)
Definition: MotionMaster.h:179
void MoveFall(float z=0, uint32 id=0)
Unit * i_owner
Definition: MotionMaster.h:214
void DirectDelete(_Ty curr)
ExpireList * m_expList
Definition: MotionMaster.h:215
_Ty top() const
Definition: MotionMaster.h:132
void InitDefault()
_Ty GetMotionSlot(int slot) const
Definition: MotionMaster.h:136
void Mutate(MovementGenerator *m, MovementSlot slot)
void DelayedDelete(_Ty curr)
void UpdateMotion(uint32 diff)
std::vector< _Ty > ExpireList
Definition: MotionMaster.h:89
ACE_UINT8 uint8
Definition: Define.h:73
MovementGenerator * _Ty
Definition: MotionMaster.h:86
void MoveConfused()
void MoveSeekAssistance(float x, float y, float z)
bool needInitTop() const
Definition: MotionMaster.h:103
float m_positionZ
Definition: Position.h:52
MovementGeneratorType GetMotionSlotType(int slot) const
MovementSlot
Definition: MotionMaster.h:58
int size() const
Definition: MotionMaster.h:124
void MoveCharge(float x, float y, float z, float speed=SPEED_CHARGE, uint32 id=EVENT_CHARGE, bool usePathfinding=true)
RotateDirection
Definition: MotionMaster.h:73
uint8 m_cleanFlag
Definition: MotionMaster.h:216
void MovePath(uint32 path_id, bool repeatable)
#define SPEED_CHARGE
Definition: MotionMaster.h:80
MovementGeneratorType
Definition: MotionMaster.h:33
_Ty Impl[MAX_MOTION_SLOT]
Definition: MotionMaster.h:87
void DelayedExpire()
void MoveRotate(uint32 time, RotateDirection direction)
ACE_UINT32 uint32
Definition: Define.h:71
void Initialize()
void MoveDistract(uint32 time)
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:158
void DelayedClean()
Definition: Unit.h:908
bool GetDestination(float &x, float &y, float &z)
bool empty() const
Definition: MotionMaster.h:128
MotionMaster(Unit *unit)
Definition: MotionMaster.h:111
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE)