TrinityCore
Loading...
Searching...
No Matches
MovementInfo.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef MovementInfo_h__
19#define MovementInfo_h__
20
21#include "ObjectGuid.h"
22#include "Optional.h"
23#include "Position.h"
24#include <algorithm>
25#include <vector>
26
28{
29 // common
36
37 // transport
39 {
40 void Reset()
41 {
42 guid.Clear();
43 pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
44 seat = -1;
45 time = 0;
46 prevTime = 0;
47 vehicleId = 0;
48 }
49
52 int8 seat = -1;
57
58 // swimming/flying
59 float pitch = 0.0f;
60
61 struct Inertia
62 {
63 Inertia() : id(0), lifetime(0) { }
64
68 };
69
71
72 // jumping
73 struct JumpInfo
74 {
75 void Reset()
76 {
77 fallTime = 0;
78 zspeed = sinAngle = cosAngle = xyspeed = 0.0f;
79 }
80
82
83 float zspeed = 0.0f;
84 float sinAngle = 0.0f;
85 float cosAngle = 0.0f;
86 float xyspeed = 0.0f;
87
89
91
92 // advflying
93 struct AdvFlying
94 {
96
99 };
100
101 struct Drive
102 {
103 Drive() : speed(0.0f), movementAngle(0.0f), accelerating(false), drifting(false) { }
104
105 float speed;
109 };
110
112
114
115 float gravityModifier = 1.0f;
116
118
119 uint32 GetMovementFlags() const { return flags; }
120 void SetMovementFlags(uint32 flag) { flags = flag; }
121 void AddMovementFlag(uint32 flag) { flags |= flag; }
122 void RemoveMovementFlag(uint32 flag) { flags &= ~flag; }
123 bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }
124
126 void SetExtraMovementFlags(uint32 flag) { flags2 = flag; }
127 void AddExtraMovementFlag(uint32 flag) { flags2 |= flag; }
128 void RemoveExtraMovementFlag(uint32 flag) { flags2 &= ~flag; }
129 bool HasExtraMovementFlag(uint32 flag) const { return (flags2 & flag) != 0; }
130
132 void SetExtraMovementFlags2(uint32 flag) { flags3 = flag; }
133 void AddExtraMovementFlag2(uint32 flag) { flags3 |= flag; }
134 void RemoveExtraMovementFlag2(uint32 flag) { flags3 &= ~flag; }
135 bool HasExtraMovementFlag2(uint32 flag) const { return (flags3 & flag) != 0; }
136
137 uint32 GetFallTime() const { return jump.fallTime; }
138 void SetFallTime(uint32 fallTime) { jump.fallTime = fallTime; }
139
141 {
143 }
144
146 {
147 jump.Reset();
148 }
149
150 void OutDebug();
151};
152
154{
155 SingleDirectional = 0, // always in a single direction
156 Gravity = 1 // pushes/pulls away from a single point
157};
158
172
174{
175public:
176 using Container = std::vector<MovementForce>;
177
178 Container const* GetForces() const { return &_forces; }
179 bool Add(MovementForce const& newForce)
180 {
181 auto itr = FindMovementForce(newForce.ID);
182 if (itr == _forces.end())
183 {
184 _forces.push_back(newForce);
185 return true;
186 }
187
188 return false;
189 }
190
192 {
193 auto itr = FindMovementForce(id);
194 if (itr != _forces.end())
195 {
196 _forces.erase(itr);
197 return true;
198 }
199
200 return false;
201 }
202
203 float GetModMagnitude() const { return _modMagnitude; }
204 void SetModMagnitude(float modMagnitude) { _modMagnitude = modMagnitude; }
205
206 bool IsEmpty() const { return _forces.empty() && _modMagnitude == 1.0f; }
207
208private:
209 Container::iterator FindMovementForce(ObjectGuid id)
210 {
211 return std::find_if(_forces.begin(), _forces.end(), [id](MovementForce const& force) { return force.ID == id; });
212 }
213
215 float _modMagnitude = 1.0f;
216};
217
218#endif // MovementInfo_h__
uint8_t uint8
Definition Define.h:156
int8_t int8
Definition Define.h:152
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
MovementForceType
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Container const * GetForces() const
float GetModMagnitude() const
bool Remove(ObjectGuid id)
void SetModMagnitude(float modMagnitude)
Container::iterator FindMovementForce(ObjectGuid id)
bool IsEmpty() const
std::vector< MovementForce > Container
bool Add(MovementForce const &newForce)
Container _forces
void Clear()
Definition ObjectGuid.h:329
MovementForceType Type
TaggedPosition< Position::XYZ > Origin
uint32 EndTimestamp
ObjectGuid ID
int32 MovementForceID
TaggedPosition< Position::XYZ > Direction
ObjectGuid guid
void ResetTransport()
bool HasExtraMovementFlag(uint32 flag) const
Optional< Inertia > inertia
Optional< Drive > driveStatus
void AddExtraMovementFlag2(uint32 flag)
bool HasExtraMovementFlag2(uint32 flag) const
void RemoveExtraMovementFlag(uint32 flag)
float gravityModifier
void SetFallTime(uint32 fallTime)
void SetExtraMovementFlags2(uint32 flag)
Optional< ObjectGuid > standingOnGameObjectGUID
uint32 GetExtraMovementFlags2() const
void AddExtraMovementFlag(uint32 flag)
uint32 GetFallTime() const
struct MovementInfo::JumpInfo jump
float stepUpStartElevation
void RemoveMovementFlag(uint32 flag)
struct MovementInfo::TransportInfo transport
uint32 GetExtraMovementFlags() const
void SetMovementFlags(uint32 flag)
void RemoveExtraMovementFlag2(uint32 flag)
bool HasMovementFlag(uint32 flag) const
uint32 GetMovementFlags() const
void AddMovementFlag(uint32 flag)
void SetExtraMovementFlags(uint32 flag)
void OutDebug()
Definition Object.cpp:167
Position pos
Optional< AdvFlying > advFlying
constexpr void Relocate(float x, float y)
Definition Position.h:74