Engine
Class Teleporter

source: e:\games\UnrealTournament\Engine\Classes\Teleporter.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.NavigationPoint
         |
         +--Engine.Teleporter
Direct Known Subclasses:VisibleTeleporter, FavoritesTeleporter

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 PlayTeleportEffect(Actor Incoming, bool bOut)
 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		native;
00007	
00008	#exec Texture Import File=Textures\Teleport.pcx Name=S_Teleport Mips=Off Flags=2
00009	
00010	//-----------------------------------------------------------------------------
00011	// Teleporter URL can be one of the following forms:
00012	//
00013	// TeleporterName
00014	//		Teleports to a named teleporter in this level.
00015	//		if none, acts only as a teleporter destination
00016	//
00017	// LevelName/TeleporterName
00018	//     Teleports to a different level on this server.
00019	//
00020	// Unreal://Server.domain.com/LevelName/TeleporterName
00021	//     Teleports to a different server on the net.
00022	//
00023	var() string URL;
00024	
00025	//-----------------------------------------------------------------------------
00026	// Product the user must have installed in order to enter the teleporter.
00027	var() name ProductRequired;
00028	
00029	//-----------------------------------------------------------------------------
00030	// Teleporter destination flags.
00031	var() bool    bChangesVelocity; // Set velocity to TargetVelocity.
00032	var() bool    bChangesYaw;      // Sets yaw to teleporter's Rotation.Yaw
00033	var() bool    bReversesX;       // Reverses X-component of velocity.
00034	var() bool    bReversesY;       // Reverses Y-component of velocity.
00035	var() bool    bReversesZ;       // Reverses Z-component of velocity.
00036	
00037	// Teleporter flags
00038	var() bool	  bEnabled;			// Teleporter is turned on;
00039	
00040	//-----------------------------------------------------------------------------
00041	// Teleporter destination directions.
00042	var() vector  TargetVelocity;   // If bChangesVelocity, set target's velocity to this.
00043	
00044	// AI related
00045	var Actor TriggerActor;		//used to tell AI how to trigger me
00046	var Actor TriggerActor2;
00047	
00048	var float LastFired;
00049	
00050	//-----------------------------------------------------------------------------
00051	// Teleporter destination functions.
00052	
00053	replication
00054	{
00055		reliable if( Role==ROLE_Authority )
00056			bEnabled, URL;
00057		reliable if ( bNetInitial && (Role == ROLE_Authority) )
00058			bChangesVelocity, bChangesYaw, bReversesX, bReversesY, bReversesZ, TargetVelocity; 
00059	}
00060	
00061	function PostBeginPlay()
00062	{
00063		if (URL ~= "")
00064			SetCollision(false, false, false); //destination only
00065			
00066		if ( !bEnabled )
00067			FindTriggerActor();
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	// Accept an actor that has teleported in.
00093	simulated function bool Accept( actor Incoming, Actor Source )
00094	{
00095		local rotator newRot, oldRot;
00096		local int oldYaw;
00097		local float mag;
00098		local vector oldDir;
00099		local pawn P;
00100	
00101		// Move the actor here.
00102		Disable('Touch');
00103		//log("Move Actor here "$tag);
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			{
00118				P = Level.PawnList;
00119				While ( P != None )
00120				{
00121					if (P.Enemy == Incoming)
00122						P.LastSeenPos = Incoming.Location; 
00123					P = P.nextPawn;
00124				}
00125			}
00126			Pawn(Incoming).SetLocation(Location);
00127			if ( (Role == ROLE_Authority) 
00128				|| (Level.TimeSeconds - LastFired > 0.5) )
00129			{
00130				Pawn(Incoming).SetRotation(newRot);
00131				Pawn(Incoming).ViewRotation = newRot;
00132				LastFired = Level.TimeSeconds;
00133			}
00134			Pawn(Incoming).MoveTimer = -1.0;
00135			Pawn(Incoming).MoveTarget = self;
00136			PlayTeleportEffect( Incoming, false);
00137		}
00138		else
00139		{
00140			if ( !Incoming.SetLocation(Location) )
00141			{
00142				Enable('Touch');
00143				return false;
00144			}
00145			if ( bChangesYaw )
00146				Incoming.SetRotation(newRot);
00147		}
00148	
00149		Enable('Touch');
00150	
00151		
00152		if (bChangesVelocity)
00153			Incoming.Velocity = TargetVelocity;
00154		else
00155		{
00156			if ( bChangesYaw )
00157			{
00158				if ( Incoming.Physics == PHYS_Walking )
00159					OldRot.Pitch = 0;
00160				oldDir = vector(OldRot);
00161				mag = Incoming.Velocity Dot oldDir;		
00162				Incoming.Velocity = Incoming.Velocity - mag * oldDir + mag * vector(Incoming.Rotation);
00163			} 
00164			if ( bReversesX )
00165				Incoming.Velocity.X *= -1.0;
00166			if ( bReversesY )
00167				Incoming.Velocity.Y *= -1.0;
00168			if ( bReversesZ )
00169				Incoming.Velocity.Z *= -1.0;
00170		}	
00171	
00172		// Play teleport-in effect.
00173	
00174		return true;
00175	}
00176		
00177	function PlayTeleportEffect(actor Incoming, bool bOut)
00178	{
00179		if ( Incoming.IsA('Pawn') )
00180		{
00181			Incoming.MakeNoise(1.0);
00182			Level.Game.PlayTeleportEffect(Incoming, bOut, true);
00183		}
00184	}
00185	
00186	//-----------------------------------------------------------------------------
00187	// Teleporter functions.
00188	
00189	function Trigger( actor Other, pawn EventInstigator )
00190	{
00191		local int i;
00192	
00193		bEnabled = !bEnabled;
00194		if ( bEnabled ) //teleport any pawns already in my radius
00195			for (i=0;i<4;i++)
00196				if ( Touching[i] != None )
00197					Touch(Touching[i]);
00198	}
00199	
00200	// Teleporter was touched by an actor.
00201	simulated function Touch( actor Other )
00202	{
00203		local Teleporter Dest;
00204		local int i;
00205		local Actor A;
00206		
00207		if ( !bEnabled )
00208			return;
00209	
00210		if( Other.bCanTeleport && Other.PreTeleport(Self)==false )
00211		{
00212			if( (InStr( URL, "/" ) >= 0) || (InStr( URL, "#" ) >= 0) )
00213			{
00214				// Teleport to a level on the net.
00215				if( (Role == ROLE_Authority) && (PlayerPawn(Other) != None) )
00216					Level.Game.SendPlayer(PlayerPawn(Other), URL);
00217			}
00218			else
00219			{
00220				// Teleport to a random teleporter in this local level, if more than one pick random.
00221	
00222				foreach AllActors( class 'Teleporter', Dest )
00223					if( string(Dest.tag)~=URL && Dest!=Self )
00224						i++;
00225				i = rand(i);
00226				foreach AllActors( class 'Teleporter', Dest )
00227					if( string(Dest.tag)~=URL && Dest!=Self && i-- == 0 )
00228						break;
00229				if( Dest != None )
00230				{
00231					// Teleport the actor into the other teleporter.
00232					if ( Other.IsA('Pawn') )
00233						PlayTeleportEffect( Pawn(Other), false);
00234					Dest.Accept( Other, self );
00235					if( (Event != '') && (Other.IsA('Pawn')) )
00236						foreach AllActors( class 'Actor', A, Event )
00237							A.Trigger( Other, Other.Instigator );
00238				}
00239				else if ( Role == ROLE_Authority )
00240					Pawn(Other).ClientMessage( "Teleport destination for "$self$" not found!" );
00241			}
00242		}
00243	}
00244	
00245	/* SpecialHandling is called by the navigation code when the next path has been found.  
00246	It gives that path an opportunity to modify the result based on any special considerations
00247	*/
00248	
00249	function Actor SpecialHandling(Pawn Other)
00250	{
00251		local int i;
00252		local vector Dist2D;
00253		if ( bEnabled && (Other.RouteCache[1] != None)
00254			&& Other.RouteCache[1].IsA('Teleporter') && (string(Other.RouteCache[1].tag)~=URL) )
00255		{
00256			if ( Abs(Location.Z - Other.Location.Z) < CollisionHeight + Other.CollisionHeight )
00257			{
00258				Dist2D = Location - Other.Location;
00259				Dist2D.Z = 0;
00260				if ( VSize(Dist2D) < CollisionRadius + Other.CollisionRadius )
00261					Touch(Other);
00262			}	
00263			return self;
00264		}
00265	
00266		if (TriggerActor == None)
00267		{
00268			FindTriggerActor();
00269			if (TriggerActor == None)
00270				return None;
00271		}
00272	
00273		if ( (TriggerActor2 != None) 
00274			&& (VSize(TriggerActor2.Location - Other.Location) < VSize(TriggerActor.Location - Other.Location)) )
00275			return TriggerActor2;
00276						
00277		return TriggerActor;			
00278	}	
00279		
00280	
00281	defaultproperties
00282	{
00283	     bChangesYaw=True
00284	     bEnabled=True
00285	     RemoteRole=ROLE_SimulatedProxy
00286	     bDirectional=True
00287	     Texture=Texture'Engine.S_Teleport'
00288	     SoundVolume=128
00289	     CollisionRadius=18.000000
00290	     CollisionHeight=40.000000
00291	     bCollideActors=True
00292	}

End Source Code