home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Engine / Classes / Teleporter.uc < prev    next >
Text File  |  2003-06-23  |  8KB  |  286 lines

  1. ///=============================================================================
  2. // Teleports actors either between different teleporters within a level
  3. // or to matching teleporters on other levels, or to general Internet URLs.
  4. //=============================================================================
  5. class Teleporter extends SmallNavigationPoint
  6.     placeable
  7.     native;
  8.  
  9. #exec Texture Import File=Textures\Teleport.pcx Name=S_Teleport Mips=Off MASKED=1
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Teleporter URL can be one of the following forms:
  13. //
  14. // TeleporterName
  15. //        Teleports to a named teleporter in this level.
  16. //        if none, acts only as a teleporter destination
  17. //
  18. // LevelName/TeleporterName
  19. //     Teleports to a different level on this server.
  20. //
  21. // Unreal://Server.domain.com/LevelName/TeleporterName
  22. //     Teleports to a different server on the net.
  23. //
  24. var() string URL;
  25.  
  26. //-----------------------------------------------------------------------------
  27. // Product the user must have installed in order to enter the teleporter.
  28. var() name ProductRequired;
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Teleporter destination flags.
  32. var() bool    bChangesVelocity; // Set velocity to TargetVelocity.
  33. var() bool    bChangesYaw;      // Sets yaw to teleporter's Rotation.Yaw
  34. var() bool    bReversesX;       // Reverses X-component of velocity.
  35. var() bool    bReversesY;       // Reverses Y-component of velocity.
  36. var() bool    bReversesZ;       // Reverses Z-component of velocity.
  37.  
  38. // Teleporter flags
  39. var() bool      bEnabled;            // Teleporter is turned on;
  40.  
  41. //-----------------------------------------------------------------------------
  42. // Teleporter destination directions.
  43. var() vector  TargetVelocity;   // If bChangesVelocity, set target's velocity to this.
  44.  
  45. // AI related
  46. var Actor TriggerActor;        //used to tell AI how to trigger me
  47. var Actor TriggerActor2;
  48.  
  49. var float LastFired;
  50.  
  51. //-----------------------------------------------------------------------------
  52. // Teleporter destination functions.
  53.  
  54. replication
  55. {
  56.     reliable if( Role==ROLE_Authority )
  57.         bEnabled, URL;
  58.     reliable if ( bNetInitial && (Role == ROLE_Authority) )
  59.         bChangesVelocity, bChangesYaw, bReversesX, bReversesY, bReversesZ, TargetVelocity; 
  60. }
  61.  
  62. function PostBeginPlay()
  63. {
  64.     if (URL ~= "")
  65.         SetCollision(false, false, false); //destination only
  66.         
  67.     if ( !bEnabled )
  68.         FindTriggerActor();
  69.     Super.PostBeginPlay();
  70. }
  71.  
  72. function FindTriggerActor()
  73. {
  74.     local Actor A;
  75.  
  76.     TriggerActor = None;
  77.     TriggerActor2 = None;
  78.     ForEach DynamicActors(class 'Actor', A)
  79.         if ( A.Event == Tag)
  80.         {
  81.             if (TriggerActor == None)
  82.                 TriggerActor = A;
  83.             else
  84.             {
  85.                 TriggerActor2 = A;
  86.                 return;
  87.             }
  88.         }
  89. }
  90.  
  91. // Accept an actor that has teleported in.
  92. simulated function bool Accept( actor Incoming, Actor Source )
  93. {
  94.     local rotator newRot, oldRot;
  95.     local float mag;
  96.     local vector oldDir;
  97.     local Controller P;
  98.  
  99.     if ( Incoming == None )
  100.         return false;
  101.         
  102.     // Move the actor here.
  103.     Disable('Touch');
  104.     newRot = Incoming.Rotation;
  105.     if (bChangesYaw)
  106.     {
  107.         oldRot = Incoming.Rotation;
  108.         newRot.Yaw = Rotation.Yaw;
  109.         if ( Source != None )
  110.             newRot.Yaw += (32768 + Incoming.Rotation.Yaw - Source.Rotation.Yaw);
  111.     }
  112.  
  113.     if ( Pawn(Incoming) != None )
  114.     {
  115.         //tell enemies about teleport
  116.         if ( Role == ROLE_Authority )
  117.             For ( P=Level.ControllerList; P!=None; P=P.NextController )
  118.                 if ( P.Enemy == Incoming )
  119.                     P.LineOfSightTo(Incoming); 
  120.  
  121.         if ( !Pawn(Incoming).SetLocation(Location) )
  122.         {
  123.             log(self$" Teleport failed for "$Incoming);
  124.             return false;
  125.         }
  126.         if ( (Role == ROLE_Authority)
  127.             || (Level.TimeSeconds - LastFired > 0.5) )
  128.         {
  129.             newRot.Roll = 0;
  130.             Pawn(Incoming).SetRotation(newRot);
  131.             Pawn(Incoming).SetViewRotation(newRot);
  132.             Pawn(Incoming).ClientSetRotation(newRot);
  133.             LastFired = Level.TimeSeconds;
  134.         }
  135.         if ( Pawn(Incoming).Controller != None )
  136.         {
  137.             Pawn(Incoming).Controller.MoveTimer = -1.0;
  138.             Pawn(Incoming).Anchor = self;
  139.             Pawn(Incoming).SetMoveTarget(self);
  140.         }
  141.         Incoming.PlayTeleportEffect(false, true);
  142.     }
  143.     else
  144.     {
  145.         if ( !Incoming.SetLocation(Location) )
  146.         {
  147.             Enable('Touch');
  148.             return false;
  149.         }
  150.         if ( bChangesYaw )
  151.             Incoming.SetRotation(newRot);
  152.     }
  153.     Enable('Touch');
  154.  
  155.     if (bChangesVelocity)
  156.         Incoming.Velocity = TargetVelocity;
  157.     else
  158.     {
  159.         if ( bChangesYaw )
  160.         {
  161.             if ( Incoming.Physics == PHYS_Walking )
  162.                 OldRot.Pitch = 0;
  163.             oldDir = vector(OldRot);
  164.             mag = Incoming.Velocity Dot oldDir;        
  165.             Incoming.Velocity = Incoming.Velocity - mag * oldDir + mag * vector(Incoming.Rotation);
  166.         } 
  167.         if ( bReversesX )
  168.             Incoming.Velocity.X *= -1.0;
  169.         if ( bReversesY )
  170.             Incoming.Velocity.Y *= -1.0;
  171.         if ( bReversesZ )
  172.             Incoming.Velocity.Z *= -1.0;
  173.     }    
  174.     return true;
  175. }
  176.  
  177. //-----------------------------------------------------------------------------
  178. // Teleporter functions.
  179.  
  180. function Trigger( actor Other, pawn EventInstigator )
  181. {
  182.     local Actor A;
  183.  
  184.     bEnabled = !bEnabled;
  185.     if ( bEnabled ) //teleport any pawns already in my radius
  186.         ForEach TouchingActors(class'Actor', A)
  187.             PostTouch(A);
  188. }
  189.  
  190. event Touch(Actor Other)
  191. {
  192.     if ( !bEnabled || (Other == None) )
  193.         return;
  194.  
  195.     if( Other.bCanTeleport && Other.PreTeleport(Self)==false )
  196.     {
  197.         PendingTouch = Other.PendingTouch;
  198.         Other.PendingTouch = self;
  199.     }
  200. }
  201.  
  202. // Teleporter was touched by an actor.
  203. simulated function PostTouch( actor Other )
  204. {
  205.     local Teleporter D,Dest[16];
  206.     local int i;
  207.  
  208.         if( (InStr( URL, "/" ) >= 0) || (InStr( URL, "#" ) >= 0) )
  209.         {
  210.             // Teleport to a level on the net.
  211.             if( (Role == ROLE_Authority) && (Pawn(Other) != None)
  212.                 && Pawn(Other).IsHumanControlled() )
  213.                 Level.Game.SendPlayer(PlayerController(Pawn(Other).Controller), URL);
  214.         }
  215.         else
  216.         {
  217.             // Teleport to a random teleporter in this local level, if more than one pick random.
  218.  
  219.             foreach AllActors( class 'Teleporter', D )
  220.                 if( string(D.tag)~=URL && D!=Self )
  221.                 {
  222.                     Dest[i] = D;
  223.                     i++;
  224.                     if ( i > arraycount(Dest) )
  225.                         break;
  226.                 }
  227.  
  228.             i = rand(i);
  229.             if( Dest[i] != None )
  230.             {
  231.                 // Teleport the actor into the other teleporter.
  232.                 if ( Other.IsA('Pawn') )
  233.                     Other.PlayTeleportEffect(false, true);
  234.                 Dest[i].Accept( Other, self );
  235.                 if ( Pawn(Other) != None )
  236.                     TriggerEvent(Event, self, Pawn(Other));
  237.             }
  238.         }
  239.     }
  240.  
  241. /* SpecialHandling is called by the navigation code when the next path has been found.  
  242. It gives that path an opportunity to modify the result based on any special considerations
  243. */
  244.  
  245. function Actor SpecialHandling(Pawn Other)
  246. {
  247.     local vector Dist2D;
  248.     if ( bEnabled && (Teleporter(Other.Controller.RouteCache[1]) != None)
  249.         && (string(Other.Controller.RouteCache[1].tag)~=URL) )
  250.     {
  251.         if ( Abs(Location.Z - Other.Location.Z) < CollisionHeight + Other.CollisionHeight )
  252.         {
  253.             Dist2D = Location - Other.Location;
  254.             Dist2D.Z = 0;
  255.             if ( VSize(Dist2D) < CollisionRadius + Other.CollisionRadius )
  256.                 PostTouch(Other);
  257.         }    
  258.         return self;
  259.     }
  260.  
  261.     if (TriggerActor == None)
  262.     {
  263.         FindTriggerActor();
  264.         if (TriggerActor == None)
  265.             return None;
  266.     }
  267.  
  268.     if ( (TriggerActor2 != None) 
  269.         && (VSize(TriggerActor2.Location - Other.Location) < VSize(TriggerActor.Location - Other.Location)) )
  270.         return TriggerActor2;
  271.                     
  272.     return TriggerActor;            
  273. }    
  274.     
  275.  
  276. defaultproperties
  277. {
  278.      RemoteRole=ROLE_SimulatedProxy
  279.      bChangesYaw=true
  280.      bEnabled=True
  281.      bDirectional=True
  282.      SoundVolume=128
  283.      bCollideActors=True
  284.      Texture=S_Teleport
  285. }
  286.