Skip to content
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

Add new functions setElementOnFire + isElementOnFire & deprecate setPedOnFire/isPedOnFire #3783

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
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
3 changes: 3 additions & 0 deletions Client/game_sa/CEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ class CEntitySA : public virtual CEntity
bool GetBonePosition(eBone boneId, CVector& position);
bool SetBonePosition(eBone boneId, const CVector& position);

bool IsOnFire() override { return false; }
bool SetOnFire(bool onFire) override { return false; }

// CEntitySA interface
virtual void OnChangingPosition(const CVector& vecNewPosition) {}

Expand Down
34 changes: 34 additions & 0 deletions Client/game_sa/CObjectSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "CPoolsSA.h"
#include "CRopesSA.h"
#include "CWorldSA.h"
#include "CFireManagerSA.h"

extern CGameSA* pGame;

Expand Down Expand Up @@ -304,3 +305,36 @@ void CObjectSA::ResetScale()
{
SetScale(1.0f, 1.0f, 1.0f);
}

bool CObjectSA::SetOnFire(bool onFire)
{
CObjectSAInterface* objectInterface = GetObjectInterface();
if (onFire == !!objectInterface->pFire)
return false;

auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());

if (onFire)
{
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
if (!fire)
return false;

fire->SetTarget(this);
fire->SetStrength(1.0f);
fire->Ignite();
fire->SetNumGenerationsAllowed(0);

objectInterface->pFire = fire->GetInterface();
}
else
{
CFire* fire = fireManager->GetFire(objectInterface->pFire);
if (!fire)
return false;

fire->Extinguish();
}

return true;
}
5 changes: 4 additions & 1 deletion Client/game_sa/CObjectSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class CObjectSA : public virtual CObject, public virtual CPhysicalSA
CVector* GetScale();
void ResetScale();

bool IsOnFire() override { return GetObjectInterface()->pFire != nullptr; }
bool SetOnFire(bool onFire) override;

private:
void CheckForGangTag();
};
};
61 changes: 24 additions & 37 deletions Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,52 +851,39 @@ void CPedSA::SetBleeding(bool bBleeding)
GetPedInterface()->pedFlags.bPedIsBleeding = bBleeding;
}

bool CPedSA::IsOnFire()
{
if (GetPedInterface()->pFireOnPed != NULL)
return true;
return false;
}

void CPedSA::SetOnFire(bool bOnFire)
bool CPedSA::SetOnFire(bool onFire)
{
CPedSAInterface* pInterface = GetPedInterface();
if (onFire == !!pInterface->pFireOnPed)
return false;

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

if (pFire)
{
// Start the fire
pFire->SetTarget(this);
pFire->Ignite();
pFire->SetStrength(1.0f);
// Attach the fire only to the player, do not let it
// create child fires when moving.
pFire->SetNumGenerationsAllowed(0);
pInterface->pFireOnPed = pFire->GetInterface();
}
}
if (onFire)
{
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
if (!fire)
return false;

// Start the fire
fire->SetTarget(this);
fire->Ignite();
fire->SetStrength(1.0f);
// Attach the fire only to the player, do not let it
// create child fires when moving.
fire->SetNumGenerationsAllowed(0);
pInterface->pFireOnPed = fire->GetInterface();
}
else
{
// Make sure that we have some attached fire
if (pInterface->pFireOnPed != NULL)
{
CFireManagerSA* pFireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
CFire* pFire = pFireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
CFire* fire = fireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
if (!fire)
return false;

if (pFire)
{
pFire->Extinguish();
}
}
fire->Extinguish();
}

return true;
}

void CPedSA::SetStayInSamePlace(bool bStay)
Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
bool IsBleeding();
void SetBleeding(bool bBleeding);

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

bool GetStayInSamePlace() { return GetPedInterface()->pedFlags.bStayInSamePlace; }
void SetStayInSamePlace(bool bStay);
Expand Down
34 changes: 34 additions & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "CVisibilityPluginsSA.h"
#include "CWorldSA.h"
#include "gamesa_renderware.h"
#include "CFireManagerSA.h"

extern CGameSA* pGame;

Expand Down Expand Up @@ -1833,6 +1834,39 @@ void CVehicleSA::OnChangingPosition(const CVector& vecNewPosition)
}
}

bool CVehicleSA::SetOnFire(bool onFire)
{
CVehicleSAInterface* vehicleInterface = GetVehicleInterface();
if (onFire == !!vehicleInterface->m_pFire)
return false;

auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());

if (onFire)
{
CFire* fire = fireManager->StartFire(this, nullptr, static_cast<float>(DEFAULT_FIRE_PARTICLE_SIZE));
if (!fire)
return false;

fire->SetTarget(this);
fire->SetStrength(1.0f);
fire->Ignite();
fire->SetNumGenerationsAllowed(0);

vehicleInterface->m_pFire = fire->GetInterface();
}
else
{
CFire* fire = fireManager->GetFire(vehicleInterface->m_pFire);
if (!fire)
return false;

fire->Extinguish();
}

return true;
}

void CVehicleSA::StaticSetHooks()
{
// Setup vehicle sun glare hook
Expand Down
5 changes: 4 additions & 1 deletion Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class CVehicleSAInterface : public CPhysicalSAInterface

unsigned char m_nSpecialColModel;
CEntity* pEntityWeAreOnForVisibilityCheck;
CFire* m_pFire;
CFireSAInterface* m_pFire;

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

bool IsOnFire() override { return GetVehicleInterface()->m_pFire != nullptr; }
bool SetOnFire(bool onFire) override;

static void StaticSetHooks();
static void SetVehiclesSunGlareEnabled(bool bEnabled);
static bool GetVehiclesSunGlareEnabled();
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ class CClientEntity : public CClientEntityBase
bool CanBeDestroyedByScript() { return m_canBeDestroyedByScript; }
void SetCanBeDestroyedByScript(bool canBeDestroyedByScript) { m_canBeDestroyedByScript = canBeDestroyedByScript; }

virtual bool IsOnFire() { return false; }
virtual bool SetOnFire(bool onFire) { return false; }
FileEX marked this conversation as resolved.
Show resolved Hide resolved

protected:
CClientManager* m_pManager;
CClientEntity* m_pParent;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class CClientObject : public CClientStreamElement
bool IsBeingRespawned() { return m_bBeingRespawned; };
void SetBeingRespawned(bool bBeingRespawned) { m_bBeingRespawned = bBeingRespawned; };

bool IsOnFire() override { return m_pObject ? m_pObject->IsOnFire() : false; }
bool SetOnFire(bool onFire) override { return m_pObject ? m_pObject->SetOnFire(onFire) : false; };
FileEX marked this conversation as resolved.
Show resolved Hide resolved

protected:
void StreamIn(bool bInstantly);
void StreamOut();
Expand Down
17 changes: 4 additions & 13 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5919,22 +5919,13 @@ void CClientPed::SetBleeding(bool bBleeding)
m_bBleeding = bBleeding;
}

bool CClientPed::IsOnFire()
bool CClientPed::SetOnFire(bool bIsOnFire)
{
if (m_pPlayerPed)
{
return m_pPlayerPed->IsOnFire();
}
return m_bIsOnFire;
}

void CClientPed::SetOnFire(bool bIsOnFire)
{
if (m_pPlayerPed)
{
m_pPlayerPed->SetOnFire(bIsOnFire);
}
return m_pPlayerPed->SetOnFire(bIsOnFire);

m_bIsOnFire = bIsOnFire;
return true;
}

void CClientPed::GetVoice(short* psVoiceType, short* psVoiceID)
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool IsBleeding() const noexcept { return m_bBleeding; };
void SetBleeding(bool bBleeding);

bool IsOnFire();
void SetOnFire(bool bOnFire);
bool IsOnFire() override { return m_pPlayerPed ? m_pPlayerPed->IsOnFire() : m_bIsOnFire; }
bool SetOnFire(bool bOnFire) override;
FileEX marked this conversation as resolved.
Show resolved Hide resolved

void GetVoice(short* psVoiceType, short* psVoiceID);
void GetVoice(const char** pszVoiceType, const char** pszVoice);
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ class CClientVehicle : public CClientStreamElement

CVector GetEntryPoint(std::uint32_t entryPointIndex);

bool IsOnFire() override { return m_pVehicle ? m_pVehicle->IsOnFire() : false; }
bool SetOnFire(bool onFire) override { return m_pVehicle ? m_pVehicle->SetOnFire(onFire) : false; }
FileEX marked this conversation as resolved.
Show resolved Hide resolved

protected:
void ConvertComponentRotationBase(const SString& vehicleComponent, CVector& vecInOutRotation, EComponentBaseType inputBase, EComponentBaseType outputBase);
void ConvertComponentPositionBase(const SString& vehicleComponent, CVector& vecInOutPosition, EComponentBaseType inputBase, EComponentBaseType outputBase);
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,9 @@ void CNetAPI::ReadVehiclePuresync(CClientPlayer* pPlayer, CClientVehicle* pVehic

pPlayer->SetControllerState(ControllerState);

if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
pVehicle->SetOnFire(BitStream.ReadBit());

// Remember now as the last puresync time
CVector vecPosition;
pVehicle->GetPosition(vecPosition);
Expand Down Expand Up @@ -1766,6 +1769,9 @@ void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVe
BitStream.WriteBit(ControllerState.RightShoulder2 != 0);
}

if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
BitStream.WriteBit(pVehicle->IsOnFire());

// Write the sent position to the interpolator
AddInterpolation(vecPosition);
}
Expand Down
15 changes: 15 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void CLuaElementDefs::LoadFunctions()
{"isElementLowLOD", IsElementLowLod},
{"isElementCallPropagationEnabled", IsElementCallPropagationEnabled},
{"isElementWaitingForGroundToLoad", IsElementWaitingForGroundToLoad},
{"isElementOnFire", ArgumentParser<IsElementOnFire>},

// Element set funcs
{"createElement", CreateElement},
Expand Down Expand Up @@ -99,6 +100,7 @@ void CLuaElementDefs::LoadFunctions()
{"setElementFrozen", SetElementFrozen},
{"setLowLODElement", ArgumentParser<SetLowLodElement>},
{"setElementCallPropagationEnabled", SetElementCallPropagationEnabled},
{"setElementOnFire", ArgumentParser<SetElementOnFire>},
};

// Add functions
Expand Down Expand Up @@ -169,6 +171,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getAttachedOffsets", "getElementAttachedOffsets");
lua_classfunction(luaVM, "getData", "getElementData");
lua_classfunction(luaVM, "getAllData", "getAllElementData");
lua_classfunction(luaVM, "isOnFire", "isElementOnFire");

lua_classfunction(luaVM, "setAttachedOffsets", "setElementAttachedOffsets");
lua_classfunction(luaVM, "setData", "setElementData");
Expand All @@ -191,6 +194,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setLowLOD", "setLowLODElement");
lua_classfunction(luaVM, "setCallPropagationEnabled", "setElementCallPropagationEnabled");
lua_classfunction(luaVM, "setStreamable", "setElementStreamable");
lua_classfunction(luaVM, "setOnFire", "setElementOnFire");

lua_classvariable(luaVM, "callPropagationEnabled", "setElementCallPropagationEnabled", "isElementCallPropagationEnabled");
lua_classvariable(luaVM, "waitingForGroundToLoad", NULL, "isElementWaitingForGroundToLoad");
Expand Down Expand Up @@ -225,6 +229,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "velocity", SetElementVelocity, OOP_GetElementVelocity);
lua_classvariable(luaVM, "angularVelocity", SetElementAngularVelocity, OOP_GetElementTurnVelocity);
lua_classvariable(luaVM, "isElement", NULL, "isElement");
lua_classvariable(luaVM, "onFire", "setElementOnFire", "isElementOnFire");
// TODO: Support element data: player.data["age"] = 1337; <=> setElementData(player, "age", 1337)

lua_registerclass(luaVM, "Element");
Expand Down Expand Up @@ -2509,6 +2514,11 @@ bool CLuaElementDefs::SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity,
return CStaticFunctionDefinitions::SetLowLodElement(*pEntity, pLowLodEntity.value_or(nullptr));
}

bool CLuaElementDefs::SetElementOnFire(CClientEntity* entity, bool onFire) noexcept
{
return entity->SetOnFire(onFire);
}

int CLuaElementDefs::IsElementLowLod(lua_State* luaVM)
{
// bool isElementLowLOD ( element theElement )
Expand Down Expand Up @@ -2604,3 +2614,8 @@ int CLuaElementDefs::IsElementWaitingForGroundToLoad(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

bool CLuaElementDefs::IsElementOnFire(CClientEntity* entity) noexcept
{
return entity->IsOnFire();
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE(IsElementLowLod);
LUA_DECLARE(IsElementCallPropagationEnabled);
LUA_DECLARE(IsElementWaitingForGroundToLoad);
static bool IsElementOnFire(CClientEntity* entity) noexcept;

// Element set funcs
LUA_DECLARE(CreateElement);
Expand Down Expand Up @@ -99,4 +100,5 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE(SetElementFrozen);
static bool SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity, std::optional<CClientEntity*> pLowLodEntity);
LUA_DECLARE(SetElementCallPropagationEnabled);
static bool SetElementOnFire(CClientEntity* entity, bool onFire) noexcept;
};
Loading
Loading