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