]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
add _animblend_fixbone 3
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index 84b6d3da6d21615017f375e2d763ad3dcb2cb872..9e5505b0a5bb5c47c0b1af68e5ff225623332985 100644 (file)
@@ -1,5 +1,3 @@
-var float(string text, float handleColors, vector fontSize) stringwidth;
-
 entity players;
 entity teams;
 
@@ -149,7 +147,7 @@ float PreviewExists(string name)
 
 vector rotate(vector v, float a)
 {
-       vector w;
+       vector w = '0 0 0';
        // FTEQCC SUCKS AGAIN
        w_x =      v_x * cos(a) + v_y * sin(a);
        w_y = -1 * v_x * sin(a) + v_y * cos(a);
@@ -229,28 +227,28 @@ vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float b
        return boxsize * (0.5 * (1 - sz));
 }
 
-void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)
+void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
 {
-       vector line_dim;
+       vector line_dim = '0 0 0';
 
        // left and right lines
        pos_x -= thickness;
        line_dim_x = thickness;
        line_dim_y = dim_y;
-       drawfill(pos, line_dim, color, alpha, drawflag);
-       drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);
+       drawfill(pos, line_dim, color, theAlpha, drawflag);
+       drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
 
        // upper and lower lines
        pos_y -= thickness;
        line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
        line_dim_y = thickness;
-       drawfill(pos, line_dim, color, alpha, drawflag);
-       drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);
+       drawfill(pos, line_dim, color, theAlpha, drawflag);
+       drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
 }
 
-void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)
+void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
 {
-       vector current_pos, end_pos, new_size, ratio;
+       vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
        end_pos = pos + area;
 
        current_pos_y = pos_y;
@@ -263,7 +261,7 @@ void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color,
                        new_size_y = min(sz_y, end_pos_y - current_pos_y);
                        ratio_x = new_size_x / sz_x;
                        ratio_y = new_size_y / sz_y;
-                       drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);
+                       drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
                        current_pos_x += sz_x;
                }
                current_pos_y += sz_y;
@@ -276,56 +274,60 @@ var vector _drawpic_imgsize;
 var vector _drawpic_sz;
 var float _drawpic_oldsz;
 var string _drawpic_picpath;
-#define drawpic_aspect(pos,pic,mySize,color,alpha,drawflag)\
+#define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
        do {\
                _drawpic_imgsize = draw_getimagesize(pic);\
-               _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
-               _drawpic_sz = mySize;\
-               if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
-                       _drawpic_oldsz = _drawpic_sz_x;\
-                       _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
-                       drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
-               } else {\
-                       _drawpic_oldsz = _drawpic_sz_y;\
-                       _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
-                       drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
+               if(_drawpic_imgsize != '0 0 0') {\
+                       _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
+                       _drawpic_sz = mySize;\
+                       if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
+                               _drawpic_oldsz = _drawpic_sz_x;\
+                               _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
+                               if(_drawpic_sz_x)\
+                                       drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
+                       } else {\
+                               _drawpic_oldsz = _drawpic_sz_y;\
+                               _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
+                               if(_drawpic_sz_y)\
+                                       drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
+                       }\
                }\
        } while(0)
 
 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
-#define drawpic_aspect_skin(pos,pic,sz,color,alpha,drawflag)\
+#define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
        do{\
                _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
                if(precache_pic(_drawpic_picpath) == "") {\
                        _drawpic_picpath = strcat("gfx/hud/default/", pic);\
                }\
-               drawpic_aspect(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
+               drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
                _drawpic_picpath = string_null;\
        } while(0)
 
 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
-#define drawpic_skin(pos,pic,sz,color,alpha,drawflag)\
+#define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
        do{\
                _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
                if(precache_pic(_drawpic_picpath) == "") {\
                        _drawpic_picpath = strcat("gfx/hud/default/", pic);\
                }\
-               drawpic(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
+               drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
                _drawpic_picpath = string_null;\
        } while(0)
 
-void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
+void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-       drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
+       drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, theAlpha * (1 - fadelerp), flag);
 }
 
-void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
+void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
-       drawpic_aspect_skin_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
-       drawpic_skin(position, pic, scale, rgb, alpha * fadelerp, flag);
+       drawpic_aspect_skin_expanding(position, pic, scale, rgb, theAlpha, flag, fadelerp);
+       drawpic_skin(position, pic, scale, rgb, theAlpha * fadelerp, flag);
 }
 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
        float textaspect, oldsz;\
@@ -341,26 +343,26 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale
        }
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
-void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {
+void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
        SET_POS_AND_SZ_Y_ASPECT(FALSE)
-       drawstring(pos, text, '1 1 0' * sz_y, color, alpha, drawflag);
+       drawstring(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag);
 }
 
 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
-void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float alpha, float drawflag) {
+void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
        SET_POS_AND_SZ_Y_ASPECT(TRUE)
-       drawcolorcodedstring(pos, text, '1 1 0' * sz_y, alpha, drawflag);
+       drawcolorcodedstring(pos, text, '1 1 0' * sz_y, theAlpha, drawflag);
 }
 
 vector drawfontscale;
-void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
+void drawstring_expanding(vector position, string text, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
        drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-       drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, alpha * (1 - fadelerp), flag);
+       drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag);
        // width parameter:
        //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
        //    SIZE1
@@ -368,25 +370,25 @@ void drawstring_expanding(vector position, string text, vector scale, vector rgb
 }
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
-void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float alpha, float drawflag, float fadelerp) {
+void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
        SET_POS_AND_SZ_Y_ASPECT(FALSE)
-       drawstring_expanding(pos, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
+       drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
 }
 
-void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
+void drawcolorcodedstring_expanding(vector position, string text, vector scale, float theAlpha, float flag, float fadelerp)
 {
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
        drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), alpha * (1 - fadelerp), flag);
+       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag);
        drawfontscale = '1 1 0';
 }
 
-void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float alpha, float drawflag, float fadelerp) {
+void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
        SET_POS_AND_SZ_Y_ASPECT(TRUE)
-       drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
+       drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, theAlpha, drawflag, fadelerp);
 }
 
 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
@@ -575,9 +577,15 @@ vector getplayerorigin(float pl)
        string s;
        entity e;
 
+       e = CSQCModel_server2csqc(pl + 1);
+       if(e)
+               return e.origin;
+
+#ifndef NO_LEGACY_NETWORKING
        s = getplayerkeyvalue(pl, "TEMPHACK_origin");
        if(s != "")
                return stov(s);
+#endif
 
        e = entcs_receiver[pl];
        if(e)
@@ -585,3 +593,103 @@ vector getplayerorigin(float pl)
 
        return GETPLAYERORIGIN_ERROR;
 }
+
+float getplayerisdead(float pl)
+{
+       entity e;
+       
+       e = CSQCModel_server2csqc(pl + 1);
+       if(e)
+               return e.csqcmodel_isdead;
+       
+       return FALSE;
+}
+
+void URI_Get_Callback(float id, float status, string data)
+{
+       if(url_URI_Get_Callback(id, status, data))
+       {
+               // handled
+       }
+       else if (id == URI_GET_DISCARD)
+       {
+               // discard
+       }
+       else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
+       {
+               // sv_cmd curl
+               Curl_URI_Get_Callback(id, status, data);
+       }
+       else
+       {
+               print(sprintf(_("Received HTTP request data for an invalid id %d.\n"), id));
+       }
+}
+
+void draw_beginBoldFont()
+{
+       drawfont = FONT_USER+2;
+}
+
+void draw_endBoldFont()
+{
+       drawfont = FONT_USER+1;
+}
+
+
+#define MAX_ACCURACY_LEVELS 10
+float acc_lev[MAX_ACCURACY_LEVELS];
+vector acc_col[MAX_ACCURACY_LEVELS];
+float acc_col_loadtime;
+float acc_levels;
+string acc_color_levels;
+void Accuracy_LoadLevels()
+{
+       float i;
+       if(autocvar_accuracy_color_levels != acc_color_levels)
+       {
+               if(acc_color_levels)
+                       strunzone(acc_color_levels);
+               acc_color_levels = strzone(autocvar_accuracy_color_levels);
+               acc_levels = tokenize_console(acc_color_levels);
+               if(acc_levels > MAX_ACCURACY_LEVELS)
+                       acc_levels = MAX_ACCURACY_LEVELS;
+               if(acc_levels < 2)
+                       print("Warning: accuracy_color_levels must contain at least 2 values\n");
+
+               for(i = 0; i < acc_levels; ++i)
+                       acc_lev[i] = stof(argv(i)) / 100.0;
+       }
+}
+
+void Accuracy_LoadColors()
+{
+       float i;
+       if(time > acc_col_loadtime)
+       if(acc_levels >= 2)
+       {
+               for(i = 0; i < acc_levels; ++i)
+                       acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
+               acc_col_loadtime = time + 2;
+       }
+}
+
+vector Accuracy_GetColor(float accuracy)
+{
+       float j, factor;
+       vector color;
+       if(acc_levels < 2)
+               return '0 0 0'; // return black, can't determine the right color
+
+       // find the max level lower than acc
+       j = acc_levels-1;
+       while(j && accuracy < acc_lev[j])
+               --j;
+
+       // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
+       factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
+       color = acc_col[j];
+       color = color + factor * (acc_col[j+1] - color);
+       return color;
+}
+