TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WaypointMovementGenerator.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_WAYPOINTMOVEMENTGENERATOR_H
20 #define TRINITY_WAYPOINTMOVEMENTGENERATOR_H
21 
28 #include "MovementGenerator.h"
29 #include "WaypointManager.h"
30 #include "Player.h"
31 
32 #define FLIGHT_TRAVEL_UPDATE 100
33 #define STOP_TIME_FOR_PLAYER 3 * MINUTE * IN_MILLISECONDS // 3 Minutes
34 #define TIMEDIFF_NEXT_WP 250
35 
36 template<class T, class P>
38 {
39  public:
41  virtual ~PathMovementBase() { };
42 
43  uint32 GetCurrentNode() const { return i_currentNode; }
44 
45  protected:
48 };
49 
50 template<class T>
52 
53 template<>
54 class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Creature, WaypointMovementGenerator<Creature> >,
55  public PathMovementBase<Creature, WaypointPath const*>
56 {
57  public:
58  WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true)
59  : i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) { }
61  void DoInitialize(Creature*);
62  void DoFinalize(Creature*);
63  void DoReset(Creature*);
64  bool DoUpdate(Creature*, uint32 diff);
65 
66  void MovementInform(Creature*);
67 
69 
70  // now path movement implmementation
71  void LoadPath(Creature*);
72 
73  bool GetResetPos(Creature*, float& x, float& y, float& z);
74 
75  private:
76 
77  void Stop(int32 time) { i_nextMoveTime.Reset(time);}
78 
79  bool Stopped() { return !i_nextMoveTime.Passed();}
80 
81  bool CanMove(int32 diff)
82  {
83  i_nextMoveTime.Update(diff);
84  return i_nextMoveTime.Passed();
85  }
86 
87  void OnArrived(Creature*);
88  bool StartMove(Creature*);
89 
90  void StartMoveNow(Creature* creature)
91  {
92  i_nextMoveTime.Reset(0);
93  StartMove(creature);
94  }
95 
99  bool repeating;
100 };
101 
105 class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
106  public PathMovementBase<Player, TaxiPathNodeList>
107 {
108  public:
110  {
111  i_currentNode = 0;
112  _endGridX = 0.0f;
113  _endGridY = 0.0f;
114  _endMapId = 0;
115  _preloadTargetNode = 0;
116  }
117  void LoadPath(Player* player, uint32 startNode = 0);
118  void DoInitialize(Player*);
119  void DoReset(Player*);
120  void DoFinalize(Player*);
121  bool DoUpdate(Player*, uint32);
123 
124  TaxiPathNodeList const& GetPath() { return i_path; }
125  uint32 GetPathAtMapEnd() const;
126  bool HasArrived() const { return (i_currentNode >= i_path.size()); }
129  void DoEventIfAny(Player* player, TaxiPathNodeEntry const* node, bool departure);
130 
131  bool GetResetPos(Player*, float& x, float& y, float& z);
132 
133  void InitEndGridInfo();
134  void PreloadEndGrid();
135 
136  private:
137 
138  float _endGridX;
139  float _endGridY;
142 
144  {
147  };
148 
149  std::deque<TaxiNodeChangeInfo> _pointsForPathSwitch;
150 };
151 #endif
void SetCurrentNodeAfterTeleport()
Definition: WaypointMovementGenerator.cpp:392
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
int32 Cost
Definition: WaypointMovementGenerator.h:146
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:97
uint32 GetCurrentNode() const
Definition: WaypointMovementGenerator.h:43
Definition: WaypointMovementGenerator.h:105
node index where preloading starts
Definition: WaypointMovementGenerator.h:143
bool DoUpdate(Player *, uint32)
Definition: WaypointMovementGenerator.cpp:358
void PreloadEndGrid()
Definition: WaypointMovementGenerator.cpp:437
Definition: MotionMaster.h:45
arena_t NULL
Definition: jemalloc_internal.h:624
#define false
Definition: CascPort.h:18
WaypointMovementGenerator(uint32 _path_id=0, bool _repeating=true)
Definition: WaypointMovementGenerator.h:58
FlightPathMovementGenerator()
Definition: WaypointMovementGenerator.h:109
virtual ~PathMovementBase()
Definition: WaypointMovementGenerator.h:41
Definition: Creature.h:467
void LoadPath(Player *player, uint32 startNode=0)
Definition: WaypointMovementGenerator.cpp:266
Definition: Timer.h:134
bool HasArrived() const
Definition: WaypointMovementGenerator.h:126
MovementGeneratorType GetMovementGeneratorType() const override
Definition: WaypointMovementGenerator.h:68
Definition: WaypointMovementGenerator.h:37
P i_path
Definition: WaypointMovementGenerator.h:46
void DoReset(Player *)
Definition: WaypointMovementGenerator.cpp:336
bool repeating
Definition: WaypointMovementGenerator.h:99
uint32 _endMapId
Y coord of last node location.
Definition: WaypointMovementGenerator.h:140
void InitEndGridInfo()
Definition: WaypointMovementGenerator.cpp:426
bool GetResetPos(Player *, float &x, float &y, float &z)
Definition: WaypointMovementGenerator.cpp:417
Definition: WaypointMovementGenerator.h:51
G3D::int16 z
Definition: Vector3int16.h:46
std::deque< TaxiNodeChangeInfo > _pointsForPathSwitch
Definition: WaypointMovementGenerator.h:149
void StartMoveNow(Creature *creature)
Definition: WaypointMovementGenerator.h:90
int32_t int32
Definition: Define.h:146
MovementGeneratorType GetMovementGeneratorType() const override
Definition: WaypointMovementGenerator.h:122
void SkipCurrentNode()
Definition: WaypointMovementGenerator.h:128
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
uint32 path_id
Definition: WaypointMovementGenerator.h:98
bool CanMove(int32 diff)
Definition: WaypointMovementGenerator.h:81
Definition: MovementGenerator.h:51
Definition: DB2Structure.h:1345
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:47
bool Stopped()
Definition: WaypointMovementGenerator.h:79
void DoEventIfAny(Player *player, TaxiPathNodeEntry const *node, bool departure)
Definition: WaypointMovementGenerator.cpp:408
PathMovementBase()
Definition: WaypointMovementGenerator.h:40
uint32 _preloadTargetNode
map Id of last node location
Definition: WaypointMovementGenerator.h:141
void DoInitialize(Player *)
Definition: WaypointMovementGenerator.cpp:308
float _endGridX
Definition: WaypointMovementGenerator.h:138
MovementGeneratorType
Definition: MotionMaster.h:35
void Stop(int32 time)
Definition: WaypointMovementGenerator.h:77
uint32 GetPathAtMapEnd() const
Definition: WaypointMovementGenerator.cpp:246
void DoFinalize(Player *)
Definition: WaypointMovementGenerator.cpp:314
G3D::int16 x
Definition: Vector2int16.h:37
uint8 const P[]
Definition: AuthenticationPackets.cpp:225
~WaypointMovementGenerator()
Definition: WaypointMovementGenerator.h:60
Definition: MotionMaster.h:39
float _endGridY
X coord of last node location.
Definition: WaypointMovementGenerator.h:139
TaxiPathNodeList const & GetPath()
Definition: WaypointMovementGenerator.h:124
uint32 PathIndex
Definition: WaypointMovementGenerator.h:145
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition: DB2Structure.h:1449