//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CWarsWeapon::IsWeaponVisible( void )
{
	CBaseViewModel *vm = NULL;

	CUnitBase *pUnit;

	CBasePlayer *pOwner = NULL;
	if( GetOwner() )
	{
		pUnit = GetOwner()->MyUnitPointer();
		if( pUnit && pUnit->GetCommander() )
		{
			pOwner = ToBasePlayer( pUnit->GetCommander() );
		}
	}

	if ( pOwner )
	{
		vm = pOwner->GetViewModel( m_nViewModelIndex );
		if ( vm )
			return ( !vm->IsEffectActive(EF_NODRAW) );
	}

	return BaseClass::IsWeaponVisible();
}
//-----------------------------------------------------------------------------
// Purpose: Show/hide weapon and corresponding view model if any
// Input  : visible - 
//-----------------------------------------------------------------------------
void CWarsWeapon::SetWeaponVisible( bool visible )
{
	CBaseViewModel *vm = NULL;
	CUnitBase *pUnit;

	if( GetOwner() )
	{
		pUnit = GetOwner()->MyUnitPointer();
		if( pUnit && pUnit->GetCommander() )
		{
			CBasePlayer *pOwner = ToBasePlayer( pUnit->GetCommander() );
			if ( pOwner )
			{
				vm = pOwner->GetViewModel( m_nViewModelIndex );
			}
		}
	}

	if ( vm )
	{
		if ( visible )
		{
			vm->RemoveEffects( EF_NODRAW );
		}
		else
		{
			vm->AddEffects( EF_NODRAW );
		}
	}
	BaseClass::SetWeaponVisible( visible );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::GetShootOriginAndDirection( Vector &vShootOrigin, Vector &vShootDirection)
{
	CBaseEntity *pOwner = GetOwner();
	if( !pOwner )
		return;

	CUnitBase *pUnit = pOwner->MyUnitPointer();
	if( !pUnit )
		return;

#if 0
#ifdef CLIENT_DLL
	if( pUnit->GetCommander() && !ShouldDrawLocalPlayer() )
	{
		QAngle vDummy;
		C_BasePlayer *player = ToBasePlayer( pUnit->GetCommander() );
		C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL;
		if ( vm )
		{
			int iAttachment = vm->LookupAttachment( "muzzle" );
			if ( vm->GetAttachment( iAttachment, vShootOrigin, vDummy ) )
			{
				AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection );
				return;
			}
		}
	}
#endif // CLIENT_DLL
#endif // 0
	vShootOrigin = pUnit->Weapon_ShootPosition();
	AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection );
}
// get the player owner of this weapon (either the unit's commander if the weapon is
//  being held by unit, or the player directly if a player is holding this weapon)
CHL2WarsPlayer* CWarsWeapon::GetCommander()
{
	CHL2WarsPlayer *pOwner = NULL;
	CUnitBase *pUnit = NULL;

	pUnit = dynamic_cast<CUnitBase*>( GetOwner() );
	if ( pUnit )
	{
		pOwner = pUnit->GetCommander();
	}
	else
	{
		pOwner = ToHL2WarsPlayer( dynamic_cast<CBasePlayer*>( GetOwner() ) );
	}

	return pOwner;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::SetViewModel()
{
	CUnitBase *pUnit;
	CHL2WarsPlayer *pOwner;

	pUnit = GetOwner()->MyUnitPointer();
	if ( pUnit )
	{
		pOwner = pUnit->GetCommander();
		if( pOwner )
		{
			CBaseViewModel *vm = pOwner->GetViewModel( m_nViewModelIndex );
			if ( vm == NULL )
				return;
			Assert( vm->ViewModelIndex() == m_nViewModelIndex );
			vm->SetWeaponModel( GetViewModel( m_nViewModelIndex ), this );
		}
	}
	BaseClass::SetViewModel();
}