]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 5 Nov 2015 08:42:39 +0000 (19:42 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 5 Nov 2015 08:42:39 +0000 (19:42 +1100)
qcsrc/lib/bits.qh
qcsrc/lib/math.qh
qcsrc/lib/random.qc
qcsrc/lib/string.qh
qcsrc/server/cl_client.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/miscfunctions.qh
qcsrc/server/t_items.qc
qcsrc/server/t_items.qh

index 33d719a0792e93fb90e2de1828fdb64b9cb46847..001984a632e0f8f9451354797879b31c5b7e67f4 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef BITS_H
 #define BITS_H
+#include "log.qh"
 
 #define BIT(n) (1 << (n))
 #define BITS(n) (BIT(n) - 1)
@@ -19,4 +20,106 @@ int lowestbit(int f)
        return f;
 }
 
+int randombit(int bits)
+{
+       if (!(bits & (bits - 1)))  // this ONLY holds for powers of two!
+               return bits;
+
+       int r = random();
+       int b = 0;
+       int n = 0;
+
+       for (int f = 1; f <= bits; f *= 2)
+       {
+               if (bits & f)
+               {
+                       ++n;
+                       r *= n;
+                       if (r <= 1) b = f;
+                       else r = (r - 1) / (n - 1);
+               }
+       }
+       return b;
+}
+
+int randombits(int bits, int k, bool error_return)
+{
+       int r = 0;
+       while (k > 0 && bits != r)
+       {
+               r += randombit(bits - r);
+               --k;
+       }
+       if (error_return)
+               if (k > 0) return -1;
+       // all
+       return r;
+}
+
+void randombit_test(int bits, int iter)
+{
+       while (iter > 0)
+       {
+               LOG_INFO(ftos(randombit(bits)), "\n");
+               --iter;
+       }
+}
+
+enum {
+       OP_SET,
+       OP_MIN,
+       OP_MAX,
+       OP_PLUS,
+       OP_MINUS
+};
+
+bool GiveBit(entity e, .int fld, int bit, int op, int val)
+{
+       int v0 = (e.(fld) & bit);
+       switch (op)
+       {
+               case OP_SET:
+                       if (val > 0) e.(fld) |= bit;
+                       else e.(fld) &= ~bit;
+                       break;
+               case OP_MIN:
+               case OP_PLUS:
+                       if (val > 0) e.(fld) |= bit;
+                       break;
+               case OP_MAX:
+                       if (val <= 0) e.(fld) &= ~bit;
+                       break;
+               case OP_MINUS:
+                       if (val > 0) e.(fld) &= ~bit;
+                       break;
+       }
+       int v1 = (e.(fld) & bit);
+       return v0 != v1;
+}
+
+bool GiveValue(entity e, .int fld, int op, int val)
+{
+       int v0 = e.(fld);
+       switch (op)
+       {
+               case OP_SET:
+                       e.(fld) = val;
+                       break;
+               case OP_MIN:
+                       e.(fld) = max(e.(fld), val);  // min 100 cells = at least 100 cells
+                       break;
+               case OP_MAX:
+                       e.(fld) = min(e.(fld), val);
+                       break;
+               case OP_PLUS:
+                       e.(fld) += val;
+                       break;
+               case OP_MINUS:
+                       e.(fld) -= val;
+                       break;
+       }
+       int v1 = e.(fld);
+       return v0 != v1;
+}
+
 #endif
index 24d004166cfd4bec600b102eb50a9198757e5e58..ea968e84c7763c35477c4674e0ce7f68e341609c 100644 (file)
@@ -184,6 +184,13 @@ float almost_in_bounds(float a, float b, float c)
        return b == median(a - eps, b, c + eps);
 }
 
+float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
+{
+       if (halflifedist > 0) return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
+       else if (halflifedist < 0) return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
+       else return 1;
+}
+
 float power2of(float e)
 {
        return pow(2, e);
index 6ae0f784d88de7afac96dcabb0827f02318b6ee8..be0f80a089c15b5057f25c974a1533963ba79c57 100644 (file)
@@ -31,6 +31,40 @@ void RandomSelection_Add(entity e, float f, string s, float weight, float priori
        }
 }
 
+float DistributeEvenly_amount;
+float DistributeEvenly_totalweight;
+
+void DistributeEvenly_Init(float amount, float totalweight)
+{
+       if (DistributeEvenly_amount)
+       {
+               LOG_TRACE("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
+               LOG_TRACE(ftos(DistributeEvenly_totalweight), " left!)\n");
+       }
+       if (totalweight == 0) DistributeEvenly_amount = 0;
+       else DistributeEvenly_amount = amount;
+       DistributeEvenly_totalweight = totalweight;
+}
+
+float DistributeEvenly_Get(float weight)
+{
+       float f;
+       if (weight <= 0) return 0;
+       f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
+       DistributeEvenly_totalweight -= weight;
+       DistributeEvenly_amount -= f;
+       return f;
+}
+
+float DistributeEvenly_GetRandomized(float weight)
+{
+       float f;
+       if (weight <= 0) return 0;
+       f = floor(random() + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
+       DistributeEvenly_totalweight -= weight;
+       DistributeEvenly_amount -= f;
+       return f;
+}
 
 // prandom - PREDICTABLE random number generator (not seeded yet)
 
index 2bf9ac1f7b5c8a5f6ddac99a14ce2a15134937e7..048b5c721b9d7365b60240109b8b06495ce55881 100644 (file)
@@ -184,4 +184,29 @@ int u8_strsize(string s)
        return l;
 }
 
+bool isInvisibleString(string s)
+{
+       s = strdecolorize(s);
+       bool utf8 = cvar("utf8_enable");
+       for (int i = 0, n = strlen(s); i < n; ++i)
+       {
+               int c = str2chr(s, i);
+               switch (c)
+               {
+                       case 0:
+                       case 32:           // space
+                               break;
+                       case 192:          // charmap space
+                               if (!utf8) break;
+                               return false;
+                       case 160:          // space in unicode fonts
+                       case 0xE000 + 192: // utf8 charmap space
+                               if (utf8) break;
+                       default:
+                               return false;
+               }
+       }
+       return true;
+}
+
 #endif
index 6cf716107db551a614cda032279ca4faea1561fd..a604055b8d8ce1a11dd66f3c2246f434fde7aa93 100644 (file)
@@ -1635,19 +1635,20 @@ void SetZoomState(float z)
 }
 
 void GetPressedKeys()
-{SELFPARAM();
+{
+       SELFPARAM();
        MUTATOR_CALLHOOK(GetPressedKeys);
-       #define X(var,bit,flag) (flag ? var |= bit : var &= ~bit)
-       X(self.pressedkeys, KEY_FORWARD,        self.movement_x > 0);
-       X(self.pressedkeys, KEY_BACKWARD,       self.movement_x < 0);
-       X(self.pressedkeys, KEY_RIGHT,          self.movement_y > 0);
-       X(self.pressedkeys, KEY_LEFT,           self.movement_y < 0);
-
-       X(self.pressedkeys, KEY_JUMP,           PHYS_INPUT_BUTTON_JUMP(self));
-       X(self.pressedkeys, KEY_CROUCH,         PHYS_INPUT_BUTTON_CROUCH(self));
-       X(self.pressedkeys, KEY_ATCK,           PHYS_INPUT_BUTTON_ATCK(self));
-       X(self.pressedkeys, KEY_ATCK2,          PHYS_INPUT_BUTTON_ATCK2(self));
-       #undef X
+       int keys = this.pressedkeys;
+       keys = BITSET(keys, KEY_FORWARD,        this.movement.x > 0);
+       keys = BITSET(keys, KEY_BACKWARD,       this.movement.x < 0);
+       keys = BITSET(keys, KEY_RIGHT,          this.movement.y > 0);
+       keys = BITSET(keys, KEY_LEFT,           this.movement.y < 0);
+
+       keys = BITSET(keys, KEY_JUMP,           PHYS_INPUT_BUTTON_JUMP(this));
+       keys = BITSET(keys, KEY_CROUCH,         PHYS_INPUT_BUTTON_CROUCH(this));
+       keys = BITSET(keys, KEY_ATCK,           PHYS_INPUT_BUTTON_ATCK(this));
+       keys = BITSET(keys, KEY_ATCK2,          PHYS_INPUT_BUTTON_ATCK2(this));
+       this.pressedkeys = keys;
 }
 
 /*
@@ -2138,32 +2139,6 @@ void PlayerUseKey()
        MUTATOR_CALLHOOK(PlayerUseKey);
 }
 
-float isInvisibleString(string s)
-{
-       float i, n, c;
-       s = strdecolorize(s);
-       for((i = 0), (n = strlen(s)); i < n; ++i)
-       {
-               c = str2chr(s, i);
-               switch(c)
-               {
-                       case 0:
-                       case 32: // space
-                               break;
-                       case 192: // charmap space
-                               if (!autocvar_utf8_enable)
-                                       break;
-                               return false;
-                       case 160: // space in unicode fonts
-                       case 0xE000 + 192: // utf8 charmap space
-                               if (autocvar_utf8_enable)
-                                       break;
-                       default:
-                               return false;
-               }
-       }
-       return true;
-}
 
 /*
 =============
index de7559222744c29760621dc65a21ebc12a2a894f..4df487c0ebc14a042acff0289d7cfc4ab071a493 100644 (file)
@@ -60,40 +60,6 @@ string admin_name()
                return "SERVER ADMIN";
 }
 
-void DistributeEvenly_Init(float amount, float totalweight)
-{
-    if (DistributeEvenly_amount)
-    {
-        LOG_TRACE("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
-        LOG_TRACE(ftos(DistributeEvenly_totalweight), " left!)\n");
-    }
-    if (totalweight == 0)
-        DistributeEvenly_amount = 0;
-    else
-        DistributeEvenly_amount = amount;
-    DistributeEvenly_totalweight = totalweight;
-}
-float DistributeEvenly_Get(float weight)
-{
-    float f;
-    if (weight <= 0)
-        return 0;
-    f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
-    DistributeEvenly_totalweight -= weight;
-    DistributeEvenly_amount -= f;
-    return f;
-}
-float DistributeEvenly_GetRandomized(float weight)
-{
-    float f;
-    if (weight <= 0)
-        return 0;
-    f = floor(random() + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
-    DistributeEvenly_totalweight -= weight;
-    DistributeEvenly_amount -= f;
-    return f;
-}
-
 
 void GameLogEcho(string s)
 {
@@ -1678,68 +1644,6 @@ void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
        return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
 }
 
-float randombit(float bits)
-{
-       if(!(bits & (bits-1))) // this ONLY holds for powers of two!
-               return bits;
-
-       float n, f, b, r;
-
-       r = random();
-       b = 0;
-       n = 0;
-
-       for(f = 1; f <= bits; f *= 2)
-       {
-               if(bits & f)
-               {
-                       ++n;
-                       r *= n;
-                       if(r <= 1)
-                               b = f;
-                       else
-                               r = (r - 1) / (n - 1);
-               }
-       }
-
-       return b;
-}
-
-float randombits(float bits, float k, float error_return)
-{
-       float r;
-       r = 0;
-       while(k > 0 && bits != r)
-       {
-               r += randombit(bits - r);
-               --k;
-       }
-       if(error_return)
-               if(k > 0)
-                       return -1; // all
-       return r;
-}
-
-void randombit_test(float bits, float iter)
-{
-       while(iter > 0)
-       {
-               LOG_INFO(ftos(randombit(bits)), "\n");
-               --iter;
-       }
-}
-
-float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
-{
-       if(halflifedist > 0)
-               return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
-       else if(halflifedist < 0)
-               return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
-       else
-               return 1;
-}
-
-
 .string aiment_classname;
 .float aiment_deadflag;
 void SetMovetypeFollow(entity ent, entity e)
index c857c2dc316873380b85e631c535cb208e35d85d..bb19cafff03cc9b58b57b30b5fb95bc001af0309 100644 (file)
@@ -39,9 +39,6 @@ void write_recordmarker(entity pl, float tstart, float dt);
 
 void play2all(string samp);
 
-void DistributeEvenly_Init(float amount, float totalweight);
-float DistributeEvenly_Get(float weight);
-
 void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector ang, vector angv, float s0, float s2, float a, float t1, float t2);
 
 void shockwave_spawn(string m, vector org, float sz, float t1, float t2);
@@ -62,10 +59,7 @@ void InitializeEntitiesRun();
 
 void stopsoundto(float _dest, entity e, float chan);
 void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
-float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d);
 
-float DistributeEvenly_amount;
-float DistributeEvenly_totalweight;
 void objerror(string s);
 void droptofloor();
 void() SUB_Remove;
index cd06f2da8b649814209b0b5038af0d9e69da2688..5d2509102925a2f0d54eb1a93d0bdb5baf3b1d76 100644 (file)
@@ -1578,62 +1578,6 @@ float GiveWeapon(entity e, float wpn, float op, float val)
        return (v0 != v1);
 }
 
-float GiveBit(entity e, .float fld, float bit, float op, float val)
-{
-       float v0, v1;
-       v0 = (e.(fld) & bit);
-       switch(op)
-       {
-               case OP_SET:
-                       if(val > 0)
-                               e.(fld) |= bit;
-                       else
-                               e.(fld) &= ~bit;
-                       break;
-               case OP_MIN:
-               case OP_PLUS:
-                       if(val > 0)
-                               e.(fld) |= bit;
-                       break;
-               case OP_MAX:
-                       if(val <= 0)
-                               e.(fld) &= ~bit;
-                       break;
-               case OP_MINUS:
-                       if(val > 0)
-                               e.(fld) &= ~bit;
-                       break;
-       }
-       v1 = (e.(fld) & bit);
-       return (v0 != v1);
-}
-
-float GiveValue(entity e, .float fld, float op, float val)
-{
-       float v0, v1;
-       v0 = e.(fld);
-       switch(op)
-       {
-               case OP_SET:
-                       e.(fld) = val;
-                       break;
-               case OP_MIN:
-                       e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells
-                       break;
-               case OP_MAX:
-                       e.(fld) = min(e.(fld), val);
-                       break;
-               case OP_PLUS:
-                       e.(fld) += val;
-                       break;
-               case OP_MINUS:
-                       e.(fld) -= val;
-                       break;
-       }
-       v1 = e.(fld);
-       return (v0 != v1);
-}
-
 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
 {
        if(v1 == v0)
index 35a1768001b50843b7c7e52a3f637bc41f62f0b5..718944952c291571dea3257a0114ab84d43463c9 100644 (file)
@@ -115,12 +115,6 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
 
 void target_items_use ();
 
-const float OP_SET = 0;
-const float OP_MIN = 1;
-const float OP_MAX = 2;
-const float OP_PLUS = 3;
-const float OP_MINUS = 4;
-
 float GiveWeapon(entity e, float wpn, float op, float val);
 
 float GiveBit(entity e, .float fld, float bit, float op, float val);