[9232] Replace list bool fields with exclusive true values by subtype field in Creature.
[getmangos.git] / src / game / MotionMaster.h
blob01ed0e90df3020e981e663e8d761c64ebd0ae032
1 /*
2 * Copyright (C) 2005-2010 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, // Just a dummy
40 CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
41 CHASE_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
47 ASSISTANCE_MOTION_TYPE= 11, // PointMovementGenerator.h (first part of flee for assistance)
48 ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance)
49 TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance)
50 FOLLOW_MOTION_TYPE = 14, // TargetedMovementGenerator.h
53 enum MMCleanFlag
55 MMCF_NONE = 0,
56 MMCF_UPDATE = 1, // Clear or Expire called from update
57 MMCF_RESET = 2 // Flag if need top()->Reset()
60 class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
62 private:
63 typedef std::stack<MovementGenerator *> Impl;
64 typedef std::vector<MovementGenerator *> ExpireList;
65 public:
67 explicit MotionMaster(Unit *unit) : i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE) {}
68 ~MotionMaster();
70 void Initialize();
72 MovementGenerator* operator->(void) { return top(); }
74 using Impl::top;
75 using Impl::empty;
77 typedef Impl::container_type::const_iterator const_iterator;
78 const_iterator begin() const { return Impl::c.begin(); }
79 const_iterator end() const { return Impl::c.end(); }
81 void UpdateMotion(uint32 diff);
82 void Clear(bool reset = true)
84 if (m_cleanFlag & MMCF_UPDATE)
86 if(reset)
87 m_cleanFlag |= MMCF_RESET;
88 else
89 m_cleanFlag &= ~MMCF_RESET;
90 DelayedClean();
92 else
93 DirectClean(reset);
95 void MovementExpired(bool reset = true)
97 if (m_cleanFlag & MMCF_UPDATE)
99 if(reset)
100 m_cleanFlag |= MMCF_RESET;
101 else
102 m_cleanFlag &= ~MMCF_RESET;
103 DelayedExpire();
105 else
106 DirectExpire(reset);
109 void MoveIdle();
110 void MoveTargetedHome();
111 void MoveFollow(Unit* target, float dist, float angle);
112 void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
113 void MoveConfused();
114 void MoveFleeing(Unit* enemy, uint32 time = 0);
115 void MovePoint(uint32 id, float x,float y,float z);
116 void MoveSeekAssistance(float x,float y,float z);
117 void MoveSeekAssistanceDistract(uint32 timer);
118 void MoveTaxiFlight(uint32 path, uint32 pathnode);
119 void MoveDistract(uint32 time);
121 MovementGeneratorType GetCurrentMovementGeneratorType() const;
123 void propagateSpeedChange();
125 // will only work in MMgens where we have a target (TARGETED_MOTION_TYPE)
126 void UpdateFinalDistanceToTarget(float fDistance);
128 bool GetDestination(float &x, float &y, float &z);
129 private:
130 void Mutate(MovementGenerator *m); // use Move* functions instead
132 void DirectClean(bool reset);
133 void DelayedClean();
135 void DirectExpire(bool reset);
136 void DelayedExpire();
138 Unit *i_owner;
139 ExpireList *m_expList;
140 uint8 m_cleanFlag;
142 #endif