Skip to content

Commit 705040f

Browse files
gunslingermodXottab-DUTY
authored andcommitted
[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.
1 parent 449c91a commit 705040f

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/xrGame/Weapon.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,13 +1746,20 @@ float CWeapon::Weight() const
17461746
res += pSettings->r_float(GetSilencerName(), "inv_weight");
17471747
}
17481748

1749-
if (iAmmoElapsed)
1749+
const char* last_type = nullptr;
1750+
float w = 0, bs = 0;
1751+
for (auto& c : m_magazine)
17501752
{
1751-
float w = pSettings->r_float(m_ammoTypes[m_ammoType].c_str(), "inv_weight");
1752-
float bs = pSettings->r_float(m_ammoTypes[m_ammoType].c_str(), "box_size");
1753-
1754-
res += w * (iAmmoElapsed / bs);
1753+
// Usually ammos in mag have same type, use it to improve performance
1754+
if (last_type != c.m_ammoSect.c_str())
1755+
{
1756+
last_type = c.m_ammoSect.c_str();
1757+
w = pSettings->r_float(last_type, "inv_weight");
1758+
bs = pSettings->r_float(last_type, "box_size");
1759+
}
1760+
res += w / bs;
17551761
}
1762+
17561763
return res;
17571764
}
17581765

src/xrGame/WeaponMagazinedWGrenade.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,26 @@ void CWeaponMagazinedWGrenade::net_Import(NET_Packet& P)
744744
inherited::net_Import(P);
745745
}
746746

747+
float CWeaponMagazinedWGrenade::Weight() const
748+
{
749+
float res = inherited::Weight();
750+
751+
const char* last_type = nullptr;
752+
float w = 0, bs = 0;
753+
for (auto& c : m_magazine2)
754+
{
755+
// Usually ammos in mag have same type, use it to improve performance
756+
if (last_type != c.m_ammoSect.c_str())
757+
{
758+
last_type = c.m_ammoSect.c_str();
759+
w = pSettings->r_float(last_type, "inv_weight");
760+
bs = pSettings->r_float(last_type, "box_size");
761+
}
762+
res += w / bs;
763+
}
764+
return res;
765+
}
766+
747767
bool CWeaponMagazinedWGrenade::IsNecessaryItem(const shared_str& item_sect)
748768
{
749769
return (std::find(m_ammoTypes.begin(), m_ammoTypes.end(), item_sect) != m_ammoTypes.end() ||

src/xrGame/WeaponMagazinedWGrenade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CWeaponMagazinedWGrenade : public CWeaponMagazined, public CRocketLauncher
5555
virtual bool GetBriefInfo(II_BriefInfo& info);
5656

5757
virtual bool IsNecessaryItem(const shared_str& item_sect);
58+
virtual float Weight() const;
5859

5960
//виртуальные функции для проигрывания анимации HUD
6061
virtual void PlayAnimShow();

0 commit comments

Comments
 (0)