1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TRINITY_VEHICLE_H
#define __TRINITY_VEHICLE_H
#include "Object.h"
#include "UniqueTrackablePtr.h"
#include "Unit.h"
#include "VehicleDefines.h"
#include <list>
struct VehicleEntry;
class Unit;
class VehicleJoinEvent;
class TC_GAME_API Vehicle final : public TransportBase
{
public:
Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry);
~Vehicle();
Vehicle(Vehicle const& right) = delete;
Vehicle(Vehicle&& right) = delete;
Vehicle& operator=(Vehicle const& right) = delete;
Vehicle& operator=(Vehicle&& right) = delete;
void Install();
void Uninstall();
void Reset(bool evading = false);
void InstallAllAccessories(bool evading);
void ApplyAllImmunities();
void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime, Optional<uint32> rideSpellId = {}); // May be called from scripts
Unit* GetBase() const { return _me; }
VehicleEntry const* GetVehicleInfo() const { return _vehicleInfo; }
uint32 GetCreatureEntry() const { return _creatureEntry; }
bool HasEmptySeat(int8 seatId) const;
Unit* GetPassenger(int8 seatId) const;
SeatMap::const_iterator GetNextEmptySeat(int8 seatId, bool next) const;
VehicleSeatAddon const* GetSeatAddonForSeatOfPassenger(Unit const* passenger) const;
uint8 GetAvailableSeatCount() const;
bool AddVehiclePassenger(Unit* unit, int8 seatId = -1);
Vehicle* RemovePassenger(WorldObject* passenger) override;
void RelocatePassengers();
void RemoveAllPassengers();
bool IsVehicleInUse() const;
bool IsControllableVehicle() const;
SeatMap::iterator GetSeatIteratorForPassenger(Unit* passenger);
SeatMap Seats; ///< The collection of all seats on the vehicle. Including vacant ones.
VehicleSeatEntry const* GetSeatForPassenger(Unit const* passenger) const;
void RemovePendingEventsForPassenger(Unit* passenger);
Milliseconds GetDespawnDelay();
float GetPitch();
std::string GetDebugInfo() const;
Trinity::unique_weak_ptr<Vehicle> GetWeakPtr() const;
protected:
friend class VehicleJoinEvent;
uint32 UsableSeatNum; ///< Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags
private:
enum Status
{
STATUS_NONE,
STATUS_INSTALLED,
STATUS_UNINSTALLING,
};
void InitMovementInfoForBase();
ObjectGuid GetTransportGUID() const override { return GetBase()->GetGUID(); }
float GetTransportOrientation() const override { return GetBase()->GetOrientation(); }
void AddPassenger(WorldObject* /*passenger*/) override { ABORT_MSG("Vehicle cannot directly gain passengers without auras"); }
/// This method transforms supplied transport offsets into global coordinates
void CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= nullptr*/) const override
{
TransportBase::CalculatePassengerPosition(x, y, z, o,
GetBase()->GetPositionX(), GetBase()->GetPositionY(),
GetBase()->GetPositionZ(), GetBase()->GetOrientation());
}
/// This method transforms supplied global coordinates into local offsets
void CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= nullptr*/) const override
{
TransportBase::CalculatePassengerOffset(x, y, z, o,
GetBase()->GetPositionX(), GetBase()->GetPositionY(),
GetBase()->GetPositionZ(), GetBase()->GetOrientation());
}
int32 GetMapIdForSpawning() const override { return GetBase()->GetMapId(); }
void RemovePendingEvent(VehicleJoinEvent* e);
void RemovePendingEventsForSeat(int8 seatId);
bool HasPendingEventForSeat(int8 seatId) const;
private:
Unit* _me; ///< The underlying unit with the vehicle kit. Can be player or creature.
VehicleEntry const* _vehicleInfo; ///< DBC data for vehicle
GuidSet vehiclePlayers;
uint32 _creatureEntry; ///< Can be different than the entry of _me in case of players
Status _status; ///< Internal variable for sanity checks
typedef std::list<VehicleJoinEvent*> PendingJoinEventContainer;
PendingJoinEventContainer _pendingJoinEvents; ///< Collection of delayed join events for prospective passengers
};
class TC_GAME_API VehicleJoinEvent : public BasicEvent
{
friend class Vehicle;
protected:
VehicleJoinEvent(Vehicle* v, Unit* u) : Target(v), Passenger(u), Seat(Target->Seats.end()) { }
bool Execute(uint64, uint32) override;
void Abort(uint64) override;
Vehicle* Target;
Unit* Passenger;
SeatMap::iterator Seat;
};
#endif
|