TrinityCore
Loading...
Searching...
No Matches
GenericMovementGenerator.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 "MovementDefines.h"
22#include "MoveSpline.h"
23#include "Unit.h"
24
25GenericMovementGenerator::GenericMovementGenerator(std::function<void(Movement::MoveSplineInit& init)>&& initializer, MovementGeneratorType type, uint32 id) : _splineInit(std::move(initializer)), _type(type), _pointId(id), _duration(0)
26{
30}
31
49
51{
52 return Initialize(owner);
53}
54
56{
58 return false;
59
60 // Cyclic splines never expire, so update the duration only if it's not cyclic
61 if (!owner->movespline->isCyclic())
62 _duration.Update(diff);
63
64 if (_duration.Passed() || owner->movespline->Finalized())
65 {
67 return false;
68 }
69 return true;
70}
71
76
77void GenericMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
78{
80
82 MovementInform(owner);
83}
84
86{
87 if (Creature* creature = owner->ToCreature())
88 {
89 if (creature->AI())
90 creature->AI()->MovementInform(_type, _pointId);
91 }
92}
93
95 : _splineInit(std::move(initializer)), _type(type), _pointId(id)
96{
99 BaseUnitState = 0;
100}
101
103{
106
107 Movement::MoveSplineInit init(owner);
108 _splineInit(init);
109 int32 duration = init.Launch();
110 if (duration <= 0)
111 return false;
112
113 owner->UpdateSplineMovement(duration); // immediately consume the entire spline
114 return true;
115}
116
117void ImmediateMovementGenerator::Finalize(Unit* owner, bool /*active*/, bool /*movementInform*/)
118{
119 if (Creature* creature = owner->ToCreature())
120 if (creature->AI())
121 creature->AI()->MovementInform(_type, _pointId);
122}
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
@ MOTION_PRIORITY_NORMAL
MovementGeneratorType
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_IMMEDIATE
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ UNIT_STATE_ROAMING
Definition Unit.h:224
void Finalize(Unit *, bool, bool) override
bool Update(Unit *, uint32) override
GenericMovementGenerator(std::function< void(Movement::MoveSplineInit &init)> &&initializer, MovementGeneratorType type, uint32 id)
std::function< void(Movement::MoveSplineInit &init)> _splineInit
bool Initialize(Unit *owner) override
ImmediateMovementGenerator(std::function< void(Movement::MoveSplineInit &init)> &&initializer, MovementGeneratorType type, uint32 id)
void Finalize(Unit *owner, bool active, bool movementInform) override
std::function< void(Movement::MoveSplineInit &init)> _splineInit
void AddFlag(uint16 const flag)
bool HasFlag(uint16 const flag) const
void RemoveFlag(uint16 const flag)
bool isCyclic() const
Definition MoveSpline.h:122
bool Finalized() const
Definition MoveSpline.h:121
static Creature * ToCreature(Object *o)
Definition Object.h:186
Definition Unit.h:769
Movement::MoveSpline * movespline
Definition Unit.h:1804
void UpdateSplineMovement(uint32 t_diff)
Definition Unit.cpp:528
STL namespace.
void Update(int32 diff)
Definition Timer.h:121
bool Passed() const
Definition Timer.h:131
void Reset(int32 expiry)
Definition Timer.h:136
Milliseconds GetExpiry() const
Definition Timer.h:146