From 705040f379317f54bc72b1fb1f683afc5311a13f Mon Sep 17 00:00:00 2001 From: Sin! Date: Sat, 5 Aug 2017 01:33:04 +1000 Subject: [PATCH] [Bugfix] Incorrect weapon weight calculation 1) Ammos in mag could have different types with different weight (especially for shotguns) 2) When grenade is loaded into the weapon, it weight should increase. --- src/xrGame/Weapon.cpp | 17 ++++++++++++----- src/xrGame/WeaponMagazinedWGrenade.cpp | 20 ++++++++++++++++++++ src/xrGame/WeaponMagazinedWGrenade.h | 1 + 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/xrGame/Weapon.cpp b/src/xrGame/Weapon.cpp index aded2ac2429..055ee635abe 100644 --- a/src/xrGame/Weapon.cpp +++ b/src/xrGame/Weapon.cpp @@ -1746,13 +1746,20 @@ float CWeapon::Weight() const res += pSettings->r_float(GetSilencerName(), "inv_weight"); } - if (iAmmoElapsed) + const char* last_type = nullptr; + float w = 0, bs = 0; + for (auto& c : m_magazine) { - float w = pSettings->r_float(m_ammoTypes[m_ammoType].c_str(), "inv_weight"); - float bs = pSettings->r_float(m_ammoTypes[m_ammoType].c_str(), "box_size"); - - res += w * (iAmmoElapsed / bs); + // Usually ammos in mag have same type, use it to improve performance + if (last_type != c.m_ammoSect.c_str()) + { + last_type = c.m_ammoSect.c_str(); + w = pSettings->r_float(last_type, "inv_weight"); + bs = pSettings->r_float(last_type, "box_size"); + } + res += w / bs; } + return res; } diff --git a/src/xrGame/WeaponMagazinedWGrenade.cpp b/src/xrGame/WeaponMagazinedWGrenade.cpp index 4e1b8bd11bd..f93033d48ab 100644 --- a/src/xrGame/WeaponMagazinedWGrenade.cpp +++ b/src/xrGame/WeaponMagazinedWGrenade.cpp @@ -744,6 +744,26 @@ void CWeaponMagazinedWGrenade::net_Import(NET_Packet& P) inherited::net_Import(P); } +float CWeaponMagazinedWGrenade::Weight() const +{ + float res = inherited::Weight(); + + const char* last_type = nullptr; + float w = 0, bs = 0; + for (auto& c : m_magazine2) + { + // Usually ammos in mag have same type, use it to improve performance + if (last_type != c.m_ammoSect.c_str()) + { + last_type = c.m_ammoSect.c_str(); + w = pSettings->r_float(last_type, "inv_weight"); + bs = pSettings->r_float(last_type, "box_size"); + } + res += w / bs; + } + return res; +} + bool CWeaponMagazinedWGrenade::IsNecessaryItem(const shared_str& item_sect) { return (std::find(m_ammoTypes.begin(), m_ammoTypes.end(), item_sect) != m_ammoTypes.end() || diff --git a/src/xrGame/WeaponMagazinedWGrenade.h b/src/xrGame/WeaponMagazinedWGrenade.h index 67f660ba91e..d05445042fb 100644 --- a/src/xrGame/WeaponMagazinedWGrenade.h +++ b/src/xrGame/WeaponMagazinedWGrenade.h @@ -55,6 +55,7 @@ class CWeaponMagazinedWGrenade : public CWeaponMagazined, public CRocketLauncher virtual bool GetBriefInfo(II_BriefInfo& info); virtual bool IsNecessaryItem(const shared_str& item_sect); + virtual float Weight() const; //виртуальные функции для проигрывания анимации HUD virtual void PlayAnimShow();