Advertisement
ijontichy

commonFuncs.h

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