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 "MovementDefines.h"
24#include "ObjectRegistry.h"
25#include "ScriptActionResult.h"
26
27class Creature;
28class Unit;
29
31
48
50{
51 public:
52 explicit MovementGenerator() : Mode(0), Priority(0), Flags(MOVEMENTGENERATOR_FLAG_NONE), BaseUnitState(0) { }
57 virtual ~MovementGenerator();
58
59 // on top first update
60 virtual void Initialize(Unit* owner) = 0;
61 // on top reassign
62 virtual void Reset(Unit* owner) = 0;
63 // on top on MotionMaster::Update
64 virtual bool Update(Unit* owner, uint32 diff) = 0;
65 // on current top if another movement replaces
66 virtual void Deactivate(Unit* owner) = 0;
67 // on movement delete
68 virtual void Finalize(Unit* owner, bool active, bool movementInform) = 0;
70
71 virtual void UnitSpeedChanged() { }
72 // timer in ms
73 virtual void Pause(uint32/* timer*/) { }
74 // timer in ms
75 virtual void Resume(uint32/* overrideTimer*/) { }
76 // used by Evade code for select point to evade with expected restart default movement
77 virtual bool GetResetPosition(Unit*, float&/* x*/, float&/* y*/, float&/* z*/) { return false; }
78
79 void AddFlag(uint16 const flag) { Flags |= flag; }
80 bool HasFlag(uint16 const flag) const { return (Flags & flag) != 0; }
81 void RemoveFlag(uint16 const flag) { Flags &= ~flag; }
82
83 virtual std::string GetDebugInfo() const;
84
90
91 protected:
92 void SetScriptResult(MovementStopReason reason);
93};
94
95template<class T, class D>
97{
98 public:
99 void Initialize(Unit* owner) override
100 {
101 (static_cast<D*>(this))->DoInitialize(static_cast<T*>(owner));
102 }
103
104 void Reset(Unit* owner) override
105 {
106 (static_cast<D*>(this))->DoReset(static_cast<T*>(owner));
107 }
108
109 bool Update(Unit* owner, uint32 diff) override
110 {
111 return (static_cast<D*>(this))->DoUpdate(static_cast<T*>(owner), diff);
112 }
113
114 void Deactivate(Unit* owner) override
115 {
116 (static_cast<D*>(this))->DoDeactivate(static_cast<T*>(owner));
117 }
118
119 void Finalize(Unit* owner, bool active, bool movementInform) override
120 {
121 (static_cast<D*>(this))->DoFinalize(static_cast<T*>(owner), active, movementInform);
122 }
123};
124
126
133
140
147
149
150#define sMovementGeneratorRegistry MovementGeneratorRegistry::instance()
151
152#endif
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
std::string GetDebugInfo()
Definition Errors.cpp:170
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
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)
virtual void Finalize(Unit *owner, bool active, bool movementInform)=0
Scripting::v2::ActionResultSetter< MovementStopReason > ScriptResult
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:635
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *object) const override
MovementGenerator * Create(Unit *object) const override