X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Fmiscfunctions.qc;h=8bee032385d1c222a737f3d467cf40c01b9aa12d;hb=f1935c7e3b9fab12d142cb10b9f153d8e770aed2;hp=0cdfb0f8e380f8ca8fa4ba9c1446e69595078cc8;hpb=cfc97de2f89e06a0dd538202d4073c4aed16173e;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index 0cdfb0f8e..8bee03238 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -560,19 +560,12 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map 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) return e.origin; @@ -621,3 +614,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; +} +