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

Revision 2, 4.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef MANGOS_WAYPOINTMOVEMENTGENERATOR_H
20#define MANGOS_WAYPOINTMOVEMENTGENERATOR_H
21
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.
26 */
27
28#include "MovementGenerator.h"
29#include "DestinationHolder.h"
30#include "WaypointManager.h"
31#include "Path.h"
32#include "Traveller.h"
33
34#include "Player.h"
35
36#include <vector>
37#include <set>
38
39#define FLIGHT_TRAVEL_UPDATE  100
40#define STOP_TIME_FOR_PLAYER  3 * 60 * 1000                         // 3 Minutes
41
42template<class T, class P = Path>
43class MANGOS_DLL_SPEC PathMovementBase
44{
45    public:
46        PathMovementBase() : i_currentNode(0) {}
47        virtual ~PathMovementBase() {};
48
49        inline bool MovementInProgress(void) const { return i_currentNode < i_path.Size(); }
50
51        // template pattern, not defined .. override required
52        void LoadPath(T &);
53        void ReloadPath(T &);
54        uint32 GetCurrentNode() const { return i_currentNode; }
55
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;
61};
62
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.
66 */
67
68template<class T>
69class MANGOS_DLL_SPEC WaypointMovementGenerator;
70
71template<>
72class MANGOS_DLL_SPEC WaypointMovementGenerator<Creature>
73: public MovementGeneratorMedium< Creature, WaypointMovementGenerator<Creature> >,
74public PathMovementBase<Creature, WaypointPath*>
75{
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)
82        {
83            i_nextMoveTime.Reset(0);                        // TODO: check the lower bound (0 is probably too small)
84            u.StopMoving();
85            LoadPath(u);
86        }
87        void Finalize(Creature &) {}
88        void Reset(Creature &u) { ReloadPath(u); }
89        bool Update(Creature &u, const uint32 &diff);
90
91        void MovementInform(Creature &);
92
93        MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
94
95        // now path movement implmementation
96        void LoadPath(Creature &c);
97        void ReloadPath(Creature &c) { ClearWaypoints(); LoadPath(c); }
98
99        // Player stoping creature
100        bool IsStopedByPlayer() { return b_StopedByPlayer; }
101        void SetStopedByPlayer(bool val) { b_StopedByPlayer = val; }
102
103        // statics
104        static void Initialize(void);
105    private:
106        void ClearWaypoints();
107        bool b_StopedByPlayer;
108};
109
110/** FlightPathMovementGenerator generates movement of the player for the paths
111 * and hence generates ground and activities for the player.
112 */
113class MANGOS_DLL_SPEC FlightPathMovementGenerator
114: public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
115public PathMovementBase<Player>
116{
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; }
126
127        void LoadPath(Player &);
128        void ReloadPath(Player &) { /* don't reload flight path */ }
129
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; }
135};
136#endif
Note: See TracBrowser for help on using the browser.