Engine
Class Teleporter

source: C:\XIII\Engine\Classes\Teleporter.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.NavigationPoint
         |
         +--Engine.Teleporter
Direct Known Subclasses:None

class Teleporter
extends Engine.NavigationPoint

///============================================================================= // Teleports actors either between different teleporters within a level // or to matching teleporters on other levels, or to general Internet URLs. //=============================================================================
Variables
 float LastFired
           used to tell AI how to trigger me
 name ProductRequired
 vector TargetVelocity
           If bChangesVelocity, set target's velocity to this.
 Actor TriggerActor
           used to tell AI how to trigger me
 Actor TriggerActor2
           used to tell AI how to trigger me
 string URL
 bool bChangesVelocity
           Set velocity to TargetVelocity.
 bool bChangesYaw
           Sets yaw to teleporter's Rotation.Yaw
 bool bEnabled
           Teleporter is turned on;
 bool bReversesX
           Reverses X-component of velocity.
 bool bReversesY
           Reverses Y-component of velocity.
 bool bReversesZ
           Reverses Z-component of velocity.


Function Summary
 bool Accept(Actor Incoming, Actor Source)
     
// Accept an actor that has teleported in.
 void FindTriggerActor()
 void PostBeginPlay()
 Actor SpecialHandling(Pawn Other)
     
/* SpecialHandling is called by the navigation code when the next path has been found.  
It gives that path an opportunity to modify the result based on any special considerations
*/
 
simulated
Touch(Actor Other)
     
// Teleporter was touched by an actor.
 void Trigger(Actor Other, Pawn EventInstigator)
     
//-----------------------------------------------------------------------------
// Teleporter functions.



Source Code


00001	///=============================================================================
00002	// Teleports actors either between different teleporters within a level
00003	// or to matching teleporters on other levels, or to general Internet URLs.
00004	//=============================================================================
00005	class Teleporter extends NavigationPoint
00006		placeable
00007		native;
00008	
00009	#exec Texture Import File=Textures\Teleport.pcx Name=S_Teleport Mips=Off MASKED=1 COMPRESS=DXT1
00010	
00011	//-----------------------------------------------------------------------------
00012	// Teleporter URL can be one of the following forms:
00013	//
00014	// TeleporterName
00015	//		Teleports to a named teleporter in this level.
00016	//		if none, acts only as a teleporter destination
00017	//
00018	// LevelName/TeleporterName
00019	//     Teleports to a different level on this server.
00020	//
00021	// Unreal://Server.domain.com/LevelName/TeleporterName
00022	//     Teleports to a different server on the net.
00023	//
00024	var() string URL;
00025	
00026	//-----------------------------------------------------------------------------
00027	// Product the user must have installed in order to enter the teleporter.
00028	var() name ProductRequired;
00029	
00030	//-----------------------------------------------------------------------------
00031	// Teleporter destination flags.
00032	var() bool    bChangesVelocity; // Set velocity to TargetVelocity.
00033	var() bool    bChangesYaw;      // Sets yaw to teleporter's Rotation.Yaw
00034	var() bool    bReversesX;       // Reverses X-component of velocity.
00035	var() bool    bReversesY;       // Reverses Y-component of velocity.
00036	var() bool    bReversesZ;       // Reverses Z-component of velocity.
00037	
00038	// Teleporter flags
00039	var() bool	  bEnabled;			// Teleporter is turned on;
00040	
00041	//-----------------------------------------------------------------------------
00042	// Teleporter destination directions.
00043	var() vector  TargetVelocity;   // If bChangesVelocity, set target's velocity to this.
00044	
00045	// AI related
00046	var Actor TriggerActor;		//used to tell AI how to trigger me
00047	var Actor TriggerActor2;
00048	
00049	var float LastFired;
00050	
00051	//-----------------------------------------------------------------------------
00052	// Teleporter destination functions.
00053	
00054	replication
00055	{
00056		reliable if( Role==ROLE_Authority )
00057			bEnabled, URL;
00058		reliable if ( bNetInitial && (Role == ROLE_Authority) )
00059			bChangesVelocity, bChangesYaw, bReversesX, bReversesY, bReversesZ, TargetVelocity; 
00060	}
00061	
00062	function PostBeginPlay()
00063	{
00064		if (URL ~= "")
00065			SetCollision(false, false, false); //destination only
00066			
00067		if ( !bEnabled )
00068			FindTriggerActor();
00069		Super.PostBeginPlay();
00070	}
00071	
00072	function FindTriggerActor()
00073	{
00074		local Actor A;
00075	
00076		TriggerActor = None;
00077		TriggerActor2 = None;
00078		ForEach DynamicActors(class 'Actor', A)
00079			if ( A.Event == Tag)
00080			{
00081				if ( A.IsA('Counter') )
00082					return; //FIXME - handle counters
00083				if (TriggerActor == None)
00084					TriggerActor = A;
00085				else
00086				{
00087					TriggerActor2 = A;
00088					return;
00089				}
00090			}
00091	}
00092	
00093	// Accept an actor that has teleported in.
00094	simulated function bool Accept( actor Incoming, Actor Source )
00095	{
00096		local rotator newRot, OldRot;
00097		local int oldYaw;
00098		local float mag;
00099		local vector oldDir;
00100		local Controller P;
00101	
00102		// Move the actor here.
00103		Disable('Touch');
00104		newRot = Incoming.Rotation;
00105		if (bChangesYaw)
00106		{
00107			OldRot = Incoming.Rotation;
00108			newRot.Yaw = Rotation.Yaw;
00109			if ( Source != None )
00110				newRot.Yaw += (32768 + Incoming.Rotation.Yaw - Source.Rotation.Yaw);
00111		}
00112	
00113		if ( Pawn(Incoming) != None )
00114		{
00115			//tell enemies about teleport
00116			if ( Role == ROLE_Authority )
00117				For ( P=Level.ControllerList; P!=None; P=P.NextController )
00118					if (P.Enemy == Incoming)
00119						P.LastSeenPos = Incoming.Location; 
00120	
00121			Pawn(Incoming).SetLocation(Location);
00122			if ( (Role == ROLE_Authority) 
00123				|| (Level.TimeSeconds - LastFired > 0.5) )
00124			{
00125				Pawn(Incoming).SetRotation(newRot);
00126				Pawn(Incoming).SetViewRotation(newRot);
00127				LastFired = Level.TimeSeconds;
00128			}
00129			if ( Pawn(Incoming).Controller != None )
00130			{
00131				Pawn(Incoming).Controller.MoveTimer = -1.0;
00132				Pawn(Incoming).SetMoveTarget(self);
00133			}
00134			Level.Game.PlayTeleportEffect( Incoming, false, true);
00135		}
00136		else
00137		{
00138			if ( !Incoming.SetLocation(Location) )
00139			{
00140				Enable('Touch');
00141				return false;
00142			}
00143			if ( bChangesYaw )
00144				Incoming.SetRotation(newRot);
00145		}
00146		Enable('Touch');
00147	
00148		
00149		if (bChangesVelocity)
00150			Incoming.Velocity = TargetVelocity;
00151		else
00152		{
00153			if ( bChangesYaw )
00154			{
00155				if ( Incoming.Physics == PHYS_Walking )
00156					OldRot.Pitch = 0;
00157				oldDir = vector(OldRot);
00158				mag = Incoming.Velocity Dot oldDir;		
00159				Incoming.Velocity = Incoming.Velocity - mag * oldDir + mag * vector(Incoming.Rotation);
00160			} 
00161			if ( bReversesX )
00162				Incoming.Velocity.X *= -1.0;
00163			if ( bReversesY )
00164				Incoming.Velocity.Y *= -1.0;
00165			if ( bReversesZ )
00166				Incoming.Velocity.Z *= -1.0;
00167		}	
00168	
00169		// Play teleport-in effect.
00170	
00171		return true;
00172	}
00173	
00174	//-----------------------------------------------------------------------------
00175	// Teleporter functions.
00176	
00177	function Trigger( actor Other, pawn EventInstigator )
00178	{
00179		local Actor A;
00180	
00181		bEnabled = !bEnabled;
00182		if ( bEnabled ) //teleport any pawns already in my radius
00183			ForEach TouchingActors(class'Actor', A)
00184				Touch(A);
00185	}
00186	
00187	// Teleporter was touched by an actor.
00188	simulated function Touch( actor Other )
00189	{
00190		local Teleporter D,Dest[16];
00191		local int i;
00192		
00193		if ( !bEnabled )
00194			return;
00195	
00196		if( Other.bCanTeleport && Other.PreTeleport(Self)==false )
00197		{
00198			if( (InStr( URL, "/" ) >= 0) || (InStr( URL, "#" ) >= 0) )
00199			{
00200				// Teleport to a level on the net.
00201				if( (Role == ROLE_Authority) && (Pawn(Other) != None)
00202					&& Pawn(Other).IsHumanControlled() )
00203					Level.Game.SendPlayer(PlayerController(Pawn(Other).Controller), URL);
00204			}
00205			else
00206			{
00207				// Teleport to a random teleporter in this local level, if more than one pick random.
00208	
00209				foreach AllActors( class 'Teleporter', D )
00210					if( string(D.tag)~=URL && D!=Self )
00211					{
00212						Dest[i] = D;
00213						i++;
00214						if ( i > arraycount(Dest) )
00215							break;
00216					}
00217	
00218				i = rand(i);
00219				if( Dest[i] != None )
00220				{
00221					// Teleport the actor into the other teleporter.
00222					if ( Other.IsA('Pawn') )
00223						Level.Game.PlayTeleportEffect( Pawn(Other), false, true);
00224					Dest[i].Accept( Other, self );
00225					if ( Pawn(Other) != None )
00226						TriggerEvent(Event, self, Pawn(Other));
00227				}
00228			}
00229		}
00230	}
00231	
00232	/* SpecialHandling is called by the navigation code when the next path has been found.  
00233	It gives that path an opportunity to modify the result based on any special considerations
00234	*/
00235	
00236	function Actor SpecialHandling(Pawn Other)
00237	{
00238		local int i;
00239		local vector Dist2D;
00240		if ( bEnabled && (Teleporter(Other.Controller.RouteCache[1]) != None)
00241			&& (string(Other.Controller.RouteCache[1].tag)~=URL) )
00242		{
00243			if ( Abs(Location.Z - Other.Location.Z) < CollisionHeight + Other.CollisionHeight )
00244			{
00245				Dist2D = Location - Other.Location;
00246				Dist2D.Z = 0;
00247				if ( VSize(Dist2D) < CollisionRadius + Other.CollisionRadius )
00248					Touch(Other);
00249			}	
00250			return self;
00251		}
00252	
00253		if (TriggerActor == None)
00254		{
00255			FindTriggerActor();
00256			if (TriggerActor == None)
00257				return None;
00258		}
00259	
00260		if ( (TriggerActor2 != None) 
00261			&& (VSize(TriggerActor2.Location - Other.Location) < VSize(TriggerActor.Location - Other.Location)) )
00262			return TriggerActor2;
00263						
00264		return TriggerActor;			
00265	}	
00266		
00267	
00268	defaultproperties
00269	{
00270	     bChangesYaw=True
00271	     bEnabled=True
00272	     bCollideActors=True
00273	     RemoteRole=ROLE_SimulatedProxy
00274	     Texture=Texture'Engine.S_Teleport'
00275	     CollisionRadius=40.000000
00276	     CollisionHeight=80.000000
00277	     bDirectional=True
00278	}

End Source Code