sp/src/game/client/hl2/hud_weaponselection.cpp
void CHudWeaponSelection::SelectWeaponSlot( int iSlot )
{
	// iSlot is one higher than it should be, since it's the number key, not the 0-based index into the weapons
	--iSlot;

	// Get the local player.
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	if ( !pPlayer )
		return;

	// Don't try and read past our possible number of slots
	if ( iSlot > MAX_WEAPON_SLOTS )
		return;
	
	// Make sure the player's allowed to switch weapons
	if ( pPlayer->IsAllowedToSwitchWeapons() == false )
		return;

	// do a fast switch if set
	if ( hud_fastswitch.GetBool() )
	{
		FastWeaponSwitch( iSlot );
		return;
	}

	int slotPos = 0;
	C_BaseCombatWeapon *pActiveWeapon = GetSelectedWeapon();

	// start later in the list
	if ( IsInSelectionMode() && pActiveWeapon && pActiveWeapon->GetSlot() == iSlot )
	{
		slotPos = pActiveWeapon->GetPosition() + 1;

		pPlayer->EmitSound( "Player.WeaponSelectionMoveSlot" );
	}
	else
	{
		pPlayer->EmitSound( "Player.WeaponSelectionOpen" );
	}

	// find the weapon in this slot
	pActiveWeapon = GetNextActivePos( iSlot, slotPos );
	if ( !pActiveWeapon )
	{
		pActiveWeapon = GetNextActivePos( iSlot, 0 );
	}
	
	if ( pActiveWeapon != NULL )
	{
		SetSelectedWeapon( pActiveWeapon );
		
		if( hud_fastswitch.GetInt() > 0 )
		{
			// only one active item in bucket, so change directly to weapon
			SelectWeapon();
		}
		else if ( !IsInSelectionMode() )
		{
			// open the weapon selection
			OpenSelection();
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Moves selection to the specified slot
//-----------------------------------------------------------------------------
Moves selection to the specified slot
Moves selection to the specified slot
void CHudWeaponSelection::SelectWeaponSlot( int iSlot )
{
	--iSlot;
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	if ( !pPlayer )
		return;
	if ( iSlot > MAX_WEAPON_SLOTS )
		return;
	if ( pPlayer->IsAllowedToSwitchWeapons() == false )
		return;
	if ( hud_fastswitch.GetBool() )
	{
		FastWeaponSwitch( iSlot );
		return;
	}
	int slotPos = 0;
	C_BaseCombatWeapon *pActiveWeapon = GetSelectedWeapon();
	if ( IsInSelectionMode() && pActiveWeapon && pActiveWeapon->GetSlot() == iSlot )
	{
		slotPos = pActiveWeapon->GetPosition() + 1;
		pPlayer->EmitSound( "Player.WeaponSelectionMoveSlot" );
	}
	else
	{
		pPlayer->EmitSound( "Player.WeaponSelectionOpen" );
	}
	pActiveWeapon = GetNextActivePos( iSlot, slotPos );
	if ( !pActiveWeapon )
	{
		pActiveWeapon = GetNextActivePos( iSlot, 0 );
	}
	if ( pActiveWeapon != NULL )
	{
		SetSelectedWeapon( pActiveWeapon );
		if( hud_fastswitch.GetInt() > 0 )
		{
			SelectWeapon();
		}
		else if ( !IsInSelectionMode() )
		{
			OpenSelection();
		}
	}
}
void CHudWeaponSelection :: SelectWeaponSlot ( int iSlot ) { -- iSlot ; C_BasePlayer * pPlayer = C_BasePlayer :: GetLocalPlayer ( ) ; if ( ! pPlayer ) return ; if ( iSlot > MAX_WEAPON_SLOTS ) return ; if ( pPlayer -> IsAllowedToSwitchWeapons ( ) == false ) return ; if ( hud_fastswitch . GetBool ( ) ) { FastWeaponSwitch ( iSlot ) ; return ; } int slotPos = 0 ; C_BaseCombatWeapon * pActiveWeapon = GetSelectedWeapon ( ) ; if ( IsInSelectionMode ( ) && pActiveWeapon && pActiveWeapon -> GetSlot ( ) == iSlot ) { slotPos = pActiveWeapon -> GetPosition ( ) + 1 ; pPlayer -> EmitSound ( " " ) ; } else { pPlayer -> EmitSound ( " " ) ; } pActiveWeapon = GetNextActivePos ( iSlot , slotPos ) ; if ( ! pActiveWeapon ) { pActiveWeapon = GetNextActivePos ( iSlot , 0 ) ; } if ( pActiveWeapon != NULL ) { SetSelectedWeapon ( pActiveWeapon ) ; if ( hud_fastswitch . GetInt ( ) > 0 ) { SelectWeapon ( ) ; } else if ( ! IsInSelectionMode ( ) ) { OpenSelection ( ) ; } } }
Purpose: Moves selection to the specified slot
Purpose : Moves selection to the specified slot
// iSlot is one higher than it should be, since it's the number key, not the 0-based index into the weapons // Get the local player. // Don't try and read past our possible number of slots // Make sure the player's allowed to switch weapons // do a fast switch if set // start later in the list // find the weapon in this slot // only one active item in bucket, so change directly to weapon // open the weapon selection