Skip to content

Add spawnFlyingComponent argument to setVehicleWheelStates() #2128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Client/game_sa/CDamageManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ BYTE CDamageManagerSA::GetWheelStatus(eWheelPosition bWheel)
return NULL;
}

VOID CDamageManagerSA::SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus)
VOID CDamageManagerSA::SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus, bool spawnFlyingComponent)
{
DEBUG_TRACE("VOID CDamageManagerSA::SetWheelStatus ( eWheelPosition bWheel, BYTE bTireStatus )");
if (bWheel < MAX_WHEELS)
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CDamageManagerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CDamageManagerSA : public CDamageManager
BYTE GetDoorStatus(eDoors bDoor);
VOID SetDoorStatus(eDoors bDoor, BYTE bDoorStatus, bool spawnFlyingComponent);
BYTE GetWheelStatus(eWheelPosition bWheel);
VOID SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus);
VOID SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus, bool spawnFlyingComponent);
BYTE GetPanelStatus(BYTE bPanel);
unsigned long GetPanelStatus();
VOID SetPanelStatus(BYTE bPanel, BYTE bPanelStatus);
Expand Down
16 changes: 8 additions & 8 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,10 +2642,10 @@ void CVehicleSA::UpdateLandingGearPosition()
fGearPosition = 0.0f;

// Remove Wheels
m_pDamageManager->SetWheelStatus(FRONT_LEFT_WHEEL, 0);
m_pDamageManager->SetWheelStatus(FRONT_RIGHT_WHEEL, 0);
m_pDamageManager->SetWheelStatus(REAR_LEFT_WHEEL, 0);
m_pDamageManager->SetWheelStatus(REAR_RIGHT_WHEEL, 0);
m_pDamageManager->SetWheelStatus(FRONT_LEFT_WHEEL, 0, false);
m_pDamageManager->SetWheelStatus(FRONT_RIGHT_WHEEL, 0, false);
m_pDamageManager->SetWheelStatus(REAR_LEFT_WHEEL, 0, false);
m_pDamageManager->SetWheelStatus(REAR_RIGHT_WHEEL, 0, false);

// Update Air Resistance
float fDragCoeff = GetHandlingData()->GetDragCoeff();
Expand All @@ -2664,10 +2664,10 @@ void CVehicleSA::UpdateLandingGearPosition()
// C++ Representaion of CPlane::SetLandingGearDown (006CAC20)

// Recreate Wheels
m_pDamageManager->SetWheelStatus(FRONT_LEFT_WHEEL, 2);
m_pDamageManager->SetWheelStatus(FRONT_RIGHT_WHEEL, 2);
m_pDamageManager->SetWheelStatus(REAR_LEFT_WHEEL, 2);
m_pDamageManager->SetWheelStatus(REAR_RIGHT_WHEEL, 2);
m_pDamageManager->SetWheelStatus(FRONT_LEFT_WHEEL, 2, false);
m_pDamageManager->SetWheelStatus(FRONT_RIGHT_WHEEL, 2, false);
m_pDamageManager->SetWheelStatus(REAR_LEFT_WHEEL, 2, false);
m_pDamageManager->SetWheelStatus(REAR_RIGHT_WHEEL, 2, false);

// Update Air Resistance
float fDragCoeff = GetHandlingData()->GetDragCoeff();
Expand Down
27 changes: 24 additions & 3 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ void CClientVehicle::Fix()
for (int i = 0; i < MAX_LIGHTS; i++)
SetLightStatus(i, 0);
for (int i = 0; i < MAX_WHEELS; i++)
SetWheelStatus(i, 0);
SetWheelStatus(i, 0, false);

// These components get a funny rotation when calling Fix() (unknown reason)
struct
Expand Down Expand Up @@ -1563,7 +1563,7 @@ void CClientVehicle::SetDoorStatus(unsigned char ucDoor, unsigned char ucStatus,
}
}

void CClientVehicle::SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent)
void CClientVehicle::SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent, bool spawnFlyingComponent)
{
if (ucWheel < MAX_WHEELS)
{
Expand All @@ -1581,7 +1581,28 @@ void CClientVehicle::SetWheelStatus(unsigned char ucWheel, unsigned char ucStatu
// Do we have a damage model?
if (HasDamageModel())
{
m_pVehicle->GetDamageManager()->SetWheelStatus((eWheelPosition)(ucWheel), ucGTAStatus);
m_pVehicle->GetDamageManager()->SetWheelStatus((eWheelPosition)(ucWheel), ucGTAStatus, spawnFlyingComponent);

if (spawnFlyingComponent && ucStatus == DT_WHEEL_MISSING)
{
switch (ucWheel)
{
case FRONT_LEFT_WHEEL:
m_pVehicle->SpawnFlyingComponent(5, 1);
break;
case REAR_LEFT_WHEEL:
m_pVehicle->SpawnFlyingComponent(7, 1);
break;
case FRONT_RIGHT_WHEEL:
m_pVehicle->SpawnFlyingComponent(2, 1);
break;
case REAR_RIGHT_WHEEL:
m_pVehicle->SpawnFlyingComponent(4, 1);
break;
default:
break;
}
}

// Update the wheel's visibility
m_pVehicle->SetWheelVisibility((eWheelPosition)ucWheel, (ucStatus != DT_WHEEL_MISSING));
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class CClientVehicle : public CClientStreamElement
bool AreLightsOn();

void SetDoorStatus(unsigned char ucDoor, unsigned char ucStatus, bool spawnFlyingComponent);
void SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent = true);
void SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent = true, bool spawnFlyingComponent = false);
void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus);
void SetLightStatus(unsigned char ucLight, unsigned char ucStatus);
bool GetWheelMissing(unsigned char ucWheel, const SString& strWheelName = "");
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ void CNetAPI::ReadVehiclePartsState(CClientVehicle* pVehicle, NetBitStreamInterf

if (damage.data.bSyncWheels)
for (unsigned int i = 0; i < MAX_WHEELS; ++i)
pVehicle->SetWheelStatus(i, damage.data.wheels.data.ucStates[i]);
pVehicle->SetWheelStatus(i, damage.data.wheels.data.ucStates[i], false);

if (damage.data.bSyncPanels)
for (unsigned int i = 0; i < MAX_PANELS; ++i)
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ void CPacketHandler::Packet_VehicleDamageSync(NetBitStreamInterface& bitStream)
for (unsigned int i = 0; i < MAX_WHEELS; ++i)
{
if (damage.data.bWheelStatesChanged[i])
pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i]);
pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i], false);
}
for (unsigned int i = 0; i < MAX_PANELS; ++i)
{
Expand Down Expand Up @@ -3264,7 +3264,7 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
for (int i = 0; i < MAX_DOORS; i++)
pVehicle->SetDoorStatus(i, damage.data.ucDoorStates[i], true);
for (int i = 0; i < MAX_WHEELS; i++)
pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i]);
pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i], false);
for (int i = 0; i < MAX_PANELS; i++)
pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]);
for (int i = 0; i < MAX_LIGHTS; i++)
Expand Down
12 changes: 6 additions & 6 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3042,9 +3042,9 @@ bool CStaticFunctionDefinitions::SetVehicleDoorState(CClientEntity& Entity, unsi
return false;
}

bool CStaticFunctionDefinitions::SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft, int iFrontRight, int iRearRight)
bool CStaticFunctionDefinitions::SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft, int iFrontRight, int iRearRight, bool spawnFlyingComponent)
{
RUN_CHILDREN(SetVehicleWheelStates(**iter, iFrontLeft, iRearLeft, iFrontRight, iRearRight))
RUN_CHILDREN(SetVehicleWheelStates(**iter, iFrontLeft, iRearLeft, iFrontRight, iRearRight, spawnFlyingComponent))

if (IS_VEHICLE(&Entity))
{
Expand All @@ -3069,10 +3069,10 @@ bool CStaticFunctionDefinitions::SetVehicleWheelStates(CClientEntity& Entity, in
// If atleast 1 wheel state is different
if (ucNewFrontLeft != ucFrontLeft || ucNewRearLeft != ucRearLeft || ucNewFrontRight != ucFrontRight || ucNewRearRight != ucRearRight)
{
Vehicle.SetWheelStatus(FRONT_LEFT_WHEEL, ucNewFrontLeft, false);
Vehicle.SetWheelStatus(REAR_LEFT_WHEEL, ucNewRearLeft, false);
Vehicle.SetWheelStatus(FRONT_RIGHT_WHEEL, ucNewFrontRight, false);
Vehicle.SetWheelStatus(REAR_RIGHT_WHEEL, ucNewRearRight, false);
Vehicle.SetWheelStatus(FRONT_LEFT_WHEEL, ucNewFrontLeft, false, spawnFlyingComponent);
Vehicle.SetWheelStatus(REAR_LEFT_WHEEL, ucNewRearLeft, false, spawnFlyingComponent);
Vehicle.SetWheelStatus(FRONT_RIGHT_WHEEL, ucNewFrontRight, false, spawnFlyingComponent);
Vehicle.SetWheelStatus(REAR_RIGHT_WHEEL, ucNewRearRight, false, spawnFlyingComponent);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class CStaticFunctionDefinitions
static bool AddAllVehicleUpgrades(CClientEntity& Entity);
static bool RemoveVehicleUpgrade(CClientEntity& Entity, unsigned short usUpgrade);
static bool SetVehicleDoorState(CClientEntity& Entity, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent);
static bool SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1);
static bool SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1, bool spawnFlyingComponent = false);
static bool SetVehicleLightState(CClientEntity& Entity, unsigned char ucLight, unsigned char ucState);
static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState);
static bool SetVehicleOverrideLights(CClientEntity& Entity, unsigned char ucLights);
Expand Down
4 changes: 3 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,16 +1894,18 @@ int CLuaVehicleDefs::SetVehicleWheelStates(lua_State* luaVM)
CClientEntity* pEntity = NULL;
int iFrontLeft = -1;
int iRearLeft = -1, iFrontRight = -1, iRearRight = -1;
bool spawnFlyingComponent = false;
CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pEntity);
argStream.ReadNumber(iFrontLeft);
argStream.ReadNumber(iRearLeft, -1);
argStream.ReadNumber(iFrontRight, -1);
argStream.ReadNumber(iRearRight, -1);
argStream.ReadBool(spawnFlyingComponent, false);

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetVehicleWheelStates(*pEntity, iFrontLeft, iRearLeft, iFrontRight, iRearRight))
if (CStaticFunctionDefinitions::SetVehicleWheelStates(*pEntity, iFrontLeft, iRearLeft, iFrontRight, iRearRight, spawnFlyingComponent))
{
lua_pushboolean(luaVM, true);
return 1;
Expand Down
15 changes: 12 additions & 3 deletions Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,15 @@ void CVehicleRPCs::SetVehicleDamageState(CClientEntity* pSource, NetBitStreamInt
unsigned char ucWheel, ucState;
if (bitStream.Read(ucWheel) && bitStream.Read(ucState))
{
pVehicle->SetWheelStatus(ucWheel, ucState, false);
bool spawnFlyingComponent = false;

if (bitStream.Can(eBitStreamVersion::setVehicleWheelStates_SpawnFlyingComponent))
{
if (!bitStream.ReadBit(spawnFlyingComponent))
break;
}

pVehicle->SetWheelStatus(ucWheel, ucState, false, spawnFlyingComponent);
}
break;
}
Expand Down Expand Up @@ -433,13 +441,14 @@ void CVehicleRPCs::SetVehicleFuelTankExplodable(CClientEntity* pSource, NetBitSt
void CVehicleRPCs::SetVehicleWheelStates(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
unsigned char ucWheelStates[MAX_WHEELS];
if (bitStream.Read((char*)ucWheelStates, MAX_WHEELS))
bool spawnFlyingComponent = false;
if (bitStream.Read((char*)ucWheelStates, MAX_WHEELS) && (!bitStream.Can(eBitStreamVersion::setVehicleWheelStates_SpawnFlyingComponent) || bitStream.ReadBit(spawnFlyingComponent)))
{
CClientVehicle* pVehicle = m_pVehicleManager->Get(pSource->GetID());
if (pVehicle)
{
for (int i = 0; i < MAX_WHEELS; i++)
pVehicle->SetWheelStatus(i, ucWheelStates[i], false);
pVehicle->SetWheelStatus(i, ucWheelStates[i], false, spawnFlyingComponent);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CDamageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class CDamageManager
virtual BYTE GetDoorStatus(eDoors bDoor) = 0;
virtual VOID SetDoorStatus(eDoors bDoor, BYTE bDoorStatus, bool spawnFlyingComponent) = 0;
virtual BYTE GetWheelStatus(eWheelPosition bTire) = 0;
virtual VOID SetWheelStatus(eWheelPosition bTire, BYTE bTireStatus) = 0;
virtual VOID SetWheelStatus(eWheelPosition bTire, BYTE bTireStatus, bool spawnFlyingComponent) = 0;
virtual BYTE GetPanelStatus(BYTE bPanel) = 0;
virtual unsigned long GetPanelStatus() = 0;
virtual VOID SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) = 0;
Expand Down
5 changes: 3 additions & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6545,10 +6545,10 @@ bool CStaticFunctionDefinitions::SetVehicleDoorState(CElement* pElement, unsigne
return false;
}

bool CStaticFunctionDefinitions::SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft, int iFrontRight, int iRearRight)
bool CStaticFunctionDefinitions::SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft, int iFrontRight, int iRearRight, bool spawnFlyingComponent)
{
assert(pElement);
RUN_CHILDREN(SetVehicleWheelStates(*iter, iFrontLeft, iRearLeft, iFrontRight, iRearRight))
RUN_CHILDREN(SetVehicleWheelStates(*iter, iFrontLeft, iRearLeft, iFrontRight, iRearRight, spawnFlyingComponent))

unsigned char a = -1;
if (a == (unsigned char)-1)
Expand Down Expand Up @@ -6577,6 +6577,7 @@ bool CStaticFunctionDefinitions::SetVehicleWheelStates(CElement* pElement, int i

CBitStream BitStream;
BitStream.pBitStream->Write((const char*)&pVehicle->m_ucWheelStates[0], MAX_WHEELS);
BitStream.pBitStream->WriteBit(spawnFlyingComponent);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_WHEEL_STATES, *BitStream.pBitStream));

return true;
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class CStaticFunctionDefinitions
static bool AddAllVehicleUpgrades(CElement* pElement);
static bool RemoveVehicleUpgrade(CElement* pElement, unsigned short usUpgrade);
static bool SetVehicleDoorState(CElement* pElement, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent);
static bool SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1);
static bool SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1, bool spawnFlyingComponent = false);
static bool SetVehicleLightState(CElement* pElement, unsigned char ucLight, unsigned char ucState);
static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState);
static bool SetVehicleIdleRespawnDelay(CElement* pElement, unsigned long ulTime);
Expand Down
4 changes: 3 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,7 @@ int CLuaVehicleDefs::SetVehicleWheelStates(lua_State* luaVM)
int iRearLeft;
int iFrontRight;
int iRearRight;
bool spawnFlyingComponent;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
Expand All @@ -2061,7 +2062,7 @@ int CLuaVehicleDefs::SetVehicleWheelStates(lua_State* luaVM)

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetVehicleWheelStates(pElement, iFrontLeft, iRearLeft, iFrontRight, iRearRight))
if (CStaticFunctionDefinitions::SetVehicleWheelStates(pElement, iFrontLeft, iRearLeft, iFrontRight, iRearRight, spawnFlyingComponent))
{
lua_pushboolean(luaVM, true);
return 1;
Expand Down Expand Up @@ -2105,6 +2106,7 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM)
CElement* pElement;
unsigned char ucPanel;
unsigned char ucState;
bool spawnFlyingComponent;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
Expand Down
6 changes: 5 additions & 1 deletion Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,14 @@ enum class eBitStreamVersion : unsigned short
// Implement entering/exiting/jacking for peds #1748
// 2020-11-10 0x71
PedEnterExit,

// Add height for colpolygon (#1908)
// 2021-01-16 0x72
SetColPolygonHeight,

// Add argument to enable the spawn of a flying component when damaging a wheel
// 2021-03-17 0x73
setVehicleWheelStates_SpawnFlyingComponent,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Expand Down