AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Vehicle Class Reference

#include "Vehicle.h"

Inheritance diagram for Vehicle:
TransportBase

Public Member Functions

void Install ()
 
void Uninstall ()
 
void Reset (bool evading=false)
 
void InstallAllAccessories (bool evading)
 
void ApplyAllImmunities ()
 
void InstallAccessory (uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
 
Unit * GetBase () const
 May be called from scripts.
 
VehicleEntry const * GetVehicleInfo () const
 
uint32 GetCreatureEntry () const
 
bool IsBoardableByPlayers () const
 
void SetBoardableByPlayers (bool boardable)
 
bool HasEmptySeat (int8 seatId) const
 
Unit * GetPassenger (int8 seatId) const
 
int8 GetNextEmptySeat (int8 seatId, bool next) const
 
VehicleSeatAddon const * GetSeatAddonForSeatOfPassenger (Unit const *passenger) const
 
uint8 GetAvailableSeatCount () const
 
bool AddPassenger (Unit *passenger, int8 seatId=-1)
 
void EjectPassenger (Unit *passenger, Unit *controller)
 
void RemovePassenger (Unit *passenger)
 
void RelocatePassengers ()
 
void RemoveAllPassengers ()
 
void Dismiss ()
 
bool IsVehicleInUse ()
 
bool IsControllableVehicle () const
 
void TeleportVehicle (float x, float y, float z, float ang)
 
VehicleSeatEntry const * GetSeatForPassenger (Unit const *passenger)
 
SeatMap::iterator GetSeatIteratorForPassenger (Unit *passenger)
 

Public Attributes

SeatMap Seats
 

Protected Member Functions

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

Private Types

enum  Status {
  STATUS_NONE ,
  STATUS_INSTALLED ,
  STATUS_UNINSTALLING
}
 

Private Member Functions

void InitMovementInfoForBase ()
 
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.
 

Private Attributes

Unit * _me
 
VehicleEntry const * _vehicleInfo
 
uint32 _usableSeatNum
 
uint32 _creatureEntry
 
Status _status
 
bool _accessoriesInstalled
 
bool _boardableByPlayers
 

Friends

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

Additional Inherited Members

- Static Protected 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)
 

Detailed Description

Member Enumeration Documentation

◆ Status

enum Vehicle::Status
private
Enumerator
STATUS_NONE 
STATUS_INSTALLED 
STATUS_UNINSTALLING 
73 {
77 };
@ STATUS_INSTALLED
Definition Vehicle.h:75
@ STATUS_UNINSTALLING
Definition Vehicle.h:76
@ STATUS_NONE
Definition Vehicle.h:74

Constructor & Destructor Documentation

◆ Vehicle()

Vehicle::Vehicle ( Unit *  unit,
VehicleEntry const *  vehInfo,
uint32  creatureEntry 
)
protected
36 :
37 _me(unit), _vehicleInfo(vehInfo), _usableSeatNum(0), _creatureEntry(creatureEntry), _status(STATUS_NONE),
39{
40 for (uint32 i = 0; i < MAX_VEHICLE_SEATS; ++i)
41 {
42 if (uint32 seatId = _vehicleInfo->m_seatID[i])
43 if (VehicleSeatEntry const* veSeat = sVehicleSeatStore.LookupEntry(seatId))
44 {
45 VehicleSeatAddon const* addon = sObjectMgr->GetVehicleSeatAddon(seatId);
46 Seats.insert(std::make_pair(i, VehicleSeat(veSeat, addon)));
47 if (veSeat->CanEnterOrExit())
49 }
50 }
51
52 // Set or remove correct flags based on available seats. Will overwrite db data (if wrong).
55 else
57
59}
DBCStorage< VehicleSeatEntry > sVehicleSeatStore(VehicleSeatEntryfmt)
#define MAX_VEHICLE_SEATS
Definition DBCStructure.h:2060
std::uint32_t uint32
Definition Define.h:107
#define sObjectMgr
Definition ObjectMgr.h:1731
@ UNIT_NPC_FLAG_SPELLCLICK
Definition UnitDefines.h:346
@ UNIT_NPC_FLAG_PLAYER_VEHICLE
Definition UnitDefines.h:347
Seats
Definition boss_flame_leviathan.cpp:171
bool IsPlayer() const
Definition Object.h:207
void RemoveNpcFlag(NPCFlags flags)
Definition Unit.h:771
void SetNpcFlag(NPCFlags flags)
Definition Unit.h:770
bool _accessoriesInstalled
Definition Vehicle.h:102
uint32 _usableSeatNum
Definition Vehicle.h:99
void InitMovementInfoForBase()
Definition Vehicle.cpp:654
uint32 _creatureEntry
Definition Vehicle.h:100
Status _status
Definition Vehicle.h:101
Unit * _me
Definition Vehicle.h:97
bool _boardableByPlayers
Definition Vehicle.h:103
VehicleEntry const * _vehicleInfo
Definition Vehicle.h:98
uint32 m_seatID[MAX_VEHICLE_SEATS]
Definition DBCStructure.h:2070
Definition VehicleDefines.h:86
Definition DBCStructure.h:2100
Definition VehicleDefines.h:101

References _me, _usableSeatNum, _vehicleInfo, InitMovementInfoForBase(), Object::IsPlayer(), VehicleEntry::m_seatID, MAX_VEHICLE_SEATS, Unit::RemoveNpcFlag(), Unit::SetNpcFlag(), sObjectMgr, sVehicleSeatStore, UNIT_NPC_FLAG_PLAYER_VEHICLE, and UNIT_NPC_FLAG_SPELLCLICK.

◆ ~Vehicle()

Vehicle::~Vehicle ( )
overrideprotected

@Uninstall must be called before this.

62{
65
66 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
67 if (itr->second.Passenger.Guid)
68 {
69 if (Unit* unit = ObjectAccessor::GetUnit(*_me, itr->second.Passenger.Guid))
70 {
71 LOG_FATAL("vehicles", "Vehicle(), unit: {}, entry: {}, typeid: {}, this_entry: {}, this_typeid: {}!", unit->GetName(), unit->GetEntry(), unit->GetTypeId(), _me ? _me->GetEntry() : 0, _me ? _me->GetTypeId() : 0);
72 unit->_ExitVehicle();
73 }
74 else
75 LOG_FATAL("vehicles", "Vehicle(), unknown guid!");
76 }
77}
#define ASSERT
Definition Errors.h:68
#define LOG_FATAL(filterType__,...)
Definition Log.h:141
uint32 GetEntry() const
Definition Object.h:123
Definition Unit.h:670
Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:223

References _me, _status, ASSERT, Object::GetEntry(), Object::GetTypeId(), ObjectAccessor::GetUnit(), LOG_FATAL, and STATUS_UNINSTALLING.

Member Function Documentation

◆ AddPassenger()

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

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

360{
363 {
364 LOG_DEBUG("vehicles", "Passenger {}, attempting to board vehicle {} during uninstall! SeatId: {}",
365 unit->GetGUID().ToString(), _me->GetGUID().ToString(), (int32)seatId);
366 return false;
367 }
368
369 if (unit->GetVehicle() != this)
370 return false;
371
372 SeatMap::iterator seat;
373 if (seatId < 0) // no specific seat requirement
374 {
375 for (seat = Seats.begin(); seat != Seats.end(); ++seat)
376 if (seat->second.IsEmpty() && (seat->second.SeatInfo->CanEnterOrExit() || seat->second.SeatInfo->IsUsableByOverride()))
377 break;
378
379 if (seat == Seats.end()) // no available seat
380 return false;
381 }
382 else
383 {
384 seat = Seats.find(seatId);
385 if (seat == Seats.end())
386 return false;
387
388 if (!seat->second.IsEmpty())
389 return false;
390
391 ASSERT(seat->second.IsEmpty());
392 }
393
394 if (!seat->second.SeatInfo)
395 return false;
396
397 LOG_DEBUG("vehicles", "Unit {} enter vehicle entry {} id {} ({}) seat {}",
398 unit->GetName(), _me->GetEntry(), _vehicleInfo->m_ID, _me->GetGUID().ToString(), (int32)seat->first);
399
400 seat->second.Passenger.Guid = unit->GetGUID();
401 seat->second.Passenger.IsUnselectable = unit->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
402
403 if (seat->second.SeatInfo->CanEnterOrExit())
404 {
407 if (!_usableSeatNum)
409 else if (!_me->IsPlayer() || _boardableByPlayers)
411 }
412
413 if (!_me || !_me->IsInWorld() || _me->IsDuringRemoveFromWorld())
414 return false;
415
416 // Xinef: moved from unit.cpp, if aura passes seatId == -1 (choose automaticly) we wont get appropriate flags
417 if (unit->IsPlayer() && !(seat->second.SeatInfo->m_flagsB & VEHICLE_SEAT_FLAG_B_KEEP_PET))
418 unit->ToPlayer()->UnsummonPetTemporaryIfAny();
419
420 if (seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE)
421 unit->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
422
423 unit->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
424 VehicleSeatEntry const* veSeat = seat->second.SeatInfo;
425 VehicleSeatAddon const* veSeatAddon = seat->second.SeatAddon;
426
427 float o = veSeatAddon ? veSeatAddon->SeatOrientationOffset : 0.f;
428 float x = veSeat->m_attachmentOffsetX;
429 float y = veSeat->m_attachmentOffsetY;
430 float z = veSeat->m_attachmentOffsetZ;
431
432 unit->m_movementInfo.transport.pos.Relocate(x, y, z, o);
433 unit->m_movementInfo.transport.time = 0;
434 unit->m_movementInfo.transport.seat = seat->first;
435 unit->m_movementInfo.transport.guid = _me->GetGUID();
436
437 // xinef: removed seat->first == 0 check...
438 if (_me->IsCreature()
439 && unit->IsPlayer()
440 && seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_CAN_CONTROL)
441 {
442 // Removed try catch + ABORT() here, and make it as simple condition check.
444 {
445 // I assume SetCharmedBy should always be true.
446 // If not, let's log some debug info.
447 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). not null: {}", _me ? 1 : 0);
448 if (!_me)
449 return false;
450 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Is: {}!", _me->IsInWorld());
451 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Is2: {}!", _me->IsDuringRemoveFromWorld());
452 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Unit {}!", _me->GetName());
453 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). typeid: {}!", _me->GetTypeId());
454 LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Unit {}, typeid: {}, in world: {}, duringremove: {} has wrong CharmType! Charmer {}, typeid: {}, in world: {}, duringremove: {}.", _me->GetName(), _me->GetTypeId(), _me->IsInWorld(), _me->IsDuringRemoveFromWorld(), unit->GetName(), unit->GetTypeId(), unit->IsInWorld(), unit->IsDuringRemoveFromWorld());
455 return false;
456 }
457 }
458
459 if (_me->IsInWorld())
460 {
461 unit->SendClearTarget(); // SMSG_BREAK_TARGET
462 unit->SetControlled(true, UNIT_STATE_ROOT); // SMSG_FORCE_ROOT - In some cases we send SMSG_SPLINE_MOVE_ROOT here (for creatures)
463 if (unit->IsPlayer())
464 unit->ToPlayer()->SetExpectingChangeTransport(true);
465 // also adds MOVEMENTFLAG_ROOT
466 Movement::MoveSplineInit init(unit);
467 init.DisableTransportPathTransformations();
468 init.MoveTo(x, y, z, false, true);
469 // Xinef: did not found anything unique in dbc, maybe missed something
470 if (veSeat->m_ID == 3566 || veSeat->m_ID == 3567 || veSeat->m_ID == 3568 || veSeat->m_ID == 3570)
471 {
472 CalculatePassengerPosition(x, y, z, &o);
473 init.SetFacing(_me->GetAngle(x, y));
474 }
475 else
476 {
477 init.SetFacing(o);
478 }
479
480 init.SetTransportEnter();
481 init.Launch();
482
483 // Put the vehicle in combat with anything that was threatening the passenger; the threat itself stays on the passenger
484 for (auto const& [guid, threatRef] : unit->GetThreatMgr().GetThreatenedByMeList())
485 threatRef->GetOwner()->GetThreatMgr().AddThreat(_me, 0.0f, nullptr, true, true);
486
487 if (_me->IsCreature())
488 {
489 if (_me->ToCreature()->IsAIEnabled)
490 _me->ToCreature()->AI()->PassengerBoarded(unit, seat->first, true);
491 }
492 }
493
494 if (GetBase()->IsCreature())
495 sScriptMgr->OnAddPassenger(this, unit, seatId);
496
497 // Remove parachute on vehicle switch
498 unit->RemoveAurasDueToSpell(VEHICLE_SPELL_PARACHUTE);
499 return true;
500}
@ CHARM_TYPE_VEHICLE
Definition CharmInfo.h:47
@ VEHICLE_SEAT_FLAG_CAN_CONTROL
Definition DBCEnums.h:455
@ VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE
Definition DBCEnums.h:464
@ VEHICLE_SEAT_FLAG_B_KEEP_PET
Definition DBCEnums.h:486
std::int32_t int32
Definition Define.h:103
#define LOG_INFO(filterType__,...)
Definition Log.h:153
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
#define sScriptMgr
Definition ScriptMgr.h:769
@ MOVEMENTFLAG_ONTRANSPORT
Definition UnitDefines.h:381
@ UNIT_STATE_ROOT
Definition UnitDefines.h:183
@ UNIT_FLAG_NOT_SELECTABLE
Definition UnitDefines.h:282
@ VEHICLE_SPELL_PARACHUTE
Definition VehicleDefines.h:53
virtual void PassengerBoarded(Unit *, int8, bool)
== Fields =======================================
Definition CreatureAI.h:239
CreatureAI * AI() const
Definition Creature.h:143
Definition MoveSplineInit.h:63
std::string ToString() const
Definition ObjectGuid.cpp:49
bool IsInWorld() const
Definition Object.h:115
TypeID GetTypeId() const
Definition Object.h:135
bool IsCreature() const
Definition Object.h:211
Creature * ToCreature()
Definition Object.h:212
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
bool IsDuringRemoveFromWorld() const
Definition Unit.h:709
bool IsAIEnabled
Definition Unit.h:2118
bool SetCharmedBy(Unit *charmer, CharmType type, AuraApplication const *aurApp=nullptr)
Definition Unit.cpp:14298
Unit * GetBase() const
May be called from scripts.
Definition Vehicle.h:37
void CalculatePassengerPosition(float &x, float &y, float &z, float *o) const override
This method transforms supplied transport offsets into global coordinates.
Definition Vehicle.h:82
std::string const & GetName() const
Definition Object.h:535
float GetAngle(Position const *pos) const
Definition Position.cpp:85
uint32 m_ID
Definition DBCStructure.h:2064
float SeatOrientationOffset
Definition VehicleDefines.h:92
float m_attachmentOffsetX
Definition DBCStructure.h:2104
uint32 m_ID
Definition DBCStructure.h:2101
float m_attachmentOffsetY
Definition DBCStructure.h:2105
float m_attachmentOffsetZ
Definition DBCStructure.h:2106

References _boardableByPlayers, _me, _status, _usableSeatNum, _vehicleInfo, Unit::AddUnitMovementFlag(), Creature::AI(), ASSERT, CalculatePassengerPosition(), CHARM_TYPE_VEHICLE, Movement::MoveSplineInit::DisableTransportPathTransformations(), Position::GetAngle(), GetBase(), Object::GetEntry(), Object::GetGUID(), WorldObject::GetName(), ThreatManager::GetThreatenedByMeList(), Unit::GetThreatMgr(), Object::GetTypeId(), Unit::GetVehicle(), MovementInfo::TransportInfo::guid, Unit::HasUnitFlag(), Unit::IsAIEnabled, Object::IsCreature(), Unit::IsDuringRemoveFromWorld(), Object::IsInWorld(), Object::IsPlayer(), Movement::MoveSplineInit::Launch(), LOG_DEBUG, LOG_INFO, VehicleSeatEntry::m_attachmentOffsetX, VehicleSeatEntry::m_attachmentOffsetY, VehicleSeatEntry::m_attachmentOffsetZ, VehicleEntry::m_ID, VehicleSeatEntry::m_ID, WorldObject::m_movementInfo, MOVEMENTFLAG_ONTRANSPORT, Movement::MoveSplineInit::MoveTo(), CreatureAI::PassengerBoarded(), MovementInfo::TransportInfo::pos, Position::Relocate(), Unit::RemoveAurasDueToSpell(), Unit::RemoveNpcFlag(), MovementInfo::TransportInfo::seat, VehicleSeatAddon::SeatOrientationOffset, Unit::SendClearTarget(), Unit::SetCharmedBy(), Unit::SetControlled(), Player::SetExpectingChangeTransport(), Movement::MoveSplineInit::SetFacing(), Unit::SetNpcFlag(), Movement::MoveSplineInit::SetTransportEnter(), Unit::SetUnitFlag(), sScriptMgr, STATUS_UNINSTALLING, MovementInfo::TransportInfo::time, Object::ToCreature(), Object::ToPlayer(), ObjectGuid::ToString(), MovementInfo::transport, UNIT_FLAG_NOT_SELECTABLE, UNIT_NPC_FLAG_PLAYER_VEHICLE, UNIT_NPC_FLAG_SPELLCLICK, UNIT_STATE_ROOT, Player::UnsummonPetTemporaryIfAny(), VEHICLE_SEAT_FLAG_B_KEEP_PET, VEHICLE_SEAT_FLAG_CAN_CONTROL, VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE, and VEHICLE_SPELL_PARACHUTE.

Referenced by Unit::_EnterVehicle(), and Unit::ChangeSeat().

◆ ApplyAllImmunities()

void Vehicle::ApplyAllImmunities ( )
179{
180 // This couldn't be done in DB, because some spells have MECHANIC_NONE
181
182 // Vehicles should be immune on Knockback ...
183 //_me->ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_KNOCK_BACK, true);
184 //_me->ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_KNOCK_BACK_DEST, true);
185
186 // Mechanical units & vehicles ( which are not Bosses, they have own immunities in DB ) should be also immune on healing ( exceptions in switch below )
188 {
189 // Heal & dispel ...
195
196 // ... Shield & Immunity grant spells ...
198 //_me->ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_UNATTACKABLE, true);
203
204 // ... Resistance, Split damage, Change stats ...
209
210 // Taunt
213 }
214
215 // Different immunities for vehicles goes below
216 switch (GetVehicleInfo()->m_ID)
217 {
218 case 160: //Isle of conquest turret
219 case 244: //Wintergrasp turret
220 case 510: // Isle of Conquest
221 case 452: // Isle of Conquest
222 case 543: // Isle of Conquest
223 //_me->SetControlled(true, UNIT_STATE_ROOT);
224 //me->AddUnitMovementFlag(MOVEMENTFLAG_ROOT);
225 //me->SetSpeed(MOVE_TURN_RATE, 0.7f);
226 //me->SetSpeed(MOVE_PITCH_RATE, 0.7f);
227 //me->m_movementInfo.flags2=59;
229 break;
230 // Ulduar vehicles, remove immunities used in flame leviathan spells
231 case 335:
232 case 336:
233 case 338:
236 break;
237 default:
238 break;
239 }
240}
@ AREA_WINTERGRASP
Definition AreaDefines.h:145
@ SPELL_EFFECT_HEAL
Definition SharedDefines.h:776
@ SPELL_EFFECT_HEAL_MAX_HEALTH
Definition SharedDefines.h:833
@ SPELL_EFFECT_DISPEL
Definition SharedDefines.h:804
@ SPELL_EFFECT_ATTACK_ME
Definition SharedDefines.h:880
@ SPELL_EFFECT_HEAL_PCT
Definition SharedDefines.h:902
@ CREATURE_TYPE_MECHANICAL
Definition SharedDefines.h:2630
@ MECHANIC_IMMUNE_SHIELD
Definition SharedDefines.h:1342
@ MECHANIC_SHIELD
Definition SharedDefines.h:1332
@ IMMUNITY_STATE
Definition SharedDefines.h:1399
@ IMMUNITY_EFFECT
Definition SharedDefines.h:1398
@ IMMUNITY_MECHANIC
Definition SharedDefines.h:1403
@ SPELL_AURA_DAMAGE_SHIELD
Definition SpellAuraDefines.h:78
@ SPELL_AURA_MOD_RESISTANCE
Definition SpellAuraDefines.h:85
@ SPELL_AURA_PERIODIC_HEAL
Definition SpellAuraDefines.h:71
@ SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
Definition SpellAuraDefines.h:150
@ SPELL_AURA_SPLIT_DAMAGE_PCT
Definition SpellAuraDefines.h:144
@ SPELL_AURA_MOD_STAT
Definition SpellAuraDefines.h:92
@ SPELL_AURA_SCHOOL_IMMUNITY
Definition SpellAuraDefines.h:102
@ SPELL_AURA_MOD_TAUNT
Definition SpellAuraDefines.h:74
@ SPELL_AURA_MOD_DECREASE_SPEED
Definition SpellAuraDefines.h:96
@ SPELL_AURA_SCHOOL_ABSORB
Definition SpellAuraDefines.h:132
bool isWorldBoss() const
Definition Creature.h:123
ObjectGuid::LowType GetSpawnId() const
Definition Creature.h:68
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:207
bool Instanceable() const
Definition Map.h:298
void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply, SpellImmuneBlockType blockType=SPELL_BLOCK_TYPE_ALL)
Definition Unit.cpp:10247
VehicleEntry const * GetVehicleInfo() const
Definition Vehicle.h:38
Map * FindMap() const
Definition Object.h:638
uint32 GetZoneId() const
Definition Object.cpp:3178
uint32 type
Definition CreatureData.h:218

References _me, Unit::ApplySpellImmune(), AREA_WINTERGRASP, CREATURE_TYPE_MECHANICAL, WorldObject::FindMap(), Creature::GetCreatureTemplate(), Creature::GetSpawnId(), GetVehicleInfo(), WorldObject::GetZoneId(), IMMUNITY_EFFECT, IMMUNITY_MECHANIC, IMMUNITY_STATE, Map::Instanceable(), Creature::isWorldBoss(), MECHANIC_IMMUNE_SHIELD, MECHANIC_SHIELD, SPELL_AURA_DAMAGE_SHIELD, SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN, SPELL_AURA_MOD_DECREASE_SPEED, SPELL_AURA_MOD_RESISTANCE, SPELL_AURA_MOD_STAT, SPELL_AURA_MOD_TAUNT, SPELL_AURA_PERIODIC_HEAL, SPELL_AURA_SCHOOL_ABSORB, SPELL_AURA_SCHOOL_IMMUNITY, SPELL_AURA_SPLIT_DAMAGE_PCT, SPELL_EFFECT_ATTACK_ME, SPELL_EFFECT_DISPEL, SPELL_EFFECT_HEAL, SPELL_EFFECT_HEAL_MAX_HEALTH, SPELL_EFFECT_HEAL_PCT, Object::ToCreature(), and CreatureTemplate::type.

Referenced by Reset().

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

91 {
93 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
94 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
95 }
virtual void CalculatePassengerOffset(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied global coordinates into local offsets.

References TransportBase::CalculatePassengerOffset(), and GetBase().

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

83 {
85 GetBase()->GetPositionX(), GetBase()->GetPositionY(),
86 GetBase()->GetPositionZ(), GetBase()->GetOrientation());
87 }
virtual void CalculatePassengerPosition(float &x, float &y, float &z, float *o=nullptr) const =0
This method transforms supplied transport offsets into global coordinates.

References TransportBase::CalculatePassengerPosition(), and GetBase().

Referenced by AddPassenger(), and RelocatePassengers().

◆ Dismiss()

void Vehicle::Dismiss ( )
586{
587 if (!GetBase()->IsCreature())
588 return;
589
590 LOG_DEBUG("vehicles", "Vehicle::Dismiss {}", _me->GetGUID().ToString());
591 Uninstall();
593}
void DespawnOrUnsummon(Milliseconds msTimeToDespawn=0ms, Seconds forcedRespawnTimer=0s)
Definition Creature.cpp:2221
void Uninstall()
Definition Vehicle.cpp:123

References _me, Creature::DespawnOrUnsummon(), GetBase(), Object::GetGUID(), LOG_DEBUG, Object::ToCreature(), ObjectGuid::ToString(), and Uninstall().

Referenced by Unit::_ExitVehicle(), BattlefieldWG::OnPlayerLeaveWar(), and Player::UpdateAreaDependentAuras().

◆ EjectPassenger()

void Vehicle::EjectPassenger ( Unit *  passenger,
Unit *  controller 
)

◆ GetAvailableSeatCount()

uint8 Vehicle::GetAvailableSeatCount ( ) const
691{
692 uint8 ret = 0;
693 SeatMap::const_iterator itr;
694 for (itr = Seats.begin(); itr != Seats.end(); ++itr)
695 if (itr->second.IsEmpty() && (itr->second.SeatInfo->CanEnterOrExit() || itr->second.SeatInfo->IsUsableByOverride()))
696 ++ret;
697
698 return ret;
699}
std::uint8_t uint8
Definition Define.h:109

Referenced by Aura::CanStackWith(), and npc_brunnhildar_prisoner::npc_brunnhildar_prisonerAI::SpellHit().

◆ GetBase()

◆ GetCreatureEntry()

uint32 Vehicle::GetCreatureEntry ( ) const
inline

◆ GetNextEmptySeat()

int8 Vehicle::GetNextEmptySeat ( int8  seatId,
bool  next 
) const
285{
286 SeatMap::const_iterator seat = Seats.find(seatId);
287 if (seat == Seats.end())
288 return -1;
289
290 while (!seat->second.IsEmpty() || (!seat->second.SeatInfo->CanEnterOrExit() && !seat->second.SeatInfo->IsUsableByOverride()))
291 {
292 if (next)
293 {
294 ++seat;
295 if (seat == Seats.end())
296 seat = Seats.begin();
297 }
298 else
299 {
300 if (seat == Seats.begin())
301 seat = Seats.end();
302 --seat;
303 }
304
305 if (seat->first == seatId)
306 return -1; // no available seat
307 }
308
309 return seat->first;
310}

Referenced by Unit::ChangeSeat().

◆ GetPassenger()

◆ GetSeatAddonForSeatOfPassenger()

VehicleSeatAddon const * Vehicle::GetSeatAddonForSeatOfPassenger ( Unit const *  passenger) const
276{
277 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); itr++)
278 if (!itr->second.IsEmpty() && itr->second.Passenger.Guid == passenger->GetGUID())
279 return itr->second.SeatAddon;
280
281 return nullptr;
282}

References Object::GetGUID().

Referenced by Unit::_ExitVehicle().

◆ GetSeatForPassenger()

VehicleSeatEntry const * Vehicle::GetSeatForPassenger ( Unit const *  passenger)
671{
672 SeatMap::iterator itr;
673 for (itr = Seats.begin(); itr != Seats.end(); ++itr)
674 if (itr->second.Passenger.Guid == passenger->GetGUID())
675 return itr->second.SeatInfo;
676
677 return nullptr;
678}

References Object::GetGUID().

Referenced by Spell::CheckCast(), WorldSession::HandleChangeSeatsOnControlledVehicle(), WorldSession::HandleEjectPassenger(), and Player::ProcessTerrainStatusUpdate().

◆ GetSeatIteratorForPassenger()

SeatMap::iterator Vehicle::GetSeatIteratorForPassenger ( Unit *  passenger)
681{
682 SeatMap::iterator itr;
683 for (itr = Seats.begin(); itr != Seats.end(); ++itr)
684 if (itr->second.Passenger.Guid == passenger->GetGUID())
685 return itr;
686
687 return Seats.end();
688}

References Object::GetGUID().

Referenced by spell_switch_infragreen_bomber_station::HandleDummy(), and RemovePassenger().

◆ GetVehicleInfo()

◆ HasEmptySeat()

bool Vehicle::HasEmptySeat ( int8  seatId) const
259{
260 SeatMap::const_iterator seat = Seats.find(seatId);
261 if (seat == Seats.end())
262 return false;
263 return seat->second.IsEmpty();
264}

Referenced by npc_salvaged_siege_engine::BeforeSpellClick(), and Unit::ChangeSeat().

◆ InitMovementInfoForBase()

void Vehicle::InitMovementInfoForBase ( )
private
655{
656 uint32 vehicleFlags = GetVehicleInfo()->m_flags;
657
658 if (vehicleFlags & VEHICLE_FLAG_NO_STRAFE)
660 if (vehicleFlags & VEHICLE_FLAG_NO_JUMPING)
662 if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDTURNING)
664 if (vehicleFlags & VEHICLE_FLAG_ALLOW_PITCHING)
666 if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDPITCHING)
668}
@ MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING
Definition UnitDefines.h:435
@ MOVEMENTFLAG2_NO_STRAFE
Definition UnitDefines.h:430
@ MOVEMENTFLAG2_FULL_SPEED_PITCHING
Definition UnitDefines.h:434
@ MOVEMENTFLAG2_FULL_SPEED_TURNING
Definition UnitDefines.h:433
@ MOVEMENTFLAG2_NO_JUMPING
Definition UnitDefines.h:431
@ VEHICLE_FLAG_NO_JUMPING
Definition VehicleDefines.h:41
@ VEHICLE_FLAG_NO_STRAFE
Definition VehicleDefines.h:40
@ VEHICLE_FLAG_FULLSPEEDTURNING
Definition VehicleDefines.h:42
@ VEHICLE_FLAG_ALLOW_PITCHING
Definition VehicleDefines.h:43
@ VEHICLE_FLAG_FULLSPEEDPITCHING
Definition VehicleDefines.h:44
void AddExtraUnitMovementFlag(uint16 f)
Definition Unit.h:784
uint32 m_flags
Definition DBCStructure.h:2065

References _me, Unit::AddExtraUnitMovementFlag(), GetVehicleInfo(), VehicleEntry::m_flags, MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING, MOVEMENTFLAG2_FULL_SPEED_PITCHING, MOVEMENTFLAG2_FULL_SPEED_TURNING, MOVEMENTFLAG2_NO_JUMPING, MOVEMENTFLAG2_NO_STRAFE, VEHICLE_FLAG_ALLOW_PITCHING, VEHICLE_FLAG_FULLSPEEDPITCHING, VEHICLE_FLAG_FULLSPEEDTURNING, VEHICLE_FLAG_NO_JUMPING, and VEHICLE_FLAG_NO_STRAFE.

Referenced by Vehicle().

◆ Install()

void Vehicle::Install ( )
80{
81 if (_me->IsCreature())
82 {
83 if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(_vehicleInfo->m_powerDisplayId))
84 {
85 _me->setPowerType(Powers(powerDisplay->PowerType));
86
87 // Pyrite does not regenerate and is only refilled by scripted energizes,
88 // so the Salvaged Demolisher and its Mechanic Seat spawn with a full bar
91 }
94 }
95
97 if (GetBase()->IsCreature())
98 sScriptMgr->OnInstall(this);
99}
DBCStorage< PowerDisplayEntry > sPowerDisplayStore(PowerDisplayfmt)
Powers
Definition SharedDefines.h:256
@ POWER_ENERGY
Definition SharedDefines.h:260
@ CLASS_ROGUE
Definition SharedDefines.h:129
@ CLASS_CONTEXT_ABILITY
Definition UnitDefines.h:241
@ POWER_DISPLAY_PYRITE
Definition Vehicle.cpp:33
void SetPower(Powers power, uint32 val, bool withPowerUpdate=true, bool fromRegenerate=false)
Definition Unit.cpp:12108
virtual bool IsClass(Classes unitClass, ClassContext context=CLASS_CONTEXT_NONE) const
Definition Unit.h:850
uint32 GetMaxPower(Powers power) const
Definition Unit.h:1150
Powers getPowerType() const
Definition Unit.h:1145
void setPowerType(Powers power)
Definition Unit.cpp:6809
Definition DBCStructure.h:1457
uint32 m_powerDisplayId
Definition DBCStructure.h:2094

References _me, _status, _vehicleInfo, CLASS_CONTEXT_ABILITY, CLASS_ROGUE, GetBase(), Unit::GetMaxPower(), Unit::getPowerType(), Unit::IsClass(), Object::IsCreature(), VehicleEntry::m_powerDisplayId, POWER_DISPLAY_PYRITE, POWER_ENERGY, Unit::SetPower(), Unit::setPowerType(), sPowerDisplayStore, sScriptMgr, and STATUS_INSTALLED.

Referenced by Creature::AddToWorld().

◆ InstallAccessory()

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

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

313{
316 {
317 LOG_ERROR("vehicles", "Vehicle {} attempts to install accessory Entry: {} on seat {} with STATUS_UNINSTALLING! "
318 "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString(), entry, (int32)seatId);
319 return;
320 }
321
322 LOG_DEBUG("vehicles", "Vehicle: Installing accessory entry {} on vehicle entry {} (seat:{})", entry, GetCreatureEntry(), seatId);
323 if (Unit* passenger = GetPassenger(seatId))
324 {
325 // already installed
326 if (passenger->GetEntry() == entry)
327 {
328 ASSERT(passenger->IsCreature());
329 if (_me->IsCreature())
330 {
331 if (_me->ToCreature()->IsInEvadeMode() && passenger->ToCreature()->IsAIEnabled)
332 passenger->ToCreature()->AI()->EnterEvadeMode();
333 return;
334 }
335 }
336 else
337 passenger->ExitVehicle(); // this should not happen
338 }
339
340 if (TempSummon* accessory = _me->SummonCreature(entry, *_me, TempSummonType(type), summonTime))
341 {
342 if (minion)
343 {
344 accessory->AddUnitTypeMask(UNIT_MASK_ACCESSORY);
345 accessory->GetThreatMgr().Initialize(); // reinitialize CanHaveThreatList cached value
346 }
347
348 if (!_me->HandleSpellClick(accessory, seatId))
349 {
350 accessory->UnSummon();
351 return;
352 }
353
354 if (GetBase()->IsCreature())
355 sScriptMgr->OnInstallAccessory(this, accessory);
356 }
357}
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
TempSummonType
Definition Object.h:49
@ UNIT_MASK_ACCESSORY
Definition UnitDefines.h:168
bool IsInEvadeMode() const
Definition Creature.h:137
Definition TemporarySummon.h:50
bool HandleSpellClick(Unit *clicker, int8 seatId=-1)
Definition Unit.cpp:15212
Unit * GetPassenger(int8 seatId) const
Definition Vehicle.cpp:266
uint32 GetCreatureEntry() const
Definition Vehicle.h:39
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition Object.cpp:2460

References _me, _status, ASSERT, GetBase(), GetCreatureEntry(), Object::GetGUID(), GetPassenger(), Unit::HandleSpellClick(), Object::IsCreature(), Creature::IsInEvadeMode(), LOG_DEBUG, LOG_ERROR, sScriptMgr, STATUS_UNINSTALLING, WorldObject::SummonCreature(), Object::ToCreature(), ObjectGuid::ToString(), and UNIT_MASK_ACCESSORY.

Referenced by boss_kologarn::AttachLeftArm(), boss_kologarn::AttachRightArm(), and InstallAllAccessories().

◆ InstallAllAccessories()

void Vehicle::InstallAllAccessories ( bool  evading)
102{
103 // Clear stale control-vehicle auras only on the first non-evade reset;
104 // a re-Reset would otherwise eject a just-seated passenger and, for
105 // accessories, fire a spurious SMART_EVENT_PASSENGER_REMOVED.
106 if (GetBase()->IsPlayer() || (!evading && !_accessoriesInstalled))
108
109 // Mark the initial reset as done even if this vehicle has no accessory
110 // list, so subsequent Resets don't eject passengers on vehicles without
111 // accessories (e.g. WG demolisher/catapult).
113
114 VehicleAccessoryList const* accessories = sObjectMgr->GetVehicleAccessoryList(this);
115 if (!accessories)
116 return;
117
118 for (VehicleAccessoryList::const_iterator itr = accessories->begin(); itr != accessories->end(); ++itr)
119 if (!evading || itr->IsMinion) // only install minions on evade mode
120 InstallAccessory(itr->AccessoryEntry, itr->SeatId, itr->IsMinion, itr->SummonedType, itr->SummonTime);
121}
std::vector< VehicleAccessory > VehicleAccessoryList
Definition VehicleDefines.h:125
void RemoveAllPassengers()
Definition Vehicle.cpp:242
void InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, uint32 summonTime)
Definition Vehicle.cpp:312

References _accessoriesInstalled, GetBase(), InstallAccessory(), RemoveAllPassengers(), and sObjectMgr.

Referenced by boss_flame_leviathan_seat::EnterEvadeMode(), Unit::Mount(), Reset(), and npc_hyldsmeet_protodrake::UpdateAI().

◆ IsBoardableByPlayers()

bool Vehicle::IsBoardableByPlayers ( ) const
inline

◆ IsControllableVehicle()

bool Vehicle::IsControllableVehicle ( ) const
610{
611 return std::ranges::any_of(Seats, [](auto const& seat) { return seat.second.SeatInfo->CanControl(); });
612}

◆ IsVehicleInUse()

bool Vehicle::IsVehicleInUse ( )
596{
597 for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); ++itr)
598 if (Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), itr->second.Passenger.Guid))
599 {
600 if (passenger->IsPlayer())
601 return true;
602 else if (passenger->IsCreature() && passenger->GetVehicleKit() && passenger->GetVehicleKit()->IsVehicleInUse())
603 return true;
604 }
605
606 return false;
607}

References GetBase(), and ObjectAccessor::GetUnit().

Referenced by VehicleAI::OnCharmed().

◆ RelocatePassengers()

void Vehicle::RelocatePassengers ( )
561{
562 ASSERT(_me->GetMap());
563
564 std::vector<std::pair<Unit*, Position>> seatRelocation;
565 seatRelocation.reserve(Seats.size());
566
567 // not sure that absolute position calculation is correct, it must depend on vehicle pitch angle
568 for (auto const& itr : Seats)
569 {
570 if (Unit* passenger = ObjectAccessor::GetUnit(*GetBase(), itr.second.Passenger.Guid))
571 {
572 ASSERT(passenger->IsInWorld());
573
574 float px, py, pz, po;
575 passenger->m_movementInfo.transport.pos.GetPosition(px, py, pz, po);
576 CalculatePassengerPosition(px, py, pz, &po);
577 seatRelocation.emplace_back(passenger, Position(px, py, pz, po));
578 }
579 }
580
581 for (auto const& pair : seatRelocation)
582 pair.first->UpdatePosition(pair.second);
583}
Map * GetMap() const
Definition Object.h:637
Definition Position.h:27

References _me, ASSERT, CalculatePassengerPosition(), GetBase(), WorldObject::GetMap(), ObjectAccessor::GetUnit(), and Seats.

Referenced by Map::CreatureRelocation(), Map::PlayerRelocation(), Unit::UpdateHeight(), and Unit::UpdateOrientation().

◆ RemoveAllPassengers()

void Vehicle::RemoveAllPassengers ( )
243{
244 LOG_DEBUG("vehicles", "Vehicle::RemoveAllPassengers. {}", _me->GetGUID().ToString());
245
246 // Passengers always cast an aura with SPELL_AURA_CONTROL_VEHICLE on the vehicle
247 // We just remove the aura and the unapply handler will make the target leave the vehicle.
248 // We don't need to iterate over Seats
250
251 // Following the above logic, this assertion should NEVER fail.
252 // Even in 'hacky' cases, there should at least be VEHICLE_SPELL_RIDE_HARDCODED on us.
253 // SeatMap::const_iterator itr;
254 // for (itr = Seats.begin(); itr != Seats.end(); ++itr)
255 // ASSERT(!itr->second.passenger.Guid);
256}
@ SPELL_AURA_CONTROL_VEHICLE
Definition SpellAuraDefines.h:299
void RemoveAurasByType(AuraType auraType, ObjectGuid casterGUID=ObjectGuid::Empty, Aura *except=nullptr, bool negative=true, bool positive=true)
Definition Unit.cpp:5178

References _me, Object::GetGUID(), LOG_DEBUG, Unit::RemoveAurasByType(), SPELL_AURA_CONTROL_VEHICLE, and ObjectGuid::ToString().

Referenced by InstallAllAccessories(), and Uninstall().

◆ RemovePassenger()

void Vehicle::RemovePassenger ( Unit *  passenger)
503{
504 if (unit->GetVehicle() != this)
505 return;
506
507 SeatMap::iterator seat = GetSeatIteratorForPassenger(unit);
508 // it can happen that unit enters vehicle and removes owner passenger
509 // then vehicles is dissmised and removes all existing passengers, even the unit (vehicle has aura of unit)
510 // but the unit is not on the vehicles seat yet, thus crashing at ASSERT(seat != Seats.end());
511 // ASSERT(seat != Seats.end());
512 if (seat == Seats.end())
513 {
514 LOG_ERROR("vehicles", "Vehicle::RemovePassenger: Vehicle entry ({}) id ({}) is dissmised and removed all existing passangers, but the unit ({}) was not on the vehicle!",
515 _me->GetEntry(), _vehicleInfo->m_ID, unit->GetName());
516 return;
517 }
518
519 LOG_DEBUG("vehicles", "Unit {} exit vehicle entry {} id {} ({}) seat {}",
520 unit->GetName(), _me->GetEntry(), _vehicleInfo->m_ID, _me->GetGUID().ToString(), (int32)seat->first);
521
522 if (seat->second.SeatInfo->CanEnterOrExit() && ++_usableSeatNum &&
525
526 // Remove UNIT_FLAG_NOT_SELECTABLE if passenger did not have it before entering vehicle
527 if (seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE && !seat->second.Passenger.IsUnselectable)
528 unit->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
529
530 seat->second.Passenger.Reset();
531
532 // RemoveCharmedBy() clears flying movement state, so cache this before uncharm.
534
535 if (_me->IsCreature() && unit->IsPlayer() && seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_CAN_CONTROL)
536 _me->RemoveCharmedBy(unit);
537
538 if (_me->IsInWorld())
539 {
540 if (!_me->GetTransport())
541 {
542 unit->RemoveUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
543 unit->m_movementInfo.transport.Reset();
544 }
545 else
546 unit->m_movementInfo.transport = _me->m_movementInfo.transport;
547 }
548
549 // only for flyable vehicles
550 if (canFly && !_me->GetInstanceId() && unit->IsPlayer() && !(unit->ToPlayer()->GetDelayedOperations() & DELAYED_VEHICLE_TELEPORT) && _me->GetEntry() != 30275 /*NPC_WILD_WYRM*/)
552
553 if (_me->IsCreature())
554 sScriptMgr->OnRemovePassenger(this, unit);
555
557 _me->ToCreature()->AI()->PassengerBoarded(unit, seat->first, false);
558}
@ DELAYED_VEHICLE_TELEPORT
Definition Player.h:903
@ SPELL_AURA_FLY
Definition SpellAuraDefines.h:264
@ MOVEMENTFLAG_CAN_FLY
Definition UnitDefines.h:396
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:780
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:5805
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition Unit.cpp:1378
void RemoveCharmedBy(Unit *charmer)
Definition Unit.cpp:14502
bool IsFlying() const
Definition Unit.h:1733
SeatMap::iterator GetSeatIteratorForPassenger(Unit *passenger)
Definition Vehicle.cpp:680
uint32 GetInstanceId() const
Definition Object.h:520
Transport * GetTransport() const
Definition Object.h:701
MovementInfo m_movementInfo
Definition Object.h:711
struct MovementInfo::TransportInfo transport

References _boardableByPlayers, _me, _usableSeatNum, _vehicleInfo, Creature::AI(), Unit::CastSpell(), DELAYED_VEHICLE_TELEPORT, Player::GetDelayedOperations(), Object::GetEntry(), Object::GetGUID(), WorldObject::GetInstanceId(), WorldObject::GetName(), GetSeatIteratorForPassenger(), WorldObject::GetTransport(), Unit::GetVehicle(), Unit::HasAuraType(), Unit::HasUnitMovementFlag(), Unit::IsAIEnabled, Object::IsCreature(), Unit::IsFlying(), Object::IsInWorld(), Object::IsPlayer(), LOG_DEBUG, LOG_ERROR, VehicleEntry::m_ID, WorldObject::m_movementInfo, MOVEMENTFLAG_CAN_FLY, MOVEMENTFLAG_ONTRANSPORT, CreatureAI::PassengerBoarded(), Unit::RemoveCharmedBy(), Unit::RemoveUnitFlag(), Unit::RemoveUnitMovementFlag(), MovementInfo::TransportInfo::Reset(), Unit::SetNpcFlag(), SPELL_AURA_FLY, sScriptMgr, Object::ToCreature(), Object::ToPlayer(), ObjectGuid::ToString(), MovementInfo::transport, UNIT_FLAG_NOT_SELECTABLE, UNIT_NPC_FLAG_PLAYER_VEHICLE, UNIT_NPC_FLAG_SPELLCLICK, VEHICLE_SEAT_FLAG_CAN_CONTROL, VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE, and VEHICLE_SPELL_PARACHUTE.

Referenced by Unit::_ExitVehicle(), and Unit::ChangeSeat().

◆ Reset()

void Vehicle::Reset ( bool  evading = false)
144{
145 LOG_DEBUG("vehicles", "Vehicle::Reset: {}", _me->GetGUID().ToString());
146 if (_me->IsPlayer())
147 {
150 }
151 else
152 {
154 // Dead spawns waiting out a respawn timer must not seat live accessories; they are seated on revival.
155 if (_me->IsAlive())
156 InstallAllAccessories(evading);
157 if (_usableSeatNum)
159 }
160
161 if (GetBase()->IsCreature())
162 sScriptMgr->OnReset(this);
163}
bool IsAlive() const
Definition Unit.h:1812
void ApplyAllImmunities()
Definition Vehicle.cpp:178
void InstallAllAccessories(bool evading)
Definition Vehicle.cpp:101

References _boardableByPlayers, _me, _usableSeatNum, ApplyAllImmunities(), GetBase(), Object::GetGUID(), InstallAllAccessories(), Unit::IsAlive(), Object::IsPlayer(), LOG_DEBUG, Unit::SetNpcFlag(), sScriptMgr, ObjectGuid::ToString(), UNIT_NPC_FLAG_PLAYER_VEHICLE, and UNIT_NPC_FLAG_SPELLCLICK.

Referenced by CreatureAI::EnterEvadeMode(), Unit::Mount(), and Creature::Update().

◆ SetBoardableByPlayers()

void Vehicle::SetBoardableByPlayers ( bool  boardable)

◆ TeleportVehicle()

void Vehicle::TeleportVehicle ( float  x,
float  y,
float  z,
float  ang 
)
615{
616 // Snapshot passenger GUIDs and cache the base BEFORE teleporting.
617 // Teleporting the base (Player::TeleportTo) may drop the mount/vehicle aura
618 // on a long hop (>100 yd) and call ExitVehicle() -> Unit::RemoveVehicleKit()
619 // -> delete m_vehicleKit, freeing THIS Vehicle (and its Seats) mid-call.
620 // Reading Seats after that is a use-after-free (see upstream PR #26116 review).
621 Unit* base = _me;
622 Vehicle* self = this;
623 std::vector<ObjectGuid> passengers;
624 passengers.reserve(Seats.size());
625 for (auto const& seat : Seats)
626 if (!seat.second.IsEmpty())
627 passengers.push_back(seat.second.Passenger.Guid);
628
629 base->GetMap()->LoadGrid(x, y);
630 base->NearTeleportTo(x, y, z, ang, true, true); // vehicleTeleport=true: do not dismount base mid-call
631
632 // THIS Vehicle may have been deleted by the base teleport above (kit freed).
633 // If so, bail out - passengers were already ejected by ~Vehicle::Uninstall().
634 if (base->GetVehicleKit() != self)
635 return;
636
637 for (ObjectGuid const& guid : passengers)
638 if (Unit* passenger = ObjectAccessor::GetUnit(*base, guid))
639 {
640 if (!passenger->IsInWorld())
641 continue;
642
643 if (passenger->IsPlayer())
644 {
645 passenger->ToPlayer()->SetMover(passenger);
646 passenger->NearTeleportTo(x, y, z, ang, false, true);
647 passenger->ToPlayer()->ScheduleDelayedOperation(DELAYED_VEHICLE_TELEPORT);
648 }
649 else if (passenger->IsCreature() && passenger->GetVehicleKit())
650 passenger->GetVehicleKit()->TeleportVehicle(x, y, z, ang);
651 }
652}
void LoadGrid(float x, float y)
Definition Map.cpp:216
Definition ObjectGuid.h:121
void NearTeleportTo(Position &pos, bool casting=false, bool vehicleTeleport=false, bool withPet=false, bool removeTransport=false)
Definition Unit.cpp:15650
Vehicle * GetVehicleKit() const
Definition Unit.h:1947
Definition Vehicle.h:28
Definition ObjectAccessor.h:61

References _me, DELAYED_VEHICLE_TELEPORT, WorldObject::GetMap(), ObjectAccessor::GetUnit(), Unit::GetVehicleKit(), Map::LoadGrid(), Unit::NearTeleportTo(), and Seats.

Referenced by Spell::EffectTeleportUnits().

◆ Uninstall()

void Vehicle::Uninstall ( )

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

124{
126 if (_status == STATUS_UNINSTALLING && !GetBase()->HasUnitTypeMask(UNIT_MASK_MINION))
127 {
128 LOG_ERROR("vehicles", "Vehicle {} attempts to uninstall, but already has STATUS_UNINSTALLING! "
129 "Check Uninstall/PassengerBoarded script hooks for errors.", _me->GetGUID().ToString());
130 return;
131 }
133 LOG_DEBUG("vehicles", "Vehicle::Uninstall {}", _me->GetGUID().ToString());
135 _accessoriesInstalled = false;
136
137 if (_me && _me->IsCreature())
138 {
139 sScriptMgr->OnUninstall(this);
140 }
141}
@ UNIT_MASK_MINION
Definition UnitDefines.h:160

References _accessoriesInstalled, _me, _status, GetBase(), Object::GetGUID(), Object::IsCreature(), LOG_DEBUG, LOG_ERROR, RemoveAllPassengers(), sScriptMgr, STATUS_UNINSTALLING, ObjectGuid::ToString(), and UNIT_MASK_MINION.

Referenced by Unit::_ExitVehicle(), Dismiss(), and Unit::RemoveVehicleKit().

Friends And Related Symbol Documentation

◆ Unit::CreateVehicleKit

bool Unit::CreateVehicleKit ( uint32  id,
uint32  creatureEntry 
)
friend

◆ Unit::RemoveVehicleKit

void Unit::RemoveVehicleKit ( )
friend

Member Data Documentation

◆ _accessoriesInstalled

bool Vehicle::_accessoriesInstalled
private

Referenced by InstallAllAccessories(), and Uninstall().

◆ _boardableByPlayers

bool Vehicle::_boardableByPlayers
private

◆ _creatureEntry

uint32 Vehicle::_creatureEntry
private

Referenced by GetCreatureEntry().

◆ _me

◆ _status

Status Vehicle::_status
private

◆ _usableSeatNum

uint32 Vehicle::_usableSeatNum
private

◆ _vehicleInfo

VehicleEntry const* Vehicle::_vehicleInfo
private

◆ Seats


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