//=============================================================================
// Peacemaker.
//=============================================================================
class Peacemaker expands Weapon;

#exec MESH IMPORT MESH=peacehand ANIVFILE=MODELS\phand_a.3D DATAFILE=MODELS\phand_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=peacehand X=0 Y=0 Z=0 YAW=-64 ROLL=0 PITCH=0
#exec MESH SEQUENCE MESH=peacehand SEQ=All       STARTFRAME=0   NUMFRAMES=54
#exec MESH SEQUENCE MESH=peacehand SEQ=Select    STARTFRAME=0   NUMFRAMES=20
#exec MESH SEQUENCE MESH=peacehand SEQ=Still     STARTFRAME=20  NUMFRAMES=1
#exec MESH SEQUENCE MESH=peacehand SEQ=Down      STARTFRAME=21  NUMFRAMES=12
#exec MESH SEQUENCE MESH=peacehand SEQ=Throw     STARTFRAME=33  NUMFRAMES=10
#exec MESH SEQUENCE MESH=peacehand SEQ=Count     STARTFRAME=43  NUMFRAMES=11
#exec TEXTURE IMPORT NAME=Jpeacehand1 FILE=MODELS\peaceh.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=peacehand  X=0.005 Y=0.005 Z=0.01
#exec MESHMAP SETTEXTURE MESHMAP=peacehand NUM=1 TEXTURE=Jpeacehand1

#exec MESH IMPORT MESH=peacepick ANIVFILE=MODELS\peacpi_a.3D DATAFILE=MODELS\phand_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=peacepick X=0 Y=0 Z=10 YAW=-64 ROLL=0 PITCH=0
#exec MESH SEQUENCE MESH=peacepick SEQ=All       STARTFRAME=0   NUMFRAMES=1
#exec MESH SEQUENCE MESH=peacepick SEQ=Still     STARTFRAME=0   NUMFRAMES=1
#exec TEXTURE IMPORT NAME=Jpeacehand1 FILE=MODELS\peaceh.PCX GROUP=Skins
#exec MESHMAP SCALE MESHMAP=peacepick  X=0.08 Y=0.08 Z=0.16
#exec MESHMAP SETTEXTURE MESHMAP=peacepick NUM=1 TEXTURE=Jpeacehand1

var float ChargeTime;

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

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

// Finish a firing sequence
function Finish()
{
	if ( bChangeWeapon )
		GotoState('DownWeapon');
	else if ( bFireMem || Pawn(Owner).bFire!=0 )
		CallGlobal.Fire(0);
	else if ( bAltFireMem || Pawn(Owner).bAltFire!=0 )
		CallGlobal.AltFire(0);
	else 
		GotoState('Idle');
}

function ThrowBarrel(bool bRocketMode)
{
	local vector X,Y,Z;
	local PeaceBarrel NewBarrel;

//	PlayAnim('Throw',0.5);
//	FinishAnim();
	InvCalcView();
	PlaySound(Misc1Sound, SLOT_Misc, Pawn(Owner).SoundDampening);	// Tossing barrel
	GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
	NewBarrel = Spawn(class'PeaceBarrel',, '', Location + 50 * X - 9 * Y - Z * 20);
	NewBarrel.bFireType = bRocketMode;
	NewBarrel.CountDown = ChargeTime;
	Pawn(Owner).DeleteInventory(self);
	Pawn(Owner).SwitchToBestWeapon();
	Destroy();
}

///////////////////////////////////////////////////////
state NormalFire
{
	function Tick( float DeltaTime )
	{
		ChargeTime += DeltaTime;
		if( (pawn(Owner).bFire==0)) 
			ThrowBarrel(True);
	}

Begin:
	ChargeTime = 0.0;
	PlayAnim('Count',0.05);
	FinishAnim();
	ThrowBarrel(True); // rocket mode
}

////////////////////////////////////////////////////////
state AltFiring
{
	function Tick( float DeltaTime )
	{
		ChargeTime += DeltaTime;
		if( (pawn(Owner).bAltFire==0)) 
			ThrowBarrel(False);
	}

Begin:
	ChargeTime = 0.0;
	PlayAnim('Count',0.05);
	FinishAnim();	
	ThrowBarrel(False);
}

///////////////////////////////////////////////////////////
function PlayIdleAnim()
{
	PlayAnim('Still');
}

