TrinityCore
Loading...
Searching...
No Matches
PointMovementGenerator.cpp
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
19#include "Creature.h"
20#include "CreatureAI.h"
21#include "Player.h"
22#include "MotionMaster.h"
23#include "MovementDefines.h"
24#include "MoveSpline.h"
25#include "MoveSplineInit.h"
26#include "World.h"
27
28//----- Point Movement Generator
29
30template<class T>
31PointMovementGenerator<T>::PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, float speed, Optional<float> finalOrient) : _movementId(id), _x(x), _y(y), _z(z), _speed(speed), _generatePath(generatePath), _finalOrient(finalOrient)
33 this->Priority = MOTION_PRIORITY_NORMAL;
35 this->BaseUnitState = UNIT_STATE_ROAMING;
38template<class T>
43
44template<class T>
46{
49
50 if (_movementId == EVENT_CHARGE_PREPATH)
51 {
52 owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
53 return true;
54 }
55
56 if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting())
57 {
59 owner->StopMoving();
60 return true;
61 }
62
63 owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
64
65 Movement::MoveSplineInit init(owner);
66 init.MoveTo(_x, _y, _z , _generatePath);
67 if (_speed > 0.0f)
68 init.SetVelocity(_speed);
69
70 if (_finalOrient)
71 init.SetFacing(*_finalOrient);
72
73 init.Launch();
74
75 // Call for creature group update
76 if (Creature* creature = owner->ToCreature())
77 creature->SignalFormationMovement();
78 return true;
79}
80
81template<class T>
88
89template<class T>
91{
92 if (!owner)
93 return false;
94
95 if (_movementId == EVENT_CHARGE_PREPATH)
96 {
97 if (owner->movespline->Finalized())
98 {
100 return false;
101 }
102 return true;
103 }
104
105 if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting())
106 {
108 owner->StopMoving();
109 return true;
110 }
111
112 if ((MovementGenerator::HasFlag(MOVEMENTGENERATOR_FLAG_INTERRUPTED) && owner->movespline->Finalized()) || (MovementGenerator::HasFlag(MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING) && !owner->movespline->Finalized()))
113 {
115
116 owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
117
118 Movement::MoveSplineInit init(owner);
119 init.MoveTo(_x, _y, _z, _generatePath);
120 if (_speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
121 init.SetVelocity(_speed);
122 init.Launch();
123
124 // Call for creature group update
125 if (Creature* creature = owner->ToCreature())
126 creature->SignalFormationMovement();
127 }
128
129 if (owner->movespline->Finalized())
130 {
133 return false;
134 }
135 return true;
136}
137
138template<class T>
144
145template<class T>
146void PointMovementGenerator<T>::DoFinalize(T* owner, bool active, bool movementInform)
147{
149 if (active)
150 owner->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
151
153 MovementInform(owner);
154}
155
156template<class T>
158
159template <>
161{
162 if (owner->AI())
163 owner->AI()->MovementInform(POINT_MOTION_TYPE, _movementId);
164}
165
166template PointMovementGenerator<Player>::PointMovementGenerator(uint32, float, float, float, bool, float, Optional<float>);
167template PointMovementGenerator<Creature>::PointMovementGenerator(uint32, float, float, float, bool, float, Optional<float>);
178template void PointMovementGenerator<Player>::DoFinalize(Player*, bool, bool);
180
181//---- AssistanceMovementGenerator
182
183void AssistanceMovementGenerator::Finalize(Unit* owner, bool active, bool movementInform)
184{
186 if (active)
188
189 if (movementInform && HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED))
190 {
191 Creature* ownerCreature = owner->ToCreature();
192 ownerCreature->SetNoCallAssistance(false);
193 ownerCreature->CallAssistance();
194 if (ownerCreature->IsAlive())
196 }
197}
198
uint32_t uint32
Definition Define.h:133
@ MOTION_PRIORITY_NORMAL
MovementGeneratorType
@ ASSISTANCE_MOTION_TYPE
@ POINT_MOTION_TYPE
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_TRANSITORY
@ MOVEMENTGENERATOR_FLAG_INTERRUPTED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
@ EVENT_CHARGE_PREPATH
@ UNIT_STATE_NOT_MOVE
Definition Unit.h:265
@ UNIT_STATE_ROAMING_MOVE
Definition Unit.h:243
@ UNIT_STATE_ROAMING
Definition Unit.h:224
void Finalize(Unit *, bool, bool) override
MovementGeneratorType GetMovementGeneratorType() const override
virtual void MovementInform(uint32, uint32)
Definition CreatureAI.h:173
void SetNoCallAssistance(bool val)
Definition Creature.h:244
void CallAssistance()
CreatureAI * AI() const
Definition Creature.h:154
void MoveSeekAssistanceDistract(uint32 timer)
void AddFlag(uint16 const flag)
bool HasFlag(uint16 const flag) const
void RemoveFlag(uint16 const flag)
void MoveTo(Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
void SetVelocity(float velocity)
void SetFacing(float angle)
static Creature * ToCreature(Object *o)
Definition Object.h:186
void DoFinalize(T *, bool, bool)
MovementGeneratorType GetMovementGeneratorType() const override
PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, float speed=0.0f, Optional< float > finalOrient={})
Definition Unit.h:769
void ClearUnitState(uint32 f)
Definition Unit.h:877
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
bool IsAlive() const
Definition Unit.h:1234
#define sWorld
Definition World.h:900
@ CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY
Definition World.h:288