From f4f83ca6c000d338c55df07a6d5ff74b846bcf04 Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Sat, 11 Dec 2021 19:46:26 +0300 Subject: [PATCH] Fix m249 tape when reloading the empty clip (#232) --- cl_dll/hl/hl_weapons.cpp | 7 ++++--- dlls/client.cpp | 1 + dlls/gearbox/m249.cpp | 31 +++++++++++++++++++++++++++---- dlls/weapons.h | 3 +++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/cl_dll/hl/hl_weapons.cpp b/cl_dll/hl/hl_weapons.cpp index 04412401..86c91a3b 100644 --- a/cl_dll/hl/hl_weapons.cpp +++ b/cl_dll/hl/hl_weapons.cpp @@ -895,6 +895,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm else if( player.m_pActiveItem->m_iId == WEAPON_M249 ) { player.ammo_556 = (int)from->client.vuser2[1]; + ( (CM249 *)player.m_pActiveItem )->m_iVisibleClip = (int)from->client.vuser2[2]; } else if( player.m_pActiveItem->m_iId == WEAPON_SHOCKRIFLE ) { @@ -1015,10 +1016,10 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm body = 1; if (pWeapon == &g_M249) { - if (g_M249.m_iClip == 0) { + if (g_M249.m_iVisibleClip == 0) { body = 8; - } else if (g_M249.m_iClip > 0 && g_M249.m_iClip < 8) { - body = 9 - g_M249.m_iClip; + } else if (g_M249.m_iVisibleClip > 0 && g_M249.m_iVisibleClip < 8) { + body = 9 - g_M249.m_iVisibleClip; } else { body = 0; } diff --git a/dlls/client.cpp b/dlls/client.cpp index 7c069c1d..3c7415d1 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1837,6 +1837,7 @@ void UpdateClientData( const struct edict_s *ent, int sendweapons, struct client else if( pl->m_pActiveItem->m_iId == WEAPON_M249 ) { cd->vuser2.y = pl->ammo_556; + cd->vuser2.z = ( (CM249 *)pl->m_pActiveItem )->m_iVisibleClip; } else if( pl->m_pActiveItem->m_iId == WEAPON_SHOCKRIFLE ) { diff --git a/dlls/gearbox/m249.cpp b/dlls/gearbox/m249.cpp index a03170a8..18ed5fc4 100644 --- a/dlls/gearbox/m249.cpp +++ b/dlls/gearbox/m249.cpp @@ -221,10 +221,25 @@ void CM249::Reload(void) void CM249::ItemPostFrame() { + if (!m_fInReload) + { + m_iVisibleClip = m_iClip; + } if ( m_fInSpecialReload ) { if (m_pPlayer->m_flNextAttack <= UTIL_WeaponTimeBase()) { + int maxClip; + #ifndef CLIENT_DLL + maxClip = iMaxClip(); + #else + ItemInfo itemInfo; + GetItemInfo( &itemInfo ); + maxClip = itemInfo.iMaxClip; + #endif + m_iVisibleClip = m_iClip + Q_min( maxClip - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ); + + UpdateTape(m_iVisibleClip); m_fInSpecialReload = FALSE; SendWeaponAnim( M249_RELOAD1, UseDecrement(), pev->body ); m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 2.4; @@ -240,6 +255,8 @@ void CM249::WeaponIdle(void) m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES); + UpdateTape(m_iVisibleClip); + if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase()) return; @@ -253,17 +270,23 @@ void CM249::WeaponIdle(void) m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 155.0/25.0; } - SendWeaponAnim(iAnim); + SendWeaponAnim(iAnim, UseDecrement(), pev->body); m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15); // how long till we do this again. } void CM249::UpdateTape() { - if (m_iClip == 0) { + UpdateTape(m_iClip); + m_iVisibleClip = m_iClip; +} + +void CM249::UpdateTape(int clip) +{ + if (clip == 0) { pev->body = 8; - } else if (m_iClip > 0 && m_iClip < 8) { - pev->body = 9 - m_iClip; + } else if (m_iClip > 0 && clip < 8) { + pev->body = 9 - clip; } else { pev->body = 0; } diff --git a/dlls/weapons.h b/dlls/weapons.h index a2f7e4a8..ae606889 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -1264,6 +1264,9 @@ public: } void UpdateTape(); + void UpdateTape(int clip); + + int m_iVisibleClip; private: unsigned short m_usM249;