## Engine
Class Trigger

source: C:\XIII\Engine\Classes\Trigger.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Triggers
             |
             +--Engine.Trigger

Direct Known Subclasses:ZoneTrigger, TimedTrigger, CineKiller, CineTrigger, CorpseDetectorTrigger, SeenTrigger

class Trigger
extends Engine.Triggers

    //=============================================================================
    // Trigger: senses things happening in its proximity and generates
    // sends Trigger/UnTrigger to actors whose names match 'EventName'.
    //=============================================================================

Variables
`class` | `ClassProximityType`
`float` | `DamageThreshold` minimum damage to trigger if TT_Shoot
`enum` | `ETriggerType`
`string` | `Message`
`float` | `ReTriggerDelay` minimum time before trigger can be triggered again
`float` | `RepeatTriggerTime` if > 0, repeat trigger message at this interval is still touching other
`Actor` | `TriggerActor2` minimum damage to trigger if TT_Shoot
`bool` | `bInitiallyActive`
`bool` | `bSavedInitialActive` minimum damage to trigger if TT_Shoot
`bool` | `bSavedInitialCollision` minimum damage to trigger if TT_Shoot
`bool` | `bTriggerOnceOnly`

Function Summary
`void` | `CheckTouchList()`
    // when trigger gets turned on, check its touch list
`void` | `FindTriggerActor()`
`bool` | `IsRelevant(Actor Other)`
    //
    // See whether the other actor is relevant to this trigger.
    //
`void` | `PostBeginPlay()`
    //=============================================================================
    // AI related functions
`void` | `Reset()`
    /* Reset()
    reset actor to initial state - used when restarting level without reloading.
    */
`Actor` | `SpecialHandling(Pawn Other)`
`void` | `Timer()`
`void` | `Touch(Actor Other)`
    //
    // Called when something touches the trigger.
    //
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
    // Other trigger turns this off.
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
    // Other trigger turns this off.
`void` | `Trigger(Actor Other, Pawn EventInstigator)`
    // Other trigger turns this off.
`void` | `UnTouch(Actor Other)`
    //
    // When something untouches the trigger.
    //

Source Code

    00001	//=============================================================================
    00002	// Trigger: senses things happening in its proximity and generates
    00003	// sends Trigger/UnTrigger to actors whose names match 'EventName'.
    00004	//=============================================================================
    00005	class Trigger extends Triggers
    00006		native;
    00007
    00008	#exec Texture Import File=Textures\Trigger.pcx Name=S_Trigger Mips=Off MASKED=1 COMPRESS=DXT1
    00009
    00010	//-----------------------------------------------------------------------------
    00011	// Trigger variables.
    00012
    00013	// Trigger type.
    00014	var() enum ETriggerType
    00015	{
    00016		TT_PlayerProximity,	// Trigger is activated by player proximity.
    00017		TT_PawnProximity,	// Trigger is activated by any pawn's proximity
    00018		TT_ClassProximity,	// Trigger is activated by actor of ClassProximityType only
    00019		TT_AnyProximity,    // Trigger is activated by any actor in proximity.
    00020		TT_Shoot,		    // Trigger is activated by player shooting it.
    00021	} TriggerType;
    00022
    00023	// Human readable triggering message.
    00024	var() localized string Message;
    00025
    00026	// Only trigger once and then go dormant.
    00027	var() bool bTriggerOnceOnly;
    00028
    00029	// For triggers that are activated/deactivated by other triggers.
    00030	var() bool bInitiallyActive;
    00031
    00032	var() class<actor> ClassProximityType;
    00033
    00034	var() float	RepeatTriggerTime; //if > 0, repeat trigger message at this interval is still touching other
    00035	var() float ReTriggerDelay; //minimum time before trigger can be triggered again
    00036	var	  float TriggerTime;
    00037	var() float DamageThreshold; //minimum damage to trigger if TT_Shoot
    00038
    00039	// AI vars
    00040	var	actor TriggerActor;	// actor that triggers this trigger
    00041	var actor TriggerActor2;
    00042
    00043	// store for reset
    00044
    00045	var bool bSavedInitialCollision;
    00046	var bool bSavedInitialActive;
    00047
    00048	//=============================================================================
    00049	// AI related functions
    00050
    00051	function PostBeginPlay()
    00052	{
    00053		if ( !bInitiallyActive )
    00054			FindTriggerActor();
    00055		if ( TriggerType == TT_Shoot )
    00056		{
    00057			bHidden = false;
    00058			bProjTarget = true;
    00059			SetDrawType(DT_None);
    00060		}
    00061
    00062		bSavedInitialActive = bInitiallyActive;
    00063		bSavedInitialCollision = bCollideActors;
    00064		Super.PostBeginPlay();
    00065	}
    00066
    00067	/* Reset()
    00068	reset actor to initial state - used when restarting level without reloading.
    00069	*/
    00070	function Reset()
    00071	{
    00072		Super.Reset();
    00073
    00074		// collision, bInitiallyactive
    00075		bInitiallyActive = bSavedInitialActive;
    00076		SetCollision(bSavedInitialCollision, bBlockActors, bBlockPlayers );
    00077	}
    00078
    00079
    00080	function FindTriggerActor()
    00081	{
    00082		local Actor A;
    00083
    00084		TriggerActor = None;
    00085		TriggerActor2 = None;
    00086		ForEach AllActors(class 'Actor', A)
    00087			if ( A.Event == Tag)
    00088			{
    00089				if ( A.IsA('Counter') )
    00090					return; //FIXME - handle counters
    00091				if (TriggerActor == None)
    00092					TriggerActor = A;
    00093				else
    00094				{
    00095					TriggerActor2 = A;
    00096					return;
    00097				}
    00098			}
    00099	}
    00100
    00101	function Actor SpecialHandling(Pawn Other)
    00102	{
    00103		local int i;
    00104		local Actor A;
    00105
    00106		if ( bTriggerOnceOnly && !bCollideActors )
    00107			return None;
    00108
    00109		if ( (TriggerType == TT_PlayerProximity) && !Other.IsPlayerPawn() )
    00110			return None;
    00111
    00112		if ( !bInitiallyActive )
    00113		{
    00114			if ( TriggerActor == None )
    00115				FindTriggerActor();
    00116			if ( TriggerActor == None )
    00117				return None;
    00118			if ( (TriggerActor2 != None)
    00119				&& (VSize(TriggerActor2.Location - Other.Location) < VSize(TriggerActor.Location - Other.Location)) )
    00120				return TriggerActor2;
    00121			else
    00122				return TriggerActor;
    00123		}
    00124
    00125		// is this a shootable trigger?
    00126		if ( TriggerType == TT_Shoot )
    00127			return Other.ShootSpecial(self);
    00128
    00129		// can other trigger it right away?
    00130		if ( IsRelevant(Other) )
    00131		{
    00132			ForEach TouchingActors(class'Actor', A)
    00133				if ( A == Other )
    00134					Touch(Other);
    00135			return self;
    00136		}
    00137
    00138		return self;
    00139	}
    00140
    00141	// when trigger gets turned on, check its touch list
    00142
    00143	function CheckTouchList()
    00144	{
    00145		local int i;
    00146		local Actor A;
    00147
    00148		ForEach TouchingActors(class'Actor', A)
    00149			Touch(A);
    00150	}
    00151
    00152	//=============================================================================
    00153	// Trigger states.
    00154
    00155	// Trigger is always active.
    00156	state() NormalTrigger
    00157	{
    00158	}
    00159
    00160	// Other trigger toggles this trigger's activity.
    00161	state() OtherTriggerToggles
    00162	{
    00163		function Trigger( actor Other, pawn EventInstigator )
    00164		{
    00165			bInitiallyActive = !bInitiallyActive;
    00166			if ( bInitiallyActive )
    00167				CheckTouchList();
    00168		}
    00169	}
    00170
    00171	// Other trigger turns this on.
    00172	state() OtherTriggerTurnsOn
    00173	{
    00174		function Trigger( actor Other, pawn EventInstigator )
    00175		{
    00176			local bool bWasActive;
    00177
    00178			bWasActive = bInitiallyActive;
    00179			bInitiallyActive = true;
    00180			if ( !bWasActive )
    00181				CheckTouchList();
    00182		}
    00183	}
    00184
    00185	// Other trigger turns this off.
    00186	state() OtherTriggerTurnsOff
    00187	{
    00188		function Trigger( actor Other, pawn EventInstigator )
    00189		{
    00190			bInitiallyActive = false;
    00191		}
    00192	}
    00193
    00194	//=============================================================================
    00195	// Trigger logic.
    00196
    00197	//
    00198	// See whether the other actor is relevant to this trigger.
    00199	//
    00200	function bool IsRelevant( actor Other )
    00201	{
    00202		if( !bInitiallyActive )
    00203			return false;
    00204		switch( TriggerType )
    00205		{
    00206			case TT_PlayerProximity:
    00207				return (Pawn(Other) != None) && Pawn(Other).IsPlayerPawn();
    00208			case TT_PawnProximity:
    00209				return (Pawn(Other) != None);
    00210			case TT_ClassProximity:
    00211				return ClassIsChildOf(Other.Class, ClassProximityType);
    00212			case TT_AnyProximity:
    00213				return true;
    00214			case TT_Shoot:
    00215				return ( (Projectile(Other) != None) && (Projectile(Other).Damage >= DamageThreshold) );
    00216		}
    00217	}
    00218	//
    00219	// Called when something touches the trigger.
    00220	//
    00221	function Touch( actor Other )
    00222	{
    00223		local int i;
    00224
    00225		if( IsRelevant( Other ) )
    00226		{
    00227			if ( ReTriggerDelay > 0 )
    00228			{
    00229				if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay )
    00230					return;
    00231				TriggerTime = Level.TimeSeconds;
    00232			}
    00233			// Broadcast the Trigger message to all matching actors.
    00234			TriggerEvent(Event, Other, Other.Instigator);
    00235
    00236			if ( (Pawn(Other) != None) && (Pawn(Other).Controller != None) )
    00237			{
    00238				for ( i=0;i<4;i++ )
    00239					if ( Pawn(Other).Controller.GoalList[i] == self )
    00240					{
    00241						Pawn(Other).Controller.GoalList[i] = None;
    00242						break;
    00243					}
    00244			}
    00245
00246 if( (Message != "") && (Other.Instigator != None) ) 00247 // Send a string message to the toucher. 00248 Other.Instigator.ClientMessage( Message ); 00249 00250 if( bTriggerOnceOnly ) 00251 // Ignore future touches. 00252 SetCollision(False); 00253 else if ( RepeatTriggerTime > 0 ) 00254 SetTimer(RepeatTriggerTime, false); 00255 } 00256 } 00257 00258 function Timer() 00259 { 00260 local bool bKeepTiming; 00261 local int i; 00262 local Actor A; 00263 00264 bKeepTiming = false; 00265 00266 ForEach TouchingActors(class'Actor', A) 00267 if ( IsRelevant(A) ) 00268 { 00269 bKeepTiming = true; 00270 Touch(A); 00271 } 00272 00273 if ( bKeepTiming ) 00274 SetTimer(RepeatTriggerTime, false); 00275 } 00276 00277 function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, 00278 Vector momentum, class<DamageType> damageType) 00279 { 00280 if ( bInitiallyActive && (TriggerType == TT_Shoot) && (Damage >= DamageThreshold) && (instigatedBy != None) ) 00281 { 00282 if ( ReTriggerDelay > 0 ) 00283 { 00284 if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay ) 00285 return; 00286 TriggerTime = Level.TimeSeconds; 00287 } 00288 // Broadcast the Trigger message to all matching actors. 00289 TriggerEvent(Event, instigatedBy, instigatedBy); 00290 00291 if( Message != "" ) 00292 // Send a string message to the toucher. 00293 instigatedBy.Instigator.ClientMessage( Message ); 00294 00295 if( bTriggerOnceOnly ) 00296 // Ignore future touches. 00297 SetCollision(False); 00298 } 00299 } 00300 00301 // 00302 // When something untouches the trigger. 00303 // 00304 function UnTouch( actor Other ) 00305 { 00306 if( IsRelevant( Other ) ) 00307 UntriggerEvent(event, Other, Other.Instigator); 00308 } 00309 00310 defaultproperties 00311 { 00312 bInitiallyActive=True 00313 InitialState="NormalTrigger" 00314 Texture=Texture'Engine.S_Trigger' 00315 }

End Source Code