//=============================================================================
// Translocator.
//=============================================================================
class Translocator expands Weapon;

#exec MESH  IMPORT MESH=TeleHand ANIVFILE=MODELS\Hand_a.3D DATAFILE=MODELS\Hand_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=TeleHand X=0 Y=0 Z=0 YAW=64 PITCH=-10 ROLL=-10
#exec MESH SEQUENCE MESH=TeleHand SEQ=All    STARTFRAME=0  NUMFRAMES=105
#exec MESH SEQUENCE MESH=TeleHand SEQ=Temp      STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=TeleHand SEQ=Select    STARTFRAME=1  NUMFRAMES=13
#exec MESH SEQUENCE MESH=TeleHand SEQ=Still     STARTFRAME=14 NUMFRAMES=2
#exec MESH SEQUENCE MESH=TeleHand SEQ=Twiddle1  STARTFRAME=16 NUMFRAMES=4
#exec MESH SEQUENCE MESH=TeleHand SEQ=Twiddle2  STARTFRAME=20 NUMFRAMES=6
#exec MESH SEQUENCE MESH=TeleHand SEQ=Throw     STARTFRAME=26 NUMFRAMES=15
#exec MESH SEQUENCE MESH=TeleHand SEQ=Select2   STARTFRAME=41 NUMFRAMES=15
#exec MESH SEQUENCE MESH=TeleHand SEQ=Fire      STARTFRAME=56 NUMFRAMES=5
#exec MESH SEQUENCE MESH=TeleHand SEQ=Rub1      STARTFRAME=61 NUMFRAMES=2
#exec MESH SEQUENCE MESH=TeleHand SEQ=Rub2      STARTFRAME=63 NUMFRAMES=2
#exec MESH SEQUENCE MESH=TeleHand SEQ=Walk      STARTFRAME=65 NUMFRAMES=4
#exec MESH SEQUENCE MESH=TeleHand SEQ=Down      STARTFRAME=69 NUMFRAMES=7
#exec MESH SEQUENCE MESH=TeleHand SEQ=Finger    STARTFRAME=76 NUMFRAMES=29
//#exec TEXTURE IMPORT NAME=Ahand1 FILE=MODELS\hand.PCX GROUP="Skins"
//#exec TEXTURE IMPORT NAME=Ahand2 FILE=MODELS\hand2.PCX GROUP="Skins"
#exec MESHMAP SCALE MESHMAP=TeleHand X=0.005 Y=0.005 Z=0.01
#exec MESHMAP SETTEXTURE MESHMAP=TeleHand NUM=0 TEXTURE=Default

#exec MESH NOTIFY MESH=TeleHand SEQ=Throw TIME=0.6 FUNCTION=Toss
#exec MESH NOTIFY MESH=TeleHand SEQ=Fire TIME=0.5 FUNCTION=Teleport

var Translocator Twin;

function Fire( float Value )
{
	bFireMem = false;
	bAltFireMem = false;
	bPointing=True;
 	GotoState('NormalFire');
}

function AltFire( float Value )
{
	bFireMem = false;
	bAltFireMem = false;
	bPointing=True;
	GoToState('AltFiring');
}

////////////////////////////////////////////////////////
state AltFiring
{
Begin:
	PlaySound(AltFireSound, SLOT_Misc, Pawn(Owner).SoundDampening);	
	PlayAnim('Down',0.6);
	FinishAnim();
	PlayAnim('Finger',0.5);
	FinishAnim();
	GoToState('Idle');
	PlayAnim('Select',0.6);
	FinishAnim();	
}

function Teleport()
{
	local Vector X,Y,Z;
	if (Twin.Owner == Owner) {
		PlaySound(Misc1Sound, SLOT_Misc, Pawn(Owner).SoundDampening);    // Teleport Fail Sound
	}
	else {
		if (Twin.Owner!=Owner && Twin.Owner!=None) 
				Twin.Owner.Damage(99999, Pawn(Owner),Twin.Owner.Location,VRand(), 'exploded');
		Owner.SetLocation(Twin.Location);
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);	
		PlaySound(Misc2Sound, SLOT_Misc, Pawn(Owner).SoundDampening);	 // Teleport Succeed Sound	
		spawn(class 'TeleportEffect',,);
		Twin.Touch(Pawn(Owner));
	}
}

///////////////////////////////////////////////////////
state NormalFire
{
function FindTwin()
{
	local Translocator PotentialTwin;

	Twin=None;	
	foreach AllActors( class 'Translocator', PotentialTwin, Tag )
		if (Target(PotentialTwin)!=None && Tag!='None') 
		{
			Twin = Target(PotentialTwin);  	// Found our match.
			Break;
		}

	if (Twin==None)
	{	
		Pawn(Owner).ClientMessage("Destination module is inaccessible");
		GotoState('Idle');
	}
	else 
		PlayAnim('Fire',0.6);
}

Begin:
	FindTwin();
	FinishAnim();
	if (Twin.Owner==Owner) 
	{
		PutDown();
		Pawn(Owner).PendingWeapon = Twin;
		GotoState('');
	}
}

///////////////////////////////////////////////////////////
function PlayIdleAnim()
{
	local Float decision;
	if ( Size(Pawn(Owner).Velocity)>20 ) {
		PlayAnim('Walk',0.1);
	}
	else  
	{
		decision = FRand();
		if ( decision<0.33 ) 
			PlayAnim('Still',0.05);
		else if ( decision<0.66 ) 
			PlayAnim('Rub1',0.05);			
		else 
			PlayAnim('Rub2',0.05);	
	}
	Enable('AnimEnd');
}

function PlaySelect()
{
//	skin = texture'AHand1';
	PlayAnim('Select',0.9, 0.0);
	PlaySound(SelectSound, SLOT_Misc,Pawn(Owner).SoundDampening);		
}

