TrinityCore
Loading...
Searching...
No Matches
MovementGenerator.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 TRINITY_MOVEMENTGENERATOR_H
19#define TRINITY_MOVEMENTGENERATOR_H
20
21#include "Define.h"
22#include "FactoryHolder.h"
23#include "ObjectRegistry.h"
24
25class Creature;
26class Unit;
27
29
47
49{
50 public:
51 MovementGenerator() : Priority(0), Flags(MOVEMENTGENERATOR_FLAG_NONE), BaseUnitState(0) { }
52 virtual ~MovementGenerator();
53
54 // on top first update
55 virtual bool Initialize(Unit*) = 0;
56 // on top reassign
57 virtual bool Reset(Unit*) = 0;
58 // on top on MotionMaster::Update
59 virtual bool Update(Unit*, uint32 diff) = 0;
60 // on current top if another movement replaces
61 virtual void Deactivate(Unit*) = 0;
62 // on movement delete
63 virtual void Finalize(Unit*, bool, bool) = 0;
65
66 virtual void UnitSpeedChanged() { }
67 // timer in ms
68 virtual void Pause(uint32/* timer = 0*/) { }
69 // timer in ms
70 virtual void Resume(uint32/* overrideTimer = 0*/) { }
71 // used by Evade code for select point to evade with expected restart default movement
72 virtual bool GetResetPosition(Unit*, float&/* x*/, float&/* y*/, float&/* z*/) { return false; }
73
74 void AddFlag(uint16 const flag) { Flags |= flag; }
75 bool HasFlag(uint16 const flag) const { return (Flags & flag) != 0; }
76 void RemoveFlag(uint16 const flag) { Flags &= ~flag; }
77
78 virtual std::string GetDebugInfo() const;
79
83};
84
85template<class T, class D>
87{
88 public:
89 bool Initialize(Unit* owner) override
90 {
91 return (static_cast<D*>(this))->DoInitialize(static_cast<T*>(owner));
92 }
93
94 bool Reset(Unit* owner) override
95 {
96 return (static_cast<D*>(this))->DoReset(static_cast<T*>(owner));
97 }
98
99 bool Update(Unit* owner, uint32 diff) override
100 {
101 return (static_cast<D*>(this))->DoUpdate(static_cast<T*>(owner), diff);
102 }
103
104 void Deactivate(Unit* owner) override
105 {
106 (static_cast<D*>(this))->DoDeactivate(static_cast<T*>(owner));
107 }
108
109 void Finalize(Unit* owner, bool active, bool movementInform) override
110 {
111 (static_cast<D*>(this))->DoFinalize(static_cast<T*>(owner), active, movementInform);
112 }
113};
114
116
117template<class Movement>
119{
120 MovementGeneratorFactory(MovementGeneratorType movementGeneratorType) : MovementGeneratorCreator(movementGeneratorType) { }
121
122 MovementGenerator* Create(Unit* /*object*/) const override
123 {
124 return new Movement();
125 }
126};
127
129{
131
132 MovementGenerator* Create(Unit* object) const override;
133};
134
136{
138
139 MovementGenerator* Create(Unit* object) const override;
140};
141
143{
145
146 MovementGenerator* Create(Unit* object) const override;
147};
148
150
151#define sMovementGeneratorRegistry MovementGeneratorRegistry::instance()
152
153#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
std::string GetDebugInfo()
Definition Errors.cpp:155
MovementGeneratorType
MovementGeneratorFlags
@ MOVEMENTGENERATOR_FLAG_TIMED_PAUSED
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_PAUSED
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_TRANSITORY
@ MOVEMENTGENERATOR_FLAG_INTERRUPTED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_IMMEDIATE
@ MOVEMENTGENERATOR_FLAG_PERSIST_ON_DEATH
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ MOVEMENTGENERATOR_FLAG_NONE
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
MovementGeneratorCreator::FactoryHolderRegistry MovementGeneratorRegistry
FactoryHolder< MovementGenerator, Unit, MovementGeneratorType > MovementGeneratorCreator
void Deactivate(Unit *owner) override
bool Reset(Unit *owner) override
void Finalize(Unit *owner, bool active, bool movementInform) override
bool Initialize(Unit *owner) override
bool Update(Unit *owner, uint32 diff) override
virtual void Deactivate(Unit *)=0
virtual void Pause(uint32)
virtual bool GetResetPosition(Unit *, float &, float &, float &)
virtual void Resume(uint32)
void AddFlag(uint16 const flag)
virtual bool Update(Unit *, uint32 diff)=0
bool HasFlag(uint16 const flag) const
virtual void UnitSpeedChanged()
virtual bool Initialize(Unit *)=0
virtual bool Reset(Unit *)=0
void RemoveFlag(uint16 const flag)
virtual MovementGeneratorType GetMovementGeneratorType() const =0
virtual void Finalize(Unit *, bool, bool)=0
Definition Unit.h:769
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *) const override
MovementGeneratorFactory(MovementGeneratorType movementGeneratorType)
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *object) const override