TrinityCore
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
57
58 // swimming/flying
59 float pitch;
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
84
86
88
89 // advflying
90 struct AdvFlying
91 {
94 };
95
97
99
101 flags(0), flags2(0), flags3(0), time(0), pitch(0.0f), stepUpStartElevation(0.0f)
102 {
103 pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
105 jump.Reset();
106 }
107
108 uint32 GetMovementFlags() const { return flags; }
109 void SetMovementFlags(uint32 flag) { flags = flag; }
110 void AddMovementFlag(uint32 flag) { flags |= flag; }
111 void RemoveMovementFlag(uint32 flag) { flags &= ~flag; }
112 bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }
113
115 void SetExtraMovementFlags(uint32 flag) { flags2 = flag; }
116 void AddExtraMovementFlag(uint32 flag) { flags2 |= flag; }
117 void RemoveExtraMovementFlag(uint32 flag) { flags2 &= ~flag; }
118 bool HasExtraMovementFlag(uint32 flag) const { return (flags2 & flag) != 0; }
119
121 void SetExtraMovementFlags2(uint32 flag) { flags3 = flag; }
122 void AddExtraMovementFlag2(uint32 flag) { flags3 |= flag; }
123 void RemoveExtraMovementFlag2(uint32 flag) { flags3 &= ~flag; }
124 bool HasExtraMovementFlag2(uint32 flag) const { return (flags3 & flag) != 0; }
125
126 uint32 GetFallTime() const { return jump.fallTime; }
127 void SetFallTime(uint32 fallTime) { jump.fallTime = fallTime; }
128
130 {
132 }
133
135 {
136 jump.Reset();
137 }
138
139 void OutDebug();
140};
141
143{
144 SingleDirectional = 0, // always in a single direction
145 Gravity = 1 // pushes/pulls away from a single point
146};
147
149{
154 float Magnitude = 0.0f;
157};
158
160{
161public:
162 using Container = std::vector<MovementForce>;
163
164 Container const* GetForces() const { return &_forces; }
165 bool Add(MovementForce const& newForce)
166 {
167 auto itr = FindMovementForce(newForce.ID);
168 if (itr == _forces.end())
169 {
170 _forces.push_back(newForce);
171 return true;
172 }
173
174 return false;
175 }
176
178 {
179 auto itr = FindMovementForce(id);
180 if (itr != _forces.end())
181 {
182 _forces.erase(itr);
183 return true;
184 }
185
186 return false;
187 }
188
189 float GetModMagnitude() const { return _modMagnitude; }
190 void SetModMagnitude(float modMagnitude) { _modMagnitude = modMagnitude; }
191
192 bool IsEmpty() const { return _forces.empty() && _modMagnitude == 1.0f; }
193
194private:
195 Container::iterator FindMovementForce(ObjectGuid id)
196 {
197 return std::find_if(_forces.begin(), _forces.end(), [id](MovementForce const& force) { return force.ID == id; });
198 }
199
201 float _modMagnitude = 1.0f;
202};
203
204#endif // MovementInfo_h__
uint8_t uint8
Definition: Define.h:144
int8_t int8
Definition: Define.h:140
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
MovementForceType
Definition: MovementInfo.h:143
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Container const * GetForces() const
Definition: MovementInfo.h:164
float GetModMagnitude() const
Definition: MovementInfo.h:189
bool Remove(ObjectGuid id)
Definition: MovementInfo.h:177
void SetModMagnitude(float modMagnitude)
Definition: MovementInfo.h:190
Container::iterator FindMovementForce(ObjectGuid id)
Definition: MovementInfo.h:195
bool IsEmpty() const
Definition: MovementInfo.h:192
std::vector< MovementForce > Container
Definition: MovementInfo.h:162
bool Add(MovementForce const &newForce)
Definition: MovementInfo.h:165
Container _forces
Definition: MovementInfo.h:200
void Clear()
Definition: ObjectGuid.h:286
MovementForceType Type
Definition: MovementInfo.h:155
uint32 TransportID
Definition: MovementInfo.h:153
TaggedPosition< Position::XYZ > Origin
Definition: MovementInfo.h:151
ObjectGuid ID
Definition: MovementInfo.h:150
TaggedPosition< Position::XYZ > Direction
Definition: MovementInfo.h:152
ObjectGuid guid
Definition: MovementInfo.h:30
void ResetTransport()
Definition: MovementInfo.h:129
bool HasExtraMovementFlag(uint32 flag) const
Definition: MovementInfo.h:118
Optional< Inertia > inertia
Definition: MovementInfo.h:70
void AddExtraMovementFlag2(uint32 flag)
Definition: MovementInfo.h:122
bool HasExtraMovementFlag2(uint32 flag) const
Definition: MovementInfo.h:124
void RemoveExtraMovementFlag(uint32 flag)
Definition: MovementInfo.h:117
uint32 flags3
Definition: MovementInfo.h:33
void SetFallTime(uint32 fallTime)
Definition: MovementInfo.h:127
void SetExtraMovementFlags2(uint32 flag)
Definition: MovementInfo.h:121
void ResetJump()
Definition: MovementInfo.h:134
Optional< ObjectGuid > standingOnGameObjectGUID
Definition: MovementInfo.h:98
uint32 GetExtraMovementFlags2() const
Definition: MovementInfo.h:120
void AddExtraMovementFlag(uint32 flag)
Definition: MovementInfo.h:116
uint32 GetFallTime() const
Definition: MovementInfo.h:126
struct MovementInfo::JumpInfo jump
float stepUpStartElevation
Definition: MovementInfo.h:87
void RemoveMovementFlag(uint32 flag)
Definition: MovementInfo.h:111
uint32 flags
Definition: MovementInfo.h:31
struct MovementInfo::TransportInfo transport
uint32 GetExtraMovementFlags() const
Definition: MovementInfo.h:114
void SetMovementFlags(uint32 flag)
Definition: MovementInfo.h:109
void RemoveExtraMovementFlag2(uint32 flag)
Definition: MovementInfo.h:123
bool HasMovementFlag(uint32 flag) const
Definition: MovementInfo.h:112
uint32 GetMovementFlags() const
Definition: MovementInfo.h:108
void AddMovementFlag(uint32 flag)
Definition: MovementInfo.h:110
uint32 flags2
Definition: MovementInfo.h:32
void SetExtraMovementFlags(uint32 flag)
Definition: MovementInfo.h:115
void OutDebug()
Definition: Object.cpp:823
Position pos
Definition: MovementInfo.h:34
Optional< AdvFlying > advFlying
Definition: MovementInfo.h:96
constexpr void Relocate(float x, float y)
Definition: Position.h:63