| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef TRINITY_MOVEMENTGENERATOR_H |
|---|
| 22 | #define TRINITY_MOVEMENTGENERATOR_H |
|---|
| 23 | |
|---|
| 24 | #include "Platform/Define.h" |
|---|
| 25 | #include "Policies/Singleton.h" |
|---|
| 26 | #include "Dynamic/ObjectRegistry.h" |
|---|
| 27 | #include "Dynamic/FactoryHolder.h" |
|---|
| 28 | #include "Common.h" |
|---|
| 29 | #include "MotionMaster.h" |
|---|
| 30 | |
|---|
| 31 | class Unit; |
|---|
| 32 | |
|---|
| 33 | class TRINITY_DLL_SPEC MovementGenerator |
|---|
| 34 | { |
|---|
| 35 | public: |
|---|
| 36 | virtual ~MovementGenerator(); |
|---|
| 37 | |
|---|
| 38 | virtual void Initialize(Unit &) = 0; |
|---|
| 39 | virtual void Finalize(Unit &) = 0; |
|---|
| 40 | |
|---|
| 41 | virtual void Reset(Unit &) = 0; |
|---|
| 42 | |
|---|
| 43 | virtual bool Update(Unit &, const uint32 &time_diff) = 0; |
|---|
| 44 | |
|---|
| 45 | virtual MovementGeneratorType GetMovementGeneratorType() = 0; |
|---|
| 46 | |
|---|
| 47 | virtual void unitSpeedChanged() { } |
|---|
| 48 | |
|---|
| 49 | virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; } |
|---|
| 50 | }; |
|---|
| 51 | |
|---|
| 52 | template<class T, class D> |
|---|
| 53 | class TRINITY_DLL_SPEC MovementGeneratorMedium : public MovementGenerator |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | void Initialize(Unit &u) |
|---|
| 57 | { |
|---|
| 58 | //u->AssertIsType<T>(); |
|---|
| 59 | (static_cast<D*>(this))->Initialize(*((T*)&u)); |
|---|
| 60 | } |
|---|
| 61 | void Finalize(Unit &u) |
|---|
| 62 | { |
|---|
| 63 | //u->AssertIsType<T>(); |
|---|
| 64 | (static_cast<D*>(this))->Finalize(*((T*)&u)); |
|---|
| 65 | } |
|---|
| 66 | void Reset(Unit &u) |
|---|
| 67 | { |
|---|
| 68 | //u->AssertIsType<T>(); |
|---|
| 69 | (static_cast<D*>(this))->Reset(*((T*)&u)); |
|---|
| 70 | } |
|---|
| 71 | bool Update(Unit &u, const uint32 &time_diff) |
|---|
| 72 | { |
|---|
| 73 | //u->AssertIsType<T>(); |
|---|
| 74 | return (static_cast<D*>(this))->Update(*((T*)&u), time_diff); |
|---|
| 75 | } |
|---|
| 76 | public: |
|---|
| 77 | // will not link if not overridden in the generators |
|---|
| 78 | void Initialize(T &u); |
|---|
| 79 | void Finalize(T &u); |
|---|
| 80 | void Reset(T &u); |
|---|
| 81 | bool Update(T &u, const uint32 &time_diff); |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType> |
|---|
| 85 | { |
|---|
| 86 | SelectableMovement(MovementGeneratorType mgt) : FactoryHolder<MovementGenerator,MovementGeneratorType>(mgt) {} |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | template<class REAL_MOVEMENT> |
|---|
| 90 | struct MovementGeneratorFactory : public SelectableMovement |
|---|
| 91 | { |
|---|
| 92 | MovementGeneratorFactory(MovementGeneratorType mgt) : SelectableMovement(mgt) {} |
|---|
| 93 | |
|---|
| 94 | MovementGenerator* Create(void *) const; |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType> MovementGeneratorCreator; |
|---|
| 98 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry; |
|---|
| 99 | typedef FactoryHolder<MovementGenerator,MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository; |
|---|
| 100 | #endif |
|---|