TrinityCore
Loading...
Searching...
No Matches
Vehicle Class Reference

#include <Vehicle.h>

Public Member Functions

 Vehicle (Unit *unit, VehicleEntry const *vehInfo, uint32 creatureEntry)
 
 ~Vehicle ()
 
 Vehicle (Vehicle const &right)=delete
 
 Vehicle (Vehicle &&right)=delete
 
Vehicleoperator= (Vehicle const &right)=delete
 
Vehicleoperator= (Vehicle &&right)=delete
 
void Install ()
 Initializes power type for vehicle. Nothing more.
 
void Uninstall ()
 Removes all passengers and sets status to STATUS_UNINSTALLING. No new passengers can be added to the vehicle after this call.
 
void Reset (bool evading=false)
 Reapplies immunities and reinstalls accessories. Only has effect for creatures.
 
void InstallAllAccessories (bool evading)
 
void ApplyAllImmunities ()
 Applies specific immunities that cannot be set in DB.
 
void InstallAccessory (uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
 Installs an accessory.
 
UnitGetBase () const
 
VehicleEntry const * GetVehicleInfo () const
 
uint32 GetCreatureEntry () const
 
bool HasEmptySeat (int8 seatId) const
 Checks if vehicle's seat specified by 'seatId' is empty.
 
UnitGetPassenger (int8 seatId) const
 Gets a passenger on specified seat.
 
SeatMap::const_iterator GetNextEmptySeat (int8 seatId, bool next) const
 Gets the next empty seat based on current seat.
 
VehicleSeatAddon const * GetSeatAddonForSeatOfPassenger (Unit const *passenger) const
 Gets the vehicle seat addon data for the seat of a passenger.
 
uint8 GetAvailableSeatCount () const
 Gets the available seat count.
 
bool AddVehiclePassenger (Unit *unit, int8 seatId=-1)
 
VehicleRemovePassenger (WorldObject *passenger) override
 Removes the passenger from the vehicle.
 
void RelocatePassengers ()
 Relocate passengers. Must be called after m_base::Relocate.
 
void RemoveAllPassengers ()
 Removes all current and pending passengers from the vehicle.
 
bool IsVehicleInUse () const
 Returns information whether the vehicle is currently used by any unit.
 
bool IsControllableVehicle () const
 
SeatMap::iterator GetSeatIteratorForPassenger (Unit *passenger)
 Gets seat iterator for specified passenger.
 
VehicleSeatEntry const * GetSeatForPassenger (Unit const *passenger) const
 Returns information on the seat of specified passenger, represented by the format in VehicleSeat.dbc.
 
void RemovePendingEventsForPassenger (Unit *passenger)
 
Milliseconds GetDespawnDelay ()
 
std::string GetDebugInfo () const
 
- Public Member Functions inherited from TransportBase
virtual ObjectGuid GetTransportGUID () const =0
 
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.
 
virtual float GetTransportOrientation () const =0
 
virtual void AddPassenger (WorldObject *passenger)=0
 
virtual TransportBaseRemovePassenger (WorldObject *passenger)=0
 
void UpdatePassengerPosition (Map *map, WorldObject *passenger, float x, float y, float z, float o, bool setHomePosition)
 
virtual int32 GetMapIdForSpawning () const =0
 

Public Attributes

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

Protected Attributes

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

Private Types

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

Private Member Functions

void InitMovementInfoForBase ()
 Sets correct MovementFlags2 based on VehicleFlags from DBC.
 
ObjectGuid GetTransportGUID () const override
 
float GetTransportOrientation () const override
 
void AddPassenger (WorldObject *) override
 Attempts to add a passenger to the vehicle on 'seatId'.
 
void CalculatePassengerPosition (float &x, float &y, float &z, float *o) const override
 This method transforms supplied transport offsets into global coordinates.
 
void CalculatePassengerOffset (float &x, float &y, float &z, float *o) const override
 This method transforms supplied global coordinates into local offsets.
 
int32 GetMapIdForSpawning () const override
 
void RemovePendingEvent (VehicleJoinEvent *e)
 Removes @VehicleJoinEvent objects from pending join event store. This method only removes it after it's executed or aborted to prevent leaving pointers to deleted events.
 
void RemovePendingEventsForSeat (int8 seatId)
 Removes any pending events for given seatId. Executed when a @VehicleJoinEvent::Execute is called.
 
bool HasPendingEventForSeat (int8 seatId) const
 

Private Attributes

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.
 
PendingJoinEventContainer _pendingJoinEvents
 Collection of delayed join events for prospective passengers.
 

Friends

class VehicleJoinEvent
 

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)
 
- Protected Member Functions inherited from TransportBase
 TransportBase ()
 
virtual ~TransportBase ()
 

Detailed Description

Definition at line 30 of file Vehicle.h.

Member Typedef Documentation

◆ PendingJoinEventContainer

Definition at line 127 of file Vehicle.h.

Member Enumeration Documentation

◆ Status

enum Vehicle::Status
private
Enumerator
STATUS_NONE 
STATUS_INSTALLED 
STATUS_UNINSTALLING 

Definition at line 81 of file Vehicle.h.

82 {
86 };
@ STATUS_INSTALLED
Definition: Vehicle.h:84
@ STATUS_UNINSTALLING
Definition: Vehicle.h:85
@ STATUS_NONE
Definition: Vehicle.h:83

Constructor & Destructor Documentation

◆ Vehicle() [1/3]

Vehicle::Vehicle ( Unit unit,
VehicleEntry const *  vehInfo,
uint32  creatureEntry 
)

Definition at line 36 of file Vehicle.cpp.

36 :
37UsableSeatNum(0), _me(unit), _vehicleInfo(vehInfo), _creatureEntry(creatureEntry), _status(STATUS_NONE)
38{
39 for (int8 i = 0; i < MAX_VEHICLE_SEATS; ++i)
40 {
41 if (uint32 seatId = _vehicleInfo->SeatID[i])
42 if (VehicleSeatEntry const* veSeat = sVehicleSeatStore.LookupEntry(seatId))
43 {
44 VehicleSeatAddon const* addon = sObjectMgr->GetVehicleSeatAddon(seatId);
45 Seats.insert(std::make_pair(i, VehicleSeat(veSeat, addon)));
46 if (veSeat->CanEnterOrExit())
48 }
49 }
50
51 // Set or remove correct flags based on available seats. Will overwrite db data (if wrong).
52 if (UsableSeatNum)
54 else
56
58}
DB2Storage< VehicleSeatEntry > sVehicleSeatStore("VehicleSeat.db2", &VehicleSeatLoadInfo::Instance)
#define MAX_VEHICLE_SEATS
int8_t int8
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:143
@ TYPEID_PLAYER
Definition: ObjectGuid.h:41
#define sObjectMgr
Definition: ObjectMgr.h:1952
@ UNIT_NPC_FLAG_SPELLCLICK
Definition: UnitDefines.h:316
@ UNIT_NPC_FLAG_PLAYER_VEHICLE
Definition: UnitDefines.h:317
TypeID GetTypeId() const
Definition: Object.h:172
void RemoveNpcFlag(NPCFlags flags)
Definition: Unit.h:1102
void SetNpcFlag(NPCFlags flags)
Definition: Unit.h:1101
void InitMovementInfoForBase()
Sets correct MovementFlags2 based on VehicleFlags from DBC.
Definition: Vehicle.cpp:617
uint32 UsableSeatNum
Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags.
Definition: Vehicle.h:78
uint32 _creatureEntry
Can be different than the entry of _me in case of players.
Definition: Vehicle.h:124
Status _status
Internal variable for sanity checks.
Definition: Vehicle.h:125
Unit * _me
The underlying unit with the vehicle kit. Can be player or creature.
Definition: Vehicle.h:120
VehicleEntry const * _vehicleInfo
DBC data for vehicle.
Definition: Vehicle.h:121
std::array< uint16, 8 > SeatID
+ Here is the call graph for this function:

◆ ~Vehicle()

Vehicle::~Vehicle ( )

@Uninstall must be called before this.

Definition at line 60 of file Vehicle.cpp.

61{
64 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
65 ASSERT(itr->second.IsEmpty());
66}
#define ASSERT
Definition: Errors.h:68

◆ Vehicle() [2/3]

Vehicle::Vehicle ( Vehicle const &  right)
delete

◆ Vehicle() [3/3]

Vehicle::Vehicle ( Vehicle &&  right)
delete

Member Function Documentation

◆ AddPassenger()

bool Vehicle::AddPassenger ( WorldObject )
inlineoverrideprivatevirtual

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

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

Implements TransportBase.

Definition at line 94 of file Vehicle.h.

94{ ABORT_MSG("Vehicle cannot directly gain passengers without auras"); }
#define ABORT_MSG
Definition: Errors.h:75

◆ AddVehiclePassenger()

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

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

Definition at line 420 of file Vehicle.cpp.

421{
424 {
425 TC_LOG_ERROR("entities.vehicle", "Passenger {}, attempting to board vehicle {} during uninstall! SeatId: {}",
426 unit->GetGUID().ToString(), _me->GetGUID().ToString(), (int32)seatId);
427 return false;
428 }
429
430 TC_LOG_DEBUG("entities.vehicle", "Unit {} scheduling enter vehicle (entry: {}, vehicleId: {}, guid: {} on seat {}",
431 unit->GetName(), _me->GetEntry(), _vehicleInfo->ID, _me->GetGUID().ToString(), (int32)seatId);
432
433 // The seat selection code may kick other passengers off the vehicle.
434 // While the validity of the following may be arguable, it is possible that when such a passenger
435 // exits the vehicle will dismiss. That's why the actual adding the passenger to the vehicle is scheduled
436 // asynchronously, so it can be cancelled easily in case the vehicle is uninstalled meanwhile.
437 SeatMap::iterator seat;
438 VehicleJoinEvent* e = new VehicleJoinEvent(this, unit);
439 unit->m_Events.AddEvent(e, unit->m_Events.CalculateTime(0s));
440
441 if (seatId < 0) // no specific seat requirement
442 {
443 for (seat = Seats.begin(); seat != Seats.end(); ++seat)
444 if (seat->second.IsEmpty() && !HasPendingEventForSeat(seat->first) && (seat->second.SeatInfo->CanEnterOrExit() || seat->second.SeatInfo->IsUsableByOverride()))
445 break;
446
447 if (seat == Seats.end()) // no available seat
448 {
449 e->ScheduleAbort();
450 return false;
451 }
452
453 e->Seat = seat;
454 _pendingJoinEvents.push_back(e);
455 }
456 else
457 {
458 seat = Seats.find(seatId);
459 if (seat == Seats.end())
460 {
461 e->ScheduleAbort();
462 return false;
463 }
464
465 e->Seat = seat;
466 _pendingJoinEvents.push_back(e);
467 if (!seat->second.IsEmpty())
468 {
469 Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), seat->second.Passenger.Guid);
470 ASSERT(passenger);
471 passenger->ExitVehicle();
472 }
473
474 ASSERT(seat->second.IsEmpty());
475 }
476
477 return true;
478}
int32_t int32
Definition: Define.h:139
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
void ScheduleAbort()
void AddEvent(BasicEvent *event, Milliseconds e_time, bool set_addtime=true)
Milliseconds CalculateTime(Milliseconds t_offset) const
std::string ToString() const
Definition: ObjectGuid.cpp:554
uint32 GetEntry() const
Definition: Object.h:160
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:158
Definition: Unit.h:747
virtual void ExitVehicle(Position const *exitPosition=nullptr)
Definition: Unit.cpp:12277
SeatMap::iterator Seat
Definition: Vehicle.h:141
Unit * GetBase() const
Definition: Vehicle.h:48
PendingJoinEventContainer _pendingJoinEvents
Collection of delayed join events for prospective passengers.
Definition: Vehicle.h:128
bool HasPendingEventForSeat(int8 seatId) const
Definition: Vehicle.cpp:949
friend class VehicleJoinEvent
Definition: Vehicle.h:77
std::string const & GetName() const
Definition: Object.h:535
EventProcessor m_Events
Definition: Object.h:755
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ApplyAllImmunities()

void Vehicle::ApplyAllImmunities ( )

Applies specific immunities that cannot be set in DB.

Author
Machiavelli
Date
17-2-2013

Definition at line 160 of file Vehicle.cpp.

161{
162 // This couldn't be done in DB, because some spells have MECHANIC_NONE
163
164 // Vehicles should be immune on Knockback ...
167
168 // Mechanical units & vehicles ( which are not Bosses, they have own immunities in DB ) should be also immune on healing ( exceptions in switch below )
170 {
171 // Heal & dispel ...
176
177 // ... Shield & Immunity grant spells ...
184
185 // ... Resistance, Split damage, Change stats ...
191 }
192
193 // Different immunities for vehicles goes below
194 switch (GetVehicleInfo()->ID)
195 {
196 // code below prevents a bug with movable cannons
197 case 160: // Strand of the Ancients
198 case 244: // Wintergrasp
199 case 510: // Isle of Conquest
200 case 452: // Isle of Conquest
201 case 543: // Isle of Conquest
203 // why we need to apply this? we can simple add immunities to slow mechanic in DB
205 break;
206 case 335: // Salvaged Chopper
207 case 336: // Salvaged Siege Engine
208 case 338: // Salvaged Demolisher
210 break;
211 default:
212 break;
213 }
214}
@ CREATURE_TYPE_MECHANICAL
@ SPELL_EFFECT_HEAL
@ SPELL_EFFECT_DISPEL
@ SPELL_EFFECT_KNOCK_BACK_DEST
@ SPELL_EFFECT_KNOCK_BACK
@ SPELL_EFFECT_HEAL_PCT
@ MECHANIC_BANISH
@ MECHANIC_IMMUNE_SHIELD
@ MECHANIC_SHIELD
@ IMMUNITY_STATE
@ IMMUNITY_EFFECT
@ IMMUNITY_MECHANIC
@ SPELL_AURA_DAMAGE_SHIELD
@ SPELL_AURA_MOD_RESISTANCE
@ SPELL_AURA_PERIODIC_HEAL
@ SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
@ SPELL_AURA_SPLIT_DAMAGE_PCT
@ SPELL_AURA_MOD_STAT
@ SPELL_AURA_SCHOOL_IMMUNITY
@ SPELL_AURA_MOD_DECREASE_SPEED
@ SPELL_AURA_SCHOOL_ABSORB
@ SPELL_AURA_MOD_UNATTACKABLE
@ UNIT_STATE_ROOT
Definition: Unit.h:262
bool isWorldBoss() const
Definition: Creature.cpp:2445
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:217
static Creature * ToCreature(Object *o)
Definition: Object.h:206
void SetControlled(bool apply, UnitState state)
Definition: Unit.cpp:10965
void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply)
Definition: Unit.cpp:7703
VehicleEntry const * GetVehicleInfo() const
Definition: Vehicle.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalculatePassengerOffset()

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

This method transforms supplied global coordinates into local offsets.

Implements TransportBase.

Definition at line 105 of file Vehicle.h.

106 {
108 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
109 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
110 }
virtual void CalculatePassengerOffset(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied global coordinates into local offsets.
+ Here is the call graph for this function:

◆ CalculatePassengerPosition()

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

This method transforms supplied transport offsets into global coordinates.

Implements TransportBase.

Definition at line 97 of file Vehicle.h.

98 {
100 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
101 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
102 }
virtual void CalculatePassengerPosition(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied transport offsets into global coordinates.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAvailableSeatCount()

uint8 Vehicle::GetAvailableSeatCount ( ) const

Gets the available seat count.

Author
Machiavelli
Date
17-2-2013
Returns
The available seat count.

Definition at line 689 of file Vehicle.cpp.

690{
691 uint8 ret = 0;
692 SeatMap::const_iterator itr;
693 for (itr = Seats.begin(); itr != Seats.end(); ++itr)
694 if (itr->second.IsEmpty() && !HasPendingEventForSeat(itr->first) && (itr->second.SeatInfo->CanEnterOrExit() || itr->second.SeatInfo->IsUsableByOverride()))
695 ++ret;
696
697 return ret;
698}
uint8_t uint8
Definition: Define.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBase()

Unit * Vehicle::GetBase ( ) const
inline

Definition at line 48 of file Vehicle.h.

48{ return _me; }
+ Here is the caller graph for this function:

◆ GetCreatureEntry()

uint32 Vehicle::GetCreatureEntry ( ) const
inline

Definition at line 50 of file Vehicle.h.

50{ return _creatureEntry; }
+ Here is the caller graph for this function:

◆ GetDebugInfo()

std::string Vehicle::GetDebugInfo ( ) const

Definition at line 967 of file Vehicle.cpp.

968{
969 std::stringstream sstr;
970 sstr << "Vehicle seats:\n";
971 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); itr++)
972 {
973 sstr << "seat " << std::to_string(itr->first) << ": " << (itr->second.IsEmpty() ? "empty" : itr->second.Passenger.Guid.ToString()) << "\n";
974 }
975
976 sstr << "Vehicle pending events:";
977
978 if (_pendingJoinEvents.empty())
979 {
980 sstr << " none";
981 }
982 else
983 {
984 sstr << "\n";
985 for (PendingJoinEventContainer::const_iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end(); ++itr)
986 {
987 sstr << "seat " << std::to_string((*itr)->Seat->first) << ": " << (*itr)->Passenger->GetGUID().ToString() << "\n";
988 }
989 }
990
991 return sstr.str();
992}
+ Here is the caller graph for this function:

◆ GetDespawnDelay()

Milliseconds Vehicle::GetDespawnDelay ( )

Definition at line 959 of file Vehicle.cpp.

960{
961 if (VehicleTemplate const* vehicleTemplate = sObjectMgr->GetVehicleTemplate(this))
962 return vehicleTemplate->DespawnDelay;
963
964 return 1ms;
965}
+ Here is the caller graph for this function:

◆ GetMapIdForSpawning()

int32 Vehicle::GetMapIdForSpawning ( ) const
inlineoverrideprivatevirtual

Implements TransportBase.

Definition at line 112 of file Vehicle.h.

112{ return GetBase()->GetMapId(); }
uint32 GetMapId() const
Definition: Position.h:185

◆ GetNextEmptySeat()

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.

Definition at line 313 of file Vehicle.cpp.

314{
315 SeatMap::const_iterator seat = Seats.find(seatId);
316 if (seat == Seats.end())
317 return seat;
318
319 while (!seat->second.IsEmpty() || HasPendingEventForSeat(seat->first) || (!seat->second.SeatInfo->CanEnterOrExit() && !seat->second.SeatInfo->IsUsableByOverride()))
320 {
321 if (next)
322 {
323 if (++seat == Seats.end())
324 seat = Seats.begin();
325 }
326 else
327 {
328 if (seat == Seats.begin())
329 seat = Seats.end();
330 --seat;
331 }
332
333 // Make sure we don't loop indefinetly
334 if (seat->first == seatId)
335 return Seats.end();
336 }
337
338 return seat;
339}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPassenger()

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

Definition at line 290 of file Vehicle.cpp.

291{
292 SeatMap::const_iterator seat = Seats.find(seatId);
293 if (seat == Seats.end())
294 return nullptr;
295
296 return ObjectAccessor::GetUnit(*GetBase(), seat->second.Passenger.Guid);
297}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSeatAddonForSeatOfPassenger()

VehicleSeatAddon const * Vehicle::GetSeatAddonForSeatOfPassenger ( Unit const *  passenger) const

Gets the vehicle seat addon data for the seat of a passenger.

Author
Ovahlord
Date
28-1-2020
Parameters
passengerIdentifier for the current seat user
Returns
The seat addon data for the currently used seat of a passenger

Definition at line 354 of file Vehicle.cpp.

355{
356 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); itr++)
357 if (!itr->second.IsEmpty() && itr->second.Passenger.Guid == passenger->GetGUID())
358 return itr->second.SeatAddon;
359
360 return nullptr;
361}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSeatForPassenger()

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.

Definition at line 646 of file Vehicle.cpp.

647{
648 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
649 if (itr->second.Passenger.Guid == passenger->GetGUID())
650 return itr->second.SeatInfo;
651
652 return nullptr;
653}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSeatIteratorForPassenger()

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

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).

Definition at line 668 of file Vehicle.cpp.

669{
670 SeatMap::iterator itr;
671 for (itr = Seats.begin(); itr != Seats.end(); ++itr)
672 if (itr->second.Passenger.Guid == passenger->GetGUID())
673 return itr;
674
675 return Seats.end();
676}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTransportGUID()

ObjectGuid Vehicle::GetTransportGUID ( ) const
inlineoverrideprivatevirtual

Implements TransportBase.

Definition at line 90 of file Vehicle.h.

90{ return GetBase()->GetGUID(); }

◆ GetTransportOrientation()

float Vehicle::GetTransportOrientation ( ) const
inlineoverrideprivatevirtual

Implements TransportBase.

Definition at line 92 of file Vehicle.h.

92{ return GetBase()->GetOrientation(); }
float GetOrientation() const
Definition: Position.h:79

◆ GetVehicleInfo()

VehicleEntry const * Vehicle::GetVehicleInfo ( ) const
inline

Definition at line 49 of file Vehicle.h.

49{ return _vehicleInfo; }
+ Here is the caller graph for this function:

◆ HasEmptySeat()

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.

Definition at line 269 of file Vehicle.cpp.

270{
271 SeatMap::const_iterator seat = Seats.find(seatId);
272 if (seat == Seats.end())
273 return false;
274 return seat->second.IsEmpty();
275}
+ Here is the caller graph for this function:

◆ HasPendingEventForSeat()

bool Vehicle::HasPendingEventForSeat ( int8  seatId) const
private

Definition at line 949 of file Vehicle.cpp.

950{
951 for (PendingJoinEventContainer::const_iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end(); ++itr)
952 {
953 if ((*itr)->Seat->first == seatId)
954 return true;
955 }
956 return false;
957}
+ Here is the caller graph for this function:

◆ InitMovementInfoForBase()

void Vehicle::InitMovementInfoForBase ( )
private

Sets correct MovementFlags2 based on VehicleFlags from DBC.

Author
Machiavelli
Date
17-2-2013

Definition at line 617 of file Vehicle.cpp.

618{
619 uint32 vehicleFlags = GetVehicleInfo()->Flags;
620
621 if (vehicleFlags & VEHICLE_FLAG_NO_STRAFE)
623 if (vehicleFlags & VEHICLE_FLAG_NO_JUMPING)
625 if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDTURNING)
627 if (vehicleFlags & VEHICLE_FLAG_ALLOW_PITCHING)
629 if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDPITCHING)
631}
@ MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING
Definition: UnitDefines.h:415
@ MOVEMENTFLAG2_NO_STRAFE
Definition: UnitDefines.h:411
@ MOVEMENTFLAG2_FULL_SPEED_PITCHING
Definition: UnitDefines.h:414
@ MOVEMENTFLAG2_FULL_SPEED_TURNING
Definition: UnitDefines.h:413
@ MOVEMENTFLAG2_NO_JUMPING
Definition: UnitDefines.h:412
@ VEHICLE_FLAG_NO_JUMPING
@ VEHICLE_FLAG_NO_STRAFE
@ VEHICLE_FLAG_FULLSPEEDTURNING
@ VEHICLE_FLAG_ALLOW_PITCHING
@ VEHICLE_FLAG_FULLSPEEDPITCHING
void AddExtraUnitMovementFlag(uint32 f)
Definition: Unit.h:1772
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Install()

void Vehicle::Install ( )

Initializes power type for vehicle. Nothing more.

Author
Machiavelli
Date
17-2-2013

Definition at line 77 of file Vehicle.cpp.

78{
80 if (GetBase()->GetTypeId() == TYPEID_UNIT)
81 sScriptMgr->OnInstall(this);
82}
@ TYPEID_UNIT
Definition: ObjectGuid.h:40
#define sScriptMgr
Definition: ScriptMgr.h:1418
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InstallAccessory()

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 @SummonType.
summonTimeTime after which the minion is despawned in case of a timed despawn @type specified.

@Prevent 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 @VehicleJoinEvent::Abort

Definition at line 380 of file Vehicle.cpp.

381{
384 {
385 TC_LOG_ERROR("entities.vehicle", "Vehicle ({}, Entry: {}) attempts to install accessory (Entry: {}) on seat {} with STATUS_UNINSTALLING! "
386 "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString(),
387 GetCreatureEntry(), entry, (int32)seatId);
388 return;
389 }
390
391 TC_LOG_DEBUG("entities.vehicle", "Vehicle ({}, Entry {}): installing accessory (Entry: {}) on seat: {}",
392 _me->GetGUID().ToString(), GetCreatureEntry(), entry, (int32)seatId);
393
394 TempSummon* accessory = _me->SummonCreature(entry, *_me, TempSummonType(type), Milliseconds(summonTime));
395 ASSERT(accessory);
396
397 if (minion)
399
400 _me->HandleSpellClick(accessory, seatId);
401
404}
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
TempSummonType
Definition: ObjectDefines.h:62
@ UNIT_MASK_ACCESSORY
Definition: Unit.h:356
void HandleSpellClick(Unit *clicker, int8 seatId=-1)
Definition: Unit.cpp:12100
void AddUnitTypeMask(uint32 mask)
Definition: Unit.h:857
uint32 GetCreatureEntry() const
Definition: Vehicle.h:50
TempSummon * SummonCreature(uint32 entry, Position const &pos, TempSummonType despawnType=TEMPSUMMON_MANUAL_DESPAWN, Milliseconds despawnTime=0s, uint32 vehId=0, uint32 spellId=0, ObjectGuid privateObjectOwner=ObjectGuid::Empty)
Definition: Object.cpp:2012
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InstallAllAccessories()

void Vehicle::InstallAllAccessories ( bool  evading)

Definition at line 84 of file Vehicle.cpp.

85{
86 if (GetBase()->GetTypeId() == TYPEID_PLAYER || !evading)
87 RemoveAllPassengers(); // We might have aura's saved in the DB with now invalid casters - remove
88
89 VehicleAccessoryList const* accessories = sObjectMgr->GetVehicleAccessoryList(this);
90 if (!accessories)
91 return;
92
93 for (VehicleAccessoryList::const_iterator itr = accessories->begin(); itr != accessories->end(); ++itr)
94 if (!evading || itr->IsMinion) // only install minions on evade mode
95 InstallAccessory(itr->AccessoryEntry, itr->SeatId, itr->IsMinion, itr->SummonedType, itr->SummonTime);
96}
std::vector< VehicleAccessory > VehicleAccessoryList
void RemoveAllPassengers()
Removes all current and pending passengers from the vehicle.
Definition: Vehicle.cpp:225
void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
Installs an accessory.
Definition: Vehicle.cpp:380
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsControllableVehicle()

bool Vehicle::IsControllableVehicle ( ) const

Definition at line 599 of file Vehicle.cpp.

600{
601 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
602 if (itr->second.SeatInfo->HasFlag(VEHICLE_SEAT_FLAG_CAN_CONTROL))
603 return true;
604
605 return false;
606}
@ VEHICLE_SEAT_FLAG_CAN_CONTROL
Definition: DBCEnums.h:2343
+ Here is the caller graph for this function:

◆ IsVehicleInUse()

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.

Definition at line 590 of file Vehicle.cpp.

591{
592 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
593 if (!itr->second.IsEmpty())
594 return true;
595
596 return false;
597}
+ Here is the caller graph for this function:

◆ operator=() [1/2]

Vehicle & Vehicle::operator= ( Vehicle &&  right)
delete

◆ operator=() [2/2]

Vehicle & Vehicle::operator= ( Vehicle const &  right)
delete

◆ RelocatePassengers()

void Vehicle::RelocatePassengers ( )

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

Author
Machiavelli
Date
17-2-2013

Definition at line 553 of file Vehicle.cpp.

554{
555 ASSERT(_me->GetMap());
556
557 std::vector<std::pair<Unit*, Position>> seatRelocation;
558 seatRelocation.reserve(Seats.size());
559
560 // not sure that absolute position calculation is correct, it must depend on vehicle pitch angle
561 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
562 {
563 if (Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), itr->second.Passenger.Guid))
564 {
565 ASSERT(passenger->IsInWorld());
566
567 float px, py, pz, po;
568 passenger->m_movementInfo.transport.pos.GetPosition(px, py, pz, po);
569 CalculatePassengerPosition(px, py, pz, &po);
570
571 seatRelocation.emplace_back(passenger, Position(px, py, pz, po));
572 }
573 }
574
575 for (auto const& [passenger, position] : seatRelocation)
576 UpdatePassengerPosition(_me->GetMap(), passenger, position.GetPositionX(), position.GetPositionY(), position.GetPositionZ(), position.GetOrientation(), false);
577}
void UpdatePassengerPosition(Map *map, WorldObject *passenger, float x, float y, float z, float o, bool setHomePosition)
Definition: Transport.cpp:39
void CalculatePassengerPosition(float &x, float &y, float &z, float *o) const override
This method transforms supplied transport offsets into global coordinates.
Definition: Vehicle.h:97
Map * GetMap() const
Definition: Object.h:603
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveAllPassengers()

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 @VehicleJoinEvent::Abort to be executed on next @Unit::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

Definition at line 225 of file Vehicle.cpp.

226{
227 TC_LOG_DEBUG("entities.vehicle", "Vehicle::RemoveAllPassengers. Entry: {}, {}", _creatureEntry, _me->GetGUID().ToString());
228
231 {
233 Vehicle* eventVehicle = _status != STATUS_UNINSTALLING ? this : nullptr;
234
235 while (!_pendingJoinEvents.empty())
236 {
238 e->ScheduleAbort();
239 e->Target = eventVehicle;
240 _pendingJoinEvents.pop_front();
241 }
242 }
243
244 // Passengers always cast an aura with SPELL_AURA_CONTROL_VEHICLE on the vehicle
245 // We just remove the aura and the unapply handler will make the target leave the vehicle.
246 // We don't need to iterate over Seats
248
249 // Aura script might cause the vehicle to be despawned in the middle of handling SPELL_AURA_CONTROL_VEHICLE removal
250 // In that case, aura effect has already been unregistered but passenger may still be found in Seats
251 for (auto const& [_, seat] : Seats)
252 if (Unit* passenger = ObjectAccessor::GetUnit(*_me, seat.Passenger.Guid))
253 passenger->_ExitVehicle();
254}
@ SPELL_AURA_CONTROL_VEHICLE
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3716
Vehicle * Target
Definition: Vehicle.h:139
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemovePassenger()

Vehicle * Vehicle::RemovePassenger ( WorldObject passenger)
overridevirtual

Removes the passenger from the vehicle.

Author
Machiavelli
Date
17-2-2013
Parameters
[in,out]unitThe passenger to remove.

Implements TransportBase.

Definition at line 491 of file Vehicle.cpp.

492{
493 Unit* unit = passenger->ToUnit();
494 if (!unit)
495 return nullptr;
496
497 if (unit->GetVehicle() != this)
498 return nullptr;
499
500 SeatMap::iterator seat = GetSeatIteratorForPassenger(unit);
501 ASSERT(seat != Seats.end());
502
503 TC_LOG_DEBUG("entities.vehicle", "Unit {} exit vehicle entry {} id {} guid {} seat {}",
504 unit->GetName(), _me->GetEntry(), _vehicleInfo->ID, _me->GetGUID().ToString(), (int32)seat->first);
505
506 if (seat->second.SeatInfo->CanEnterOrExit() && ++UsableSeatNum)
508
509 // Enable gravity for passenger when he did not have it active before entering the vehicle
510 if (seat->second.SeatInfo->Flags & VEHICLE_SEAT_FLAG_DISABLE_GRAVITY && !seat->second.Passenger.IsGravityDisabled)
511 unit->SetDisableGravity(false);
512
513 // Remove UNIT_FLAG_UNINTERACTIBLE if passenger did not have it before entering vehicle
514 if (seat->second.SeatInfo->Flags & VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE && !seat->second.Passenger.IsUninteractible)
515 unit->SetUninteractible(false);
516
517 seat->second.Passenger.Reset();
518
519 if (_me->GetTypeId() == TYPEID_UNIT && unit->GetTypeId() == TYPEID_PLAYER && seat->second.SeatInfo->Flags & VEHICLE_SEAT_FLAG_CAN_CONTROL)
520 _me->RemoveCharmedBy(unit);
521
522 if (_me->IsInWorld())
523 {
524 if (!_me->GetTransport())
526 else
528 }
529
530 // only for flyable vehicles
531 if (unit->IsFlying())
533
535 _me->ToCreature()->AI()->PassengerBoarded(unit, seat->first, false);
536
537 if (GetBase()->GetTypeId() == TYPEID_UNIT)
538 sScriptMgr->OnRemovePassenger(this, unit);
539
540 unit->SetVehicle(nullptr);
541 return this;
542}
@ VEHICLE_SEAT_FLAG_DISABLE_GRAVITY
Definition: DBCEnums.h:2334
@ VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE
Definition: DBCEnums.h:2352
@ VEHICLE_SPELL_PARACHUTE
virtual void PassengerBoarded(Unit *, int8, bool)
== Fields =======================================
Definition: CreatureAI.h:220
CreatureAI * AI() const
Definition: Creature.h:184
static Unit * ToUnit(Object *o)
Definition: Object.h:212
bool IsInWorld() const
Definition: Object.h:153
Vehicle * GetVehicle() const
Definition: Unit.h:1817
bool SetDisableGravity(bool disable, bool updateAnimTier=true)
Definition: Unit.cpp:12788
void SetUninteractible(bool apply)
Definition: Unit.cpp:8001
bool IsAIEnabled() const
Definition: Unit.h:778
void RemoveCharmedBy(Unit *charmer)
Definition: Unit.cpp:11372
void SetVehicle(Vehicle *vehicle)
Definition: Unit.h:1818
bool IsFlying() const
Definition: Unit.h:1839
SeatMap::iterator GetSeatIteratorForPassenger(Unit *passenger)
Gets seat iterator for specified passenger.
Definition: Vehicle.cpp:668
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2881
TransportBase * GetTransport() const
Definition: Object.h:728
MovementInfo m_movementInfo
Definition: Object.h:739
void ResetTransport()
Definition: MovementInfo.h:129
struct MovementInfo::TransportInfo transport
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemovePendingEvent()

void Vehicle::RemovePendingEvent ( VehicleJoinEvent e)
private

Removes @VehicleJoinEvent 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.

Definition at line 713 of file Vehicle.cpp.

714{
715 for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end(); ++itr)
716 {
717 if (*itr == e)
718 {
719 _pendingJoinEvents.erase(itr);
720 break;
721 }
722 }
723}
+ Here is the caller graph for this function:

◆ RemovePendingEventsForPassenger()

void Vehicle::RemovePendingEventsForPassenger ( Unit passenger)

Definition at line 761 of file Vehicle.cpp.

762{
763 for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end();)
764 {
765 if ((*itr)->Passenger == passenger)
766 {
767 (*itr)->ScheduleAbort();
768 _pendingJoinEvents.erase(itr++);
769 }
770 else
771 ++itr;
772 }
773}
+ Here is the caller graph for this function:

◆ RemovePendingEventsForSeat()

void Vehicle::RemovePendingEventsForSeat ( int8  seatId)
private

Removes any pending events for given seatId. Executed when a @VehicleJoinEvent::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.

Definition at line 736 of file Vehicle.cpp.

737{
738 for (PendingJoinEventContainer::iterator itr = _pendingJoinEvents.begin(); itr != _pendingJoinEvents.end();)
739 {
740 if ((*itr)->Seat->first == seatId)
741 {
742 (*itr)->ScheduleAbort();
743 _pendingJoinEvents.erase(itr++);
744 }
745 else
746 ++itr;
747 }
748}
+ Here is the caller graph for this function:

◆ Reset()

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

Definition at line 137 of file Vehicle.cpp.

138{
139 if (GetBase()->GetTypeId() != TYPEID_UNIT)
140 return;
141
142 TC_LOG_DEBUG("entities.vehicle", "Vehicle::Reset (Entry: {}, {}, DBGuid: {})", GetCreatureEntry(), _me->GetGUID().ToString(), _me->ToCreature()->GetSpawnId());
143
145 if (GetBase()->IsAlive())
146 InstallAllAccessories(evading);
147
148 sScriptMgr->OnReset(this);
149}
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:101
void ApplyAllImmunities()
Applies specific immunities that cannot be set in DB.
Definition: Vehicle.cpp:160
void InstallAllAccessories(bool evading)
Definition: Vehicle.cpp:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Uninstall()

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

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

Definition at line 108 of file Vehicle.cpp.

109{
111 if (_status == STATUS_UNINSTALLING && !GetBase()->HasUnitTypeMask(UNIT_MASK_MINION))
112 {
113 TC_LOG_ERROR("entities.vehicle", "Vehicle {} Entry: {} attempts to uninstall, but already has STATUS_UNINSTALLING! "
114 "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString(), _creatureEntry);
115 return;
116 }
117
119 TC_LOG_DEBUG("entities.vehicle", "Vehicle::Uninstall Entry: {}, {}", _creatureEntry, _me->GetGUID().ToString());
121
122 if (GetBase()->GetTypeId() == TYPEID_UNIT)
123 sScriptMgr->OnUninstall(this);
124}
@ UNIT_MASK_MINION
Definition: Unit.h:348
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ VehicleJoinEvent

friend class VehicleJoinEvent
friend

Definition at line 77 of file Vehicle.h.

Member Data Documentation

◆ _creatureEntry

uint32 Vehicle::_creatureEntry
private

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

Definition at line 124 of file Vehicle.h.

◆ _me

Unit* Vehicle::_me
private

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

Definition at line 120 of file Vehicle.h.

◆ _pendingJoinEvents

PendingJoinEventContainer Vehicle::_pendingJoinEvents
private

Collection of delayed join events for prospective passengers.

Definition at line 128 of file Vehicle.h.

◆ _status

Status Vehicle::_status
private

Internal variable for sanity checks.

Definition at line 125 of file Vehicle.h.

◆ _vehicleInfo

VehicleEntry const* Vehicle::_vehicleInfo
private

DBC data for vehicle.

Definition at line 121 of file Vehicle.h.

◆ Seats

SeatMap Vehicle::Seats

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

Definition at line 66 of file Vehicle.h.

◆ UsableSeatNum

uint32 Vehicle::UsableSeatNum
protected

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

Definition at line 78 of file Vehicle.h.

◆ vehiclePlayers

GuidSet Vehicle::vehiclePlayers
private

Definition at line 122 of file Vehicle.h.


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