sp/src/game/shared/hl2/weapon_css_base.cpp
void CBase_CSS_HL2_Shotgun::ItemPostFrame( void )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	if (!pOwner)
	{
		return;
	}

	if (m_bInReload)
	{
		// If I'm primary firing and have one round stop reloading and fire
		if ((pOwner->m_nButtons & IN_ATTACK ) && (m_iClip1 >=1))
		{
			m_bInReload		= false;
			m_bNeedPump		= false;
			m_bDelayedFire1 = true;
		}
		// If I'm secondary firing and have one round stop reloading and fire
		else if ((pOwner->m_nButtons & IN_ATTACK2 ) && (m_iClip1 >=2))
		{
			m_bInReload		= false;
			m_bNeedPump		= false;
			m_bDelayedFire2 = true;
		}
		else if (m_flNextPrimaryAttack <= gpGlobals->curtime)
		{
			// If out of ammo end reload
			if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <=0)
			{
				FinishReload();
				return;
			}
			// If clip not full reload again
			if (m_iClip1 < GetMaxClip1())
			{
				Reload();
				return;
			}
			// Clip full, stop reloading
			else
			{
				FinishReload();
				return;
			}
		}
	}
	else
	{			
		// Make shotgun shell invisible
		SetBodygroup(1,1);
	}

	if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		Pump();
		return;
	}
	
	// Shotgun uses same timing and ammo for secondary attack
	if ((m_bDelayedFire2 || pOwner->m_nButtons & IN_ATTACK2)&&(m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		m_bDelayedFire2 = false;
		
		if ( (m_iClip1 <= 1 && UsesClipsForAmmo1()))
		{
			// If only one shell is left, do a single shot instead	
			if ( m_iClip1 == 1 )
			{
				PrimaryAttack();
			}
			else if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType))
			{
				DryFire();
			}
			else
			{
				StartReload();
			}
		}

		// Fire underwater?
		else if (GetOwner()->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 ( pOwner->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}
			SecondaryAttack();
		}
	}
	else if ( (m_bDelayedFire1 || pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime)
	{
		m_bDelayedFire1 = false;
		if ( (m_iClip1 <= 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pOwner->GetAmmoCount(m_iPrimaryAmmoType) ) )
		{
			if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType))
			{
				DryFire();
			}
			else
			{
				StartReload();
			}
		}
		// Fire underwater?
		else if (pOwner->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
			CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
			if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}
			PrimaryAttack();
		}
	}

	if ( pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) 
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.
		StartReload();
	}
	else 
	{
		// no fire buttons down
		m_bFireOnEmpty = false;

		if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
		{
			// weapon isn't useable, switch.
			if ( !(GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pOwner->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 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				if (StartReload())
				{
					// if we've successfully started to reload, we're done
					return;
				}
			}
		}

		WeaponIdle( );
		return;
	}

}
//-----------------------------------------------------------------------------
// Purpose: Override so shotgun can do mulitple reloads in a row
//-----------------------------------------------------------------------------
Override so shotgun can do mulitple reloads in a row
Override so shotgun can do mulitple reloads in a row
void CBase_CSS_HL2_Shotgun::ItemPostFrame( void )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	if (!pOwner)
	{
		return;
	}
	if (m_bInReload)
	{
		if ((pOwner->m_nButtons & IN_ATTACK ) && (m_iClip1 >=1))
		{
			m_bInReload		= false;
			m_bNeedPump		= false;
			m_bDelayedFire1 = true;
		}
		else if ((pOwner->m_nButtons & IN_ATTACK2 ) && (m_iClip1 >=2))
		{
			m_bInReload		= false;
			m_bNeedPump		= false;
			m_bDelayedFire2 = true;
		}
		else if (m_flNextPrimaryAttack <= gpGlobals->curtime)
		{
			if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <=0)
			{
				FinishReload();
				return;
			}
			if (m_iClip1 < GetMaxClip1())
			{
				Reload();
				return;
			}
			else
			{
				FinishReload();
				return;
			}
		}
	}
	else
	{			
		SetBodygroup(1,1);
	}
	if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		Pump();
		return;
	}
	if ((m_bDelayedFire2 || pOwner->m_nButtons & IN_ATTACK2)&&(m_flNextPrimaryAttack <= gpGlobals->curtime))
	{
		m_bDelayedFire2 = false;
		if ( (m_iClip1 <= 1 && UsesClipsForAmmo1()))
		{
			if ( m_iClip1 == 1 )
			{
				PrimaryAttack();
			}
			else if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType))
			{
				DryFire();
			}
			else
			{
				StartReload();
			}
		}
		else if (GetOwner()->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
		{
			WeaponSound(EMPTY);
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
			return;
		}
		else
		{
			if ( pOwner->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}
			SecondaryAttack();
		}
	}
	else if ( (m_bDelayedFire1 || pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime)
	{
		m_bDelayedFire1 = false;
		if ( (m_iClip1 <= 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pOwner->GetAmmoCount(m_iPrimaryAmmoType) ) )
		{
			if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType))
			{
				DryFire();
			}
			else
			{
				StartReload();
			}
		}
		else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
		{
			WeaponSound(EMPTY);
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
			return;
		}
		else
		{
			CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
			if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK )
			{
				 m_flNextPrimaryAttack = gpGlobals->curtime;
			}
			PrimaryAttack();
		}
	}
	if ( pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) 
	{
		StartReload();
	}
	else 
	{
		m_bFireOnEmpty = false;
		if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
		{
			if ( !(GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pOwner->SwitchToNextBestWeapon( this ) )
			{
				m_flNextPrimaryAttack = gpGlobals->curtime + 0.3;
				return;
			}
		}
		else
		{
			if ( m_iClip1 <= 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				if (StartReload())
				{
					return;
				}
			}
		}
		WeaponIdle( );
		return;
	}
}
void CBase_CSS_HL2_Shotgun :: ItemPostFrame ( void ) { CBasePlayer * pOwner = ToBasePlayer ( GetOwner ( ) ) ; if ( ! pOwner ) { return ; } if ( m_bInReload ) { if ( ( pOwner -> m_nButtons & IN_ATTACK ) && ( m_iClip1 >= 1 ) ) { m_bInReload = false ; m_bNeedPump = false ; m_bDelayedFire1 = true ; } else if ( ( pOwner -> m_nButtons & IN_ATTACK2 ) && ( m_iClip1 >= 2 ) ) { m_bInReload = false ; m_bNeedPump = false ; m_bDelayedFire2 = true ; } else if ( m_flNextPrimaryAttack <= gpGlobals -> curtime ) { if ( pOwner -> GetAmmoCount ( m_iPrimaryAmmoType ) <= 0 ) { FinishReload ( ) ; return ; } if ( m_iClip1 < GetMaxClip1 ( ) ) { Reload ( ) ; return ; } else { FinishReload ( ) ; return ; } } } else { SetBodygroup ( 1 , 1 ) ; } if ( ( m_bNeedPump ) && ( m_flNextPrimaryAttack <= gpGlobals -> curtime ) ) { Pump ( ) ; return ; } if ( ( m_bDelayedFire2 || pOwner -> m_nButtons & IN_ATTACK2 ) && ( m_flNextPrimaryAttack <= gpGlobals -> curtime ) ) { m_bDelayedFire2 = false ; if ( ( m_iClip1 <= 1 && UsesClipsForAmmo1 ( ) ) ) { if ( m_iClip1 == 1 ) { PrimaryAttack ( ) ; } else if ( ! pOwner -> GetAmmoCount ( m_iPrimaryAmmoType ) ) { DryFire ( ) ; } else { StartReload ( ) ; } } else if ( GetOwner ( ) -> GetWaterLevel ( ) == 3 && m_bFiresUnderwater == false ) { WeaponSound ( EMPTY ) ; m_flNextPrimaryAttack = gpGlobals -> curtime + 0.2 ; return ; } else { if ( pOwner -> m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals -> curtime ; } SecondaryAttack ( ) ; } } else if ( ( m_bDelayedFire1 || pOwner -> m_nButtons & IN_ATTACK ) && m_flNextPrimaryAttack <= gpGlobals -> curtime ) { m_bDelayedFire1 = false ; if ( ( m_iClip1 <= 0 && UsesClipsForAmmo1 ( ) ) || ( ! UsesClipsForAmmo1 ( ) && ! pOwner -> GetAmmoCount ( m_iPrimaryAmmoType ) ) ) { if ( ! pOwner -> GetAmmoCount ( m_iPrimaryAmmoType ) ) { DryFire ( ) ; } else { StartReload ( ) ; } } else if ( pOwner -> GetWaterLevel ( ) == 3 && m_bFiresUnderwater == false ) { WeaponSound ( EMPTY ) ; m_flNextPrimaryAttack = gpGlobals -> curtime + 0.2 ; return ; } else { CBasePlayer * pPlayer = ToBasePlayer ( GetOwner ( ) ) ; if ( pPlayer && pPlayer -> m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals -> curtime ; } PrimaryAttack ( ) ; } } if ( pOwner -> m_nButtons & IN_RELOAD && UsesClipsForAmmo1 ( ) && ! m_bInReload ) { StartReload ( ) ; } else { m_bFireOnEmpty = false ; if ( ! HasAnyAmmo ( ) && m_flNextPrimaryAttack < gpGlobals -> curtime ) { if ( ! ( GetWeaponFlags ( ) & ITEM_FLAG_NOAUTOSWITCHEMPTY ) && pOwner -> SwitchToNextBestWeapon ( this ) ) { m_flNextPrimaryAttack = gpGlobals -> curtime + 0.3 ; return ; } } else { if ( m_iClip1 <= 0 && ! ( GetWeaponFlags ( ) & ITEM_FLAG_NOAUTORELOAD ) && m_flNextPrimaryAttack < gpGlobals -> curtime ) { if ( StartReload ( ) ) { return ; } } } WeaponIdle ( ) ; return ; } }
Purpose: Override so shotgun can do mulitple reloads in a row
Purpose : Override so shotgun can do mulitple reloads in a row
// If I'm primary firing and have one round stop reloading and fire // If I'm secondary firing and have one round stop reloading and fire // If out of ammo end reload // If clip not full reload again // Clip full, stop reloading // Make shotgun shell invisible // Shotgun uses same timing and ammo for secondary attack // If only one shell is left, do a single shot instead	 // Fire underwater? // If the firing button was just pressed, reset the firing time // Fire underwater? // If the firing button was just pressed, reset the firing time // reload when reload is pressed, or if no buttons are down and weapon is empty. // 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 // if we've successfully started to reload, we're done