// Do the work of deploying the gun at the current location and angles
void CDODBipodWeapon::DeployBipod( float flHeight, CBaseEntity *pDeployedOn, float flYawLimitLeft, float flYawLimitRight )
{
	m_flDeployedHeight = flHeight;
	m_hDeployedOnEnt = pDeployedOn;

	if ( pDeployedOn )
        m_DeployedEntOrigin = pDeployedOn->GetAbsOrigin();
	else
		m_DeployedEntOrigin = vec3_origin;	// world ent 

	SendWeaponAnim( GetDeployActivity() );
	SetDeployed( true );

	CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
	pPlayer->m_Shared.SetDeployed( true, flHeight );
	pPlayer->m_Shared.SetDeployedYawLimits( flYawLimitLeft, flYawLimitRight );

	// Save this off so we do duck checks later, even though we won't be flagged as ducking
	m_bDuckedWhenDeployed = pPlayer->m_Shared.IsDucking();	

	// More TODO:
	// recalc our yaw limits if the item we're deployed on has moved or rotated
	// if our new limits are outside our current eye angles, undeploy us

	m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
	m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
	m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseSDKGrenade::ItemPostFrame()
{
	CSDKPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
	if ( !vm )
		return;

	// If they let go of the fire button, they want to throw the grenade.
	if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) 
	{
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
//		if (m_bSecondary)
//			DropGrenade();
//		else
			ThrowGrenade();
		
		DecrementAmmo( pPlayer );
	
		m_bPinPulled = false;
		SendWeaponAnim( ACT_VM_THROW );	
		SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() );

		m_bPinPulled = false;
//		m_bSecondary = false;
	}
	else if( m_bRedraw )
	{
		// Has the throw animation finished playing
		if( m_flTimeWeaponIdle < gpGlobals->curtime )
		{
			// if we're officially out of grenades, ditch this weapon
			if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
#ifdef GAME_DLL
				pPlayer->Weapon_Drop( this, NULL, NULL );
				UTIL_Remove(this);
#endif
				pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs!
			}
			else
			{
				m_bRedraw = false;
				m_flNextPrimaryAttack = gpGlobals->curtime + 1.2;
				m_flNextSecondaryAttack = gpGlobals->curtime + 1.2;
				SendWeaponAnim( GetDeployActivity() );			
			}
			return;	//don't animate this grenade any more!
		}	
	}
	else if( !m_bRedraw )
	{
		BaseClass::ItemPostFrame();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseSDKGrenade::ItemPostFrame()
{
	CSDKPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
	if ( !vm )
		return;

	// If they let go of the fire button, they want to throw the grenade.
	if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) 
	{
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
//		if (m_bSecondary)
//			DropGrenade();
//		else
			ThrowGrenade();

		if (!pPlayer->IsStyleSkillActive(SKILL_TROLL))
			DecrementAmmo( pPlayer );

		m_bPinPulled = false;
		SendWeaponAnim( ACT_VM_THROW );	
		SetWeaponIdleTime( GetCurrentTime() + SequenceDuration() );

		m_bPinPulled = false;
//		m_bSecondary = false;
	}
	else if( m_bRedraw )
	{
		// Has the throw animation finished playing
		if( m_flTimeWeaponIdle < GetCurrentTime() )
		{
			// if we're officially out of grenades, ditch this weapon
			if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
#ifdef GAME_DLL
				pPlayer->Weapon_Drop( this, NULL, NULL );
				UTIL_Remove(this);
#endif
				pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs!
			}
			else if (pPlayer->IsStyleSkillActive(SKILL_TROLL))
			{
				m_bRedraw = false;
				m_flNextPrimaryAttack = GetCurrentTime() + 1.2;
				m_flNextSecondaryAttack = GetCurrentTime() + 1.2;
				SendWeaponAnim( GetDeployActivity() );	
			}
			else
			{
				m_bRedraw = false;

				// Only switch to the next best weapon if the next best weapon is not brawl.
				CBaseCombatWeapon *pNewWeapon = g_pGameRules->GetNextBestWeapon(pPlayer, this);
				CWeaponSDKBase* pSDKNewWeapon = dynamic_cast<CWeaponSDKBase*>(pNewWeapon);

				bool bSwitch = true;

				if (!pSDKNewWeapon)
					bSwitch = false;

				// If I'm going to switch to brawl but I have more grenades, don't switch.
				else if (pSDKNewWeapon && pSDKNewWeapon->GetWeaponID() == SDK_WEAPON_BRAWL && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) > 0)
					bSwitch = false;

				if (bSwitch)
					pPlayer->SwitchToNextBestWeapon( this );
			}
			return;	//don't animate this grenade any more!
		}	
	}
	else if( !m_bRedraw )
	{
		BaseClass::ItemPostFrame();
	}
}