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 TRANSPORTS_H |
---|
20 | #define TRANSPORTS_H |
---|
21 | |
---|
22 | #include "GameObject.h" |
---|
23 | |
---|
24 | #include <map> |
---|
25 | #include <set> |
---|
26 | #include <string> |
---|
27 | |
---|
28 | class TransportPath |
---|
29 | { |
---|
30 | public: |
---|
31 | struct PathNode |
---|
32 | { |
---|
33 | uint32 mapid; |
---|
34 | float x,y,z; |
---|
35 | uint32 actionFlag; |
---|
36 | uint32 delay; |
---|
37 | }; |
---|
38 | |
---|
39 | inline void SetLength(const unsigned int sz) |
---|
40 | { |
---|
41 | i_nodes.resize( sz ); |
---|
42 | } |
---|
43 | |
---|
44 | inline unsigned int Size(void) const { return i_nodes.size(); } |
---|
45 | inline bool Empty(void) const { return i_nodes.empty(); } |
---|
46 | inline void Resize(unsigned int sz) { i_nodes.resize(sz); } |
---|
47 | inline void Clear(void) { i_nodes.clear(); } |
---|
48 | inline PathNode* GetNodes(void) { return static_cast<PathNode *>(&i_nodes[0]); } |
---|
49 | |
---|
50 | PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; } |
---|
51 | const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; } |
---|
52 | |
---|
53 | protected: |
---|
54 | std::vector<PathNode> i_nodes; |
---|
55 | }; |
---|
56 | |
---|
57 | class Transport : private GameObject |
---|
58 | { |
---|
59 | public: |
---|
60 | explicit Transport(); |
---|
61 | |
---|
62 | // prevent using Transports as normal GO, but allow call some inherited functions |
---|
63 | using GameObject::IsTransport; |
---|
64 | using GameObject::GetEntry; |
---|
65 | using GameObject::GetGUID; |
---|
66 | using GameObject::GetGUIDLow; |
---|
67 | using GameObject::GetMapId; |
---|
68 | using GameObject::GetPositionX; |
---|
69 | using GameObject::GetPositionY; |
---|
70 | using GameObject::GetPositionZ; |
---|
71 | using GameObject::BuildCreateUpdateBlockForPlayer; |
---|
72 | using GameObject::BuildOutOfRangeUpdateBlock; |
---|
73 | |
---|
74 | bool Create(uint32 guidlow, uint32 mapid, float x, float y, float z, float ang, uint32 animprogress, uint32 dynflags); |
---|
75 | bool GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids); |
---|
76 | void Update(uint32 p_time); |
---|
77 | bool AddPassenger(Player* passenger); |
---|
78 | bool RemovePassenger(Player* passenger); |
---|
79 | |
---|
80 | typedef std::set<Player*> PlayerSet; |
---|
81 | PlayerSet const& GetPassengers() const { return m_passengers; } |
---|
82 | |
---|
83 | std::string m_name; |
---|
84 | private: |
---|
85 | struct WayPoint |
---|
86 | { |
---|
87 | WayPoint() : mapid(0), x(0), y(0), z(0), teleport(false) {} |
---|
88 | WayPoint(uint32 _mapid, float _x, float _y, float _z, bool _teleport) : |
---|
89 | mapid(_mapid), x(_x), y(_y), z(_z), teleport(_teleport) {} |
---|
90 | uint32 mapid; |
---|
91 | float x; |
---|
92 | float y; |
---|
93 | float z; |
---|
94 | bool teleport; |
---|
95 | }; |
---|
96 | |
---|
97 | typedef std::map<uint32, WayPoint> WayPointMap; |
---|
98 | |
---|
99 | WayPointMap::iterator m_curr; |
---|
100 | WayPointMap::iterator m_next; |
---|
101 | uint32 m_pathTime; |
---|
102 | uint32 m_timer; |
---|
103 | |
---|
104 | PlayerSet m_passengers; |
---|
105 | |
---|
106 | public: |
---|
107 | WayPointMap m_WayPoints; |
---|
108 | uint32 m_nextNodeTime; |
---|
109 | uint32 m_period; |
---|
110 | |
---|
111 | private: |
---|
112 | void TeleportTransport(uint32 newMapid, float x, float y, float z); |
---|
113 | WayPointMap::iterator GetNextWayPoint(); |
---|
114 | }; |
---|
115 | #endif |
---|