* Fix some warlock talent work
[getmangos.git] / src / game / WaypointMovementGenerator.h
blobd6cb2175229b92999d818d22bf885320e72cae06
1 /*
2 * Copyright (C) 2005-2008 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_WAYPOINTMOVEMENTGENERATOR_H
20 #define MANGOS_WAYPOINTMOVEMENTGENERATOR_H
22 /** @page PathMovementGenerator is used to generate movements
23 * of waypoints and flight paths. Each serves the purpose
24 * of generate activities so that it generates updated
25 * packets for the players.
28 #include "MovementGenerator.h"
29 #include "DestinationHolder.h"
30 #include "WaypointManager.h"
31 #include "Path.h"
32 #include "Traveller.h"
34 #include "Player.h"
36 #include <vector>
37 #include <set>
39 #define FLIGHT_TRAVEL_UPDATE 100
40 #define STOP_TIME_FOR_PLAYER 3 * 60 * 1000 // 3 Minutes
42 template<class T, class P = Path>
43 class MANGOS_DLL_SPEC PathMovementBase
45 public:
46 PathMovementBase() : i_currentNode(0) {}
47 virtual ~PathMovementBase() {};
49 inline bool MovementInProgress(void) const { return i_currentNode < i_path.Size(); }
51 // template pattern, not defined .. override required
52 void LoadPath(T &);
53 void ReloadPath(T &);
54 uint32 GetCurrentNode() const { return i_currentNode; }
56 bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; }
57 protected:
58 uint32 i_currentNode;
59 DestinationHolder< Traveller<T> > i_destinationHolder;
60 P i_path;
63 /** WaypointMovementGenerator loads a series of way points
64 * from the DB and apply it to the creature's movement generator.
65 * Hence, the creature will move according to its predefined way points.
68 template<class T>
69 class MANGOS_DLL_SPEC WaypointMovementGenerator;
71 template<>
72 class MANGOS_DLL_SPEC WaypointMovementGenerator<Creature>
73 : public MovementGeneratorMedium< Creature, WaypointMovementGenerator<Creature> >,
74 public PathMovementBase<Creature, WaypointPath*>
76 public:
77 WaypointMovementGenerator(Creature &) : i_nextMoveTime(0), b_StopedByPlayer(false) {}
78 ~WaypointMovementGenerator() { ClearWaypoints(); }
79 void Initialize(Creature &u)
81 i_nextMoveTime.Reset(0); // TODO: check the lower bound (0 is probably too small)
82 u.StopMoving();
83 LoadPath(u);
85 void Finalize(Creature &) {}
86 void Reset(Creature &u)
88 ReloadPath(u);
89 b_StopedByPlayer = false;
90 i_nextMoveTime.Reset(0);
92 bool Update(Creature &u, const uint32 &diff);
94 void MovementInform(Creature &);
96 MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
98 // now path movement implmementation
99 void LoadPath(Creature &c);
100 void ReloadPath(Creature &c) { ClearWaypoints(); LoadPath(c); }
102 // Player stoping creature
103 bool IsStopedByPlayer() { return b_StopedByPlayer; }
104 void SetStopedByPlayer(bool val) { b_StopedByPlayer = val; }
106 // statics
107 static void Initialize(void);
108 private:
109 void ClearWaypoints();
111 TimeTrackerSmall i_nextMoveTime;
112 std::vector<bool> i_hasDone;
113 bool b_StopedByPlayer;
116 /** FlightPathMovementGenerator generates movement of the player for the paths
117 * and hence generates ground and activities for the player.
119 class MANGOS_DLL_SPEC FlightPathMovementGenerator
120 : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
121 public PathMovementBase<Player>
123 uint32 i_pathId;
124 std::vector<uint32> i_mapIds;
125 public:
126 explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; }
127 void Initialize(Player &);
128 void Finalize(Player &);
129 void Reset(Player &) {}
130 bool Update(Player &, const uint32 &);
131 MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; }
133 void LoadPath(Player &);
134 void ReloadPath(Player &) { /* don't reload flight path */ }
136 Path& GetPath() { return i_path; }
137 uint32 GetPathAtMapEnd() const;
138 inline bool HasArrived() const { return (i_currentNode >= i_path.Size()); }
139 void SetCurrentNodeAfterTeleport();
140 void SkipCurrentNode() { ++i_currentNode; }
142 #endif