
class IncenFragmentsSmall extends Projectile;

var bool bCanHitOwner, bHitWater;
var float Count, SmokeRate;
var() bool CanHitInstigator;
var() float HitInstigatorTimeOut;

simulated function PostBeginPlay()
{
	local rotator RandRot;
	local ObjectsFlames F;

	Super.PostBeginPlay();

	if (Role == ROLE_Authority)
	{
		RandRot = Rotation;
		RandRot.Pitch += FRand() * 2000 - 1000;
		RandRot.Yaw += FRand() * 2000 - 1000;
		RandRot.Roll += FRand() * 2000 - 1000;
		Velocity = Vector(RandRot) * (Speed + (FRand() * 200 - 100));
		if (Region.zone.bWaterZone)
			Velocity *= 0.65;
	}
	if (Level.NetMode != NM_DedicatedServer)
		F = Spawn(Class'ObjectsFlames', Self,, Self.Location);

	Super.PostBeginPlay();
}

simulated function ZoneChange(Zoneinfo NewZone)
{
	local waterring w;
	
	if (!NewZone.bWaterZone || bHitWater) Return;
	bHitWater = True;
	w = Spawn(class'WaterRing',,,,rot(16384,0,0));
	w.DrawScale = 0.2;
	w.RemoteRole = ROLE_None;
	Velocity=0.1*Velocity;
}

simulated function Landed(vector HitNormal)
{
	HitWall(HitNormal, None);
}

simulated function ProcessTouch(actor Other, vector HitLocation)
{
	local ObjectsFlames F;
	local bool bThere;

	if ((!CanHitInstigator || (CanHitInstigator && (Default.LifeSpan - LifeSpan) < HitInstigatorTimeOut)) && Other == Instigator)
		return;
		
	if (!Region.Zone.bWaterZone)
	{
   	if (Other.IsA('Pawn') || (Other.IsA('Decoration') && (!Other.IsA('CTFFlag'))) || (Other.IsA('Carcass')))
		{
			if (Other.DrawScale < 1.25 && Other.DrawScale > 0.75)
			{
				ForEach RadiusActors(Class'ObjectsFlames', F, 8.0, Other.Location)
				{
					if (F.Owner == Other)
					{
						bThere=True;
						break;
					}
				}
				if (!bThere)
					F = Spawn(Class'ObjectsFlames', Other,, Other.Location);
			}
		}
	}
}

simulated function HitWall(vector HitNormal, actor Wall)
{
	bCanHitOwner = True;
	Velocity = 0.4*((Velocity dot HitNormal) * HitNormal * (-2.0) + Velocity);
	RandSpin(100000);
	speed = VSize(Velocity);
	if (Level.NetMode != NM_DedicatedServer)
		PlaySound(ImpactSound, SLOT_Misc, 1.5);
	if (Velocity.Z > 400)
		Velocity.Z = 0.5 * (400 + Velocity.Z);	
	else if (speed < 20)
	{
		bBounce = False;
		SetPhysics(PHYS_None);
	}
}

auto state Flying
{
   function ProcessTouch (Actor Other, vector HitLocation)
   {
	 	local ObjectsFlames F;
		local bool bThere;

		if ((!CanHitInstigator || (CanHitInstigator && (Default.LifeSpan - LifeSpan) < HitInstigatorTimeOut)) && Other == Instigator)
		return;

		if (!Region.Zone.bWaterZone)
		{
			//only spawns fire on these classes
   	   if (Other.IsA('Pawn') || (Other.IsA('Decoration') && (!Other.IsA('CTFFlag'))) || (Other.IsA('Carcass')))
			{
				if (Other.DrawScale < 1.25 && Other.DrawScale > 0.75)
				{
					ForEach RadiusActors(Class'ObjectsFlames', F, 8.0, Other.Location)
					{
						if (F.Owner == Other)
						{
							bThere=True;
							break;
						}
					}
					if (!bThere)
						F = Spawn(Class'ObjectsFlames', Other,, Other.Location);
				}
			}
		}
   }
}

defaultproperties
{
	HitInstigatorTimeOut=0.500000
	CanHitInstigator=True
	speed=400.000000
	MaxSpeed=1000.000000
	Damage=100.000000
	LifeSpan=10.00000
	MomentumTransfer=50000
	MyDamageType=GrenadeDeath
	RemoteRole=ROLE_SimulatedProxy
	ImpactSound=Sound'UnrealShare.General.Chunkhit1'
	Physics=PHYS_Falling
	AnimSequence=Still
	Mesh=Mesh'UnrealShare.ChipM'
   bUnlit=True
	CollisionRadius=4.00
	CollisionHeight=4.00
	bNetTemporary=False
   DesiredRotation=(Pitch=12000,Yaw=5666,Roll=2334) //check me
	bNoSmooth=True
	bBounce=True
	bFixedRotationDir=True
}
