Engine
Class Trigger

source: c:\runehov\Engine\Classes\Trigger.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Triggers
         |
         +--Engine.Trigger
Direct Known Subclasses:ZoneTrigger, CineTrigger, DamageTrigger, DestroyTrigger, Lever, OrdersTrigger, Pump, SightTrigger, ZoneTemplateTrigger, ZoneVelocityTrigger

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, TT_Damage
 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
 float SightAngle
           RUNE: for TT_Sight, the angle on-screen before it is triggered
 float SightDistance
           RUNE: for TT_Sight, the distance before it is triggered (<=0 denotes infinite)
 Actor TriggerActor2
           RUNE: for TT_Sight, the angle on-screen before it is triggered
 bool bInitiallyActive
 bool bTriggerOnceOnly

States
Dormant

Function Summary
 void ChangedState()
     
// State of trigger changed, query bInitiallyActive to tell state
 void CheckTouchList()
     
// when trigger gets turned on, check its touch list
 void FindTriggerActor()
 void PostBeginPlay()
     
//=============================================================================
// AI related functions
 Actor SpecialHandling(Pawn Other)
 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.


State Dormant Function Summary
 void UnTouch(Actor Other)
     
//
// When something untouches the trigger.
//
 bool UseTrigger(Actor Other)
     
//
// Called when somethings uses trigger
//
 bool JointDamaged(int Damage, Pawn EventInstigator, vector HitLoc, vector Momentum, name DamageType, int joint)
     
//
// Called when something damages the trigger
//
 void Touch(Actor Other)
     
//
// Called when something touches the trigger.
//
 void Timer()
     
// Used for RepeatTrigger (only valid for TT_Touch)
 bool IsRelevant(Actor Other)
     
//
// See whether the other actor is relevant to this trigger.
//
 void UnTriggerAction(Actor Receiver, Actor Cause, Pawn EventInstigator)
     
//--------------------------------------------------------
//
// UnTriggerAction
//
// This is the action that happens to each receiver when I am un-triggered
// Override this for different trigger types
//--------------------------------------------------------
 void TriggerAction(Actor Receiver, Actor Cause, Pawn EventInstigator)
     
//--------------------------------------------------------
//
// TriggerAction
//
// This is the action that happens to each receiver when I am triggered
// Override this for different trigger types
//--------------------------------------------------------
 void Fired(Actor Other)
     
//--------------------------------------------------------
//
// Fired
//
// Happens when fired by any means (happens once per triggering)
//--------------------------------------------------------



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 Flags=2
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 that class only
00019		TT_AnyProximity,    // Trigger is activated by any actor in proximity.
00020		TT_Shoot,		    // Trigger is activated by player shooting it.
00021		TT_Damage,			// Trigger is activated by taking damage
00022		TT_Use,				// Trigger is activated by being used
00023		TT_Sight,			// RUNE: Trigger is activated when the player sees it (rendered)
00024	} TriggerType;
00025	
00026	// Human readable triggering message.
00027	var() localized string Message;
00028	
00029	// Only trigger once and then go dormant.
00030	var() bool bTriggerOnceOnly;
00031	
00032	// For triggers that are activated/deactivated by other triggers.
00033	var() bool bInitiallyActive;
00034	
00035	var() class<actor> ClassProximityType;
00036	
00037	var() float	RepeatTriggerTime; //if > 0, repeat trigger message at this interval is still touching other
00038	var() float ReTriggerDelay; //minimum time before trigger can be triggered again
00039	var	  float TriggerTime;
00040	var() float DamageThreshold; //minimum damage to trigger if TT_Shoot, TT_Damage
00041	
00042	var() float	SightDistance;	// RUNE: for TT_Sight, the distance before it is triggered (<=0 denotes infinite)
00043	var() float SightAngle;		// RUNE: for TT_Sight, the angle on-screen before it is triggered
00044	
00045	// AI vars
00046	var	actor TriggerActor;	// actor that triggers this trigger
00047	var actor TriggerActor2;
00048	
00049	//=============================================================================
00050	// AI related functions
00051	
00052	function PostBeginPlay()
00053	{
00054		if ( !bInitiallyActive )
00055			FindTriggerActor();
00056		if ( TriggerType == TT_Shoot )
00057		{
00058			bHidden = false;
00059			bProjTarget = true;
00060			DrawType = DT_None;
00061		}
00062		
00063		if(TriggerType == TT_Damage)
00064		{
00065			 bSweepable = True;
00066		}
00067			
00068		Super.PostBeginPlay();
00069	}
00070	
00071	function FindTriggerActor()
00072	{
00073		local Actor A;
00074	
00075		TriggerActor = None;
00076		TriggerActor2 = None;
00077		ForEach AllActors(class 'Actor', A)
00078			if ( A.Event == Tag)
00079			{
00080				if ( Counter(A) != None )
00081					return; //FIXME - handle counters
00082				if (TriggerActor == None)
00083					TriggerActor = A;
00084				else
00085				{
00086					TriggerActor2 = A;
00087					return;
00088				}
00089			}
00090	}
00091	
00092	function Actor SpecialHandling(Pawn Other)
00093	{
00094		local int i;
00095	
00096		if ( bTriggerOnceOnly && !bCollideActors )
00097			return None;
00098	
00099		if ( (TriggerType == TT_PlayerProximity) && !Other.bIsPlayer )
00100			return None;
00101	
00102		if ( !bInitiallyActive )
00103		{
00104			if ( TriggerActor == None )
00105				FindTriggerActor();
00106			if ( TriggerActor == None )
00107				return None;
00108			if ( (TriggerActor2 != None) 
00109				&& (VSize(TriggerActor2.Location - Other.Location) < VSize(TriggerActor.Location - Other.Location)) )
00110				return TriggerActor2;
00111			else
00112				return TriggerActor;
00113		}
00114	
00115		// is this a shootable trigger?
00116		if ( TriggerType == TT_Shoot || TriggerType == TT_Damage)
00117		{
00118			if ( !Other.bCanDoSpecial || (Other.Weapon == None) )
00119				return None;
00120	
00121			Other.Target = self;
00122			Other.bShootSpecial = true;
00123	//		Other.FireWeapon();
00124			Other.bFire = 0;
00125			Other.bAltFire = 0;
00126			return Other;
00127		}
00128	
00129		// can other trigger it right away?
00130		if ( IsRelevant(Other) )
00131		{
00132			for (i=0;i<4;i++)
00133				if (Touching[i] == 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	
00147		for (i=0;i<4;i++)
00148			if ( Touching[i] != None )
00149				Touch(Touching[i]);
00150	}
00151	
00152	// State of trigger changed, query bInitiallyActive to tell state
00153	function ChangedState()
00154	{
00155	}
00156	
00157	
00158	//=============================================================================
00159	// Trigger states.
00160	
00161	// Trigger is always active.
00162	state() NormalTrigger
00163	{
00164	}
00165	
00166	// Other trigger toggles this trigger's activity.
00167	state() OtherTriggerToggles
00168	{
00169		function Trigger( actor Other, pawn EventInstigator )
00170		{
00171			bInitiallyActive = !bInitiallyActive;
00172			ChangedState();
00173			if ( bInitiallyActive )
00174				CheckTouchList();
00175		}
00176	}
00177	
00178	// Other trigger turns this on.
00179	state() OtherTriggerTurnsOn
00180	{
00181		function Trigger( actor Other, pawn EventInstigator )
00182		{
00183			local bool bWasActive;
00184	
00185			bWasActive = bInitiallyActive;
00186			bInitiallyActive = true;
00187			ChangedState();
00188			if ( !bWasActive )
00189				CheckTouchList();
00190		}
00191	}
00192	
00193	// Other trigger turns this off.
00194	state() OtherTriggerTurnsOff
00195	{
00196		function Trigger( actor Other, pawn EventInstigator )
00197		{
00198			bInitiallyActive = false;
00199			ChangedState();
00200		}
00201	}
00202	
00203	state Dormant
00204	{
00205		ignores Touch, UnTouch, Timer, JointDamaged, Trigger, UseTrigger;
00206	}
00207	
00208	
00209	//=============================================================================
00210	// Trigger logic.
00211	
00212	
00213	//--------------------------------------------------------
00214	//
00215	// Fired
00216	//
00217	// Happens when fired by any means (happens once per triggering)
00218	//--------------------------------------------------------
00219	function Fired(actor Other)
00220	{
00221	}
00222	
00223	
00224	//--------------------------------------------------------
00225	//
00226	// TriggerAction
00227	//
00228	// This is the action that happens to each receiver when I am triggered
00229	// Override this for different trigger types
00230	//--------------------------------------------------------
00231	function TriggerAction(actor Receiver, actor Cause, Pawn EventInstigator)
00232	{
00233		Receiver.Trigger(Cause, EventInstigator);
00234	}
00235	
00236	
00237	//--------------------------------------------------------
00238	//
00239	// UnTriggerAction
00240	//
00241	// This is the action that happens to each receiver when I am un-triggered
00242	// Override this for different trigger types
00243	//--------------------------------------------------------
00244	function UnTriggerAction(actor Receiver, actor Cause, Pawn EventInstigator)
00245	{
00246		Receiver.UnTrigger( Cause, EventInstigator );
00247	}
00248	
00249	
00250	//
00251	// See whether the other actor is relevant to this trigger.
00252	//
00253	function bool IsRelevant( actor Other )
00254	{
00255		if( !bInitiallyActive )
00256			return false;
00257		switch( TriggerType )
00258		{
00259			case TT_PlayerProximity:
00260				return Pawn(Other)!=None && Pawn(Other).bIsPlayer;
00261			case TT_PawnProximity:
00262				return Pawn(Other)!=None && ( Pawn(Other).Intelligence > BRAINS_None );
00263			case TT_ClassProximity:
00264				return ClassIsChildOf(Other.Class, ClassProximityType);
00265			case TT_AnyProximity:
00266				return true;
00267			case TT_Shoot:
00268				return ( (Projectile(Other) != None) && (Projectile(Other).Damage >= DamageThreshold) );
00269			case TT_Damage:
00270				return false;
00271			case TT_Use:
00272				return false;
00273			case TT_Sight:
00274				return Pawn(Other)!=None && Pawn(Other).bIsPlayer;
00275		}
00276	}
00277	
00278	
00279	
00280	//=============================================================================
00281	// Stimuli
00282	
00283	// Used for RepeatTrigger (only valid for TT_Touch)
00284	function Timer()
00285	{
00286		local bool bKeepTiming;
00287		local int i;
00288	
00289		bKeepTiming = false;
00290	
00291		for (i=0;i<4;i++)
00292			if ( (Touching[i] != None) && IsRelevant(Touching[i]) )
00293			{
00294				bKeepTiming = true;
00295				Touch(Touching[i]);
00296			}
00297	
00298		if ( bKeepTiming )
00299			SetTimer(RepeatTriggerTime, false);
00300	}
00301	
00302	
00303	//
00304	// Called when something touches the trigger.
00305	//
00306	function Touch( actor Other )
00307	{
00308		local actor A;
00309		if( IsRelevant( Other ) )
00310		{
00311			if ( ReTriggerDelay > 0 )
00312			{
00313				if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay )
00314					return;
00315				TriggerTime = Level.TimeSeconds;
00316			}
00317			Fired(Other);
00318			// Broadcast the Trigger message to all matching actors.
00319			if( Event != '' )
00320				foreach AllActors( class 'Actor', A, Event )
00321					TriggerAction(A, Other, Other.Instigator);
00322	
00323			if ( Other.IsA('Pawn') && (Pawn(Other).SpecialGoal == self) )
00324				Pawn(Other).SpecialGoal = None;
00325					
00326			if( Message != "" )
00327				// Send a string message to the toucher.
00328				Other.Instigator.ClientMessage( Message );
00329	
00330			if( bTriggerOnceOnly )
00331				// Ignore future touches.
00332				SetCollision(False);
00333			else if ( RepeatTriggerTime > 0 )
00334				SetTimer(RepeatTriggerTime, false);
00335		}
00336	}
00337	
00338	//
00339	// Called when something damages the trigger
00340	//
00341	function bool JointDamaged(int Damage, Pawn EventInstigator, vector HitLoc, vector Momentum, name DamageType, int joint)
00342	{
00343		local actor A;
00344	
00345		if ( bInitiallyActive && (TriggerType==TT_Shoot || TriggerType==TT_Damage) && (Damage >= DamageThreshold) && (EventInstigator != None) )
00346		{
00347			if ( ReTriggerDelay > 0 )
00348			{
00349				if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay )
00350					return true;
00351				TriggerTime = Level.TimeSeconds;
00352			}
00353			Fired(EventInstigator);
00354			// Broadcast the Trigger message to all matching actors.
00355			if( Event != '' )
00356				foreach AllActors( class 'Actor', A, Event )
00357					TriggerAction(A, EventInstigator, EventInstigator);
00358	
00359			if( Message != "" )
00360				// Send a string message to the toucher.
00361				EventInstigator.Instigator.ClientMessage( Message );
00362	
00363			if( bTriggerOnceOnly )
00364				// Ignore future touches.
00365				SetCollision(False);
00366		}
00367		return true;
00368	}
00369	
00370	
00371	//
00372	// Called when somethings uses trigger
00373	//
00374	function bool UseTrigger(actor Other)
00375	{
00376		local actor A;
00377		
00378		if(Other == None)
00379			return(false);
00380	
00381		if (bInitiallyActive && TriggerType == TT_Use)
00382		{
00383			if ( ReTriggerDelay > 0 )
00384			{
00385				if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay )
00386					return false;
00387				TriggerTime = Level.TimeSeconds;
00388			}
00389			Fired(Other);
00390			// Broadcast the Trigger message to all matching actors.
00391			if( Event != '' )
00392				foreach AllActors( class 'Actor', A, Event )
00393					TriggerAction(A, Other, Other.Instigator);
00394	
00395			if ( Other.IsA('Pawn') && (Pawn(Other).SpecialGoal == self) )
00396				Pawn(Other).SpecialGoal = None;
00397					
00398			if( Message != "" && Other.Instigator != None)
00399				// Send a string message to the toucher.
00400				Other.Instigator.ClientMessage( Message );
00401	
00402			if( bTriggerOnceOnly )	// Ignore future stimuli
00403				GotoState('Dormant');
00404	
00405			return true;
00406		}
00407		return false;
00408	}
00409	
00410	
00411	//
00412	// When something untouches the trigger.
00413	//
00414	function UnTouch( actor Other )
00415	{
00416		local actor A;
00417		if( IsRelevant( Other ) )
00418		{
00419			// Untrigger all matching actors.
00420			if( Event != '' )
00421				foreach AllActors( class 'Actor', A, Event )
00422					UntriggerAction(A, Other, Other.Instigator);
00423		}
00424	}
00425	
00426	defaultproperties
00427	{
00428	     bInitiallyActive=True
00429	     InitialState=NormalTrigger
00430	     Texture=Texture'Engine.S_Trigger'
00431	}

End Source Code