class FlameTBall expands Projectile;

#exec MESH IMPORT MESH=FlameTBall ANIVFILE=MODELS\FlameTBall_a.3d DATAFILE=MODELS\FlameTBall_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=FlameTBall X=0 Y=0 Z=0

#exec MESH SEQUENCE MESH=FlameTBall SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FlameTBall SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=FlameTBall MESH=FlameTBall
#exec MESHMAP SCALE MESHMAP=FlameTBall X=0.05 Y=0.05 Z=0.1


#exec TEXTURE IMPORT NAME=Sk_FlameTBall FILE=Skins\Sk_FlameTBall.bmp GROUP=Skins FLAGS=2
#exec MESHMAP SETTEXTURE MESHMAP=FlameTBall NUM=1 TEXTURE=Sk_FlameTBall

#exec OBJ LOAD FILE=Textures\NaliEffects.utx PACKAGE=NaliWeaponsII.GFX
#exec MESHMAP SETTEXTURE MESHMAP=FlameTBall NUM=2 TEXTURE=FlameTFX

#exec AUDIO IMPORT NAME="FlameT_AltExpl" FILE=SOUNDS\FlameT_AltExpl.wav GROUP="FlameT"


var bool bHitWater;

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

var FlameTBTrail FlameTrail;


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


simulated function Destroyed()
{
    if ( FlameTrail != None )
        FlameTrail.Destroy();
    Super.Destroyed();
}



simulated function PostBeginPlay()
{
	local vector X,Y,Z;
	local rotator RandRot;

	Super.PostBeginPlay();

	FlameTrail = Spawn(Class'FlameTBTrail', Self);


	if ( Role == ROLE_Authority )
	{
		GetAxes(Instigator.ViewRotation,X,Y,Z);	
		Velocity = X * (Instigator.Velocity Dot X)*0.4 + Vector(Rotation) * (Speed +
			FRand() * 100);
		Velocity.z += 210;
		MaxSpeed = 1000;
		RandSpin(50000);	
		if (Instigator.HeadRegion.Zone.bWaterZone)
		{
			bHitWater = True;
			Disable('Tick');
			Velocity=0.6*Velocity;		
		}
	}

}

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.6*Velocity;
}

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

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


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

		if (Other.DrawScale < 1.25 && Other.DrawScale > 0.75 && !Region.Zone.bWaterZone)
		{
			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)
{

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

	MakeNoise(1.8);
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
local FlameBallExplosionC fbex;
local FlameWheel fw;

	BlowUp(HitLocation);

	if (Level.NetMode != NM_DedicatedServer)
	{
		if (ExplosionDecal != None)
			Spawn(Class'FlameTD_Light',self,,Location, rotator(HitNormal));

		fbex = Spawn(Class'FlameBallExplosionC');
		fbex.RemoteRole = ROLE_None;
	}

	fw = Spawn(Class'FlameWheel',,, Location + 6 * HitNormal, rot(0,0,0));
	fw.RotationRate = rot(36400,0,0);
	fw.KickBack = KickBack;
	fw.MoreDamage = MoreDamage;
	fw.Splasher = Splasher;
	fw.HealthGiver = HealthGiver;

	fw = Spawn(Class'FlameWheel',,, Location + 6 * HitNormal, rot(0,0,0));
	fw.RotationRate = rot(0,36400,0);
	fw.KickBack = KickBack;
	fw.MoreDamage = MoreDamage;
	fw.Splasher = Splasher;
	fw.HealthGiver = HealthGiver;

	PlaySound(Sound'FlameT_AltExpl',,22.0,,2200);

 	Destroy();
}


//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_Mesh
	Mesh=FlameTBall
	LightBrightness=100
	LightHue=0
	LightSaturation=0
	LightRadius=6
	LightEffect=LE_NonIncidence
	LightType=LT_Steady
	bBounce=True
	bFixedRotationDir=True
	Physics=PHYS_Falling
	RemoteRole=ROLE_SimulatedProxy
	Damage=85.000000
	ExplosionDecal=Class'FlameTDecal'
	MaxSpeed=750.000000
	MomentumTransfer=40000
	MyDamageType="Burned"
	speed=450.000000
	bUnlit=True
}
