Advertisement
ijontichy

commonFuncs.h

May 19th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.35 KB | None | 0 0
  1. // A bunch of functions that I've built up
  2. // They come in handy :>
  3.  
  4. #define PLAYERMAX 64
  5. #define TEAMCOUNT 8
  6. #define DEFAULTTID_SCRIPT 471
  7.  
  8. #define SECOND_TICS 35.714285714285715
  9. #define UNIT_CM     2.73921568627451
  10.  
  11. function int itof(int x) { return x << 16; }
  12. function int ftoi(int x) { return x >> 16; }
  13.  
  14. function int abs(int x)
  15. {
  16.     if (x < 0) { return -x; }
  17.     return x;
  18. }
  19.  
  20. function int sign(int x)
  21. {
  22.     if (x < 0) { return -1; }
  23.     return 1;
  24. }
  25.  
  26. function int randSign(void)
  27. {
  28.     return (2*random(0,1))-1;
  29. }
  30.  
  31. function int mod(int x, int y)
  32. {
  33.     int ret = x - ((x / y) * y);
  34.     if (ret < 0) { ret = y + ret; }
  35.     return ret;
  36. }
  37.  
  38. function int pow(int x, int y)
  39. {
  40.     int n = 1;
  41.     while (y-- > 0) { n *= x; }
  42.     return n;
  43. }
  44.  
  45. function int powFloat(int x, int y)
  46. {
  47.     int n = 1.0;
  48.     while (y-- > 0) { n = FixedMul(n, x); }
  49.     return n;
  50. }
  51.  
  52. function int gcf(int a, int b)
  53. {
  54.     int c;
  55.     while (1)
  56.     {
  57.         if (b == 0) { return a; }
  58.         c = a % b;
  59.         a = b;
  60.         b = c;
  61.     }
  62.    
  63.     return -1;
  64. }
  65.  
  66. function int min(int x, int y)
  67. {
  68.     if (x < y) { return x; }
  69.     return y;
  70. }
  71.  
  72. function int max (int x, int y)
  73. {
  74.     if (x > y) { return x; }
  75.     return y;
  76. }
  77.  
  78. function int middle(int x, int y, int z)
  79. {
  80.     if ((x < z) && (y < z)) { return max(x, y); }
  81.     return max(min(x, y), z);
  82. }
  83.  
  84. function int percFloat(int intg, int frac)
  85. {
  86.     return itof(intg) + (itof(frac) / 100);
  87. }
  88.  
  89. function int percFloat2(int intg, int frac1, int frac2)
  90. {
  91.     return itof(intg) + (itof(frac1) / 100) + (itof(frac2) / 10000);
  92. }
  93.  
  94. function int keyUp(int key)
  95. {
  96.     int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
  97.  
  98.     if ((~buttons & key) == key) { return 1; }
  99.     return 0;
  100. }
  101.  
  102. function int keyDown(int key)
  103. {
  104.     int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
  105.  
  106.     if ((buttons & key) == key) { return 1; }
  107.     return 0;
  108. }
  109.  
  110. function int keyDown_any(int key)
  111. {
  112.     int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
  113.  
  114.     if (buttons & key) { return 1; }
  115.     return 0;
  116. }
  117.  
  118. function int keysPressed(void)
  119. {
  120.     int buttons     = GetPlayerInput(-1, INPUT_BUTTONS);
  121.     int oldbuttons  = GetPlayerInput(-1, INPUT_OLDBUTTONS);
  122.     int newbuttons  = (buttons ^ oldbuttons) & buttons;
  123.  
  124.     return newbuttons;
  125. }
  126.  
  127. function int keyPressed(int key)
  128. {
  129.     if ((keysPressed() & key) == key) { return 1; }
  130.     return 0;
  131. }
  132.  
  133. function int keyPressed_any(int key)
  134. {
  135.     if (keysPressed() & key) { return 1; }
  136.     return 0;
  137. }
  138.  
  139. function int adjustBottom(int tmin, int tmax, int i)
  140. {
  141.     if (tmin > tmax)
  142.     {
  143.         tmax ^= tmin; tmin ^= tmax; tmax ^= tmin;  // XOR swap
  144.     }
  145.  
  146.     if (i < tmin) { tmin = i; }
  147.     if (i > tmax) { tmin += (i - tmax); }
  148.  
  149.     return tmin;
  150. }
  151.  
  152. function int adjustTop(int tmin, int tmax, int i)
  153. {
  154.     if (tmin > tmax)
  155.     {
  156.         tmax ^= tmin; tmin ^= tmax; tmax ^= tmin;
  157.     }
  158.  
  159.     if (i < tmin) { tmax -= (tmin - i); }
  160.     if (i > tmax) { tmax = i; }
  161.  
  162.     return tmax;
  163. }
  164.  
  165. function int adjustShort(int tmin, int tmax, int i)
  166. {
  167.     if (tmin > tmax)
  168.     {
  169.         tmax ^= tmin; tmin ^= tmax; tmax ^= tmin;
  170.     }
  171.  
  172.     if (i < tmin)
  173.     {
  174.         tmax -= (tmin - i);
  175.         tmin = i;
  176.     }
  177.     if (i > tmax)
  178.     {
  179.         tmin += (i - tmax);
  180.         tmax = i;
  181.     }
  182.    
  183.     return packShorts(tmin, tmax);
  184. }
  185.  
  186.  
  187. // Taken from http://zdoom.org/wiki/sqrt
  188.  
  189. function int sqrt_i(int number)
  190. {
  191.     if (number <= 3) { return number > 0; }
  192.  
  193.     int oldAns = number >> 1,                     // initial guess
  194.         newAns = (oldAns + number / oldAns) >> 1; // first iteration
  195.  
  196.     // main iterative method
  197.     while (newAns < oldAns)
  198.     {
  199.         oldAns = newAns;
  200.         newAns = (oldAns + number / oldAns) >> 1;
  201.     }
  202.  
  203.     return oldAns;
  204. }
  205.  
  206. function int sqrt(int number)
  207. {
  208.     if (number == 1.0) { return 1.0; }
  209.     if (number <= 0) { return 0; }
  210.     int val = 150.0;
  211.     for (int i=0; i<15; i++) { val = (val + FixedDiv(number, val)) >> 1; }
  212.  
  213.     return val;
  214. }
  215.  
  216. function int magnitudeTwo(int x, int y)
  217. {
  218.     return sqrt_i(x*x + y*y);
  219. }
  220.  
  221. function int magnitudeTwo_f(int x, int y)
  222. {
  223.     return sqrt(FixedMul(x, x) + FixedMul(y, y));
  224. }
  225.  
  226. function int magnitudeThree(int x, int y, int z)
  227. {
  228.     return sqrt_i(x*x + y*y + z*z);
  229. }
  230.  
  231. function int magnitudeThree_f(int x, int y, int z)
  232. {
  233.     int len, ang;
  234.  
  235.     ang = VectorAngle(x, y);
  236.     if (((ang + 0.125) % 0.5) > 0.25) { len = FixedDiv(y, sin(ang)); }
  237.     else { len = FixedDiv(x, cos(ang)); }
  238.  
  239.     ang = VectorAngle(len, z);
  240.     if (((ang + 0.125) % 0.5) > 0.25) { len = FixedDiv(z, sin(ang)); }
  241.     else { len = FixedDiv(len, cos(ang)); }
  242.  
  243.     return len;
  244. }
  245.  
  246.  
  247. function int quadPos(int a, int b, int c)
  248. {
  249.     int s1 = sqrt(FixedMul(b, b)-(4*FixedMul(a, c)));
  250.     int s2 = (2 * a);
  251.     int b1 = FixedDiv(-b + s1, s2);
  252.  
  253.     return b1;
  254. }
  255.  
  256. function int quadNeg(int a, int b, int c)
  257. {
  258.     int s1 = sqrt(FixedMul(b, b)-(4*FixedMul(a, c)));
  259.     int s2 = (2 * a);
  260.     int b1 = FixedDiv(-b - s1, s2);
  261.  
  262.     return b1;
  263. }
  264.  
  265. // All the arguments are to be fixed-point
  266. function int quad(int a, int b, int c, int y)
  267. {
  268.     return FixedMul(a, FixedMul(y, y)) + FixedMul(b, y) + c + y;
  269. }
  270.  
  271. function int quadHigh(int a, int b, int c, int x)
  272. {
  273.     return quadPos(a, b, c-x);
  274. }
  275.  
  276. function int quadLow(int a, int b, int c, int x)
  277. {
  278.     return quadNeg(a, b, c-x);
  279. }
  280.  
  281. function int inRange(int low, int high, int x)
  282. {
  283.     return ((x >= low) && (x < high));
  284. }
  285.  
  286. function void AddAmmoCapacity(int type, int add)
  287. {
  288.     SetAmmoCapacity(type, GetAmmoCapacity(type) + add);
  289. }
  290.  
  291. function int packShorts(int left, int right)
  292. {
  293.     return ((left & 0xFFFF) << 16) + (right & 0xFFFF);
  294. }
  295.  
  296. function int leftShort(int packed) { return packed >> 16; }
  297. function int rightShort(int packed) { return (packed << 16) >> 16; }
  298.  
  299.  
  300. // This stuff only works with StrParam
  301.  
  302. function int cleanString(int string)
  303. {
  304.     int ret = "";
  305.     int strSize = StrLen(string);
  306.  
  307.     int c, i, ignoreNext;
  308.    
  309.     for (i = 0; i < strSize; i++)
  310.     {
  311.         c = GetChar(string, i);
  312.  
  313.         if ( ( ((c > 8) && (c < 14)) || ((c > 31) && (c < 127)) || ((c > 160) && (c < 173)) ) && !ignoreNext)
  314.         {
  315.             ret = StrParam(s:ret, c:c);
  316.         }
  317.         else if (c == 28 && !ignoreNext)
  318.         {
  319.             ignoreNext = 1;
  320.         }
  321.         else
  322.         {
  323.             ignoreNext = 0;
  324.         }
  325.     }
  326.  
  327.     return ret;
  328. }
  329.  
  330. function int padStringR(int baseStr, int padChar, int len)
  331. {
  332.     int baseStrLen = StrLen(baseStr);
  333.     int pad = "";
  334.     int padLen; int i;
  335.  
  336.     if (baseStrLen >= len)
  337.     {
  338.         return baseStr;
  339.     }
  340.    
  341.     padChar = GetChar(padChar, 0);
  342.     padLen = len - baseStrLen;
  343.  
  344.     for (i = 0; i < padLen; i++)
  345.     {
  346.         pad = StrParam(s:pad, c:padChar);
  347.     }
  348.  
  349.     return StrParam(s:baseStr, s:pad);
  350. }
  351.  
  352. function int padStringL(int baseStr, int padChar, int len)
  353. {
  354.     int baseStrLen = StrLen(baseStr);
  355.     int pad = "";
  356.     int padLen; int i;
  357.  
  358.     if (baseStrLen >= len)
  359.     {
  360.         return baseStr;
  361.     }
  362.    
  363.     padChar = GetChar(padChar, 0);
  364.     padLen = len - baseStrLen;
  365.  
  366.     for (i = 0; i < padLen; i++)
  367.     {
  368.         pad = StrParam(s:pad, c:padChar);
  369.     }
  370.  
  371.     return StrParam(s:pad, s:baseStr);
  372. }
  373.  
  374. function int changeString(int string, int repl, int where)
  375. {
  376.     int i; int j; int k;
  377.     int ret = "";
  378.     int len = StrLen(string);
  379.     int rLen = StrLen(repl);
  380.  
  381.     if ((where + rLen < 0) || (where >= len))
  382.     {
  383.         return string;
  384.     }
  385.    
  386.     for (i = 0; i < len; i++)
  387.     {
  388.         if (inRange(where, where+rLen, i))
  389.         {
  390.             ret = StrParam(s:ret, c:GetChar(repl, i-where));
  391.         }
  392.         else
  393.         {
  394.             ret = StrParam(s:ret, c:GetChar(string, i));
  395.         }
  396.     }
  397.  
  398.     return ret;
  399. }
  400.  
  401. function int sliceString(int string, int start, int end)
  402. {
  403.     int len = StrLen(string);
  404.     int ret = "";
  405.     int i;
  406.  
  407.     if (start < 0)
  408.     {
  409.         start = len + start;
  410.     }
  411.  
  412.     if (end <= 0)
  413.     {
  414.         end = len + end;
  415.     }
  416.  
  417.     start = max(0, start);
  418.     end   = min(end, len-1);
  419.    
  420.     for (i = start; i < end; i++)
  421.     {
  422.         ret = StrParam(s:ret, c:GetChar(string, i));
  423.     }
  424.  
  425.     return ret;
  426. }
  427.  
  428. function int strcmp(int str1, int str2)
  429. {
  430.     int i,j,k,l;
  431.     int len1 = StrLen(str1);
  432.     int len2 = StrLen(str2);
  433.     j = max(len1, len2);
  434.  
  435.     for (i = 0; i < j; i++)
  436.     {
  437.         if (i >= len1) { return -1; }
  438.         if (i >= len2) { return  1; }
  439.        
  440.         k = GetChar(str1, i); l = GetChar(str2, i);
  441.  
  442.         if (k > j) { return  1; }
  443.         if (k < j) { return -1; }
  444.     }
  445.     return 0;
  446. }
  447.  
  448.  
  449. // End StrParam
  450.  
  451. function int unusedTID(int start, int end)
  452. {
  453.     int ret = start - 1;
  454.     int tidNum;
  455.  
  456.     if (start > end) { start ^= end; end ^= start; start ^= end; }  // good ol' XOR swap
  457.    
  458.     while (ret++ != end)
  459.     {
  460.         if (ThingCount(0, ret) == 0)
  461.         {
  462.             return ret;
  463.         }
  464.     }
  465.    
  466.     return -1;
  467. }
  468.  
  469. function int getMaxHealth(void)
  470. {
  471.     int maxHP = GetActorProperty(0, APROP_SpawnHealth);
  472.  
  473.     if ((maxHP == 0) && (PlayerNumber() != -1))
  474.     {
  475.         maxHP = 100;
  476.     }
  477.  
  478.     return maxHP;
  479. }
  480.  
  481. function int giveHealth(int amount)
  482. {
  483.     return giveHealthFactor(amount, 1.0);
  484. }
  485.  
  486. function int giveHealthFactor(int amount, int maxFactor)
  487. {
  488.     return giveHealthMax(amount, ftoi(getMaxHealth() * maxFactor));
  489. }
  490.  
  491. function int giveHealthMax(int amount, int maxHP)
  492. {
  493.     int newHP;
  494.  
  495.     int curHP = GetActorProperty(0, APROP_Health);
  496.  
  497.     if (maxHP == 0) { newHP = max(curHP, curHP+amount); }
  498.     else { newHP = middle(curHP, curHP+amount, maxHP); }
  499.  
  500.     SetActorProperty(0, APROP_Health, newHP);
  501.  
  502.     return newHP - curHP;
  503. }
  504.  
  505. function int isDead(int tid)
  506. {
  507.     return GetActorProperty(tid, APROP_Health) <= 0;
  508. }
  509.  
  510. function int isSinglePlayer(void)
  511. {
  512.     return GameType() == GAME_SINGLE_PLAYER;
  513. }
  514.  
  515. function int isLMS(void)
  516. {
  517.     return GetCVar("lastmanstanding") || GetCVar("teamlms");
  518. }
  519.  
  520. function int isCoop(void)
  521. {
  522.     int check1 = GameType() == GAME_NET_COOPERATIVE;
  523.     int check2 = GetCVar("cooperative") || GetCVar("invasion") || GetCVar("survival");
  524.  
  525.     return check1 || check2;
  526. }
  527.  
  528. function int isInvasion(void)
  529. {
  530.     return GetCVar("invasion");
  531. }
  532.  
  533. function int isFreeForAll(void)
  534. {
  535.     if (GetCVar("terminator") || GetCVar("duel"))
  536.     {
  537.         return 1;
  538.     }
  539.  
  540.     int check1 = GetCVar("deathmatch") || GetCVar("possession") || GetCVar("lastmanstanding");
  541.     int check2 = check1 && !GetCVar("teamplay");
  542.  
  543.     return check2;
  544. }
  545.  
  546. function int isTeamGame(void)
  547. {
  548.     int ret = (GetCVar("teamplay") || GetCVar("teamgame") || GetCVar("teamlms"));
  549.     return ret;
  550. }
  551.  
  552. function int spawnDistance(int item, int dist, int tid)
  553. {
  554.     int myX, myY, myZ, myAng, myPitch, spawnX, spawnY, spawnZ;
  555.  
  556.     myX = GetActorX(0); myY = GetActorY(0); myZ = GetActorZ(0);
  557.     myAng = GetActorAngle(0); myPitch = GetActorPitch(0);
  558.  
  559.     spawnX = FixedMul(cos(myAng) * dist, cos(myPitch));
  560.     spawnX += myX;
  561.     spawnY = FixedMul(sin(myAng) * dist, cos(myPitch));
  562.     spawnY += myY;
  563.     spawnZ = myZ + (-sin(myPitch) * dist);
  564.  
  565.     return Spawn(item, spawnX, spawnY, spawnZ, tid, myAng >> 8);
  566. }
  567.  
  568. function void SetInventory(int item, int amount)
  569. {
  570.     int count = CheckInventory(item);
  571.  
  572.     if (count == amount) { return; }
  573.    
  574.     if (count > amount)
  575.     {
  576.         TakeInventory(item, count - amount);
  577.         return;
  578.     }
  579.  
  580.     GiveAmmo(item, amount - count);
  581.     return;
  582. }
  583. function void ToggleInventory(int inv)
  584. {
  585.     if (CheckInventory(inv))
  586.     {
  587.         TakeInventory(inv, 0x7FFFFFFF);
  588.     }
  589.     else
  590.     {
  591.         GiveInventory(inv, 1);
  592.     }
  593. }
  594.  
  595. function void GiveAmmo(int type, int amount)
  596. {
  597.     if (GetCVar("sv_doubleammo"))
  598.     {
  599.         int m = GetAmmoCapacity(type);
  600.         int expected = min(m, CheckInventory(type) + amount);
  601.  
  602.         GiveInventory(type, amount);
  603.         TakeInventory(type, CheckInventory(type) - expected);
  604.     }
  605.     else
  606.     {  
  607.         GiveInventory(type, amount);
  608.     }
  609. }
  610.  
  611. function void GiveActorAmmo(int tid, int type, int amount)
  612. {
  613.     if (GetCVar("sv_doubleammo"))
  614.     {
  615.         int m = GetAmmoCapacity(type);
  616.         int expected = min(m, CheckActorInventory(tid, type) + amount);
  617.  
  618.         GiveActorInventory(tid, type, amount);
  619.         TakeActorInventory(tid, type, CheckActorInventory(tid, type) - expected);
  620.     }
  621.     else
  622.     {  
  623.         GiveActorInventory(tid, type, amount);
  624.     }
  625. }
  626.  
  627. function int cond(int test, int trueRet, int falseRet)
  628. {
  629.     if (test) { return trueRet; }
  630.     return falseRet;
  631. }
  632.  
  633. function int condTrue(int test, int trueRet)
  634. {
  635.     if (test) { return trueRet; }
  636.     return test;
  637. }
  638.  
  639. function int condFalse(int test, int falseRet)
  640. {
  641.     if (test) { return test; }
  642.     return falseRet;
  643. }
  644.  
  645. function void saveCVar(int cvar, int val)
  646. {
  647.     int setStr = StrParam(s:"set ", s:cvar, s:" ", d:val);
  648.     int arcStr = StrParam(s:"archivecvar ", s:cvar);
  649.     ConsoleCommand(setStr); ConsoleCommand(arcStr);
  650. }
  651.  
  652. function int defaultCVar(int cvar, int defaultVal)
  653. {
  654.     int ret = GetCVar(cvar);
  655.     if (ret == 0) { saveCVar(cvar, defaultVal); return defaultVal; }
  656.  
  657.     return ret;
  658. }
  659.  
  660.  
  661. function int onGround(int tid)
  662. {
  663.     return (GetActorZ(tid) - GetActorFloorZ(tid)) == 0;
  664. }
  665.  
  666. function int ThingCounts(int start, int end)
  667. {
  668.     int i, ret = 0;
  669.  
  670.     if (start > end) { start ^= end; end ^= start; start ^= end; }
  671.     for (i = start; i < end; i++) { ret += ThingCount(0, i); }
  672.  
  673.     return ret;
  674. }
  675.  
  676. function int PlaceOnFloor(int tid)
  677. {
  678.     if (ThingCount(0, tid) != 1) { return 1; }
  679.    
  680.     SetActorPosition(tid, GetActorX(tid), GetActorY(tid), GetActorFloorZ(tid), 0);
  681.     return 0;
  682. }
  683.  
  684. #define DIR_E  1
  685. #define DIR_NE 2
  686. #define DIR_N  3
  687. #define DIR_NW 4
  688. #define DIR_W  5
  689. #define DIR_SW 6
  690. #define DIR_S  7
  691. #define DIR_SE 8
  692.  
  693. function int getDirection(void)
  694. {
  695.     int sideMove = keyDown(BT_MOVERIGHT) - keyDown(BT_MOVELEFT);
  696.     int forwMove = keyDown(BT_FORWARD) - keyDown(BT_BACK);
  697.  
  698.     if (sideMove || forwMove)
  699.     {
  700.         switch (sideMove)
  701.         {
  702.           case -1:
  703.             switch (forwMove)
  704.             {
  705.                 case -1: return DIR_SW;
  706.                 case  0: return DIR_W;
  707.                 case  1: return DIR_NW;
  708.             }
  709.             break;
  710.  
  711.           case 0:
  712.             switch (forwMove)
  713.             {
  714.                 case -1: return DIR_S;
  715.                 case  1: return DIR_N;
  716.             }
  717.             break;
  718.  
  719.           case 1:
  720.             switch (forwMove)
  721.             {
  722.                 case -1: return DIR_SE;
  723.                 case  0: return DIR_E;
  724.                 case  1: return DIR_NE;
  725.             }
  726.             break;
  727.         }
  728.     }
  729.  
  730.     return 0;
  731. }
  732.  
  733. function int isInvulnerable(void)
  734. {
  735.     int check1 = GetActorProperty(0, APROP_Invulnerable);
  736.     int check2 = CheckInventory("PowerInvulnerable");
  737.  
  738.     return check1 || check2;
  739. }
  740.  
  741. function void saveStringCVar(int string, int cvarname)
  742. {
  743.     int slen = StrLen(string);
  744.     int i, c, cvarname2;
  745.  
  746.     for (i = 0; i < slen; i++)
  747.     {
  748.         cvarname2 = StrParam(s:cvarname, s:"_char", d:i);
  749.         SaveCVar(cvarname2, GetChar(string, i));
  750.     }
  751.  
  752.     while (1)
  753.     {
  754.         cvarname2 = StrParam(s:cvarname, s:"_char", d:i);
  755.         c = GetCVar(cvarname2);
  756.  
  757.         if (c == 0) { break; }
  758.  
  759.         ConsoleCommand(StrParam(s:"unset ", s:cvarname2));
  760.         i += 1;
  761.     }
  762. }
  763.  
  764. function int loadStringCVar(int cvarname)
  765. {
  766.     int ret = "";
  767.     int i = 0, c, cvarname2;
  768.  
  769.     while (1)
  770.     {
  771.         cvarname2 = StrParam(s:cvarname, s:"_char", d:i);
  772.         c = GetCVar(cvarname2);
  773.  
  774.         if (c == 0) { break; }
  775.  
  776.         ret = StrParam(s:ret, c:c);
  777.         i += 1;
  778.     }
  779.  
  780.     return ret;
  781. }
  782.  
  783. function int defaultTID(int def)
  784. {
  785.     int tid = ActivatorTID();
  786.     int i;
  787.  
  788.     if (ThingCount(0, tid) == 1) { return tid; }
  789.  
  790.     tid = def;
  791.     if (def <= 0)
  792.     {
  793.         i = random(13, 23);
  794.         tid = unusedTID(i*1000, (i+10)*1000);
  795.     }
  796.  
  797.     Thing_ChangeTID(0, tid);
  798.     ACS_ExecuteAlways(DEFAULTTID_SCRIPT, 0, tid,0,0);
  799.  
  800.     return tid;
  801. }
  802.  
  803. script DEFAULTTID_SCRIPT (int tid) clientside
  804. {
  805.     if (ConsolePlayerNumber() == -1) { terminate; }
  806.     Thing_ChangeTID(0, tid);
  807. }
  808.  
  809. function int JumpZFromHeight(int height, int gravFactor)
  810. {
  811.     return sqrt(2 * height * gravFactor);
  812. }
  813.  
  814. function int roundZero(int toround)
  815. {
  816.     int i = toround % 1.0;
  817.     return ftoi(toround - i);
  818. }
  819.  
  820. function int roundAway(int toround)
  821. {
  822.     int i = toround % 1.0;
  823.  
  824.     if (i == 0) { return ftoi(toround); }
  825.     return ftoi(toround + (1.0 - i));
  826. }
  827.  
  828. function int round(int toround)
  829. {
  830.     return ftoi(toround + 0.5);
  831. }
  832.  
  833. function int ceil(int toround)
  834. {
  835.     return ftoi(toround + (1.0-1));
  836. }
  837.  
  838. function int intFloat(int toround)
  839. {
  840.     return itof(ftoi(toround));
  841. }
  842.  
  843. function int distance_ftoi(int x1, int y1, int z1, int x2, int y2, int z2)
  844. {
  845.     return magnitudeThree(ftoi(x2-x1), ftoi(y2-y1), ftoi(z2-z1));
  846. }
  847.  
  848. function void printDebugInfo(void)
  849. {
  850.     int classify    = ClassifyActor(0);
  851.     int fead        = classify & ACTOR_DEAD;
  852.     int player      = classify & ACTOR_PLAYER;
  853.     int pln         = PlayerNumber();
  854.  
  855.     Log(s:" -- DEBUG INFO -- ");
  856.  
  857.     Log(s:"Executed on tic ", d:Timer(), s:" on map ", d:GetLevelInfo(LEVELINFO_LEVELNUM));
  858.  
  859.     if (classify & (ACTOR_PLAYER | ACTOR_MONSTER))
  860.     {
  861.         Log(s:"Script activator has ", d:GetActorProperty(0, APROP_Health), s:"/", d:getMaxHealth(), s:" HP");
  862.     }
  863.  
  864.     if (player)
  865.     {
  866.         Log(s:"Is player ", d:pln, s:" (", n:0, s:"\c-) with class number ", d:PlayerClass(pln));
  867.     }
  868.  
  869.     Log(s:" -- END DEBUG -- ");
  870. }
  871.  
  872.  
  873. function int PlayerTeamCount(int teamNo)
  874. {
  875.     int i, ret;
  876.     for (i = 0; i < PLAYERMAX; i++)
  877.     {
  878.         if (GetPlayerInfo(i, PLAYERINFO_TEAM) == teamNO) { ret++; }
  879.     }
  880.     return ret;
  881. }
  882.  
  883. function int lower(int chr)
  884. {
  885.     if (chr > 64 && chr < 91) { return chr+32; }
  886.     return chr;
  887. }
  888.  
  889. function int upper(int chr)
  890. {
  891.     if (chr > 90 && chr < 123) { return chr-32; }
  892.     return chr;
  893. }
  894.  
  895. function int AddActorProperty(int tid, int prop, int amount)
  896. {
  897.     int newAmount = GetActorProperty(tid, prop) + amount;
  898.     SetActorProperty(tid, prop, newAmount);
  899.     return newAmount;
  900. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement