TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vehicle Class Reference

#include <Vehicle.h>

Public Member Functions

void Install ()
 Initializes power type for vehicle. Nothing more. More...
 
void Uninstall ()
 Removes all passengers and sets status to STATUS_UNINSTALLING. No new passengers can be added to the vehicle after this call. More...
 
void Reset (bool evading=false)
 Reapplies immunities and reinstalls accessories. Only has effect for creatures. More...
 
void InstallAllAccessories (bool evading)
 
void ApplyAllImmunities ()
 Applies specific immunities that cannot be set in DB. More...
 
void InstallAccessory (uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
 Installs an accessory. More...
 
UnitGetBase () const
 May be called from scripts. More...
 
VehicleEntry constGetVehicleInfo () const
 
uint32 GetCreatureEntry () const
 
bool HasEmptySeat (int8 seatId) const
 Checks if vehicle's seat specified by 'seatId' is empty. More...
 
UnitGetPassenger (int8 seatId) const
 Gets a passenger on specified seat. More...
 
SeatMap::const_iterator GetNextEmptySeat (int8 seatId, bool next) const
 Gets the next empty seat based on current seat. More...
 
uint8 GetAvailableSeatCount () const
 Gets the available seat count. More...
 
bool AddPassenger (Unit *passenger, int8 seatId=-1)
 Attempts to add a passenger to the vehicle on 'seatId'. More...
 
void EjectPassenger (Unit *passenger, Unit *controller)
 
VehicleRemovePassenger (Unit *passenger)
 Removes the passenger from the vehicle. More...
 
void RelocatePassengers ()
 Relocate passengers. Must be called after m_base::Relocate. More...
 
void RemoveAllPassengers ()
 Removes all current and pending passengers from the vehicle. More...
 
bool IsVehicleInUse () const
 Returns information whether the vehicle is currently used by any unit. More...
 
void SetLastShootPos (Position const &pos)
 
Position constGetLastShootPos () const
 
VehicleSeatEntry constGetSeatForPassenger (Unit const *passenger) const
 Returns information on the seat of specified passenger, represented by the format in VehicleSeat.dbc. More...
 
void RemovePendingEventsForPassenger (Unit *passenger)
 

Public Attributes

SeatMap Seats
 The collection of all seats on the vehicle. Including vacant ones. More...
 

Protected Member Functions

 Vehicle (Unit *unit, VehicleEntry const *vehInfo, uint32 creatureEntry)
 
 ~Vehicle ()
 
- Protected Member Functions inherited from TransportBase
 TransportBase ()
 
virtual ~TransportBase ()
 

Protected Attributes

uint32 UsableSeatNum
 Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags. More...
 

Private Types

enum  Status { STATUS_NONE, STATUS_INSTALLED, STATUS_UNINSTALLING }
 
typedef std::list
< VehicleJoinEvent * > 
PendingJoinEventContainer
 

Private Member Functions

SeatMap::iterator GetSeatIteratorForPassenger (Unit *passenger)
 Gets seat iterator for specified passenger. More...
 
void InitMovementInfoForBase ()
 Sets correct MovementFlags2 based on VehicleFlags from DBC. More...
 
void CalculatePassengerPosition (float &x, float &y, float &z, float *o) const override
 This method transforms supplied transport offsets into global coordinates. More...
 
void CalculatePassengerOffset (float &x, float &y, float &z, float *o) const override
 This method transforms supplied global coordinates into local offsets. More...
 
void RemovePendingEvent (VehicleJoinEvent *e)
 Removes objects from pending join event store. This method only removes it after it's executed or aborted to prevent leaving pointers to deleted events. More...
 
void RemovePendingEventsForSeat (int8 seatId)
 Removes any pending events for given seatId. Executed when a ::Execute is called. More...
 

Private Attributes

Unit_me
 The underlying unit with the vehicle kit. Can be player or creature. More...
 
VehicleEntry const_vehicleInfo
 DBC data for vehicle. More...
 
GuidSet vehiclePlayers
 
uint32 _creatureEntry
 Can be different than the entry of _me in case of players. More...
 
Status _status
 Internal variable for sanity checks. More...
 
Position _lastShootPos
 
PendingJoinEventContainer _pendingJoinEvents
 Collection of delayed join events for prospective passengers. More...
 

Friends

class VehicleJoinEvent
 
bool Unit::CreateVehicleKit (uint32 id, uint32 creatureEntry, bool)
 
void Unit::RemoveVehicleKit (bool)
 

Additional Inherited Members

- Static Public Member Functions inherited from TransportBase
static void CalculatePassengerPosition (float &x, float &y, float &z, float *o, float transX, float transY, float transZ, float transO)
 
static void CalculatePassengerOffset (float &x, float &y, float &z, float *o, float transX, float transY, float transZ, float transO)
 

Member Typedef Documentation

Member Enumeration Documentation

enum Vehicle::Status
private
Enumerator
STATUS_NONE 
STATUS_INSTALLED 
STATUS_UNINSTALLING 
80  {
84  };
Definition: Vehicle.h:83
Definition: Vehicle.h:81
Definition: Vehicle.h:82

Constructor & Destructor Documentation

Vehicle::Vehicle ( Unit unit,
VehicleEntry const vehInfo,
uint32  creatureEntry 
)
protected
33  :
34 UsableSeatNum(0), _me(unit), _vehicleInfo(vehInfo), _creatureEntry(creatureEntry), _status(STATUS_NONE), _lastShootPos()
35 {
36  for (uint32 i = 0; i < MAX_VEHICLE_SEATS; ++i)
37  {
38  if (uint32 seatId = _vehicleInfo->SeatID[i])
39  if (VehicleSeatEntry const* veSeat = sVehicleSeatStore.LookupEntry(seatId))
40  {
41  Seats.insert(std::make_pair(i, VehicleSeat(veSeat)));
42  if (veSeat->CanEnterOrExit())
43  ++UsableSeatNum;
44  }
45  }
46 
47  // Set or remove correct flags based on available seats. Will overwrite db data (if wrong).
48  if (UsableSeatNum)
50  else
52 
54 }
Definition: DBCStructure.h:1305
Position _lastShootPos
Definition: Vehicle.h:115
Definition: Unit.h:759
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags...
Definition: Vehicle.h:76
TypeID GetTypeId() const
Definition: Object.h:113
Definition: Unit.h:760
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Seats
Definition: boss_grand_champions.cpp:78
Definition: Vehicle.h:81
uint32_t uint32
Definition: Define.h:150
uint32 SeatID[MAX_VEHICLE_SEATS]
Definition: DBCStructure.h:1280
void SetFlag64(uint16 index, uint64 newFlag)
Definition: Object.cpp:1305
void InitMovementInfoForBase()
Sets correct MovementFlags2 based on VehicleFlags from DBC.
Definition: Vehicle.cpp:569
DBCStorage< VehicleSeatEntry > sVehicleSeatStore(VehicleSeatfmt)
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
#define MAX_VEHICLE_SEATS
Definition: DBCStructure.h:1269
Definition: ObjectGuid.h:33
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110
Definition: UpdateFields.h:135
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:113
Definition: VehicleDefines.h:90
void RemoveFlag64(uint16 index, uint64 oldFlag)
Definition: Object.cpp:1312

+ Here is the call graph for this function:

Vehicle::~Vehicle ( )
protected

must be called before this.

57 {
60  for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
61  ASSERT(itr->second.IsEmpty());
62 }
Definition: Vehicle.h:83
Seats
Definition: boss_grand_champions.cpp:78
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
#define ASSERT
Definition: Errors.h:55

Member Function Documentation

bool Vehicle::AddPassenger ( Unit unit,
int8  seatId = -1 
)

Attempts to add a passenger to the vehicle on 'seatId'.

Author
Machiavelli
Date
17-2-2013
Parameters
[in,out]Theprospective passenger.
seatIdIdentifier for the seat. Value of -1 indicates the next available seat.
Returns
true if it succeeds, false if it fails.

adding passengers when vehicle is uninstalling. (Bad script in OnUninstall/OnRemovePassenger/PassengerBoarded hook.)

395 {
398  {
399  TC_LOG_ERROR("entities.vehicle", "Passenger %s, Entry: %u, attempting to board %s, Entry: %u during uninstall! SeatId: %d",
400  unit->GetGUID().ToString().c_str(), unit->GetEntry(), _me->GetGUID().ToString().c_str(), _me->GetEntry(), (int32)seatId);
401  return false;
402  }
403 
404  TC_LOG_DEBUG("entities.vehicle", "Unit %s scheduling enter vehicle (entry: %u, vehicleId: %u, %s (dbguid: " UI64FMTD ") on seat %d",
405  unit->GetName().c_str(), _me->GetEntry(), _vehicleInfo->ID, _me->GetGUID().ToString().c_str(),
406  uint64(_me->GetTypeId() == TYPEID_UNIT ? _me->ToCreature()->GetSpawnId() : UI64LIT(0)), (int32)seatId);
407 
408  // The seat selection code may kick other passengers off the vehicle.
409  // While the validity of the following may be arguable, it is possible that when such a passenger
410  // exits the vehicle will dismiss. That's why the actual adding the passenger to the vehicle is scheduled
411  // asynchronously, so it can be cancelled easily in case the vehicle is uninstalled meanwhile.
412  SeatMap::iterator seat;
413  VehicleJoinEvent* e = new VehicleJoinEvent(this, unit);
414  unit->m_Events.AddEvent(e, unit->m_Events.CalculateTime(0));
415 
416  if (seatId < 0) // no specific seat requirement
417  {
418  for (seat = Seats.begin(); seat != Seats.end(); ++seat)
419  if (seat->second.IsEmpty() && (seat->second.SeatInfo->CanEnterOrExit() || seat->second.SeatInfo->IsUsableByOverride()))
420  break;
421 
422  if (seat == Seats.end()) // no available seat
423  {
424  e->to_Abort = true;
425  return false;
426  }
427 
428  e->Seat = seat;
429  _pendingJoinEvents.push_back(e);
430  }
431  else
432  {
433  seat = Seats.find(seatId);
434  if (seat == Seats.end())
435  {
436  e->to_Abort = true;
437  return false;
438  }
439 
440  e->Seat = seat;
441  _pendingJoinEvents.push_back(e);
442  if (!seat->second.IsEmpty())
443  {
444  Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), seat->second.Passenger.Guid);
445  ASSERT(passenger);
446  passenger->ExitVehicle();
447  }
448 
449  ASSERT(seat->second.IsEmpty());
450  }
451 
452  return true;
453 }
bool to_Abort
Definition: EventProcessor.h:48
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
Definition: Vehicle.h:83
std::string const & GetName() const
Definition: Object.h:479
#define UI64LIT(N)
Definition: Define.h:138
Definition: ObjectGuid.h:32
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint64_t uint64
Definition: g3dmath.h:170
void ExitVehicle(Position const *exitPosition=NULL)
Definition: Unit.cpp:15321
TypeID GetTypeId() const
Definition: Object.h:113
uint32 ID
Definition: DBCStructure.h:1273
std::map< int8, VehicleSeat > SeatMap
Definition: VehicleDefines.h:117
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Seats
Definition: boss_grand_champions.cpp:78
#define UI64FMTD
Definition: Define.h:137
int32_t int32
Definition: Define.h:146
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Creature * ToCreature()
Definition: Object.h:194
Definition: Vehicle.h:121
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110
int32_t int32
Definition: g3dmath.h:167
#define ASSERT
Definition: Errors.h:55
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: Unit.h:1305
std::string ToString() const
Definition: ObjectGuid.cpp:99
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::ApplyAllImmunities ( )

Applies specific immunities that cannot be set in DB.

Author
Machiavelli
Date
17-2-2013
164 {
165  // This couldn't be done in DB, because some spells have MECHANIC_NONE
166 
167  // Vehicles should be immune on Knockback ...
170 
171  // Mechanical units & vehicles ( which are not Bosses, they have own immunities in DB ) should be also immune on healing ( exceptions in switch below )
173  {
174  // Heal & dispel ...
179 
180  // ... Shield & Immunity grant spells ...
186 
187  // ... Resistance, Split damage, Change stats ...
193  }
194 
195  // Different immunities for vehicles goes below
196  switch (GetVehicleInfo()->ID)
197  {
198  // code below prevents a bug with movable cannons
199  case 160: // Strand of the Ancients
200  case 244: // Wintergrasp
201  case 510: // Isle of Conquest
202  case 452: // Isle of Conquest
203  case 543: // Isle of Conquest
205  // why we need to apply this? we can simple add immunities to slow mechanic in DB
207  break;
208  default:
209  break;
210  }
211 }
Definition: SpellAuraDefines.h:68
Definition: SharedDefines.h:3562
Definition: SharedDefines.h:1819
Definition: SpellAuraDefines.h:147
VehicleEntry const * GetVehicleInfo() const
Definition: Vehicle.h:50
Definition: SharedDefines.h:1861
void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply)
Definition: Unit.cpp:9615
Definition: SpellAuraDefines.h:75
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:558
void SetControlled(bool apply, UnitState state)
Definition: Unit.cpp:13808
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Definition: SpellAuraDefines.h:141
Definition: SharedDefines.h:1020
Definition: SharedDefines.h:1809
Definition: SharedDefines.h:1108
Definition: SpellAuraDefines.h:89
Creature * ToCreature()
Definition: Object.h:194
Definition: Unit.h:560
Definition: SpellAuraDefines.h:153
Definition: SharedDefines.h:1146
Definition: SpellAuraDefines.h:82
Definition: SpellAuraDefines.h:93
Definition: SharedDefines.h:1860
bool isWorldBoss() const
Definition: Creature.cpp:1833
Definition: SharedDefines.h:1865
Definition: SharedDefines.h:1154
Definition: SpellAuraDefines.h:129
Definition: SharedDefines.h:1048
Definition: SpellAuraDefines.h:99
uint32 type
Definition: Creature.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::CalculatePassengerOffset ( float &  x,
float &  y,
float &  z,
float *  o 
) const
inlineoverrideprivatevirtual

This method transforms supplied global coordinates into local offsets.

Implements TransportBase.

99  {
101  GetBase()->GetPositionX(), GetBase()->GetPositionY(),
102  GetBase()->GetPositionZ(), GetBase()->GetOrientation());
103  }
virtual void CalculatePassengerOffset(float &x, float &y, float &z, float *o=NULL) const =0
This method transforms supplied global coordinates into local offsets.
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

void Vehicle::CalculatePassengerPosition ( float &  x,
float &  y,
float &  z,
float *  o 
) const
inlineoverrideprivatevirtual

This method transforms supplied transport offsets into global coordinates.

Implements TransportBase.

91  {
93  GetBase()->GetPositionX(), GetBase()->GetPositionY(),
94  GetBase()->GetPositionZ(), GetBase()->GetOrientation());
95  }
virtual void CalculatePassengerPosition(float &x, float &y, float &z, float *o=NULL) const =0
This method transforms supplied transport offsets into global coordinates.
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::EjectPassenger ( Unit passenger,
Unit controller 
)
uint8 Vehicle::GetAvailableSeatCount ( ) const

Gets the available seat count.

Author
Machiavelli
Date
17-2-2013
Returns
The available seat count.
642 {
643  uint8 ret = 0;
644  SeatMap::const_iterator itr;
645  for (itr = Seats.begin(); itr != Seats.end(); ++itr)
646  if (itr->second.IsEmpty() && (itr->second.SeatInfo->CanEnterOrExit() || itr->second.SeatInfo->IsUsableByOverride()))
647  ++ret;
648 
649  return ret;
650 }
Seats
Definition: boss_grand_champions.cpp:78
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

Unit* Vehicle::GetBase ( ) const
inline

May be called from scripts.

49 { return _me; }
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109

+ Here is the caller graph for this function:

uint32 Vehicle::GetCreatureEntry ( ) const
inline
51 { return _creatureEntry; }
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:113

+ Here is the caller graph for this function:

Position const& Vehicle::GetLastShootPos ( ) const
inline
66 { return _lastShootPos; }
Position _lastShootPos
Definition: Vehicle.h:115
SeatMap::const_iterator Vehicle::GetNextEmptySeat ( int8  seatId,
bool  next 
) const

Gets the next empty seat based on current seat.

Author
Machiavelli
Date
17-2-2013
Parameters
seatIdIdentifier for the current seat.
nexttrue if iterating forward, false means iterating backwards.
Returns
The next empty seat.
311 {
312  SeatMap::const_iterator seat = Seats.find(seatId);
313  if (seat == Seats.end())
314  return seat;
315 
316  while (!seat->second.IsEmpty() || (!seat->second.SeatInfo->CanEnterOrExit() && !seat->second.SeatInfo->IsUsableByOverride()))
317  {
318  if (next)
319  {
320  if (++seat == Seats.end())
321  seat = Seats.begin();
322  }
323  else
324  {
325  if (seat == Seats.begin())
326  seat = Seats.end();
327  --seat;
328  }
329 
330  // Make sure we don't loop indefinetly
331  if (seat->first == seatId)
332  return Seats.end();
333  }
334 
335  return seat;
336 }
int next(int i, int n)
Definition: RecastContour.cpp:469
Seats
Definition: boss_grand_champions.cpp:78

+ Here is the caller graph for this function:

Unit * Vehicle::GetPassenger ( int8  seatId) const

Gets a passenger on specified seat.

Author
Machiavelli
Date
17-2-2013
Parameters
seatIdSeat to look on.
Returns
null if it not found, else pointer to passenger if in world
288 {
289  SeatMap::const_iterator seat = Seats.find(seatId);
290  if (seat == Seats.end())
291  return NULL;
292 
293  return ObjectAccessor::GetUnit(*GetBase(), seat->second.Passenger.Guid);
294 }
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
arena_t NULL
Definition: jemalloc_internal.h:624
Seats
Definition: boss_grand_champions.cpp:78
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VehicleSeatEntry const * Vehicle::GetSeatForPassenger ( Unit const passenger) const

Returns information on the seat of specified passenger, represented by the format in VehicleSeat.dbc.

Author
Machiavelli
Date
17-2-2013
Parameters
[in,out]Thepassenger for which we check the seat info.
Returns
null if passenger not found on vehicle, else the DBC record for the seat.
599 {
600  for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
601  if (itr->second.Passenger.Guid == passenger->GetGUID())
602  return itr->second.SeatInfo;
603 
604  return NULL;
605 }
arena_t NULL
Definition: jemalloc_internal.h:624
Seats
Definition: boss_grand_champions.cpp:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SeatMap::iterator Vehicle::GetSeatIteratorForPassenger ( Unit passenger)
private

Gets seat iterator for specified passenger.

Author
Machiavelli
Date
17-2-2013
Parameters
[in,out]passengerPassenger to look up.
Returns
The seat iterator for specified passenger if it's found on the vehicle. Otherwise Seats.end() (invalid iterator).
621 {
622  SeatMap::iterator itr;
623  for (itr = Seats.begin(); itr != Seats.end(); ++itr)
624  if (itr->second.Passenger.Guid == passenger->GetGUID())
625  return itr;
626 
627  return Seats.end();
628 }
Seats
Definition: boss_grand_champions.cpp:78
ObjectGuid const & GetGUID() const
Definition: Object.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VehicleEntry const* Vehicle::GetVehicleInfo ( ) const
inline
50 { return _vehicleInfo; }
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110

+ Here is the caller graph for this function:

bool Vehicle::HasEmptySeat ( int8  seatId) const

Checks if vehicle's seat specified by 'seatId' is empty.

Author
Machiavelli
Date
17-2-2013
Parameters
seatIdIdentifier for the seat.
Returns
true if empty seat, false if not.
267 {
268  SeatMap::const_iterator seat = Seats.find(seatId);
269  if (seat == Seats.end())
270  return false;
271  return seat->second.IsEmpty();
272 }
Seats
Definition: boss_grand_champions.cpp:78

+ Here is the caller graph for this function:

void Vehicle::InitMovementInfoForBase ( )
private

Sets correct MovementFlags2 based on VehicleFlags from DBC.

Author
Machiavelli
Date
17-2-2013
570 {
571  uint32 vehicleFlags = GetVehicleInfo()->Flags;
572 
573  if (vehicleFlags & VEHICLE_FLAG_NO_STRAFE)
575  if (vehicleFlags & VEHICLE_FLAG_NO_JUMPING)
577  if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDTURNING)
579  if (vehicleFlags & VEHICLE_FLAG_ALLOW_PITCHING)
581  if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDPITCHING)
583 }
Definition: VehicleDefines.h:66
Definition: Unit.h:837
VehicleEntry const * GetVehicleInfo() const
Definition: Vehicle.h:50
void AddExtraUnitMovementFlag(uint16 f)
Definition: Unit.h:2113
Definition: VehicleDefines.h:64
uint32 Flags
Definition: DBCStructure.h:1274
Definition: VehicleDefines.h:65
Definition: Unit.h:839
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Definition: Unit.h:840
uint32_t uint32
Definition: Define.h:150
Definition: Unit.h:838
Definition: VehicleDefines.h:63
Definition: VehicleDefines.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::Install ( )

Initializes power type for vehicle. Nothing more.

Author
Machiavelli
Date
17-2-2013
74 {
75  if (_me->GetTypeId() == TYPEID_UNIT)
76  {
77  if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(_vehicleInfo->PowerDisplayID[0]))
78  _me->setPowerType(Powers(powerDisplay->PowerType));
79  else if (_me->getClass() == CLASS_ROGUE)
81  }
82 
84  if (GetBase()->GetTypeId() == TYPEID_UNIT)
85  sScriptMgr->OnInstall(this);
86 }
Definition: SharedDefines.h:170
Definition: ObjectGuid.h:32
uint32 PowerDisplayID[3]
Definition: DBCStructure.h:1302
void setPowerType(Powers power)
Definition: Unit.cpp:6977
TypeID GetTypeId() const
Definition: Object.h:113
Powers
Definition: SharedDefines.h:246
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
DBCStorage< PowerDisplayEntry > sPowerDisplayStore(PowerDisplayfmt)
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
Definition: SharedDefines.h:251
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110
uint8 getClass() const
Definition: Unit.h:1413
Definition: Vehicle.h:82
#define sScriptMgr
Definition: ScriptMgr.h:837
Definition: DBCStructure.h:916
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::InstallAccessory ( uint32  entry,
int8  seatId,
bool  minion,
uint8  type,
uint32  summonTime 
)

Installs an accessory.

Author
Machiavelli
Date
17-2-2013
Parameters
entryThe NPC entry of accessory.
seatIdIdentifier for the seat to add the accessory to.
miniontrue if accessory considered a 'minion'. Implies that the accessory will despawn when the vehicle despawns. Essentially that it has no life without the vehicle. Their fates are bound.
typeSee enum .
summonTimeTime after which the minion is despawned in case of a timed despawn specified.

adding accessories when vehicle is uninstalling. (Bad script in OnUninstall/OnRemovePassenger/PassengerBoarded hook.)

If for some reason adding accessory to vehicle fails it will unsummon in ::Abort

356 {
359  {
360  TC_LOG_ERROR("entities.vehicle", "Vehicle (%s, Entry: %u) attempts to install accessory (Entry: %u) on seat %d with STATUS_UNINSTALLING! "
361  "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString().c_str(), GetCreatureEntry(), entry, (int32)seatId);
362  return;
363  }
364 
365  TC_LOG_DEBUG("entities.vehicle", "Vehicle (%s, Entry %u): installing accessory (Entry: %u) on seat: %d",
366  _me->GetGUID().ToString().c_str(), GetCreatureEntry(), entry, (int32)seatId);
367 
368  TempSummon* accessory = _me->SummonCreature(entry, *_me, TempSummonType(type), summonTime);
369  ASSERT(accessory);
370 
371  if (minion)
373 
374  (void)_me->HandleSpellClick(accessory, seatId);
375 
378 }
Definition: TemporarySummon.h:40
Definition: Unit.h:867
Definition: Vehicle.h:83
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
TempSummonType
Definition: Object.h:52
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
void AddUnitTypeMask(uint32 mask)
Definition: Unit.h:1400
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
ObjectGuid const & GetGUID() const
Definition: Object.h:105
int32_t int32
Definition: g3dmath.h:167
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32 GetCreatureEntry() const
Definition: Vehicle.h:51
std::string ToString() const
Definition: ObjectGuid.cpp:99
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0) const
Definition: Object.cpp:2346
bool HandleSpellClick(Unit *clicker, int8 seatId=-1)
Definition: Unit.cpp:15173

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::InstallAllAccessories ( bool  evading)
89 {
90  if (GetBase()->GetTypeId() == TYPEID_PLAYER || !evading)
91  RemoveAllPassengers(); // We might have aura's saved in the DB with now invalid casters - remove
92 
93  VehicleAccessoryList const* accessories = sObjectMgr->GetVehicleAccessoryList(this);
94  if (!accessories)
95  return;
96 
97  for (VehicleAccessoryList::const_iterator itr = accessories->begin(); itr != accessories->end(); ++itr)
98  if (!evading || itr->IsMinion) // only install minions on evade mode
99  InstallAccessory(itr->AccessoryEntry, itr->SeatId, itr->IsMinion, itr->SummonedType, itr->SummonTime);
100 }
std::vector< VehicleAccessory > VehicleAccessoryList
Definition: VehicleDefines.h:114
#define sObjectMgr
Definition: ObjectMgr.h:1567
void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
Installs an accessory.
Definition: Vehicle.cpp:355
Definition: ObjectGuid.h:33
void RemoveAllPassengers()
Removes all current and pending passengers from the vehicle.
Definition: Vehicle.cpp:222
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Vehicle::IsVehicleInUse ( ) const

Returns information whether the vehicle is currently used by any unit.

Author
Shauren
Date
26-2-2013
Returns
true if any passenger is boarded on vehicle, false otherwise.
552 {
553  for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
554  if (!itr->second.IsEmpty())
555  return true;
556 
557  return false;
558 }
Seats
Definition: boss_grand_champions.cpp:78

+ Here is the caller graph for this function:

void Vehicle::RelocatePassengers ( )

Relocate passengers. Must be called after m_base::Relocate.

Author
Machiavelli
Date
17-2-2013
521 {
522  ASSERT(_me->GetMap());
523 
524  // not sure that absolute position calculation is correct, it must depend on vehicle pitch angle
525  for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
526  {
527  if (Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), itr->second.Passenger.Guid))
528  {
529  ASSERT(passenger->IsInWorld());
530 
531  float px, py, pz, po;
532  passenger->m_movementInfo.transport.pos.GetPosition(px, py, pz, po);
533  CalculatePassengerPosition(px, py, pz, &po);
534 
535  passenger->UpdatePosition(px, py, pz, po);
536  }
537  }
538 }
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
Map * GetMap() const
Definition: Object.h:543
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
Seats
Definition: boss_grand_champions.cpp:78
#define ASSERT
Definition: Errors.h:55
Definition: Unit.h:1305
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::RemoveAllPassengers ( )

Removes all current and pending passengers from the vehicle.

Author
Machiavelli
Date
17-2-2013

Setting to_Abort to true will cause ::Abort to be executed on next ::UpdateEvents call This will properly "reset" the pending join process for the passenger.

Update vehicle pointer in every pending join event - Abort may be called after vehicle is deleted

223 {
224  TC_LOG_DEBUG("entities.vehicle", "Vehicle::RemoveAllPassengers. Entry: %u, %s", _creatureEntry, _me->GetGUID().ToString().c_str());
225 
228  {
230  Vehicle* eventVehicle = _status != STATUS_UNINSTALLING ? this : NULL;
231 
232  while (!_pendingJoinEvents.empty())
233  {
235  e->to_Abort = true;
236  e->Target = eventVehicle;
237  _pendingJoinEvents.pop_front();
238  }
239  }
240 
241  // Passengers always cast an aura with SPELL_AURA_CONTROL_VEHICLE on the vehicle
242  // We just remove the aura and the unapply handler will make the target leave the vehicle.
243  // We don't need to iterate over Seats
245 
246  // Following the above logic, this assertion should NEVER fail.
247  // Even in 'hacky' cases, there should at least be VEHICLE_SPELL_RIDE_HARDCODED on us.
248  // SeatMap::const_iterator itr;
249  // for (itr = Seats.begin(); itr != Seats.end(); ++itr)
250  // ASSERT(!itr->second.passenger);
251 }
bool to_Abort
Definition: EventProcessor.h:48
Definition: Vehicle.h:32
Definition: Vehicle.h:83
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: SpellAuraDefines.h:296
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: Vehicle.h:121
Vehicle * Target
Definition: Vehicle.h:130
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check)
Definition: Unit.cpp:3567
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:113
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vehicle * Vehicle::RemovePassenger ( Unit unit)

Removes the passenger from the vehicle.

Author
Machiavelli
Date
17-2-2013
Parameters
[in,out]unitThe passenger to remove.
467 {
468  if (unit->GetVehicle() != this)
469  return NULL;
470 
471  SeatMap::iterator seat = GetSeatIteratorForPassenger(unit);
472  ASSERT(seat != Seats.end());
473 
474  TC_LOG_DEBUG("entities.vehicle", "Unit %s exit vehicle entry %u id %u %s seat %d",
475  unit->GetName().c_str(), _me->GetEntry(), _vehicleInfo->ID, _me->GetGUID().ToString().c_str(), (int32)seat->first);
476 
477  if (seat->second.SeatInfo->CanEnterOrExit() && ++UsableSeatNum)
479 
480  // Remove UNIT_FLAG_NOT_SELECTABLE if passenger did not have it before entering vehicle
481  if (seat->second.SeatInfo->Flags & VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE && !seat->second.Passenger.IsUnselectable)
483 
484  seat->second.Passenger.Reset();
485 
486  if (_me->GetTypeId() == TYPEID_UNIT && unit->GetTypeId() == TYPEID_PLAYER && seat->second.SeatInfo->Flags & VEHICLE_SEAT_FLAG_CAN_CONTROL)
487  _me->RemoveCharmedBy(unit);
488 
489  if (_me->IsInWorld())
490  {
491  if (!_me->GetTransport())
493  else
495  }
496 
497  // only for flyable vehicles
498  if (unit->IsFlying())
499  _me->CastSpell(unit, VEHICLE_SPELL_PARACHUTE, true);
500 
502  _me->ToCreature()->AI()->PassengerBoarded(unit, seat->first, false);
503 
504  if (GetBase()->GetTypeId() == TYPEID_UNIT)
505  sScriptMgr->OnRemovePassenger(this, unit);
506 
507  unit->SetVehicle(NULL);
508  return this;
509 }
virtual void PassengerBoarded(Unit *, int8, bool)
== Fields =======================================
Definition: CreatureAI.h:183
bool IsFlying() const
Definition: Unit.h:2189
Definition: Unit.h:759
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags...
Definition: Vehicle.h:76
MovementInfo m_movementInfo
Definition: Object.h:612
std::string const & GetName() const
Definition: Object.h:479
Definition: ObjectGuid.h:32
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
bool IsAIEnabled
Definition: Unit.h:2161
struct MovementInfo::TransportInfo transport
TypeID GetTypeId() const
Definition: Object.h:113
void SetVehicle(Vehicle *vehicle)
Definition: Unit.h:2167
uint32 ID
Definition: DBCStructure.h:1273
Definition: Unit.h:760
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Seats
Definition: boss_grand_champions.cpp:78
Definition: DBCEnums.h:718
CreatureAI * AI() const
Definition: Creature.h:525
void SetFlag64(uint16 index, uint64 newFlag)
Definition: Object.cpp:1305
void ResetTransport()
Definition: Object.h:341
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition: Object.cpp:1214
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Transport * GetTransport() const
Definition: Object.h:602
Definition: ObjectGuid.h:33
Vehicle * GetVehicle() const
Definition: Unit.h:2166
Definition: VehicleDefines.h:75
Definition: UpdateFields.h:109
Creature * ToCreature()
Definition: Object.h:194
void RemoveCharmedBy(Unit *charmer)
Definition: Unit.cpp:14172
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:110
int32_t int32
Definition: g3dmath.h:167
#define ASSERT
Definition: Errors.h:55
Definition: UpdateFields.h:135
#define sScriptMgr
Definition: ScriptMgr.h:837
uint32 GetEntry() const
Definition: Object.h:107
bool IsInWorld() const
Definition: Object.h:100
void CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=NULL, AuraEffect const *triggeredByAura=NULL, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:869
Definition: Unit.h:698
std::string ToString() const
Definition: ObjectGuid.cpp:99
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49
SeatMap::iterator GetSeatIteratorForPassenger(Unit *passenger)
Gets seat iterator for specified passenger.
Definition: Vehicle.cpp:620

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::RemovePendingEvent ( VehicleJoinEvent e)
private

Removes objects from pending join event store. This method only removes it after it's executed or aborted to prevent leaving pointers to deleted events.

Author
Shauren
Date
22-2-2013
Parameters
[in]eThe VehicleJoinEvent* to remove from pending event store.
666 {
667  for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end(); ++itr)
668  {
669  if (*itr == e)
670  {
671  _pendingJoinEvents.erase(itr);
672  break;
673  }
674  }
675 }
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118

+ Here is the caller graph for this function:

void Vehicle::RemovePendingEventsForPassenger ( Unit passenger)
714 {
715  for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end();)
716  {
717  if ((*itr)->Passenger == passenger)
718  {
719  (*itr)->to_Abort = true;
720  _pendingJoinEvents.erase(itr++);
721  }
722  else
723  ++itr;
724  }
725 }
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118

+ Here is the caller graph for this function:

void Vehicle::RemovePendingEventsForSeat ( int8  seatId)
private

Removes any pending events for given seatId. Executed when a ::Execute is called.

Removes any pending events for given passenger. Executed when vehicle control aura is removed while adding passenger is in progress.

Author
Machiavelli
Date
23-2-2013
Parameters
seatIdIdentifier for the seat.
Author
Shauren
Date
13-2-2013
Parameters
passengerUnit that is supposed to enter the vehicle.
689 {
690  for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end();)
691  {
692  if ((*itr)->Seat->first == seatId)
693  {
694  (*itr)->to_Abort = true;
695  _pendingJoinEvents.erase(itr++);
696  }
697  else
698  ++itr;
699  }
700 }
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:118

+ Here is the caller graph for this function:

void Vehicle::Reset ( bool  evading = false)

Reapplies immunities and reinstalls accessories. Only has effect for creatures.

Author
Machiavelli
Date
17-2-2013
Parameters
evadingtrue if called from CreatureAI::EnterEvadeMode
142 {
143  if (GetBase()->GetTypeId() != TYPEID_UNIT)
144  return;
145 
146  TC_LOG_DEBUG("entities.vehicle", "Vehicle::Reset (Entry: %u, %s, DBGuid: " UI64FMTD ")", GetCreatureEntry(), _me->GetGUID().ToString().c_str(), _me->ToCreature()->GetSpawnId());
147 
149  InstallAllAccessories(evading);
150 
151  sScriptMgr->OnReset(this);
152 }
Definition: ObjectGuid.h:32
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void InstallAllAccessories(bool evading)
Definition: Vehicle.cpp:88
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
#define UI64FMTD
Definition: Define.h:137
void ApplyAllImmunities()
Applies specific immunities that cannot be set in DB.
Definition: Vehicle.cpp:163
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Creature * ToCreature()
Definition: Object.h:194
#define sScriptMgr
Definition: ScriptMgr.h:837
uint32 GetCreatureEntry() const
Definition: Vehicle.h:51
std::string ToString() const
Definition: ObjectGuid.cpp:99
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Vehicle::SetLastShootPos ( Position const pos)
inline
65 { _lastShootPos.Relocate(pos); }
Position _lastShootPos
Definition: Vehicle.h:115
void Relocate(float x, float y)
Definition: Position.h:67
void Vehicle::Uninstall ( )

Removes all passengers and sets status to STATUS_UNINSTALLING. No new passengers can be added to the vehicle after this call.

Author
Machiavelli
Date
17-2-2013

recursive uninstall call. (Bad script in OnUninstall/OnRemovePassenger/PassengerBoarded hook.)

113 {
115  if (_status == STATUS_UNINSTALLING && !GetBase()->HasUnitTypeMask(UNIT_MASK_MINION))
116  {
117  TC_LOG_ERROR("entities.vehicle", "%s, Entry: %u attempts to uninstall, but already has STATUS_UNINSTALLING! "
118  "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString().c_str(), _creatureEntry);
119  return;
120  }
121 
123  TC_LOG_DEBUG("entities.vehicle", "Vehicle::Uninstall Entry: %u, %s", _creatureEntry, _me->GetGUID().ToString().c_str());
125 
126  if (GetBase()->GetTypeId() == TYPEID_UNIT)
127  sScriptMgr->OnUninstall(this);
128 }
Definition: Vehicle.h:83
Definition: ObjectGuid.h:32
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Unit.h:859
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:109
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:114
ObjectGuid const & GetGUID() const
Definition: Object.h:105
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:113
#define sScriptMgr
Definition: ScriptMgr.h:837
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
void RemoveAllPassengers()
Removes all current and pending passengers from the vehicle.
Definition: Vehicle.cpp:222
std::string ToString() const
Definition: ObjectGuid.cpp:99
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

bool Unit::CreateVehicleKit ( uint32  id,
uint32  creatureEntry,
bool   
)
friend
void Unit::RemoveVehicleKit ( bool  )
friend
friend class VehicleJoinEvent
friend

Member Data Documentation

uint32 Vehicle::_creatureEntry
private

Can be different than the entry of _me in case of players.

Position Vehicle::_lastShootPos
private
Unit* Vehicle::_me
private

The underlying unit with the vehicle kit. Can be player or creature.

PendingJoinEventContainer Vehicle::_pendingJoinEvents
private

Collection of delayed join events for prospective passengers.

Status Vehicle::_status
private

Internal variable for sanity checks.

VehicleEntry const* Vehicle::_vehicleInfo
private

DBC data for vehicle.

SeatMap Vehicle::Seats

The collection of all seats on the vehicle. Including vacant ones.

uint32 Vehicle::UsableSeatNum
protected

Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags.

GuidSet Vehicle::vehiclePlayers
private

The documentation for this class was generated from the following files: