Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.46 KB | None | 0 0
  1. #library "JASHIN"
  2. #include "zcommon.acs"
  3.  
  4. /*
  5.     user_chase_time = last Timer()
  6.     user_chase_x = x to move to
  7.     user_chase_y = y to move to
  8.     user_chase_z = z to move to
  9. */
  10.  
  11. script "Jashin::ChaseTarget" (void)
  12. {
  13.     int chase_speed = 15;
  14.  
  15.     int stored_tid = ActivatorTID();
  16.     int jashin_tid = UniqueTID();
  17.     Thing_ChangeTID(0, jashin_tid);
  18.     int jashin_x = GetActorX(0);
  19.     int jashin_y = GetActorY(0);
  20.     int jashin_z = GetActorZ(0);
  21.     int jashin_angle = GetActorAngle(0);
  22.    
  23.     if (!SetActivatorToTarget(0)) // target left.
  24.     {
  25.         Thing_ChangeTID(0, stored_tid);
  26.         SetActorState(0, "See");
  27.         terminate;
  28.     }
  29.    
  30.     int target_stored_tid = ActivatorTID();
  31.     int target_tid = UniqueTID();
  32.     Thing_ChangeTID(0, target_tid);
  33.     int target_x = GetActorX(0);
  34.     int target_y = GetActorY(0);
  35.     int target_z = GetActorZ(0);
  36.     bool target_sight = CheckSight(jashin_tid, target_tid, 0);
  37.    
  38.     int jashin_chase_time = GetUserVariable(jashin_tid, "user_chase_time");
  39.     int jashin_chase_x = GetUserVariable(jashin_tid, "user_chase_x")<<16;
  40.     int jashin_chase_y = GetUserVariable(jashin_tid, "user_chase_y")<<16;
  41.     int jashin_chase_z = GetUserVariable(jashin_tid, "user_chase_z")<<16;
  42.     if (!jashin_chase_time || Timer()-jashin_chase_time > chase_speed)
  43.     {
  44.         int chaser_tid = GetUserVariable(jashin_tid, "user_chase_tid");
  45.         if (!chaser_tid)
  46.         {
  47.             chaser_tid = UniqueTID();
  48.             if (!Spawn("JashinChaser", jashin_x, jashin_y, jashin_z, chaser_tid, jashin_angle))
  49.             {
  50.                 SetActivator(target_tid);
  51.                 Thing_ChangeTID(0, target_stored_tid);
  52.                 SetActivator(jashin_tid);
  53.                 Thing_ChangeTID(0, stored_tid);
  54.                 terminate;
  55.             }
  56.             //SetUserVariable(jashin_tid, "user_chase_tid", chaser_tid);
  57.         }
  58.        
  59.         SetActivator(chaser_tid);
  60.         SetPointer(AAPTR_TARGET, target_tid, AAPTR_DEFAULT, 0);
  61.         for (int i = 0; i <= chase_speed; i++) SetActorState(0, "DoChase");
  62.         jashin_chase_x = GetActorX(0);
  63.         jashin_chase_y = GetActorY(0);
  64.         jashin_chase_z = GetActorZ(0);
  65.         Thing_Remove(0);
  66.         SetActivator(target_tid);
  67.        
  68.         SetUserVariable(jashin_tid, "user_chase_time", Timer());
  69.         SetUserVariable(jashin_tid, "user_chase_x", jashin_chase_x>>16);
  70.         SetUserVariable(jashin_tid, "user_chase_y", jashin_chase_y>>16);
  71.         SetUserVariable(jashin_tid, "user_chase_z", jashin_chase_z>>16);
  72.        
  73.         //printbold(s:"newchase");
  74.     }
  75.    
  76.     SetActivator(target_tid);
  77.     Thing_ChangeTID(0, target_stored_tid);
  78.     SetActivator(jashin_tid);
  79.     Thing_ChangeTID(0, stored_tid);
  80.    
  81.     int mdx = jashin_chase_x-GetActorX(0);
  82.     int mdy = jashin_chase_y-GetActorY(0);
  83.     int mdz = jashin_chase_z-GetActorZ(0);
  84.     int mdlen = VectorLength(mdz, VectorLength(mdx, mdy));
  85.     mdx = FixedDiv(mdx, mdlen);
  86.     mdy = FixedDiv(mdy, mdlen);
  87.     mdz = FixedDiv(mdz, mdlen);
  88.    
  89.     //printbold(s:"moving to ", f:jashin_chase_x, c:',', f:jashin_chase_y, c:',', f:jashin_chase_z);
  90.     //printbold(s:"target is ", f:target_x, c:',', f:target_y, c:',', f:target_z);
  91.    
  92.     Warp(0, mdx, mdy, mdz, 0, WARPF_INTERPOLATE|WARPF_ABSOLUTEOFFSET);
  93.    
  94.     if (mdlen >= 2.0)
  95.     {
  96.         // calculate new angle too.
  97.         int oldang = GetActorAngle(0);
  98.         int reqang = VectorAngle(mdx, mdy);
  99.         int newang = (reqang-oldang);
  100.         if (newang > 0.5) newang = -(newang-0.5);
  101.         if (newang < -0.5) newang = (-newang)-0.5;
  102.         newang /= chase_speed;
  103.        
  104.         if ((oldang+newang > reqang && oldang < reqang) ||
  105.             (oldang+newang < reqang && oldang > reqang)) ChangeActorAngle(0, reqang, true);
  106.         else ChangeActorAngle(0, oldang+newang, true);
  107.     }
  108.    
  109.     if (target_sight && Random(0, 1024) < 8)
  110.     {
  111.         SetActorState(0, "Missile");
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement