Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 11 additions & 17 deletions Client/game_sa/CWeaponSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 8 additions & 12 deletions Client/game_sa/CWeaponSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading