bool CWeaponCSBaseGun::Reload()
{
	CCSPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return false;

	if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
		return false;

	int iResult = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
	if ( !iResult )
		return false;

	pPlayer->SetAnimation( PLAYER_RELOAD );

#ifndef CLIENT_DLL
	if ((iResult) && (pPlayer->GetFOV() != pPlayer->GetDefaultFOV()))
	{
		pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV() );
	}
#endif

	m_flAccuracy = 0.2;
	pPlayer->m_iShotsFired = 0;
	m_bDelayFire = false;

	pPlayer->SetShieldDrawnState( false );
	return true;
}
bool CDEagle::Reload()
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	if ( pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
		return false;

	if ( !DefaultReload( 7, DEAGLE_RELOAD, 2.2 ) )
		return false;

	//m_pPlayer->SetAnimation( PLAYER_RELOAD );
	m_flAccuracy = 0.9;
	return true;
}
bool CWeaponUSP::Reload()
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
		return true;

	int iResult = DefaultReload( 12, 0, ACT_VM_RELOAD );
	if (!iResult)
		return true;

	pPlayer->SetAnimation( PLAYER_RELOAD );
	m_flAccuracy = 0.92;
	return true;
}
	bool CWeaponCSBase::IsUseable()
	{
		CCSPlayer *pPlayer = GetPlayerOwner();

		if ( Clip1() <= 0 )
		{
			if ( pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 && GetMaxClip1() != -1 )			
			{
				// clip is empty (or nonexistant) and the player has no more ammo of this type. 
				return false;
			}
		}

		return true;
	}
void CWeaponElite::ELITEFire( float flSpread )
{
	CCSPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	pPlayer->m_iShotsFired++;

	if (pPlayer->m_iShotsFired > 1)
		return;

	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	m_flAccuracy -= (0.275)*(0.325 - (gpGlobals->curtime - m_flLastFire));

	if (m_flAccuracy > 0.88)
		m_flAccuracy = 0.88;
	else if (m_flAccuracy < 0.55)
		m_flAccuracy = 0.55;

	m_flLastFire = gpGlobals->curtime;

	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_iClip1--;
	m_bFireRight = !m_bFireRight; // flip side

	pPlayer->DoMuzzleFlash();

	//SetPlayerShieldAnim();
	
	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	FX_FireBullets(
		pPlayer->entindex(),
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
		GetWeaponID(),
		m_bFireRight?Primary_Mode:Secondary_Mode,
		CBaseEntity::GetPredictionRandomSeed() & 255,
		flSpread );
		
	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + GetCSWpnData().m_flCycleTime;
	
	if (!m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}

	SetWeaponIdleTime( gpGlobals->curtime + 2.5 );

	if ( m_bFireRight )  //even number
	{
		if ( m_iClip1 > 1 )
			 SendWeaponAnim( ACT_VM_PRIMARYATTACK );
		else
			 SendWeaponAnim( ACT_VM_DRYFIRE_LEFT );
	}
	else
	{
		if ( m_iClip1 > 0 )
			 SendWeaponAnim( ACT_VM_SECONDARYATTACK );
		else
			 SendWeaponAnim( ACT_VM_DRYFIRE );
	}

	QAngle punchAngle = pPlayer->GetPunchAngle();
	punchAngle.x -= 2;
	pPlayer->SetPunchAngle( punchAngle );

	//ResetPlayerShieldAnim();
}
void CDEagle::DEAGLEFire( float flSpread, float flCycleTime, bool fUseSemi )
{
	CCSPlayer *pPlayer = GetPlayerOwner();


	flCycleTime -= 0.075;
	m_iShotsFired++;

	if (m_iShotsFired > 1)
		return;

	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	if ( m_flLastFire == 0 )
	{
		m_flLastFire = gpGlobals->curtime;
	}
	else 
	{
		m_flAccuracy -= (0.35)*(0.4 - ( gpGlobals->curtime - m_flLastFire ) );

		if (m_flAccuracy > 0.9)
			m_flAccuracy = 0.9;
		else if (m_flAccuracy < 0.55)
			m_flAccuracy = 0.55;

		m_flLastFire = gpGlobals->curtime;
	}


	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_iClip1--;

	pPlayer->m_fEffects |= EF_MUZZLEFLASH;

	//SetPlayerShieldAnim();
	
	// player "shoot" animation
	//m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

	//pPlayer->m_iWeaponVolume = BIG_EXPLOSION_VOLUME;
	//pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;

	Vector vecSrc = pPlayer->Weapon_ShootPosition();
	Vector vecDir = pPlayer->FireBullets3( 
		vecSrc, 
		pPlayer->EyeAngles() + pPlayer->GetPunchAngle(), 
		flSpread, 
		4096, 
		2, 
		GetPrimaryAmmoType(), 
		54, 
		0.81, 
		pPlayer );

	WeaponSound( SINGLE );

	/*
	#if defined( CLIENT_WEAPONS )
		int flag = FEV_NOTHOST;
	#else
		int flag = 0;
	#endif
	
	PLAYBACK_EVENT_FULL( flag, m_pPlayer->edict(), m_usFireDeagle,
		0.0, (float *)&g_vecZero, (float *)&g_vecZero, 
		vecDir.x,
		vecDir.y,
		m_pPlayer->pev->punchangle.x * 100,
		m_pPlayer->pev->punchangle.y * 100, 
		m_iClip1 ? 0 : 1, 0 );
	*/

	m_flNextPrimaryAttack = gpGlobals->curtime + flCycleTime;

	if ( !m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}

	m_flTimeWeaponIdle = gpGlobals->curtime + 1.8;

	QAngle punchAngle = pPlayer->GetPunchAngle();
	punchAngle.x -= 2;
	pPlayer->SetPunchAngle( punchAngle );

	//ResetPlayerShieldAnim();
}
void CWeaponUSP::USPFire( float flSpread, float flCycleTime, bool fUseSemi )
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	flCycleTime -= 0.075;
	m_iShotsFired++;

	if (m_iShotsFired > 1)
		return;
	
	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	if (m_flLastFire == 0)
		m_flLastFire = gpGlobals->curtime;
	else 
	{
		m_flAccuracy -= (0.275)*(0.3 - (gpGlobals->curtime - m_flLastFire));

		if (m_flAccuracy > 0.92)
			m_flAccuracy = 0.92;
		else if (m_flAccuracy < 0.6)
			m_flAccuracy = 0.6;

		m_flLastFire = gpGlobals->curtime;
	}

	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime;

	m_iClip1--;

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	
	int damageAmt;
	if ( m_bSilencerOn )
	{
		WeaponSound( SPECIAL1 );
		damageAmt = 30;
	}
	else
	{
		WeaponSound( SINGLE );
		damageAmt = 34;
		pPlayer->m_fEffects |= EF_MUZZLEFLASH;
	}
	
	Vector vecDir = pPlayer->FireBullets3( 
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + pPlayer->GetPunchAngle(),
		flSpread, 
		4096, 
		1, 
		GetPrimaryAmmoType(), 
		damageAmt, 
		0.79, 
		pPlayer );


	/*
	pPlayer->m_iWeaponVolume = BIG_EXPLOSION_VOLUME;
	pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;

	int flag;
	#if defined( CLIENT_WEAPONS )
		flag = FEV_NOTHOST;
	#else
		flag = 0;
	#endif

	PLAYBACK_EVENT_FULL( flag, pPlayer->edict(), m_usFireUSP,
	0.0, (float *)&g_vecZero, (float *)&g_vecZero, 
	vecDir.x,
	vecDir.y,
	pPlayer->pev->punchangle.x * 100, 0, m_iClip1 ? 0 : 1, (m_iWeaponState & WPNSTATE_USP_SILENCER_ON) ? 1 : 0 );
	*/

	if (!m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}
 
	m_flTimeWeaponIdle = gpGlobals->curtime + 2;

	QAngle angle = pPlayer->GetPunchAngle();
	angle.x -= 2;
	pPlayer->SetPunchAngle( angle );
}
bool CWeaponCSBaseGun::CSBaseGunFire( float flSpread, float flCycleTime, bool bPrimaryMode )
{
	CCSPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return false;

	const CCSWeaponInfo &pCSInfo = GetCSWpnData();

	m_bDelayFire = true;
	pPlayer->m_iShotsFired++;
	
	// These modifications feed back into flSpread eventually.
	if ( pCSInfo.m_flAccuracyDivisor != -1 )
	{
		int iShotsFired = pPlayer->m_iShotsFired;

		if ( pCSInfo.m_bAccuracyQuadratic )
			iShotsFired = iShotsFired * iShotsFired;
		else
			iShotsFired = iShotsFired * iShotsFired * iShotsFired;

		m_flAccuracy = ( iShotsFired / pCSInfo.m_flAccuracyDivisor) + pCSInfo.m_flAccuracyOffset;
		
		if (m_flAccuracy > pCSInfo.m_flMaxInaccuracy)
			m_flAccuracy = pCSInfo.m_flMaxInaccuracy;
	}

	// Out of ammo?
	if ( m_iClip1 <= 0 )
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return false;
	}

	SendWeaponAnim( ACT_VM_PRIMARYATTACK );

	m_iClip1--;

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	FX_FireBullets(
		pPlayer->entindex(),
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
		GetWeaponID(),
		bPrimaryMode?Primary_Mode:Secondary_Mode,
		CBaseEntity::GetPredictionRandomSeed() & 255,
		flSpread );

	DoFireEffects();

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime;

	if (!m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}

	SetWeaponIdleTime( gpGlobals->curtime + pCSInfo.m_flTimeToIdleAfterFire );
	return true;
}
void CWeaponCSBase::ItemPostFrame()
{
	CCSPlayer *pPlayer = GetPlayerOwner();


	//GOOSEMAN : Return zoom level back to previous zoom level before we fired a shot. This is used only for the AWP.
	if ( (m_flNextPrimaryAttack <= gpGlobals->curtime) && (pPlayer->m_bResumeZoom == TRUE) )
	{
		#ifndef CLIENT_DLL
			pPlayer->SetFOV( pPlayer->m_iLastZoom );

			if ( pPlayer->GetFOV() == pPlayer->m_iLastZoom )
			{
				// return the fade level in zoom.
				pPlayer->m_bResumeZoom = false;
			}
		#endif
	}

	//GOOSEMAN : Delayed shell ejection code..
	if ( (pPlayer->m_flEjectBrass != 0.0) && (pPlayer->m_flEjectBrass <= gpGlobals->curtime ) )
	{
		pPlayer->m_flEjectBrass = 0.0;
		EjectBrassLate();
	}


	if ((m_bInReload) && (pPlayer->m_flNextAttack <= gpGlobals->curtime))
	{
		// complete the reload. 
		int j = min( GetMaxClip1() - m_iClip1, pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) );	

		// Add them to the clip
		m_iClip1 += j;
		pPlayer->RemoveAmmo( j, m_iPrimaryAmmoType );

		m_bInReload = false;
	}

	if ((pPlayer->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
	{
		if ( m_iClip2 != -1 && !pPlayer->GetAmmoCount( GetSecondaryAmmoType() ) )
		{
			m_bFireOnEmpty = TRUE;
		}
		SecondaryAttack();
		pPlayer->m_nButtons &= ~IN_ATTACK2;
	}
	else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime ))
	{
		if ( (m_iClip1 == 0/* && pszAmmo1()*/) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) ) )
		{
			m_bFireOnEmpty = TRUE;
		}

		// Can't shoot during the freeze period
		// Ken: Always allow firing in single player
		//---
		if ( !CSGameRules()->IsFreezePeriod() && 
			!pPlayer->m_bIsDefusing &&
			pPlayer->State_Get() == STATE_JOINED
			)
		{
			PrimaryAttack();
		}
		//---
	}
	else if ( pPlayer->m_nButtons & IN_RELOAD && GetMaxClip1() != WEAPON_NOCLIP && !m_bInReload && m_flNextPrimaryAttack < gpGlobals->curtime) 
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.
		
		//MIKETODO: add code for shields...
		//if ( !FBitSet( m_iWeaponState, WPNSTATE_SHIELD_DRAWN ) )
			  Reload();	
	}
	else if ( !(pPlayer->m_nButtons & (IN_ATTACK|IN_ATTACK2) ) )
	{
		// no fire buttons down

		// The following code prevents the player from tapping the firebutton repeatedly 
		// to simulate full auto and retaining the single shot accuracy of single fire
		if (m_bDelayFire == TRUE)
		{
			m_bDelayFire = FALSE;
			if (m_iShotsFired > 15)
				m_iShotsFired = 15;
			m_flDecreaseShotsFired = gpGlobals->curtime + 0.4;
		}

		m_bFireOnEmpty = FALSE;

		// if it's a pistol then set the shots fired to 0 after the player releases a button
		if ( IsPistol() )
		{
			m_iShotsFired = 0;
		}
		else
		{
			if ( (m_iShotsFired > 0) && (m_flDecreaseShotsFired < gpGlobals->curtime)	)
			{
				m_flDecreaseShotsFired = gpGlobals->curtime + 0.0225;
				m_iShotsFired--;
			}
		}

		#ifndef CLIENT_DLL
			if ( !IsUseable() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
			{
				// Intentionally blank -- used to switch weapons here
			}
			else
		#endif
		{
			// 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;
	}
}
示例#10
0
void CWeaponUSP::USPFire( float flSpread )
{
	CCSPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	float flCycleTime =  GetCSWpnData().m_flCycleTime;

	pPlayer->m_iShotsFired++;
	
	if (pPlayer->m_iShotsFired > 1)
		return;
	
	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	m_flAccuracy -= (0.275)*(0.3 - (gpGlobals->curtime - m_flLastFire));

	if (m_flAccuracy > 0.92)
		m_flAccuracy = 0.92;
	else if (m_flAccuracy < 0.6)
		m_flAccuracy = 0.6;

	m_flLastFire = gpGlobals->curtime;

	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime;

	m_iClip1--;

	SendWeaponAnim( ACT_VM_PRIMARYATTACK );

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	
	if ( !m_bSilencerOn )
	{
		pPlayer->DoMuzzleFlash();
	}
	
	FX_FireBullets(
		pPlayer->entindex(),
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
		GetWeaponID(),
		m_bSilencerOn?Secondary_Mode:Primary_Mode,
		CBaseEntity::GetPredictionRandomSeed() & 255,
		flSpread );

	if (!m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}
 
	SetWeaponIdleTime( gpGlobals->curtime + 2 );

	QAngle angle = pPlayer->GetPunchAngle();
	angle.x -= 2;
	pPlayer->SetPunchAngle( angle );
}