//=============================================================================
// TriggeredDeath.
// When triggered, kills the player, causing screen flashes and sounds.
//=============================================================================
class TriggeredDeath expands Triggers;

var() Sound  MaleDeathSound;
var() Sound  FemaleDeathSound;
var() Vector StartFlashScale;
var() Vector StartFlashFog;
var() Vector EndFlashScale;
var() Vector EndFlashFog;
var() float  ChangeTime;
var() Name   DeathName;

var float TimePassed;
var UnrealIPlayer Victim;

function BeginPlay()
{
	Victim = None;
}

function Touch( Actor Other )
{
	// Something has contacted the death trigger.
	// If it is an UnrealIPlayer, have it screen flash and
	// die.

	if( UnrealIPlayer( Other ) != None )
	{
		TimePassed = 0;
		Victim = UnrealIPlayer( Other );
		if( Female( Other ) != None )
			Victim.PlaySound( FemaleDeathSound, SLOT_Talk );
		else
			Victim.PlaySound( MaleDeathSound, SLOT_Talk );
		Enable('Tick');
	}
}


function Tick( float DeltaTime )
{
	local Vector CurScale, CurFog;
	local float  TimeRatio;

	if( Victim != None )
	{
		// Check the timing
		TimePassed += DeltaTime;
		if( TimePassed >= ChangeTime )
		{
			TimeRatio = 1;
			Disable('Tick');
			Victim.level.game.Killed(None, Victim, DeathName);
			Victim.HidePlayer();
			Victim.Level.Game.DiscardInventory(Victim);
			Victim.Health = -1;
			Victim.Score -= 1;
			Victim.GotoState('Dying');
		}
		else TimeRatio = TimePassed/ChangeTime;

		// Continue the screen flashing
		CurScale = (EndFlashScale-StartFlashScale)*TimeRatio + StartFlashScale;
		CurFog   = (EndFlashFog  -StartFlashFog  )*TimeRatio + StartFlashFog;

		Victim.ClientFlash( CurScale, CurFog );
	}
	else Disable('Tick');
}


