TrinityCore
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); // 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
75 std::string GetDebugInfo() const;
76
77 Trinity::unique_weak_ptr<Vehicle> GetWeakPtr() const;
78
79 protected:
80 friend class VehicleJoinEvent;
82
83 private:
84 enum Status
85 {
89 };
90
91 void InitMovementInfoForBase();
92
93 ObjectGuid GetTransportGUID() const override { return GetBase()->GetGUID(); }
94
95 float GetTransportOrientation() const override { return GetBase()->GetOrientation(); }
96
97 void AddPassenger(WorldObject* /*passenger*/) override { ABORT_MSG("Vehicle cannot directly gain passengers without auras"); }
98
100 void CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= nullptr*/) const override
101 {
103 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
104 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
105 }
106
108 void CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= nullptr*/) const override
109 {
111 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
112 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
113 }
114
115 int32 GetMapIdForSpawning() const override { return GetBase()->GetMapId(); }
116
117 void RemovePendingEvent(VehicleJoinEvent* e);
118 void RemovePendingEventsForSeat(int8 seatId);
119
120 bool HasPendingEventForSeat(int8 seatId) const;
121
122 private:
126
129
130 typedef std::list<VehicleJoinEvent*> PendingJoinEventContainer;
132};
133
135{
136 friend class Vehicle;
137 protected:
138 VehicleJoinEvent(Vehicle* v, Unit* u) : Target(v), Passenger(u), Seat(Target->Seats.end()) { }
139 bool Execute(uint64, uint32) override;
140 void Abort(uint64) override;
141
144 SeatMap::iterator Seat;
145};
146
147#endif
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int8_t int8
Definition: Define.h:140
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:142
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
std::string GetDebugInfo()
Definition: Errors.cpp:157
#define ABORT_MSG
Definition: Errors.h:75
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:393
std::map< int8, VehicleSeat > SeatMap
virtual void CalculatePassengerPosition(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied transport offsets into global coordinates.
virtual TransportBase * RemovePassenger(WorldObject *passenger)=0
virtual void CalculatePassengerOffset(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied global coordinates into local offsets.
Trinity::unique_trackable_ptr companion class, replicating what std::weak_ptr is to std::shared_ptr.
Definition: Unit.h:627
SeatMap::iterator Seat
Definition: Vehicle.h:144
Unit * Passenger
Definition: Vehicle.h:143
Vehicle * Target
Definition: Vehicle.h:142
VehicleJoinEvent(Vehicle *v, Unit *u)
Definition: Vehicle.h:138
Vehicle(Vehicle &&right)=delete
float GetTransportOrientation() const override
Definition: Vehicle.h:95
Unit * GetBase() const
Definition: Vehicle.h:49
GuidSet vehiclePlayers
Definition: Vehicle.h:125
VehicleEntry const * GetVehicleInfo() const
Definition: Vehicle.h:50
Status
Definition: Vehicle.h:85
@ STATUS_INSTALLED
Definition: Vehicle.h:87
@ STATUS_UNINSTALLING
Definition: Vehicle.h:88
@ STATUS_NONE
Definition: Vehicle.h:86
uint32 GetCreatureEntry() const
Definition: Vehicle.h:51
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags.
Definition: Vehicle.h:81
std::list< VehicleJoinEvent * > PendingJoinEventContainer
Definition: Vehicle.h:130
void CalculatePassengerPosition(float &x, float &y, float &z, float *o) const override
This method transforms supplied transport offsets into global coordinates.
Definition: Vehicle.h:100
Vehicle & operator=(Vehicle const &right)=delete
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:127
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:128
Vehicle(Vehicle const &right)=delete
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:123
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:131
void AddPassenger(WorldObject *) override
Attempts to add a passenger to the vehicle on 'seatId'.
Definition: Vehicle.h:97
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:93
int32 GetMapIdForSpawning() const override
Definition: Vehicle.h:115
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:124
void CalculatePassengerOffset(float &x, float &y, float &z, float *o) const override
This method transforms supplied global coordinates into local offsets.
Definition: Vehicle.h:108
void Abort(char const *file, int line, char const *function)
Definition: Errors.cpp:124