Skip to content

Commit

Permalink
[Bugfix] Incorrect weapon weight calculation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gunslingermod authored and Xottab-DUTY committed Aug 14, 2017
1 parent 449c91a commit 705040f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions src/xrGame/WeaponMagazinedWGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/WeaponMagazinedWGrenade.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 705040f

Please sign in to comment.