* Implemented second choice aggro targets for creatures. This will prevent players...
[auctionmangos.git] / src / game / WaypointMovementGenerator.h
blobbcd14d893024ecd563b499f5dad0ed4f86960b35
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 TimeTrackerSmall i_nextMoveTime;
77 std::vector<bool> i_hasDone;
78 public:
79 WaypointMovementGenerator(Creature &) : i_nextMoveTime(0) {}
80 ~WaypointMovementGenerator() { ClearWaypoints(); }
81 void Initialize(Creature &u)
83 i_nextMoveTime.Reset(0); // TODO: check the lower bound (0 is probably too small)
84 u.StopMoving();
85 LoadPath(u);
87 void Finalize(Creature &) {}
88 void Reset(Creature &u) { ReloadPath(u); }
89 bool Update(Creature &u, const uint32 &diff);
91 void MovementInform(Creature &);
93 MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
95 // now path movement implmementation
96 void LoadPath(Creature &c);
97 void ReloadPath(Creature &c) { ClearWaypoints(); LoadPath(c); }
99 // Player stoping creature
100 bool IsStopedByPlayer() { return b_StopedByPlayer; }
101 void SetStopedByPlayer(bool val) { b_StopedByPlayer = val; }
103 // statics
104 static void Initialize(void);
105 private:
106 void ClearWaypoints();
107 bool b_StopedByPlayer;
110 /** FlightPathMovementGenerator generates movement of the player for the paths
111 * and hence generates ground and activities for the player.
113 class MANGOS_DLL_SPEC FlightPathMovementGenerator
114 : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
115 public PathMovementBase<Player>
117 uint32 i_pathId;
118 std::vector<uint32> i_mapIds;
119 public:
120 explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; }
121 void Initialize(Player &);
122 void Finalize(Player &);
123 void Reset(Player &) {}
124 bool Update(Player &, const uint32 &);
125 MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; }
127 void LoadPath(Player &);
128 void ReloadPath(Player &) { /* don't reload flight path */ }
130 Path& GetPath() { return i_path; }
131 uint32 GetPathAtMapEnd() const;
132 inline bool HasArrived() const { return (i_currentNode >= i_path.Size()); }
133 void SetCurrentNodeAfterTeleport();
134 void SkipCurrentNode() { ++i_currentNode; }
136 #endif