Skip to content

Commit

Permalink
Add "flyingcomponents" special world property (PR #3597)
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Jan 10, 2025
1 parent f3b3013 commit 5ee6414
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6044,6 +6044,9 @@ bool CClientGame::SetWorldSpecialProperty(WorldSpecialProperty property, bool is
case WorldSpecialProperty::IGNOREFIRESTATE:
g_pGame->SetIgnoreFireStateEnabled(isEnabled);
break;
case WorldSpecialProperty::FLYINGCOMPONENTS:
m_pVehicleManager->SetSpawnFlyingComponentEnabled(isEnabled);
break;
default:
return false;
}
Expand Down Expand Up @@ -6094,6 +6097,8 @@ bool CClientGame::IsWorldSpecialProperty(WorldSpecialProperty property)
return g_pGame->IsTunnelWeatherBlendEnabled();
case WorldSpecialProperty::IGNOREFIRESTATE:
return g_pGame->IsIgnoreFireStateEnabled();
case WorldSpecialProperty::FLYINGCOMPONENTS:
return m_pVehicleManager->IsSpawnFlyingComponentEnabled();
}
return false;
}
Expand Down
11 changes: 7 additions & 4 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,12 @@ void CClientVehicle::Fix()

SFixedArray<unsigned char, MAX_DOORS> ucDoorStates;
GetInitialDoorStates(ucDoorStates);

bool flyingComponents = m_pVehicleManager->IsSpawnFlyingComponentEnabled();
for (int i = 0; i < MAX_DOORS; i++)
SetDoorStatus(i, ucDoorStates[i], true);
SetDoorStatus(i, ucDoorStates[i], flyingComponents);
for (int i = 0; i < MAX_PANELS; i++)
SetPanelStatus(i, 0);
SetPanelStatus(i, 0, flyingComponents);
for (int i = 0; i < MAX_LIGHTS; i++)
SetLightStatus(i, 0);
for (int i = 0; i < MAX_WHEELS; i++)
Expand Down Expand Up @@ -2170,11 +2172,12 @@ void CClientVehicle::StreamedInPulse()
{
// Set the damage model doors
CDamageManager* pDamageManager = m_pVehicle->GetDamageManager();
bool flyingComponents = m_pVehicleManager->IsSpawnFlyingComponentEnabled();

for (int i = 0; i < MAX_DOORS; i++)
pDamageManager->SetDoorStatus(static_cast<eDoors>(i), m_ucDoorStates[i], true);
pDamageManager->SetDoorStatus(static_cast<eDoors>(i), m_ucDoorStates[i], flyingComponents);
for (int i = 0; i < MAX_PANELS; i++)
pDamageManager->SetPanelStatus(static_cast<ePanels>(i), m_ucPanelStates[i]);
pDamageManager->SetPanelStatus(static_cast<ePanels>(i), m_ucPanelStates[i], flyingComponents);
for (int i = 0; i < MAX_LIGHTS; i++)
pDamageManager->SetLightStatus(static_cast<eLights>(i), m_ucLightStates[i]);
}
Expand Down
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ class CClientVehicleManager
void OnCreation(CClientVehicle* pVehicle);
void OnDestruction(CClientVehicle* pVehicle);

bool IsSpawnFlyingComponentEnabled() const noexcept { return m_spawnFlyingComponentsDuringRecreate; }
void SetSpawnFlyingComponentEnabled(bool isEnabled) noexcept { m_spawnFlyingComponentsDuringRecreate = isEnabled; }

protected:
CClientManager* m_pManager;
bool m_bCanRemoveFromList;
CMappedArray<CClientVehicle*> m_List;
CMappedArray<CClientVehicle*> m_StreamedIn;
bool m_spawnFlyingComponentsDuringRecreate{true};
};
5 changes: 3 additions & 2 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,18 +2243,19 @@ void CNetAPI::ReadVehiclePartsState(CClientVehicle* pVehicle, NetBitStreamInterf

SVehicleDamageSyncMethodeB damage;
BitStream.Read(&damage);
bool flyingComponents = m_pVehicleManager->IsSpawnFlyingComponentEnabled();

if (damage.data.bSyncDoors)
for (unsigned int i = 0; i < MAX_DOORS; ++i)
pVehicle->SetDoorStatus(i, damage.data.doors.data.ucStates[i], true);
pVehicle->SetDoorStatus(i, damage.data.doors.data.ucStates[i], flyingComponents);

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

if (damage.data.bSyncPanels)
for (unsigned int i = 0; i < MAX_PANELS; ++i)
pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i]);
pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i], flyingComponents);

if (damage.data.bSyncLights)
for (unsigned int i = 0; i < MAX_LIGHTS; ++i)
Expand Down
12 changes: 8 additions & 4 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,10 +1628,12 @@ void CPacketHandler::Packet_VehicleDamageSync(NetBitStreamInterface& bitStream)
CDeathmatchVehicle* pVehicle = static_cast<CDeathmatchVehicle*>(g_pClientGame->m_pVehicleManager->Get(ID));
if (pVehicle)
{
bool flyingComponents = g_pClientGame->IsWorldSpecialProperty(WorldSpecialProperty::FLYINGCOMPONENTS);

for (unsigned int i = 0; i < MAX_DOORS; ++i)
{
if (damage.data.bDoorStatesChanged[i])
pVehicle->SetDoorStatus(i, damage.data.ucDoorStates[i], true);
pVehicle->SetDoorStatus(i, damage.data.ucDoorStates[i], flyingComponents);
}
for (unsigned int i = 0; i < MAX_WHEELS; ++i)
{
Expand All @@ -1641,7 +1643,7 @@ void CPacketHandler::Packet_VehicleDamageSync(NetBitStreamInterface& bitStream)
for (unsigned int i = 0; i < MAX_PANELS; ++i)
{
if (damage.data.bPanelStatesChanged[i])
pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]);
pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], flyingComponents);
}
for (unsigned int i = 0; i < MAX_LIGHTS; ++i)
{
Expand Down Expand Up @@ -2398,6 +2400,7 @@ void CPacketHandler::Packet_MapInfo(NetBitStreamInterface& bitStream)
g_pClientGame->SetWorldSpecialProperty(WorldSpecialProperty::EXTENDEDWATERCANNONS, wsProps.data4.extendedwatercannons);
g_pClientGame->SetWorldSpecialProperty(WorldSpecialProperty::TUNNELWEATHERBLEND, wsProps.data5.tunnelweatherblend);
g_pClientGame->SetWorldSpecialProperty(WorldSpecialProperty::IGNOREFIRESTATE, wsProps.data6.ignoreFireState);
g_pClientGame->SetWorldSpecialProperty(WorldSpecialProperty::FLYINGCOMPONENTS, wsProps.data7.flyingcomponents);

float fJetpackMaxHeight = 100;
if (!bitStream.Read(fJetpackMaxHeight))
Expand Down Expand Up @@ -3391,13 +3394,14 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
pVehicle->SetPaintjob(paintjob.data.ucPaintjob);
pVehicle->SetColor(vehColor);

bool flyingComponents = g_pClientGame->IsWorldSpecialProperty(WorldSpecialProperty::FLYINGCOMPONENTS);
// Setup our damage model
for (int i = 0; i < MAX_DOORS; i++)
pVehicle->SetDoorStatus(i, damage.data.ucDoorStates[i], true);
pVehicle->SetDoorStatus(i, damage.data.ucDoorStates[i], flyingComponents);
for (int i = 0; i < MAX_WHEELS; i++)
pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i]);
for (int i = 0; i < MAX_PANELS; i++)
pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]);
pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], flyingComponents);
for (int i = 0; i < MAX_LIGHTS; i++)
pVehicle->SetLightStatus(i, damage.data.ucLightStates[i]);
pVehicle->ResetDamageModelSync();
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ CGame::CGame() : m_FloodProtect(4, 30000, 30000) // Max of 4 connecti
m_WorldSpecialProps[WorldSpecialProperty::ROADSIGNSTEXT] = true;
m_WorldSpecialProps[WorldSpecialProperty::TUNNELWEATHERBLEND] = true;
m_WorldSpecialProps[WorldSpecialProperty::IGNOREFIRESTATE] = false;
m_WorldSpecialProps[WorldSpecialProperty::FLYINGCOMPONENTS] = true;

m_JetpackWeapons[WEAPONTYPE_MICRO_UZI] = true;
m_JetpackWeapons[WEAPONTYPE_TEC9] = true;
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/packets/CMapInfoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ bool CMapInfoPacket::Write(NetBitStreamInterface& BitStream) const
wsProps.data4.extendedwatercannons = g_pGame->IsWorldSpecialPropertyEnabled(WorldSpecialProperty::EXTENDEDWATERCANNONS);
wsProps.data5.tunnelweatherblend = g_pGame->IsWorldSpecialPropertyEnabled(WorldSpecialProperty::TUNNELWEATHERBLEND);
wsProps.data6.ignoreFireState = g_pGame->IsWorldSpecialPropertyEnabled(WorldSpecialProperty::IGNOREFIRESTATE);
wsProps.data7.flyingcomponents = g_pGame->IsWorldSpecialPropertyEnabled(WorldSpecialProperty::FLYINGCOMPONENTS);
BitStream.Write(&wsProps);
}

Expand Down
1 change: 1 addition & 0 deletions Shared/mods/deathmatch/logic/Enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ADD_ENUM(WorldSpecialProperty::EXTENDEDWATERCANNONS, "extendedwatercannons")
ADD_ENUM(WorldSpecialProperty::ROADSIGNSTEXT, "roadsignstext")
ADD_ENUM(WorldSpecialProperty::TUNNELWEATHERBLEND, "tunnelweatherblend")
ADD_ENUM(WorldSpecialProperty::IGNOREFIRESTATE, "ignorefirestate")
ADD_ENUM(WorldSpecialProperty::FLYINGCOMPONENTS, "flyingcomponents")
IMPLEMENT_ENUM_CLASS_END("world-special-property")

IMPLEMENT_ENUM_BEGIN(ePacketID)
Expand Down
1 change: 1 addition & 0 deletions Shared/mods/deathmatch/logic/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum class WorldSpecialProperty
EXTENDEDWATERCANNONS,
TUNNELWEATHERBLEND,
IGNOREFIRESTATE,
FLYINGCOMPONENTS,
};
DECLARE_ENUM_CLASS(WorldSpecialProperty);

Expand Down
20 changes: 19 additions & 1 deletion Shared/sdk/net/SyncStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,10 @@ struct SWorldSpecialPropertiesStateSync : public ISyncStructure
{
BITCOUNT6 = 1
};
enum
{
BITCOUNT7 = 1
};

bool Read(NetBitStreamInterface& bitStream)
{
Expand Down Expand Up @@ -2103,7 +2107,12 @@ struct SWorldSpecialPropertiesStateSync : public ISyncStructure
isOK &= bitStream.ReadBits(reinterpret_cast<char*>(&data6), BITCOUNT6);
else
data6.ignoreFireState = false;


if (bitStream.Can(eBitStreamVersion::WorldSpecialProperty_FlyingComponents))
isOK &= bitStream.ReadBits(reinterpret_cast<char*>(&data7), BITCOUNT7);
else
data7.flyingcomponents = true;

//// Example for adding item:
// if (bitStream.Can(eBitStreamVersion::YourProperty))
// isOK &= bitStream.ReadBits(reinterpret_cast<char*>(&data9), BITCOUNT9);
Expand All @@ -2130,6 +2139,9 @@ struct SWorldSpecialPropertiesStateSync : public ISyncStructure
if (bitStream.Can(eBitStreamVersion::WorldSpecialProperty_IgnoreFireState))
bitStream.WriteBits(reinterpret_cast<const char*>(&data6), BITCOUNT6);

if (bitStream.Can(eBitStreamVersion::WorldSpecialProperty_FlyingComponents))
bitStream.WriteBits(reinterpret_cast<const char*>(&data7), BITCOUNT7);

//// Example for adding item:
// if (bitStream.Can(eBitStreamVersion::YourProperty))
// bitStream.WriteBits(reinterpret_cast<const char*>(&data9), BITCOUNT9);
Expand Down Expand Up @@ -2177,6 +2189,11 @@ struct SWorldSpecialPropertiesStateSync : public ISyncStructure
bool ignoreFireState : 1;
} data6;

struct
{
bool flyingcomponents : 1;
} data7;

SWorldSpecialPropertiesStateSync()
{
// Set default states
Expand All @@ -2197,6 +2214,7 @@ struct SWorldSpecialPropertiesStateSync : public ISyncStructure
data4.extendedwatercannons = true;
data5.tunnelweatherblend = true;
data6.ignoreFireState = false;
data7.flyingcomponents = true;
}
};

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 @@ -556,7 +556,7 @@ enum class eBitStreamVersion : unsigned short
// 2024-06-16
PedSync_Revision,

// Add "extendedwatercannons" to setWorldSpecialPropertyEnabled
// Add "tunnelweatherblend" to setWorldSpecialPropertyEnabled
// 2024-06-30
WorldSpecialProperty_TunnelWeatherBlend,

Expand Down Expand Up @@ -604,6 +604,10 @@ enum class eBitStreamVersion : unsigned short
// 2025-01-09
IsPedReloadingWeapon,

// Add "flyingcomponents" to setWorldSpecialPropertyEnabled
// 2025-01-10
WorldSpecialProperty_FlyingComponents,

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

0 comments on commit 5ee6414

Please sign in to comment.