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"
27 #include "MotionMaster.h"
31 class MANGOS_DLL_SPEC MovementGenerator
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 virtual void UpdateFinalDistance(float /*fDistance*/) { }
54 virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; }
56 // used by Evade code for select point to evade with expected restart default movement
57 virtual bool GetResetPosition(Unit
&, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
59 // used for check from Update call is movegen still be active (top movement generator)
60 // after some not safe for this calls
61 bool IsActive(Unit
& u
);
64 template<class T
, class D
>
65 class MANGOS_DLL_SPEC MovementGeneratorMedium
: public MovementGenerator
68 void Initialize(Unit
&u
)
70 //u->AssertIsType<T>();
71 (static_cast<D
*>(this))->Initialize(*((T
*)&u
));
73 void Finalize(Unit
&u
)
75 //u->AssertIsType<T>();
76 (static_cast<D
*>(this))->Finalize(*((T
*)&u
));
78 void Interrupt(Unit
&u
)
80 //u->AssertIsType<T>();
81 (static_cast<D
*>(this))->Interrupt(*((T
*)&u
));
85 //u->AssertIsType<T>();
86 (static_cast<D
*>(this))->Reset(*((T
*)&u
));
88 bool Update(Unit
&u
, const uint32
&time_diff
)
90 //u->AssertIsType<T>();
91 return (static_cast<D
*>(this))->Update(*((T
*)&u
), time_diff
);
93 bool GetResetPosition(Unit
& u
, float& x
, float& y
, float& z
)
95 //u->AssertIsType<T>();
96 return (static_cast<D
*>(this))->GetResetPosition(*((T
*)&u
), x
, y
, z
);
99 // will not link if not overridden in the generators
100 void Initialize(T
&u
);
102 void Interrupt(T
&u
);
104 bool Update(T
&u
, const uint32
&time_diff
);
106 // not need always overwrites
107 bool GetResetPosition(T
& /*u*/, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
110 struct SelectableMovement
: public FactoryHolder
<MovementGenerator
,MovementGeneratorType
>
112 SelectableMovement(MovementGeneratorType mgt
) : FactoryHolder
<MovementGenerator
,MovementGeneratorType
>(mgt
) {}
115 template<class REAL_MOVEMENT
>
116 struct MovementGeneratorFactory
: public SelectableMovement
118 MovementGeneratorFactory(MovementGeneratorType mgt
) : SelectableMovement(mgt
) {}
120 MovementGenerator
* Create(void *) const;
123 typedef FactoryHolder
<MovementGenerator
,MovementGeneratorType
> MovementGeneratorCreator
;
124 typedef FactoryHolder
<MovementGenerator
,MovementGeneratorType
>::FactoryHolderRegistry MovementGeneratorRegistry
;
125 typedef FactoryHolder
<MovementGenerator
,MovementGeneratorType
>::FactoryHolderRepository MovementGeneratorRepository
;