1 #include "miscfunctions.qh"
3 #include "autocvars.qh"
9 #include "../common/command/generic.qh"
11 #include "../common/teams.qh"
12 #include "../common/urllib.qh"
13 #include "../common/util.qh"
15 #include "../csqcmodellib/cl_model.qh"
17 #include "../warpzonelib/mathlib.qh"
25 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
27 if(prev != e.sort_prev)
28 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
32 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
34 if(prev != e.sort_prev)
35 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
40 float RegisterPlayer(entity player)
44 for(pl = players.sort_next; pl; pl = pl.sort_next)
46 error("Player already registered!");
47 player.sort_next = players.sort_next;
48 player.sort_prev = players;
50 players.sort_next.sort_prev = player;
51 players.sort_next = player;
56 void RemovePlayer(entity player)
61 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
66 error("Trying to remove a player which is not in the playerlist!");
69 parent.sort_next = player.sort_next;
71 player.sort_next.sort_prev = parent;
75 void MoveToLast(entity e)
87 float RegisterTeam(entity Team)
91 for(tm = teams.sort_next; tm; tm = tm.sort_next)
93 error("Team already registered!");
94 Team.sort_next = teams.sort_next;
95 Team.sort_prev = teams;
97 teams.sort_next.sort_prev = Team;
98 teams.sort_next = Team;
99 if(Team.team && Team.team != NUM_SPECTATOR)
105 void RemoveTeam(entity Team)
110 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
115 print(_("Trying to remove a team which is not in the teamlist!"));
118 parent.sort_next = Team.sort_next;
120 Team.sort_next.sort_prev = parent;
121 if(Team.team && Team.team != NUM_SPECTATOR)
126 entity GetTeam(int Team, bool add)
128 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
130 return teamslots[num];
140 vector HUD_GetFontsize(string cvarname)
143 v = stov(cvar_string(cvarname));
152 float PreviewExists(string name)
154 if(autocvar_cl_readpicture_force)
157 if (fexists(strcat(name, ".tga"))) return true;
158 if (fexists(strcat(name, ".png"))) return true;
159 if (fexists(strcat(name, ".jpg"))) return true;
160 if (fexists(strcat(name, ".pcx"))) return true;
165 vector rotate(vector v, float a)
168 // FTEQCC SUCKS AGAIN
169 w.x = v.x * cos(a) + v.y * sin(a);
170 w.y = -1 * v.x * sin(a) + v.y * cos(a);
174 string ColorTranslateRGB(string s)
176 if(ColorTranslateMode & 1)
177 return strdecolorize(s);
182 // decolorizes and team colors the player name when needed
183 string playername(string thename, float teamid)
188 t = Team_ColorCode(teamid);
189 return strcat(t, strdecolorize(thename));
192 return strdecolorize(thename);
195 float cvar_or(string cv, float v)
205 vector project_3d_to_2d(vector vec)
207 vec = cs_project(vec);
208 if(cs_project_is_b0rked > 0)
210 vec.x *= vid_conwidth / vid_width;
211 vec.y *= vid_conheight / vid_height;
216 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
220 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
222 return 1.2 / (1.2 - fadelerp);
225 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
227 boxsize.x *= boxxsizefactor; // easier interface for text
228 return boxsize * (0.5 * (1 - sz));
231 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
233 vector line_dim = '0 0 0';
235 // left and right lines
237 line_dim.x = thickness;
239 drawfill(pos, line_dim, color, theAlpha, drawflag);
240 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
242 // upper and lower lines
244 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
245 line_dim.y = thickness;
246 drawfill(pos, line_dim, color, theAlpha, drawflag);
247 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
250 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
252 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
253 end_pos = pos + area;
255 current_pos.y = pos.y;
256 while (current_pos.y < end_pos.y)
258 current_pos.x = pos.x;
259 while (current_pos.x < end_pos.x)
261 new_size.x = min(sz.x, end_pos.x - current_pos.x);
262 new_size.y = min(sz.y, end_pos.y - current_pos.y);
263 ratio.x = new_size.x / sz.x;
264 ratio.y = new_size.y / sz.y;
265 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
266 current_pos.x += sz.x;
268 current_pos.y += sz.y;
272 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
275 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
277 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
280 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
282 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
283 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
286 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
287 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
288 SET_POS_AND_SZ_Y_ASPECT(false);
289 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
292 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
293 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
294 SET_POS_AND_SZ_Y_ASPECT(true);
295 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
298 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
301 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
303 drawfontscale = sz * '1 1 0';
304 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
305 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);
307 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
309 drawfontscale = '1 1 0';
312 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
313 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
314 SET_POS_AND_SZ_Y_ASPECT(false);
315 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
318 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
321 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
323 drawfontscale = sz * '1 1 0';
324 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
325 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);
326 drawfontscale = '1 1 0';
329 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
330 SET_POS_AND_SZ_Y_ASPECT(true);
331 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
334 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
335 float PolyDrawModelSurface(entity e, float i_s)
341 tex = getsurfacetexture(e, i_s);
343 return 0; // this is beyond the last one
344 n_t = getsurfacenumtriangles(e, i_s);
345 for(i_t = 0; i_t < n_t; ++i_t)
347 tri = getsurfacetriangle(e, i_s, i_t);
348 R_BeginPolygon(tex, 0);
349 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
350 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
351 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
356 void PolyDrawModel(entity e)
359 for(i_s = 0; ; ++i_s)
360 if(!PolyDrawModelSurface(e, i_s))
364 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
367 vector ringsize, v, t;
368 ringsize = radius * '1 1 0';
370 x = cos(f * 2 * M_PI);
371 y = sin(f * 2 * M_PI);
372 q = fabs(x) + fabs(y);
378 // draw full rectangle
379 R_BeginPolygon(pic, drawflag);
380 v = centre; t = '0.5 0.5 0';
381 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
382 R_PolygonVertex(v, t, rgb, a);
384 v = centre; t = '0.5 0.5 0';
385 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
386 R_PolygonVertex(v, t, rgb, a);
388 v = centre; t = '0.5 0.5 0';
389 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
390 R_PolygonVertex(v, t, rgb, a);
392 v = centre; t = '0.5 0.5 0';
393 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
394 R_PolygonVertex(v, t, rgb, a);
400 R_BeginPolygon(pic, drawflag);
401 v = centre; t = '0.5 0.5 0';
402 R_PolygonVertex(v, t, rgb, a);
404 v = centre; t = '0.5 0.5 0';
405 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
406 R_PolygonVertex(v, t, rgb, a);
411 // draw upper and first triangle
412 R_BeginPolygon(pic, drawflag);
413 v = centre; t = '0.5 0.5 0';
414 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
415 R_PolygonVertex(v, t, rgb, a);
417 v = centre; t = '0.5 0.5 0';
418 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
419 R_PolygonVertex(v, t, rgb, a);
421 v = centre; t = '0.5 0.5 0';
422 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
423 R_PolygonVertex(v, t, rgb, a);
425 R_BeginPolygon(pic, drawflag);
426 v = centre; t = '0.5 0.5 0';
427 R_PolygonVertex(v, t, rgb, a);
429 v = centre; t = '0.5 0.5 0';
430 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
431 R_PolygonVertex(v, t, rgb, a);
433 v = centre; t = '0.5 0.5 0';
434 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
435 R_PolygonVertex(v, t, rgb, a);
443 // draw upper triangle
444 R_BeginPolygon(pic, drawflag);
445 v = centre; t = '0.5 0.5 0';
446 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
447 R_PolygonVertex(v, t, rgb, a);
449 v = centre; t = '0.5 0.5 0';
450 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
451 R_PolygonVertex(v, t, rgb, a);
453 v = centre; t = '0.5 0.5 0';
454 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
455 R_PolygonVertex(v, t, rgb, a);
461 R_BeginPolygon(pic, drawflag);
462 v = centre; t = '0.5 0.5 0';
463 R_PolygonVertex(v, t, rgb, a);
465 v = centre; t = '0.5 0.5 0';
466 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
467 R_PolygonVertex(v, t, rgb, a);
472 // draw first triangle
473 R_BeginPolygon(pic, drawflag);
474 v = centre; t = '0.5 0.5 0';
475 R_PolygonVertex(v, t, rgb, a);
477 v = centre; t = '0.5 0.5 0';
478 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
479 R_PolygonVertex(v, t, rgb, a);
481 v = centre; t = '0.5 0.5 0';
482 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
483 R_PolygonVertex(v, t, rgb, a);
494 R_BeginPolygon(pic, drawflag);
495 v = centre; t = '0.5 0.5 0';
496 R_PolygonVertex(v, t, rgb, a);
498 v = centre; t = '0.5 0.5 0';
499 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
500 R_PolygonVertex(v, t, rgb, a);
506 v = centre; t = '0.5 0.5 0';
507 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
508 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
509 R_PolygonVertex(v, t, rgb, a);
514 vector getplayerorigin(int pl)
518 e = CSQCModel_server2csqc(pl + 1);
522 e = entcs_receiver[pl];
526 return GETPLAYERORIGIN_ERROR;
529 float getplayeralpha(float pl)
533 e = CSQCModel_server2csqc(pl + 1);
540 vector getcsqcplayercolor(float pl)
544 e = CSQCModel_server2csqc(pl);
548 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
554 float getplayerisdead(float pl)
558 e = CSQCModel_server2csqc(pl + 1);
560 return e.csqcmodel_isdead;
565 void URI_Get_Callback(int id, float status, string data)
567 if(url_URI_Get_Callback(id, status, data))
571 else if (id == URI_GET_DISCARD)
575 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
578 Curl_URI_Get_Callback(id, status, data);
582 printf("Received HTTP request data for an invalid id %d.\n", id);
586 void draw_beginBoldFont()
588 drawfont = FONT_USER+2;
591 void draw_endBoldFont()
593 drawfont = FONT_USER+1;
596 void Accuracy_LoadLevels()
598 if(autocvar_accuracy_color_levels != acc_color_levels)
601 strunzone(acc_color_levels);
602 acc_color_levels = strzone(autocvar_accuracy_color_levels);
603 acc_levels = tokenize_console(acc_color_levels);
604 if(acc_levels > MAX_ACCURACY_LEVELS)
605 acc_levels = MAX_ACCURACY_LEVELS;
607 print("Warning: accuracy_color_levels must contain at least 2 values\n");
610 for(i = 0; i < acc_levels; ++i)
611 acc_lev[i] = stof(argv(i)) / 100.0;
615 void Accuracy_LoadColors()
617 if(time > acc_col_loadtime)
621 for(i = 0; i < acc_levels; ++i)
622 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
623 acc_col_loadtime = time + 2;
627 vector Accuracy_GetColor(float accuracy)
632 return '0 0 0'; // return black, can't determine the right color
634 // find the max level lower than acc
635 int j = acc_levels-1;
636 while(j && accuracy < acc_lev[j])
639 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
640 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
642 color = color + factor * (acc_col[j+1] - color);