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];
126 entity tm = new(team);
134 vector HUD_GetFontsize(string cvarname)
137 v = stov(cvar_string(cvarname));
146 float PreviewExists(string name)
148 if(autocvar_cl_readpicture_force)
151 if (fexists(strcat(name, ".tga"))) return true;
152 if (fexists(strcat(name, ".png"))) return true;
153 if (fexists(strcat(name, ".jpg"))) return true;
154 if (fexists(strcat(name, ".pcx"))) return true;
159 vector rotate(vector v, float a)
162 // FTEQCC SUCKS AGAIN
163 w.x = v.x * cos(a) + v.y * sin(a);
164 w.y = -1 * v.x * sin(a) + v.y * cos(a);
168 // decolorizes and team colors the player name when needed
169 string playername(string thename, float teamid)
174 t = Team_ColorCode(teamid);
175 return strcat(t, strdecolorize(thename));
178 return strdecolorize(thename);
181 float cvar_or(string cv, float v)
191 vector project_3d_to_2d(vector vec)
193 vec = cs_project(vec);
194 if(cs_project_is_b0rked > 0)
196 vec.x *= vid_conwidth / vid_width;
197 vec.y *= vid_conheight / vid_height;
202 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
206 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
208 return 1.2 / (1.2 - fadelerp);
211 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
213 boxsize.x *= boxxsizefactor; // easier interface for text
214 return boxsize * (0.5 * (1 - sz));
217 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
219 vector line_dim = '0 0 0';
221 // left and right lines
223 line_dim.x = thickness;
225 drawfill(pos, line_dim, color, theAlpha, drawflag);
226 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
228 // upper and lower lines
230 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
231 line_dim.y = thickness;
232 drawfill(pos, line_dim, color, theAlpha, drawflag);
233 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
236 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
238 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
239 end_pos = pos + area;
241 current_pos.y = pos.y;
242 while (current_pos.y < end_pos.y)
244 current_pos.x = pos.x;
245 while (current_pos.x < end_pos.x)
247 new_size.x = min(sz.x, end_pos.x - current_pos.x);
248 new_size.y = min(sz.y, end_pos.y - current_pos.y);
249 ratio.x = new_size.x / sz.x;
250 ratio.y = new_size.y / sz.y;
251 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
252 current_pos.x += sz.x;
254 current_pos.y += sz.y;
258 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
261 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
263 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
266 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
268 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
269 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
272 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
273 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
274 SET_POS_AND_SZ_Y_ASPECT(false);
275 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
278 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
279 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
280 SET_POS_AND_SZ_Y_ASPECT(true);
281 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
284 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
287 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
289 drawfontscale = sz * '1 1 0';
290 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
291 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);
293 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
295 drawfontscale = '1 1 0';
298 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
299 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
300 SET_POS_AND_SZ_Y_ASPECT(false);
301 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
304 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
307 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
309 drawfontscale = sz * '1 1 0';
310 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
311 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);
312 drawfontscale = '1 1 0';
315 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
316 SET_POS_AND_SZ_Y_ASPECT(true);
317 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
320 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
321 float PolyDrawModelSurface(entity e, float i_s)
327 tex = getsurfacetexture(e, i_s);
329 return 0; // this is beyond the last one
330 n_t = getsurfacenumtriangles(e, i_s);
331 for(i_t = 0; i_t < n_t; ++i_t)
333 tri = getsurfacetriangle(e, i_s, i_t);
334 R_BeginPolygon(tex, 0);
335 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
336 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
337 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
342 void PolyDrawModel(entity e)
345 for(i_s = 0; ; ++i_s)
346 if(!PolyDrawModelSurface(e, i_s))
350 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
353 vector ringsize, v, t;
354 ringsize = radi * '1 1 0';
356 x = cos(f * 2 * M_PI);
357 y = sin(f * 2 * M_PI);
358 q = fabs(x) + fabs(y);
364 // draw full rectangle
365 R_BeginPolygon(pic, drawflag);
366 v = centre; t = '0.5 0.5 0';
367 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
368 R_PolygonVertex(v, t, rgb, a);
370 v = centre; t = '0.5 0.5 0';
371 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
372 R_PolygonVertex(v, t, rgb, a);
374 v = centre; t = '0.5 0.5 0';
375 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
376 R_PolygonVertex(v, t, rgb, a);
378 v = centre; t = '0.5 0.5 0';
379 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
380 R_PolygonVertex(v, t, rgb, a);
386 R_BeginPolygon(pic, drawflag);
387 v = centre; t = '0.5 0.5 0';
388 R_PolygonVertex(v, t, rgb, a);
390 v = centre; t = '0.5 0.5 0';
391 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
392 R_PolygonVertex(v, t, rgb, a);
397 // draw upper and first triangle
398 R_BeginPolygon(pic, drawflag);
399 v = centre; t = '0.5 0.5 0';
400 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
401 R_PolygonVertex(v, t, rgb, a);
403 v = centre; t = '0.5 0.5 0';
404 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
405 R_PolygonVertex(v, t, rgb, a);
407 v = centre; t = '0.5 0.5 0';
408 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
409 R_PolygonVertex(v, t, rgb, a);
411 R_BeginPolygon(pic, drawflag);
412 v = centre; t = '0.5 0.5 0';
413 R_PolygonVertex(v, t, rgb, a);
415 v = centre; t = '0.5 0.5 0';
416 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
417 R_PolygonVertex(v, t, rgb, a);
419 v = centre; t = '0.5 0.5 0';
420 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
421 R_PolygonVertex(v, t, rgb, a);
429 // draw upper triangle
430 R_BeginPolygon(pic, drawflag);
431 v = centre; t = '0.5 0.5 0';
432 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
433 R_PolygonVertex(v, t, rgb, a);
435 v = centre; t = '0.5 0.5 0';
436 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
437 R_PolygonVertex(v, t, rgb, a);
439 v = centre; t = '0.5 0.5 0';
440 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
441 R_PolygonVertex(v, t, rgb, a);
447 R_BeginPolygon(pic, drawflag);
448 v = centre; t = '0.5 0.5 0';
449 R_PolygonVertex(v, t, rgb, a);
451 v = centre; t = '0.5 0.5 0';
452 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
453 R_PolygonVertex(v, t, rgb, a);
458 // draw first triangle
459 R_BeginPolygon(pic, drawflag);
460 v = centre; t = '0.5 0.5 0';
461 R_PolygonVertex(v, t, rgb, a);
463 v = centre; t = '0.5 0.5 0';
464 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
465 R_PolygonVertex(v, t, rgb, a);
467 v = centre; t = '0.5 0.5 0';
468 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
469 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);
492 v = centre; t = '0.5 0.5 0';
493 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
494 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
495 R_PolygonVertex(v, t, rgb, a);
500 vector getplayerorigin(int pl)
504 e = CSQCModel_server2csqc(pl + 1);
508 e = entcs_receiver[pl];
512 return GETPLAYERORIGIN_ERROR;
515 float getplayeralpha(float pl)
519 e = CSQCModel_server2csqc(pl + 1);
526 vector getcsqcplayercolor(float pl)
530 e = CSQCModel_server2csqc(pl);
534 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
540 float getplayerisdead(float pl)
544 e = CSQCModel_server2csqc(pl + 1);
546 return e.csqcmodel_isdead;
551 void URI_Get_Callback(int id, float status, string data)
553 if(url_URI_Get_Callback(id, status, data))
557 else if (id == URI_GET_DISCARD)
561 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
564 Curl_URI_Get_Callback(id, status, data);
568 LOG_INFOF("Received HTTP request data for an invalid id %d.\n", id);
572 void draw_beginBoldFont()
574 drawfont = FONT_USER+2;
577 void draw_endBoldFont()
579 drawfont = FONT_USER+1;
582 void Accuracy_LoadLevels()
584 if(autocvar_accuracy_color_levels != acc_color_levels)
587 strunzone(acc_color_levels);
588 acc_color_levels = strzone(autocvar_accuracy_color_levels);
589 acc_levels = tokenize_console(acc_color_levels);
590 if(acc_levels > MAX_ACCURACY_LEVELS)
591 acc_levels = MAX_ACCURACY_LEVELS;
593 LOG_INFO("Warning: accuracy_color_levels must contain at least 2 values\n");
596 for(i = 0; i < acc_levels; ++i)
597 acc_lev[i] = stof(argv(i)) / 100.0;
601 void Accuracy_LoadColors()
603 if(time > acc_col_loadtime)
607 for(i = 0; i < acc_levels; ++i)
608 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
609 acc_col_loadtime = time + 2;
613 vector Accuracy_GetColor(float accuracy)
618 return '0 0 0'; // return black, can't determine the right color
620 // find the max level lower than acc
621 int j = acc_levels-1;
622 while(j && accuracy < acc_lev[j])
625 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
626 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
628 color = color + factor * (acc_col[j+1] - color);