Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFSniperRifle::Fire( CTFPlayer *pPlayer )
{
	// Check the ammo.  We don't use clip ammo, check the primary ammo type.
	if ( pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 )
	{
		HandleFireOnEmpty();
		return;
	}

	if ( m_flNextPrimaryAttack > gpGlobals->curtime )
		return;

	// Fire the sniper shot.
	PrimaryAttack();

	if ( IsZoomed() )
	{
		// If we have more bullets, zoom out, play the bolt animation and zoom back in
		if( pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) > 0 )
		{
			SetRezoom( true, 0.5f );	// zoom out in 0.5 seconds, then rezoom
		}
		else	
		{
			//just zoom out
			SetRezoom( false, 0.5f );	// just zoom out in 0.5 seconds
		}
	}
	else
	{
		// Prevent primary fire preventing zooms
		m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
	}

	m_flChargedDamage = 0.0f;

#ifdef GAME_DLL
	if ( m_hSniperDot )
	{
		m_hSniperDot->ResetChargeTime();
	}
#endif
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFHunterRifle::Fire(CTFPlayer *pPlayer)
{
	if ( m_flNextPrimaryAttack > gpGlobals->curtime )
		return;

	// Check the ammo.
	if ( Clip1() <= 0 )
	{
		HandleFireOnEmpty();
		return;
	}

	// Fire the Hunter shot.
	PrimaryAttack();

	if ( !IsZoomed() )
	{
		// Prevent primary fire preventing zooms
		m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
	}

	m_flChargedSpread = TF_WEAPON_HUNTERRIFLE_SPREAD_MAX;
}
Ejemplo n.º 3
0
// check player or marine commander's buttons for firing/reload/etc
void CASW_Weapon::ItemPostFrame( void )
{
	//CBasePlayer *pOwner = GetCommander();
	CASW_Marine* pOwner = GetMarine();
	if (!pOwner)
		return;

	bool bThisActive = ( pOwner && pOwner->GetActiveWeapon() == this );

	bool bAttack1, bAttack2, bReload, bOldReload, bOldAttack1;
	GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 );

	if ( pOwner->IsHacking() )
	{
		bThisActive = bAttack1 = bAttack2 = bReload = false;
	}

	// check for clearing our weapon switching bool
	if (m_bSwitchingWeapons && gpGlobals->curtime > m_flNextPrimaryAttack)
	{
		m_bSwitchingWeapons = false;
	}

	// check for clearing our firing bool from reloading
	if (m_bInReload && gpGlobals->curtime > m_fReloadClearFiringTime)
	{
		ClearIsFiring();
	}

	if ( m_bShotDelayed && gpGlobals->curtime > m_flDelayedFire )
	{
		DelayedAttack();
	}

	if ( UsesClipsForAmmo1() )
	{
		CheckReload();
	}

	bool bFired = false;
	if ( bThisActive )
	{
		//Track the duration of the fire
		//FIXME: Check for IN_ATTACK2 as well?
		//FIXME: What if we're calling ItemBusyFrame?
		m_fFireDuration = bAttack1 ? ( m_fFireDuration + gpGlobals->frametime ) : 0.0f;

		if (bAttack2 && (m_flNextSecondaryAttack <= gpGlobals->curtime) && gpGlobals->curtime > pOwner->m_fFFGuardTime)
		{
			if ( SecondaryAttackUsesPrimaryAmmo() )
			{
				if ( !IsMeleeWeapon() &&  
					(( UsesClipsForAmmo1() && !(this->PrimaryAmmoLoaded())) || ( !UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType)<=0 )) )
				{
					HandleFireOnEmpty();
				}
				else
				{
					bFired = true;
					SecondaryAttack();

#ifndef CLIENT_DLL
					if ( pOwner->IsInhabited() )
					{
						IGameEvent * event = gameeventmanager->CreateEvent( "player_alt_fire" );
						if ( event )
						{
							CASW_Player *pPlayer = pOwner->GetCommander();
							event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
							gameeventmanager->FireEvent( event );
						}
					}
#endif
				}
			}
			else if ( UsesSecondaryAmmo() &&  
				 ( ( UsesClipsForAmmo2() && m_iClip2 <= 0 ) ||
				   ( !UsesClipsForAmmo2() && pOwner->GetAmmoCount( m_iSecondaryAmmoType ) <= 0 ) ) )
			{
				if ( m_flNextEmptySoundTime < gpGlobals->curtime )
				{
					WeaponSound( EMPTY );
					m_flNextSecondaryAttack = m_flNextEmptySoundTime = gpGlobals->curtime + 0.5;
				}
			}		
			else
			{
				bFired = true;
				SecondaryAttack();

#ifndef CLIENT_DLL
				if ( pOwner->IsInhabited() )
				{
					IGameEvent * event = gameeventmanager->CreateEvent( "player_alt_fire" );
					if ( event )
					{
						CASW_Player *pPlayer = pOwner->GetCommander();
						event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
						gameeventmanager->FireEvent( event );
					}
				}
#endif

				// Secondary ammo doesn't have a reload animation
				// this code makes secondary ammo come from nowhere!
				/*
				if ( UsesClipsForAmmo2() )
				{
					// reload clip2 if empty
					if (m_iClip2 < 1)
					{
						pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType );
						m_iClip2 = m_iClip2 + 1;
					}
				}*/
			}
		}
		
		if ( !bFired && bAttack1 && (m_flNextPrimaryAttack <= gpGlobals->curtime) && gpGlobals->curtime > pOwner->m_fFFGuardTime)
		{
			// Clip empty? Or out of ammo on a no-clip weapon?
			if ( !IsMeleeWeapon() &&  
				(( UsesClipsForAmmo1() && !(this->PrimaryAmmoLoaded())) || ( !UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType)<=0 )) )
			{
				HandleFireOnEmpty();
			}
			else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
			{
				// This weapon doesn't fire underwater
				WeaponSound(EMPTY);
				m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
				return;
			}
			else
			{
				//NOTENOTE: There is a bug with this code with regards to the way machine guns catch the leading edge trigger
				//			on the player hitting the attack key.  It relies on the gun catching that case in the same frame.
				//			However, because the player can also be doing a secondary attack, the edge trigger may be missed.
				//			We really need to hold onto the edge trigger and only clear the condition when the gun has fired its
				//			first shot.  Right now that's too much of an architecture change -- jdw
				
				// If the firing button was just pressed, reset the firing time
				if ( pOwner && bAttack1 )
				{
	#ifdef CLIENT_DLL
					//Msg("[Client] setting nextprimaryattack to now %f\n", gpGlobals->curtime);
	#else
					//Msg("[Server] setting nextprimaryattack to now %f\n", gpGlobals->curtime);
	#endif
					 m_flNextPrimaryAttack = gpGlobals->curtime;
				}
				PrimaryAttack();
			}
		}
	}

	if (!bAttack1)	// clear our firing var if we don't have the attack button held down (not totally accurate since firing could continue for some time after pulling the trigger, but it's good enough for our purposes)
	{
		m_bIsFiring = false;		// NOTE: Only want to clear primary fire IsFiring bool here (i.e. don't call ClearIsFiring as that'll clear secondary fire too, in subclasses that have it)
		if ( bOldAttack1 )
		{
			OnStoppedFiring();
		}
	}

	// -----------------------
	//  Reload pressed / Clip Empty
	// -----------------------
	if ( bReload && UsesClipsForAmmo1())	
	{
		if ( m_bInReload ) 
		{
			// todo: check for a fast reload
			//Msg("Check for fast reload\n");
		}
		else
		{
			// reload when reload is pressed, or if no buttons are down and weapon is empty.
			Reload();
			m_fFireDuration = 0.0f;
		}
	}

	// -----------------------
	//  No buttons down
	// -----------------------
	if (!(bAttack1 || bAttack2 || bReload))
	{
		// no fire buttons down or reloading
		if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) )
		{
			WeaponIdle();
		}
	}
}