3 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(int Team, bool 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 int 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 float _drawpic_imgaspect;
264 vector _drawpic_imgsize;
266 float _drawpic_oldsz;
267 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) do { \
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; \
337 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
338 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
339 SET_POS_AND_SZ_Y_ASPECT(false);
340 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
343 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
344 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
345 SET_POS_AND_SZ_Y_ASPECT(true);
346 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
349 vector drawfontscale;
350 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
353 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
355 drawfontscale = sz * '1 1 0';
356 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
357 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);
359 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
361 drawfontscale = '1 1 0';
364 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
365 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
366 SET_POS_AND_SZ_Y_ASPECT(false);
367 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
370 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
373 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
375 drawfontscale = sz * '1 1 0';
376 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
377 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);
378 drawfontscale = '1 1 0';
381 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
382 SET_POS_AND_SZ_Y_ASPECT(true);
383 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
386 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
387 float PolyDrawModelSurface(entity e, float i_s)
393 tex = getsurfacetexture(e, i_s);
395 return 0; // this is beyond the last one
396 n_t = getsurfacenumtriangles(e, i_s);
397 for(i_t = 0; i_t < n_t; ++i_t)
399 tri = getsurfacetriangle(e, i_s, i_t);
400 R_BeginPolygon(tex, 0);
401 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
402 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
403 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
408 void PolyDrawModel(entity e)
411 for(i_s = 0; ; ++i_s)
412 if(!PolyDrawModelSurface(e, i_s))
416 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
419 vector ringsize, v, t;
420 ringsize = radius * '1 1 0';
422 x = cos(f * 2 * M_PI);
423 y = sin(f * 2 * M_PI);
424 q = fabs(x) + fabs(y);
430 // draw full rectangle
431 R_BeginPolygon(pic, drawflag);
432 v = centre; t = '0.5 0.5 0';
433 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
434 R_PolygonVertex(v, t, rgb, a);
436 v = centre; t = '0.5 0.5 0';
437 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
438 R_PolygonVertex(v, t, rgb, a);
440 v = centre; t = '0.5 0.5 0';
441 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
442 R_PolygonVertex(v, t, rgb, a);
444 v = centre; t = '0.5 0.5 0';
445 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
446 R_PolygonVertex(v, t, rgb, a);
452 R_BeginPolygon(pic, drawflag);
453 v = centre; t = '0.5 0.5 0';
454 R_PolygonVertex(v, t, rgb, a);
456 v = centre; t = '0.5 0.5 0';
457 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
458 R_PolygonVertex(v, t, rgb, a);
463 // draw upper and first triangle
464 R_BeginPolygon(pic, drawflag);
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);
473 v = centre; t = '0.5 0.5 0';
474 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
475 R_PolygonVertex(v, t, rgb, a);
477 R_BeginPolygon(pic, drawflag);
478 v = centre; t = '0.5 0.5 0';
479 R_PolygonVertex(v, t, rgb, a);
481 v = centre; t = '0.5 0.5 0';
482 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
483 R_PolygonVertex(v, t, rgb, a);
485 v = centre; t = '0.5 0.5 0';
486 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
487 R_PolygonVertex(v, t, rgb, a);
495 // draw upper triangle
496 R_BeginPolygon(pic, drawflag);
497 v = centre; t = '0.5 0.5 0';
498 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
499 R_PolygonVertex(v, t, rgb, a);
501 v = centre; t = '0.5 0.5 0';
502 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
503 R_PolygonVertex(v, t, rgb, a);
505 v = centre; t = '0.5 0.5 0';
506 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
507 R_PolygonVertex(v, t, rgb, a);
513 R_BeginPolygon(pic, drawflag);
514 v = centre; t = '0.5 0.5 0';
515 R_PolygonVertex(v, t, rgb, a);
517 v = centre; t = '0.5 0.5 0';
518 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
519 R_PolygonVertex(v, t, rgb, a);
524 // draw first triangle
525 R_BeginPolygon(pic, drawflag);
526 v = centre; t = '0.5 0.5 0';
527 R_PolygonVertex(v, t, rgb, a);
529 v = centre; t = '0.5 0.5 0';
530 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
531 R_PolygonVertex(v, t, rgb, a);
533 v = centre; t = '0.5 0.5 0';
534 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
535 R_PolygonVertex(v, t, rgb, a);
546 R_BeginPolygon(pic, drawflag);
547 v = centre; t = '0.5 0.5 0';
548 R_PolygonVertex(v, t, rgb, a);
550 v = centre; t = '0.5 0.5 0';
551 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
552 R_PolygonVertex(v, t, rgb, a);
558 v = centre; t = '0.5 0.5 0';
559 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
560 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
561 R_PolygonVertex(v, t, rgb, a);
566 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
567 vector getplayerorigin(int pl)
571 e = CSQCModel_server2csqc(pl + 1);
575 e = entcs_receiver[pl];
579 return GETPLAYERORIGIN_ERROR;
582 float getplayeralpha(float pl)
586 e = CSQCModel_server2csqc(pl + 1);
593 vector getcsqcplayercolor(float pl)
597 e = CSQCModel_server2csqc(pl);
601 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
607 float getplayerisdead(float pl)
611 e = CSQCModel_server2csqc(pl + 1);
613 return e.csqcmodel_isdead;
618 void URI_Get_Callback(float id, float status, string data)
620 if(url_URI_Get_Callback(id, status, data))
624 else if (id == URI_GET_DISCARD)
628 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
631 Curl_URI_Get_Callback(id, status, data);
635 printf("Received HTTP request data for an invalid id %d.\n", id);
639 void draw_beginBoldFont()
641 drawfont = FONT_USER+2;
644 void draw_endBoldFont()
646 drawfont = FONT_USER+1;
650 const float MAX_ACCURACY_LEVELS = 10;
651 float acc_lev[MAX_ACCURACY_LEVELS];
652 vector acc_col[MAX_ACCURACY_LEVELS];
653 float acc_col_loadtime;
655 string acc_color_levels;
656 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");
670 for(i = 0; i < acc_levels; ++i)
671 acc_lev[i] = stof(argv(i)) / 100.0;
675 void Accuracy_LoadColors()
677 if(time > acc_col_loadtime)
681 for(i = 0; i < acc_levels; ++i)
682 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
683 acc_col_loadtime = time + 2;
687 vector Accuracy_GetColor(float accuracy)
692 return '0 0 0'; // return black, can't determine the right color
694 // find the max level lower than acc
695 int j = acc_levels-1;
696 while(j && accuracy < acc_lev[j])
699 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
700 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
702 color = color + factor * (acc_col[j+1] - color);