Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Oct 9, 2024
1 parent 594afaa commit ab6bea5
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 207 deletions.
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
16 changes: 10 additions & 6 deletions Client/game_sa/CObjectSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,19 @@ void CObjectSA::ResetScale()
SetScale(1.0f, 1.0f, 1.0f);
}

void CObjectSA::SetOnFire(bool onFire)
bool CObjectSA::SetOnFire(bool onFire)
{
CObjectSAInterface* objectInterface = GetObjectInterface();
if ((onFire && objectInterface->pFire) || (!onFire && !objectInterface->pFire))
return;
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;
return false;

fire->SetTarget(this);
fire->SetStrength(1.0f);
Expand All @@ -330,7 +330,11 @@ void CObjectSA::SetOnFire(bool onFire)
else
{
CFire* fire = fireManager->GetFire(objectInterface->pFire);
if (fire)
fire->Extinguish();
if (!fire)
return false;

fire->Extinguish();
}

return true;
}
2 changes: 1 addition & 1 deletion Client/game_sa/CObjectSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class CObjectSA : public virtual CObject, public virtual CPhysicalSA
void ResetScale();

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

private:
void CheckForGangTag();
Expand Down
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
16 changes: 10 additions & 6 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,19 +1834,19 @@ void CVehicleSA::OnChangingPosition(const CVector& vecNewPosition)
}
}

void CVehicleSA::SetOnFire(bool onFire)
bool CVehicleSA::SetOnFire(bool onFire)
{
CVehicleSAInterface* vehicleInterface = GetVehicleInterface();
if ((onFire && vehicleInterface->m_pFire) || (!onFire && !vehicleInterface->m_pFire))
return;
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;
return false;

fire->SetTarget(this);
fire->SetStrength(1.0f);
Expand All @@ -1858,9 +1858,13 @@ void CVehicleSA::SetOnFire(bool onFire)
else
{
CFire* fire = fireManager->GetFire(vehicleInterface->m_pFire);
if (fire)
fire->Extinguish();
if (!fire)
return false;

fire->Extinguish();
}

return true;
}

void CVehicleSA::StaticSetHooks()
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
const CVector* GetDummyPositions() const override { return m_dummyPositions.data(); }

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

static void StaticSetHooks();
static void SetVehiclesSunGlareEnabled(bool bEnabled);
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; }

protected:
CClientManager* m_pManager;
CClientEntity* m_pParent;
Expand Down
14 changes: 0 additions & 14 deletions Client/mods/deathmatch/logic/CClientObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,6 @@ void CClientObject::SetHealth(float fHealth)
m_fHealth = fHealth;
}

bool CClientObject::IsOnFire() const noexcept
{
if (!m_pObject)
return false;

return m_pObject->IsOnFire();
}

void CClientObject::SetOnFire(bool onFire) noexcept
{
if (m_pObject)
m_pObject->SetOnFire(onFire);
}

void CClientObject::StreamIn(bool bInstantly)
{
// Don't stream the object in, if respawn is disabled and the object is broken
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class CClientObject : public CClientStreamElement
bool IsBeingRespawned() { return m_bBeingRespawned; };
void SetBeingRespawned(bool bBeingRespawned) { m_bBeingRespawned = bBeingRespawned; };

bool IsOnFire() const noexcept;
void SetOnFire(bool onFire) noexcept;
bool IsOnFire() override { return m_pObject ? m_pObject->IsOnFire() : false; }
bool SetOnFire(bool onFire) override { return m_pObject ? m_pObject->SetOnFire(onFire) : false; };

protected:
void StreamIn(bool bInstantly);
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;

void GetVoice(short* psVoiceType, short* psVoiceID);
void GetVoice(const char** pszVoiceType, const char** pszVoice);
Expand Down
14 changes: 0 additions & 14 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5058,17 +5058,3 @@ CVector CClientVehicle::GetEntryPoint(std::uint32_t entryPointIndex)

return entryPoint;
}

bool CClientVehicle::IsOnFire() const noexcept
{
if (!m_pVehicle)
return false;

return m_pVehicle->IsOnFire();
}

void CClientVehicle::SetOnFire(bool onFire) noexcept
{
if (m_pVehicle)
m_pVehicle->SetOnFire(onFire);
}
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ class CClientVehicle : public CClientStreamElement

CVector GetEntryPoint(std::uint32_t entryPointIndex);

bool IsOnFire() const noexcept;
void SetOnFire(bool onFire) noexcept;
bool IsOnFire() override { return m_pVehicle ? m_pVehicle->IsOnFire() : false; }
bool SetOnFire(bool onFire) override { return m_pVehicle ? m_pVehicle->SetOnFire(onFire) : false; }

protected:
void ConvertComponentRotationBase(const SString& vehicleComponent, CVector& vecInOutRotation, EComponentBaseType inputBase, EComponentBaseType outputBase);
Expand Down
39 changes: 4 additions & 35 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,30 +2514,9 @@ bool CLuaElementDefs::SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity,
return CStaticFunctionDefinitions::SetLowLodElement(*pEntity, pLowLodEntity.value_or(nullptr));
}

bool CLuaElementDefs::SetElementOnFire(CClientEntity* entity, bool onFire)
bool CLuaElementDefs::SetElementOnFire(CClientEntity* entity, bool onFire) noexcept
{
switch (entity->GetType())
{
case CCLIENTPED:
case CCLIENTPLAYER:
{
static_cast<CClientPed*>(entity)->SetOnFire(onFire);
return true;
}
case CCLIENTVEHICLE:
{
static_cast<CClientVehicle*>(entity)->SetOnFire(onFire);
return true;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
static_cast<CClientObject*>(entity)->SetOnFire(onFire);
return true;
}
}

return false;
return entity->SetOnFire(onFire);
}

int CLuaElementDefs::IsElementLowLod(lua_State* luaVM)
Expand Down Expand Up @@ -2636,17 +2615,7 @@ int CLuaElementDefs::IsElementWaitingForGroundToLoad(lua_State* luaVM)
return 1;
}

bool CLuaElementDefs::IsElementOnFire(CClientEntity* entity)
bool CLuaElementDefs::IsElementOnFire(CClientEntity* entity) noexcept
{
switch (entity->GetType())
{
case CCLIENTPED:
return static_cast<CClientPed*>(entity)->IsOnFire();
case CCLIENTVEHICLE:
return static_cast<CClientVehicle*>(entity)->IsOnFire();
case CCLIENTOBJECT:
return static_cast<CClientObject*>(entity)->IsOnFire();
}

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

// Element set funcs
LUA_DECLARE(CreateElement);
Expand Down Expand Up @@ -100,5 +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);
static bool SetElementOnFire(CClientEntity* entity, bool onFire) noexcept;
};
21 changes: 1 addition & 20 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,24 +763,5 @@ void CElementRPCs::SetColPolygonHeight(CClientEntity* pSource, NetBitStreamInter

void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
switch (pSource->GetType())
{
case CCLIENTPLAYER:
case CCLIENTPED:
{
static_cast<CClientPed*>(pSource)->SetOnFire(bitStream.ReadBit());
break;
}
case CCLIENTVEHICLE:
{
static_cast<CClientVehicle*>(pSource)->SetOnFire(bitStream.ReadBit());
break;
}
case CCLIENTOBJECT:
case CCLIENTWEAPON:
{
static_cast<CClientObject*>(pSource)->SetOnFire(bitStream.ReadBit());
break;
}
}
pSource->SetOnFire(bitStream.ReadBit());
}
Loading

0 comments on commit ab6bea5

Please sign in to comment.