root/trunk/src/game/WaypointMovementGenerator.h @ 131

Revision 102, 4.8 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef TRINITY_WAYPOINTMOVEMENTGENERATOR_H
22#define TRINITY_WAYPOINTMOVEMENTGENERATOR_H
23
24/** @page PathMovementGenerator is used to generate movements
25 * of waypoints and flight paths.  Each serves the purpose
26 * of generate activities so that it generates updated
27 * packets for the players.
28 */
29
30#include "MovementGenerator.h"
31#include "DestinationHolder.h"
32#include "WaypointManager.h"
33#include "Path.h"
34#include "Traveller.h"
35
36#include "Player.h"
37
38#include <vector>
39#include <set>
40
41#define FLIGHT_TRAVEL_UPDATE  100
42#define STOP_TIME_FOR_PLAYER  3 * 60 * 1000                         // 3 Minutes
43
44template<class T, class P = Path>
45class TRINITY_DLL_SPEC PathMovementBase
46{
47    public:
48        PathMovementBase() : i_currentNode(0) {}
49        virtual ~PathMovementBase() {};
50
51        inline bool MovementInProgress(void) const { return i_currentNode < i_path.Size(); }
52
53        // template pattern, not defined .. override required
54        void LoadPath(T &);
55        void ReloadPath(T &);
56        uint32 GetCurrentNode() const { return i_currentNode; }
57
58        bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; }
59    protected:
60        uint32 i_currentNode;
61        DestinationHolder< Traveller<T> > i_destinationHolder;
62        P i_path;
63};
64
65/** WaypointMovementGenerator loads a series of way points
66 * from the DB and apply it to the creature's movement generator.
67 * Hence, the creature will move according to its predefined way points.
68 */
69
70template<class T>
71class TRINITY_DLL_SPEC WaypointMovementGenerator;
72
73template<>
74class TRINITY_DLL_SPEC WaypointMovementGenerator<Creature>
75: public MovementGeneratorMedium< Creature, WaypointMovementGenerator<Creature> >,
76public PathMovementBase<Creature, WaypointPath*>
77{
78    TimeTrackerSmall i_nextMoveTime;
79    std::vector<bool> i_hasDone;
80    public:
81        WaypointMovementGenerator(Creature &) : i_nextMoveTime(0) {}
82        ~WaypointMovementGenerator() { ClearWaypoints(); }
83        void Initialize(Creature &u)
84        {
85            i_nextMoveTime.Reset(0);                        // TODO: check the lower bound (0 is probably too small)
86            u.StopMoving();
87            LoadPath(u);
88        }
89        void Finalize(Creature &) {}
90        void Reset(Creature &u) { ReloadPath(u); }
91        bool Update(Creature &u, const uint32 &diff);
92
93        void MovementInform(Creature &);
94
95        MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
96
97        // now path movement implmementation
98        void LoadPath(Creature &c);
99        void ReloadPath(Creature &c) { ClearWaypoints(); LoadPath(c); }
100
101        // Player stoping creature
102        bool IsStopedByPlayer() { return b_StopedByPlayer; }
103        void SetStopedByPlayer(bool val) { b_StopedByPlayer = val; }
104
105        // statics
106        static void Initialize(void);
107    private:
108        void ClearWaypoints();
109        bool b_StopedByPlayer;
110};
111
112/** FlightPathMovementGenerator generates movement of the player for the paths
113 * and hence generates ground and activities for the player.
114 */
115class TRINITY_DLL_SPEC FlightPathMovementGenerator
116: public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
117public PathMovementBase<Player>
118{
119    uint32 i_pathId;
120    std::vector<uint32> i_mapIds;
121    public:
122        explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; }
123        void Initialize(Player &);
124        void Finalize(Player &);
125        void Reset(Player &) {}
126        bool Update(Player &, const uint32 &);
127        MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; }
128
129        void LoadPath(Player &);
130        void ReloadPath(Player &) { /* don't reload flight path */ }
131
132        Path& GetPath() { return i_path; }
133        uint32 GetPathAtMapEnd() const;
134        inline bool HasArrived() const { return (i_currentNode >= i_path.Size()); }
135        void SetCurrentNodeAfterTeleport();
136        void SkipCurrentNode() { ++i_currentNode; }
137};
138#endif
Note: See TracBrowser for help on using the browser.