Advertisement
Guest User

oascnacn

a guest
Oct 4th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #library "ORBITER"
  2. #include "zcommon.acs"
  3.  
  4. function int sqrtx(int param) {
  5.     int slider = 0.0;
  6.     int range = 128.0;
  7.     while (range > 0.0) {
  8.         slider += range;
  9.         if (FixedMul(slider, slider) > param) {
  10.             slider -= range;
  11.         }
  12.         range >>= 1;
  13.     }
  14.     return slider;
  15. }
  16.  
  17. #define ORBIT_RANDOMSCALE 0
  18. #define ORBIT_ORBITERCLASS 1
  19. #define ORBIT_ORBITERDEATHCLASS 2
  20. #define ORBIT_STOPTRIGGER 3
  21. #define ORBIT_RADIUSMIN 4
  22. #define ORBIT_RADIUSMAX 5
  23. #define ORBIT_ELLIPSISMIN 6
  24. #define ORBIT_TORQUE 7
  25. #define ORBIT_DEATHSPEEDMUL 8
  26. #define ORBIT_DEATHANGLEFIX 9
  27. #define ORBIT_ALL 10
  28.  
  29. //100.0 - Random radius (bigger - better quality, but risk of blowing up)
  30. //Circler - What orbits around actor
  31. //Rocket - What object spawns during death, anything beginning with $ will not spawn
  32. //IAmGonnaDie - Death trigger
  33. //70.0, 90.0 - Random for radius
  34. //0.7 - if it's 1.0, then we get circle, otherwise it's ellipsis (random)
  35. //0.03 - orbiting speed
  36.  
  37. //1st 0.25 - Object spawn speed when it stops orbiting
  38. //2nd 0.25 - Angle control after orbiting ends
  39. //only active if orbiterdeathclass doesn't start with "$"
  40.  
  41. int ScriptConfig[2][ORBIT_ALL] = {
  42.     {160.0, "DreadballOrbiter", "$DreadballOrbiter", "DreadballDetonate",
  43.         140.0, 120.1, 0.999, 0.03, 0.01, 0.25},
  44.     {160.0, "CoreDreadballOrbiter", "$CoreDreadballOrbiter", "DreadballDetonate",
  45.         140.0, 120.1, 0.999, 0.03, 0.01, 0.25}
  46. };
  47.  
  48. script "Orbit Dat Shite" (int liczba) {
  49.     int randomium = ScriptConfig[liczba][ORBIT_RANDOMSCALE];
  50.     int orbiterclass = ScriptConfig[liczba][ORBIT_ORBITERCLASS];
  51.     int orbiterdeathclass = ScriptConfig[liczba][ORBIT_ORBITERDEATHCLASS];
  52.     int stoptrigger = ScriptConfig[liczba][ORBIT_STOPTRIGGER];
  53.     int radiusmin = ScriptConfig[liczba][ORBIT_RADIUSMIN];
  54.     int radiusmax = ScriptConfig[liczba][ORBIT_RADIUSMAX];
  55.     int ellipsismin = ScriptConfig[liczba][ORBIT_ELLIPSISMIN];
  56.     int torque = ScriptConfig[liczba][ORBIT_TORQUE];
  57.     int deathspeedmul = ScriptConfig[liczba][ORBIT_DEATHSPEEDMUL];
  58.     int deathanglefix = ScriptConfig[liczba][ORBIT_DEATHANGLEFIX];
  59.  
  60. //BEGIN: Generate two random perpendicular vectors
  61.     int vx = Random(-randomium, randomium);
  62.     int vy = Random(-randomium, randomium);
  63.     int vz = Random(-randomium, randomium);
  64.     int wx = Random(-randomium, randomium);
  65.     int wy = Random(-randomium, randomium);
  66.     int wz = Random(-randomium, randomium);
  67.  
  68.     int dotwv_presquish = FixedMul(wx, vx) + FixedMul(wy, vy) + FixedMul(wz, vz);
  69.     int dotvv = FixedMul(vx, vx) + FixedMul(vy, vy) + FixedMul(vz, vz);
  70.     int ratio = FixedDiv(dotwv_presquish, dotvv);
  71.     wx -= FixedMul(vx, ratio);
  72.     wy -= FixedMul(vy, ratio);
  73.     wz -= FixedMul(vz, ratio);
  74.     int dotww = FixedMul(wx, wx) + FixedMul(wy, wy) + FixedMul(wz, wz);
  75. //END: v and w are perpendicular vectors, 99,9% of the time, that is unless they were initially parallel
  76.  
  77. //BEGIN: resize v and w according to specs
  78.     int radius = random(radiusmin, radiusmax);
  79.     int vratio = FixedDiv(radius, sqrtx(dotvv)); //the latter is vlen
  80.     vx = FixedMul(vx, vratio);
  81.     vy = FixedMul(vy, vratio);
  82.     vz = FixedMul(vz, vratio);
  83.     int ellipsisfactor = random(ellipsismin, 1.0);
  84.     int wratio = FixedDiv(FixedMul(ellipsismin, radius), sqrt(dotww)); //the latter is wlen
  85.     wx = FixedMul(wx, wratio);
  86.     wy = FixedMul(wy, wratio);
  87.     wz = FixedMul(wz, wratio);
  88. //END: v, w resized
  89.  
  90.     int i, fx, fy, fz;
  91. //DEBUG
  92.     for (i = 0; i <= 1.0; i += 0.125) {
  93.         fx = GetActorX(0) + FixedMul(i, vx);
  94.         fy = GetActorY(0) + FixedMul(i, vy);
  95.         fz = GetActorZ(0) + FixedMul(i, vz);
  96.         Spawn("DebugGhost", fx, fy, fz);
  97.     }
  98. //SPAWN
  99.     int TID = UniqueTID();
  100.     fx = GetActorX(0) + vx;
  101.     fy = GetActorY(0) + vy;
  102.     fz = GetActorZ(0) + vz;
  103.     int angle = 0.0;
  104.     if (!Spawn(orbiterclass, fx, fy, fz, TID)) {
  105.         log(s:"ORBITER COULD NOT SPAWN");
  106.         delay(35); restart;
  107.     }
  108.     SetActorVelocity(TID, 0.0, 0.0, 0.0, 0, 0);
  109.  
  110.  
  111.     delay(1);
  112.  
  113.     while (CheckInventory(stoptrigger) == 0) {
  114.         if (!IsTIDUsed(TID)) {
  115.             Restart;
  116.         }
  117.         angle = (angle + torque) % 1.0;
  118.         fx = GetActorX(0) + FixedMul(cos(angle), vx) + FixedMul(sin(angle), wx);
  119.         fy = GetActorY(0) + FixedMul(cos(angle), vy) + FixedMul(sin(angle), wy);
  120.         fz = GetActorZ(0) + FixedMul(cos(angle), vz) + FixedMul(sin(angle), wz);
  121.         if (!SetActorPosition(TID, fx, fy, fz, 0)) {
  122.             if (SetActorState(TID, "DieDieDie2") == 0
  123.                 && SetActorState(TID, "DieDieDie") == 0) {
  124.                 SetActorState(TID, "Death");
  125.             }
  126.             for (i = 0; i < 8; i++) {
  127.                 delay(1);
  128.                 if (CheckInventory(stoptrigger) > 0) {
  129.                     Terminate;
  130.                 }
  131.             }
  132.             Restart;
  133.         }
  134.         delay(1);
  135.     }
  136.  
  137.     if (SetActorState(TID, "DieDieDie") == 0
  138.         && SetActorState(TID, "DieDieDie2") == 0) {
  139.         SetActorState(TID, "Death");
  140.     }
  141.  
  142. //optional post-death spawn-something option
  143.     if (GetChar(orbiterdeathclass, 0) == '$') terminate;
  144.  
  145.     while (!IsTIDUsed(TID)) {
  146.         delay(1);
  147.     }
  148.     angle = (angle + deathanglefix) % 1.0;
  149.     Spawn(orbiterdeathclass, fx, fy, fz, TID);
  150.     fx = FixedMul(deathspeedmul, FixedMul(cos(angle), vx) + FixedMul(sin(angle), wx));
  151.     fy = FixedMul(deathspeedmul, FixedMul(cos(angle), vy) + FixedMul(sin(angle), wy));
  152.     fz = FixedMul(deathspeedmul, FixedMul(cos(angle), vz) + FixedMul(sin(angle), wz));
  153.     SetActorVelocity(TID, fx, fy, fz, 0, 0);
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement