1 #include "miscfunctions.qh"
7 #include "../common/command/generic.qh"
9 #include "../common/teams.qh"
10 #include "../common/urllib.qh"
11 #include "../common/util.qh"
13 #include "../csqcmodellib/cl_model.qh"
15 #include "../warpzonelib/mathlib.qh"
23 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
25 if(prev != e.sort_prev)
26 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
30 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
32 if(prev != e.sort_prev)
33 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
38 float RegisterPlayer(entity player)
42 for(pl = players.sort_next; pl; pl = pl.sort_next)
44 error("Player already registered!");
45 player.sort_next = players.sort_next;
46 player.sort_prev = players;
48 players.sort_next.sort_prev = player;
49 players.sort_next = player;
54 void RemovePlayer(entity player)
59 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
64 error("Trying to remove a player which is not in the playerlist!");
67 parent.sort_next = player.sort_next;
69 player.sort_next.sort_prev = parent;
73 void MoveToLast(entity e)
85 float RegisterTeam(entity Team)
89 for(tm = teams.sort_next; tm; tm = tm.sort_next)
91 error("Team already registered!");
92 Team.sort_next = teams.sort_next;
93 Team.sort_prev = teams;
95 teams.sort_next.sort_prev = Team;
96 teams.sort_next = Team;
97 if(Team.team && Team.team != NUM_SPECTATOR)
103 void RemoveTeam(entity Team)
108 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
113 print(_("Trying to remove a team which is not in the teamlist!"));
116 parent.sort_next = Team.sort_next;
118 Team.sort_next.sort_prev = parent;
119 if(Team.team && Team.team != NUM_SPECTATOR)
124 entity GetTeam(int Team, bool add)
126 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
128 return teamslots[num];
138 vector HUD_GetFontsize(string cvarname)
141 v = stov(cvar_string(cvarname));
150 float PreviewExists(string name)
152 if(autocvar_cl_readpicture_force)
155 if (fexists(strcat(name, ".tga"))) return true;
156 if (fexists(strcat(name, ".png"))) return true;
157 if (fexists(strcat(name, ".jpg"))) return true;
158 if (fexists(strcat(name, ".pcx"))) return true;
163 vector rotate(vector v, float a)
166 // FTEQCC SUCKS AGAIN
167 w.x = v.x * cos(a) + v.y * sin(a);
168 w.y = -1 * v.x * sin(a) + v.y * cos(a);
172 string ColorTranslateRGB(string s)
174 if(ColorTranslateMode & 1)
175 return strdecolorize(s);
180 // decolorizes and team colors the player name when needed
181 string playername(string thename, float teamid)
186 t = Team_ColorCode(teamid);
187 return strcat(t, strdecolorize(thename));
190 return strdecolorize(thename);
193 float cvar_or(string cv, float v)
203 vector project_3d_to_2d(vector vec)
205 vec = cs_project(vec);
206 if(cs_project_is_b0rked > 0)
208 vec.x *= vid_conwidth / vid_width;
209 vec.y *= vid_conheight / vid_height;
214 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
218 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
220 return 1.2 / (1.2 - fadelerp);
223 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
225 boxsize.x *= boxxsizefactor; // easier interface for text
226 return boxsize * (0.5 * (1 - sz));
229 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
231 vector line_dim = '0 0 0';
233 // left and right lines
235 line_dim.x = thickness;
237 drawfill(pos, line_dim, color, theAlpha, drawflag);
238 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
240 // upper and lower lines
242 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
243 line_dim.y = thickness;
244 drawfill(pos, line_dim, color, theAlpha, drawflag);
245 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
248 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
250 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
251 end_pos = pos + area;
253 current_pos.y = pos.y;
254 while (current_pos.y < end_pos.y)
256 current_pos.x = pos.x;
257 while (current_pos.x < end_pos.x)
259 new_size.x = min(sz.x, end_pos.x - current_pos.x);
260 new_size.y = min(sz.y, end_pos.y - current_pos.y);
261 ratio.x = new_size.x / sz.x;
262 ratio.y = new_size.y / sz.y;
263 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
264 current_pos.x += sz.x;
266 current_pos.y += sz.y;
270 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
273 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
275 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
278 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
280 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
281 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
284 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
285 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
286 SET_POS_AND_SZ_Y_ASPECT(false);
287 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
290 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
291 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
292 SET_POS_AND_SZ_Y_ASPECT(true);
293 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
296 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
299 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
301 drawfontscale = sz * '1 1 0';
302 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
303 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);
305 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
307 drawfontscale = '1 1 0';
310 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
311 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
312 SET_POS_AND_SZ_Y_ASPECT(false);
313 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
316 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
319 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
321 drawfontscale = sz * '1 1 0';
322 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
323 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);
324 drawfontscale = '1 1 0';
327 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
328 SET_POS_AND_SZ_Y_ASPECT(true);
329 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
332 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
333 float PolyDrawModelSurface(entity e, float i_s)
339 tex = getsurfacetexture(e, i_s);
341 return 0; // this is beyond the last one
342 n_t = getsurfacenumtriangles(e, i_s);
343 for(i_t = 0; i_t < n_t; ++i_t)
345 tri = getsurfacetriangle(e, i_s, i_t);
346 R_BeginPolygon(tex, 0);
347 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
348 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
349 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
354 void PolyDrawModel(entity e)
357 for(i_s = 0; ; ++i_s)
358 if(!PolyDrawModelSurface(e, i_s))
362 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
365 vector ringsize, v, t;
366 ringsize = radi * '1 1 0';
368 x = cos(f * 2 * M_PI);
369 y = sin(f * 2 * M_PI);
370 q = fabs(x) + fabs(y);
376 // draw full rectangle
377 R_BeginPolygon(pic, drawflag);
378 v = centre; t = '0.5 0.5 0';
379 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
380 R_PolygonVertex(v, t, rgb, a);
382 v = centre; t = '0.5 0.5 0';
383 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
384 R_PolygonVertex(v, t, rgb, a);
386 v = centre; t = '0.5 0.5 0';
387 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
388 R_PolygonVertex(v, t, rgb, a);
390 v = centre; t = '0.5 0.5 0';
391 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
392 R_PolygonVertex(v, t, rgb, a);
398 R_BeginPolygon(pic, drawflag);
399 v = centre; t = '0.5 0.5 0';
400 R_PolygonVertex(v, t, rgb, a);
402 v = centre; t = '0.5 0.5 0';
403 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
404 R_PolygonVertex(v, t, rgb, a);
409 // draw upper and first triangle
410 R_BeginPolygon(pic, drawflag);
411 v = centre; t = '0.5 0.5 0';
412 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
413 R_PolygonVertex(v, t, rgb, a);
415 v = centre; t = '0.5 0.5 0';
416 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
417 R_PolygonVertex(v, t, rgb, a);
419 v = centre; t = '0.5 0.5 0';
420 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
421 R_PolygonVertex(v, t, rgb, a);
423 R_BeginPolygon(pic, drawflag);
424 v = centre; t = '0.5 0.5 0';
425 R_PolygonVertex(v, t, rgb, a);
427 v = centre; t = '0.5 0.5 0';
428 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
429 R_PolygonVertex(v, t, rgb, a);
431 v = centre; t = '0.5 0.5 0';
432 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
433 R_PolygonVertex(v, t, rgb, a);
441 // draw upper triangle
442 R_BeginPolygon(pic, drawflag);
443 v = centre; t = '0.5 0.5 0';
444 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
445 R_PolygonVertex(v, t, rgb, a);
447 v = centre; t = '0.5 0.5 0';
448 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
449 R_PolygonVertex(v, t, rgb, a);
451 v = centre; t = '0.5 0.5 0';
452 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
453 R_PolygonVertex(v, t, rgb, a);
459 R_BeginPolygon(pic, drawflag);
460 v = centre; t = '0.5 0.5 0';
461 R_PolygonVertex(v, t, rgb, a);
463 v = centre; t = '0.5 0.5 0';
464 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
465 R_PolygonVertex(v, t, rgb, a);
470 // draw first triangle
471 R_BeginPolygon(pic, drawflag);
472 v = centre; t = '0.5 0.5 0';
473 R_PolygonVertex(v, t, rgb, a);
475 v = centre; t = '0.5 0.5 0';
476 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
477 R_PolygonVertex(v, t, rgb, a);
479 v = centre; t = '0.5 0.5 0';
480 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
481 R_PolygonVertex(v, t, rgb, a);
492 R_BeginPolygon(pic, drawflag);
493 v = centre; t = '0.5 0.5 0';
494 R_PolygonVertex(v, t, rgb, a);
496 v = centre; t = '0.5 0.5 0';
497 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
498 R_PolygonVertex(v, t, rgb, a);
504 v = centre; t = '0.5 0.5 0';
505 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
506 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
507 R_PolygonVertex(v, t, rgb, a);
512 vector getplayerorigin(int pl)
516 e = CSQCModel_server2csqc(pl + 1);
520 e = entcs_receiver[pl];
524 return GETPLAYERORIGIN_ERROR;
527 float getplayeralpha(float pl)
531 e = CSQCModel_server2csqc(pl + 1);
538 vector getcsqcplayercolor(float pl)
542 e = CSQCModel_server2csqc(pl);
546 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
552 float getplayerisdead(float pl)
556 e = CSQCModel_server2csqc(pl + 1);
558 return e.csqcmodel_isdead;
563 void URI_Get_Callback(int id, float status, string data)
565 if(url_URI_Get_Callback(id, status, data))
569 else if (id == URI_GET_DISCARD)
573 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
576 Curl_URI_Get_Callback(id, status, data);
580 printf("Received HTTP request data for an invalid id %d.\n", id);
584 void draw_beginBoldFont()
586 drawfont = FONT_USER+2;
589 void draw_endBoldFont()
591 drawfont = FONT_USER+1;
594 void Accuracy_LoadLevels()
596 if(autocvar_accuracy_color_levels != acc_color_levels)
599 strunzone(acc_color_levels);
600 acc_color_levels = strzone(autocvar_accuracy_color_levels);
601 acc_levels = tokenize_console(acc_color_levels);
602 if(acc_levels > MAX_ACCURACY_LEVELS)
603 acc_levels = MAX_ACCURACY_LEVELS;
605 print("Warning: accuracy_color_levels must contain at least 2 values\n");
608 for(i = 0; i < acc_levels; ++i)
609 acc_lev[i] = stof(argv(i)) / 100.0;
613 void Accuracy_LoadColors()
615 if(time > acc_col_loadtime)
619 for(i = 0; i < acc_levels; ++i)
620 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
621 acc_col_loadtime = time + 2;
625 vector Accuracy_GetColor(float accuracy)
630 return '0 0 0'; // return black, can't determine the right color
632 // find the max level lower than acc
633 int j = acc_levels-1;
634 while(j && accuracy < acc_lev[j])
637 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
638 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
640 color = color + factor * (acc_col[j+1] - color);