TrinityCore
Loading...
Searching...
No Matches
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
48
49// Represents a segment within path leg between stops
56
62
63// Represents a contignuous part of transport path (without map changes or teleports)
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{
112
115 TransportAnimation& operator=(TransportAnimation const&) = delete;
117
119 std::map<uint32, TransportRotationEntry const*> Rotations;
120 uint32 TotalTime = 0;
121
122 TransportAnimationEntry const* GetPrevAnimNode(uint32 time) const;
123 TransportRotationEntry const* GetPrevAnimRotation(uint32 time) const;
124
125 TransportAnimationEntry const* GetNextAnimNode(uint32 time) const;
126 TransportRotationEntry const* GetNextAnimRotation(uint32 time) const;
127};
128
130{
132 uint32 TransportGameObjectId = 0; // entry in respective _template table
133 uint8 PhaseUseFlags = 0;
134 uint32 PhaseId = 0;
135 uint32 PhaseGroup = 0;
136};
137
139{
140 public:
141 TransportMgr(TransportMgr const&) = delete;
145
146 static TransportMgr* instance();
147
148 void Unload();
149
150 void LoadTransportTemplates();
151
152 void LoadTransportAnimationAndRotation();
153
154 void LoadTransportSpawns();
155
156 // Creates a transport using given GameObject template entry
157 Transport* CreateTransport(uint32 entry, Map* map, ObjectGuid::LowType guid = 0, uint8 phaseUseFlags = 0, uint32 phaseId = 0, uint32 phaseGroupId = 0);
158
159 // creates all transports for map
160 void CreateTransportsForMap(Map* map);
161
162 TransportTemplate const* GetTransportTemplate(uint32 entry) const;
163
164 TransportAnimation const* GetTransportAnimInfo(uint32 entry) const;
165
166 TransportSpawn const* GetTransportSpawn(ObjectGuid::LowType spawnId) const;
167
168 private:
171
172 // Generates and precaches a path for transport to avoid generation each time transport instance is created
173 void GeneratePath(GameObjectTemplate const* goInfo, TransportTemplate* transport);
174
175 void AddPathNodeToTransport(uint32 transportEntry, uint32 timeSeg, TransportAnimationEntry const* node);
176
177 void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const* node);
178
179 // Container storing transport templates
180 std::unordered_map<uint32, TransportTemplate> _transportTemplates;
181
182 // Container storing transport entries to create for instanced maps
183 std::unordered_map<uint32, std::set<TransportSpawn*>> _transportsByMap;
184
185 std::map<uint32, TransportAnimation> _transportAnimations;
186
187 std::unordered_map<ObjectGuid::LowType, TransportSpawn> _transportSpawns;
188};
189
190#define sTransportMgr TransportMgr::instance()
191
192#endif // TRANSPORTMGR_H
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
#define UI64LIT(N)
Definition Define.h:139
uint32_t uint32
Definition Define.h:154
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
EventId
TransportMovementState
Definition Map.h:225
uint64 LowType
Definition ObjectGuid.h:321
std::unordered_map< ObjectGuid::LowType, TransportSpawn > _transportSpawns
std::unordered_map< uint32, std::set< TransportSpawn * > > _transportsByMap
TransportMgr(TransportMgr &&)=delete
TransportMgr(TransportMgr const &)=delete
std::map< uint32, TransportAnimation > _transportAnimations
std::unordered_map< uint32, TransportTemplate > _transportTemplates
TransportMgr & operator=(TransportMgr const &)=delete
TransportMgr & operator=(TransportMgr &&)=delete
STL namespace.
TransportAnimation(TransportAnimation &&) noexcept
TransportAnimation(TransportAnimation const &)=delete
std::vector< TransportPathSegment > Segments
TransportPathLeg(TransportPathLeg const &)=delete
std::unique_ptr< TransportSpline > Spline
TransportPathLeg(TransportPathLeg &&) noexcept
uint32 SegmentEndArrivalTimestamp
double DistanceFromLegStartAtEnd
TransportTemplate(TransportTemplate &&) noexcept
TransportTemplate(TransportTemplate const &)=delete