]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
Merge remote-tracking branch 'origin/master' into samual/notification_rewrite
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index ff43b29d20b51a3e0e1cd7540d9f87bcb69e262e..c56ee1d2ff67809a0ba6dc9c077bdbf0648edea6 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);
@@ -217,7 +215,7 @@ vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float b
 
 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;
@@ -236,7 +234,7 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa
 
 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;
@@ -623,3 +621,61 @@ 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;
+}
+