class MegaTonDecoder expands NaliWeapons;

//1st person
#exec MESH IMPORT MESH=MegaTonDecoder ANIVFILE=MODELS\MegaTonDecoder_a.3d DATAFILE=MODELS\MegaTonDecoder_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=MegaTonDecoder STRENGTH=0
#exec MESH ORIGIN MESH=MegaTonDecoder X=0 Y=0 Z=0 YAW=128

//pickup / 3rd person
#exec MESH IMPORT MESH=MegaTonDecoderM ANIVFILE=MODELS\MegaTonDecoder_a.3d DATAFILE=MODELS\MegaTonDecoder_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=MegaTonDecoderM STRENGTH=0
#exec MESH ORIGIN MESH=MegaTonDecoderM X=0 Y=0 Z=0 YAW=128

#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=All STARTFRAME=0 NUMFRAMES=5
#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=KeyPress STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=Down STARTFRAME=1 NUMFRAMES=2 RATE=3.0
#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=Select STARTFRAME=2 NUMFRAMES=2 RATE=3.0

#exec MESH SEQUENCE MESH=MegaTonDecoder SEQ=All STARTFRAME=0 NUMFRAMES=5
#exec MESH SEQUENCE MESH=MegaTonDecoderM SEQ=Still STARTFRAME=4 NUMFRAMES=1


#exec MESHMAP NEW MESHMAP=MegaTonDecoder MESH=MegaTonDecoder
#exec MESHMAP SCALE MESHMAP=MegaTonDecoder X=0.015 Y=0.015 Z=0.03

#exec MESHMAP NEW MESHMAP=MegaTonDecoderM MESH=MegaTonDecoderM
#exec MESHMAP SCALE MESHMAP=MegaTonDecoderM X=0.015 Y=0.015 Z=0.03

//Skins
#exec TEXTURE IMPORT NAME=Sk_MegaTonDec_01 FILE=SKINS\Sk_MegaTonDec_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=1 TEXTURE=Sk_MegaTonDec_01
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=1 TEXTURE=Sk_MegaTonDec_01

#exec TEXTURE IMPORT NAME=Sk_MegaTonDec_02 FILE=SKINS\Sk_MegaTonDec_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=2 TEXTURE=Sk_MegaTonDec_02
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=2 TEXTURE=Sk_MegaTonDec_02

#exec TEXTURE IMPORT NAME=Sk_MegaTonDec_03 FILE=SKINS\Sk_MegaTonDec_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=3 TEXTURE=Sk_MegaTonDec_03
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=3 TEXTURE=Sk_MegaTonDec_03

#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=4 TEXTURE=DigitalSecDead
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=4 TEXTURE=DigitalSecDead
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=5 TEXTURE=DigitalSecDead
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=5 TEXTURE=DigitalSecDead
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoder NUM=6 TEXTURE=DigitalSecDead
#exec MESHMAP SETTEXTURE MESHMAP=MegaTonDecoderM NUM=6 TEXTURE=DigitalSecDead

//--------------------------------------------------------------
//Icons
#exec TEXTURE IMPORT NAME=MegaTDecIcon FILE=ICONS\MegaTDecIcon.bmp GROUP=Icons MIPS=OFF

//Digital skinning import-----------------------------------------------------------------------------
#exec TEXTURE IMPORT NAME=DigitalE FILE=SKINS\DigitalE.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=DigitalR FILE=SKINS\DigitalR.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=DigitalTrace FILE=SKINS\DigitalTrace.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=DigitalTripleTrace FILE=SKINS\DigitalTripleTrace.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
//----------------------------------------------------------------------------------------------------

//Sounds
#exec AUDIO IMPORT NAME="DecoderTransmission" FILE=SOUNDS\DecoderTransmission.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoded_OK" FILE=SOUNDS\Decoded_OK.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoded_Error" FILE=SOUNDS\Decoded_Error.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoder_Pick" FILE=SOUNDS\Decoder_Pick.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoder_Select" FILE=SOUNDS\Decoder_Select.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoder_Enter" FILE=SOUNDS\Decoder_Enter.wav GROUP="Decoder"
#exec AUDIO IMPORT NAME="Decoder_Typing" FILE=SOUNDS\Decoder_Typing.wav GROUP="Decoder"


var() texture DigitalSeconds[10];
var byte NukePassword[3];

var bool bTransmiting, bError, bOk;
var byte TweakStage;

var float TimeCount, RateCountCross, RateCountDisplay;
var MegaTonOMFG MegaT;

replication
{
	reliable if (Role == ROLE_Authority)
		NukePassword, MegaT;
	reliable if (Role == ROLE_Authority && bNetOwner)
		bTransmiting, bError, bOk, TweakStage, TimeCount;
}


function Fire( float Value )
{
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);

	if (TweakStage == 0)
	{

		GotoState('NormalFire');
		bPointing=True;
		bCanClientFire = true;
		ClientFire(Value);
		TimeCount = 0;
		bTransmiting = True;
		TraceFire(0.0);
		
	}
	if (TweakStage > 0)
		SetFireAction();
}

simulated function SetFireAction()
{
	TweakStage++;

	if (TweakStage > 3)
		TweakStage = 0;
}

simulated function PlayFiring()
{
	if (TweakStage == 0)
		PlayAnim('KeyPress', 0.25, 0.0);
	else
	{
		PlayAnim('KeyPress', 2.0, 0.0);
		PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	}
}


function TraceFire( float Accuracy )
{
    local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z;
    local actor Other;
    local Pawn PawnOwner;

    PawnOwner = Pawn(Owner);

    Owner.MakeNoise(PawnOwner.SoundDampening);
    GetAxes(PawnOwner.ViewRotation,X,Y,Z);
    StartTrace = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
    AdjustedAim = PawnOwner.AdjustAim(1000000, StartTrace, 2*AimError, False, False);   
    EndTrace = StartTrace + Accuracy * (FRand() - 0.5 )* Y * 1000
        + Accuracy * (FRand() - 0.5 ) * Z * 1000;
    X = vector(AdjustedAim);
    EndTrace += (256 * X); 
    Other = PawnOwner.TraceShot(HitLocation,HitNormal,EndTrace,StartTrace);
    ProcessTraceHit(Other, HitLocation, HitNormal, X,Y,Z);
}



function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	GetMegaInfo(Other);
}

simulated function GetMegaInfo(actor Other)
{
	if (Other.IsA('MegaTonOMFG'))
	{
		if (MegaTonOMFG(Other).NukePassword[0] == NukePassword[0] && MegaTonOMFG(Other).NukePassword[1] == NukePassword[1] && MegaTonOMFG(Other).NukePassword[3] == NukePassword[3])
		{
			MegaT = MegaTonOMFG(Other);
			bOk = True;
		}
		else
			bError = True;
	}
	else
		bError = True;
}


function AltFire( float Value )
{
        GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);

	SetAltFireAction();
}

simulated function SetAltFireAction()
{
	if (TweakStage == 0)
		TweakStage = 1;

	if (TweakStage == 1)
	{
		NukePassword[0]++;

		if (NukePassword[0] > 9)
			NukePassword[0] = 0;
	}
	else if (TweakStage == 2)
	{
		NukePassword[1]++;

		if (NukePassword[1] > 9)
			NukePassword[1] = 0;
	}
	else if (TweakStage == 3)
	{
		NukePassword[3]++;

		if (NukePassword[2] > 9)
			NukePassword[2] = 0;
	}
}


simulated function PlayAltFiring()
{
	PlayAnim('KeyPress', 4.0, 0.0);
	PlayOwnedSound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
}


simulated function Tick( float DeltaTime)
{

	if (Pawn(Owner) != None)
	{
		if (!bTransmiting)
		{

		if (TweakStage == 0)
		{
			MultiSkins[4] = DigitalSeconds[NukePassword[0]];
			MultiSkins[5] = DigitalSeconds[NukePassword[1]];
			MultiSkins[6] = DigitalSeconds[NukePassword[2]];
		}
		else if (TweakStage == 1)
		{
			MultiSkins[4] = DigitalSeconds[NukePassword[0]];
			MultiSkins[5] = None;
			MultiSkins[6] = None;
		}
		else if (TweakStage == 2)
		{
			MultiSkins[4] = None;
			MultiSkins[5] = DigitalSeconds[NukePassword[1]];
			MultiSkins[6] = None;
		}
		else if (TweakStage == 3)
		{
			MultiSkins[4] = None;
			MultiSkins[5] = None;
			MultiSkins[6] = DigitalSeconds[NukePassword[2]];
		}
		}
		else
		{

			RateCountCross += DeltaTime;
			RateCountDisplay += DeltaTime;

			if (RateCountCross > 0.08)
				RateCountCross = 0;

			if (RateCountDisplay > 0.3)
				RateCountDisplay = 0;

			if (bError || bOk)
			{
				if (AmbientSound == None)
					AmbientSound = Sound'DecoderTransmission';

				if (RateCountCross == 0)
				{
					if (CustomCross == Texture'DecCross01')
						CustomCross = Texture'DecCross02';
					else if (CustomCross == Texture'DecCross02')
						CustomCross = Texture'DecCross03';
					else if (CustomCross == Texture'DecCross03')
						CustomCross = Texture'DecCross04';
					else if (CustomCross == Texture'DecCross04')
						CustomCross = Texture'DecCross05';
					else if (CustomCross == Texture'DecCross05')
						CustomCross = Texture'DecCross06';
					else
						CustomCross = Texture'DecCross01';
				}

				if (RateCountDisplay == 0)
				{
					if (MultiSkins[4] == Texture'DigitalTrace')
					{
						MultiSkins[4] = None;
						MultiSkins[5] = None;
						MultiSkins[6] = None;
					}
					else
					{
						MultiSkins[4] = Texture'DigitalTrace';
						MultiSkins[5] = Texture'DigitalTrace';
						MultiSkins[6] = Texture'DigitalTrace';
					}
				}
			}
			else
				CustomCross = Default.CustomCross;

		if (bError)
		{
			TimeCount += DeltaTime;
			if (TimeCount > 2.8)
			{
				bError = False;
				AmbientSound = None;
				PlayOwnedSound(Sound'Decoded_Error', SLOT_None, Pawn(Owner).SoundDampening*3.0);

				MultiSkins[4] = Texture'DigitalE';
				MultiSkins[5] = Texture'DigitalR';
				MultiSkins[6] = Texture'DigitalR';
			}
		}
		else if (bOk)
		{
			TimeCount += DeltaTime;

			if (TimeCount > 2.8)
			{
				bOk = False;
				AmbientSound = None;
				PlayOwnedSound(Sound'Decoded_OK', SLOT_None, Pawn(Owner).SoundDampening*3.0);

				MultiSkins[4] = Texture'DigitalTripleTrace';
				MultiSkins[5] = Texture'DigitalTrace';
				MultiSkins[6] = Texture'DigitalTripleTrace';

				if (MegaT != None)
					MegaT.UnArm();
			}
		}
		else
		{
			if (TimeCount > 3.8)
				bTransmiting = False;
			else
				TimeCount += DeltaTime;
		}

		}
	}
	else
	{
		MultiSkins[4] = None;
		MultiSkins[5] = None;
		MultiSkins[6] = None;
	}
}



defaultproperties
{
	DrawType=DT_Mesh
	Mesh=MegaTonDecoderM
	AnimSequence=Still
	CollisionRadius=5.000000
	CollisionHeight=5.000000
	AutoSwitchPriority=1
	Icon=MegaTDecIcon
	InventoryGroup=1
	ItemArticle="a"
	ItemName="MegaTon Decoder"
	MaxDesireability=0.100000
	PickupMessage="You got a MegaTon Decoder."
	PickupSound=Decoder_Pick
	PickupViewMesh=MegaTonDecoderM
	PickupViewScale=1.000000
	PlayerViewMesh=MegaTonDecoder
	PlayerViewOffset=(X=16.000000,Y=0.000000,Z=-10.000000)
	PlayerViewScale=1.000000
	RespawnTime=300.000000
	StatusIcon=MegaTDecIcon
	ThirdPersonMesh=MegaTonDecoderM
	ThirdPersonScale=0.700000
	AltDamageType=None
	AltFireSound=Decoder_Typing
	AltProjectileClass=None
	bInstantHit=True
	AmmoName=Class'DecoderAmmo'
	DeathMessage="-"
	FireOffset=(X=0.000000,Y=0.000000,Z=0.000000)
	FireSound=Decoder_Enter
	FiringSpeed=1.000000
	MaxTargetRange=4096.000000
	MyDamageType=None
	NameColor=(R=255,G=0,B=0)
	PickupAmmoCount=3
	ProjectileClass=None
	SelectSound=Decoder_Select
	shakemag=0.000000
	shaketime=0.200000
	shakevert=0.000000
	AIRating=0.000000
	AltRefireRate=1.000000
	bAltWarnTarget=False
	bRecommendAltSplashDamage=False
	bRecommendSplashDamage=False
	bSplashDamage=False
	bWarnTarget=False
	RefireRate=1.200000
	Mass=15.000000
	bNoSmooth=False
	bOwnsCrossHair=True
	CustomCross=DecCross01
	CrossHairSize=64
	bMegaWeapon=True
	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
	SoundVolume=160
	SoundRadius=64
}
