1 var float(string text, float handleColors, vector fontSize) stringwidth;
12 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
14 if(prev != e.sort_prev)
15 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
19 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
21 if(prev != e.sort_prev)
22 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
27 float RegisterPlayer(entity player)
31 for(pl = players.sort_next; pl; pl = pl.sort_next)
33 error("Player already registered!");
34 player.sort_next = players.sort_next;
35 player.sort_prev = players;
37 players.sort_next.sort_prev = player;
38 players.sort_next = player;
43 void RemovePlayer(entity player)
48 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
53 error("Trying to remove a player which is not in the playerlist!");
56 parent.sort_next = player.sort_next;
58 player.sort_next.sort_prev = parent;
62 void MoveToLast(entity e)
74 float RegisterTeam(entity Team)
78 for(tm = teams.sort_next; tm; tm = tm.sort_next)
80 error("Team already registered!");
81 Team.sort_next = teams.sort_next;
82 Team.sort_prev = teams;
84 teams.sort_next.sort_prev = Team;
85 teams.sort_next = Team;
90 void RemoveTeam(entity Team)
95 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
100 print(_("Trying to remove a team which is not in the teamlist!"));
103 parent.sort_next = Team.sort_next;
105 Team.sort_next.sort_prev = parent;
109 entity GetTeam(float Team, float add)
113 num = (Team == COLOR_SPECTATOR) ? 16 : Team;
115 return teamslots[num];
125 vector HUD_GetFontsize(string cvarname)
128 v = stov(cvar_string(cvarname));
137 float PreviewExists(string name)
139 if(autocvar_cl_readpicture_force)
142 if (fexists(strcat(name, ".tga"))) return true;
143 if (fexists(strcat(name, ".png"))) return true;
144 if (fexists(strcat(name, ".jpg"))) return true;
145 if (fexists(strcat(name, ".pcx"))) return true;
150 vector rotate(vector v, float a)
153 // FTEQCC SUCKS AGAIN
154 w_x = v_x * cos(a) + v_y * sin(a);
155 w_y = -1 * v_x * sin(a) + v_y * cos(a);
159 float ColorTranslateMode;
161 string ColorTranslateRGB(string s)
163 if(ColorTranslateMode & 1)
164 return strdecolorize(s);
169 string Team_ColorCode(float teamid)
171 if (teamid == COLOR_TEAM1)
173 else if (teamid == COLOR_TEAM2)
175 else if (teamid == COLOR_TEAM3)
177 else if (teamid == COLOR_TEAM4)
183 // decolorizes and team colors the player name when needed
184 string playername(string thename, float teamid)
189 t = Team_ColorCode(teamid);
190 return strcat(t, strdecolorize(thename));
193 return strdecolorize(thename);
196 float cvar_or(string cv, float v)
206 vector project_3d_to_2d(vector vec)
208 vec = cs_project(vec);
209 if(cs_project_is_b0rked > 0)
211 vec_x *= vid_conwidth / vid_width;
212 vec_y *= vid_conheight / vid_height;
217 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
221 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
223 return 1.2 / (1.2 - fadelerp);
226 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
228 boxsize_x *= boxxsizefactor; // easier interface for text
229 return boxsize * (0.5 * (1 - sz));
232 void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)
236 // left and right lines
238 line_dim_x = thickness;
240 drawfill(pos, line_dim, color, alpha, drawflag);
241 drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);
243 // upper and lower lines
245 line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
246 line_dim_y = thickness;
247 drawfill(pos, line_dim, color, alpha, drawflag);
248 drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);
251 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)
253 vector current_pos, end_pos, new_size, ratio;
254 end_pos = pos + area;
256 current_pos_y = pos_y;
257 while (current_pos_y < end_pos_y)
259 current_pos_x = pos_x;
260 while (current_pos_x < end_pos_x)
262 new_size_x = min(sz_x, end_pos_x - current_pos_x);
263 new_size_y = min(sz_y, end_pos_y - current_pos_y);
264 ratio_x = new_size_x / sz_x;
265 ratio_y = new_size_y / sz_y;
266 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);
267 current_pos_x += sz_x;
269 current_pos_y += sz_y;
273 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
274 var float _drawpic_imgaspect;
275 var vector _drawpic_imgsize;
276 var vector _drawpic_sz;
277 var float _drawpic_oldsz;
278 var string _drawpic_picpath;
279 #define drawpic_aspect(pos,pic,mySize,color,alpha,drawflag)\
281 _drawpic_imgsize = draw_getimagesize(pic);\
282 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
283 _drawpic_sz = mySize;\
284 if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
285 _drawpic_oldsz = _drawpic_sz_x;\
286 _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
287 drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
289 _drawpic_oldsz = _drawpic_sz_y;\
290 _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
291 drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
295 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
296 #define drawpic_aspect_skin(pos,pic,sz,color,alpha,drawflag)\
298 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
299 if(precache_pic(_drawpic_picpath) == "") {\
300 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
302 drawpic_aspect(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
303 _drawpic_picpath = string_null;\
306 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
307 #define drawpic_skin(pos,pic,sz,color,alpha,drawflag)\
309 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
310 if(precache_pic(_drawpic_picpath) == "") {\
311 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
313 drawpic(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
314 _drawpic_picpath = string_null;\
317 void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
320 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
322 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
325 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
327 drawpic_aspect_skin_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
328 drawpic_skin(position, pic, scale, rgb, alpha * fadelerp, flag);
330 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
331 float textaspect, oldsz;\
332 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
333 if(sz_x/sz_y > textaspect) {\
335 sz_x = sz_y * textaspect;\
336 pos_x += (oldsz - sz_x) * 0.5;\
339 sz_y = sz_x / textaspect; \
340 pos_y += (oldsz - sz_y) * 0.5;\
343 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
344 void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {
345 SET_POS_AND_SZ_Y_ASPECT(FALSE)
346 drawstring(pos, text, '1 1 0' * sz_y, color, alpha, drawflag);
349 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
350 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float alpha, float drawflag) {
351 SET_POS_AND_SZ_Y_ASPECT(TRUE)
352 drawcolorcodedstring(pos, text, '1 1 0' * sz_y, alpha, drawflag);
355 vector drawfontscale;
356 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
359 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
361 drawfontscale = sz * '1 1 0';
362 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
363 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, alpha * (1 - fadelerp), flag);
365 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
367 drawfontscale = '1 1 0';
370 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
371 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float alpha, float drawflag, float fadelerp) {
372 SET_POS_AND_SZ_Y_ASPECT(FALSE)
373 drawstring_expanding(pos, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
376 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
379 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
381 drawfontscale = sz * '1 1 0';
382 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
383 drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), alpha * (1 - fadelerp), flag);
384 drawfontscale = '1 1 0';
387 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float alpha, float drawflag, float fadelerp) {
388 SET_POS_AND_SZ_Y_ASPECT(TRUE)
389 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
392 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
393 float PolyDrawModelSurface(entity e, float i_s)
399 tex = getsurfacetexture(e, i_s);
401 return 0; // this is beyond the last one
402 n_t = getsurfacenumtriangles(e, i_s);
403 for(i_t = 0; i_t < n_t; ++i_t)
405 tri = getsurfacetriangle(e, i_s, i_t);
406 R_BeginPolygon(tex, 0);
407 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
408 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
409 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
414 void PolyDrawModel(entity e)
417 for(i_s = 0; ; ++i_s)
418 if(!PolyDrawModelSurface(e, i_s))
422 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
425 vector ringsize, v, t;
426 ringsize = radius * '1 1 0';
428 x = cos(f * 2 * M_PI);
429 y = sin(f * 2 * M_PI);
430 q = fabs(x) + fabs(y);
436 // draw full rectangle
437 R_BeginPolygon(pic, drawflag);
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);
446 v = centre; t = '0.5 0.5 0';
447 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
448 R_PolygonVertex(v, t, rgb, a);
450 v = centre; t = '0.5 0.5 0';
451 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
452 R_PolygonVertex(v, t, rgb, a);
458 R_BeginPolygon(pic, drawflag);
459 v = centre; t = '0.5 0.5 0';
460 R_PolygonVertex(v, t, rgb, a);
462 v = centre; t = '0.5 0.5 0';
463 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
464 R_PolygonVertex(v, t, rgb, a);
469 // draw upper and first triangle
470 R_BeginPolygon(pic, drawflag);
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 v = centre; t = '0.5 0.5 0';
476 v_y += 0.5 * ringsize_y; 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 R_BeginPolygon(pic, drawflag);
484 v = centre; t = '0.5 0.5 0';
485 R_PolygonVertex(v, t, rgb, a);
487 v = centre; t = '0.5 0.5 0';
488 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
489 R_PolygonVertex(v, t, rgb, a);
491 v = centre; t = '0.5 0.5 0';
492 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
493 R_PolygonVertex(v, t, rgb, a);
501 // draw upper triangle
502 R_BeginPolygon(pic, drawflag);
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);
507 v = centre; t = '0.5 0.5 0';
508 v_y += 0.5 * ringsize_y; 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);
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);
530 // draw first triangle
531 R_BeginPolygon(pic, drawflag);
532 v = centre; t = '0.5 0.5 0';
533 R_PolygonVertex(v, t, rgb, a);
535 v = centre; t = '0.5 0.5 0';
536 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
537 R_PolygonVertex(v, t, rgb, a);
539 v = centre; t = '0.5 0.5 0';
540 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
541 R_PolygonVertex(v, t, rgb, a);
552 R_BeginPolygon(pic, drawflag);
553 v = centre; t = '0.5 0.5 0';
554 R_PolygonVertex(v, t, rgb, a);
556 v = centre; t = '0.5 0.5 0';
557 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
558 R_PolygonVertex(v, t, rgb, a);
564 v = centre; t = '0.5 0.5 0';
565 v_x += x * 0.5 * ringsize_x; t += x * '0.5 0.5 0';
566 v_y += y * 0.5 * ringsize_y; t += y * '0.5 -0.5 0';
567 R_PolygonVertex(v, t, rgb, a);
572 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
573 vector getplayerorigin(float pl)
578 s = getplayerkeyvalue(pl, "TEMPHACK_origin");
582 e = entcs_receiver[pl];
586 return GETPLAYERORIGIN_ERROR;