[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / MotionMaster.h
bloba1a4a55a3d3bffb16d12795bcb1e0ee783da3e8c
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_MOTIONMASTER_H
20 #define MANGOS_MOTIONMASTER_H
22 #include "Common.h"
23 #include <stack>
24 #include <vector>
26 class MovementGenerator;
27 class Unit;
29 // Creature Entry ID used for waypoints show, visible only for GMs
30 #define VISUAL_WAYPOINT 1
32 // values 0 ... MAX_DB_MOTION_TYPE-1 used in DB
33 enum MovementGeneratorType
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 CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
41 TARGETED_MOTION_TYPE = 5, // TargetedMovementGenerator.h
42 HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
43 FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
44 POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
45 FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
46 DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
49 enum MMCleanFlag
51 MMCF_NONE = 0,
52 MMCF_UPDATE = 1, // Clear or Expire called from update
53 MMCF_RESET = 2 // Flag if need top()->Reset()
56 class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
58 private:
59 typedef std::stack<MovementGenerator *> Impl;
60 typedef std::vector<MovementGenerator *> ExpireList;
61 public:
63 explicit MotionMaster(Unit *unit) : i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE) {}
64 ~MotionMaster();
66 void Initialize();
68 MovementGenerator* operator->(void) { return top(); }
70 using Impl::top;
71 using Impl::empty;
73 typedef Impl::container_type::const_iterator const_iterator;
74 const_iterator begin() const { return Impl::c.begin(); }
75 const_iterator end() const { return Impl::c.end(); }
77 void UpdateMotion(uint32 diff);
78 void Clear(bool reset = true)
80 if (m_cleanFlag & MMCF_UPDATE)
82 if(reset)
83 m_cleanFlag |= MMCF_RESET;
84 else
85 m_cleanFlag &= ~MMCF_RESET;
86 DelayedClean();
88 else
89 DirectClean(reset);
91 void MovementExpired(bool reset = true)
93 if (m_cleanFlag & MMCF_UPDATE)
95 if(reset)
96 m_cleanFlag |= MMCF_RESET;
97 else
98 m_cleanFlag &= ~MMCF_RESET;
99 DelayedExpire();
101 else
102 DirectExpire(reset);
105 void MoveIdle();
106 void MoveTargetedHome();
107 void MoveFollow(Unit* target, float dist, float angle);
108 void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
109 void MoveConfused();
110 void MoveFleeing(Unit* enemy);
111 void MovePoint(uint32 id, float x,float y,float z);
112 void MoveTaxiFlight(uint32 path, uint32 pathnode);
113 void MoveDistract(uint32 time);
115 MovementGeneratorType GetCurrentMovementGeneratorType() const;
117 void propagateSpeedChange();
119 bool GetDestination(float &x, float &y, float &z);
120 private:
121 void Mutate(MovementGenerator *m); // use Move* functions instead
123 void DirectClean(bool reset);
124 void DelayedClean();
126 void DirectExpire(bool reset);
127 void DelayedExpire();
129 Unit *i_owner;
130 ExpireList *m_expList;
131 uint8 m_cleanFlag;
133 #endif