3 var float team_count; // real teams
11 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
13 if(prev != e.sort_prev)
14 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
18 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
20 if(prev != e.sort_prev)
21 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
26 float RegisterPlayer(entity player)
30 for(pl = players.sort_next; pl; pl = pl.sort_next)
32 error("Player already registered!");
33 player.sort_next = players.sort_next;
34 player.sort_prev = players;
36 players.sort_next.sort_prev = player;
37 players.sort_next = player;
42 void RemovePlayer(entity player)
47 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
52 error("Trying to remove a player which is not in the playerlist!");
55 parent.sort_next = player.sort_next;
57 player.sort_next.sort_prev = parent;
61 void MoveToLast(entity e)
73 float RegisterTeam(entity Team)
77 for(tm = teams.sort_next; tm; tm = tm.sort_next)
79 error("Team already registered!");
80 Team.sort_next = teams.sort_next;
81 Team.sort_prev = teams;
83 teams.sort_next.sort_prev = Team;
84 teams.sort_next = Team;
85 if(Team.team && Team.team != NUM_SPECTATOR)
91 void RemoveTeam(entity Team)
96 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
101 print(_("Trying to remove a team which is not in the teamlist!"));
104 parent.sort_next = Team.sort_next;
106 Team.sort_next.sort_prev = parent;
107 if(Team.team && Team.team != NUM_SPECTATOR)
112 entity GetTeam(float Team, float add)
116 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 float ColorTranslateMode;
164 string ColorTranslateRGB(string s)
166 if(ColorTranslateMode & 1)
167 return strdecolorize(s);
172 // decolorizes and team colors the player name when needed
173 string playername(string thename, float teamid)
178 t = Team_ColorCode(teamid);
179 return strcat(t, strdecolorize(thename));
182 return strdecolorize(thename);
185 float cvar_or(string cv, float v)
195 vector project_3d_to_2d(vector vec)
197 vec = cs_project(vec);
198 if(cs_project_is_b0rked > 0)
200 vec_x *= vid_conwidth / vid_width;
201 vec_y *= vid_conheight / vid_height;
206 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
210 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
212 return 1.2 / (1.2 - fadelerp);
215 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
217 boxsize_x *= boxxsizefactor; // easier interface for text
218 return boxsize * (0.5 * (1 - sz));
221 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
223 vector line_dim = '0 0 0';
225 // left and right lines
227 line_dim_x = thickness;
229 drawfill(pos, line_dim, color, theAlpha, drawflag);
230 drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
232 // upper and lower lines
234 line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
235 line_dim_y = thickness;
236 drawfill(pos, line_dim, color, theAlpha, drawflag);
237 drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
240 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
242 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
243 end_pos = pos + area;
245 current_pos_y = pos_y;
246 while (current_pos_y < end_pos_y)
248 current_pos_x = pos_x;
249 while (current_pos_x < end_pos_x)
251 new_size_x = min(sz_x, end_pos_x - current_pos_x);
252 new_size_y = min(sz_y, end_pos_y - current_pos_y);
253 ratio_x = new_size_x / sz_x;
254 ratio_y = new_size_y / sz_y;
255 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
256 current_pos_x += sz_x;
258 current_pos_y += sz_y;
262 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
263 var float _drawpic_imgaspect;
264 var vector _drawpic_imgsize;
265 var vector _drawpic_sz;
266 var float _drawpic_oldsz;
267 var string _drawpic_picpath;
268 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
270 _drawpic_imgsize = draw_getimagesize(pic);\
271 if(_drawpic_imgsize != '0 0 0') {\
272 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
273 _drawpic_sz = mySize;\
274 if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
275 _drawpic_oldsz = _drawpic_sz_x;\
276 _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
278 drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
280 _drawpic_oldsz = _drawpic_sz_y;\
281 _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
283 drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
288 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
289 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
291 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
292 if(precache_pic(_drawpic_picpath) == "") {\
293 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
295 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
296 _drawpic_picpath = string_null;\
299 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
300 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
302 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
303 if(precache_pic(_drawpic_picpath) == "") {\
304 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
306 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
307 _drawpic_picpath = string_null;\
310 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
313 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
315 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
318 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
320 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
321 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
323 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
324 float textaspect, oldsz;\
325 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
326 if(sz_x/sz_y > textaspect) {\
328 sz_x = sz_y * textaspect;\
329 pos_x += (oldsz - sz_x) * 0.5;\
332 sz_y = sz_x / textaspect; \
333 pos_y += (oldsz - sz_y) * 0.5;\
336 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
337 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
338 SET_POS_AND_SZ_Y_ASPECT(FALSE)
339 drawstring(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag);
342 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
343 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
344 SET_POS_AND_SZ_Y_ASPECT(TRUE)
345 drawcolorcodedstring(pos, text, '1 1 0' * sz_y, theAlpha, drawflag);
348 vector drawfontscale;
349 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
352 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
354 drawfontscale = sz * '1 1 0';
355 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
356 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);
358 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
360 drawfontscale = '1 1 0';
363 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
364 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
365 SET_POS_AND_SZ_Y_ASPECT(FALSE)
366 drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
369 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
372 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
374 drawfontscale = sz * '1 1 0';
375 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
376 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);
377 drawfontscale = '1 1 0';
380 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
381 SET_POS_AND_SZ_Y_ASPECT(TRUE)
382 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, theAlpha, drawflag, fadelerp);
385 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
386 float PolyDrawModelSurface(entity e, float i_s)
392 tex = getsurfacetexture(e, i_s);
394 return 0; // this is beyond the last one
395 n_t = getsurfacenumtriangles(e, i_s);
396 for(i_t = 0; i_t < n_t; ++i_t)
398 tri = getsurfacetriangle(e, i_s, i_t);
399 R_BeginPolygon(tex, 0);
400 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
401 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
402 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
407 void PolyDrawModel(entity e)
410 for(i_s = 0; ; ++i_s)
411 if(!PolyDrawModelSurface(e, i_s))
415 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
418 vector ringsize, v, t;
419 ringsize = radius * '1 1 0';
421 x = cos(f * 2 * M_PI);
422 y = sin(f * 2 * M_PI);
423 q = fabs(x) + fabs(y);
429 // draw full rectangle
430 R_BeginPolygon(pic, drawflag);
431 v = centre; t = '0.5 0.5 0';
432 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
433 R_PolygonVertex(v, t, rgb, a);
435 v = centre; t = '0.5 0.5 0';
436 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
437 R_PolygonVertex(v, t, rgb, a);
439 v = centre; t = '0.5 0.5 0';
440 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
441 R_PolygonVertex(v, t, rgb, a);
443 v = centre; t = '0.5 0.5 0';
444 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
445 R_PolygonVertex(v, t, rgb, a);
451 R_BeginPolygon(pic, drawflag);
452 v = centre; t = '0.5 0.5 0';
453 R_PolygonVertex(v, t, rgb, a);
455 v = centre; t = '0.5 0.5 0';
456 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
457 R_PolygonVertex(v, t, rgb, a);
462 // draw upper and first triangle
463 R_BeginPolygon(pic, drawflag);
464 v = centre; t = '0.5 0.5 0';
465 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
466 R_PolygonVertex(v, t, rgb, a);
468 v = centre; t = '0.5 0.5 0';
469 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
470 R_PolygonVertex(v, t, rgb, a);
472 v = centre; t = '0.5 0.5 0';
473 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
474 R_PolygonVertex(v, t, rgb, a);
476 R_BeginPolygon(pic, drawflag);
477 v = centre; t = '0.5 0.5 0';
478 R_PolygonVertex(v, t, rgb, a);
480 v = centre; t = '0.5 0.5 0';
481 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
482 R_PolygonVertex(v, t, rgb, a);
484 v = centre; t = '0.5 0.5 0';
485 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
486 R_PolygonVertex(v, t, rgb, a);
494 // draw upper triangle
495 R_BeginPolygon(pic, drawflag);
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);
500 v = centre; t = '0.5 0.5 0';
501 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
502 R_PolygonVertex(v, t, rgb, a);
504 v = centre; t = '0.5 0.5 0';
505 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
506 R_PolygonVertex(v, t, rgb, a);
512 R_BeginPolygon(pic, drawflag);
513 v = centre; t = '0.5 0.5 0';
514 R_PolygonVertex(v, t, rgb, a);
516 v = centre; t = '0.5 0.5 0';
517 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
518 R_PolygonVertex(v, t, rgb, a);
523 // draw first triangle
524 R_BeginPolygon(pic, drawflag);
525 v = centre; t = '0.5 0.5 0';
526 R_PolygonVertex(v, t, rgb, a);
528 v = centre; t = '0.5 0.5 0';
529 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
530 R_PolygonVertex(v, t, rgb, a);
532 v = centre; t = '0.5 0.5 0';
533 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
534 R_PolygonVertex(v, t, rgb, a);
545 R_BeginPolygon(pic, drawflag);
546 v = centre; t = '0.5 0.5 0';
547 R_PolygonVertex(v, t, rgb, a);
549 v = centre; t = '0.5 0.5 0';
550 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
551 R_PolygonVertex(v, t, rgb, a);
557 v = centre; t = '0.5 0.5 0';
558 v_x += x * 0.5 * ringsize_x; t += x * '0.5 0.5 0';
559 v_y += y * 0.5 * ringsize_y; t += y * '0.5 -0.5 0';
560 R_PolygonVertex(v, t, rgb, a);
565 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
566 vector getplayerorigin(float pl)
570 e = CSQCModel_server2csqc(pl + 1);
574 e = entcs_receiver[pl];
578 return GETPLAYERORIGIN_ERROR;
581 float getplayeralpha(float pl)
585 e = CSQCModel_server2csqc(pl + 1);
592 vector getcsqcplayercolor(float pl)
596 e = CSQCModel_server2csqc(pl);
600 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, TRUE);
606 float getplayerisdead(float pl)
610 e = CSQCModel_server2csqc(pl + 1);
612 return e.csqcmodel_isdead;
617 void URI_Get_Callback(float id, float status, string data)
619 if(url_URI_Get_Callback(id, status, data))
623 else if (id == URI_GET_DISCARD)
627 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
630 Curl_URI_Get_Callback(id, status, data);
634 printf("Received HTTP request data for an invalid id %d.\n", id);
638 void draw_beginBoldFont()
640 drawfont = FONT_USER+2;
643 void draw_endBoldFont()
645 drawfont = FONT_USER+1;
649 #define MAX_ACCURACY_LEVELS 10
650 float acc_lev[MAX_ACCURACY_LEVELS];
651 vector acc_col[MAX_ACCURACY_LEVELS];
652 float acc_col_loadtime;
654 string acc_color_levels;
655 void Accuracy_LoadLevels()
658 if(autocvar_accuracy_color_levels != acc_color_levels)
661 strunzone(acc_color_levels);
662 acc_color_levels = strzone(autocvar_accuracy_color_levels);
663 acc_levels = tokenize_console(acc_color_levels);
664 if(acc_levels > MAX_ACCURACY_LEVELS)
665 acc_levels = MAX_ACCURACY_LEVELS;
667 print("Warning: accuracy_color_levels must contain at least 2 values\n");
669 for(i = 0; i < acc_levels; ++i)
670 acc_lev[i] = stof(argv(i)) / 100.0;
674 void Accuracy_LoadColors()
677 if(time > acc_col_loadtime)
680 for(i = 0; i < acc_levels; ++i)
681 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
682 acc_col_loadtime = time + 2;
686 vector Accuracy_GetColor(float accuracy)
691 return '0 0 0'; // return black, can't determine the right color
693 // find the max level lower than acc
695 while(j && accuracy < acc_lev[j])
698 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
699 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
701 color = color + factor * (acc_col[j+1] - color);