TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TargetedMovementGenerator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_TARGETEDMOVEMENTGENERATOR_H
20 #define TRINITY_TARGETEDMOVEMENTGENERATOR_H
21 
22 #include "MovementGenerator.h"
23 #include "FollowerReference.h"
24 #include "Timer.h"
25 #include "Unit.h"
26 #include "PathGenerator.h"
27 
29 {
30  public:
31  TargetedMovementGeneratorBase(Unit* target) { i_target.link(target, this); }
32  void stopFollowing() { }
33  protected:
35 };
36 
37 template<class T, typename D>
39 {
40  protected:
41  TargetedMovementGeneratorMedium(Unit* target, float offset, float angle) :
43  i_recheckDistance(0), i_offset(offset), i_angle(angle),
45  {
46  }
48 
49  public:
50  bool DoUpdate(T*, uint32);
51  Unit* GetTarget() const { return i_target.getTarget(); }
52 
53  void unitSpeedChanged() override { i_recalculateTravel = true; }
54  bool IsReachable() const { return (i_path) ? (i_path->GetPathType() & PATHFIND_NORMAL) : true; }
55  protected:
56  void _setTargetLocation(T* owner, bool updateDestination);
57 
60  float i_offset;
61  float i_angle;
63  bool i_targetReached : 1;
64 };
65 
66 template<class T>
67 class ChaseMovementGenerator : public TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >
68 {
69  public:
72  ChaseMovementGenerator(Unit* target, float offset, float angle)
73  : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target, offset, angle) { }
75 
77 
78  void DoInitialize(T*);
79  void DoFinalize(T*);
80  void DoReset(T*);
81  void MovementInform(T*);
82 
83  static void _clearUnitStateMove(T* u) { u->ClearUnitState(UNIT_STATE_CHASE_MOVE); }
84  static void _addUnitStateMove(T* u) { u->AddUnitState(UNIT_STATE_CHASE_MOVE); }
85  bool EnableWalking() const { return false;}
86  bool _lostTarget(T* u) const { return u->GetVictim() != this->GetTarget(); }
87  void _reachTarget(T*);
88 };
89 
90 template<class T>
91 class FollowMovementGenerator : public TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >
92 {
93  public:
96  FollowMovementGenerator(Unit* target, float offset, float angle)
97  : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target, offset, angle) { }
99 
101 
102  void DoInitialize(T*);
103  void DoFinalize(T*);
104  void DoReset(T*);
105  void MovementInform(T*);
106 
107  static void _clearUnitStateMove(T* u) { u->ClearUnitState(UNIT_STATE_FOLLOW_MOVE); }
108  static void _addUnitStateMove(T* u) { u->AddUnitState(UNIT_STATE_FOLLOW_MOVE); }
109  bool EnableWalking() const;
110  bool _lostTarget(T*) const { return false; }
111  void _reachTarget(T*) { }
112  private:
113  void _updateSpeed(T* owner);
114 };
115 
116 #endif
Definition: TargetedMovementGenerator.h:38
FollowMovementGenerator(Unit *target)
Definition: TargetedMovementGenerator.h:94
TargetedMovementGeneratorMedium(Unit *target, float offset, float angle)
Definition: TargetedMovementGenerator.h:41
bool EnableWalking() const
Definition: TargetedMovementGenerator.h:85
Definition: TargetedMovementGenerator.h:28
void MovementInform(T *)
Definition: TargetedMovementGenerator.cpp:303
Definition: PathGenerator.h:44
~FollowMovementGenerator()
Definition: TargetedMovementGenerator.h:98
bool IsReachable() const
Definition: TargetedMovementGenerator.h:54
Definition: TargetedMovementGenerator.h:67
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
arena_t NULL
Definition: jemalloc_internal.h:624
void stopFollowing()
Definition: TargetedMovementGenerator.h:32
#define false
Definition: CascPort.h:18
bool _lostTarget(T *u) const
Definition: TargetedMovementGenerator.h:86
ChaseMovementGenerator(Unit *target, float offset, float angle)
Definition: TargetedMovementGenerator.h:72
Definition: FollowerReference.h:27
void MovementInform(T *)
Definition: TargetedMovementGenerator.cpp:231
Definition: Timer.h:134
static void _clearUnitStateMove(T *u)
Definition: TargetedMovementGenerator.h:83
float i_offset
Definition: TargetedMovementGenerator.h:60
bool _lostTarget(T *) const
Definition: TargetedMovementGenerator.h:110
MovementGeneratorType GetMovementGeneratorType() const override
Definition: TargetedMovementGenerator.h:76
bool i_targetReached
Definition: TargetedMovementGenerator.h:63
void _updateSpeed(T *owner)
void DoReset(T *)
Definition: TargetedMovementGenerator.cpp:297
void DoReset(T *)
Definition: TargetedMovementGenerator.cpp:225
static void _addUnitStateMove(T *u)
Definition: TargetedMovementGenerator.h:84
float i_angle
Definition: TargetedMovementGenerator.h:61
~TargetedMovementGeneratorMedium()
Definition: TargetedMovementGenerator.h:47
MovementGeneratorType GetMovementGeneratorType() const override
Definition: TargetedMovementGenerator.h:100
uint32_t uint32
Definition: Define.h:150
void _reachTarget(T *)
Definition: TargetedMovementGenerator.h:111
Definition: PathGenerator.h:52
Definition: MovementGenerator.h:51
FollowMovementGenerator(Unit *target, float offset, float angle)
Definition: TargetedMovementGenerator.h:96
ChaseMovementGenerator(Unit *target)
Definition: TargetedMovementGenerator.h:70
void link(TO *toObj, FROM *fromObj)
Definition: Reference.h:46
Unit * GetTarget() const
Definition: TargetedMovementGenerator.h:51
PathGenerator * i_path
Definition: TargetedMovementGenerator.h:58
Definition: Unit.h:575
Definition: TargetedMovementGenerator.h:91
void DoFinalize(T *)
Definition: TargetedMovementGenerator.cpp:290
TimeTrackerSmall i_recheckDistance
Definition: TargetedMovementGenerator.h:59
void unitSpeedChanged() override
Definition: TargetedMovementGenerator.h:53
static void _addUnitStateMove(T *u)
Definition: TargetedMovementGenerator.h:108
bool DoUpdate(T *, uint32)
Definition: TargetedMovementGenerator.cpp:124
void _reachTarget(T *)
Definition: TargetedMovementGenerator.cpp:197
static void _clearUnitStateMove(T *u)
Definition: TargetedMovementGenerator.h:107
MovementGeneratorType
Definition: MotionMaster.h:35
void DoFinalize(T *)
Definition: TargetedMovementGenerator.cpp:219
TargetedMovementGeneratorBase(Unit *target)
Definition: TargetedMovementGenerator.h:31
Definition: MotionMaster.h:43
PathType GetPathType() const
Definition: PathGenerator.h:73
Definition: Unit.h:1305
~ChaseMovementGenerator()
Definition: TargetedMovementGenerator.h:74
TO * getTarget() const
Definition: Reference.h:94
bool EnableWalking() const
Definition: MotionMaster.h:52
void _setTargetLocation(T *owner, bool updateDestination)
Definition: TargetedMovementGenerator.cpp:31
Definition: Unit.h:576
bool i_recalculateTravel
Definition: TargetedMovementGenerator.h:62