1 #include "miscfunctions.qh"
7 #include "../common/command/generic.qh"
9 #include "../common/teams.qh"
10 #include "../common/util.qh"
12 #include "../csqcmodellib/cl_model.qh"
14 #include "../warpzonelib/mathlib.qh"
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"));
29 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
31 if(prev != e.sort_prev)
32 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
37 float RegisterPlayer(entity player)
41 for(pl = players.sort_next; pl; pl = pl.sort_next)
43 error("Player already registered!");
44 player.sort_next = players.sort_next;
45 player.sort_prev = players;
47 players.sort_next.sort_prev = player;
48 players.sort_next = player;
53 void RemovePlayer(entity player)
58 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
63 error("Trying to remove a player which is not in the playerlist!");
66 parent.sort_next = player.sort_next;
68 player.sort_next.sort_prev = parent;
72 void MoveToLast(entity e)
84 float RegisterTeam(entity Team)
88 for(tm = teams.sort_next; tm; tm = tm.sort_next)
90 error("Team already registered!");
91 Team.sort_next = teams.sort_next;
92 Team.sort_prev = teams;
94 teams.sort_next.sort_prev = Team;
95 teams.sort_next = Team;
96 if(Team.team && Team.team != NUM_SPECTATOR)
102 void RemoveTeam(entity Team)
107 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
112 print(_("Trying to remove a team which is not in the teamlist!"));
115 parent.sort_next = Team.sort_next;
117 Team.sort_next.sort_prev = parent;
118 if(Team.team && Team.team != NUM_SPECTATOR)
123 entity GetTeam(int Team, bool add)
125 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
127 return teamslots[num];
137 vector HUD_GetFontsize(string cvarname)
140 v = stov(cvar_string(cvarname));
149 float PreviewExists(string name)
151 if(autocvar_cl_readpicture_force)
154 if (fexists(strcat(name, ".tga"))) return true;
155 if (fexists(strcat(name, ".png"))) return true;
156 if (fexists(strcat(name, ".jpg"))) return true;
157 if (fexists(strcat(name, ".pcx"))) return true;
162 vector rotate(vector v, float a)
165 // FTEQCC SUCKS AGAIN
166 w.x = v.x * cos(a) + v.y * sin(a);
167 w.y = -1 * v.x * sin(a) + v.y * cos(a);
171 string ColorTranslateRGB(string s)
173 if(ColorTranslateMode & 1)
174 return strdecolorize(s);
179 // decolorizes and team colors the player name when needed
180 string playername(string thename, float teamid)
185 t = Team_ColorCode(teamid);
186 return strcat(t, strdecolorize(thename));
189 return strdecolorize(thename);
192 float cvar_or(string cv, float v)
202 vector project_3d_to_2d(vector vec)
204 vec = cs_project(vec);
205 if(cs_project_is_b0rked > 0)
207 vec.x *= vid_conwidth / vid_width;
208 vec.y *= vid_conheight / vid_height;
213 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
217 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
219 return 1.2 / (1.2 - fadelerp);
222 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
224 boxsize.x *= boxxsizefactor; // easier interface for text
225 return boxsize * (0.5 * (1 - sz));
228 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
230 vector line_dim = '0 0 0';
232 // left and right lines
234 line_dim.x = thickness;
236 drawfill(pos, line_dim, color, theAlpha, drawflag);
237 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
239 // upper and lower lines
241 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
242 line_dim.y = thickness;
243 drawfill(pos, line_dim, color, theAlpha, drawflag);
244 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
247 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
249 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
250 end_pos = pos + area;
252 current_pos.y = pos.y;
253 while (current_pos.y < end_pos.y)
255 current_pos.x = pos.x;
256 while (current_pos.x < end_pos.x)
258 new_size.x = min(sz.x, end_pos.x - current_pos.x);
259 new_size.y = min(sz.y, end_pos.y - current_pos.y);
260 ratio.x = new_size.x / sz.x;
261 ratio.y = new_size.y / sz.y;
262 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
263 current_pos.x += sz.x;
265 current_pos.y += sz.y;
269 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
272 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
274 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
277 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
279 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
280 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
283 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
284 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
285 SET_POS_AND_SZ_Y_ASPECT(false);
286 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
289 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
290 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
291 SET_POS_AND_SZ_Y_ASPECT(true);
292 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
295 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
298 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
300 drawfontscale = sz * '1 1 0';
301 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
302 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);
304 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
306 drawfontscale = '1 1 0';
309 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
310 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
311 SET_POS_AND_SZ_Y_ASPECT(false);
312 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
315 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
318 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
320 drawfontscale = sz * '1 1 0';
321 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
322 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);
323 drawfontscale = '1 1 0';
326 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
327 SET_POS_AND_SZ_Y_ASPECT(true);
328 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
331 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
332 float PolyDrawModelSurface(entity e, float i_s)
338 tex = getsurfacetexture(e, i_s);
340 return 0; // this is beyond the last one
341 n_t = getsurfacenumtriangles(e, i_s);
342 for(i_t = 0; i_t < n_t; ++i_t)
344 tri = getsurfacetriangle(e, i_s, i_t);
345 R_BeginPolygon(tex, 0);
346 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
347 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
348 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
353 void PolyDrawModel(entity e)
356 for(i_s = 0; ; ++i_s)
357 if(!PolyDrawModelSurface(e, i_s))
361 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
364 vector ringsize, v, t;
365 ringsize = radi * '1 1 0';
367 x = cos(f * 2 * M_PI);
368 y = sin(f * 2 * M_PI);
369 q = fabs(x) + fabs(y);
375 // draw full rectangle
376 R_BeginPolygon(pic, drawflag);
377 v = centre; t = '0.5 0.5 0';
378 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
379 R_PolygonVertex(v, t, rgb, a);
381 v = centre; t = '0.5 0.5 0';
382 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
383 R_PolygonVertex(v, t, rgb, a);
385 v = centre; t = '0.5 0.5 0';
386 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
387 R_PolygonVertex(v, t, rgb, a);
389 v = centre; t = '0.5 0.5 0';
390 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
391 R_PolygonVertex(v, t, rgb, a);
397 R_BeginPolygon(pic, drawflag);
398 v = centre; t = '0.5 0.5 0';
399 R_PolygonVertex(v, t, rgb, a);
401 v = centre; t = '0.5 0.5 0';
402 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
403 R_PolygonVertex(v, t, rgb, a);
408 // draw upper and first triangle
409 R_BeginPolygon(pic, drawflag);
410 v = centre; t = '0.5 0.5 0';
411 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
412 R_PolygonVertex(v, t, rgb, a);
414 v = centre; t = '0.5 0.5 0';
415 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
416 R_PolygonVertex(v, t, rgb, a);
418 v = centre; t = '0.5 0.5 0';
419 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
420 R_PolygonVertex(v, t, rgb, a);
422 R_BeginPolygon(pic, drawflag);
423 v = centre; t = '0.5 0.5 0';
424 R_PolygonVertex(v, t, rgb, a);
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);
440 // draw upper triangle
441 R_BeginPolygon(pic, drawflag);
442 v = centre; t = '0.5 0.5 0';
443 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
444 R_PolygonVertex(v, t, rgb, a);
446 v = centre; t = '0.5 0.5 0';
447 v.y += 0.5 * ringsize.y; 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);
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 first triangle
470 R_BeginPolygon(pic, drawflag);
471 v = centre; t = '0.5 0.5 0';
472 R_PolygonVertex(v, t, rgb, a);
474 v = centre; t = '0.5 0.5 0';
475 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
476 R_PolygonVertex(v, t, rgb, a);
478 v = centre; t = '0.5 0.5 0';
479 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
480 R_PolygonVertex(v, t, rgb, a);
491 R_BeginPolygon(pic, drawflag);
492 v = centre; t = '0.5 0.5 0';
493 R_PolygonVertex(v, t, rgb, a);
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);
503 v = centre; t = '0.5 0.5 0';
504 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
505 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
506 R_PolygonVertex(v, t, rgb, a);
511 vector getplayerorigin(int pl)
515 e = CSQCModel_server2csqc(pl + 1);
519 e = entcs_receiver[pl];
523 return GETPLAYERORIGIN_ERROR;
526 float getplayeralpha(float pl)
530 e = CSQCModel_server2csqc(pl + 1);
537 vector getcsqcplayercolor(float pl)
541 e = CSQCModel_server2csqc(pl);
545 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
551 float getplayerisdead(float pl)
555 e = CSQCModel_server2csqc(pl + 1);
557 return e.csqcmodel_isdead;
562 void URI_Get_Callback(int id, float status, string data)
564 if(url_URI_Get_Callback(id, status, data))
568 else if (id == URI_GET_DISCARD)
572 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
575 Curl_URI_Get_Callback(id, status, data);
579 printf("Received HTTP request data for an invalid id %d.\n", id);
583 void draw_beginBoldFont()
585 drawfont = FONT_USER+2;
588 void draw_endBoldFont()
590 drawfont = FONT_USER+1;
593 void Accuracy_LoadLevels()
595 if(autocvar_accuracy_color_levels != acc_color_levels)
598 strunzone(acc_color_levels);
599 acc_color_levels = strzone(autocvar_accuracy_color_levels);
600 acc_levels = tokenize_console(acc_color_levels);
601 if(acc_levels > MAX_ACCURACY_LEVELS)
602 acc_levels = MAX_ACCURACY_LEVELS;
604 print("Warning: accuracy_color_levels must contain at least 2 values\n");
607 for(i = 0; i < acc_levels; ++i)
608 acc_lev[i] = stof(argv(i)) / 100.0;
612 void Accuracy_LoadColors()
614 if(time > acc_col_loadtime)
618 for(i = 0; i < acc_levels; ++i)
619 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
620 acc_col_loadtime = time + 2;
624 vector Accuracy_GetColor(float accuracy)
629 return '0 0 0'; // return black, can't determine the right color
631 // find the max level lower than acc
632 int j = acc_levels-1;
633 while(j && accuracy < acc_lev[j])
636 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
637 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
639 color = color + factor * (acc_col[j+1] - color);