Updated Copyright year to 2013
[getmangos.git] / src / game / MovementGenerator.h
blob50be0e3c05a99bfd4cd07112cb6d3d53cbf3e730
1 /*
2 * Copyright (C) 2005-2013 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 "Common.h"
23 #include "Platform/Define.h"
24 #include "Policies/Singleton.h"
25 #include "Dynamic/ObjectRegistry.h"
26 #include "Dynamic/FactoryHolder.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() const = 0;
50 virtual void unitSpeedChanged() { }
52 // used by Evade code for select point to evade with expected restart default movement
53 virtual bool GetResetPosition(Unit&, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
55 // given destination unreachable? due to pathfinsing or other
56 virtual bool IsReachable() const { return true; }
58 // used for check from Update call is movegen still be active (top movement generator)
59 // after some not safe for this calls
60 bool IsActive(Unit& u);
63 template<class T, class D>
64 class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
66 public:
67 void Initialize(Unit& u) override
69 // u->AssertIsType<T>();
70 (static_cast<D*>(this))->Initialize(*((T*)&u));
72 void Finalize(Unit& u) override
74 // u->AssertIsType<T>();
75 (static_cast<D*>(this))->Finalize(*((T*)&u));
77 void Interrupt(Unit& u) override
79 // u->AssertIsType<T>();
80 (static_cast<D*>(this))->Interrupt(*((T*)&u));
82 void Reset(Unit& u) override
84 // u->AssertIsType<T>();
85 (static_cast<D*>(this))->Reset(*((T*)&u));
87 bool Update(Unit& u, const uint32& time_diff) override
89 // u->AssertIsType<T>();
90 return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
92 bool GetResetPosition(Unit& u, float& x, float& y, float& z) override
94 // u->AssertIsType<T>();
95 return (static_cast<D*>(this))->GetResetPosition(*((T*)&u), x, y, z);
97 public:
98 // Will not link if not overridden in the generators
99 void Initialize(T& u);
100 void Finalize(T& u);
101 void Interrupt(T& u);
102 void Reset(T& u);
103 bool Update(T& u, const uint32& time_diff);
105 // not need always overwrites
106 bool GetResetPosition(T& /*u*/, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
109 struct SelectableMovement : public FactoryHolder<MovementGenerator, MovementGeneratorType>
111 SelectableMovement(MovementGeneratorType mgt) : FactoryHolder<MovementGenerator, MovementGeneratorType>(mgt) {}
114 template<class REAL_MOVEMENT>
115 struct MovementGeneratorFactory : public SelectableMovement
117 MovementGeneratorFactory(MovementGeneratorType mgt) : SelectableMovement(mgt) {}
119 MovementGenerator* Create(void*) const override;
122 typedef FactoryHolder<MovementGenerator, MovementGeneratorType> MovementGeneratorCreator;
123 typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry;
124 typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository;
126 #endif