class NukeMissileA expands Projectile;

#exec MESH IMPORT MESH=NukeMissileA ANIVFILE=MODELS\NukeMissile_a.3d DATAFILE=MODELS\NukeMissile_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=NukeMissileA STRENGTH=0
#exec MESH ORIGIN MESH=NukeMissileA X=0 Y=0 Z=0 YAW=128

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

#exec MESHMAP NEW MESHMAP=NukeMissileA MESH=NukeMissileA
#exec MESHMAP SCALE MESHMAP=NukeMissileA X=0.0313 Y=0.0313 Z=0.0625

#exec TEXTURE IMPORT NAME=XNukeSk FILE=SKINS\XNukeSk.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=NukeMissileA NUM=1 TEXTURE=XNukeSk

#exec AUDIO IMPORT NAME="NukeAmb" FILE=SOUNDS\NukeAmb.wav GROUP="NukeLauncher"
#exec AUDIO IMPORT NAME="NukeSpawnSnd" FILE=SOUNDS\NukeSpawnSnd.wav GROUP="NukeLauncher"

var bool bHitWater;

var bool bHomingMode, bStartedMission;
var vector TrgtLoc;
var float HomingDelay, HDelayCount;

var NukeBurner NBTrail;
var NukeTrail NkTrail;


replication
{
	// Things the server should send to the client.
	reliable if(Role==ROLE_Authority)
		TrgtLoc, bHomingMode, HomingDelay;
}


simulated function Destroyed()
{
	if (NBTrail != None)
		NBTrail.Destroy();
	if (NkTrail != None)
		NkTrail.Destroy();

	Super.Destroyed();
}

simulated function PostBeginPlay()
{
	NBTrail = Spawn(Class'NukeBurner',Self);
	NkTrail = Spawn(Class'NukeTrail',Self);
	SetTimer(0.1, False);
}

simulated function Timer()
{
local TM_Smoke ts;

	if (!bStartedMission)
	{
		bStartedMission = True;
		HDelayCount = HomingDelay;
		SetTimer(0.05, True);
	}
	else if (bHomingMode)
	{

		if (!bRotateToDesired && HDelayCount <= 0)
		{
			bRotateToDesired = True;
			DesiredRotation = rotator(TrgtLoc - Location);
		}
		else if (HDelayCount <= 0)
			DesiredRotation = rotator(TrgtLoc - Location);
	}

	ts = Spawn(Class'TM_Smoke');
	ts.RemoteRole = ROLE_None;
}


simulated function Tick( float DeltaTime)
{
local vector Dir;

	if (HDelayCount > 0)
		HDelayCount -= DeltaTime;

	if (bRotateToDesired)
	{
		Dir = vector(Rotation);
		Velocity = speed * Dir;
		Acceleration = Dir * 50;
	}
}

simulated function SpawnCorona(vector HitNormal)
{
local vector X, Y, Z;
	GetAxes(rotator(HitNormal), X, Y, Z);

	Spawn(Class'X_NukeCoronaA',,, Location + 100*X);
}


auto state Flying
{

    simulated function ZoneChange( Zoneinfo NewZone )
    {
        local waterring w;
        
        if (!NewZone.bWaterZone && bHitWater)
	{
		Velocity=(1/0.75)*Velocity;
		speed = (1/0.75)*speed;
		bHitWater = False;
	}
	else if (NewZone.bWaterZone && !bHitWater)
	{
		Velocity=0.75*Velocity;
		speed = 0.75*speed;
		bHitWater = True;
	}
	else
		return;

        if ( Level.NetMode != NM_DedicatedServer )
        {
            w = Spawn(class'WaterRing',,,,rot(16384,0,0));
            w.DrawScale = 0.2;
            w.RemoteRole = ROLE_None;
        }
    }

    simulated function ProcessTouch (Actor Other, Vector HitLocation)
    {
        if ( (Other != instigator) && (!Other.IsA('Projectile') || Other.bProjTarget)) 
            Explode(HitLocation,Normal(HitLocation-Other.Location));
    }

function BlowUp(vector HitLocation)
{
local Pawn P;
	
	MakeNoise(3.0);
	HurtRadius(Damage, 250, MyDamageType, MomentumTransfer, HitLocation);
}


    simulated function Explode(vector HitLocation, vector HitNormal)
    {

        //local vector X, Y, Z;
	//GetAxes(rotator(HitNormal), X, Y, Z);

        BlowUp(HitLocation);
	//Spawn(Class'X_NukeCoronaA',,, Location + 100*X);
	SpawnCorona(HitNormal);
	ShakePeople(0.5, 40, 200, 4000);

	SpawnShock(HitNormal);

        Destroy();
    }

    function BeginState()
    {
        local vector Dir;

        Dir = vector(Rotation);
        Velocity = speed * Dir;
        Acceleration = Dir * 50;
        if (Region.Zone.bWaterZone)
        {
            bHitWater = True;
            Velocity=0.75*Velocity;
	    speed = 0.75*speed;
        }
    }
}


simulated function ShakePeople(float shaketime, float RollMag, float vertmag, float MaxRange)
{
local Pawn P;

	for ( P=Level.PawnList; P!=None; P=P.NextPawn )
	{
			if ( P.IsA('PlayerPawn') && (VSize(P.Location - Location) < MaxRange) )
				PlayerPawn(P).ShakeView(shaketime, 
		(FMax(0.1, MaxRange - VSize(Location - P.Location))) * RollMag / MaxRange, 
		(FMax(0.1, MaxRange - VSize(Location - P.Location))) * vertmag / MaxRange);
	}
}


function SpawnShock(vector HitNormal)
{
local vector X, Y, Z;
local BigShockwave b;

	GetAxes(rotator(HitNormal), X, Y, Z);
	b = Spawn(Class'BigShockwave',,,, rotator(HitNormal));
	Spawn(Class'RingTypeA',,, Location + 32*X, rotator(HitNormal));
	Spawn(Class'RingTypeB',,, Location + 600*X, rotator(HitNormal));
}


defaultproperties
{
	DrawType=DT_Mesh
	Mesh=NukeMissileA
	SpawnSound=NukeSpawnSnd
	AmbientSound=NukeAmb
	SoundRadius=128
	SoundVolume=255
	SoundPitch=100
	LightType=LT_Steady
	LightEffect=LE_NonIncidence
	LightBrightness=100
	LightHue=42
	LightSaturation=127
	LightRadius=6
	bBounce=True
	ExplosionDecal=None
	MyDamageType=NuclearExplosion
	speed=1000.000000
	MaxSpeed=1500.000000
	Damage=1000.000000
	MomentumTransfer=200000
	RemoteRole=ROLE_SimulatedProxy
	DrawScale=1.000000
	RotationRate=(Yaw=9000,Pitch=9000,Roll=9000)
	bNetTemporary=False
	bUnlit=True
	AmbientGlow=96
}
