TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MoveSplineInit.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #ifndef TRINITYSERVER_MOVESPLINEINIT_H
20 #define TRINITYSERVER_MOVESPLINEINIT_H
21 
22 #include "MoveSplineInitArgs.h"
23 #include "PathGenerator.h"
24 
25 class Unit;
26 
27 namespace Movement
28 {
29  enum AnimType
30  {
31  ToGround = 0, // 460 = ToGround, index of AnimationData.dbc
32  FlyToFly = 1, // 461 = FlyToFly?
33  ToFly = 2, // 458 = ToFly
34  FlyToGround = 3 // 463 = FlyToGround
35  };
36 
37  // Transforms coordinates from global to transport offsets
39  {
40  public:
41  TransportPathTransform(Unit* owner, bool transformForTransport)
42  : _owner(owner), _transformForTransport(transformForTransport) { }
43  Vector3 operator()(Vector3 input);
44 
45  private:
48  };
49 
50  /* Initializes and launches spline movement
51  */
53  {
54  public:
55 
56  explicit MoveSplineInit(Unit* m);
57 
58  /* Final pass of initialization that launches spline movement.
59  */
60  int32 Launch();
61 
62  /* Final pass of initialization that stops movement.
63  */
64  void Stop();
65 
66  /* Adds movement by parabolic trajectory
67  * @param amplitude - the maximum height of parabola, value could be negative and positive
68  * @param start_time - delay between movement starting time and beginning to move by parabolic trajectory
69  * can't be combined with final animation
70  */
71  void SetParabolic(float amplitude, float start_time);
72  /* Plays animation after movement done
73  * can't be combined with parabolic movement
74  */
75  void SetAnimation(AnimType anim);
76 
77  /* Adds final facing animation
78  * sets unit's facing to specified point/angle after all path done
79  * you can have only one final facing: previous will be overriden
80  */
81  void SetFacing(float angle);
82  void SetFacing(Vector3 const& point);
83  void SetFacing(const Unit* target);
84 
85  /* Initializes movement by path
86  * @param path - array of points, shouldn't be empty
87  * @param pointId - Id of fisrt point of the path. Example: when third path point will be done it will notify that pointId + 3 done
88  */
89  void MovebyPath(const PointsArray& path, int32 pointId = 0);
90 
91  /* Initializes simple A to B motion, A is current unit's position, B is destination
92  */
93  void MoveTo(const Vector3& destination, bool generatePath = true, bool forceDestination = false);
94  void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDestination = false);
95 
96  /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
97  * Needed for waypoint movement where path splitten into parts
98  */
99  void SetFirstPointId(int32 pointId) { args.path_Idx_offset = pointId; }
100 
101  /* Enables CatmullRom spline interpolation mode(makes path smooth)
102  * if not enabled linear spline mode will be choosen. Disabled by default
103  */
104  void SetSmooth();
105 
106  /* Waypoints in packets will be sent without compression
107  */
108  void SetUncompressed();
109 
110  /* Enables flying animation. Disabled by default
111  */
112  void SetFly();
113 
114  /* Enables walk mode. Disabled by default
115  */
116  void SetWalk(bool enable);
117 
118  /* Makes movement cyclic. Disabled by default
119  */
120  void SetCyclic();
121 
122  /* Enables falling mode. Disabled by default
123  */
124  void SetFall();
125 
126  /* Enters transport. Disabled by default
127  */
128  void SetTransportEnter();
129 
130  /* Exits transport. Disabled by default
131  */
132  void SetTransportExit();
133 
134  /* Inverses unit model orientation. Disabled by default
135  */
136  void SetOrientationInversed();
137 
138  /* Fixes unit's model rotation. Disabled by default
139  */
140  void SetOrientationFixed(bool enable);
141 
142  /* Sets the velocity (in case you want to have custom movement velocity)
143  * if no set, speed will be selected based on unit's speeds and current movement mode
144  * Has no effect if falling mode enabled
145  * velocity shouldn't be negative
146  */
147  void SetVelocity(float velocity);
148 
149  PointsArray& Path() { return args.path; }
150 
151  /* Disables transport coordinate transformations for cases where raw offsets are available
152  */
153  void DisableTransportPathTransformations();
154  protected:
155 
158  };
159 
161  inline void MoveSplineInit::SetWalk(bool enable) { args.flags.walkmode = enable; }
164  inline void MoveSplineInit::SetCyclic() { args.flags.cyclic = true; }
165  inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
169  inline void MoveSplineInit::SetOrientationFixed(bool enable) { args.flags.orientationFixed = enable; }
170 
171  inline void MoveSplineInit::MovebyPath(const PointsArray& controls, int32 path_offset)
172  {
173  args.path_Idx_offset = path_offset;
174  args.path.resize(controls.size());
175  std::transform(controls.begin(), controls.end(), args.path.begin(), TransportPathTransform(unit, args.TransformForTransport));
176  }
177 
178  inline void MoveSplineInit::MoveTo(float x, float y, float z, bool generatePath, bool forceDestination)
179  {
180  MoveTo(G3D::Vector3(x, y, z), generatePath, forceDestination);
181  }
182 
183  inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift)
184  {
185  args.time_perc = time_shift;
186  args.parabolic_amplitude = amplitude;
188  }
189 
191  {
192  args.time_perc = 0.f;
194  }
195 
196  inline void MoveSplineInit::SetFacing(Vector3 const& spot)
197  {
199  Vector3 finalSpot = transform(spot);
200  args.facing.f.x = finalSpot.x;
201  args.facing.f.y = finalSpot.y;
202  args.facing.f.z = finalSpot.z;
204  }
205 
207 }
208 #endif // TRINITYSERVER_MOVESPLINEINIT_H
bool HasVelocity
Definition: MoveSplineInitArgs.h:59
void SetVelocity(float velocity)
Definition: MoveSplineInit.h:165
float x
Definition: Vector3.h:62
TransportPathTransform(Unit *owner, bool transformForTransport)
Definition: MoveSplineInit.h:41
bool cyclic
Definition: MoveSplineFlag.h:121
void SetCyclic()
Definition: MoveSplineInit.h:164
int32 path_Idx_offset
Definition: MoveSplineInitArgs.h:53
MoveSplineFlag flags
Definition: MoveSplineInitArgs.h:52
bool orientationInversed
Definition: MoveSplineFlag.h:128
float parabolic_amplitude
Definition: MoveSplineInitArgs.h:55
Definition: MoveSplineInit.h:34
bool _transformForTransport
Definition: MoveSplineInit.h:47
void SetOrientationInversed()
Definition: MoveSplineInit.h:166
Definition: MoveSplineInit.h:33
void SetFly()
Definition: MoveSplineInit.h:160
PointsArray & Path()
Definition: MoveSplineInit.h:149
void SetAnimation(AnimType anim)
Definition: MoveSplineInit.h:190
MoveSplineInitArgs args
Definition: MoveSplineInit.h:156
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
float time_perc
Definition: MoveSplineInitArgs.h:56
void MovebyPath(const PointsArray &path, int32 pointId=0)
Definition: MoveSplineInit.h:171
void MoveTo(const Vector3 &destination, bool generatePath=true, bool forceDestination=false)
Definition: MoveSplineInit.cpp:206
Definition: MoveSplineInit.h:38
void EnableAnimation(uint8 anim)
Definition: MoveSplineFlag.h:100
bool TransformForTransport
Definition: MoveSplineInitArgs.h:60
Definition: MoveSplineInit.h:31
G3D::Vector3 f
Definition: MoveSplineInitArgs.h:34
PointsArray path
Definition: MoveSplineInitArgs.h:50
Unit * unit
Definition: MoveSplineInit.h:157
void DisableTransportPathTransformations()
Definition: MoveSplineInit.h:206
FacingInfo facing
Definition: MoveSplineInitArgs.h:51
G3D::int16 z
Definition: Vector3int16.h:46
Definition: Unit.h:409
#define input
Definition: wire_format_lite.h:242
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:30
int32_t int32
Definition: Define.h:146
G3D::int16 y
Definition: Vector2int16.h:38
void SetTransportEnter()
Definition: MoveSplineInit.h:167
void EnableParabolic()
Definition: MoveSplineFlag.h:101
bool walkmode
Definition: MoveSplineFlag.h:130
float velocity
Definition: MoveSplineInitArgs.h:54
void SetTransportExit()
Definition: MoveSplineInit.h:168
void SetWalk(bool enable)
Definition: MoveSplineInit.h:161
void SetOrientationFixed(bool enable)
Definition: MoveSplineInit.h:169
void EnableTransportExit()
Definition: MoveSplineFlag.h:109
float z
Definition: Vector3.h:62
void EnableFacingPoint()
Definition: MoveSplineFlag.h:105
AnimType
Definition: MoveSplineInit.h:29
bool uncompressedPath
Definition: MoveSplineFlag.h:131
#define TC_GAME_API
Definition: Define.h:134
void SetFirstPointId(int32 pointId)
Definition: MoveSplineInit.h:99
uint8_t uint8
Definition: Define.h:152
void EnableTransportEnter()
Definition: MoveSplineFlag.h:108
Unit * _owner
Definition: MoveSplineInit.h:46
G3D::int16 x
Definition: Vector2int16.h:37
Definition: MoveSplineInit.h:32
void SetParabolic(float amplitude, float start_time)
Definition: MoveSplineInit.h:183
Definition: MoveSplineInit.h:52
void EnableCatmullRom()
Definition: MoveSplineFlag.h:104
Definition: Unit.h:1305
void SetUncompressed()
Definition: MoveSplineInit.h:163
void SetSmooth()
Definition: MoveSplineInit.h:162
void SetFacing(float angle)
Definition: MoveSplineInit.cpp:192
Definition: MoveSplineInitArgs.h:41
bool orientationFixed
Definition: MoveSplineFlag.h:119
void EnableFlying()
Definition: MoveSplineFlag.h:102