
if( SERVER ) then

	AddCSLuaFile( "shared.lua" );
	
	SWEP.HoldType = "rpg";

end

SWEP.PrintName = "Nuke";
SWEP.Author				= "Disseminate"

if( CLIENT ) then

	
	SWEP.Slot = 2;
	SWEP.SlotPos = 2;
	SWEP.CSMuzzleFlashes	= true
	SWEP.ViewModelFOV		= 83;	
	
	SWEP.DrawCrosshair = false;
	
end

SWEP.Base = "weapon_ts_base";
SWEP.Category = "Starship Troopers";

SWEP.ViewModel			= "models/weapons/v_rpg.mdl"
SWEP.WorldModel			= "models/weapons/w_rocket_launcher.mdl"
SWEP.Primary.Sound			= Sound( "weapons/rpg/rocketfire1.wav" )

SWEP.ViewModelFOV		= 40;

SWEP.InvSize = 2;
SWEP.InvWeight = 1;

SWEP.Primary.ClipSize = 5;
SWEP.Primary.DefaultClip = 5;
SWEP.Primary.Ammo = "rpg";
SWEP.Primary.Delay = 10;
SWEP.Primary.Damage = 3;
SWEP.Primary.Force = 1;
SWEP.Primary.RunCone = Vector( .07, .07, 0 );
SWEP.Primary.SpreadCone = Vector( .047, .047, 0 );
SWEP.Primary.CrouchSpreadCone = Vector( .03, .03, 0 );
SWEP.Primary.ViewPunch = Angle( -0.5, 0.0, 0 );
SWEP.Primary.Automatic = false;

SWEP.NoIronsights = true;

function SWEP:PrimaryAttack()
	
	if( self.Owner:GetNWInt( "tiedup" ) == 1 ) then 
		return; 
	end

	if( not self:CanShootPrimary() ) then return; end
	
	if( self.Owner:KeyDown( IN_SPEED ) and self.Owner:GetVelocity():Length() >= 140 ) then return; end
	
	self.Weapon:EmitSound( self.Primary.Sound );
	
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay );
	
	self:TakePrimaryAmmo( 1 );
	
	self.Owner:SetAnimation( PLAYER_ATTACK1 );
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	
	-- Nuke code below
	local trace = { }
		trace.start = self.Owner:EyePos();
		trace.endpos = trace.start + self.Owner:GetAimVector() * 100;
		trace.filter = self.Owner;
	local tr = util.TraceLine( trace );
	
	local shoot_vector = ( self.Owner:GetEyeTrace().HitPos - tr.HitPos );
	shoot_vector:Normalize();
	
	if( SERVER ) then
	
		self.Nuke = ents.Create( "sent_nuke_projectile" );
			self.Nuke:SetPos( tr.HitPos );
			self.Nuke:SetAngles( shoot_vector:Angle() + Angle( 90, 0, 0 ) );
			self.Nuke:Spawn();
			self.Nuke:SetROwner( self.Owner );
			
			local phys = self.Nuke:GetPhysicsObject();
			
			if( phys:IsValid() ) then
				
				phys:EnableGravity( false );
				phys:EnableDrag( false );
				
			end
			
	end
		
	self:Reload();
	
end
