From ea13d88e37b3c6a8aaa2c49bf569fc56211997bf Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Thu, 1 Aug 2019 01:23:37 +0300 Subject: [PATCH] Update m249 --- cl_dll/ev_hldm.cpp | 2 +- cl_dll/hl/hl_weapons.cpp | 10 ++++++ dlls/gearbox/m249.cpp | 73 ++++++++++++++++++++++++++-------------- dlls/weapons.cpp | 2 +- dlls/weapons.h | 9 ++--- 5 files changed, 62 insertions(+), 34 deletions(-) diff --git a/cl_dll/ev_hldm.cpp b/cl_dll/ev_hldm.cpp index 1388512c..f703cf2d 100644 --- a/cl_dll/ev_hldm.cpp +++ b/cl_dll/ev_hldm.cpp @@ -2018,7 +2018,7 @@ void EV_FireM249( event_args_t *args ) { // Add muzzle flash to current weapon model EV_MuzzleFlash(); - gEngfuncs.pEventAPI->EV_WeaponAnimation( M249_SHOOT1 + gEngfuncs.pfnRandomLong( 0, 2 ), 1 ); + gEngfuncs.pEventAPI->EV_WeaponAnimation( M249_SHOOT1 + gEngfuncs.pfnRandomLong( 0, 2 ), args->iparam2 ); V_PunchAxis( 0, gEngfuncs.pfnRandomFloat( -2, 2 ) ); } diff --git a/cl_dll/hl/hl_weapons.cpp b/cl_dll/hl/hl_weapons.cpp index 78d813f7..3997afcf 100644 --- a/cl_dll/hl/hl_weapons.cpp +++ b/cl_dll/hl/hl_weapons.cpp @@ -1005,6 +1005,16 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm if( pWeapon == &g_Python && bIsMultiplayer() ) body = 1; + if (pWeapon == &g_M249) { + if (g_M249.m_iClip == 0) { + body = 8; + } else if (g_M249.m_iClip > 0 && g_M249.m_iClip < 8) { + body = 9 - g_M249.m_iClip; + } else { + body = 0; + } + } + // Force a fixed anim down to viewmodel HUD_SendWeaponAnim( to->client.weaponanim, body, 1 ); } diff --git a/dlls/gearbox/m249.cpp b/dlls/gearbox/m249.cpp index d735b9e2..7aa7510e 100644 --- a/dlls/gearbox/m249.cpp +++ b/dlls/gearbox/m249.cpp @@ -37,8 +37,7 @@ enum m249_e }; -LINK_ENTITY_TO_CLASS(weapon_m249, CM249); - +LINK_ENTITY_TO_CLASS(weapon_m249, CM249) //========================================================= //========================================================= @@ -51,7 +50,7 @@ void CM249::Spawn() m_iDefaultAmmo = M249_DEFAULT_GIVE; - m_iReloadState = RELOAD_STATE_NONE; + m_fInSpecialReload = 0; FallInit();// get ready to fall down. } @@ -111,9 +110,16 @@ int CM249::AddToPlayer(CBasePlayer *pPlayer) BOOL CM249::Deploy() { + m_fInSpecialReload = FALSE; + UpdateTape(); return DefaultDeploy("models/v_saw.mdl", "models/p_saw.mdl", M249_DEPLOY, "m249"); } +void CM249::Holster(int skiplocal) +{ + m_fInSpecialReload = FALSE; + CBasePlayerWeapon::Holster(); +} void CM249::PrimaryAttack() { @@ -139,8 +145,7 @@ void CM249::PrimaryAttack() m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH; m_iClip--; - - + UpdateTape(); m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH; // player "shoot" animation @@ -172,7 +177,7 @@ void CM249::PrimaryAttack() flags = 0; #endif - PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usM249, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0); + PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usM249, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, pev->body, 0, 0); #ifndef CLIENT_DLL @@ -193,7 +198,7 @@ void CM249::PrimaryAttack() // HEV suit - indicate out of ammo condition m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); - m_flNextPrimaryAttack = GetNextAttackDelay(0.1); + m_flNextPrimaryAttack = GetNextAttackDelay(0.067); if (m_flNextPrimaryAttack < UTIL_WeaponTimeBase()) m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.1; @@ -204,12 +209,31 @@ void CM249::PrimaryAttack() void CM249::Reload(void) { - if (m_pPlayer->ammo_556 <= 0) + if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == M249_MAX_CLIP) return; - DefaultReload(M249_MAX_CLIP, M249_RELOAD1, 1.5); + if (DefaultReload(M249_MAX_CLIP, M249_LAUNCH, 1.33, pev->body)) { + m_fInSpecialReload = TRUE; + m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 3.78; + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3.78; + } } +void CM249::WeaponTick() +{ + if ( m_fInSpecialReload ) + { + if (m_pPlayer->m_flNextAttack <= UTIL_WeaponTimeBase()) + { + UpdateTape(); + m_fInSpecialReload = FALSE; + SendWeaponAnim( M249_RELOAD1, UseDecrement(), pev->body ); + m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 2.4; + } + + return; + } +} void CM249::WeaponIdle(void) { @@ -220,17 +244,14 @@ void CM249::WeaponIdle(void) if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase()) return; + float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0f, 1.0f ); int iAnim; - switch (RANDOM_LONG(0, 1)) - { - case 0: + if (flRand <= 0.8) { iAnim = M249_SLOWIDLE; - break; - - default: - case 1: + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 5; + } else { iAnim = M249_IDLE2; - break; + m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 155.0/25.0; } SendWeaponAnim(iAnim); @@ -238,15 +259,15 @@ void CM249::WeaponIdle(void) m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15); // how long till we do this again. } - -void CM249::ReloadStart(void) +void CM249::UpdateTape() { - SendWeaponAnim(M249_RELOAD1, UseDecrement()); -} - -void CM249::ReloadInsert(void) -{ - SendWeaponAnim(M249_RELOAD1, UseDecrement()); + if (m_iClip == 0) { + pev->body = 8; + } else if (m_iClip > 0 && m_iClip < 8) { + pev->body = 9 - m_iClip; + } else { + pev->body = 0; + } } class CM249AmmoClip : public CBasePlayerAmmo @@ -273,4 +294,4 @@ class CM249AmmoClip : public CBasePlayerAmmo } }; -LINK_ENTITY_TO_CLASS(ammo_556, CM249AmmoClip); \ No newline at end of file +LINK_ENTITY_TO_CLASS(ammo_556, CM249AmmoClip); diff --git a/dlls/weapons.cpp b/dlls/weapons.cpp index be470d33..a2f18e39 100644 --- a/dlls/weapons.cpp +++ b/dlls/weapons.cpp @@ -1697,7 +1697,7 @@ IMPLEMENT_SAVERESTORE( CBarnacleGrapple, CBasePlayerWeapon ) TYPEDESCRIPTION CM249::m_SaveData[] = { - DEFINE_FIELD( CM249, m_iReloadState, FIELD_INTEGER ), + DEFINE_FIELD( CM249, m_fInSpecialReload, FIELD_INTEGER ), }; IMPLEMENT_SAVERESTORE( CM249, CBasePlayerWeapon ) diff --git a/dlls/weapons.h b/dlls/weapons.h index b44278e7..de6c6499 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -1247,7 +1247,9 @@ public: void PrimaryAttack(void); BOOL Deploy(void); + void Holster(int skiplocal = 0); void Reload(void); + void WeaponTick(); void WeaponIdle(void); virtual BOOL ShouldWeaponIdle(void) { return TRUE; } float m_flNextAnimTime; @@ -1262,12 +1264,7 @@ public: #endif } - void ReloadStart( void ); - void ReloadInsert( void ); - - enum M249_RELOAD_STATE { RELOAD_STATE_NONE = 0, RELOAD_STATE_OPEN, RELOAD_STATE_FILL }; - - int m_iReloadState; + void UpdateTape(); private: unsigned short m_usM249;