class UR_Proj_Snare extends UTProj_Rocket;

var class<UR_Proj_SnareCluster> MissileClass;
var float DetectionRange;

function Init(vector Direction)
{
	Super.Init(Direction);
	
	SetTimer(0.5, false, 'CheckForEnemies');
}

function CheckForEnemies()
{
	local Controller C;
	local float NextInterval;

	// make sure we have an Instigator
	if (Instigator == None)
	{
		if (InstigatorController == None)
		{
			// no one to take credit, so destroy
			Destroy();
			return;
		}
		else
		{
			Instigator = InstigatorController.Pawn;
		}
	}

	if (InstigatorController == None || !WorldInfo.GRI.OnSameTeam(self, InstigatorController))
	{
		Destroy();
		return;
	}

	if (!bDeleteMe)
	{
		NextInterval = 0.05;
		foreach WorldInfo.AllControllers(class'Controller', C)
		{
			if ( C.Pawn != None && !WorldInfo.GRI.OnSameTeam(self, C) && C.Pawn.IsA('UTPawn')
				&& VSize(C.Pawn.Location - Location) < DetectionRange && FastTrace(C.Pawn.Location, Location) )
			{
				SpawnMissile(C.Pawn, Normal(C.Pawn.Location - Location));
				Destroy();
			}
		}
		SetTimer(NextInterval, false, 'CheckForEnemies');
	}
}

function SpawnMissile(Pawn Target, vector TargetDir)
{
	local UR_Proj_SnareCluster Missile;
	local vector X,Y,Z;
	local int i;

	GetAxes(Rotation, X,Y,Z);
	
	for (i = 0; i < 5; i++)
	{
		Missile = Spawn(MissileClass,,, Location + 75*Z*FRand());
		
		if (Missile != None)
		{
			Missile.SetTarget(Target, TargetDir);
		}
	}
}


DefaultProperties
{
	CheckRadius=5
	DetectionRange=600
	MissileClass=Class'UnrealRider.UR_Proj_SnareCluster'
}