TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vehicle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __TRINITY_VEHICLE_H
20 #define __TRINITY_VEHICLE_H
21 
22 #include "ObjectDefines.h"
23 #include "Object.h"
24 #include "VehicleDefines.h"
25 #include "Unit.h"
26 #include <list>
27 
28 struct VehicleEntry;
29 class Unit;
30 class VehicleJoinEvent;
31 
33 {
34  protected:
35  friend bool Unit::CreateVehicleKit(uint32 id, uint32 creatureEntry, bool);
36  Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry);
37 
38  friend void Unit::RemoveVehicleKit(bool);
39  ~Vehicle();
40 
41  public:
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);
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  uint8 GetAvailableSeatCount() const;
57 
58  bool AddPassenger(Unit* passenger, int8 seatId = -1);
59  void EjectPassenger(Unit* passenger, Unit* controller);
60  Vehicle* RemovePassenger(Unit* passenger);
61  void RelocatePassengers();
62  void RemoveAllPassengers();
63  bool IsVehicleInUse() const;
64 
65  void SetLastShootPos(Position const& pos) { _lastShootPos.Relocate(pos); }
66  Position const& GetLastShootPos() const { return _lastShootPos; }
67 
69 
70  VehicleSeatEntry const* GetSeatForPassenger(Unit const* passenger) const;
71 
72  void RemovePendingEventsForPassenger(Unit* passenger);
73 
74  protected:
75  friend class VehicleJoinEvent;
77 
78  private:
79  enum Status
80  {
84  };
85 
86  SeatMap::iterator GetSeatIteratorForPassenger(Unit* passenger);
87  void InitMovementInfoForBase();
88 
90  void CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= NULL*/) const override
91  {
93  GetBase()->GetPositionX(), GetBase()->GetPositionY(),
94  GetBase()->GetPositionZ(), GetBase()->GetOrientation());
95  }
96 
98  void CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= NULL*/) const override
99  {
101  GetBase()->GetPositionX(), GetBase()->GetPositionY(),
102  GetBase()->GetPositionZ(), GetBase()->GetOrientation());
103  }
104 
105  void RemovePendingEvent(VehicleJoinEvent* e);
106  void RemovePendingEventsForSeat(int8 seatId);
107 
108  private:
112 
116 
117  typedef std::list<VehicleJoinEvent*> PendingJoinEventContainer;
118  PendingJoinEventContainer _pendingJoinEvents;
119 };
120 
122 {
123  friend class Vehicle;
124  protected:
125  VehicleJoinEvent(Vehicle* v, Unit* u) : Target(v), Passenger(u), Seat(Target->Seats.end()) { }
126  ~VehicleJoinEvent();
127  bool Execute(uint64, uint32) override;
128  void Abort(uint64) override;
129 
132  SeatMap::iterator Seat;
133 };
134 
135 #endif
Definition: DBCStructure.h:1305
Position _lastShootPos
Definition: Vehicle.h:115
Definition: Vehicle.h:32
int8_t int8
Definition: Define.h:148
VehicleEntry const * GetVehicleInfo() const
Definition: Vehicle.h:50
void RemoveVehicleKit(bool onRemoveFromWorld=false)
Definition: Unit.cpp:14318
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags...
Definition: Vehicle.h:76
Definition: Vehicle.h:83
int next(int i, int n)
Definition: RecastContour.cpp:469
Unit * Passenger
Definition: Vehicle.h:131
virtual void CalculatePassengerOffset(float &x, float &y, float &z, float *o=NULL) const =0
This method transforms supplied global coordinates into local offsets.
virtual void Abort(uint64)
Definition: EventProcessor.h:46
GuidSet vehiclePlayers
Definition: Vehicle.h:111
Definition: VehicleDefines.h:119
Position const & GetLastShootPos() const
Definition: Vehicle.h:66
virtual void CalculatePassengerPosition(float &x, float &y, float &z, float *o=NULL) const =0
This method transforms supplied transport offsets into global coordinates.
Definition: DBCStructure.h:1271
std::map< int8, VehicleSeat > SeatMap
Definition: VehicleDefines.h:117
bool CreateVehicleKit(uint32 id, uint32 creatureEntry, bool loading=false)
Definition: Unit.cpp:14302
void CalculatePassengerOffset(float &x, float &y, float &z, float *o) const override
This method transforms supplied global coordinates into local offsets.
Definition: Vehicle.h:98
void CalculatePassengerPosition(float &x, float &y, float &z, float *o) const override
This method transforms supplied transport offsets into global coordinates.
Definition: Vehicle.h:90
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
G3D::int16 z
Definition: Vector3int16.h:46
Seats
Definition: boss_grand_champions.cpp:78
VehicleJoinEvent(Vehicle *v, Unit *u)
Definition: Vehicle.h:125
Definition: Vehicle.h:81
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
G3D::int16 y
Definition: Vector2int16.h:38
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
virtual bool Execute(uint64, uint32)
Definition: EventProcessor.h:42
Definition: EventProcessor.h:28
SeatMap::iterator Seat
Definition: Vehicle.h:132
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:332
#define TC_GAME_API
Definition: Define.h:134
Definition: Vehicle.h:121
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110
uint8_t uint8
Definition: Define.h:152
Definition: Position.h:27
Vehicle * Target
Definition: Vehicle.h:130
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118
Definition: Vehicle.h:82
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:113
G3D::int16 x
Definition: Vector2int16.h:37
void SetLastShootPos(Position const &pos)
Definition: Vehicle.h:65
Definition: Unit.h:1305
std::list< VehicleJoinEvent * > PendingJoinEventContainer
Definition: Vehicle.h:117
SeatMap Seats
The collection of all seats on the vehicle. Including vacant ones.
Definition: Vehicle.h:68
uint32 GetCreatureEntry() const
Definition: Vehicle.h:51
Status
Definition: Vehicle.h:79
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49