class MegaTonOMFG expands Projectile;

#exec AUDIO IMPORT NAME="MegaTon_Arming" FILE=SOUNDS\MegaTon_Arming.wav GROUP="MegaTon"
#exec AUDIO IMPORT NAME="MegaTon_Count" FILE=SOUNDS\MegaTon_Count.wav GROUP="MegaTon"
#exec AUDIO IMPORT NAME="MegaTon_FinalCount" FILE=SOUNDS\MegaTon_FinalCount.wav GROUP="MegaTon"


var() texture DigitalSeconds[10], DigitalMinutes[10];
var() float TimeToBlow;
var() byte NukePassword[3];
var bool bArming;
var() texture TeamFX[4];

var PassCard PCard;

var bool bHitWater;

replication
{
	reliable if (Role == ROLE_Authority)
		TimeToBlow, NukePassword, PCard;
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	SetRotation((Rotation.Yaw + 32768) * rot(0,1,0));

	if ( Role == ROLE_Authority )
		Velocity = vect(0,0,1);

	CheckTeam();

	if (Instigator != None)
	{
		PCard = Spawn(Class'PassCard');
		PCard.MegaO = Self;
		PCard.Instigator = Instigator;
		PCard.BecomeItem();
		Instigator.AddInventory(PCard);
		PCard.GiveAmmo(Instigator);
		PCard.SetSwitchPriority(Instigator);
		PCard.WeaponSet(Instigator);
	}

	if (TimeToBlow > 999)
		TimeToBlow = 999;
}


function CheckTeam()
{
	if (Class'NWMutator'.default.bMegaTonID_InTeamGames && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt'))
		MultiSkins[6] = TeamFX[Instigator.PlayerReplicationInfo.Team];
}


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.4;
	w.RemoteRole = ROLE_None;
	Velocity=0.6*Velocity;
}

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

simulated function ProcessTouch( actor Other, vector HitLocation )
{
	if ( Other!=instigator && Other.bBlockPlayers && Other.bBlockActors)
		HitWall( Normal(Velocity), Other );
}

simulated function HitWall( vector HitNormal, actor Wall )
{
	PlaySound(Sound'MegaTon_Arming',,50.0,,2048.0);
	PlayAnim('Arming', 1.0);
	bArming = True;
}

simulated function UnArm()
{
	bArming = False;
	PlaySound(Sound'MegaTon_Arming',,50.0,,2048.0);
	PlayAnim('Disarming', 1.0);
}

simulated function AnimEnd()
{
	if (bArming)
	{
		if (TimeToBlow > 999)
			TimeToBlow = 999;

		SetTimer(1.0, True);

		if (PCard != None)
		{
			PCard.MultiSkins[2] = PCard.NumbersTex[NukePassword[0]];
			PCard.MultiSkins[3] = PCard.NumbersTex[NukePassword[1]];
			PCard.MultiSkins[4] = PCard.NumbersTex[NukePassword[2]];
		}
	}
	else
	{
		SpawnNewMega();
		Destroy();
	}
}

function SpawnNewMega()
{
local MegaTon MT;

	MT = Spawn(Class'MegaTon');
	MT.DropFrom(Location);
}

function Timer()
{
local float Min, SecD, SecU;

	TimeToBlow = Int(TimeToBlow - 1) + 0.2;

	if (bArming && TimeToBlow >= 1)
	{
		Min = Int(TimeToBlow / 60);
		SecD = Int(((TimeToBlow / 60) - Min) * 6);
		SecU = Int(((TimeToBlow / 60) - Min) * 60 - 10*SecD);
	
		//log("-------------------------------------------------");
		//log("Time OMFG :     " $ Int(Min) $ " : " $ Int(Min) $ Int(Min));

		MultiSkins[3] = DigitalMinutes[Int(Min)];
		MultiSkins[4] = DigitalSeconds[Int(SecD)];
		MultiSkins[5] = DigitalSeconds[Int(SecU)];

		if (TimeToBlow >= 6)
			PlaySound(Sound'MegaTon_Count',,10.0,,150.0);
		else
			PlaySound(Sound'MegaTon_FinalCount',,10.0,,150.0);
	}
	else if (TimeToBlow < 1)
		Explosion(Location);
}


function Explosion(vector HitLocation)
{
	if ( Role < ROLE_Authority )
            		return;

	Spawn(Class'NuclearExplosionI');
	MakeNoise(5.0);
 	Destroy();
}

simulated function Destroyed()
{
	if (PCard != None)
		PCard.DestroyByMaster();

	Super.Destroyed();
}

defaultproperties
{
	DrawType=DT_Mesh
	Mesh=MegaTonM
	CollisionRadius=15.000000
	CollisionHeight=16.000000
	Physics=PHYS_Falling
	RemoteRole=ROLE_SimulatedProxy
	ExplosionDecal=?
	ImpactSound=MetalHit
	MaxSpeed=1300.000000
	MomentumTransfer=50000
	MyDamageType=MushroomNuke
	speed=1000.000000
	DigitalSeconds(0)=DigitalSec0
	DigitalSeconds(1)=DigitalSec1
	DigitalSeconds(2)=DigitalSec2
	DigitalSeconds(3)=DigitalSec3
	DigitalSeconds(4)=DigitalSec4
	DigitalSeconds(5)=DigitalSec5
	DigitalSeconds(6)=DigitalSec6
	DigitalSeconds(7)=DigitalSec7
	DigitalSeconds(8)=DigitalSec8
	DigitalSeconds(9)=DigitalSec9
	DigitalMinutes(0)=DigitalMin0
	DigitalMinutes(1)=DigitalMin1
	DigitalMinutes(2)=DigitalMin2
	DigitalMinutes(3)=DigitalMin3
	DigitalMinutes(4)=DigitalMin4
	DigitalMinutes(5)=DigitalMin5
	DigitalMinutes(6)=DigitalMin6
	DigitalMinutes(7)=DigitalMin7
	DigitalMinutes(8)=DigitalMin8
	DigitalMinutes(9)=DigitalMin9
	TimeToBlow=30.000000
	bBlockActors=True
	bBlockPlayers=True
	bProjTarget=True
	bNetTemporary=False
	LifeSpan=0.000000
	TeamFX(0)=Red_Over
	TeamFX(1)=Blue_OVer
	TeamFX(2)=Green_Over
	TeamFX(3)=Yeallow_Over
}
