class UR_DeployedActor_Skymine extends UTDeployedActor;

/** number of spider mines available */
var int AvailableMines;

/** currently deployed spidermine count */
var int DeployedMines;

/** range for detecting enemies */
var float DetectionRange;
/** class of spider mine to spawn */
var class<UR_Proj_SkyMissile> MineClass;

/** played when we spawn a mine */
var SoundCue ActivateSound;

event Landed(vector HitNormal, Actor HitActor)
{
	PerformDeploy();
	SetTimer(0.5, false, 'CheckForEnemies');
}

simulated function PerformDeploy()
{
	bDeployed = true;
	SkeletalMeshComponent(Mesh).PlayAnim('Deploy');
}

/** spawn a mine to attack the given target */
function UR_Proj_SkyMissile SpawnMine(Pawn Target, vector TargetDir)
{
	local UR_Proj_SkyMissile Mine;
	local vector X,Y,Z;

	if ( AvailableMines > 0 )
	{
		PlaySound(ActivateSound);
		GetAxes(Rotation, X,Y,Z);
		Mine = Spawn(MineClass,,, Location + 25*Z);
		if (Mine != None)
		{
			Mine.SetTarget(Target, TargetDir);
			Mine.TossZ = 1000.0;
			AvailableMines--;
			DeployedMines++;
		}
	}
	return Mine;
}

/** called on a timer to check for enemies to target with mines */
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 ( AvailableMines <= 0 )
	{
		// out of mines
		Destroy();
		return;
	}

	if (!bDeleteMe)
	{
		NextInterval = 0.25;
		foreach WorldInfo.AllControllers(class'Controller', C)
		{
			if ( C.Pawn != None && !WorldInfo.GRI.OnSameTeam(self, C) && ( C.Pawn.IsA('UTRemoteRedeemer') || C.Pawn.IsA('UR_SurferRocket') )
				&& VSize(C.Pawn.Location - Location) < DetectionRange && FastTrace(C.Pawn.Location, Location) )
			{
				SpawnMine(C.Pawn, Normal(C.Pawn.Location - Location));
				NextInterval = 0.5;
			}
		}
		SetTimer(NextInterval, false, 'CheckForEnemies');
	}
}

defaultproperties
{
   AvailableMines=15
   DetectionRange=1000.000000
   MineClass=Class'UnrealRider.UR_Proj_SkyMissile'

   bOrientOnSlope=True
   LifeSpan=360.000000

   ActivateSound=SoundCue'A_Pickups_Deployables.SpiderMine.SpiderMine_ActivateCue'
      Begin Object class=DynamicLightEnvironmentComponent Name=MyLightEnvironment ObjName=MyLightEnvironment Archetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
      ModShadowFadeoutTime=1.000000
      name="MyLightEnvironment"
      ObjectArchetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
   End Object
     Begin Object Name=DeployedLightEnvironment ObjName=DeployedLightEnvironment Archetype=DynamicLightEnvironmentComponent'UTGame.Default__UTSpiderMineTrap:DeployedLightEnvironment'
      ObjectArchetype=DynamicLightEnvironmentComponent'UTGame.Default__UTSpiderMineTrap:DeployedLightEnvironment'
   End Object
   Begin Object Class=SkeletalMeshComponent Name=ThirdPersonMesh ObjName=ThirdPersonMesh Archetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
      SkeletalMesh=SkeletalMesh'PICKUPS.Deployables.Mesh.SK_Deployables_SpiderMine'
      Begin Object Class=AnimNodeSequence Name=MeshSequenceA ObjName=MeshSequenceA Archetype=AnimNodeSequence'Engine.Default__AnimNodeSequence'
         Name="MeshSequenceA"
         ObjectArchetype=AnimNodeSequence'Engine.Default__AnimNodeSequence'
      End Object
      Animations=AnimNodeSequence'UTGameContent.Default__UTSpiderMineTrapBlue:MeshSequenceA'
      AnimSets(0)=AnimSet'PICKUPS.Deployables.Anims.K_Deployables_SpiderMine'
      Materials(0)=Material'PICKUPS.Deployables.Materials.M_Deployables_Spidermine_VBlue'
      LightEnvironment=MyLightEnvironment
      bUseAsOccluder=False
      Name="ThirdPersonMesh"
      ObjectArchetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
   End Object
   Mesh=ThirdPersonMesh

   LightEnvironment=DeployedLightEnvironment
   Components(0)=DeployedLightEnvironment
   Begin Object Class=CylinderComponent Name=CollisionCylinder ObjName=CollisionCylinder Archetype=CylinderComponent'UTGame.Default__UTSpiderMineTrap:CollisionCylinder'
      ObjectArchetype=CylinderComponent'UTGame.Default__UTSpiderMineTrap:CollisionCylinder'
   End Object
   Components(1)=CollisionCylinder

   Components(2)=MyLightEnvironment
   Components(3)=ThirdPersonMesh
   CollisionComponent=CollisionCylinder
   name="Default__UTSpiderMineTrapBlue"
   ObjectArchetype=UTSpiderMineTrap'UTGame.Default__UTSpiderMineTrap'
}
