Пример #1
0
// 
//  CurWeapon: Update hud state with the current weapon and clip count. Ammo
//  counts are updated with AmmoX. Server assures that the Weapon ammo type 
//  numbers match a real ammo type.
//
int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf )
{
	wrect_t nullrc = {};

	CBufferReader reader( pbuf, iSize );

	const WpnOnTargetState state = static_cast<WpnOnTargetState>( reader.ReadByte() );
	int iId = reader.ReadChar();
	int iClip = reader.ReadChar();

	// detect if we're also on target
	bool fOnTarget = state == WpnOnTargetState::ACTIVE_IS_ONTARGET;

	if ( iId < 1 )
	{
		SetCrosshair(0, nullrc, 0, 0, 0);
		//Clear out the weapon so we don't keep drawing the last active weapon's ammo. - Solokiller
		m_pWeapon = nullptr;
		return 0;
	}

	if ( g_iUser1 != OBS_IN_EYE )
	{
		// Is player dead???
		if ((iId == -1) && (iClip == -1))
		{
			gHUD.m_bPlayerDead = true;
			m_pActiveSel = nullptr;
			return 1;
		}
		gHUD.m_bPlayerDead = false;
	}

	CBasePlayerWeapon *pWeapon = g_Prediction.GetWeapon( iId );

	if( !pWeapon )
	{
		m_bNeedsLocalUpdate = true;
		m_bOnTarget = fOnTarget;
		m_iFlags |= HUD_ACTIVE;
		return 1;
	}
	else if( m_bNeedsLocalUpdate )
		m_bNeedsLocalUpdate = false;

	if ( iClip < -1 )
		pWeapon->m_iClientClip = abs(iClip);
	else
		pWeapon->m_iClientClip = iClip;


	if ( state == WpnOnTargetState::NOT_ACTIVE_WEAPON )	// we're not the current weapon, so update no more
		return 1;

	m_pWeapon = pWeapon;

	UpdateWeaponHUD( m_pWeapon, fOnTarget );
	
	return 1;
}
Пример #2
0
//
// Think:
//  Used for selection of weapon menu item.
//
void CHudAmmo::Think()
{
	if( m_bNeedsLocalUpdate )
	{
		m_bNeedsLocalUpdate = false;

		if( m_pWeapon )
			UpdateWeaponHUD( m_pWeapon, m_bOnTarget );
	}

	if ( gHUD.m_bPlayerDead )
		return;

	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	if ( gHUD.m_iWeaponBits != pPlayer->pev->weapons )
	{
		pPlayer->pev->weapons = gHUD.m_iWeaponBits;

		for (int i = MAX_WEAPONS-1; i > 0; i-- )
		{
			CBasePlayerWeapon *p = g_Prediction.GetWeapon(i);

			if ( p && p->GetWeaponInfo() )
			{
				if ( gHUD.m_iWeaponBits & ( 1 << p->GetWeaponInfo()->GetID() ) )
					pPlayer->AddPlayerItem( p );
				else
					pPlayer->RemovePlayerItem( p );
			}
		}
	}

	if( !m_pActiveSel )
		return;

	// has the player selected one?
	if (gHUD.m_iKeyBits & IN_ATTACK)
	{
		if ( m_pActiveSel != (CBasePlayerWeapon *)1)
		{
			ServerCmd( m_pActiveSel->GetWeaponInfo()->GetWeaponName());
			g_weaponselect = m_pActiveSel->GetWeaponInfo()->GetID();
		}

		m_pLastSel = m_pActiveSel;
		m_pActiveSel = nullptr;
		gHUD.m_iKeyBits &= ~IN_ATTACK;

		PlaySound("common/wpn_select.wav", 1);
	}

}
Пример #3
0
/*virtual*/ void WBCompEldHands::HandleEvent( const WBEvent& Event )
{
	XTRACE_FUNCTION;

	Super::HandleEvent( Event );

	STATIC_HASHED_STRING( OnWorldLoaded );
	STATIC_HASHED_STRING( OnItemEquipped );
	STATIC_HASHED_STRING( OnItemUnequipped );
	STATIC_HASHED_STRING( OnItemsSwapped );
	STATIC_HASHED_STRING( UseRightHand );
	STATIC_HASHED_STRING( UseLeftHand );
	STATIC_HASHED_STRING( ShowHands );
	STATIC_HASHED_STRING( HideHands );
	STATIC_HASHED_STRING( PlayHandAnim );
	STATIC_HASHED_STRING( SetHandMeshes );

	const HashedString EventName = Event.GetEventName();
	if( EventName == sOnWorldLoaded )
	{
		if( GetItemInRightHand() == GetWeapon() )
		{
			WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
			WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetWeapon() );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );
		}

		RestoreHandAnimations();

		UpdateWeaponHUD();
	}
	else if( EventName == sOnItemEquipped )
	{
		STATIC_HASHED_STRING( Item );
		WBEntity* const pItem = Event.GetEntity( sItem );
		ASSERT( pItem );

		// Hide fists and show ammo when we equip a weapon
		if( pItem == GetWeapon() )
		{
			WB_MAKE_EVENT( Hide, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Hide, GetFists() );

			WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
			WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, pItem );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );

			ShowWeaponHUD();
		}
		
		if( pItem == GetItemInRightHand() ||
			pItem == GetItemInLeftHand() )
		{
			AddAnimationsToHand( pItem );
		}

		if( pItem == GetWeaponAlt() )
		{
			// When traveling to a new world and spawning an item in the alt slot, immediately hide it
			WB_MAKE_EVENT( Hide, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() );

			ShowWeaponAltHUD();
		}
	}
	else if( EventName == sOnItemUnequipped )
	{
		// Show fists when we unequip a weapon
		STATIC_HASHED_STRING( Item );
		WBEntity* const pItem = Event.GetEntity( sItem );
		if( pItem == GetWeapon() )
		{
			WB_MAKE_EVENT( Show, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Show, GetFists() );

			WB_MAKE_EVENT( OnWeaponUnequipped, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponUnequipped, GetEntity() );

			// Revert to the fists animations
			AddAnimationsToHand( GetFists(), EH_Right );

			// HACK: Play the idle animation. I could add an event for "restored equip focus"
			// or whatever and hook this up in data, but eh. That somehow feels worse.
			STATIC_HASHED_STRING( Idle );
			PlayAnimation( GetFists(), sIdle, EH_Right );

			HideWeaponHUD();
		}
	}
	else if( EventName == sOnItemsSwapped )
	{
		// HACK, since the only things we swap (currently) are Weapon/WeaponAlt

		// Hide the alt weapon, show the right hand item
		WB_MAKE_EVENT( Hide, GetEntity() );
		WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() );

		WB_MAKE_EVENT( Show, GetEntity() );
		WB_DISPATCH_EVENT( GetEventManager(), Show, GetItemInRightHand() );

		AddAnimationsToHand( GetItemInRightHand() );

		STATIC_HASHED_STRING( Idle );
		PlayAnimation( GetItemInRightHand(), sIdle, EH_Right );

		UpdateWeaponHUD();

		WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
		WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetItemInRightHand() );
		WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );
	}
	else if( EventName == sUseRightHand )
	{
		WBEntity* const pWeapon = GetItemInRightHand();
		if( pWeapon )
		{
			STATIC_HASHED_STRING( InputEdge );
			const int InputEdge = Event.GetInt( sInputEdge );

			{
				WB_MAKE_EVENT( Use, GetEntity() );
				WB_SET_AUTO( Use, Int, InputEdge, InputEdge );
				WB_DISPATCH_EVENT( GetEventManager(), Use, pWeapon );
			}
		}
	}
	else if( EventName == sUseLeftHand )
	{
		WBEntity* const pPower = GetItemInLeftHand();
		if( pPower )
		{
			STATIC_HASHED_STRING( InputEdge );
			const int InputEdge = Event.GetInt( sInputEdge );

			{
				WB_MAKE_EVENT( Use, GetEntity() );
				WB_SET_AUTO( Use, Int, InputEdge, InputEdge );
				WB_DISPATCH_EVENT( GetEventManager(), Use, pPower );
			}
		}
	}
	else if( EventName == sShowHands )
	{
		DecrementHideHandsRefs();
	}
	else if( EventName == sHideHands )
	{
		IncrementHideHandsRefs();
	}
	else if( EventName == sPlayHandAnim )
	{
		STATIC_HASHED_STRING( AnimatingEntity );
		WBEntity* const pAnimatingEntity = Event.GetEntity( sAnimatingEntity );

		STATIC_HASHED_STRING( AnimationName );
		const HashedString AnimationName = Event.GetHash( sAnimationName );

		// Don't play hand anim if we're restoring the alternate weapon
		if( pAnimatingEntity == GetItemInRightHand() || pAnimatingEntity == GetItemInLeftHand() )
		{
			const EHand Hand = GetHandEnum( pAnimatingEntity );
			PlayAnimation( pAnimatingEntity, AnimationName, Hand );
		}
	}
	else if( EventName == sSetHandMeshes )
	{
		STATIC_HASHED_STRING( LeftHandMesh );
		const SimpleString LeftHandMesh = Event.GetString( sLeftHandMesh );

		STATIC_HASHED_STRING( LeftHandTexture );
		const SimpleString LeftHandTexture = Event.GetString( sLeftHandTexture );

		STATIC_HASHED_STRING( RightHandMesh );
		const SimpleString RightHandMesh = Event.GetString( sRightHandMesh );

		STATIC_HASHED_STRING( RightHandTexture );
		const SimpleString RightHandTexture = Event.GetString( sRightHandTexture );

		SetHandMeshes( LeftHandMesh, LeftHandTexture, RightHandMesh, RightHandTexture );
		RestoreHandAnimations();
	}
}