[9362] Make specs work at least for action bars
[getmangos.git] / src / game / MovementGenerator.h
blobbd77fb00eaa0ce7d0a13e850f272b805db4d862b
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_MOVEMENTGENERATOR_H
20 #define MANGOS_MOVEMENTGENERATOR_H
22 #include "Platform/Define.h"
23 #include "Policies/Singleton.h"
24 #include "Dynamic/ObjectRegistry.h"
25 #include "Dynamic/FactoryHolder.h"
26 #include "Common.h"
27 #include "MotionMaster.h"
29 class Unit;
31 class MANGOS_DLL_SPEC MovementGenerator
33 public:
34 virtual ~MovementGenerator();
36 // called before adding movement generator to motion stack
37 virtual void Initialize(Unit &) = 0;
38 // called aftre remove movement generator from motion stack
39 virtual void Finalize(Unit &) = 0;
41 // called before lost top position (before push new movement generator above)
42 virtual void Interrupt(Unit &) = 0;
43 // called after return movement generator to top position (after remove above movement generator)
44 virtual void Reset(Unit &) = 0;
46 virtual bool Update(Unit &, const uint32 &time_diff) = 0;
48 virtual MovementGeneratorType GetMovementGeneratorType() = 0;
50 virtual void unitSpeedChanged() { }
52 virtual void UpdateFinalDistance(float fDistance) { }
54 virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; }
57 template<class T, class D>
58 class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
60 public:
61 void Initialize(Unit &u)
63 //u->AssertIsType<T>();
64 (static_cast<D*>(this))->Initialize(*((T*)&u));
66 void Finalize(Unit &u)
68 //u->AssertIsType<T>();
69 (static_cast<D*>(this))->Finalize(*((T*)&u));
71 void Interrupt(Unit &u)
73 //u->AssertIsType<T>();
74 (static_cast<D*>(this))->Interrupt(*((T*)&u));
76 void Reset(Unit &u)
78 //u->AssertIsType<T>();
79 (static_cast<D*>(this))->Reset(*((T*)&u));
81 bool Update(Unit &u, const uint32 &time_diff)
83 //u->AssertIsType<T>();
84 return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
86 public:
87 // will not link if not overridden in the generators
88 void Initialize(T &u);
89 void Finalize(T &u);
90 void Interrupt(T &u);
91 void Reset(T &u);
92 bool Update(T &u, const uint32 &time_diff);
95 struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType>
97 SelectableMovement(MovementGeneratorType mgt) : FactoryHolder<MovementGenerator,MovementGeneratorType>(mgt) {}
100 template<class REAL_MOVEMENT>
101 struct MovementGeneratorFactory : public SelectableMovement
103 MovementGeneratorFactory(MovementGeneratorType mgt) : SelectableMovement(mgt) {}
105 MovementGenerator* Create(void *) const;
108 typedef FactoryHolder<MovementGenerator,MovementGeneratorType> MovementGeneratorCreator;
109 typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry;
110 typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository;
111 #endif