From 81df8292707fbfba443688eeb076244733ac9486 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Thu, 6 Mar 2025 20:02:41 +0300 Subject: [PATCH] Remove useless checks --- Client/game_sa/CGameSA.cpp | 2 +- Client/game_sa/CWeaponSA.cpp | 28 ++++++++----------- Client/game_sa/CWeaponSA.h | 20 ++++++------- .../mods/deathmatch/logic/CClientWeapon.cpp | 2 +- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/Client/game_sa/CGameSA.cpp b/Client/game_sa/CGameSA.cpp index bbb0b7c00e6..86802ed978d 100644 --- a/Client/game_sa/CGameSA.cpp +++ b/Client/game_sa/CGameSA.cpp @@ -1126,7 +1126,7 @@ void CGameSA::DisableVSync() } CWeapon* CGameSA::CreateWeapon() { - return new CWeaponSA(new CWeaponSAInterface, NULL, WEAPONSLOT_MAX); + return new CWeaponSA(new CWeaponSAInterface, nullptr, WEAPONSLOT_MAX); } CWeaponStat* CGameSA::CreateWeaponStat(eWeaponType weaponType, eWeaponSkill weaponSkill) diff --git a/Client/game_sa/CWeaponSA.cpp b/Client/game_sa/CWeaponSA.cpp index 3d09657c8c5..9ca46fc88fd 100644 --- a/Client/game_sa/CWeaponSA.cpp +++ b/Client/game_sa/CWeaponSA.cpp @@ -21,7 +21,7 @@ extern CGameSA* pGame; CWeaponInfo* CWeaponSA::GetInfo(eWeaponSkill skill) const { - return m_interface ? pGame->GetWeaponInfo(m_interface->m_eWeaponType, skill) : nullptr; + return pGame->GetWeaponInfo(m_interface->m_eWeaponType, skill); } void CWeaponSA::SetAsCurrentWeapon() @@ -32,17 +32,16 @@ void CWeaponSA::SetAsCurrentWeapon() void CWeaponSA::Destroy() { - if (m_interface) - delete m_interface; + // We should not delete weapons from CPedInterface + if (m_owner) + return; + delete m_interface; delete this; } void CWeaponSA::Remove() { - if (!m_interface) - return; - m_interface->Shutdown(); // If the removed weapon was the currently active weapon, switch to empty-handed @@ -57,26 +56,24 @@ void CWeaponSA::Remove() void CWeaponSA::Initialize(eWeaponType type, std::uint32_t ammo, CPed* ped) { - if (m_interface) - m_interface->Initialize(type, ammo, ped ? ped->GetPedInterface() : nullptr); + m_interface->Initialize(type, ammo, ped ? ped->GetPedInterface() : nullptr); } void CWeaponSA::AddGunshell(CEntity* firingEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float size) const { - if (m_interface && firingEntity) + if (firingEntity) m_interface->AddGunshell(firingEntity->GetInterface(), vecOrigin, vecDirection, size); } void CWeaponSA::DoBulletImpact(CEntity* firingEntity, CEntitySAInterface* hitEntityInterface, const CVector& vecOrigin, const CVector& vecTarget, const CColPointSAInterface& colPoint, int incrementalHit) const { - if (m_interface) - m_interface->DoBulletImpact(firingEntity ? firingEntity->GetInterface() : nullptr, hitEntityInterface, vecOrigin, vecTarget, colPoint, incrementalHit); + m_interface->DoBulletImpact(firingEntity ? firingEntity->GetInterface() : nullptr, hitEntityInterface, vecOrigin, vecTarget, colPoint, incrementalHit); } bool CWeaponSA::Fire(CEntity* firingEntity, CVector* vecOrigin, CVector* vecEffectPos, CEntity* targetEntity, CVector* vecTarget, CVector* vecAlt) { - if (!firingEntity || !m_interface) + if (!firingEntity) return false; return m_interface->Fire(firingEntity->GetInterface(), vecOrigin, vecEffectPos, targetEntity ? targetEntity->GetInterface() : nullptr, vecTarget, vecAlt); @@ -85,9 +82,6 @@ bool CWeaponSA::Fire(CEntity* firingEntity, CVector* vecOrigin, CVector* vecEffe bool CWeaponSA::FireInstantHit(CEntity* firingEntity, CVector* vecOrigin, CVector* vecMuzzle, CEntity* targetEntity, CVector* vecTarget, CVector* vecForDriveby, bool crossHairGun, bool createGunFx) { - if (!m_interface) - return false; - return m_interface->FireInstantHit(firingEntity ? firingEntity->GetInterface() : nullptr, vecOrigin, vecMuzzle, targetEntity ? targetEntity->GetInterface() : nullptr, vecTarget, vecForDriveby, crossHairGun, createGunFx); } @@ -152,10 +146,10 @@ bool CWeaponSA::FireBullet(CEntity* firingEntity, const CVector& vecOrigin, cons bool CWeaponSA::GenerateDamageEvent(CPed* ped, CEntity* responsible, eWeaponType weaponType, int damagePerHit, ePedPieceTypes hitZone, std::uint8_t dir) const { - if (!ped || !m_interface) + if (!ped) return false; - return m_interface->GenerateDamageEvent(ped ? ped->GetPedInterface() : nullptr, responsible ? responsible->GetInterface() : nullptr, weaponType, + return m_interface->GenerateDamageEvent(ped->GetPedInterface(), responsible ? responsible->GetInterface() : nullptr, weaponType, damagePerHit, hitZone, dir); } diff --git a/Client/game_sa/CWeaponSA.h b/Client/game_sa/CWeaponSA.h index 9ef7124493a..dea73835304 100644 --- a/Client/game_sa/CWeaponSA.h +++ b/Client/game_sa/CWeaponSA.h @@ -73,32 +73,28 @@ class CWeaponSA : public CWeapon CWeaponSAInterface* GetInterface() { return m_interface; } CWeaponSAInterface* GetInterface() const { return m_interface; } - eWeaponType GetType() const override { return m_interface ? m_interface->m_eWeaponType : eWeaponType::WEAPONTYPE_UNIDENTIFIED; } + eWeaponType GetType() const override { return m_interface->m_eWeaponType; } void SetType(eWeaponType type) override { - if (m_interface) - m_interface->m_eWeaponType = type; + m_interface->m_eWeaponType = type; } - eWeaponState GetState() const override { return m_interface ? m_interface->m_eState : eWeaponState::WEAPONSTATE_READY; } + eWeaponState GetState() const override { return m_interface->m_eState; } void SetState(eWeaponState state) override { - if (m_interface) - m_interface->m_eState = state; + m_interface->m_eState = state; } - std::uint32_t GetAmmoInClip() const override { return m_interface ? m_interface->m_ammoInClip : 0; } + std::uint32_t GetAmmoInClip() const override { return m_interface->m_ammoInClip; } void SetAmmoInClip(std::uint32_t ammoInClip) override { - if (m_interface) - m_interface->m_ammoInClip = ammoInClip; + m_interface->m_ammoInClip = ammoInClip; } - std::uint32_t GetAmmoTotal() const override { return m_interface ? m_interface->m_ammoTotal : 0; } + std::uint32_t GetAmmoTotal() const override { return m_interface->m_ammoTotal; } void SetAmmoTotal(std::uint32_t ammoTotal) override { - if (m_interface) - m_interface->m_ammoTotal = ammoTotal; + m_interface->m_ammoTotal = ammoTotal; } CPed* GetPed() const noexcept override { return m_owner; } diff --git a/Client/mods/deathmatch/logic/CClientWeapon.cpp b/Client/mods/deathmatch/logic/CClientWeapon.cpp index 14f8e6338f3..4e5eef27c41 100644 --- a/Client/mods/deathmatch/logic/CClientWeapon.cpp +++ b/Client/mods/deathmatch/logic/CClientWeapon.cpp @@ -209,7 +209,7 @@ void CClientWeapon::Destroy() { // g_pGame->GetAudioEngine ()->ReportWeaponEvent ( WEAPON_EVENT_RELOAD, m_Type, m_pObject ); m_pWeapon->Destroy(); - m_pWeapon = NULL; + m_pWeapon = nullptr; } }