Skip to content

Commit

Permalink
[12172] Implement Vehicle Seat Switching. Patch based on work of a lo…
Browse files Browse the repository at this point in the history
…ng history

Signed-off-by: Schmoozerd <schmoozerd@cmangos>
  • Loading branch information
kid10 authored and Schmoozerd committed Sep 14, 2012
1 parent 35870e8 commit dab63d9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/game/DBCEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ enum VehicleFlags
VEHICLE_FLAG_CUSTOM_PITCH = 0x00000040, // If set use pitchMin and pitchMax from DBC, otherwise pitchMin = -pi/2, pitchMax = pi/2
VEHICLE_FLAG_ADJUST_AIM_ANGLE = 0x00000400, // Lua_IsVehicleAimAngleAdjustable
VEHICLE_FLAG_ADJUST_AIM_POWER = 0x00000800, // Lua_IsVehicleAimPowerAdjustable
VEHICLE_FLAG_DISABLE_SWITCH = 0x00400000, // Can't change seats, VEHICLE_ID = 335 chopper
};

enum VehicleSeatFlags
Expand Down
48 changes: 46 additions & 2 deletions src/game/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Currently implemented
* - TODO Board
* - Unboard to unboard a passenger from the vehicle
* - TODO Switch
* - SwitchSeat to switch to another seat of the same vehicle
* - CanBoard to check if a passenger can board a vehicle
* - Internal helper to set the controlling and spells for a vehicle's seat
* - Internal helper to control the available seats of a vehicle
Expand Down Expand Up @@ -93,14 +93,58 @@ void VehicleInfo::Board(Unit* passenger, uint8 seat)
}

/**
* This function will switch the seat of a passenger
* This function will switch the seat of a passenger on the same vehicle
*
* @param passenger MUST be provided. This Unit will change its seat on the vehicle
* @param seat Seat to which the passenger will be switched
*/
void VehicleInfo::SwitchSeat(Unit* passenger, uint8 seat)
{
MANGOS_ASSERT(passenger);

DEBUG_LOG("VehicleInfo::SwitchSeat: passenger: %s try to switch to seat %u", passenger->GetGuidStr().c_str(), seat);

// Switching seats is not possible
if (m_vehicleEntry->m_flags & VEHICLE_FLAG_DISABLE_SWITCH)
return;

PassengerMap::const_iterator itr = m_passengers.find(passenger);
MANGOS_ASSERT(itr != m_passengers.end());

// We are already boarded to this seat
if (itr->second->GetTransportSeat() == seat)
return;

// Check if it's a valid seat
if (!IsSeatAvailableFor(passenger, seat))
return;

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

// Switching seats is only allowed if this flag is set
if (~seatEntry->m_flags & SEAT_FLAG_CAN_SWITCH)
return;

// Remove passenger modifications of the old seat
RemoveSeatMods(passenger, seatEntry->m_flags);

// Set to new seat
itr->second->SetTransportSeat(seat);

Movement::MoveSplineInit init(*passenger);
init.MoveTo(0.0f, 0.0f, 0.0f); // ToDo: Set correct local coords
//if (oldorientation != neworientation) (?)
//init.SetFacing(0.0f); // local orientation ? ToDo: Set proper orientation!
// It seems that Seat switching is sent without SplineFlag BoardVehicle
init.Launch();

// Get seatEntry of new seat
seatEntry = GetSeatEntry(seat);
MANGOS_ASSERT(seatEntry);

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

/**
Expand Down
41 changes: 41 additions & 0 deletions src/game/VehicleHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ void WorldSession::HandleRequestVehicleSwitchSeat(WorldPacket& recvPacket)

recvPacket >> vehicleGuid.ReadAsPacked();
recvPacket >> seat;

TransportInfo* transportInfo = _player->GetTransportInfo();
if (!transportInfo || !transportInfo->IsOnVehicle())
return;

Unit* vehicle = (Unit*)transportInfo->GetTransport();

// Something went wrong
if (vehicleGuid != vehicle->GetObjectGuid())
return;

vehicle->GetVehicleInfo()->SwitchSeat(_player, seat);
}

void WorldSession::HandleChangeSeatsOnControlledVehicle(WorldPacket& recvPacket)
Expand All @@ -89,4 +101,33 @@ void WorldSession::HandleChangeSeatsOnControlledVehicle(WorldPacket& recvPacket)
recvPacket >> movementInfo; // Not used at the moment
recvPacket >> destVehicleGuid.ReadAsPacked();
recvPacket >> seat;

TransportInfo* transportInfo = _player->GetTransportInfo();
if (!transportInfo || !transportInfo->IsOnVehicle())
return;

Unit* srcVehicle = (Unit*)transportInfo->GetTransport();

// Something went wrong
if (srcVehicleGuid != srcVehicle->GetObjectGuid())
return;

if (srcVehicleGuid != destVehicleGuid)
{
Unit* destVehicle = _player->GetMap()->GetUnit(destVehicleGuid);

if (!destVehicle || !destVehicle->IsVehicle())
return;

// Change vehicle is not possible
if (destVehicle->GetVehicleInfo()->GetVehicleEntry()->m_flags & VEHICLE_FLAG_DISABLE_SWITCH)
return;

SpellClickInfoMapBounds clickPair = sObjectMgr.GetSpellClickInfoMapBounds(destVehicle->GetEntry());
for (SpellClickInfoMap::const_iterator itr = clickPair.first; itr != clickPair.second; ++itr)
if (itr->second.IsFitToRequirements(_player))
_player->CastSpell(destVehicle, itr->second.spellId, true);
}
else
srcVehicle->GetVehicleInfo()->SwitchSeat(_player, seat);
}
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12171"
#define REVISION_NR "12172"
#endif // __REVISION_NR_H__

0 comments on commit dab63d9

Please sign in to comment.