//=============================================================================
// Amplifier.
//=============================================================================
class Amplifier expands Pickup;

#exec AUDIO IMPORT FILE="Sounds\Pickups\HEALTH1.WAV" NAME="HEALTH1" GROUP="Pickups"
#exec AUDIO IMPORT FILE="Sounds\Pickups\ampl1.WAV" NAME="AmpAct" GROUP="Pickups"

#exec TEXTURE IMPORT NAME=I_Amp FILE=TEXTURES\HUD\i_amp.PCX GROUP="Icons"

#exec MESH IMPORT MESH=Amplifier ANIVFILE=MODELS\amp_a.3D DATAFILE=MODELS\amp_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=Amplifier X=0 Y=0 Z=50 YAW=0
#exec MESH SEQUENCE MESH=Amplifier SEQ=All    STARTFRAME=0  NUMFRAMES=1
#exec TEXTURE IMPORT NAME=JAmplifier1 FILE=MODELS\Amp.PCX GROUP="Skins" 
#exec MESHMAP SCALE MESHMAP=Amplifier X=0.08 Y=0.08 Z=0.16
#exec MESHMAP SETTEXTURE MESHMAP=Amplifier NUM=1 TEXTURE=JAmplifier1

var() float AmpMultiplier;

function bool HandlePickupQuery( inventory Item )
{
	if (DispersionPistol(Item)!=None) 
	{
		DispersionPistol(Item).Amp = Self;
	}

	if (ASMD(Item)!=None) 
	{
		ASMD(Item).Amp = Self;
	}
	
	return CallParent.HandlePickupQuery(Item);
}

event TravelPostAccept()
{
	local inventory w;

	CallParent.TravelPostAccept();
	w = Pawn(Owner).FindInventoryType(class'DispersionPistol');
	if ( w != None )
		DispersionPistol(w).Amp = self;
	w = Pawn(Owner).FindInventoryType(class'ASMD');
	if ( w != None )
		ASMD(w).Amp = self;
}

function float UseCharge(float Amount)
{
	Return 1.0;
}

function UsedUp()
{
	local Inventory I;

	I = Pawn(Owner).FindInventoryType(class'DispersionPistol');
	if ( DispersionPistol(I) != None )
		DispersionPistol(I).amp = None;

	I = Pawn(Owner).FindInventoryType(class'ASMD');
	if ( ASMD(I) != None )
		ASMD(I).amp = None;

	CallParent.UsedUp();
}

state Activated
{

	function float UseCharge(float Amount)
	{
		local float TempCharge;
		if (AmpMultiplier<1.0) AmpMultiplier=1.0;
	
		if (Charge < Amount) {
			TempCharge = Charge;
			Charge=0;
			Return (AmpMultiplier-1.0)*TempCharge/Amount+1.0;
		}
		Charge = Charge - Amount;
		return AmpMultiplier;
	}


	function Timer()
	{
		Charge -= 1;
		if (Charge<-0) {
			PlaySound(DeActivateSound);
			UsedUp();		
		}
	}
	function EndState()
	{
		PlayerPawn(Owner).ClientAdjustGlow(vect(0.1,0.1,0.1),vect(-0.1,-0.02,0));
		PlayerPawn(Owner).AmbientSound=None;
		PlayerPawn(Owner).LightType=LT_None;
		PlayerPawn(Owner).AmbientGlow=0;		
		bActive = false;		
	}
Begin:
	SetTimer(1.0,True);
	PlayerPawn(Owner).AmbientSound=DeActivateSound;
	PlayerPawn(Owner).ClientAdjustGlow(vect(-0.1,-0.1,-0.1),vect(0.1,0.02,0));
	PlaySound(ActivateSound);	
	PlayerPawn(Owner).LightType=LT_Steady;	
	PlayerPawn(Owner).LightRadius=6;
	PlayerPawn(Owner).LightEffect=LE_NonIncidence;
	PlayerPawn(Owner).LightSaturation=40;
	PlayerPawn(Owner).LightHue=6;
	PlayerPawn(Owner).LightBrightness=255;
	PlayerPawn(Owner).AmbientGlow=255;
}

state DeActivated
{
Begin:

}

