//-----------------------------------------------------------------------------
// Purpose: called every frame to get ammo info from the weapon
//-----------------------------------------------------------------------------
void CDoDHudAmmo::OnThink()
{
    C_BaseCombatWeapon *wpn = GetActiveWeapon();
    C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();

    hudlcd->SetGlobalStat( "(weapon_print_name)", wpn ? wpn->GetPrintName() : " " );
    hudlcd->SetGlobalStat( "(weapon_name)", wpn ? wpn->GetName() : " " );

    if ( !wpn || !player || !wpn->UsesPrimaryAmmo() )
    {
        hudlcd->SetGlobalStat( "(ammo_primary)", "n/a" );
        hudlcd->SetGlobalStat( "(ammo_secondary)", "n/a" );

        SetPaintEnabled( false );
        SetPaintBackgroundEnabled( false );
        return;
    }
    else
    {
        SetPaintEnabled( true );
        SetPaintBackgroundEnabled( true );
    }

    // get the ammo in our clip
    int ammo1 = wpn->Clip1();
    int ammo2;
    if ( ammo1 < 0 )
    {
        // we don't use clip ammo, just use the total ammo count
        ammo1 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() );
        ammo2 = 0;
    }
    else
    {
        // we use clip ammo, so the second ammo is the total ammo
        ammo2 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() );
    }

    hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) );
    hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) );

    if ( wpn == m_hCurrentActiveWeapon )
    {
        // same weapon, just update counts
        SetAmmo( ammo1, true );
        SetAmmo2( ammo2, true );
    }
    else
    {
        // diferent weapon, change without triggering
        SetAmmo( ammo1, false );
        SetAmmo2( ammo2, false );

        // update whether or not we show the total ammo display
        m_bUsesClips = wpn->UsesClipsForAmmo1();
        m_hCurrentActiveWeapon = wpn;
    }
}
//-----------------------------------------------------------------------------
// Purpose: called every frame to get ammo info from the weapon
//-----------------------------------------------------------------------------
void CHudAmmo::UpdatePlayerAmmo( C_BasePlayer *player )
{
    // Clear out the vehicle entity
    m_hCurrentVehicle = NULL;

    C_BaseCombatWeapon *wpn = player ? player->GetActiveWeapon() : NULL;

    hudlcd->SetGlobalStat( "(weapon_print_name)", wpn ? wpn->GetPrintName() : " " );
    hudlcd->SetGlobalStat( "(weapon_name)", wpn ? wpn->GetName() : " " );

    if ( !wpn || !player || !wpn->UsesPrimaryAmmo() )
    {
        hudlcd->SetGlobalStat( "(ammo_primary)", "n/a" );
        hudlcd->SetGlobalStat( "(ammo_secondary)", "n/a" );

        SetPaintEnabled(false);
        SetPaintBackgroundEnabled(false);
        return;
    }

    SetPaintEnabled(true);
    SetPaintBackgroundEnabled(true);

    // get the ammo in our clip
    int ammo1 = wpn->Clip1();
    int ammo2;
    if (ammo1 < 0)
    {
        // we don't use clip ammo, just use the total ammo count
        ammo1 = player->GetAmmoCount(wpn->GetPrimaryAmmoType());
        ammo2 = 0;
    }
    else
    {
        // we use clip ammo, so the second ammo is the total ammo
        ammo2 = player->GetAmmoCount(wpn->GetPrimaryAmmoType());
    }

    hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) );
    hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) );

    if (wpn == m_hCurrentActiveWeapon)
    {
        // same weapon, just update counts
        SetAmmo(ammo1, true);
        SetAmmo2(ammo2, true);
    }
    else
    {
        // diferent weapon, change without triggering
        SetAmmo(ammo1, false);
        SetAmmo2(ammo2, false);

        // update whether or not we show the total ammo display
        if (wpn->UsesClipsForAmmo1())
        {
            SetShouldDisplaySecondaryValue(true);
            GetClientMode()->GetViewportAnimationController()->StartAnimationSequence("WeaponUsesClips");
        }
        else
        {
            GetClientMode()->GetViewportAnimationController()->StartAnimationSequence("WeaponDoesNotUseClips");
            SetShouldDisplaySecondaryValue(false);
        }

        GetClientMode()->GetViewportAnimationController()->StartAnimationSequence("WeaponChanged");
        m_hCurrentActiveWeapon = wpn;
    }
}