TrinityCore
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 "MovementDefines.h"
24#include "ObjectRegistry.h"
25#include "Optional.h"
26#include "ScriptActionResult.h"
27
28class Creature;
29class Unit;
30
32
34{
46
48};
49
51{
52 public:
53 explicit MovementGenerator() : Mode(0), Priority(0), Flags(MOVEMENTGENERATOR_FLAG_NONE), BaseUnitState(0) { }
58 virtual ~MovementGenerator();
59
60 // on top first update
61 virtual void Initialize(Unit* owner) = 0;
62 // on top reassign
63 virtual void Reset(Unit* owner) = 0;
64 // on top on MotionMaster::Update
65 virtual bool Update(Unit* owner, uint32 diff) = 0;
66 // on current top if another movement replaces
67 virtual void Deactivate(Unit* owner) = 0;
68 // on movement delete
69 virtual void Finalize(Unit* owner, bool active, bool movementInform) = 0;
71
72 virtual void UnitSpeedChanged() { }
73 // timer in ms
74 virtual void Pause(uint32/* timer*/) { }
75 // timer in ms
76 virtual void Resume(uint32/* overrideTimer*/) { }
77 // used by Evade code for select point to evade with expected restart default movement
78 virtual bool GetResetPosition(Unit*, float&/* x*/, float&/* y*/, float&/* z*/) { return false; }
79
80 void AddFlag(uint16 const flag) { Flags |= flag; }
81 bool HasFlag(uint16 const flag) const { return (Flags & flag) != 0; }
82 void RemoveFlag(uint16 const flag) { Flags &= ~flag; }
83
84 virtual std::string GetDebugInfo() const;
85
91
92 protected:
93 void SetScriptResult(MovementStopReason reason);
94};
95
96template<class T, class D>
98{
99 public:
100 void Initialize(Unit* owner) override
101 {
102 (static_cast<D*>(this))->DoInitialize(static_cast<T*>(owner));
103 }
104
105 void Reset(Unit* owner) override
106 {
107 (static_cast<D*>(this))->DoReset(static_cast<T*>(owner));
108 }
109
110 bool Update(Unit* owner, uint32 diff) override
111 {
112 return (static_cast<D*>(this))->DoUpdate(static_cast<T*>(owner), diff);
113 }
114
115 void Deactivate(Unit* owner) override
116 {
117 (static_cast<D*>(this))->DoDeactivate(static_cast<T*>(owner));
118 }
119
120 void Finalize(Unit* owner, bool active, bool movementInform) override
121 {
122 (static_cast<D*>(this))->DoFinalize(static_cast<T*>(owner), active, movementInform);
123 }
124};
125
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:123
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::string GetDebugInfo()
Definition: Errors.cpp:157
MovementGeneratorType
@ IDLE_MOTION_TYPE
@ WAYPOINT_MOTION_TYPE
@ RANDOM_MOTION_TYPE
MovementStopReason
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_PERSIST_ON_DEATH
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ MOVEMENTGENERATOR_FLAG_NONE
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
MovementGeneratorCreator::FactoryHolderRegistry MovementGeneratorRegistry
FactoryHolder< MovementGenerator, Unit, MovementGeneratorType > MovementGeneratorCreator
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
void Deactivate(Unit *owner) override
void Reset(Unit *owner) override
void Initialize(Unit *owner) override
void Finalize(Unit *owner, bool active, bool movementInform) override
bool Update(Unit *owner, uint32 diff) override
virtual void Initialize(Unit *owner)=0
MovementGenerator(MovementGenerator const &)=delete
virtual void Pause(uint32)
virtual bool GetResetPosition(Unit *, float &, float &, float &)
MovementGenerator & operator=(MovementGenerator const &)=delete
MovementGenerator & operator=(MovementGenerator &&)=delete
virtual void Resume(uint32)
virtual bool Update(Unit *owner, uint32 diff)=0
virtual void Deactivate(Unit *owner)=0
void AddFlag(uint16 const flag)
Optional< Scripting::v2::ActionResultSetter< MovementStopReason > > ScriptResult
virtual void Finalize(Unit *owner, bool active, bool movementInform)=0
bool HasFlag(uint16 const flag) const
MovementGenerator(MovementGenerator &&)=delete
virtual void Reset(Unit *owner)=0
virtual void UnitSpeedChanged()
void RemoveFlag(uint16 const flag)
virtual MovementGeneratorType GetMovementGeneratorType() const =0
Definition: Unit.h:630
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *object) const override