## Gameplay
Class TriggerLight

source: C:\XIII\Gameplay\Classes\TriggerLight.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Light
             |
             +--Gameplay.TriggerLight

Direct Known Subclasses:None

class TriggerLight
extends Engine.Light

    //=============================================================================
    // TriggerLight.
    // A lightsource which can be triggered on or off.
    //=============================================================================

Variables
`float` | `ChangeTime` Time light takes to change from on to off.
`Alpha,` | `Direction` Initial brightness.
`float` | `InitialBrightness` Initial brightness.
`float` | `RemainOnTime` How long the TriggerPound effect lasts
`Actor` | `SavedTrigger` Initial brightness.
`bool` | `bDelayFullOn` Delay then go full-on.
`bool` | `bInitiallyOn` Whether it's initially on.
`float` | `poundTime` Initial brightness.

Function Summary
`simulated` | `BeginPlay()`
    // Called at start of gameplay.
`void` | `Tick(float DeltaTime)`
    // Called whenever time passes.
`void` | `Timer()`
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
`void` | `UnTrigger(Actor Other, Pawn EventInstigator)`

Source Code

    00001	//=============================================================================
    00002	// TriggerLight.
    00003	// A lightsource which can be triggered on or off.
    00004	//=============================================================================
    00005	class TriggerLight extends Light;
    00006
    00007	//-----------------------------------------------------------------------------
    00008	// Variables.
    00009
    00010	var() float ChangeTime;        // Time light takes to change from on to off.
    00011	var() bool  bInitiallyOn;      // Whether it's initially on.
    00012	var() bool  bDelayFullOn;      // Delay then go full-on.
    00013	var() float RemainOnTime;      // How long the TriggerPound effect lasts
    00014	VAR	 bool	ShowIcon;
    00015
    00016	var   float InitialBrightness; // Initial brightness.
    00017	var   float Alpha, Direction;
    00018	var   actor SavedTrigger;
    00019	var   float poundTime;
    00020
    00021	//-----------------------------------------------------------------------------
    00022	// Engine functions.
    00023
    00024	// Called at start of gameplay.
    00025	simulated function BeginPlay()
    00026	{
    00027		// Remember initial light type and set new one.
    00028		ShowIcon=!bHidden;
    00029		if (bHidden)
    00030			SetDrawType(DT_None);
    00031
    00032		InitialBrightness = LightBrightness;
    00033		if( bInitiallyOn )
    00034		{
    00035			Alpha     = 1.0;
    00036			Direction = 1.0;
    00037			if (ShowIcon)
    00038				bHidden=False;
    00039		}
    00040		else
    00041		{
    00042			Alpha     = 0.0;
    00043			Direction = -1.0;
    00044			if (ShowIcon)
    00045				bHidden=True;
    00046		}
    00047	}
    00048
    00049	// Called whenever time passes.
    00050	FUNCTION Tick( float DeltaTime )
    00051	{
    00052	//	log("bDelayFullOn "$bDelayFullOn$" LightBrightness "$LightBrightness$" Direction "$Direction$" Alpha "$Alpha);
    00053		if (bDelayFullOn)
    00054		{
    00055			Alpha += Direction * DeltaTime / ChangeTime;
    00056			if( Alpha > 1.0 )
    00057			{
    00058				Alpha = 1.0;
    00059				Disable( 'Tick' );
    00060				if( SavedTrigger != None )
    00061					SavedTrigger.EndEvent();
    00062			}
    00063			else if( Alpha < 0.0 )
    00064			{
    00065				Alpha = 0.0;
    00066				Disable( 'Tick' );
    00067				if( SavedTrigger != None )
    00068					SavedTrigger.EndEvent();
    00069			}
    00070		}
    00071		else
    00072		{
    00073			if( Direction<0 ) //(Direction>0 && Alpha!=1) || Alpha==0 )
    00074			{
    00075				Alpha=0.0;
    00076				LightBrightness = 0;
    00077				if (ShowIcon)
    00078					bHidden=True;
    00079			}
    00080			else
    00081			{
    00082				Alpha=1.0;
    00083				LightBrightness = InitialBrightness;
    00084				if (ShowIcon)
    00085					bHidden=False;
    00086			}
    00087			Disable( 'Tick' );
    00088		}
    00089		LightBrightness = Alpha * InitialBrightness;
    00090	}
    00091
    00092	//-----------------------------------------------------------------------------
    00093	// Public states.
    00094
    00095	// Trigger turns the light on.
    00096	state() TriggerTurnsOn
    00097	{
    00098		function Trigger( actor Other, pawn EventInstigator )
    00099		{
    00100			if( SavedTrigger!=None )
    00101				SavedTrigger.EndEvent();
    00102			SavedTrigger = Other;
    00103			SavedTrigger.BeginEvent();
    00104			Direction = 1.0;
    00105			if (ShowIcon)
    00106				bHidden=False;
    00107			Enable( 'Tick' );
    00108		}
    00109	}
    00110
    00111	// Trigger turns the light off.
    00112	state() TriggerTurnsOff
    00113	{
    00114		function Trigger( actor Other, pawn EventInstigator )
    00115		{
    00116			if( SavedTrigger!=None )
    00117				SavedTrigger.EndEvent();
    00118			SavedTrigger = Other;
    00119			SavedTrigger.BeginEvent();
    00120			Direction = -1.0;
    00121			if (ShowIcon)
    00122				bHidden=True;
    00123			Enable( 'Tick' );
    00124		}
    00125	}
    00126
    00127	// Trigger toggles the light.
    00128	state() TriggerToggle
    00129	{
    00130		function Trigger( actor Other, pawn EventInstigator )
    00131		{
    00132			if( SavedTrigger!=None )
    00133				SavedTrigger.EndEvent();
    00134			SavedTrigger = Other;
    00135			SavedTrigger.BeginEvent();
    00136			Direction *= -1;
    00137			if (ShowIcon)
    00138				bHidden=!bHidden;
    00139			Enable( 'Tick' );
    00140		}
    00141	}
    00142
    00143	// Trigger controls the light.
    00144	state() TriggerControl
    00145	{
    00146		function Trigger( actor Other, pawn EventInstigator )
    00147		{
    00148			if( SavedTrigger!=None )
    00149				SavedTrigger.EndEvent();
    00150			SavedTrigger = Other;
    00151			SavedTrigger.BeginEvent();
    00152			if( bInitiallyOn ) Direction = -1.0;
    00153			else               Direction = 1.0;
    00154			if (ShowIcon)
    00155				bHidden=bInitiallyOn;
    00156			Enable( 'Tick' );
    00157		}
    00158		function UnTrigger( actor Other, pawn EventInstigator )
    00159		{
    00160			if( SavedTrigger!=None )
    00161				SavedTrigger.EndEvent();
    00162			SavedTrigger = Other;
    00163			SavedTrigger.BeginEvent();
    00164			if( bInitiallyOn ) Direction = 1.0;
    00165			else               Direction = -1.0;
    00166			if (ShowIcon)
    00167				bHidden=!bInitiallyOn;
    00168			Enable( 'Tick' );
    00169		}
    00170	}
    00171
    00172	state() TriggerPound {
    00173
    00174		function Timer () {
    00175
    00176			if (poundTime >= RemainOnTime) {
    00177
    00178				Disable ('Timer');
    00179			}
    00180			poundTime += ChangeTime;
    00181			Direction *= -1;
    00182			if (ShowIcon)
    00183				bHidden=!bHidden;
    00184			SetTimer (ChangeTime, false);
    00185		}
    00186
    00187		function Trigger( actor Other, pawn EventInstigator )
    00188		{
    00189
    00190			if( SavedTrigger!=None )
    00191				SavedTrigger.EndEvent();
    00192			SavedTrigger = Other;
    00193			SavedTrigger.BeginEvent();
    00194			Direction = 1;
    00195			if (ShowIcon)
    00196				bHidden=False;
    00197			poundTime = ChangeTime;			// how much time will pass till reversal
    00198			SetTimer (ChangeTime, false);		// wake up when it's time to reverse
    00199			Enable   ('Timer');
    00200			Enable   ('Tick');
    00201		}
    00202	}
    00203
    00204
    00205	defaultproperties
    00206	{
    00207	     bStatic=False
    00208	     bHidden=False
    00209	     bNoDelete=False
    00210	     bDynamicLight=True
    00211	     bMovable=True
    00212	     RemoteRole=ROLE_SimulatedProxy
    00213	}

End Source Code