//=============================================================================
// PressureZone.
//=============================================================================
class PressureZone expands ZoneInfo;

var() float  KillTime;					// How long to kill the player?
var() name   KillName;					// What shall we call this kill?
var() float  StartFlashScale;			// Fog values for client death sequence
var() Vector StartFlashFog;
var() float  EndFlashScale;
var() Vector EndFlashFog;
var() Sound  MaleScreamSound;			// Screaming of the various entities
var() Sound  FemaleScreamSound;
var() Sound  SkaarjScreamSound;
var() float  DieFOV;					// Field of view when dead (interpolates)
var() float  DieDrawScale;				// Drawscale when dead
var() byte   DieFatness;				// Fatness when dead
var   float  TimePassed;
var   bool   bTriggered;				// Ensure that it doesn't update until it should
var	  bool	 bScreamed;

function BeginPlay()
{
	Super.BeginPlay();
	Disable('Tick');
	bTriggered = false;
	DieFOV = FClamp( DieFOV, 1, 170 );
	DieFatness = Clamp( DieFatness, 1, 255 );
}

function Trigger( actor Other, pawn EventInstigator )
{
	local Pawn p;

	// The pressure zone has been triggered to kill something

	Instigator = EventInstigator;

	// Engage Tick so that death may be slow and dramatic
	TimePassed = 0;
	bTriggered = true;
	bScreamed = false;
	Disable('Trigger');
	Enable('Tick');
}

function Tick( float DeltaTime )
{
	local float  		ratio, curScale;
	local vector 		curFog;
	local PlayerPawn	pPawn;
	local Pawn P;

	if( !bTriggered ) 
	{
		Disable('Tick');
		return;
	}

	TimePassed += DeltaTime;
	ratio = TimePassed/KillTime;
	if( ratio > 1.0 ) ratio = 1.0;

	for ( P=Level.PawnList; P!=None; P=P.NextPawn )
	{
		// Ensure player hasn't been dispatched through other means already (suicide?)
		if( (P.FootRegion.Zone == self) && (P.Health > 0) )
		{
			// Fatness
			P.Fatness   = byte( 128 + Int( (Float(DieFatness)-128) * ratio ));
			P.DrawScale = 1 + (DieDrawScale-1) * ratio;

			// Maybe scream?
			if( !bScreamed && P.bIsPlayer && (Ratio > 0.2) && (FRand() < 2 * DeltaTime) )
			{
				// Scream now (from the terrible pain)
				bScreamed = true;
				if ( P.bIsHuman )
				{
					if ( P.IsA('Female') || P.IsA('FemaleBotPlus') )
						P.PlaySound( FemaleScreamSound, SLOT_Talk );
					else
						P.PlaySound( MaleScreamSound, SLOT_Talk );
				}
				else
				{
					// Skaarj 
					P.PlaySound( SkaarjScreamSound, SLOT_Talk );
				}
			}
		
			// Fog & Field of view
			pPawn = PlayerPawn(P);
			if( pPawn != None )
			{
				curScale = (EndFlashScale-StartFlashScale)*ratio + StartFlashScale;
				curFog   = (EndFlashFog  -StartFlashFog  )*ratio + StartFlashFog;
				pPawn.ClientFlash( curScale, 1000 * curFog );

				pPawn.SetFOVAngle( (DieFOV-pPawn.default.FOVAngle)*ratio + pPawn.default.FOVAngle);
			}
			if ( ratio == 1.0 )
			{			
				P.TakeDamage
				(
					10000,
					Instigator,
					P.Location,
					Vect(0,0,0),
					KillName				
				);
				// set the fatness back to normal
				P.Fatness = 128;
				P.DrawScale = 1;
				if( pPawn != None )
					pPawn.SetFOVAngle( pPawn.Default.FOVAngle );
			}
		}
	}	
	
	if( ratio == 1.0 )
	{
		Disable('Tick');
		Enable('Trigger');
		bTriggered = false;
	}
}

defaultproperties
{
}
