virtual const Vector& GetBulletSpread( void ) { static const Vector cone = VECTOR_CONE_7DEGREES; static const Vector ironsightCone = VECTOR_CONE_4DEGREES; if (IsIronsighted()) { return ironsightCone; } return cone; }
//----------------------------------------------------------------------------- // Purpose: // Input : &origin - // &angles - // viewmodelindex - //----------------------------------------------------------------------------- void CBaseHLCombatWeapon::AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles ) { Vector forward, right; if (!IsIronsighted()) { AngleVectors(angles, &forward, &right, NULL); CalcViewmodelBob(); // Apply bob, but scaled down to 40% VectorMA(origin, g_verticalBob * 0.1f, forward, origin); // Z bob a bit more origin[2] += g_verticalBob * 0.1f; // bob the angles angles[ROLL] += g_verticalBob * 0.5f; angles[PITCH] -= g_verticalBob * 0.4f; angles[YAW] -= g_lateralBob * 0.3f; VectorMA(origin, g_lateralBob * 0.8f, right, origin); } else { AngleVectors(angles, &forward, &right, NULL); CalcViewmodelBob(); // Apply bob, but scaled down to 40% VectorMA(origin, g_verticalBob * 0.05f, forward, origin); // Z bob a bit more origin[2] += g_verticalBob * 0.05f; // bob the angles angles[ROLL] += g_verticalBob * 0.1f; angles[PITCH] -= g_verticalBob * 0.1f; angles[YAW] -= g_lateralBob * 0.1f; } }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponSMG1::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; m_nShotsFired++; pPlayer->DoMuzzleFlash(); // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, // especially if the weapon we're firing has a really fast rate of fire. int iBulletsToFire = 0; float fireRate = GetFireRate(); // MUST call sound before removing a round from the clip of a CHLMachineGun while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { WeaponSound(SINGLE, m_flNextPrimaryAttack); m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; iBulletsToFire++; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { if ( iBulletsToFire > m_iClip1 ) iBulletsToFire = m_iClip1; m_iClip1 -= iBulletsToFire; } m_iPrimaryAttacks++; gamestats->Event_WeaponFired( pPlayer, true, GetClassname() ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT ); info.m_vecSpread = pPlayer->GetAttackSpread( this ); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; FireBullets( info ); //Factor in the view kick if( IsIronsighted() ) { DoMachineGunKick( pPlayer, 0.5, 5.0, 0.5, 3.0 ); } else { DoMachineGunKick( pPlayer, 0.5, 10.0, 0.5, 3.0 ); } CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pPlayer ); SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); // Register a muzzleflash for the AI pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); }