Skip to content

Commit 6a115c7

Browse files
Synchronize changes from 1.6 master branch [ci skip]
7ad96e2 Add new functions is/setElementOnFire (PR #3783, Fixes #3673)
2 parents a4b4fad + 7ad96e2 commit 6a115c7

37 files changed

+240
-63
lines changed

Client/game_sa/CEntitySA.h

+3
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ class CEntitySA : public virtual CEntity
334334
bool GetBonePosition(eBone boneId, CVector& position);
335335
bool SetBonePosition(eBone boneId, const CVector& position);
336336

337+
bool IsOnFire() override { return false; }
338+
bool SetOnFire(bool onFire) override { return false; }
339+
337340
// CEntitySA interface
338341
virtual void OnChangingPosition(const CVector& vecNewPosition) {}
339342

Client/game_sa/CObjectSA.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "CPoolsSA.h"
1616
#include "CRopesSA.h"
1717
#include "CWorldSA.h"
18+
#include "CFireManagerSA.h"
1819

1920
extern CGameSA* pGame;
2021

@@ -304,3 +305,36 @@ void CObjectSA::ResetScale()
304305
{
305306
SetScale(1.0f, 1.0f, 1.0f);
306307
}
308+
309+
bool CObjectSA::SetOnFire(bool onFire)
310+
{
311+
CObjectSAInterface* objectInterface = GetObjectInterface();
312+
if (onFire == !!objectInterface->pFire)
313+
return false;
314+
315+
auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
316+
317+
if (onFire)
318+
{
319+
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
320+
if (!fire)
321+
return false;
322+
323+
fire->SetTarget(this);
324+
fire->SetStrength(1.0f);
325+
fire->Ignite();
326+
fire->SetNumGenerationsAllowed(0);
327+
328+
objectInterface->pFire = fire->GetInterface();
329+
}
330+
else
331+
{
332+
CFire* fire = fireManager->GetFire(objectInterface->pFire);
333+
if (!fire)
334+
return false;
335+
336+
fire->Extinguish();
337+
}
338+
339+
return true;
340+
}

Client/game_sa/CObjectSA.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class CObjectSA : public virtual CObject, public virtual CPhysicalSA
153153
CVector* GetScale();
154154
void ResetScale();
155155

156+
bool IsOnFire() override { return GetObjectInterface()->pFire != nullptr; }
157+
bool SetOnFire(bool onFire) override;
158+
156159
private:
157160
void CheckForGangTag();
158-
};
161+
};

Client/game_sa/CPedSA.cpp

+24-37
Original file line numberDiff line numberDiff line change
@@ -851,52 +851,39 @@ void CPedSA::SetBleeding(bool bBleeding)
851851
GetPedInterface()->pedFlags.bPedIsBleeding = bBleeding;
852852
}
853853

854-
bool CPedSA::IsOnFire()
855-
{
856-
if (GetPedInterface()->pFireOnPed != NULL)
857-
return true;
858-
return false;
859-
}
860-
861-
void CPedSA::SetOnFire(bool bOnFire)
854+
bool CPedSA::SetOnFire(bool onFire)
862855
{
863856
CPedSAInterface* pInterface = GetPedInterface();
857+
if (onFire == !!pInterface->pFireOnPed)
858+
return false;
864859

865-
if (bOnFire)
866-
{
867-
// If we are already on fire, don't apply a new fire
868-
if (pInterface->pFireOnPed == NULL)
869-
{
870-
CFireManagerSA* pFireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
871-
CFire* pFire = pFireManager->StartFire(this, NULL, (float)DEFAULT_FIRE_PARTICLE_SIZE);
860+
auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
872861

873-
if (pFire)
874-
{
875-
// Start the fire
876-
pFire->SetTarget(this);
877-
pFire->Ignite();
878-
pFire->SetStrength(1.0f);
879-
// Attach the fire only to the player, do not let it
880-
// create child fires when moving.
881-
pFire->SetNumGenerationsAllowed(0);
882-
pInterface->pFireOnPed = pFire->GetInterface();
883-
}
884-
}
862+
if (onFire)
863+
{
864+
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
865+
if (!fire)
866+
return false;
867+
868+
// Start the fire
869+
fire->SetTarget(this);
870+
fire->Ignite();
871+
fire->SetStrength(1.0f);
872+
// Attach the fire only to the player, do not let it
873+
// create child fires when moving.
874+
fire->SetNumGenerationsAllowed(0);
875+
pInterface->pFireOnPed = fire->GetInterface();
885876
}
886877
else
887878
{
888-
// Make sure that we have some attached fire
889-
if (pInterface->pFireOnPed != NULL)
890-
{
891-
CFireManagerSA* pFireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
892-
CFire* pFire = pFireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
879+
CFire* fire = fireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
880+
if (!fire)
881+
return false;
893882

894-
if (pFire)
895-
{
896-
pFire->Extinguish();
897-
}
898-
}
883+
fire->Extinguish();
899884
}
885+
886+
return true;
900887
}
901888

902889
void CPedSA::SetStayInSamePlace(bool bStay)

Client/game_sa/CPedSA.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
389389
bool IsBleeding();
390390
void SetBleeding(bool bBleeding);
391391

392-
bool IsOnFire();
393-
void SetOnFire(bool bOnFire);
392+
bool IsOnFire() override { return GetPedInterface()->pFireOnPed != nullptr; }
393+
bool SetOnFire(bool onFire) override;
394394

395395
bool GetStayInSamePlace() { return GetPedInterface()->pedFlags.bStayInSamePlace; }
396396
void SetStayInSamePlace(bool bStay);

Client/game_sa/CVehicleSA.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "CVisibilityPluginsSA.h"
2727
#include "CWorldSA.h"
2828
#include "gamesa_renderware.h"
29+
#include "CFireManagerSA.h"
2930

3031
extern CGameSA* pGame;
3132

@@ -1925,6 +1926,39 @@ void CVehicleSA::OnChangingPosition(const CVector& vecNewPosition)
19251926
}
19261927
}
19271928

1929+
bool CVehicleSA::SetOnFire(bool onFire)
1930+
{
1931+
CVehicleSAInterface* vehicleInterface = GetVehicleInterface();
1932+
if (onFire == !!vehicleInterface->m_pFire)
1933+
return false;
1934+
1935+
auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
1936+
1937+
if (onFire)
1938+
{
1939+
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
1940+
if (!fire)
1941+
return false;
1942+
1943+
fire->SetTarget(this);
1944+
fire->SetStrength(1.0f);
1945+
fire->Ignite();
1946+
fire->SetNumGenerationsAllowed(0);
1947+
1948+
vehicleInterface->m_pFire = fire->GetInterface();
1949+
}
1950+
else
1951+
{
1952+
CFire* fire = fireManager->GetFire(vehicleInterface->m_pFire);
1953+
if (!fire)
1954+
return false;
1955+
1956+
fire->Extinguish();
1957+
}
1958+
1959+
return true;
1960+
}
1961+
19281962
void CVehicleSA::StaticSetHooks()
19291963
{
19301964
// Setup vehicle sun glare hook

Client/game_sa/CVehicleSA.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class CVehicleSAInterface : public CPhysicalSAInterface
310310

311311
unsigned char m_nSpecialColModel;
312312
CEntity* pEntityWeAreOnForVisibilityCheck;
313-
CFire* m_pFire;
313+
CFireSAInterface* m_pFire;
314314

315315
float m_fSteerAngle; // +1172
316316
float m_f2ndSteerAngle; // used for steering 2nd set of wheels or elevators etc..
@@ -694,6 +694,9 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
694694
CVector* GetDummyPositions() { return m_dummyPositions.data(); }
695695
const CVector* GetDummyPositions() const override { return m_dummyPositions.data(); }
696696

697+
bool IsOnFire() override { return GetVehicleInterface()->m_pFire != nullptr; }
698+
bool SetOnFire(bool onFire) override;
699+
697700
static void StaticSetHooks();
698701
static void SetVehiclesSunGlareEnabled(bool bEnabled);
699702
static bool GetVehiclesSunGlareEnabled();

Client/mods/deathmatch/logic/CClientEntity.h

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ class CClientEntity : public CClientEntityBase
331331
bool CanBeDestroyedByScript() { return m_canBeDestroyedByScript; }
332332
void SetCanBeDestroyedByScript(bool canBeDestroyedByScript) { m_canBeDestroyedByScript = canBeDestroyedByScript; }
333333

334+
virtual bool IsOnFire() { return false; }
335+
virtual bool SetOnFire(bool onFire) { return false; }
336+
334337
protected:
335338
CClientManager* m_pManager;
336339
CClientEntity* m_pParent;

Client/mods/deathmatch/logic/CClientObject.h

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class CClientObject : public CClientStreamElement
119119
bool IsBeingRespawned() { return m_bBeingRespawned; };
120120
void SetBeingRespawned(bool bBeingRespawned) { m_bBeingRespawned = bBeingRespawned; };
121121

122+
bool IsOnFire() override { return m_pObject ? m_pObject->IsOnFire() : false; }
123+
bool SetOnFire(bool onFire) override { return m_pObject ? m_pObject->SetOnFire(onFire) : false; };
124+
122125
protected:
123126
void StreamIn(bool bInstantly);
124127
void StreamOut();

Client/mods/deathmatch/logic/CClientPed.cpp

+4-13
Original file line numberDiff line numberDiff line change
@@ -5902,22 +5902,13 @@ void CClientPed::SetBleeding(bool bBleeding)
59025902
m_bBleeding = bBleeding;
59035903
}
59045904

5905-
bool CClientPed::IsOnFire()
5905+
bool CClientPed::SetOnFire(bool bIsOnFire)
59065906
{
59075907
if (m_pPlayerPed)
5908-
{
5909-
return m_pPlayerPed->IsOnFire();
5910-
}
5911-
return m_bIsOnFire;
5912-
}
5913-
5914-
void CClientPed::SetOnFire(bool bIsOnFire)
5915-
{
5916-
if (m_pPlayerPed)
5917-
{
5918-
m_pPlayerPed->SetOnFire(bIsOnFire);
5919-
}
5908+
return m_pPlayerPed->SetOnFire(bIsOnFire);
5909+
59205910
m_bIsOnFire = bIsOnFire;
5911+
return true;
59215912
}
59225913

59235914
void CClientPed::GetVoice(short* psVoiceType, short* psVoiceID)

Client/mods/deathmatch/logic/CClientPed.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
483483
bool IsBleeding() const noexcept { return m_bBleeding; };
484484
void SetBleeding(bool bBleeding);
485485

486-
bool IsOnFire();
487-
void SetOnFire(bool bOnFire);
486+
bool IsOnFire() override { return m_pPlayerPed ? m_pPlayerPed->IsOnFire() : m_bIsOnFire; }
487+
bool SetOnFire(bool bOnFire) override;
488488

489489
void GetVoice(short* psVoiceType, short* psVoiceID);
490490
void GetVoice(const char** pszVoiceType, const char** pszVoice);

Client/mods/deathmatch/logic/CClientVehicle.h

+3
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ class CClientVehicle : public CClientStreamElement
549549

550550
CVector GetEntryPoint(std::uint32_t entryPointIndex);
551551

552+
bool IsOnFire() override { return m_pVehicle ? m_pVehicle->IsOnFire() : false; }
553+
bool SetOnFire(bool onFire) override { return m_pVehicle ? m_pVehicle->SetOnFire(onFire) : false; }
554+
552555
protected:
553556
void ConvertComponentRotationBase(const SString& vehicleComponent, CVector& vecInOutRotation, EComponentBaseType inputBase, EComponentBaseType outputBase);
554557
void ConvertComponentPositionBase(const SString& vehicleComponent, CVector& vecInOutPosition, EComponentBaseType inputBase, EComponentBaseType outputBase);

Client/mods/deathmatch/logic/CNetAPI.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,9 @@ void CNetAPI::ReadVehiclePuresync(CClientPlayer* pPlayer, CClientVehicle* pVehic
15411541

15421542
pPlayer->SetControllerState(ControllerState);
15431543

1544+
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
1545+
pVehicle->SetOnFire(BitStream.ReadBit());
1546+
15441547
// Remember now as the last puresync time
15451548
CVector vecPosition;
15461549
pVehicle->GetPosition(vecPosition);
@@ -1766,6 +1769,9 @@ void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVe
17661769
BitStream.WriteBit(ControllerState.RightShoulder2 != 0);
17671770
}
17681771

1772+
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
1773+
BitStream.WriteBit(pVehicle->IsOnFire());
1774+
17691775
// Write the sent position to the interpolator
17701776
AddInterpolation(vecPosition);
17711777
}

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,9 @@ bool CStaticFunctionDefinitions::SetPedOnFire(CClientEntity& Entity, bool bOnFir
25892589
{
25902590
if (IS_PED(&Entity))
25912591
{
2592+
if (!Entity.IsLocalEntity())
2593+
return false;
2594+
25922595
CClientPed& Ped = static_cast<CClientPed&>(Entity);
25932596
Ped.SetOnFire(bOnFire);
25942597
return true;

Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void CLuaElementDefs::LoadFunctions()
7171
{"isElementLowLOD", IsElementLowLod},
7272
{"isElementCallPropagationEnabled", IsElementCallPropagationEnabled},
7373
{"isElementWaitingForGroundToLoad", IsElementWaitingForGroundToLoad},
74+
{"isElementOnFire", ArgumentParser<IsElementOnFire>},
7475

7576
// Element set funcs
7677
{"createElement", CreateElement},
@@ -100,6 +101,7 @@ void CLuaElementDefs::LoadFunctions()
100101
{"setLowLODElement", ArgumentParser<SetLowLodElement>},
101102
{"setElementCallPropagationEnabled", SetElementCallPropagationEnabled},
102103
{"setElementLighting", ArgumentParser<SetElementLighting>},
104+
{"setElementOnFire", ArgumentParser<SetElementOnFire>},
103105
};
104106

105107
// Add functions
@@ -170,6 +172,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
170172
lua_classfunction(luaVM, "getAttachedOffsets", "getElementAttachedOffsets");
171173
lua_classfunction(luaVM, "getData", "getElementData");
172174
lua_classfunction(luaVM, "getAllData", "getAllElementData");
175+
lua_classfunction(luaVM, "isOnFire", "isElementOnFire");
173176

174177
lua_classfunction(luaVM, "setAttachedOffsets", "setElementAttachedOffsets");
175178
lua_classfunction(luaVM, "setData", "setElementData");
@@ -193,6 +196,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
193196
lua_classfunction(luaVM, "setCallPropagationEnabled", "setElementCallPropagationEnabled");
194197
lua_classfunction(luaVM, "setStreamable", "setElementStreamable");
195198
lua_classfunction(luaVM, "setLighting", "setElementLighting");
199+
lua_classfunction(luaVM, "setOnFire", "setElementOnFire");
196200

197201
lua_classvariable(luaVM, "callPropagationEnabled", "setElementCallPropagationEnabled", "isElementCallPropagationEnabled");
198202
lua_classvariable(luaVM, "waitingForGroundToLoad", NULL, "isElementWaitingForGroundToLoad");
@@ -228,6 +232,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
228232
lua_classvariable(luaVM, "angularVelocity", SetElementAngularVelocity, OOP_GetElementTurnVelocity);
229233
lua_classvariable(luaVM, "isElement", NULL, "isElement");
230234
lua_classvariable(luaVM, "lighting", "setElementLighting", "getElementLighting");
235+
lua_classvariable(luaVM, "onFire", "setElementOnFire", "isElementOnFire");
231236
// TODO: Support element data: player.data["age"] = 1337; <=> setElementData(player, "age", 1337)
232237

233238
lua_registerclass(luaVM, "Element");
@@ -2513,6 +2518,14 @@ bool CLuaElementDefs::SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity,
25132518
return CStaticFunctionDefinitions::SetLowLodElement(*pEntity, pLowLodEntity.value_or(nullptr));
25142519
}
25152520

2521+
bool CLuaElementDefs::SetElementOnFire(CClientEntity* entity, bool onFire) noexcept
2522+
{
2523+
if (!entity->IsLocalEntity())
2524+
return false;
2525+
2526+
return entity->SetOnFire(onFire);
2527+
}
2528+
25162529
int CLuaElementDefs::IsElementLowLod(lua_State* luaVM)
25172530
{
25182531
// bool isElementLowLOD ( element theElement )
@@ -2646,3 +2659,8 @@ bool CLuaElementDefs::SetElementLighting(CClientEntity* entity, float lighting)
26462659

26472660
return false;
26482661
}
2662+
2663+
bool CLuaElementDefs::IsElementOnFire(CClientEntity* entity) noexcept
2664+
{
2665+
return entity->IsOnFire();
2666+
}

Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CLuaElementDefs : public CLuaDefs
7171
LUA_DECLARE(IsElementLowLod);
7272
LUA_DECLARE(IsElementCallPropagationEnabled);
7373
LUA_DECLARE(IsElementWaitingForGroundToLoad);
74+
static bool IsElementOnFire(CClientEntity* entity) noexcept;
7475

7576
// Element set funcs
7677
LUA_DECLARE(CreateElement);
@@ -100,4 +101,5 @@ class CLuaElementDefs : public CLuaDefs
100101
static bool SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity, std::optional<CClientEntity*> pLowLodEntity);
101102
LUA_DECLARE(SetElementCallPropagationEnabled);
102103
static bool SetElementLighting(CClientEntity* entity, float lighting);
104+
static bool SetElementOnFire(CClientEntity* entity, bool onFire) noexcept;
103105
};

0 commit comments

Comments
 (0)