Guest User

Untitled

a guest
Sep 6th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function vector CheckTeleportConditions(float Dist, int TeleportationMethod)
  2. {
  3.    local NavigationPoint N;
  4.    local vector ViewPoint, Best;
  5.    local Rotator Rot;
  6.     local float Rating, NewRating;
  7.     local Vector HitLocation, HitNormal, EndTrace;
  8.    local Actor jActor;
  9.    
  10.    local int i, NumberOfIterations;
  11.  
  12.    local int TeleportDistNum;
  13.    TeleportDistNum = 1024;
  14.  
  15.     Switch(TeleportationMethod)
  16.     {
  17.       /*
  18.       //Teleports really close to enemy
  19.       */
  20.       Case(0) :
  21.             if (Dist < TeleportDistNum || Controller.Enemy == None)
  22.                 return vect(0,0,0);
  23.  
  24.             Rot = Controller.Enemy.Rotation;
  25.  
  26.          NumberOfIterations = 4;
  27.          for (i = 0; i <= NumberOfIterations; i++)
  28.          {
  29.             Rot.Yaw += Rand(32768) + 16384*i; //Randomly teleport around the enemy
  30.             EndTrace = Controller.Enemy.Location + vector(Rot) * Clamp(GroundSpeed, 96, 256);
  31.             Trace(HitLocation, HitNormal, EndTrace, Controller.Enemy.Location);
  32.  
  33.             //Do a FastTrace here to make sure we have some world geometry below us to hit.
  34.             if (!FastTrace((HitLocation+vect(0,0,-10240)),HitLocation) )
  35.                continue;
  36.                else
  37.                {
  38.                   if (!bool(HitLocation))
  39.                      HitLocation = EndTrace;
  40.                   HitLocation.Z += CollisionHeight * 0.5;
  41.                   return HitLocation;
  42.                   break;
  43.                }
  44.          }
  45.       /*
  46.       //Teleport to midpoint between enemy and self
  47.       */
  48.       Case(1) :
  49.             if (Dist < TeleportDistNum || Controller.Enemy == None)
  50.                 return vect(0,0,0);
  51.  
  52.             Rot = Rotation;
  53.  
  54.          NumberOfIterations = 4;
  55.             for (i = 0; i <= NumberOfIterations; i++)
  56.          {
  57.             Rot.Yaw += Rand(8192) + 16384*i; //Randomly teleport around the enemy
  58.             EndTrace = Location + Controller.Enemy.Location;
  59.             EndTrace *= 0.5;
  60.             EndTrace = Location + vector(Rot) * VSize(EndTrace - Location);
  61.             Trace(HitLocation, HitNormal, EndTrace, Controller.Enemy.Location);
  62.  
  63.             //Do a FastTrace here to make sure we have some world geometry below us to hit.
  64.             if (!FastTrace((HitLocation+vect(0,0,-10240)),HitLocation) )
  65.                continue;
  66.                else
  67.                {
  68.                   if (!bool(HitLocation))
  69.                      HitLocation = EndTrace;
  70.                   HitLocation.Z += CollisionHeight * 0.5;
  71.                   return HitLocation;
  72.                   break;
  73.                }
  74.          }
  75.  
  76.       /*
  77.       //Teleport to a more distance location between enemy and self
  78.       */
  79.         Case(2) :
  80.             if (Dist > TeleportDistNum || Controller.Enemy == None)
  81.                 return vect(0,0,0);
  82.  
  83.             Rot = Rotation;
  84.  
  85.          NumberOfIterations = 4;
  86.             for (i = 0; i <= NumberOfIterations; i++)
  87.          {
  88.             Rot.Yaw += Rand(8192) + 16384*i; //Randomly teleport around the enemy
  89.             EndTrace = Location + Controller.Enemy.Location;
  90.             EndTrace *= 2.0;
  91.             EndTrace = Location + vector(Rot) * VSize(EndTrace - Location);
  92.             Trace(HitLocation, HitNormal, EndTrace, Controller.Enemy.Location);
  93.  
  94.             //Do a FastTrace here to make sure we have some world geometry below us to hit.
  95.             if (!FastTrace((HitLocation+vect(0,0,-10240)),HitLocation) )
  96.                continue;
  97.                else
  98.                {
  99.                   if (!bool(HitLocation))
  100.                      HitLocation = EndTrace;
  101.                   HitLocation.Z += CollisionHeight * 0.5;
  102.                   return HitLocation;
  103.                   break;
  104.                }
  105.          }
  106.            
  107.         /*
  108.         //Teleport away from enemy using navigation points, set this as default in case we don't return from any of the
  109.         */
  110.         default :
  111.             if (Dist > TeleportDistNum || Controller.Enemy == None)
  112.                 return vect(0,0,0);
  113.  
  114.             Best = Location;
  115.             Rating = 0;
  116.  
  117.             for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint )
  118.             {
  119.                 NewRating = 0;
  120.  
  121.                 ViewPoint = N.Location + vect(0,0,1)*CollisionHeight/2;
  122.                 if (VSize(ViewPoint - Location) > TeleportDistNum * 3 || !LineOfSightTo(N))
  123.                     NewRating -= 200000; //can't see player don't bother with this one
  124.                 NewRating += VSize(N.Location - Controller.Enemy.Location) + 1000 * FRand();
  125.                 foreach N.VisibleCollidingActors(class'Actor',jActor,CollisionRadius,ViewPoint)
  126.                     NewRating -= 30000;
  127.  
  128.                 if ( NewRating > Rating )
  129.                 {
  130.                     Rating = NewRating;
  131.                     Best = N.Location;
  132.                 }
  133.          }
  134.          if (Best == Location)
  135.             return Vect(0,0,0);
  136.          else
  137.                 return Best;
  138.     }
  139.     return vect(0,0,0);
  140. }
Add Comment
Please, Sign In to add comment