]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util.qc
Merge branch 'terencehill/menu_weaponarena_selection_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qc
index beb27aa28b2c336881bd0fc638d26822a4e72713..439f0bffa0f9b77485362c12815b4e26ce75ac7b 100644 (file)
@@ -1,3 +1,26 @@
+#include "util.qh"
+
+#if defined(CSQC)
+       #include "../dpdefs/csprogsdefs.qh"
+    #include "../client/defs.qh"
+    #include "constants.qh"
+       #include "../client/mutators/events.qh"
+    #include "mapinfo.qh"
+    #include "notifications.qh"
+    #include "deathtypes.qh"
+#elif defined(MENUQC)
+#elif defined(SVQC)
+       #include "../dpdefs/progsdefs.qh"
+    #include "../dpdefs/dpextensions.qh"
+    #include "constants.qh"
+    #include "../server/autocvars.qh"
+    #include "../server/defs.qh"
+       #include "../server/mutators/events.qh"
+    #include "notifications.qh"
+    #include "deathtypes.qh"
+    #include "mapinfo.qh"
+#endif
+
 string wordwrap_buffer;
 
 void wordwrap_buffer_put(string s)
@@ -161,26 +184,26 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(
        entity e;
        e = start;
        funcPre(pass, e);
-       while(e.downleft)
+       while (e.(downleft))
        {
-               e = e.downleft;
+               e = e.(downleft);
                funcPre(pass, e);
        }
        funcPost(pass, e);
        while(e != start)
        {
-               if(e.right)
+               if (e.(right))
                {
-                       e = e.right;
+                       e = e.(right);
                        funcPre(pass, e);
-                       while(e.downleft)
+                       while (e.(downleft))
                        {
-                               e = e.downleft;
+                               e = e.(downleft);
                                funcPre(pass, e);
                        }
                }
                else
-                       e = e.up;
+                       e = e.(up);
                funcPost(pass, e);
        }
 }
@@ -248,14 +271,13 @@ string fstrunzone(string s)
        return sc;
 }
 
-float fexists(string f)
+bool fexists(string f)
 {
-    float fh;
-    fh = fopen(f, FILE_READ);
+    int fh = fopen(f, FILE_READ);
     if (fh < 0)
-        return FALSE;
+        return false;
     fclose(fh);
-    return TRUE;
+    return true;
 }
 
 // Databases (hash tables)
@@ -266,7 +288,7 @@ void db_save(float db, string pFilename)
        fh = fopen(pFilename, FILE_WRITE);
        if(fh < 0)
        {
-               print(strcat("^1Can't write DB to ", pFilename));
+               LOG_INFO(strcat("^1Can't write DB to ", pFilename));
                return;
        }
        n = buf_getsize(db);
@@ -276,12 +298,12 @@ void db_save(float db, string pFilename)
        fclose(fh);
 }
 
-float db_create()
+int db_create()
 {
        return buf_create();
 }
 
-float db_load(string pFilename)
+int db_load(string pFilename)
 {
        float db, fh, i, j, n;
        string l;
@@ -346,34 +368,34 @@ void db_close(float db)
 string db_get(float db, string pKey)
 {
        float h;
-       h = crc16(FALSE, pKey) % DB_BUCKETS;
+       h = crc16(false, pKey) % DB_BUCKETS;
        return uri_unescape(infoget(bufstr_get(db, h), pKey));
 }
 
 void db_put(float db, string pKey, string pValue)
 {
        float h;
-       h = crc16(FALSE, pKey) % DB_BUCKETS;
+       h = crc16(false, pKey) % DB_BUCKETS;
        bufstr_set(db, h, infoadd(bufstr_get(db, h), pKey, uri_escape(pValue)));
 }
 
 void db_test()
 {
        float db, i;
-       print("LOAD...\n");
+       LOG_INFO("LOAD...\n");
        db = db_load("foo.db");
-       print("LOADED. FILL...\n");
+       LOG_INFO("LOADED. FILL...\n");
        for(i = 0; i < DB_BUCKETS; ++i)
                db_put(db, ftos(random()), "X");
-       print("FILLED. SAVE...\n");
+       LOG_INFO("FILLED. SAVE...\n");
        db_save(db, "foo.db");
-       print("SAVED. CLOSE...\n");
+       LOG_INFO("SAVED. CLOSE...\n");
        db_close(db);
-       print("CLOSED.\n");
+       LOG_INFO("CLOSED.\n");
 }
 
 // Multiline text file buffers
-float buf_load(string pFilename)
+int buf_load(string pFilename)
 {
        float buf, fh, i;
        string l;
@@ -478,19 +500,6 @@ string ScoreString(int pFlags, float pValue)
        return valstr;
 }
 
-float dotproduct(vector a, vector b)
-{
-       return a.x * b.x + a.y * b.y + a.z * b.z;
-}
-
-vector cross(vector a, vector b)
-{
-       return
-               '1 0 0' * (a.y * b.z - a.z * b.y)
-       +       '0 1 0' * (a.z * b.x - a.x * b.z)
-       +       '0 0 1' * (a.x * b.y - a.y * b.x);
-}
-
 // compressed vector format:
 // like MD3, just even shorter
 //   4 bit pitch (16 angles), 0 is -90, 8 is 0, 16 would be 90
@@ -545,20 +554,20 @@ vector decompressShortVector(int data)
 
        if(p == 0)
        {
-               out_x = 0;
-               out_y = 0;
+               out.x = 0;
+               out.y = 0;
                if(y == 31)
-                       out_z = -1;
+                       out.z = -1;
                else
-                       out_z = +1;
+                       out.z = +1;
        }
        else
        {
                y   = .19634954084936207740 * y;
                p = .19634954084936207740 * p - 1.57079632679489661922;
-               out_x = cos(y) *  cos(p);
-               out_y = sin(y) *  cos(p);
-               out_z =          -sin(p);
+               out.x = cos(y) *  cos(p);
+               out.y = sin(y) *  cos(p);
+               out.z =          -sin(p);
        }
 
        //print("decompressed: ", vtos(out), "\n");
@@ -574,7 +583,7 @@ float compressShortVector(vector vec)
                return 0;
        //print("compress: ", vtos(vec), "\n");
        ang = vectoangles(vec);
-       ang_x = -ang.x;
+       ang.x = -ang.x;
        if(ang.x < -90)
                ang.x += 360;
        if(ang.x < -90 && ang.x > +90)
@@ -611,35 +620,35 @@ void compressShortVector_init()
 
        if(cvar("developer"))
        {
-               print("Verifying vector compression table...\n");
+               LOG_INFO("Verifying vector compression table...\n");
                for(i = 0x0F00; i < 0xFFFF; ++i)
                        if(i != compressShortVector(decompressShortVector(i)))
                        {
-                               print("BROKEN vector compression: ", ftos(i));
-                               print(" -> ", vtos(decompressShortVector(i)));
-                               print(" -> ", ftos(compressShortVector(decompressShortVector(i))));
-                               print("\n");
+                               LOG_INFO("BROKEN vector compression: ", ftos(i));
+                               LOG_INFO(" -> ", vtos(decompressShortVector(i)));
+                               LOG_INFO(" -> ", ftos(compressShortVector(decompressShortVector(i))));
+                               LOG_INFO("\n");
                                error("b0rk");
                        }
-               print("Done.\n");
+               LOG_INFO("Done.\n");
        }
 }
 
 #ifndef MENUQC
 float CheckWireframeBox(entity forent, vector v0, vector dvx, vector dvy, vector dvz)
 {
-       traceline(v0, v0 + dvx, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0, v0 + dvy, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0, v0 + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvx, v0 + dvx + dvy, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvx, v0 + dvx + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvy, v0 + dvy + dvx, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvy, v0 + dvy + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvz, v0 + dvz + dvx, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvz, v0 + dvz + dvy, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvx + dvy, v0 + dvx + dvy + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvx + dvz, v0 + dvx + dvy + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
-       traceline(v0 + dvy + dvz, v0 + dvx + dvy + dvz, TRUE, forent); if(trace_fraction < 1) return 0;
+       traceline(v0, v0 + dvx, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0, v0 + dvy, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0, v0 + dvz, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvx, v0 + dvx + dvy, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvx, v0 + dvx + dvz, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvy, v0 + dvy + dvx, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvy, v0 + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvz, v0 + dvz + dvx, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvz, v0 + dvz + dvy, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvx + dvy, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvx + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
+       traceline(v0 + dvy + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
        return 1;
 }
 #endif
@@ -781,7 +790,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_min_x = trace_endpos.x;
+                               mi_min.x = trace_endpos.x;
 
                        tracebox('0 1 0' * mi.y,
                                         '1 0 0' * mi.x + '0 0 1' * mi.z,
@@ -790,7 +799,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_min_y = trace_endpos.y;
+                               mi_min.y = trace_endpos.y;
 
                        tracebox('0 0 1' * mi.z,
                                         '1 0 0' * mi.x + '0 1 0' * mi.y,
@@ -799,7 +808,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_min_z = trace_endpos.z;
+                               mi_min.z = trace_endpos.z;
 
                        tracebox('1 0 0' * ma.x,
                                         '0 1 0' * mi.y + '0 0 1' * mi.z,
@@ -808,7 +817,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_max_x = trace_endpos.x;
+                               mi_max.x = trace_endpos.x;
 
                        tracebox('0 1 0' * ma.y,
                                         '1 0 0' * mi.x + '0 0 1' * mi.z,
@@ -817,7 +826,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_max_y = trace_endpos.y;
+                               mi_max.y = trace_endpos.y;
 
                        tracebox('0 0 1' * ma.z,
                                         '1 0 0' * mi.x + '0 1 0' * mi.y,
@@ -826,7 +835,7 @@ void get_mi_min_max(float mode)
                                         MOVE_WORLDONLY,
                                         world);
                        if(!trace_startsolid)
-                               mi_max_z = trace_endpos.z;
+                               mi_max.z = trace_endpos.z;
                }
        }
 }
@@ -883,13 +892,13 @@ float cvar_settemp(string tmp_cvar, string tmp_value)
 
        if (!(tmp_cvar || tmp_value))
        {
-               dprint("Error: Invalid usage of cvar_settemp(string, string); !\n");
+               LOG_TRACE("Error: Invalid usage of cvar_settemp(string, string); !\n");
                return 0;
        }
 
        if(!cvar_type(tmp_cvar))
        {
-               printf("Error: cvar %s doesn't exist!\n", tmp_cvar);
+               LOG_INFOF("Error: cvar %s doesn't exist!\n", tmp_cvar);
                return 0;
        }
 
@@ -926,7 +935,7 @@ float cvar_settemp_restore()
                        ++i;
                }
                else
-                       printf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname);
+                       LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname);
        }
 
        return i;
@@ -937,8 +946,8 @@ float almost_equals(float a, float b)
        float eps;
        eps = (max(a, -a) + max(b, -b)) * 0.001;
        if(a - b < eps && b - a < eps)
-               return TRUE;
-       return FALSE;
+               return true;
+       return false;
 }
 
 float almost_in_bounds(float a, float b, float c)
@@ -1056,45 +1065,45 @@ vector hue_mi_ma_to_rgb(float hue, float mi, float ma)
        //      hue = 60 * (rgb_y - rgb_z) / (ma - mi);
        if(hue <= 1)
        {
-               rgb_x = ma;
-               rgb_y = hue * (ma - mi) + mi;
-               rgb_z = mi;
+               rgb.x = ma;
+               rgb.y = hue * (ma - mi) + mi;
+               rgb.z = mi;
        }
        //else if(ma == rgb_y)
        //      hue = 60 * (rgb_z - rgb_x) / (ma - mi) + 120;
        else if(hue <= 2)
        {
-               rgb_x = (2 - hue) * (ma - mi) + mi;
-               rgb_y = ma;
-               rgb_z = mi;
+               rgb.x = (2 - hue) * (ma - mi) + mi;
+               rgb.y = ma;
+               rgb.z = mi;
        }
        else if(hue <= 3)
        {
-               rgb_x = mi;
-               rgb_y = ma;
-               rgb_z = (hue - 2) * (ma - mi) + mi;
+               rgb.x = mi;
+               rgb.y = ma;
+               rgb.z = (hue - 2) * (ma - mi) + mi;
        }
        //else // if(ma == rgb_z)
        //      hue = 60 * (rgb_x - rgb_y) / (ma - mi) + 240;
        else if(hue <= 4)
        {
-               rgb_x = mi;
-               rgb_y = (4 - hue) * (ma - mi) + mi;
-               rgb_z = ma;
+               rgb.x = mi;
+               rgb.y = (4 - hue) * (ma - mi) + mi;
+               rgb.z = ma;
        }
        else if(hue <= 5)
        {
-               rgb_x = (hue - 4) * (ma - mi) + mi;
-               rgb_y = mi;
-               rgb_z = ma;
+               rgb.x = (hue - 4) * (ma - mi) + mi;
+               rgb.y = mi;
+               rgb.z = ma;
        }
        //else if(ma == rgb_x)
        //      hue = 60 * (rgb_y - rgb_z) / (ma - mi);
        else // if(hue <= 6)
        {
-               rgb_x = ma;
-               rgb_y = mi;
-               rgb_z = (6 - hue) * (ma - mi) + mi;
+               rgb.x = ma;
+               rgb.y = mi;
+               rgb.z = (6 - hue) * (ma - mi) + mi;
        }
 
        return rgb;
@@ -1108,13 +1117,13 @@ vector rgb_to_hsv(vector rgb)
        mi = min(rgb.x, rgb.y, rgb.z);
        ma = max(rgb.x, rgb.y, rgb.z);
 
-       hsv_x = rgb_mi_ma_to_hue(rgb, mi, ma);
-       hsv_z = ma;
+       hsv.x = rgb_mi_ma_to_hue(rgb, mi, ma);
+       hsv.z = ma;
 
        if(ma == 0)
-               hsv_y = 0;
+               hsv.y = 0;
        else
-               hsv_y = 1 - mi/ma;
+               hsv.y = 1 - mi/ma;
 
        return hsv;
 }
@@ -1132,15 +1141,15 @@ vector rgb_to_hsl(vector rgb)
        mi = min(rgb.x, rgb.y, rgb.z);
        ma = max(rgb.x, rgb.y, rgb.z);
 
-       hsl_x = rgb_mi_ma_to_hue(rgb, mi, ma);
+       hsl.x = rgb_mi_ma_to_hue(rgb, mi, ma);
 
-       hsl_z = 0.5 * (mi + ma);
+       hsl.z = 0.5 * (mi + ma);
        if(mi == ma)
-               hsl_y = 0;
+               hsl.y = 0;
        else if(hsl.z <= 0.5)
-               hsl_y = (ma - mi) / (2*hsl.z);
+               hsl.y = (ma - mi) / (2*hsl.z);
        else // if(hsl_z > 0.5)
-               hsl_y = (ma - mi) / (2 - 2*hsl.z);
+               hsl.y = (ma - mi) / (2 - 2*hsl.z);
 
        return hsl;
 }
@@ -1570,15 +1579,15 @@ vector solve_quadratic(float a, float b, float c) // ax^2 + bx + c = 0
        {
                if(b != 0)
                {
-                       v_x = v_y = -c / b;
-                       v_z = 1;
+                       v.x = v.y = -c / b;
+                       v.z = 1;
                }
                else
                {
                        if(c == 0)
                        {
                                // actually, every number solves the equation!
-                               v_z = 1;
+                               v.z = 1;
                        }
                }
        }
@@ -1590,26 +1599,26 @@ vector solve_quadratic(float a, float b, float c) // ax^2 + bx + c = 0
                        D = sqrt(D);
                        if(a > 0) // put the smaller solution first
                        {
-                               v_x = ((-b)-D) / (2*a);
-                               v_y = ((-b)+D) / (2*a);
+                               v.x = ((-b)-D) / (2*a);
+                               v.y = ((-b)+D) / (2*a);
                        }
                        else
                        {
-                               v_x = (-b+D) / (2*a);
-                               v_y = (-b-D) / (2*a);
+                               v.x = (-b+D) / (2*a);
+                               v.y = (-b-D) / (2*a);
                        }
-                       v_z = 1;
+                       v.z = 1;
                }
                else
                {
                        // complex solutions!
                        D = sqrt(-D);
-                       v_x = -b / (2*a);
+                       v.x = -b / (2*a);
                        if(a > 0)
-                               v_y =  D / (2*a);
+                               v.y =  D / (2*a);
                        else
-                               v_y = -D / (2*a);
-                       v_z = 0;
+                               v.y = -D / (2*a);
+                       v.z = 0;
                }
        }
        return v;
@@ -1726,17 +1735,17 @@ float compressShotOrigin(vector v)
        z = rint(v.z * 4) + 128;
        if(x > 255 || x < 0)
        {
-               print("shot origin ", vtos(v), " x out of bounds\n");
+               LOG_INFO("shot origin ", vtos(v), " x out of bounds\n");
                x = bound(0, x, 255);
        }
        if(y > 255 || y < 0)
        {
-               print("shot origin ", vtos(v), " y out of bounds\n");
+               LOG_INFO("shot origin ", vtos(v), " y out of bounds\n");
                y = bound(0, y, 255);
        }
        if(z > 255 || z < 0)
        {
-               print("shot origin ", vtos(v), " z out of bounds\n");
+               LOG_INFO("shot origin ", vtos(v), " z out of bounds\n");
                z = bound(0, z, 255);
        }
        return x * 0x10000 + y * 0x100 + z;
@@ -1744,9 +1753,9 @@ float compressShotOrigin(vector v)
 vector decompressShotOrigin(int f)
 {
        vector v;
-       v_x = ((f & 0xFF0000) / 0x10000) / 2;
-       v_y = ((f & 0xFF00) / 0x100 - 128) / 4;
-       v_z = ((f & 0xFF) - 128) / 4;
+       v.x = ((f & 0xFF0000) / 0x10000) / 2;
+       v.y = ((f & 0xFF00) / 0x100 - 128) / 4;
+       v.z = ((f & 0xFF) - 128) / 4;
        return v;
 }
 
@@ -1834,7 +1843,7 @@ void RandomSelection_Add(entity e, float f, string s, float weight, float priori
 }
 
 #ifndef MENUQC
-vector healtharmor_maxdamage(float h, float a, float armorblock, float deathtype)
+vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype)
 {
        // NOTE: we'll always choose the SMALLER value...
        float healthdamage, armordamage, armorideal;
@@ -1844,28 +1853,28 @@ vector healtharmor_maxdamage(float h, float a, float armorblock, float deathtype
        healthdamage = (h - 1) / (1 - armorblock); // damage we can take if we could use more health
        armordamage = a + (h - 1); // damage we can take if we could use more armor
        armorideal = healthdamage * armorblock;
-       v_y = armorideal;
+       v.y = armorideal;
        if(armordamage < healthdamage)
        {
-               v_x = armordamage;
-               v_z = 1;
+               v.x = armordamage;
+               v.z = 1;
        }
        else
        {
-               v_x = healthdamage;
-               v_z = 0;
+               v.x = healthdamage;
+               v.z = 0;
        }
        return v;
 }
 
-vector healtharmor_applydamage(float a, float armorblock, float deathtype, float damage)
+vector healtharmor_applydamage(float a, float armorblock, int deathtype, float damage)
 {
        vector v;
        if (deathtype == DEATH_DROWN)  // Why should armor help here...
                armorblock = 0;
-       v_y = bound(0, damage * armorblock, a); // save
-       v_x = bound(0, damage - v.y, damage); // take
-       v_z = 0;
+       v.y = bound(0, damage * armorblock, a); // save
+       v.x = bound(0, damage - v.y, damage); // take
+       v.z = 0;
        return v;
 }
 #endif
@@ -1884,27 +1893,26 @@ string getcurrentmod()
 
 #ifndef MENUQC
 #ifdef CSQC
-float ReadInt24_t()
+int ReadInt24_t()
 {
-       float v;
-       v = ReadShort() * 256; // note: this is signed
+       int v = ReadShort() * 256; // note: this is signed
        v += ReadByte(); // note: this is unsigned
        return v;
 }
 vector ReadInt48_t()
 {
        vector v;
-       v_x = ReadInt24_t();
-       v_y = ReadInt24_t();
-       v_z = 0;
+       v.x = ReadInt24_t();
+       v.y = ReadInt24_t();
+       v.z = 0;
        return v;
 }
 vector ReadInt72_t()
 {
        vector v;
-       v_x = ReadInt24_t();
-       v_y = ReadInt24_t();
-       v_z = ReadInt24_t();
+       v.x = ReadInt24_t();
+       v.y = ReadInt24_t();
+       v.z = ReadInt24_t();
        return v;
 }
 #else
@@ -2034,9 +2042,6 @@ string get_model_datafilename(string m, float sk, string fil)
 
 float get_model_parameters(string m, float sk)
 {
-       string fn, s, c;
-       float fh, i;
-
        get_model_parameters_modelname = string_null;
        get_model_parameters_modelskin = -1;
        get_model_parameters_name = string_null;
@@ -2047,13 +2052,17 @@ float get_model_parameters(string m, float sk)
        get_model_parameters_desc = string_null;
        get_model_parameters_bone_upperbody = string_null;
        get_model_parameters_bone_weapon = string_null;
-       for(i = 0; i < MAX_AIM_BONES; ++i)
+       for(int i = 0; i < MAX_AIM_BONES; ++i)
        {
                get_model_parameters_bone_aim[i] = string_null;
                get_model_parameters_bone_aimweight[i] = 0;
        }
        get_model_parameters_fixbone = 0;
 
+#ifndef MENUQC
+       MUTATOR_CALLHOOK(ClearModelParams);
+#endif
+
        if (!m)
                return 1;
 
@@ -2070,8 +2079,8 @@ float get_model_parameters(string m, float sk)
                m = substring(m, 0, -7);
        }
 
-       fn = get_model_datafilename(m, sk, "txt");
-       fh = fopen(fn, FILE_READ);
+       string fn = get_model_datafilename(m, sk, "txt");
+       int fh = fopen(fn, FILE_READ);
        if(fh < 0)
        {
                sk = 0;
@@ -2083,6 +2092,7 @@ float get_model_parameters(string m, float sk)
 
        get_model_parameters_modelname = m;
        get_model_parameters_modelskin = sk;
+       string s, c;
        while((s = fgets(fh)))
        {
                if(s == "")
@@ -2114,7 +2124,10 @@ float get_model_parameters(string m, float sk)
                        get_model_parameters_bone_upperbody = s;
                if(c == "bone_weapon")
                        get_model_parameters_bone_weapon = s;
-               for(i = 0; i < MAX_AIM_BONES; ++i)
+       #ifndef MENUQC
+               MUTATOR_CALLHOOK(GetModelParams, c, s);
+       #endif
+               for(int i = 0; i < MAX_AIM_BONES; ++i)
                        if(c == strcat("bone_aim", ftos(i)))
                        {
                                get_model_parameters_bone_aimweight[i] = stof(car(s));
@@ -2139,7 +2152,7 @@ float get_model_parameters(string m, float sk)
 
 vector vec2(vector v)
 {
-       v_z = 0;
+       v.z = 0;
        return v;
 }
 
@@ -2151,9 +2164,9 @@ vector NearestPointOnBox(entity box, vector org)
        m1 = box.mins + box.origin;
        m2 = box.maxs + box.origin;
 
-       nearest_x = bound(m1_x, org.x, m2_x);
-       nearest_y = bound(m1_y, org.y, m2_y);
-       nearest_z = bound(m1_z, org.z, m2_z);
+       nearest.x = bound(m1_x, org.x, m2_x);
+       nearest.y = bound(m1_y, org.y, m2_y);
+       nearest.z = bound(m1_z, org.z, m2_z);
 
        return nearest;
 }
@@ -2230,30 +2243,6 @@ float u8_strsize(string s)
        return l;
 }
 
-// translation helpers
-string language_filename(string s)
-{
-       string fn;
-       float fh;
-       fn = prvm_language;
-       if(fn == "" || fn == "dump")
-               return s;
-       fn = strcat(s, ".", fn);
-       if((fh = fopen(fn, FILE_READ)) >= 0)
-       {
-               fclose(fh);
-               return fn;
-       }
-       return s;
-}
-string CTX(string s)
-{
-       float p = strstrofs(s, "^", 0);
-       if(p < 0)
-               return s;
-       return substring(s, p+1, -1);
-}
-
 // x-encoding (encoding as zero length invisible string)
 const string XENCODE_2  = "xX";
 const string XENCODE_22 = "0123456789abcdefABCDEF";
@@ -2288,7 +2277,7 @@ float xdecode(string s)
        return ((a * 22 + b) * 22 + c) * 22 + d;
 }
 
-float lowestbit(int f)
+int lowestbit(int f)
 {
        f &= ~(f * 2);
        f &= ~(f * 4);
@@ -2317,32 +2306,10 @@ string MakeConsoleSafe(string input)
        return input;
 }
 
-#ifndef MENUQC
-// get true/false value of a string with multiple different inputs
-float InterpretBoolean(string input)
-{
-       switch(strtolower(input))
-       {
-               case "yes":
-               case "true":
-               case "on":
-                       return TRUE;
-
-               case "no":
-               case "false":
-               case "off":
-                       return FALSE;
-
-               default: return stof(input);
-       }
-}
-#endif
-
 #ifdef CSQC
 entity ReadCSQCEntity()
 {
-       float f;
-       f = ReadShort();
+       int f = ReadShort();
        if(f == 0)
                return world;
        return findfloat(world, entnum, f);
@@ -2362,7 +2329,7 @@ void m_shutdown()
 {
        if(shutdown_running)
        {
-               print("Recursive shutdown detected! Only restoring cvars...\n");
+               LOG_INFO("Recursive shutdown detected! Only restoring cvars...\n");
        }
        else
        {
@@ -2458,25 +2425,25 @@ float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float x)
 float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
 {
        if(startspeedfactor < 0 || endspeedfactor < 0)
-               return FALSE;
+               return false;
 
        /*
        // if this is the case, the possible zeros of the first derivative are outside
        // 0..1
        We can calculate this condition as condition
        if(se <= 3)
-               return TRUE;
+               return true;
        */
 
        // better, see below:
        if(startspeedfactor <= 3 && endspeedfactor <= 3)
-               return TRUE;
+               return true;
 
        // if this is the case, the first derivative has no zeros at all
        float se = startspeedfactor + endspeedfactor;
        float s_e = startspeedfactor - endspeedfactor;
        if(3 * (se - 4) * (se - 4) + s_e * s_e <= 12) // an ellipse
-               return TRUE;
+               return true;
 
        // Now let s <= 3, s <= 3, s+e >= 3 (triangle) then we get se <= 6 (top right corner).
        // we also get s_e <= 6 - se
@@ -2484,7 +2451,7 @@ float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
        // is quadratic, has value 12 at 3 and 6, and value < 12 in between.
        // Therefore, above "better" check works!
 
-       return FALSE;
+       return false;
 
        // known good cases:
        // (0, [0..3])
@@ -2534,11 +2501,11 @@ void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t
 
        // start with a 1-element queue
        queue_start = queue_end = e;
-       queue_end.fld = world;
+       queue_end.(fld) = world;
        queue_end.FindConnectedComponent_processing = 1;
 
        // for each queued item:
-       for(0; queue_start; queue_start = queue_start.fld)
+       for (; queue_start; queue_start = queue_start.(fld))
        {
                // find all neighbors of queue_start
                entity t;
@@ -2549,16 +2516,16 @@ void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t
                        if(iscon(t, queue_start, pass))
                        {
                                // it is connected? ADD IT. It will look for neighbors soon too.
-                               queue_end.fld = t;
+                               queue_end.(fld) = t;
                                queue_end = t;
-                               queue_end.fld = world;
+                               queue_end.(fld) = world;
                                queue_end.FindConnectedComponent_processing = 1;
                        }
                }
        }
 
        // unmark
-       for(queue_start = e; queue_start; queue_start = queue_start.fld)
+       for (queue_start = e; queue_start; queue_start = queue_start.(fld))
                queue_start.FindConnectedComponent_processing = 0;
 }
 
@@ -2586,29 +2553,6 @@ vector get_corner_position(entity box, float corner)
 }
 #endif
 
-// todo: this sucks, lets find a better way to do backtraces?
-void backtrace(string msg)
-{
-       float dev, war;
-       #ifdef SVQC
-       dev = autocvar_developer;
-       war = autocvar_prvm_backtraceforwarnings;
-       #else
-       dev = cvar("developer");
-       war = cvar("prvm_backtraceforwarnings");
-       #endif
-       cvar_set("developer", "1");
-       cvar_set("prvm_backtraceforwarnings", "1");
-       print("\n");
-       print("--- CUT HERE ---\nWARNING: ");
-       print(msg);
-       print("\n");
-       remove(world); // isn't there any better way to cause a backtrace?
-       print("\n--- CUT UNTIL HERE ---\n");
-       cvar_set("developer", ftos(dev));
-       cvar_set("prvm_backtraceforwarnings", ftos(war));
-}
-
 // color code replace, place inside of sprintf and parse the string
 string CCR(string input)
 {
@@ -2634,9 +2578,9 @@ string CCR(string input)
 vector vec3(float x, float y, float z)
 {
        vector v;
-       v_x = x;
-       v_y = y;
-       v_z = z;
+       v.x = x;
+       v.y = y;
+       v.z = z;
        return v;
 }
 
@@ -2644,7 +2588,7 @@ vector vec3(float x, float y, float z)
 vector animfixfps(entity e, vector a, vector b)
 {
        // multi-frame anim: keep as-is
-       if(a_y == 1)
+       if(a.y == 1)
        {
                float dur;
                dur = frameduration(e.modelindex, a.x);
@@ -2654,7 +2598,7 @@ vector animfixfps(entity e, vector a, vector b)
                        dur = frameduration(e.modelindex, a.x);
                }
                if(dur > 0)
-                       a_z = 1.0 / dur;
+                       a.z = 1.0 / dur;
        }
        return a;
 }
@@ -2663,7 +2607,7 @@ vector animfixfps(entity e, vector a, vector b)
 #ifdef SVQC
 void dedicated_print(string input) // print(), but only print if the server is not local
 {
-       if(server_is_dedicated) { print(input); }
+       if(server_is_dedicated) { LOG_INFO(input); }
 }
 #endif
 
@@ -2780,7 +2724,7 @@ float Announcer_PickNumber(float type, float num)
 #endif
 
 #ifndef MENUQC
-float Mod_Q1BSP_SuperContentsFromNativeContents(float nativecontents)
+int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents)
 {
        switch(nativecontents)
        {
@@ -2800,7 +2744,7 @@ float Mod_Q1BSP_SuperContentsFromNativeContents(float nativecontents)
        return 0;
 }
 
-float Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
+int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
 {
        if(supercontents & (DPCONTENTS_SOLID | DPCONTENTS_BODY))
                return CONTENT_SOLID;