예제 #1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponBuilder::ItemPostFrame( void )
{
	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if ( !pOwner )
		return;

	// Ignore input while the player's building anything
	if ( pOwner->IsBuilding() )
		return;

	// Switch away if I'm not in placement mode
	if ( m_iBuildState != BS_PLACING && m_iBuildState != BS_PLACING_INVALID )
	{
		pOwner->SwitchToNextBestWeapon( NULL );
		return;
	}

	if (( pOwner->m_nButtons & IN_ATTACK ) && (m_flNextPrimaryAttack <= gpGlobals->curtime) )
	{
		PrimaryAttack();
	}

	// Allow shield post frame 
	AllowShieldPostFrame( true );

	WeaponIdle();
}
//-----------------------------------------------------------------------------
// Purpose: Handle deploying, undeploying, firing, etc.
// TODO: Add a deploy to the firing!  Currently no reloading!
//-----------------------------------------------------------------------------
void CWeaponRocketLauncher::ItemPostFrame( void )
{
	// Get the player.
	CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
	if ( !pPlayer )
		return;

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

#if !defined( CLIENT_DLL )
	if ( !HasPrimaryAmmo() && ( m_flNextPrimaryAttack <= gpGlobals->curtime ) )
	{
		pPlayer->SwitchToNextBestWeapon( NULL );
	}
#endif

	// Handle Firing
	if ( GetShieldState() == SS_DOWN && !m_bInReload )
	{
		// Attempting to fire.
		if ( ( pPlayer->m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack <= gpGlobals->curtime ) )
		{
			if ( m_iClip1 > 0 )
			{
				PrimaryAttack();
			}
			else
			{
				Reload();
			}
		}

		// Reload button (or fire button when we're out of ammo)
		if ( m_flNextPrimaryAttack <= gpGlobals->curtime ) 
		{
			if ( pPlayer->m_nButtons & IN_RELOAD ) 
			{
				Reload();
			}
			else if ( !((pPlayer->m_nButtons & IN_ATTACK) || (pPlayer->m_nButtons & IN_ATTACK2) || (pPlayer->m_nButtons & IN_RELOAD)) )
			{
				if ( !m_iClip1 && HasPrimaryAmmo() )
				{
					Reload();
				}
			}
		}
	}

	// Prevent shield post frame if we're not ready to attack, or we're charging
	AllowShieldPostFrame( m_flNextPrimaryAttack <= gpGlobals->curtime || m_bInReload );
}
예제 #3
0
//-----------------------------------------------------------------------------
// Purpose: Start placing or building the currently selected object
//-----------------------------------------------------------------------------
void CWeaponBuilder::PrimaryAttack( void )
{
	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if ( !pOwner )
		return;

	// What state should we move to?
	switch( m_iBuildState )
	{
	case BS_IDLE:
		{
			// Idle state starts selection
			SetCurrentState( BS_SELECTING );
		}
		break;

	case BS_SELECTING:
		{
			// Do nothing, client handles selection
			return;
		}
		break;

	case BS_PLACING:
		{
			if ( m_hObjectBeingBuilt )
			{
				// Give the object a chance to veto the "start building" command. Objects like barbed wire
				// may want to change their properties instead of actually building yet.
				if ( m_hObjectBeingBuilt->PreStartBuilding() )
				{
					int iFlags = m_hObjectBeingBuilt->GetObjectFlags();

					// Can't build if the game hasn't started
					if ( !tf_fastbuild.GetInt() && CurrentActIsAWaitingAct() )
					{
						ClientPrint( pOwner, HUD_PRINTCENTER, "Can't build until the game's started.\n" );
						return;
					}

					StartBuilding();

					// Should we switch away?
					if ( iFlags & OF_ALLOW_REPEAT_PLACEMENT )
					{
						// Start placing another
						SetCurrentState( BS_PLACING );
						StartPlacement(); 
					}
					else
					{
						pOwner->SwitchToNextBestWeapon( NULL );
					}
				}
			}
		}
		break;

	case BS_PLACING_INVALID:
		{
			WeaponSound( SINGLE_NPC );

			// If there is any associated error text when placing the object, display it
			if( m_hObjectBeingBuilt != NULL )
			{
				if (m_hObjectBeingBuilt->MustBeBuiltInResourceZone())
				{
					ClientPrint( pOwner, HUD_PRINTCENTER, "Only placeable in an empty resource zone.\n" );
				}
				else if (m_hObjectBeingBuilt->MustBeBuiltInConstructionYard())
				{
					ClientPrint( pOwner, HUD_PRINTCENTER, "Only placeable in a construction yard.\n" );
				}
			}
		}
		break;
	}

	m_flNextPrimaryAttack = gpGlobals->curtime + 0.2f;
}