@@ -1730,6 +1730,24 @@ bool CWeapon::unlimited_ammo()
17301730 return ((GameID () == eGameIDDeathmatch) && m_DefaultCartridge.m_flags .test (CCartridge::cfCanBeUnlimited));
17311731};
17321732
1733+ float CWeapon::GetMagazineWeight (const decltype (CWeapon::m_magazine)& mag) const
1734+ {
1735+ float res = 0 ;
1736+ const char * last_type = nullptr ;
1737+ float last_ammo_weight = 0 ;
1738+ for (auto & c : mag)
1739+ {
1740+ // Usually ammos in mag have same type, use this fact to improve performance
1741+ if (last_type != c.m_ammoSect .c_str ())
1742+ {
1743+ last_type = c.m_ammoSect .c_str ();
1744+ last_ammo_weight = c.Weight ();
1745+ }
1746+ res += last_ammo_weight;
1747+ }
1748+ return res;
1749+ }
1750+
17331751float CWeapon::Weight () const
17341752{
17351753 float res = CInventoryItemObject::Weight ();
@@ -1745,20 +1763,7 @@ float CWeapon::Weight() const
17451763 {
17461764 res += pSettings->r_float (GetSilencerName (), " inv_weight" );
17471765 }
1748-
1749- const char * last_type = nullptr ;
1750- float w = 0 , bs = 0 ;
1751- for (auto & c : m_magazine)
1752- {
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;
1761- }
1766+ res += GetMagazineWeight (m_magazine);
17621767
17631768 return res;
17641769}
0 commit comments