1 #include "miscfunctions.qh"
3 #include "../common/urllib.qh"
5 #include "../common/command/generic.qh"
13 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
15 if(prev != e.sort_prev)
16 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
20 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
22 if(prev != e.sort_prev)
23 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
28 float RegisterPlayer(entity player)
32 for(pl = players.sort_next; pl; pl = pl.sort_next)
34 error("Player already registered!");
35 player.sort_next = players.sort_next;
36 player.sort_prev = players;
38 players.sort_next.sort_prev = player;
39 players.sort_next = player;
44 void RemovePlayer(entity player)
49 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
54 error("Trying to remove a player which is not in the playerlist!");
57 parent.sort_next = player.sort_next;
59 player.sort_next.sort_prev = parent;
63 void MoveToLast(entity e)
75 float RegisterTeam(entity Team)
79 for(tm = teams.sort_next; tm; tm = tm.sort_next)
81 error("Team already registered!");
82 Team.sort_next = teams.sort_next;
83 Team.sort_prev = teams;
85 teams.sort_next.sort_prev = Team;
86 teams.sort_next = Team;
87 if(Team.team && Team.team != NUM_SPECTATOR)
93 void RemoveTeam(entity Team)
98 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
103 print(_("Trying to remove a team which is not in the teamlist!"));
106 parent.sort_next = Team.sort_next;
108 Team.sort_next.sort_prev = parent;
109 if(Team.team && Team.team != NUM_SPECTATOR)
114 entity GetTeam(int Team, bool add)
116 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
118 return teamslots[num];
128 vector HUD_GetFontsize(string cvarname)
131 v = stov(cvar_string(cvarname));
140 float PreviewExists(string name)
142 if(autocvar_cl_readpicture_force)
145 if (fexists(strcat(name, ".tga"))) return true;
146 if (fexists(strcat(name, ".png"))) return true;
147 if (fexists(strcat(name, ".jpg"))) return true;
148 if (fexists(strcat(name, ".pcx"))) return true;
153 vector rotate(vector v, float a)
156 // FTEQCC SUCKS AGAIN
157 w_x = v.x * cos(a) + v.y * sin(a);
158 w_y = -1 * v.x * sin(a) + v.y * cos(a);
162 string ColorTranslateRGB(string s)
164 if(ColorTranslateMode & 1)
165 return strdecolorize(s);
170 // decolorizes and team colors the player name when needed
171 string playername(string thename, float teamid)
176 t = Team_ColorCode(teamid);
177 return strcat(t, strdecolorize(thename));
180 return strdecolorize(thename);
183 float cvar_or(string cv, float v)
193 vector project_3d_to_2d(vector vec)
195 vec = cs_project(vec);
196 if(cs_project_is_b0rked > 0)
198 vec.x *= vid_conwidth / vid_width;
199 vec.y *= vid_conheight / vid_height;
204 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
208 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
210 return 1.2 / (1.2 - fadelerp);
213 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
215 boxsize.x *= boxxsizefactor; // easier interface for text
216 return boxsize * (0.5 * (1 - sz));
219 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
221 vector line_dim = '0 0 0';
223 // left and right lines
225 line_dim_x = thickness;
227 drawfill(pos, line_dim, color, theAlpha, drawflag);
228 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
230 // upper and lower lines
232 line_dim_x = dim.x + thickness * 2; // make upper and lower lines longer
233 line_dim_y = thickness;
234 drawfill(pos, line_dim, color, theAlpha, drawflag);
235 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
238 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
240 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
241 end_pos = pos + area;
243 current_pos_y = pos.y;
244 while (current_pos.y < end_pos.y)
246 current_pos_x = pos.x;
247 while (current_pos.x < end_pos.x)
249 new_size_x = min(sz.x, end_pos.x - current_pos.x);
250 new_size_y = min(sz.y, end_pos.y - current_pos.y);
251 ratio_x = new_size.x / sz.x;
252 ratio_y = new_size.y / sz.y;
253 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
254 current_pos.x += sz.x;
256 current_pos.y += sz.y;
260 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
263 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
265 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
268 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
270 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
271 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
274 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
275 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
276 SET_POS_AND_SZ_Y_ASPECT(false);
277 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
280 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
281 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
282 SET_POS_AND_SZ_Y_ASPECT(true);
283 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
286 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
289 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
291 drawfontscale = sz * '1 1 0';
292 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
293 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);
295 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
297 drawfontscale = '1 1 0';
300 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
301 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
302 SET_POS_AND_SZ_Y_ASPECT(false);
303 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
306 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
309 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
311 drawfontscale = sz * '1 1 0';
312 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
313 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);
314 drawfontscale = '1 1 0';
317 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
318 SET_POS_AND_SZ_Y_ASPECT(true);
319 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
322 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
323 float PolyDrawModelSurface(entity e, float i_s)
329 tex = getsurfacetexture(e, i_s);
331 return 0; // this is beyond the last one
332 n_t = getsurfacenumtriangles(e, i_s);
333 for(i_t = 0; i_t < n_t; ++i_t)
335 tri = getsurfacetriangle(e, i_s, i_t);
336 R_BeginPolygon(tex, 0);
337 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
338 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
339 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
344 void PolyDrawModel(entity e)
347 for(i_s = 0; ; ++i_s)
348 if(!PolyDrawModelSurface(e, i_s))
352 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
355 vector ringsize, v, t;
356 ringsize = radius * '1 1 0';
358 x = cos(f * 2 * M_PI);
359 y = sin(f * 2 * M_PI);
360 q = fabs(x) + fabs(y);
366 // draw full rectangle
367 R_BeginPolygon(pic, drawflag);
368 v = centre; t = '0.5 0.5 0';
369 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
370 R_PolygonVertex(v, t, rgb, a);
372 v = centre; t = '0.5 0.5 0';
373 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
374 R_PolygonVertex(v, t, rgb, a);
376 v = centre; t = '0.5 0.5 0';
377 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
378 R_PolygonVertex(v, t, rgb, a);
380 v = centre; t = '0.5 0.5 0';
381 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
382 R_PolygonVertex(v, t, rgb, a);
388 R_BeginPolygon(pic, drawflag);
389 v = centre; t = '0.5 0.5 0';
390 R_PolygonVertex(v, t, rgb, a);
392 v = centre; t = '0.5 0.5 0';
393 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
394 R_PolygonVertex(v, t, rgb, a);
399 // draw upper and first triangle
400 R_BeginPolygon(pic, drawflag);
401 v = centre; t = '0.5 0.5 0';
402 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
403 R_PolygonVertex(v, t, rgb, a);
405 v = centre; t = '0.5 0.5 0';
406 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
407 R_PolygonVertex(v, t, rgb, a);
409 v = centre; t = '0.5 0.5 0';
410 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
411 R_PolygonVertex(v, t, rgb, a);
413 R_BeginPolygon(pic, drawflag);
414 v = centre; t = '0.5 0.5 0';
415 R_PolygonVertex(v, t, rgb, a);
417 v = centre; t = '0.5 0.5 0';
418 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
419 R_PolygonVertex(v, t, rgb, a);
421 v = centre; t = '0.5 0.5 0';
422 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
423 R_PolygonVertex(v, t, rgb, a);
431 // draw upper triangle
432 R_BeginPolygon(pic, drawflag);
433 v = centre; t = '0.5 0.5 0';
434 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
435 R_PolygonVertex(v, t, rgb, a);
437 v = centre; t = '0.5 0.5 0';
438 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
439 R_PolygonVertex(v, t, rgb, a);
441 v = centre; t = '0.5 0.5 0';
442 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
443 R_PolygonVertex(v, t, rgb, a);
449 R_BeginPolygon(pic, drawflag);
450 v = centre; 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);
460 // draw first triangle
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);
469 v = centre; t = '0.5 0.5 0';
470 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
471 R_PolygonVertex(v, t, rgb, a);
482 R_BeginPolygon(pic, drawflag);
483 v = centre; t = '0.5 0.5 0';
484 R_PolygonVertex(v, t, rgb, a);
486 v = centre; t = '0.5 0.5 0';
487 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
488 R_PolygonVertex(v, t, rgb, a);
494 v = centre; t = '0.5 0.5 0';
495 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
496 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
497 R_PolygonVertex(v, t, rgb, a);
502 vector getplayerorigin(int pl)
506 e = CSQCModel_server2csqc(pl + 1);
510 e = entcs_receiver[pl];
514 return GETPLAYERORIGIN_ERROR;
517 float getplayeralpha(float pl)
521 e = CSQCModel_server2csqc(pl + 1);
528 vector getcsqcplayercolor(float pl)
532 e = CSQCModel_server2csqc(pl);
536 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
542 float getplayerisdead(float pl)
546 e = CSQCModel_server2csqc(pl + 1);
548 return e.csqcmodel_isdead;
553 void URI_Get_Callback(int id, float status, string data)
555 if(url_URI_Get_Callback(id, status, data))
559 else if (id == URI_GET_DISCARD)
563 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
566 Curl_URI_Get_Callback(id, status, data);
570 printf("Received HTTP request data for an invalid id %d.\n", id);
574 void draw_beginBoldFont()
576 drawfont = FONT_USER+2;
579 void draw_endBoldFont()
581 drawfont = FONT_USER+1;
584 void Accuracy_LoadLevels()
586 if(autocvar_accuracy_color_levels != acc_color_levels)
589 strunzone(acc_color_levels);
590 acc_color_levels = strzone(autocvar_accuracy_color_levels);
591 acc_levels = tokenize_console(acc_color_levels);
592 if(acc_levels > MAX_ACCURACY_LEVELS)
593 acc_levels = MAX_ACCURACY_LEVELS;
595 print("Warning: accuracy_color_levels must contain at least 2 values\n");
598 for(i = 0; i < acc_levels; ++i)
599 acc_lev[i] = stof(argv(i)) / 100.0;
603 void Accuracy_LoadColors()
605 if(time > acc_col_loadtime)
609 for(i = 0; i < acc_levels; ++i)
610 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
611 acc_col_loadtime = time + 2;
615 vector Accuracy_GetColor(float accuracy)
620 return '0 0 0'; // return black, can't determine the right color
622 // find the max level lower than acc
623 int j = acc_levels-1;
624 while(j && accuracy < acc_lev[j])
627 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
628 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
630 color = color + factor * (acc_col[j+1] - color);