1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MovementInfo_h__
#define MovementInfo_h__
#include "ObjectGuid.h"
#include "Optional.h"
#include "Position.h"
#include <algorithm>
#include <vector>
struct MovementInfo
{
// common
ObjectGuid guid;
uint32 flags = 0;
uint32 flags2 = 0;
uint32 flags3 = 0;
Position pos;
uint32 time = 0;
// transport
struct TransportInfo
{
void Reset()
{
guid.Clear();
pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
seat = -1;
time = 0;
prevTime = 0;
vehicleId = 0;
}
ObjectGuid guid;
Position pos;
int8 seat = -1;
uint32 time = 0;
uint32 prevTime = 0;
uint32 vehicleId = 0;
} transport;
// swimming/flying
float pitch = 0.0f;
struct Inertia
{
Inertia() : id(0), lifetime(0) { }
int32 id;
Position force;
uint32 lifetime;
};
Optional<Inertia> inertia;
// jumping
struct JumpInfo
{
void Reset()
{
fallTime = 0;
zspeed = sinAngle = cosAngle = xyspeed = 0.0f;
}
uint32 fallTime = 0;
float zspeed = 0.0f;
float sinAngle = 0.0f;
float cosAngle = 0.0f;
float xyspeed = 0.0f;
} jump;
float stepUpStartElevation = 0.0f;
// advflying
struct AdvFlying
{
AdvFlying() : forwardVelocity(0.0f), upVelocity(0.0f) { }
float forwardVelocity;
float upVelocity;
};
struct Drive
{
Drive() : speed(0.0f), movementAngle(0.0f), accelerating(false), drifting(false) { }
float speed;
float movementAngle;
bool accelerating;
bool drifting;
};
Optional<AdvFlying> advFlying;
Optional<Drive> driveStatus;
Optional<ObjectGuid> standingOnGameObjectGUID;
uint32 GetMovementFlags() const { return flags; }
void SetMovementFlags(uint32 flag) { flags = flag; }
void AddMovementFlag(uint32 flag) { flags |= flag; }
void RemoveMovementFlag(uint32 flag) { flags &= ~flag; }
bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }
uint32 GetExtraMovementFlags() const { return flags2; }
void SetExtraMovementFlags(uint32 flag) { flags2 = flag; }
void AddExtraMovementFlag(uint32 flag) { flags2 |= flag; }
void RemoveExtraMovementFlag(uint32 flag) { flags2 &= ~flag; }
bool HasExtraMovementFlag(uint32 flag) const { return (flags2 & flag) != 0; }
uint32 GetExtraMovementFlags2() const { return flags3; }
void SetExtraMovementFlags2(uint32 flag) { flags3 = flag; }
void AddExtraMovementFlag2(uint32 flag) { flags3 |= flag; }
void RemoveExtraMovementFlag2(uint32 flag) { flags3 &= ~flag; }
bool HasExtraMovementFlag2(uint32 flag) const { return (flags3 & flag) != 0; }
uint32 GetFallTime() const { return jump.fallTime; }
void SetFallTime(uint32 fallTime) { jump.fallTime = fallTime; }
void ResetTransport()
{
transport.Reset();
}
void ResetJump()
{
jump.Reset();
}
void OutDebug();
};
enum class MovementForceType : uint8
{
SingleDirectional = 0, // always in a single direction
Gravity = 1 // pushes/pulls away from a single point
};
struct MovementForce
{
ObjectGuid ID;
TaggedPosition<Position::XYZ> Origin;
TaggedPosition<Position::XYZ> Direction;
uint32 TransportID = 0;
float Magnitude = 0.0f;
MovementForceType Type = MovementForceType::SingleDirectional;
int32 MovementForceID = 0;
int32 Unknown1110_1 = 0;
int32 Unused1110 = 0;
uint32 Flags = 0;
};
class MovementForces
{
public:
using Container = std::vector<MovementForce>;
Container const* GetForces() const { return &_forces; }
bool Add(MovementForce const& newForce)
{
auto itr = FindMovementForce(newForce.ID);
if (itr == _forces.end())
{
_forces.push_back(newForce);
return true;
}
return false;
}
bool Remove(ObjectGuid id)
{
auto itr = FindMovementForce(id);
if (itr != _forces.end())
{
_forces.erase(itr);
return true;
}
return false;
}
float GetModMagnitude() const { return _modMagnitude; }
void SetModMagnitude(float modMagnitude) { _modMagnitude = modMagnitude; }
bool IsEmpty() const { return _forces.empty() && _modMagnitude == 1.0f; }
private:
Container::iterator FindMovementForce(ObjectGuid id)
{
return std::find_if(_forces.begin(), _forces.end(), [id](MovementForce const& force) { return force.ID == id; });
}
Container _forces;
float _modMagnitude = 1.0f;
};
#endif // MovementInfo_h__
|