sp/src/game/server/hl2/weapon_sniperrifle.cpp
void CWeaponSniperRifle::ItemPostFrame( void )
{
	CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
	if (pPlayer == NULL)
	{
		return;
	}

	if ((m_bInReload) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		FinishReload();
		m_bInReload = false;
	}

	if (pPlayer->m_nButtons & IN_ATTACK2)
	{
		if (m_fNextZoom <= gpGlobals->curtime)
		{
			Zoom();
			pPlayer->m_nButtons &= ~IN_ATTACK2;
		}
	}
	else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		if ( (m_iClip1 == 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) )
		{
			m_bFireOnEmpty = true;
		}

		// Fire underwater?
		if (pPlayer->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
		{
			WeaponSound(EMPTY);
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
			return;
		}
		else
		{
			// If the firing button was just pressed, reset the firing time
			if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}

			PrimaryAttack();
		}
	}

	// -----------------------
	//  Reload pressed / Clip Empty
	// -----------------------
	if ( pPlayer->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) 
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.
		Reload();
	}

	// -----------------------
	//  No buttons down
	// -----------------------
	if (!((pPlayer->m_nButtons & IN_ATTACK) || (pPlayer->m_nButtons & IN_ATTACK2) || (pPlayer->m_nButtons & IN_RELOAD)))
	{
		// no fire buttons down
		m_bFireOnEmpty = false;

		if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
		{
			// weapon isn't useable, switch.
			if ( !(GetFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pPlayer->SwitchToNextBestWeapon( this ) )
			{
				m_flNextPrimaryAttack = gpGlobals->curtime + 0.3;
				return;
			}
		}
		else
		{
			// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
			if ( m_iClip1 == 0 && !(GetFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				Reload();
				return;
			}
		}

		WeaponIdle( );
		return;
	}
}
//-----------------------------------------------------------------------------
// Purpose: Overloaded to handle the zoom functionality.
//-----------------------------------------------------------------------------
Overloaded to handle the zoom functionality.
Overloaded to handle the zoom functionality .
void CWeaponSniperRifle::ItemPostFrame( void )
{
	CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
	if (pPlayer == NULL)
	{
		return;
	}
	if ((m_bInReload) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		FinishReload();
		m_bInReload = false;
	}
	if (pPlayer->m_nButtons & IN_ATTACK2)
	{
		if (m_fNextZoom <= gpGlobals->curtime)
		{
			Zoom();
			pPlayer->m_nButtons &= ~IN_ATTACK2;
		}
	}
	else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		if ( (m_iClip1 == 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) )
		{
			m_bFireOnEmpty = true;
		}
		if (pPlayer->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
		{
			WeaponSound(EMPTY);
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
			return;
		}
		else
		{
			if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}
			PrimaryAttack();
		}
	}
	if ( pPlayer->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) 
	{
		Reload();
	}
	if (!((pPlayer->m_nButtons & IN_ATTACK) || (pPlayer->m_nButtons & IN_ATTACK2) || (pPlayer->m_nButtons & IN_RELOAD)))
	{
		m_bFireOnEmpty = false;
		if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
		{
			if ( !(GetFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pPlayer->SwitchToNextBestWeapon( this ) )
			{
				m_flNextPrimaryAttack = gpGlobals->curtime + 0.3;
				return;
			}
		}
		else
		{
			if ( m_iClip1 == 0 && !(GetFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				Reload();
				return;
			}
		}
		WeaponIdle( );
		return;
	}
}
void CWeaponSniperRifle :: ItemPostFrame ( void ) { CBasePlayer * pPlayer = ToBasePlayer ( GetOwner ( ) ) ; if ( pPlayer == NULL ) { return ; } if ( ( m_bInReload ) && ( m_flNextPrimaryAttack <= gpGlobals -> curtime ) ) { FinishReload ( ) ; m_bInReload = false ; } if ( pPlayer -> m_nButtons & IN_ATTACK2 ) { if ( m_fNextZoom <= gpGlobals -> curtime ) { Zoom ( ) ; pPlayer -> m_nButtons &= ~ IN_ATTACK2 ; } } else if ( ( pPlayer -> m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack <= gpGlobals -> curtime ) ) { if ( ( m_iClip1 == 0 && UsesClipsForAmmo1 ( ) ) || ( ! UsesClipsForAmmo1 ( ) && ! pPlayer -> GetAmmoCount ( m_iPrimaryAmmoType ) ) ) { m_bFireOnEmpty = true ; } if ( pPlayer -> GetWaterLevel ( ) == 3 && m_bFiresUnderwater == false ) { WeaponSound ( EMPTY ) ; m_flNextPrimaryAttack = gpGlobals -> curtime + 0.2 ; return ; } else { if ( pPlayer && pPlayer -> m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals -> curtime ; } PrimaryAttack ( ) ; } } if ( pPlayer -> m_nButtons & IN_RELOAD && UsesClipsForAmmo1 ( ) && ! m_bInReload ) { Reload ( ) ; } if ( ! ( ( pPlayer -> m_nButtons & IN_ATTACK ) || ( pPlayer -> m_nButtons & IN_ATTACK2 ) || ( pPlayer -> m_nButtons & IN_RELOAD ) ) ) { m_bFireOnEmpty = false ; if ( ! HasAnyAmmo ( ) && m_flNextPrimaryAttack < gpGlobals -> curtime ) { if ( ! ( GetFlags ( ) & ITEM_FLAG_NOAUTOSWITCHEMPTY ) && pPlayer -> SwitchToNextBestWeapon ( this ) ) { m_flNextPrimaryAttack = gpGlobals -> curtime + 0.3 ; return ; } } else { if ( m_iClip1 == 0 && ! ( GetFlags ( ) & ITEM_FLAG_NOAUTORELOAD ) && m_flNextPrimaryAttack < gpGlobals -> curtime ) { Reload ( ) ; return ; } } WeaponIdle ( ) ; return ; } }
Purpose: Overloaded to handle the zoom functionality.
Purpose : Overloaded to handle the zoom functionality .
// Fire underwater? // If the firing button was just pressed, reset the firing time // ----------------------- //  Reload pressed / Clip Empty // ----------------------- // reload when reload is pressed, or if no buttons are down and weapon is empty. // ----------------------- //  No buttons down // ----------------------- // no fire buttons down // weapon isn't useable, switch. // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing