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 "ObjectDefines.h"
22#include "Object.h"
23#include "UniqueTrackablePtr.h"
24#include "Unit.h"
25#include "VehicleDefines.h"
26#include <list>
27
28struct VehicleEntry;
29class Unit;
31
33{
34 public:
35 Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry);
36 ~Vehicle();
37
38 void Install();
39 void Uninstall();
40 void Reset(bool evading = false);
41 void InstallAllAccessories(bool evading);
42 void ApplyAllImmunities();
43 void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime);
44
45 Unit* GetBase() const { return _me; }
46 VehicleEntry const* GetVehicleInfo() const { return _vehicleInfo; }
47 uint32 GetCreatureEntry() const { return _creatureEntry; }
48
49 bool HasEmptySeat(int8 seatId) const;
50 Unit* GetPassenger(int8 seatId) const;
51 SeatMap::const_iterator GetNextEmptySeat(int8 seatId, bool next) const;
52 VehicleSeatAddon const* GetSeatAddonForSeatOfPassenger(Unit const* passenger) const;
53 uint8 GetAvailableSeatCount() const;
54
55 bool AddPassenger(Unit* passenger, int8 seatId = -1);
56 void EjectPassenger(Unit* passenger, Unit* controller);
57 Vehicle* RemovePassenger(Unit* passenger);
58 void RelocatePassengers();
59 void RemoveAllPassengers();
60 bool IsVehicleInUse() const;
61 bool IsControllableVehicle() const;
62
64
65 VehicleSeatEntry const* GetSeatForPassenger(Unit const* passenger) const;
66
67 void RemovePendingEventsForPassenger(Unit* passenger);
68
69 Milliseconds GetDespawnDelay();
70
71 std::string GetDebugInfo() const;
72
73 Trinity::unique_weak_ptr<Vehicle> GetWeakPtr() const;
74
75 protected:
76 friend class VehicleJoinEvent;
78
79 private:
86
87 SeatMap::iterator GetSeatIteratorForPassenger(Unit* passenger);
88 void InitMovementInfoForBase();
89
91 void CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= nullptr*/) const override
92 {
94 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
95 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
96 }
97
99 void CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= nullptr*/) const override
100 {
102 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
103 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
104 }
105
106 void RemovePendingEvent(VehicleJoinEvent* e);
107 void RemovePendingEventsForSeat(int8 seatId);
108
109 bool HasPendingEventForSeat(int8 seatId) const;
110
111 private:
115
118
119 typedef std::list<VehicleJoinEvent*> PendingJoinEventContainer;
121};
122
124{
125 friend class Vehicle;
126 protected:
127 VehicleJoinEvent(Vehicle* v, Unit* u) : Target(v), Passenger(u), Seat(Target->Seats.end()) { }
128 bool Execute(uint64, uint32) override;
129 void Abort(uint64) override;
130
133 SeatMap::iterator Seat;
134};
135
136#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int8_t int8
Definition Define.h:131
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
std::string GetDebugInfo()
Definition Errors.cpp:155
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
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 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:769
SeatMap::iterator Seat
Definition Vehicle.h:133
Unit * Passenger
Definition Vehicle.h:132
Vehicle * Target
Definition Vehicle.h:131
VehicleJoinEvent(Vehicle *v, Unit *u)
Definition Vehicle.h:127
void EjectPassenger(Unit *passenger, Unit *controller)
Unit * GetBase() const
May be called from scripts.
Definition Vehicle.h:45
GuidSet vehiclePlayers
Definition Vehicle.h:114
VehicleEntry const * GetVehicleInfo() const
Definition Vehicle.h:46
@ STATUS_INSTALLED
Definition Vehicle.h:83
@ STATUS_UNINSTALLING
Definition Vehicle.h:84
@ STATUS_NONE
Definition Vehicle.h:82
uint32 GetCreatureEntry() const
Definition Vehicle.h:47
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags.
Definition Vehicle.h:77
std::list< VehicleJoinEvent * > PendingJoinEventContainer
Definition Vehicle.h:119
void CalculatePassengerPosition(float &x, float &y, float &z, float *o) const override
This method transforms supplied transport offsets into global coordinates.
Definition Vehicle.h:91
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition Vehicle.h:116
Status _status
Internal variable for sanity checks.
Definition Vehicle.h:117
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition Vehicle.h:112
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition Vehicle.h:120
SeatMap Seats
The collection of all seats on the vehicle. Including vacant ones.
Definition Vehicle.h:63
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition Vehicle.h:113
void CalculatePassengerOffset(float &x, float &y, float &z, float *o) const override
This method transforms supplied global coordinates into local offsets.
Definition Vehicle.h:99