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)
114 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
116 return teamslots[num];
126 vector HUD_GetFontsize(string cvarname)
129 v = stov(cvar_string(cvarname));
138 float PreviewExists(string name)
140 if(autocvar_cl_readpicture_force)
143 if (fexists(strcat(name, ".tga"))) return true;
144 if (fexists(strcat(name, ".png"))) return true;
145 if (fexists(strcat(name, ".jpg"))) return true;
146 if (fexists(strcat(name, ".pcx"))) return true;
151 vector rotate(vector v, float a)
154 // FTEQCC SUCKS AGAIN
155 w_x = v.x * cos(a) + v.y * sin(a);
156 w_y = -1 * v.x * sin(a) + v.y * cos(a);
160 int ColorTranslateMode;
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 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
261 float _drawpic_imgaspect;
262 vector _drawpic_imgsize;
264 float _drawpic_oldsz;
265 string _drawpic_picpath;
266 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
268 _drawpic_imgsize = draw_getimagesize(pic);\
269 if(_drawpic_imgsize != '0 0 0') {\
270 _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
271 _drawpic_sz = mySize;\
272 if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
273 _drawpic_oldsz = _drawpic_sz.x;\
274 _drawpic_sz_x = _drawpic_sz.y * _drawpic_imgaspect;\
276 drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
278 _drawpic_oldsz = _drawpic_sz.y;\
279 _drawpic_sz_y = _drawpic_sz.x / _drawpic_imgaspect;\
281 drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
286 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
287 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
289 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
290 if(precache_pic(_drawpic_picpath) == "") {\
291 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
293 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
294 _drawpic_picpath = string_null;\
297 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
298 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
300 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
301 if(precache_pic(_drawpic_picpath) == "") {\
302 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
304 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
305 _drawpic_picpath = string_null;\
308 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
311 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
313 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
316 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
318 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
319 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
321 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do { \
322 float textaspect, oldsz; \
323 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \
324 if(sz.x/sz.y > textaspect) { \
326 sz_x = sz.y * textaspect; \
327 pos.x += (oldsz - sz.x) * 0.5; \
330 sz_y = sz.x / textaspect; \
331 pos.y += (oldsz - sz.y) * 0.5; \
335 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
336 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
337 SET_POS_AND_SZ_Y_ASPECT(false);
338 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
341 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
342 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
343 SET_POS_AND_SZ_Y_ASPECT(true);
344 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
347 vector drawfontscale;
348 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
351 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
353 drawfontscale = sz * '1 1 0';
354 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
355 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);
357 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
359 drawfontscale = '1 1 0';
362 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
363 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
364 SET_POS_AND_SZ_Y_ASPECT(false);
365 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
368 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
371 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
373 drawfontscale = sz * '1 1 0';
374 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
375 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);
376 drawfontscale = '1 1 0';
379 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
380 SET_POS_AND_SZ_Y_ASPECT(true);
381 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
384 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
385 float PolyDrawModelSurface(entity e, float i_s)
391 tex = getsurfacetexture(e, i_s);
393 return 0; // this is beyond the last one
394 n_t = getsurfacenumtriangles(e, i_s);
395 for(i_t = 0; i_t < n_t; ++i_t)
397 tri = getsurfacetriangle(e, i_s, i_t);
398 R_BeginPolygon(tex, 0);
399 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
400 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
401 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
406 void PolyDrawModel(entity e)
409 for(i_s = 0; ; ++i_s)
410 if(!PolyDrawModelSurface(e, i_s))
414 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
417 vector ringsize, v, t;
418 ringsize = radius * '1 1 0';
420 x = cos(f * 2 * M_PI);
421 y = sin(f * 2 * M_PI);
422 q = fabs(x) + fabs(y);
428 // draw full rectangle
429 R_BeginPolygon(pic, drawflag);
430 v = centre; t = '0.5 0.5 0';
431 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
432 R_PolygonVertex(v, t, rgb, a);
434 v = centre; t = '0.5 0.5 0';
435 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
436 R_PolygonVertex(v, t, rgb, a);
438 v = centre; t = '0.5 0.5 0';
439 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
440 R_PolygonVertex(v, t, rgb, a);
442 v = centre; t = '0.5 0.5 0';
443 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
444 R_PolygonVertex(v, t, rgb, a);
450 R_BeginPolygon(pic, drawflag);
451 v = centre; t = '0.5 0.5 0';
452 R_PolygonVertex(v, t, rgb, a);
454 v = centre; t = '0.5 0.5 0';
455 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
456 R_PolygonVertex(v, t, rgb, a);
461 // draw upper and first triangle
462 R_BeginPolygon(pic, drawflag);
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);
467 v = centre; t = '0.5 0.5 0';
468 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
469 R_PolygonVertex(v, t, rgb, a);
471 v = centre; t = '0.5 0.5 0';
472 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
473 R_PolygonVertex(v, t, rgb, a);
475 R_BeginPolygon(pic, drawflag);
476 v = centre; t = '0.5 0.5 0';
477 R_PolygonVertex(v, t, rgb, a);
479 v = centre; t = '0.5 0.5 0';
480 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
481 R_PolygonVertex(v, t, rgb, a);
483 v = centre; t = '0.5 0.5 0';
484 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
485 R_PolygonVertex(v, t, rgb, a);
493 // draw upper triangle
494 R_BeginPolygon(pic, drawflag);
495 v = centre; t = '0.5 0.5 0';
496 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
497 R_PolygonVertex(v, t, rgb, a);
499 v = centre; t = '0.5 0.5 0';
500 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
501 R_PolygonVertex(v, t, rgb, a);
503 v = centre; t = '0.5 0.5 0';
504 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
505 R_PolygonVertex(v, t, rgb, a);
511 R_BeginPolygon(pic, drawflag);
512 v = centre; t = '0.5 0.5 0';
513 R_PolygonVertex(v, t, rgb, a);
515 v = centre; t = '0.5 0.5 0';
516 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
517 R_PolygonVertex(v, t, rgb, a);
522 // draw first triangle
523 R_BeginPolygon(pic, drawflag);
524 v = centre; t = '0.5 0.5 0';
525 R_PolygonVertex(v, t, rgb, a);
527 v = centre; t = '0.5 0.5 0';
528 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
529 R_PolygonVertex(v, t, rgb, a);
531 v = centre; t = '0.5 0.5 0';
532 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
533 R_PolygonVertex(v, t, rgb, a);
544 R_BeginPolygon(pic, drawflag);
545 v = centre; t = '0.5 0.5 0';
546 R_PolygonVertex(v, t, rgb, a);
548 v = centre; t = '0.5 0.5 0';
549 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
550 R_PolygonVertex(v, t, rgb, a);
556 v = centre; t = '0.5 0.5 0';
557 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
558 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
559 R_PolygonVertex(v, t, rgb, a);
564 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
565 vector getplayerorigin(int pl)
569 e = CSQCModel_server2csqc(pl + 1);
573 e = entcs_receiver[pl];
577 return GETPLAYERORIGIN_ERROR;
580 float getplayeralpha(float pl)
584 e = CSQCModel_server2csqc(pl + 1);
591 vector getcsqcplayercolor(float pl)
595 e = CSQCModel_server2csqc(pl);
599 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
605 float getplayerisdead(float pl)
609 e = CSQCModel_server2csqc(pl + 1);
611 return e.csqcmodel_isdead;
616 void URI_Get_Callback(int id, float status, string data)
618 if(url_URI_Get_Callback(id, status, data))
622 else if (id == URI_GET_DISCARD)
626 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
629 Curl_URI_Get_Callback(id, status, data);
633 printf("Received HTTP request data for an invalid id %d.\n", id);
637 void draw_beginBoldFont()
639 drawfont = FONT_USER+2;
642 void draw_endBoldFont()
644 drawfont = FONT_USER+1;
648 const int MAX_ACCURACY_LEVELS = 10;
649 float acc_lev[MAX_ACCURACY_LEVELS];
650 vector acc_col[MAX_ACCURACY_LEVELS];
651 float acc_col_loadtime;
653 string acc_color_levels;
654 void Accuracy_LoadLevels()
656 if(autocvar_accuracy_color_levels != acc_color_levels)
659 strunzone(acc_color_levels);
660 acc_color_levels = strzone(autocvar_accuracy_color_levels);
661 acc_levels = tokenize_console(acc_color_levels);
662 if(acc_levels > MAX_ACCURACY_LEVELS)
663 acc_levels = MAX_ACCURACY_LEVELS;
665 print("Warning: accuracy_color_levels must contain at least 2 values\n");
668 for(i = 0; i < acc_levels; ++i)
669 acc_lev[i] = stof(argv(i)) / 100.0;
673 void Accuracy_LoadColors()
675 if(time > acc_col_loadtime)
679 for(i = 0; i < acc_levels; ++i)
680 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
681 acc_col_loadtime = time + 2;
685 vector Accuracy_GetColor(float accuracy)
690 return '0 0 0'; // return black, can't determine the right color
692 // find the max level lower than acc
693 int j = acc_levels-1;
694 while(j && accuracy < acc_lev[j])
697 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
698 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
700 color = color + factor * (acc_col[j+1] - color);