1 #include "miscfunctions.qh"
5 #include "../common/command/generic.qh"
7 #include "../common/teams.qh"
9 #include "../lib/csqcmodel/cl_model.qh"
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"));
25 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
27 if(prev != e.sort_prev)
28 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
33 float RegisterPlayer(entity player)
37 for(pl = players.sort_next; pl; pl = pl.sort_next)
39 error("Player already registered!");
40 player.sort_next = players.sort_next;
41 player.sort_prev = players;
43 players.sort_next.sort_prev = player;
44 players.sort_next = player;
49 void RemovePlayer(entity player)
54 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
59 error("Trying to remove a player which is not in the playerlist!");
62 parent.sort_next = player.sort_next;
64 player.sort_next.sort_prev = parent;
68 void MoveToLast(entity e)
80 float RegisterTeam(entity Team)
84 for(tm = teams.sort_next; tm; tm = tm.sort_next)
86 error("Team already registered!");
87 Team.sort_next = teams.sort_next;
88 Team.sort_prev = teams;
90 teams.sort_next.sort_prev = Team;
91 teams.sort_next = Team;
92 if(Team.team && Team.team != NUM_SPECTATOR)
98 void RemoveTeam(entity Team)
103 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
108 LOG_INFO(_("Trying to remove a team which is not in the teamlist!"));
111 parent.sort_next = Team.sort_next;
113 Team.sort_next.sort_prev = parent;
114 if(Team.team && Team.team != NUM_SPECTATOR)
119 entity GetTeam(int Team, bool add)
121 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
123 return teamslots[num];
133 vector HUD_GetFontsize(string cvarname)
136 v = stov(cvar_string(cvarname));
145 float PreviewExists(string name)
147 if(autocvar_cl_readpicture_force)
150 if (fexists(strcat(name, ".tga"))) return true;
151 if (fexists(strcat(name, ".png"))) return true;
152 if (fexists(strcat(name, ".jpg"))) return true;
153 if (fexists(strcat(name, ".pcx"))) return true;
158 vector rotate(vector v, float a)
161 // FTEQCC SUCKS AGAIN
162 w.x = v.x * cos(a) + v.y * sin(a);
163 w.y = -1 * v.x * sin(a) + v.y * cos(a);
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 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
260 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
262 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
265 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
267 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
268 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
271 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
272 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
273 SET_POS_AND_SZ_Y_ASPECT(false);
274 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
277 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
278 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
279 SET_POS_AND_SZ_Y_ASPECT(true);
280 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
283 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
286 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
288 drawfontscale = sz * '1 1 0';
289 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
290 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);
292 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
294 drawfontscale = '1 1 0';
297 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
298 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
299 SET_POS_AND_SZ_Y_ASPECT(false);
300 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
303 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
306 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
308 drawfontscale = sz * '1 1 0';
309 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
310 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);
311 drawfontscale = '1 1 0';
314 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
315 SET_POS_AND_SZ_Y_ASPECT(true);
316 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
319 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
320 float PolyDrawModelSurface(entity e, float i_s)
326 tex = getsurfacetexture(e, i_s);
328 return 0; // this is beyond the last one
329 n_t = getsurfacenumtriangles(e, i_s);
330 for(i_t = 0; i_t < n_t; ++i_t)
332 tri = getsurfacetriangle(e, i_s, i_t);
333 R_BeginPolygon(tex, 0);
334 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
335 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
336 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
341 void PolyDrawModel(entity e)
344 for(i_s = 0; ; ++i_s)
345 if(!PolyDrawModelSurface(e, i_s))
349 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
352 vector ringsize, v, t;
353 ringsize = radi * '1 1 0';
355 x = cos(f * 2 * M_PI);
356 y = sin(f * 2 * M_PI);
357 q = fabs(x) + fabs(y);
363 // draw full rectangle
364 R_BeginPolygon(pic, drawflag);
365 v = centre; t = '0.5 0.5 0';
366 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
367 R_PolygonVertex(v, t, rgb, a);
369 v = centre; t = '0.5 0.5 0';
370 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
371 R_PolygonVertex(v, t, rgb, a);
373 v = centre; t = '0.5 0.5 0';
374 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
375 R_PolygonVertex(v, t, rgb, a);
377 v = centre; t = '0.5 0.5 0';
378 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
379 R_PolygonVertex(v, t, rgb, a);
385 R_BeginPolygon(pic, drawflag);
386 v = centre; t = '0.5 0.5 0';
387 R_PolygonVertex(v, t, rgb, a);
389 v = centre; t = '0.5 0.5 0';
390 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
391 R_PolygonVertex(v, t, rgb, a);
396 // draw upper and first triangle
397 R_BeginPolygon(pic, drawflag);
398 v = centre; t = '0.5 0.5 0';
399 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
400 R_PolygonVertex(v, t, rgb, a);
402 v = centre; t = '0.5 0.5 0';
403 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
404 R_PolygonVertex(v, t, rgb, a);
406 v = centre; t = '0.5 0.5 0';
407 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
408 R_PolygonVertex(v, t, rgb, a);
410 R_BeginPolygon(pic, drawflag);
411 v = centre; t = '0.5 0.5 0';
412 R_PolygonVertex(v, t, rgb, a);
414 v = centre; t = '0.5 0.5 0';
415 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
416 R_PolygonVertex(v, t, rgb, a);
418 v = centre; t = '0.5 0.5 0';
419 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
420 R_PolygonVertex(v, t, rgb, a);
428 // draw upper triangle
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);
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 first triangle
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);
466 v = centre; t = '0.5 0.5 0';
467 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
468 R_PolygonVertex(v, t, rgb, a);
479 R_BeginPolygon(pic, drawflag);
480 v = centre; t = '0.5 0.5 0';
481 R_PolygonVertex(v, t, rgb, a);
483 v = centre; t = '0.5 0.5 0';
484 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
485 R_PolygonVertex(v, t, rgb, a);
491 v = centre; t = '0.5 0.5 0';
492 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
493 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
494 R_PolygonVertex(v, t, rgb, a);
499 vector getplayerorigin(int pl)
503 e = CSQCModel_server2csqc(pl + 1);
507 e = entcs_receiver[pl];
511 return GETPLAYERORIGIN_ERROR;
514 float getplayeralpha(float pl)
518 e = CSQCModel_server2csqc(pl + 1);
525 vector getcsqcplayercolor(float pl)
529 e = CSQCModel_server2csqc(pl);
533 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
539 float getplayerisdead(float pl)
543 e = CSQCModel_server2csqc(pl + 1);
545 return e.csqcmodel_isdead;
550 void URI_Get_Callback(int id, float status, string data)
552 if(url_URI_Get_Callback(id, status, data))
556 else if (id == URI_GET_DISCARD)
560 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
563 Curl_URI_Get_Callback(id, status, data);
567 LOG_INFOF("Received HTTP request data for an invalid id %d.\n", id);
571 void draw_beginBoldFont()
573 drawfont = FONT_USER+2;
576 void draw_endBoldFont()
578 drawfont = FONT_USER+1;
581 void Accuracy_LoadLevels()
583 if(autocvar_accuracy_color_levels != acc_color_levels)
586 strunzone(acc_color_levels);
587 acc_color_levels = strzone(autocvar_accuracy_color_levels);
588 acc_levels = tokenize_console(acc_color_levels);
589 if(acc_levels > MAX_ACCURACY_LEVELS)
590 acc_levels = MAX_ACCURACY_LEVELS;
592 LOG_INFO("Warning: accuracy_color_levels must contain at least 2 values\n");
595 for(i = 0; i < acc_levels; ++i)
596 acc_lev[i] = stof(argv(i)) / 100.0;
600 void Accuracy_LoadColors()
602 if(time > acc_col_loadtime)
606 for(i = 0; i < acc_levels; ++i)
607 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
608 acc_col_loadtime = time + 2;
612 vector Accuracy_GetColor(float accuracy)
617 return '0 0 0'; // return black, can't determine the right color
619 // find the max level lower than acc
620 int j = acc_levels-1;
621 while(j && accuracy < acc_lev[j])
624 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
625 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
627 color = color + factor * (acc_col[j+1] - color);