[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / TargetedMovementGenerator.h
blob738d4233cbf16a307ee960e0fb57fca351c1919f
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_TARGETEDMOVEMENTGENERATOR_H
20 #define MANGOS_TARGETEDMOVEMENTGENERATOR_H
22 #include "MovementGenerator.h"
23 #include "DestinationHolder.h"
24 #include "Traveller.h"
25 #include "FollowerReference.h"
27 class MANGOS_DLL_SPEC TargetedMovementGeneratorBase
29 public:
30 TargetedMovementGeneratorBase(Unit &target) { i_target.link(&target, this); }
31 void stopFollowing() { }
32 protected:
33 FollowerReference i_target;
36 template<class T, typename D>
37 class MANGOS_DLL_SPEC TargetedMovementGeneratorMedium
38 : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase
40 protected:
41 TargetedMovementGeneratorMedium()
42 : TargetedMovementGeneratorBase(), i_offset(0), i_angle(0), i_recalculateTravel(false) {}
43 TargetedMovementGeneratorMedium(Unit &target)
44 : TargetedMovementGeneratorBase(target), i_offset(0), i_angle(0), i_recalculateTravel(false) {}
45 TargetedMovementGeneratorMedium(Unit &target, float offset, float angle)
46 : TargetedMovementGeneratorBase(target), i_offset(offset), i_angle(angle), i_recalculateTravel(false) {}
47 ~TargetedMovementGeneratorMedium() {}
49 public:
50 bool Update(T &, const uint32 &);
52 Unit* GetTarget() const { return i_target.getTarget(); }
54 bool GetDestination(float &x, float &y, float &z) const
56 if(!i_destinationHolder.HasDestination()) return false;
57 i_destinationHolder.GetDestination(x,y,z);
58 return true;
61 void unitSpeedChanged() { i_recalculateTravel=true; }
62 void UpdateFinalDistance(float fDistance);
64 protected:
65 void _setTargetLocation(T &);
67 float i_offset;
68 float i_angle;
69 DestinationHolder< Traveller<T> > i_destinationHolder;
70 bool i_recalculateTravel;
73 template<class T>
74 class MANGOS_DLL_SPEC ChaseMovementGenerator : public TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >
76 public:
77 ChaseMovementGenerator(Unit &target)
78 : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target) {}
79 ChaseMovementGenerator(Unit &target, float offset, float angle)
80 : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target, offset, angle) {}
81 ~ChaseMovementGenerator() {}
83 MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; }
85 void Initialize(T &);
86 void Finalize(T &);
87 void Interrupt(T &);
88 void Reset(T &);
90 static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_CHASE_MOVE); }
91 static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_CHASE_MOVE); }
92 bool _lostTarget(T &u) const { return u.getVictim() != this->GetTarget(); }
93 void _reachTarget(T &);
96 template<class T>
97 class MANGOS_DLL_SPEC FollowMovementGenerator : public TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >
99 public:
100 FollowMovementGenerator(Unit &target)
101 : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target){}
102 FollowMovementGenerator(Unit &target, float offset, float angle)
103 : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target, offset, angle) {}
104 ~FollowMovementGenerator() {}
106 MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; }
108 void Initialize(T &);
109 void Finalize(T &);
110 void Interrupt(T &);
111 void Reset(T &);
113 static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_FOLLOW_MOVE); }
114 static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_FOLLOW_MOVE); }
115 bool _lostTarget(T &) const { return false; }
116 void _reachTarget(T &) {}
117 private:
118 void _updateWalkMode(T &u);
119 void _updateSpeed(T &u);
122 #endif