1 // WARNING: this kills the trace globals
2 float WarpZoneLib_ExactTrigger_Touch();
3 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
7 var float team_count; // real teams
15 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
17 if(prev != e.sort_prev)
18 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
22 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
24 if(prev != e.sort_prev)
25 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
30 float RegisterPlayer(entity player)
34 for(pl = players.sort_next; pl; pl = pl.sort_next)
36 error("Player already registered!");
37 player.sort_next = players.sort_next;
38 player.sort_prev = players;
40 players.sort_next.sort_prev = player;
41 players.sort_next = player;
46 void RemovePlayer(entity player)
51 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
56 error("Trying to remove a player which is not in the playerlist!");
59 parent.sort_next = player.sort_next;
61 player.sort_next.sort_prev = parent;
65 void MoveToLast(entity e)
77 float RegisterTeam(entity Team)
81 for(tm = teams.sort_next; tm; tm = tm.sort_next)
83 error("Team already registered!");
84 Team.sort_next = teams.sort_next;
85 Team.sort_prev = teams;
87 teams.sort_next.sort_prev = Team;
88 teams.sort_next = Team;
89 if(Team.team && Team.team != NUM_SPECTATOR)
95 void RemoveTeam(entity Team)
100 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
105 print(_("Trying to remove a team which is not in the teamlist!"));
108 parent.sort_next = Team.sort_next;
110 Team.sort_next.sort_prev = parent;
111 if(Team.team && Team.team != NUM_SPECTATOR)
116 entity GetTeam(float Team, float add)
120 num = (Team == NUM_SPECTATOR) ? 16 : Team;
122 return teamslots[num];
132 vector HUD_GetFontsize(string cvarname)
135 v = stov(cvar_string(cvarname));
144 float PreviewExists(string name)
146 if(autocvar_cl_readpicture_force)
149 if (fexists(strcat(name, ".tga"))) return true;
150 if (fexists(strcat(name, ".png"))) return true;
151 if (fexists(strcat(name, ".jpg"))) return true;
152 if (fexists(strcat(name, ".pcx"))) return true;
157 vector rotate(vector v, float a)
160 // FTEQCC SUCKS AGAIN
161 w_x = v_x * cos(a) + v_y * sin(a);
162 w_y = -1 * v_x * sin(a) + v_y * cos(a);
166 float ColorTranslateMode;
168 string ColorTranslateRGB(string s)
170 if(ColorTranslateMode & 1)
171 return strdecolorize(s);
176 // decolorizes and team colors the player name when needed
177 string playername(string thename, float teamid)
182 t = Team_ColorCode(teamid);
183 return strcat(t, strdecolorize(thename));
186 return strdecolorize(thename);
189 float cvar_or(string cv, float v)
199 vector project_3d_to_2d(vector vec)
201 vec = cs_project(vec);
202 if(cs_project_is_b0rked > 0)
204 vec_x *= vid_conwidth / vid_width;
205 vec_y *= vid_conheight / vid_height;
210 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
214 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
216 return 1.2 / (1.2 - fadelerp);
219 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
221 boxsize_x *= boxxsizefactor; // easier interface for text
222 return boxsize * (0.5 * (1 - sz));
225 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
227 vector line_dim = '0 0 0';
229 // left and right lines
231 line_dim_x = thickness;
233 drawfill(pos, line_dim, color, theAlpha, drawflag);
234 drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
236 // upper and lower lines
238 line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
239 line_dim_y = thickness;
240 drawfill(pos, line_dim, color, theAlpha, drawflag);
241 drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
244 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
246 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
247 end_pos = pos + area;
249 current_pos_y = pos_y;
250 while (current_pos_y < end_pos_y)
252 current_pos_x = pos_x;
253 while (current_pos_x < end_pos_x)
255 new_size_x = min(sz_x, end_pos_x - current_pos_x);
256 new_size_y = min(sz_y, end_pos_y - current_pos_y);
257 ratio_x = new_size_x / sz_x;
258 ratio_y = new_size_y / sz_y;
259 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
260 current_pos_x += sz_x;
262 current_pos_y += sz_y;
266 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
267 var float _drawpic_imgaspect;
268 var vector _drawpic_imgsize;
269 var vector _drawpic_sz;
270 var float _drawpic_oldsz;
271 var string _drawpic_picpath;
272 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
274 _drawpic_imgsize = draw_getimagesize(pic);\
275 if(_drawpic_imgsize != '0 0 0') {\
276 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
277 _drawpic_sz = mySize;\
278 if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
279 _drawpic_oldsz = _drawpic_sz_x;\
280 _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
282 drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
284 _drawpic_oldsz = _drawpic_sz_y;\
285 _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
287 drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
292 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
293 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
295 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
296 if(precache_pic(_drawpic_picpath) == "") {\
297 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
299 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
300 _drawpic_picpath = string_null;\
303 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
304 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
306 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
307 if(precache_pic(_drawpic_picpath) == "") {\
308 _drawpic_picpath = strcat("gfx/hud/default/", pic);\
310 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
311 _drawpic_picpath = string_null;\
314 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
317 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
319 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
322 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
324 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
325 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
327 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
328 float textaspect, oldsz;\
329 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
330 if(sz_x/sz_y > textaspect) {\
332 sz_x = sz_y * textaspect;\
333 pos_x += (oldsz - sz_x) * 0.5;\
336 sz_y = sz_x / textaspect; \
337 pos_y += (oldsz - sz_y) * 0.5;\
340 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
341 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
342 SET_POS_AND_SZ_Y_ASPECT(FALSE)
343 drawstring(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag);
346 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
347 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
348 SET_POS_AND_SZ_Y_ASPECT(TRUE)
349 drawcolorcodedstring(pos, text, '1 1 0' * sz_y, theAlpha, drawflag);
352 vector drawfontscale;
353 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
356 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
358 drawfontscale = sz * '1 1 0';
359 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
360 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);
362 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
364 drawfontscale = '1 1 0';
367 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
368 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
369 SET_POS_AND_SZ_Y_ASPECT(FALSE)
370 drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
373 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
376 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
378 drawfontscale = sz * '1 1 0';
379 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
380 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);
381 drawfontscale = '1 1 0';
384 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
385 SET_POS_AND_SZ_Y_ASPECT(TRUE)
386 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, theAlpha, drawflag, fadelerp);
389 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
390 float PolyDrawModelSurface(entity e, float i_s)
396 tex = getsurfacetexture(e, i_s);
398 return 0; // this is beyond the last one
399 n_t = getsurfacenumtriangles(e, i_s);
400 for(i_t = 0; i_t < n_t; ++i_t)
402 tri = getsurfacetriangle(e, i_s, i_t);
403 R_BeginPolygon(tex, 0);
404 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
405 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
406 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
411 void PolyDrawModel(entity e)
414 for(i_s = 0; ; ++i_s)
415 if(!PolyDrawModelSurface(e, i_s))
419 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
422 vector ringsize, v, t;
423 ringsize = radius * '1 1 0';
425 x = cos(f * 2 * M_PI);
426 y = sin(f * 2 * M_PI);
427 q = fabs(x) + fabs(y);
433 // draw full rectangle
434 R_BeginPolygon(pic, drawflag);
435 v = centre; t = '0.5 0.5 0';
436 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
437 R_PolygonVertex(v, t, rgb, a);
439 v = centre; t = '0.5 0.5 0';
440 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
441 R_PolygonVertex(v, t, rgb, a);
443 v = centre; t = '0.5 0.5 0';
444 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
445 R_PolygonVertex(v, t, rgb, a);
447 v = centre; t = '0.5 0.5 0';
448 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
449 R_PolygonVertex(v, t, rgb, a);
455 R_BeginPolygon(pic, drawflag);
456 v = centre; t = '0.5 0.5 0';
457 R_PolygonVertex(v, t, rgb, a);
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);
466 // draw upper and first triangle
467 R_BeginPolygon(pic, drawflag);
468 v = centre; t = '0.5 0.5 0';
469 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
470 R_PolygonVertex(v, t, rgb, a);
472 v = centre; t = '0.5 0.5 0';
473 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
474 R_PolygonVertex(v, t, rgb, a);
476 v = centre; t = '0.5 0.5 0';
477 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
478 R_PolygonVertex(v, t, rgb, a);
480 R_BeginPolygon(pic, drawflag);
481 v = centre; t = '0.5 0.5 0';
482 R_PolygonVertex(v, t, rgb, a);
484 v = centre; t = '0.5 0.5 0';
485 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
486 R_PolygonVertex(v, t, rgb, a);
488 v = centre; t = '0.5 0.5 0';
489 v_y -= 0.5 * ringsize_y; t -= '0.5 -0.5 0';
490 R_PolygonVertex(v, t, rgb, a);
498 // draw upper triangle
499 R_BeginPolygon(pic, drawflag);
500 v = centre; t = '0.5 0.5 0';
501 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
502 R_PolygonVertex(v, t, rgb, a);
504 v = centre; t = '0.5 0.5 0';
505 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
506 R_PolygonVertex(v, t, rgb, a);
508 v = centre; t = '0.5 0.5 0';
509 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
510 R_PolygonVertex(v, t, rgb, a);
516 R_BeginPolygon(pic, drawflag);
517 v = centre; t = '0.5 0.5 0';
518 R_PolygonVertex(v, t, rgb, a);
520 v = centre; t = '0.5 0.5 0';
521 v_x -= 0.5 * ringsize_x; t -= '0.5 0.5 0';
522 R_PolygonVertex(v, t, rgb, a);
527 // draw first triangle
528 R_BeginPolygon(pic, drawflag);
529 v = centre; t = '0.5 0.5 0';
530 R_PolygonVertex(v, t, rgb, a);
532 v = centre; t = '0.5 0.5 0';
533 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
534 R_PolygonVertex(v, t, rgb, a);
536 v = centre; t = '0.5 0.5 0';
537 v_y += 0.5 * ringsize_y; t += '0.5 -0.5 0';
538 R_PolygonVertex(v, t, rgb, a);
549 R_BeginPolygon(pic, drawflag);
550 v = centre; t = '0.5 0.5 0';
551 R_PolygonVertex(v, t, rgb, a);
553 v = centre; t = '0.5 0.5 0';
554 v_x += 0.5 * ringsize_x; t += '0.5 0.5 0';
555 R_PolygonVertex(v, t, rgb, a);
561 v = centre; t = '0.5 0.5 0';
562 v_x += x * 0.5 * ringsize_x; t += x * '0.5 0.5 0';
563 v_y += y * 0.5 * ringsize_y; t += y * '0.5 -0.5 0';
564 R_PolygonVertex(v, t, rgb, a);
569 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
570 vector getplayerorigin(float pl)
574 e = CSQCModel_server2csqc(pl + 1);
578 e = entcs_receiver[pl];
582 return GETPLAYERORIGIN_ERROR;
585 float getplayeralpha(float pl)
589 e = CSQCModel_server2csqc(pl + 1);
596 vector getcsqcplayercolor(float pl)
600 e = CSQCModel_server2csqc(pl);
604 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, TRUE);
610 float getplayerisdead(float pl)
614 e = CSQCModel_server2csqc(pl + 1);
616 return e.csqcmodel_isdead;
621 void URI_Get_Callback(float id, float status, string data)
623 if(url_URI_Get_Callback(id, status, data))
627 else if (id == URI_GET_DISCARD)
631 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
634 Curl_URI_Get_Callback(id, status, data);
638 printf("Received HTTP request data for an invalid id %d.\n", id);
642 void draw_beginBoldFont()
644 drawfont = FONT_USER+2;
647 void draw_endBoldFont()
649 drawfont = FONT_USER+1;
653 #define MAX_ACCURACY_LEVELS 10
654 float acc_lev[MAX_ACCURACY_LEVELS];
655 vector acc_col[MAX_ACCURACY_LEVELS];
656 float acc_col_loadtime;
658 string acc_color_levels;
659 void Accuracy_LoadLevels()
662 if(autocvar_accuracy_color_levels != acc_color_levels)
665 strunzone(acc_color_levels);
666 acc_color_levels = strzone(autocvar_accuracy_color_levels);
667 acc_levels = tokenize_console(acc_color_levels);
668 if(acc_levels > MAX_ACCURACY_LEVELS)
669 acc_levels = MAX_ACCURACY_LEVELS;
671 print("Warning: accuracy_color_levels must contain at least 2 values\n");
673 for(i = 0; i < acc_levels; ++i)
674 acc_lev[i] = stof(argv(i)) / 100.0;
678 void Accuracy_LoadColors()
681 if(time > acc_col_loadtime)
684 for(i = 0; i < acc_levels; ++i)
685 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
686 acc_col_loadtime = time + 2;
690 vector Accuracy_GetColor(float accuracy)
695 return '0 0 0'; // return black, can't determine the right color
697 // find the max level lower than acc
699 while(j && accuracy < acc_lev[j])
702 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
703 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
705 color = color + factor * (acc_col[j+1] - color);