Esempio n. 1
0
void CHUDAmmo::Update()
{

	HWEAPON hWeapon = g_pPlayerStats->GetCurrentWeaponRecord();
	HAMMO hAmmo = g_pPlayerStats->GetCurrentAmmoRecord();

	m_bDraw = (hWeapon && hAmmo);

	if (hAmmo)
	{
		DamageType dtAmmoInstDamageType = g_pWeaponDB->GetAmmoInstDamageType( hAmmo);
		if (dtAmmoInstDamageType == DT_MELEE)
			m_bDraw = false;
	}

	if (!m_bDraw) return;

	CClientWeapon* pClientWeapon = g_pClientWeaponMgr->GetCurrentClientWeapon( );
	int nAmmoInClip = pClientWeapon ? pClientWeapon->GetAmmoInClips() : 0;
	int nAmmo = g_pPlayerStats->GetCurrentAmmoCount() - nAmmoInClip;

	HWEAPONDATA hWpnData = g_pWeaponDB->GetWeaponData(hWeapon, !USE_AI_DATA);
	m_bInfinite = g_pWeaponDB->GetBool( hWpnData, WDB_WEAPON_bInfiniteAmmo );

	if (!m_bInfinite)
	{
		wchar_t wstr[32];
		FormatString("HUD_Ammo_Format",wstr,LTARRAYSIZE(wstr), nAmmoInClip, nAmmo < 0 ? 0 : nAmmo);

		if ((nAmmo > 0) || (nAmmoInClip > 0))
		{
			EnableFade(true);
		}
		else
		{
			ResetFade();
			EnableFade( false );
		}
		

		m_Text.SetText(wstr);
	}

	if (m_hLastAmmo != hAmmo)
	{
		HAMMODATA hAmmoData = g_pWeaponDB->GetAmmoData(hAmmo);
		m_hIconTexture.Load( g_pWeaponDB->GetString( hAmmoData, WDB_AMMO_sIcon ) );
		SetupQuadUVs(m_IconPoly, m_hIconTexture, 0.0f, 0.0f, 1.0f, 1.0f);
		m_hLastAmmo = hAmmo;
	}

	ResetFade();

}