X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fclient%2Fmiscfunctions.qc;h=b1dcce0ee25d3cdbe6370dd9349fdfbdb29be2e1;hp=0cdfb0f8e380f8ca8fa4ba9c1446e69595078cc8;hb=25d031b3b379ce9d87096fa791019242ffadce24;hpb=80ea2c26461cab2b2992f79643eaf59aacb7cda7 diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index 0cdfb0f8e..b1dcce0ee 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -108,10 +108,10 @@ entity GetTeam(float Team, float add) { float num; entity tm; - num = (Team == FL_SPECTATOR) ? 16 : Team; + num = (Team == NUM_SPECTATOR) ? 16 : Team; if(teamslots[num]) return teamslots[num]; - if not(add) + if (!add) return world; tm = spawn(); tm.team = Team; @@ -302,18 +302,18 @@ var string _drawpic_picpath; _drawpic_picpath = string_null;\ } while(0) -void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp) +void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, 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, theAlpha * (1 - fadelerp), flag); + drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag); } -void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp) +void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp) { - drawpic_aspect_skin_expanding(position, pic, scale, rgb, theAlpha, flag, fadelerp); - drawpic_skin(position, pic, scale, rgb, theAlpha * fadelerp, flag); + drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp); + drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag); } #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\ float textaspect, oldsz;\ @@ -341,14 +341,14 @@ void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAl } vector drawfontscale; -void drawstring_expanding(vector position, string text, vector scale, vector rgb, float theAlpha, float flag, float fadelerp) +void drawstring_expanding(vector position, string text, vector theScale, 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, theAlpha * (1 - fadelerp), flag); + drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, FALSE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag); // width parameter: // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz) // SIZE1 @@ -361,14 +361,14 @@ void drawstring_aspect_expanding(vector pos, string text, vector sz, vector colo drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp); } -void drawcolorcodedstring_expanding(vector position, string text, vector scale, float theAlpha, float flag, float fadelerp) +void drawcolorcodedstring_expanding(vector position, string text, vector theScale, 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), theAlpha * (1 - fadelerp), flag); + drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, TRUE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag); drawfontscale = '1 1 0'; } @@ -385,7 +385,7 @@ float PolyDrawModelSurface(entity e, float i_s) vector tri; string tex; tex = getsurfacetexture(e, i_s); - if not(tex) + if (!tex) return 0; // this is beyond the last one n_t = getsurfacenumtriangles(e, i_s); for(i_t = 0; i_t < n_t; ++i_t) @@ -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; @@ -580,14 +573,25 @@ vector getplayerorigin(float pl) return GETPLAYERORIGIN_ERROR; } +float getplayeralpha(float pl) +{ + entity e; + + e = CSQCModel_server2csqc(pl + 1); + if(e) + return e.alpha; + + return 1; +} + float getplayerisdead(float pl) { entity e; - + e = CSQCModel_server2csqc(pl + 1); if(e) return e.csqcmodel_isdead; - + return FALSE; } @@ -608,7 +612,7 @@ void URI_Get_Callback(float id, float status, string data) } else { - print(sprintf(_("Received HTTP request data for an invalid id %d.\n"), id)); + print(sprintf("Received HTTP request data for an invalid id %d.\n", id)); } } @@ -621,3 +625,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; +} +