10 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
12 if(prev != e.sort_prev)
13 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
17 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
19 if(prev != e.sort_prev)
20 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
25 float RegisterPlayer(entity player)
29 for(pl = players.sort_next; pl; pl = pl.sort_next)
31 error("Player already registered!");
32 player.sort_next = players.sort_next;
33 player.sort_prev = players;
35 players.sort_next.sort_prev = player;
36 players.sort_next = player;
41 void RemovePlayer(entity player)
46 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
51 error("Trying to remove a player which is not in the playerlist!");
54 parent.sort_next = player.sort_next;
56 player.sort_next.sort_prev = parent;
60 void MoveToLast(entity e)
72 float RegisterTeam(entity Team)
76 for(tm = teams.sort_next; tm; tm = tm.sort_next)
78 error("Team already registered!");
79 Team.sort_next = teams.sort_next;
80 Team.sort_prev = teams;
82 teams.sort_next.sort_prev = Team;
83 teams.sort_next = Team;
88 void RemoveTeam(entity Team)
93 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
98 print(_("Trying to remove a team which is not in the teamlist!"));
101 parent.sort_next = Team.sort_next;
103 Team.sort_next.sort_prev = parent;
107 entity GetTeam(float Team, float add)
111 num = (Team == FL_SPECTATOR) ? 16 : Team;
113 return teamslots[num];
123 vector HUD_GetFontsize(string cvarname)
126 v = stov(cvar_string(cvarname));
135 float PreviewExists(string name)
137 if(autocvar_cl_readpicture_force)
140 if (fexists(strcat(name, ".tga"))) return true;
141 if (fexists(strcat(name, ".png"))) return true;
142 if (fexists(strcat(name, ".jpg"))) return true;
143 if (fexists(strcat(name, ".pcx"))) return true;
148 vector rotate(vector v, float a)
151 // FTEQCC SUCKS AGAIN
152 w_x = v_x * cos(a) + v_y * sin(a);
153 w_y = -1 * v_x * sin(a) + v_y * cos(a);
157 float ColorTranslateMode;
159 string ColorTranslateRGB(string s)
161 if(ColorTranslateMode & 1)
162 return strdecolorize(s);
167 // decolorizes and team colors the player name when needed
168 string playername(string thename, float teamid)
173 t = Team_ColorCode(teamid);
174 return strcat(t, strdecolorize(thename));
177 return strdecolorize(thename);
180 float cvar_or(string cv, float v)
190 vector project_3d_to_2d(vector vec)
192 vec = cs_project(vec);
193 if(cs_project_is_b0rked > 0)
195 vec_x *= vid_conwidth / vid_width;
196 vec_y *= vid_conheight / vid_height;
201 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
205 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
207 return 1.2 / (1.2 - fadelerp);
210 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
212 boxsize_x *= boxxsizefactor; // easier interface for text
213 return boxsize * (0.5 * (1 - sz));
216 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
218 vector line_dim = '0 0 0';
220 // left and right lines
222 line_dim_x = thickness;
224 drawfill(pos, line_dim, color, theAlpha, drawflag);
225 drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
227 // upper and lower lines
229 line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
230 line_dim_y = thickness;
231 drawfill(pos, line_dim, color, theAlpha, drawflag);
232 drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
235 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
237 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
238 end_pos = pos + area;
240 current_pos_y = pos_y;
241 while (current_pos_y < end_pos_y)
243 current_pos_x = pos_x;
244 while (current_pos_x < end_pos_x)
246 new_size_x = min(sz_x, end_pos_x - current_pos_x);
247 new_size_y = min(sz_y, end_pos_y - current_pos_y);
248 ratio_x = new_size_x / sz_x;
249 ratio_y = new_size_y / sz_y;
250 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
251 current_pos_x += sz_x;
253 current_pos_y += sz_y;
257 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
258 var float _drawpic_imgaspect;
259 var vector _drawpic_imgsize;
260 var vector _drawpic_sz;
261 var float _drawpic_oldsz;
262 var string _drawpic_picpath;
263 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
265 _drawpic_imgsize = draw_getimagesize(pic);\
266 if(_drawpic_imgsize != '0 0 0') {\
267 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
268 _drawpic_sz = mySize;\
269 if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
270 _drawpic_oldsz = _drawpic_sz_x;\
271 _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
273 drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
275 _drawpic_oldsz = _drawpic_sz_y;\
276 _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
278 drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
283 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
284 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
286 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
287 if(precache_pic(_drawpic_picpath) == "") {\
288 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
290 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
291 _drawpic_picpath = string_null;\
294 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
295 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
297 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
298 if(precache_pic(_drawpic_picpath) == "") {\
299 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
301 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
302 _drawpic_picpath = string_null;\
305 void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
308 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
310 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, theAlpha * (1 - fadelerp), flag);
313 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
315 drawpic_aspect_skin_expanding(position, pic, scale, rgb, theAlpha, flag, fadelerp);
316 drawpic_skin(position, pic, scale, rgb, theAlpha * fadelerp, flag);
318 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
319 float textaspect, oldsz;\
320 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
321 if(sz_x/sz_y > textaspect) {\
323 sz_x = sz_y * textaspect;\
324 pos_x += (oldsz - sz_x) * 0.5;\
327 sz_y = sz_x / textaspect; \
328 pos_y += (oldsz - sz_y) * 0.5;\
331 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
332 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
333 SET_POS_AND_SZ_Y_ASPECT(FALSE)
334 drawstring(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag);
337 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
338 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
339 SET_POS_AND_SZ_Y_ASPECT(TRUE)
340 drawcolorcodedstring(pos, text, '1 1 0' * sz_y, theAlpha, drawflag);
343 vector drawfontscale;
344 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
347 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
349 drawfontscale = sz * '1 1 0';
350 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
351 drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag);
353 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
355 drawfontscale = '1 1 0';
358 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
359 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
360 SET_POS_AND_SZ_Y_ASPECT(FALSE)
361 drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
364 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float theAlpha, float flag, float fadelerp)
367 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
369 drawfontscale = sz * '1 1 0';
370 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
371 drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag);
372 drawfontscale = '1 1 0';
375 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
376 SET_POS_AND_SZ_Y_ASPECT(TRUE)
377 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, theAlpha, drawflag, fadelerp);
380 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
381 float PolyDrawModelSurface(entity e, float i_s)
387 tex = getsurfacetexture(e, i_s);
389 return 0; // this is beyond the last one
390 n_t = getsurfacenumtriangles(e, i_s);
391 for(i_t = 0; i_t < n_t; ++i_t)
393 tri = getsurfacetriangle(e, i_s, i_t);
394 R_BeginPolygon(tex, 0);
395 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
396 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
397 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
402 void PolyDrawModel(entity e)
405 for(i_s = 0; ; ++i_s)
406 if(!PolyDrawModelSurface(e, i_s))
410 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
413 vector ringsize, v, t;
414 ringsize = radius * '1 1 0';
416 x = cos(f * 2 * M_PI);
417 y = sin(f * 2 * M_PI);
418 q = fabs(x) + fabs(y);
424 // draw full rectangle
425 R_BeginPolygon(pic, drawflag);
426 v = centre; t = '0.5 0.5 0';
427 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
428 R_PolygonVertex(v, t, rgb, a);
430 v = centre; t = '0.5 0.5 0';
431 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
432 R_PolygonVertex(v, t, rgb, a);
434 v = centre; t = '0.5 0.5 0';
435 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
436 R_PolygonVertex(v, t, rgb, a);
438 v = centre; t = '0.5 0.5 0';
439 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
440 R_PolygonVertex(v, t, rgb, a);
446 R_BeginPolygon(pic, drawflag);
447 v = centre; t = '0.5 0.5 0';
448 R_PolygonVertex(v, t, rgb, a);
450 v = centre; t = '0.5 0.5 0';
451 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
452 R_PolygonVertex(v, t, rgb, a);
457 // draw upper and first triangle
458 R_BeginPolygon(pic, drawflag);
459 v = centre; t = '0.5 0.5 0';
460 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
461 R_PolygonVertex(v, t, rgb, a);
463 v = centre; t = '0.5 0.5 0';
464 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
465 R_PolygonVertex(v, t, rgb, a);
467 v = centre; t = '0.5 0.5 0';
468 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
469 R_PolygonVertex(v, t, rgb, a);
471 R_BeginPolygon(pic, drawflag);
472 v = centre; t = '0.5 0.5 0';
473 R_PolygonVertex(v, t, rgb, a);
475 v = centre; t = '0.5 0.5 0';
476 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
477 R_PolygonVertex(v, t, rgb, a);
479 v = centre; t = '0.5 0.5 0';
480 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
481 R_PolygonVertex(v, t, rgb, a);
489 // draw upper triangle
490 R_BeginPolygon(pic, drawflag);
491 v = centre; t = '0.5 0.5 0';
492 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
493 R_PolygonVertex(v, t, rgb, a);
495 v = centre; t = '0.5 0.5 0';
496 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
497 R_PolygonVertex(v, t, rgb, a);
499 v = centre; t = '0.5 0.5 0';
500 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
501 R_PolygonVertex(v, t, rgb, a);
507 R_BeginPolygon(pic, drawflag);
508 v = centre; t = '0.5 0.5 0';
509 R_PolygonVertex(v, t, rgb, a);
511 v = centre; t = '0.5 0.5 0';
512 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
513 R_PolygonVertex(v, t, rgb, a);
518 // draw first triangle
519 R_BeginPolygon(pic, drawflag);
520 v = centre; t = '0.5 0.5 0';
521 R_PolygonVertex(v, t, rgb, a);
523 v = centre; t = '0.5 0.5 0';
524 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
525 R_PolygonVertex(v, t, rgb, a);
527 v = centre; t = '0.5 0.5 0';
528 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
529 R_PolygonVertex(v, t, rgb, a);
540 R_BeginPolygon(pic, drawflag);
541 v = centre; t = '0.5 0.5 0';
542 R_PolygonVertex(v, t, rgb, a);
544 v = centre; t = '0.5 0.5 0';
545 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
546 R_PolygonVertex(v, t, rgb, a);
552 v = centre; t = '0.5 0.5 0';
553 v_x += x * 0.5 * ringsize_x; t += x * '0.5 0.5 0';
554 v_y += y * 0.5 * ringsize_y; t += y * '0.5 -0.5 0';
555 R_PolygonVertex(v, t, rgb, a);
560 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
561 vector getplayerorigin(float pl)
565 e = CSQCModel_server2csqc(pl + 1);
569 e = entcs_receiver[pl];
573 return GETPLAYERORIGIN_ERROR;
576 float getplayerisdead(float pl)
580 e = CSQCModel_server2csqc(pl + 1);
582 return e.csqcmodel_isdead;
587 void URI_Get_Callback(float id, float status, string data)
589 if(url_URI_Get_Callback(id, status, data))
593 else if (id == URI_GET_DISCARD)
597 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
600 Curl_URI_Get_Callback(id, status, data);
604 print(sprintf(_("Received HTTP request data for an invalid id %d.\n"), id));
608 void draw_beginBoldFont()
610 drawfont = FONT_USER+2;
613 void draw_endBoldFont()
615 drawfont = FONT_USER+1;
619 #define MAX_ACCURACY_LEVELS 10
620 float acc_lev[MAX_ACCURACY_LEVELS];
621 vector acc_col[MAX_ACCURACY_LEVELS];
622 float acc_col_loadtime;
624 string acc_color_levels;
625 void Accuracy_LoadLevels()
628 if(autocvar_accuracy_color_levels != acc_color_levels)
631 strunzone(acc_color_levels);
632 acc_color_levels = strzone(autocvar_accuracy_color_levels);
633 acc_levels = tokenize_console(acc_color_levels);
634 if(acc_levels > MAX_ACCURACY_LEVELS)
635 acc_levels = MAX_ACCURACY_LEVELS;
637 print("Warning: accuracy_color_levels must contain at least 2 values\n");
639 for(i = 0; i < acc_levels; ++i)
640 acc_lev[i] = stof(argv(i)) / 100.0;
644 void Accuracy_LoadColors()
647 if(time > acc_col_loadtime)
650 for(i = 0; i < acc_levels; ++i)
651 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
652 acc_col_loadtime = time + 2;
656 vector Accuracy_GetColor(float accuracy)
661 return '0 0 0'; // return black, can't determine the right color
663 // find the max level lower than acc
665 while(j && accuracy < acc_lev[j])
668 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
669 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
671 color = color + factor * (acc_col[j+1] - color);