class Flames expands Projectile;

//Flamming textures
#exec TEXTURE IMPORT NAME=Flames_01 FILE=EFFECTS\Flames_01.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_02 FILE=EFFECTS\Flames_02.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_03 FILE=EFFECTS\Flames_03.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_04 FILE=EFFECTS\Flames_04.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_05 FILE=EFFECTS\Flames_05.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_06 FILE=EFFECTS\Flames_06.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_07 FILE=EFFECTS\Flames_07.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_08 FILE=EFFECTS\Flames_08.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_09 FILE=EFFECTS\Flames_09.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_10 FILE=EFFECTS\Flames_10.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_11 FILE=EFFECTS\Flames_11.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_12 FILE=EFFECTS\Flames_12.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_13 FILE=EFFECTS\Flames_13.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_14 FILE=EFFECTS\Flames_14.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Flames_15 FILE=EFFECTS\Flames_15.bmp GROUP=Effects FLAGS=2

#exec TEXTURE IMPORT NAME=AFlames_01 FILE=EFFECTS\AFlames_01.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_02 FILE=EFFECTS\AFlames_02.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_03 FILE=EFFECTS\AFlames_03.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_04 FILE=EFFECTS\AFlames_04.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_05 FILE=EFFECTS\AFlames_05.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_06 FILE=EFFECTS\AFlames_06.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_07 FILE=EFFECTS\AFlames_07.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_08 FILE=EFFECTS\AFlames_08.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_09 FILE=EFFECTS\AFlames_09.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_10 FILE=EFFECTS\AFlames_10.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_11 FILE=EFFECTS\AFlames_11.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_12 FILE=EFFECTS\AFlames_12.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_13 FILE=EFFECTS\AFlames_13.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_14 FILE=EFFECTS\AFlames_14.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=AFlames_15 FILE=EFFECTS\AFlames_15.bmp GROUP=Effects FLAGS=2

#exec TEXTURE IMPORT NAME=CFlames_01 FILE=EFFECTS\CFlames_01.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_02 FILE=EFFECTS\CFlames_02.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_03 FILE=EFFECTS\CFlames_03.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_04 FILE=EFFECTS\CFlames_04.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_05 FILE=EFFECTS\CFlames_05.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_06 FILE=EFFECTS\CFlames_06.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_07 FILE=EFFECTS\CFlames_07.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_08 FILE=EFFECTS\CFlames_08.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_09 FILE=EFFECTS\CFlames_09.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_10 FILE=EFFECTS\CFlames_10.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_11 FILE=EFFECTS\CFlames_11.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_12 FILE=EFFECTS\CFlames_12.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_13 FILE=EFFECTS\CFlames_13.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_14 FILE=EFFECTS\CFlames_14.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=CFlames_15 FILE=EFFECTS\CFlames_15.bmp GROUP=Effects FLAGS=2


//Smoke textures
#exec TEXTURE IMPORT NAME=Smoke_01 FILE=EFFECTS\Smoke_01.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_02 FILE=EFFECTS\Smoke_02.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_03 FILE=EFFECTS\Smoke_03.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_04 FILE=EFFECTS\Smoke_04.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_05 FILE=EFFECTS\Smoke_05.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_06 FILE=EFFECTS\Smoke_06.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_07 FILE=EFFECTS\Smoke_07.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=Smoke_08 FILE=EFFECTS\Smoke_08.bmp GROUP=Effects FLAGS=2


var bool bCanHitOwner, bHitWater;

var int Kickback;
var float Splasher, MoreDamage;
var bool HealthGiver;

var byte ScalingSmk;

var() texture RandFlames[15], RandAFlames[15], RandCFlames[15];
var() texture RandSmoke[8];

var byte FlameStg;
var int FlameRand;

var vector initialDir;


replication
{
	// Things the server should send to the client.
	reliable if(Role==ROLE_Authority)
		Kickback, MoreDamage, HealthGiver, Splasher, FlameRand;
}

simulated function Tick( float DeltaTime)
{
	ScaleGlow = LifeSpan * 4;
	DrawScale = (Default.LifeSpan - LifeSpan) * 4 * ScalingSmk;

	if (Class'NWMutator'.default.bFlamesFDetail)
	{
		if (FlameStg == 0 && LifeSpan < Default.LifeSpan*0.85)
		{
			Texture = RandFlames[FlameRand];
			FlameStg = 1;
		}
		else if (FlameStg == 1 && LifeSpan < Default.LifeSpan*0.6)
		{
			Texture = RandCFlames[FlameRand];
			FlameStg = 2;
		}
		else if (FlameStg == 2 && LifeSpan < Default.LifeSpan*0.2)
		{
			Texture = RandSmoke[Rand(7)];
			FlameStg = 3;
			ScalingSmk = 2;
		}
	}
}

simulated function GiveFlames()
{
	FlameRand = Rand(14);
	if (Class'NWMutator'.default.bFlamesFDetail)
		Texture = RandAFlames[FlameRand];
	else
		Texture = RandFlames[FlameRand];
}


auto state Flying
{

    simulated function ZoneChange( Zoneinfo NewZone )
    {
        if (NewZone.bWaterZone)
	{
		Texture = RandSmoke[Rand(7)];
		LightType = LT_None;
		Velocity=0.6*Velocity;
		ScalingSmk = 2;
		FlameStg = 3;
	}
    }


	simulated function HitWall (vector HitNormal, actor Wall)
	{
		local rotator R;
		local vector Dir;
		local vector Vel2D, Norm2D;


		Vel2D = Velocity;
			Vel2D.Z = 0;
			Norm2D = HitNormal;
			Norm2D.Z = 0;
			Norm2D = Normal(Norm2D);
			Vel2D = Normal(Vel2D);
			if ( (Vel2D Dot Norm2D) < -0.999 )
			{
				HitNormal = Normal(HitNormal + 0.6 * Vel2D);
				Norm2D = HitNormal;
				Norm2D.Z = 0;
				Norm2D = Normal(Norm2D);
				if ( (Vel2D Dot Norm2D) < -0.999 )
				{
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0.05,0,0);
					else
						HitNormal = HitNormal - vect(0.05,0,0);
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0,0.05,0);
					else
						HitNormal = HitNormal - vect(0,0.05,0);
					HitNormal = Normal(HitNormal);
				}
			}

		Velocity -= 2 * (Velocity dot HitNormal) * HitNormal;
		
		Dir = Velocity / speed;
        Acceleration = Dir * 50;	
	}


    simulated function ProcessTouch (Actor Other, Vector HitLocation)
    {
	local ObjectsFlames F;
	local IceOv io;
	local bool bThere;

	ForEach RadiusActors(Class'IceOv', io, 8.0, Other.Location)
		io.Destroy();
	

	if (!Region.Zone.bWaterZone)
	{

        if ( !Other.IsA('Projectile') && Other!=Level && (Other!=Instigator || bCanHitOwner))
	{
            Explode(HitLocation,Normal(HitLocation-Other.Location));

		if (Other.DrawScale < 1.25 && Other.DrawScale > 0.75 && Other.Tag != 'NoBurn' && Class'NWMutator'.default.EnableFTrackerFlames)
		{
			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);
				F.HealthGiver = HealthGiver;
				F.MoreDamage = MoreDamage;
			}
		}
	}
	}
    }

    function BlowUp(vector HitLocation)
    {
	local Pawn P;

        HurtRadiusX(Damage * FMax(1.0,MoreDamage), 200 * FMax(1.0, Splasher), MyDamageType, MomentumTransfer * (KickBack + 1), HitLocation);
        MakeNoise(1.0);
    }

    simulated function Explode(vector HitLocation, vector HitNormal)
    {
        BlowUp(HitLocation);

        Destroy();
    }

	simulated function Timer()
	{
		bCanHitOwner = True;
	}

    function BeginState()
    {
        local vector Dir;

        Dir = vector(Rotation);
        Velocity = speed * Dir;
        Acceleration = Dir * 50;
	SetTimer(0.2, False);
	initialDir = Velocity;

        if (Region.Zone.bWaterZone) //Flames cannot exist underwater
        {
		Texture = RandSmoke[Rand(7)];
		LightType = LT_None;
		Velocity=0.6*Velocity;
		ScalingSmk = 2;
        }
	else
		GiveFlames();
    }
}


//Special HurtRadius - With Health giving implementation
//******************************************************************************************************************
function HurtRadiusX( float DamageAmount, float DamageRadius, name DamageName, float Momentum, vector HitLocation )
{
    local actor Victims;
    local float damageScale, dist;
    local vector dir;
    local Pawn P;
    
    if( bHurtEntry )
        return;

    bHurtEntry = true;
    foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
    {
	if (HealthGiver && Victims.IsA('Pawn'))
	{
		dir = Victims.Location - HitLocation;
		dist = FMax(1,VSize(dir));
		dir = dir/dist; 
		damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

		P = Pawn(Victims);
		If (((P.PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
		(Level.Game.IsA('MonsterHunt') && !P.IsA('ScriptedPawn')) || P==Instigator) && 
		P.Health < Class'NWMutator'.default.MaxHealth)
		{
			P.Health += damageScale * DamageAmount * FMax(1.0,MoreDamage);
			if (P.Health > Class'NWMutator'.default.MaxHealth)
				P.Health = Class'NWMutator'.default.MaxHealth;
		}
		else
		{
        	if( Victims != self )
        	{
         	   Victims.TakeDamage(
                	damageScale * DamageAmount,
                	Instigator, 
			Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
			(damageScale * Momentum * dir),
			DamageName
			);
        	}
	}
		
	}
	else
	{
        if( Victims != self )
        {
            dir = Victims.Location - HitLocation;
            dist = FMax(1,VSize(dir));
            dir = dir/dist; 
            damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);
            Victims.TakeDamage
            (
                damageScale * DamageAmount,
                Instigator, 
                Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
                (damageScale * Momentum * dir),
                DamageName
            );
        }
	}
    }

    bHurtEntry = false;
}
//******************************************************************************************************************



defaultproperties
{
	DrawType=DT_Sprite
	Style=STY_Translucent
	LightBrightness=100
	LightHue=0
	LightSaturation=0
	LightRadius=3
	LightEffect=LE_NonIncidence
	LightType=LT_Steady
	bBounce=True
	RemoteRole=ROLE_SimulatedProxy
	Damage=10
	MaxSpeed=1700.000000
	MomentumTransfer=15000
	MyDamageType="Burned"
	speed=900.000000
	LifeSpan=0.750000
	DrawScale=0.200000
	bUnlit=True
	RandFlames(0)=Flames_01
	RandFlames(1)=Flames_02
	RandFlames(2)=Flames_03
	RandFlames(3)=Flames_04
	RandFlames(4)=Flames_05
	RandFlames(5)=Flames_06
	RandFlames(6)=Flames_07
	RandFlames(7)=Flames_08
	RandFlames(8)=Flames_09
	RandFlames(9)=Flames_10
	RandFlames(10)=Flames_11
	RandFlames(11)=Flames_12
	RandFlames(12)=Flames_13
	RandFlames(13)=Flames_14
	RandFlames(14)=Flames_15
	RandAFlames(0)=AFlames_01
	RandAFlames(1)=AFlames_02
	RandAFlames(2)=AFlames_03
	RandAFlames(3)=AFlames_04
	RandAFlames(4)=AFlames_05
	RandAFlames(5)=AFlames_06
	RandAFlames(6)=AFlames_07
	RandAFlames(7)=AFlames_08
	RandAFlames(8)=AFlames_09
	RandAFlames(9)=AFlames_10
	RandAFlames(10)=AFlames_11
	RandAFlames(11)=AFlames_12
	RandAFlames(12)=AFlames_13
	RandAFlames(13)=AFlames_14
	RandAFlames(14)=AFlames_15
	RandCFlames(0)=CFlames_01
	RandCFlames(1)=CFlames_02
	RandCFlames(2)=CFlames_03
	RandCFlames(3)=CFlames_04
	RandCFlames(4)=CFlames_05
	RandCFlames(5)=CFlames_06
	RandCFlames(6)=CFlames_07
	RandCFlames(7)=CFlames_08
	RandCFlames(8)=CFlames_09
	RandCFlames(9)=CFlames_10
	RandCFlames(10)=CFlames_11
	RandCFlames(11)=CFlames_12
	RandCFlames(12)=CFlames_13
	RandCFlames(13)=CFlames_14
	RandCFlames(14)=CFlames_15
	RandSmoke(0)=Smoke_01
	RandSmoke(1)=Smoke_02
	RandSmoke(2)=Smoke_03
	RandSmoke(3)=Smoke_04
	RandSmoke(4)=Smoke_05
	RandSmoke(5)=Smoke_06
	RandSmoke(6)=Smoke_07
	RandSmoke(7)=Smoke_08
	CollisionHeight=10.000000
	CollisionRadius=10.000000
	ScalingSmk=1
}

