TrinityCore
TransportMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRANSPORTMGR_H
19#define TRANSPORTMGR_H
20
21#include "ObjectGuid.h"
22#include "Optional.h"
23#include "Position.h"
24#include <map>
25#include <memory>
26#include <unordered_map>
27
33class Transport;
34class Map;
35
36namespace Movement
37{
38 template <typename length_type> class Spline;
39}
40
42
44{
45 Moving,
47};
48
49// Represents a segment within path leg between stops
51{
55};
56
58{
61};
62
63// Represents a contignuous part of transport path (without map changes or teleports)
65{
68
71 TransportPathLeg& operator=(TransportPathLeg const&) = delete;
72 TransportPathLeg& operator=(TransportPathLeg&&) noexcept;
73
79};
80
82{
85
88 TransportTemplate& operator=(TransportTemplate const&) = delete;
89 TransportTemplate& operator=(TransportTemplate&&) noexcept;
90
91 uint32 TotalPathTime = 0;
92 double Speed = 0.0;
93 double AccelerationRate = 0.0;
94 double AccelerationTime = 0.0;
95 double AccelerationDistance = 0.0;
96 std::vector<TransportPathLeg> PathLegs;
98
99 Optional<Position> ComputePosition(uint32 time, TransportMovementState* moveState, size_t* legIndex) const;
100 TransportPathLeg const* GetLegForTime(uint32 time) const;
101 uint32 GetNextPauseWaypointTimestamp(uint32 time) const;
102
103 double CalculateDistanceMoved(double timePassedInSegment, double segmentDuration, bool isFirstSegment, bool isLastSegment) const;
104
105 std::set<uint32> MapIds;
106};
107
109{
110 TransportAnimation() : TotalTime(0) { }
111
112 std::map<uint32, TransportAnimationEntry const*> Path;
113 std::map<uint32, TransportRotationEntry const*> Rotations;
115
116 TransportAnimationEntry const* GetPrevAnimNode(uint32 time) const;
117 TransportRotationEntry const* GetPrevAnimRotation(uint32 time) const;
118
119 TransportAnimationEntry const* GetNextAnimNode(uint32 time) const;
120 TransportRotationEntry const* GetNextAnimRotation(uint32 time) const;
121};
122
124{
126 uint32 TransportGameObjectId = 0; // entry in respective _template table
127 uint8 PhaseUseFlags = 0;
128 uint32 PhaseId = 0;
129 uint32 PhaseGroup = 0;
130};
131
133{
134 public:
135 static TransportMgr* instance();
136
137 void Unload();
138
139 void LoadTransportTemplates();
140
141 void LoadTransportAnimationAndRotation();
142
143 void LoadTransportSpawns();
144
145 // Creates a transport using given GameObject template entry
146 Transport* CreateTransport(uint32 entry, Map* map, ObjectGuid::LowType guid = 0, uint8 phaseUseFlags = 0, uint32 phaseId = 0, uint32 phaseGroupId = 0);
147
148 // creates all transports for map
149 void CreateTransportsForMap(Map* map);
150
151 TransportTemplate const* GetTransportTemplate(uint32 entry) const;
152
153 TransportAnimation const* GetTransportAnimInfo(uint32 entry) const;
154
155 TransportSpawn const* GetTransportSpawn(ObjectGuid::LowType spawnId) const;
156
157 private:
160 TransportMgr(TransportMgr const&) = delete;
164
165 // Generates and precaches a path for transport to avoid generation each time transport instance is created
166 void GeneratePath(GameObjectTemplate const* goInfo, TransportTemplate* transport);
167
168 void AddPathNodeToTransport(uint32 transportEntry, uint32 timeSeg, TransportAnimationEntry const* node);
169
170 void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const* node);
171
172 // Container storing transport templates
173 std::unordered_map<uint32, TransportTemplate> _transportTemplates;
174
175 // Container storing transport entries to create for instanced maps
176 std::unordered_map<uint32, std::set<TransportSpawn*>> _transportsByMap;
177
178 std::map<uint32, TransportAnimation> _transportAnimations;
179
180 std::unordered_map<ObjectGuid::LowType, TransportSpawn> _transportSpawns;
181};
182
183#define sTransportMgr TransportMgr::instance()
184
185#endif // TRANSPORTMGR_H
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
#define UI64LIT(N)
Definition: Define.h:127
uint32_t uint32
Definition: Define.h:142
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
EventId
TransportMovementState
Definition: TransportMgr.h:44
Definition: Map.h:189
uint64 LowType
Definition: ObjectGuid.h:278
std::unordered_map< ObjectGuid::LowType, TransportSpawn > _transportSpawns
Definition: TransportMgr.h:180
std::unordered_map< uint32, std::set< TransportSpawn * > > _transportsByMap
Definition: TransportMgr.h:176
TransportMgr(TransportMgr &&)=delete
TransportMgr(TransportMgr const &)=delete
std::map< uint32, TransportAnimation > _transportAnimations
Definition: TransportMgr.h:178
std::unordered_map< uint32, TransportTemplate > _transportTemplates
Definition: TransportMgr.h:173
TransportMgr & operator=(TransportMgr const &)=delete
TransportMgr & operator=(TransportMgr &&)=delete
STL namespace.
std::map< uint32, TransportAnimationEntry const * > Path
Definition: TransportMgr.h:112
std::map< uint32, TransportRotationEntry const * > Rotations
Definition: TransportMgr.h:113
std::vector< TransportPathSegment > Segments
Definition: TransportMgr.h:78
TransportPathLeg(TransportPathLeg const &)=delete
std::unique_ptr< TransportSpline > Spline
Definition: TransportMgr.h:75
uint32 StartTimestamp
Definition: TransportMgr.h:76
TransportPathLeg(TransportPathLeg &&) noexcept
uint32 SegmentEndArrivalTimestamp
Definition: TransportMgr.h:52
double DistanceFromLegStartAtEnd
Definition: TransportMgr.h:54
TransportTemplate(TransportTemplate &&) noexcept
TransportTemplate(TransportTemplate const &)=delete