1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef MANGOS_MOVEMENTGENERATOR_H |
---|
20 | #define MANGOS_MOVEMENTGENERATOR_H |
---|
21 | |
---|
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" |
---|
28 | |
---|
29 | class Unit; |
---|
30 | |
---|
31 | class MANGOS_DLL_SPEC MovementGenerator |
---|
32 | { |
---|
33 | public: |
---|
34 | virtual ~MovementGenerator(); |
---|
35 | |
---|
36 | virtual void Initialize(Unit &) = 0; |
---|
37 | virtual void Finalize(Unit &) = 0; |
---|
38 | |
---|
39 | virtual void Reset(Unit &) = 0; |
---|
40 | |
---|
41 | virtual bool Update(Unit &, const uint32 &time_diff) = 0; |
---|
42 | |
---|
43 | virtual MovementGeneratorType GetMovementGeneratorType() = 0; |
---|
44 | |
---|
45 | virtual void unitSpeedChanged() { } |
---|
46 | |
---|
47 | virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; } |
---|
48 | }; |
---|
49 | |
---|
50 | template<class T, class D> |
---|
51 | class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator |
---|
52 | { |
---|
53 | public: |
---|
54 | void Initialize(Unit &u) |
---|
55 | { |
---|
56 | //u->AssertIsType<T>(); |
---|
57 | (static_cast<D*>(this))->Initialize(*((T*)&u)); |
---|
58 | } |
---|
59 | void Finalize(Unit &u) |
---|
60 | { |
---|
61 | //u->AssertIsType<T>(); |
---|
62 | (static_cast<D*>(this))->Finalize(*((T*)&u)); |
---|
63 | } |
---|
64 | void Reset(Unit &u) |
---|
65 | { |
---|
66 | //u->AssertIsType<T>(); |
---|
67 | (static_cast<D*>(this))->Reset(*((T*)&u)); |
---|
68 | } |
---|
69 | bool Update(Unit &u, const uint32 &time_diff) |
---|
70 | { |
---|
71 | //u->AssertIsType<T>(); |
---|
72 | return (static_cast<D*>(this))->Update(*((T*)&u), time_diff); |
---|
73 | } |
---|
74 | public: |
---|
75 | // will not link if not overridden in the generators |
---|
76 | void Initialize(T &u); |
---|
77 | void Finalize(T &u); |
---|
78 | void Reset(T &u); |
---|
79 | bool Update(T &u, const uint32 &time_diff); |
---|
80 | }; |
---|
81 | |
---|
82 | struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType> |
---|
83 | { |
---|
84 | SelectableMovement(MovementGeneratorType mgt) : FactoryHolder<MovementGenerator,MovementGeneratorType>(mgt) {} |
---|
85 | }; |
---|
86 | |
---|
87 | template<class REAL_MOVEMENT> |
---|
88 | struct MovementGeneratorFactory : public SelectableMovement |
---|
89 | { |
---|
90 | MovementGeneratorFactory(MovementGeneratorType mgt) : SelectableMovement(mgt) {} |
---|
91 | |
---|
92 | MovementGenerator* Create(void *) const; |
---|
93 | }; |
---|
94 | |
---|
95 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType> MovementGeneratorCreator; |
---|
96 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry; |
---|
97 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository; |
---|
98 | #endif |
---|