TrinityCore
Loading...
Searching...
No Matches
Vehicle.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 __TRINITY_VEHICLE_H
19#define __TRINITY_VEHICLE_H
20
21#include "Object.h"
22#include "UniqueTrackablePtr.h"
23#include "Unit.h"
24#include "VehicleDefines.h"
25#include <list>
26
27struct VehicleEntry;
28class Unit;
30
31class TC_GAME_API Vehicle final : public TransportBase
32{
33 public:
34 Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry);
35 ~Vehicle();
36
37 Vehicle(Vehicle const& right) = delete;
38 Vehicle(Vehicle&& right) = delete;
39 Vehicle& operator=(Vehicle const& right) = delete;
40 Vehicle& operator=(Vehicle&& right) = delete;
41
42 void Install();
43 void Uninstall();
44 void Reset(bool evading = false);
45 void InstallAllAccessories(bool evading);
46 void ApplyAllImmunities();
47 void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime, Optional<uint32> rideSpellId = {}); // May be called from scripts
48
49 Unit* GetBase() const { return _me; }
50 VehicleEntry const* GetVehicleInfo() const { return _vehicleInfo; }
51 uint32 GetCreatureEntry() const { return _creatureEntry; }
52
53 bool HasEmptySeat(int8 seatId) const;
54 Unit* GetPassenger(int8 seatId) const;
55 SeatMap::const_iterator GetNextEmptySeat(int8 seatId, bool next) const;
56 VehicleSeatAddon const* GetSeatAddonForSeatOfPassenger(Unit const* passenger) const;
57 uint8 GetAvailableSeatCount() const;
58
59 bool AddVehiclePassenger(Unit* unit, int8 seatId = -1);
60 Vehicle* RemovePassenger(WorldObject* passenger) override;
61 void RelocatePassengers();
62 void RemoveAllPassengers();
63 bool IsVehicleInUse() const;
64 bool IsControllableVehicle() const;
65
66 SeatMap::iterator GetSeatIteratorForPassenger(Unit* passenger);
68
69 VehicleSeatEntry const* GetSeatForPassenger(Unit const* passenger) const;
70
71 void RemovePendingEventsForPassenger(Unit* passenger);
72
73 Milliseconds GetDespawnDelay();
74 float GetPitch();
75
76 std::string GetDebugInfo() const;
77
78 Trinity::unique_weak_ptr<Vehicle> GetWeakPtr() const;
79
80 protected:
81 friend class VehicleJoinEvent;
83
84 private:
91
92 void InitMovementInfoForBase();
93
94 ObjectGuid GetTransportGUID() const override { return GetBase()->GetGUID(); }
95
96 float GetTransportOrientation() const override { return GetBase()->GetOrientation(); }
97
98 void AddPassenger(WorldObject* /*passenger*/, Position const& /*offset*/) override { ABORT_MSG("Vehicle cannot directly gain passengers without auras"); }
99
101 Position GetPositionWithOffset(Position const& offset) const override { return GetBase()->GetPositionWithOffset(offset); }
102
104 Position GetPositionOffsetTo(Position const& endPos) const override { return GetBase()->GetPositionOffsetTo(endPos); }
105
106 int32 GetMapIdForSpawning() const override { return GetBase()->GetMapId(); }
107
108 void RemovePendingEvent(VehicleJoinEvent* e);
109 void RemovePendingEventsForSeat(int8 seatId);
110
111 bool HasPendingEventForSeat(int8 seatId) const;
112
113 private:
117
120
121 typedef std::list<VehicleJoinEvent*> PendingJoinEventContainer;
123};
124
125#endif
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int8_t int8
Definition Define.h:152
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
std::string GetDebugInfo()
Definition Errors.cpp:170
#define ABORT_MSG
Definition Errors.h:88
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:432
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
std::map< int8, VehicleSeat > SeatMap
virtual TransportBase * RemovePassenger(WorldObject *passenger)=0
Trinity::unique_trackable_ptr companion class, replicating what std::weak_ptr is to std::shared_ptr.
Definition Unit.h:635
Vehicle(Vehicle &&right)=delete
float GetTransportOrientation() const override
Definition Vehicle.h:96
Unit * GetBase() const
Definition Vehicle.h:49
GuidSet vehiclePlayers
Definition Vehicle.h:116
Position GetPositionWithOffset(Position const &offset) const override
This method transforms supplied transport offsets into global coordinates.
Definition Vehicle.h:101
VehicleEntry const * GetVehicleInfo() const
Definition Vehicle.h:50
Position GetPositionOffsetTo(Position const &endPos) const override
This method transforms supplied global coordinates into local offsets.
Definition Vehicle.h:104
@ STATUS_INSTALLED
Definition Vehicle.h:88
@ STATUS_UNINSTALLING
Definition Vehicle.h:89
@ STATUS_NONE
Definition Vehicle.h:87
uint32 GetCreatureEntry() const
Definition Vehicle.h:51
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags.
Definition Vehicle.h:82
std::list< VehicleJoinEvent * > PendingJoinEventContainer
Definition Vehicle.h:121
Vehicle & operator=(Vehicle const &right)=delete
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition Vehicle.h:118
Status _status
Internal variable for sanity checks.
Definition Vehicle.h:119
Vehicle(Vehicle const &right)=delete
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition Vehicle.h:114
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition Vehicle.h:122
SeatMap Seats
The collection of all seats on the vehicle. Including vacant ones.
Definition Vehicle.h:67
Vehicle & operator=(Vehicle &&right)=delete
ObjectGuid GetTransportGUID() const override
Definition Vehicle.h:94
int32 GetMapIdForSpawning() const override
Definition Vehicle.h:106
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition Vehicle.h:115
void AddPassenger(WorldObject *, Position const &) override
Attempts to add a passenger to the vehicle on 'seatId'.
Definition Vehicle.h:98
Position GetPositionWithOffset(Position const &offset) const
Definition Position.cpp:61
Position GetPositionOffsetTo(Position const &endPos) const
Definition Position.cpp:47