Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. function int LamePow(int a, int pow)
  2. {
  3.     int res = a;
  4.     for(int i = 1; i < pow; i++)
  5.         res *= a;
  6.     return res;
  7. }
  8.  
  9. function int DMulScale16(int a, int b, int c, int d)
  10. {
  11.     return (FixedMul(a, b) + FixedMul(c, d));
  12. }
  13.  
  14. function int DivScale13(int a, int b)
  15. {
  16.     return FixedDiv(a, b);
  17. }
  18.  
  19. function int GetCVarFixed(str name)
  20. {
  21.     str c = GetCVarString(name);
  22.    
  23.     // [-|+][123123123][.123123123]
  24.    
  25.     int part_integer = 0;
  26.     int part_fractional = 0;
  27.    
  28.     // first, get the location of the dot
  29.     int i;
  30.     int dot = 0;
  31.     for (i = 0; i < StrLen(c); i++)
  32.     {
  33.         if (GetChar(c, i) == '.')
  34.             break;
  35.     }
  36.     dot = i;
  37.    
  38.     bool negative = false;
  39.    
  40.     for (i = 0; i < dot; i++)
  41.     {
  42.         if (i == 0 && (GetChar(c, i) == '-'))
  43.         {
  44.             negative = true;
  45.         }
  46.         else
  47.         {
  48.             int ch = GetChar(c, i);
  49.             ch -= 0x30;
  50.             int countOr = dot-i-1;
  51.             for (int j = 0; j < countOr; j++)
  52.                 ch *= 10;
  53.             part_integer += ch;
  54.         }
  55.     }
  56.    
  57.     for (i = dot+1; i < StrLen(c); i++)
  58.     {
  59.         ch = GetChar(c, i);
  60.         ch -= 0x30;
  61.         ch <<= 16;
  62.         countOr = i-dot;
  63.         for (j = 0; j < countOr; j++)
  64.             ch /= 10;
  65.         part_fractional += ch;
  66.     }
  67.    
  68.     return ((part_integer & 0xFFFF) << 16) | (part_fractional & 0xFFFF);
  69. }
  70.  
  71. function int /* fixed */ CalculateBob(int tid)
  72. {
  73.     int momx = GetActorVelX(tid);
  74.     int momy = GetActorVelY(tid);
  75.     //print(f:momx, s:";", f:momy);
  76.     int bob = DMulScale16(momx, momx, momy, momy);
  77.     bool still = false;
  78.     if(bob == 0)
  79.     {  
  80.         still = true;
  81.     }
  82.     else
  83.     {
  84.         bob = FixedMul(bob, GetCVarFixed("movebob"));
  85.         if(bob < 0 || bob > 0x100000)
  86.             bob = 0x100000;
  87.         int angle = DivScale13(Timer() % 65536, 20);
  88.         int wloffset = 1;
  89.         if(GetActorProperty(tid, APROP_Waterlevel) > 1)
  90.             wloffset = 2;
  91.         bob = FixedMul(bob>>wloffset, sin(angle));
  92.     }
  93.    
  94.     return bob;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement