Skip to content

Commit

Permalink
Vehicles: Add Passenger Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
insunaa committed Jan 12, 2024
1 parent bbd0e8d commit 43c9dcc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/game/AI/BaseAI/UnitAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ class UnitAI : public CombatActions
virtual void RequestFollow(Unit* /*followee*/) {}
virtual void RelinquishFollow(ObjectGuid /*follower*/) {}

// Vehicle Hooks
virtual void OnPassengerRide(Unit* passenger, bool boarded, uint8 seat) {}
virtual void OnVehicleRide(Unit* vehicle, bool boarded, uint8 seat) {}

protected:
virtual std::string GetAIName() { return "UnitAI"; }
void DespawnGuids(GuidVector& spawns); // despawns all creature guids and clears contents
Expand Down
28 changes: 27 additions & 1 deletion src/game/Entities/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ void VehicleInfo::Board(Unit* passenger, uint8 seat)

// Apply passenger modifications
ApplySeatMods(passenger, seatEntry->m_flags);

if (Unit* owner = dynamic_cast<Unit*>(m_owner))
{
if (owner->AI())
owner->AI()->OnPassengerRide(passenger, true, seat);
if (passenger->AI())
passenger->AI()->OnVehicleRide(owner, true, seat);
}
}

void VehicleInfo::ChangeSeat(Unit* passenger, uint8 currentSeat, bool next)
Expand Down Expand Up @@ -438,6 +446,14 @@ void VehicleInfo::SwitchSeat(Unit* passenger, uint8 seat)

// Apply passenger modifications of the new seat
ApplySeatMods(passenger, seatEntry->m_flags);

if (Unit* owner = dynamic_cast<Unit*>(m_owner))
{
if (owner->AI())
owner->AI()->OnPassengerRide(passenger, true, seat);
if (passenger->AI())
passenger->AI()->OnVehicleRide(owner, true, seat);
}
}

/**
Expand All @@ -457,7 +473,9 @@ void VehicleInfo::UnBoard(Unit* passenger, bool changeVehicle)

DEBUG_LOG("VehicleInfo::Unboard: passenger: %s", passenger->GetGuidStr().c_str());

VehicleSeatEntry const* seatEntry = GetSeatEntry(itr->second->GetTransportSeat());
uint8 seat = itr->second->GetTransportSeat();

VehicleSeatEntry const* seatEntry = GetSeatEntry(seat);
MANGOS_ASSERT(seatEntry);

UnBoardPassenger(passenger); // Use TransportBase to remove the passenger from storage list
Expand Down Expand Up @@ -542,6 +560,14 @@ void VehicleInfo::UnBoard(Unit* passenger, bool changeVehicle)
((Creature*)m_owner)->ForcedDespawn(1000);
}
}

if (Unit* owner = dynamic_cast<Unit*>(m_owner))
{
if (owner->AI())
owner->AI()->OnPassengerRide(passenger, false, seat);
if (passenger->AI())
passenger->AI()->OnVehicleRide(owner, false, seat);
}
}

/**
Expand Down

0 comments on commit 43c9dcc

Please sign in to comment.