From 4807bfdd913b572409ba3d3eeff22e74c975f58a Mon Sep 17 00:00:00 2001 From: Night Owl Date: Sun, 31 Dec 2017 19:05:32 +0500 Subject: [PATCH] Add bullets spread such as in original "Escape from the Darkness". --- dlls/eftd/ak47.cpp | 19 +++++++++++++--- dlls/eftd/mac10.cpp | 16 ++++++------- dlls/glock.cpp | 55 ++++++++++++++++++++++----------------------- dlls/player.cpp | 34 ++++++++++++++++++++++++++++ dlls/player.h | 3 +++ 5 files changed, 87 insertions(+), 40 deletions(-) diff --git a/dlls/eftd/ak47.cpp b/dlls/eftd/ak47.cpp index 4aa02356..0ccd7ab6 100644 --- a/dlls/eftd/ak47.cpp +++ b/dlls/eftd/ak47.cpp @@ -141,13 +141,26 @@ void CAK47::PrimaryAttack() Vector vecSpread; // Allow for higher accuracy when the player is crouching. - if (m_pPlayer->pev->flags & FL_DUCKING) + if( m_pPlayer->pev->flags & FL_DUCKING ) { - vecSpread = VECTOR_CONE_2DEGREES; + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 1.6 + 0.01, m_pPlayer->m_flBulletSpreadCoefficient * 1.4 + 0.01, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.045 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.006; } else { - vecSpread = VECTOR_CONE_5DEGREES; + if( m_pPlayer->pev->button & IN_JUMP ) + { + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 2.4 + 0.065, m_pPlayer->m_flBulletSpreadCoefficient * 2.1 + 0.05, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.08 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.009; + } + else + { + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 8.0 + 0.3, m_pPlayer->m_flBulletSpreadCoefficient * 6.0 + 0.2, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.1 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.012; + } } // single player spread diff --git a/dlls/eftd/mac10.cpp b/dlls/eftd/mac10.cpp index 7e3a3fb6..64c6d387 100644 --- a/dlls/eftd/mac10.cpp +++ b/dlls/eftd/mac10.cpp @@ -140,15 +140,13 @@ void CMac10::PrimaryAttack() Vector vecDir; Vector vecSpread; - // Allow for higher accuracy when the player is crouching. - if (m_pPlayer->pev->flags & FL_DUCKING) - { - vecSpread = VECTOR_CONE_1DEGREES; - } - else - { - vecSpread = VECTOR_CONE_4DEGREES; - } + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 1.2 + 0.03, m_pPlayer->m_flBulletSpreadCoefficient * 0.9 + 0.02, 0 ); + + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.06 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.0027; + + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.1 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.002; // single player spread vecDir = m_pPlayer->FireBulletsPlayer(1, vecSrc, vecAiming, vecSpread, 8192, BULLET_PLAYER_MAC10, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed); diff --git a/dlls/glock.cpp b/dlls/glock.cpp index 1c045d9b..b0e13a05 100644 --- a/dlls/glock.cpp +++ b/dlls/glock.cpp @@ -109,8 +109,6 @@ void CGlock::Holster(int skiplocal /*= 0*/) m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5; SendWeaponAnim( GLOCK_HOLSTER ); - - m_fInAttack = 0; } void CGlock::SecondaryAttack( void ) @@ -119,17 +117,7 @@ void CGlock::SecondaryAttack( void ) void CGlock::PrimaryAttack( void ) { - float flSpread; - - // Allow for higher accuracy when the player is crouching. - if( m_pPlayer->pev->flags & FL_DUCKING ) - { - flSpread = 0.00873; - } - else - { - flSpread = 0.03490; - } + float flSpread = 0; GlockFire( flSpread, 0.18, TRUE ); } @@ -137,7 +125,7 @@ void CGlock::PrimaryAttack( void ) void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) { // Do not allow attack unless primary attack key was released. - if( m_fInAttack ) + if( FBitSet ( m_pPlayer->m_afButtonLast, IN_ATTACK ) ) return; if( m_iClip <= 0 ) @@ -153,9 +141,6 @@ void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) return; } - // Prevent from continuously refire. - m_fInAttack = 1; - m_iClip--; m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH; @@ -184,6 +169,7 @@ void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) Vector vecSrc = m_pPlayer->GetGunPosition(); Vector vecAiming; + Vector vecSpread; if( fUseAutoAim ) { @@ -194,8 +180,30 @@ void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) vecAiming = gpGlobals->v_forward; } - Vector vecDir; - vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, Vector( flSpread, flSpread, flSpread ), 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed ); + // Allow for higher accuracy when the player is crouching. + if( m_pPlayer->pev->flags & FL_DUCKING ) + { + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 2.3 + 0.012, m_pPlayer->m_flBulletSpreadCoefficient * 1.5 + 0.01, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.05 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.003; + } + else + { + if( m_pPlayer->pev->button & IN_JUMP ) + { + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 3.0 + 0.065, m_pPlayer->m_flBulletSpreadCoefficient * 2.0 + 0.055, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.06 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.0045; + } + else + { + vecSpread = Vector( m_pPlayer->m_flBulletSpreadCoefficient * 8.0 + 0.1, m_pPlayer->m_flBulletSpreadCoefficient * 5.0 + 0.1, 0 ); + if( m_pPlayer->m_flBulletSpreadCoefficient < 0.8 ) + m_pPlayer->m_flBulletSpreadCoefficient += 0.009; + } + } + + Vector vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, vecSpread, 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed ); PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireGlock1 : m_usFireGlock2, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 ); @@ -223,9 +231,6 @@ void CGlock::Reload( void ) if( iResult ) { m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); - - // Unblock primary attack. - m_fInAttack = 0; } } @@ -235,12 +240,6 @@ void CGlock::WeaponIdle( void ) m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); - // - // Unblock primary attack. - // This will only occur if players released primary attack key. - // - m_fInAttack = 0; - if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() ) return; diff --git a/dlls/player.cpp b/dlls/player.cpp index 78e7f979..39c85809 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -2621,6 +2621,40 @@ pt_end: if( m_flAmmoStartCharge < -0.001 ) m_flAmmoStartCharge = -0.001; } + + if( pev->flags & FL_DUCKING ) + { + if( gpGlobals->frametime > m_flNextBulletSpreadRandTime + 0.44 ) + { + m_flNextBulletSpreadRandTime = gpGlobals->frametime; + m_flBulletSpreadCoefficient -= 0.0025; + if( !( m_afButtonPressed | m_afButtonReleased ) ) + m_flBulletSpreadCoefficient -= 0.015; + } + } + else + { + if( pev->button & IN_JUMP ) + { + if( gpGlobals->frametime > m_flNextBulletSpreadRandTime + 0.6 ) + { + m_flNextBulletSpreadRandTime = gpGlobals->frametime; + m_flBulletSpreadCoefficient -= 0.0015; + if( !( m_afButtonPressed | m_afButtonReleased ) ) + m_flBulletSpreadCoefficient -= 0.004; + } + } + else if( gpGlobals->frametime > m_flNextBulletSpreadRandTime + 0.47 ) + { + m_flNextBulletSpreadRandTime = gpGlobals->frametime; + m_flBulletSpreadCoefficient -= 0.001; + if( !( m_afButtonPressed | m_afButtonReleased ) ) + m_flBulletSpreadCoefficient -= 0.012; + } + } + + if( m_flBulletSpreadCoefficient < 0.001 ) + m_flBulletSpreadCoefficient = 0.001; #else return; #endif diff --git a/dlls/player.h b/dlls/player.h index 6fc06dbb..73b6cdd1 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -325,6 +325,9 @@ public: float m_flNextChatTime; + float m_flBulletSpreadCoefficient; + float m_flNextBulletSpreadRandTime; + bool m_bSentBhopcap; // If false, the player just joined and needs a bhopcap message. };