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
30 TargetedMovementGeneratorBase(Unit
&target
) { i_target
.link(&target
, this); }
31 void stopFollowing() { }
33 FollowerReference i_target
;
36 template<class T
, typename D
>
37 class MANGOS_DLL_SPEC TargetedMovementGeneratorMedium
38 : public MovementGeneratorMedium
< T
, D
>, public TargetedMovementGeneratorBase
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() {}
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
);
61 void unitSpeedChanged() { i_recalculateTravel
=true; }
62 void UpdateFinalDistance(float fDistance
);
65 void _setTargetLocation(T
&);
69 DestinationHolder
< Traveller
<T
> > i_destinationHolder
;
70 bool i_recalculateTravel
;
74 class MANGOS_DLL_SPEC ChaseMovementGenerator
: public TargetedMovementGeneratorMedium
<T
, ChaseMovementGenerator
<T
> >
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() const { return CHASE_MOTION_TYPE
; }
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
&);
97 class MANGOS_DLL_SPEC FollowMovementGenerator
: public TargetedMovementGeneratorMedium
<T
, FollowMovementGenerator
<T
> >
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() const { return FOLLOW_MOTION_TYPE
; }
108 void Initialize(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
&) {}
118 void _updateWalkMode(T
&u
);
119 void _updateSpeed(T
&u
);