1 #include "miscfunctions.qh"
6 #include "../common/command/generic.qh"
8 #include "../common/teams.qh"
9 #include "../common/util.qh"
11 #include "../csqcmodellib/cl_model.qh"
20 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
22 if(prev != e.sort_prev)
23 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
27 for(e = prev.sort_next; e; prev = e, e = e.sort_next)
29 if(prev != e.sort_prev)
30 error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
35 float RegisterPlayer(entity player)
39 for(pl = players.sort_next; pl; pl = pl.sort_next)
41 error("Player already registered!");
42 player.sort_next = players.sort_next;
43 player.sort_prev = players;
45 players.sort_next.sort_prev = player;
46 players.sort_next = player;
51 void RemovePlayer(entity player)
56 for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
61 error("Trying to remove a player which is not in the playerlist!");
64 parent.sort_next = player.sort_next;
66 player.sort_next.sort_prev = parent;
70 void MoveToLast(entity e)
82 float RegisterTeam(entity Team)
86 for(tm = teams.sort_next; tm; tm = tm.sort_next)
88 error("Team already registered!");
89 Team.sort_next = teams.sort_next;
90 Team.sort_prev = teams;
92 teams.sort_next.sort_prev = Team;
93 teams.sort_next = Team;
94 if(Team.team && Team.team != NUM_SPECTATOR)
100 void RemoveTeam(entity Team)
105 for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
110 LOG_INFO(_("Trying to remove a team which is not in the teamlist!"));
113 parent.sort_next = Team.sort_next;
115 Team.sort_next.sort_prev = parent;
116 if(Team.team && Team.team != NUM_SPECTATOR)
121 entity GetTeam(int Team, bool add)
123 int num = (Team == NUM_SPECTATOR) ? 16 : Team;
125 return teamslots[num];
135 vector HUD_GetFontsize(string cvarname)
138 v = stov(cvar_string(cvarname));
147 float PreviewExists(string name)
149 if(autocvar_cl_readpicture_force)
152 if (fexists(strcat(name, ".tga"))) return true;
153 if (fexists(strcat(name, ".png"))) return true;
154 if (fexists(strcat(name, ".jpg"))) return true;
155 if (fexists(strcat(name, ".pcx"))) return true;
160 vector rotate(vector v, float a)
163 // FTEQCC SUCKS AGAIN
164 w.x = v.x * cos(a) + v.y * sin(a);
165 w.y = -1 * v.x * sin(a) + v.y * cos(a);
169 // decolorizes and team colors the player name when needed
170 string playername(string thename, float teamid)
175 t = Team_ColorCode(teamid);
176 return strcat(t, strdecolorize(thename));
179 return strdecolorize(thename);
182 float cvar_or(string cv, float v)
192 vector project_3d_to_2d(vector vec)
194 vec = cs_project(vec);
195 if(cs_project_is_b0rked > 0)
197 vec.x *= vid_conwidth / vid_width;
198 vec.y *= vid_conheight / vid_height;
203 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
207 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
209 return 1.2 / (1.2 - fadelerp);
212 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
214 boxsize.x *= boxxsizefactor; // easier interface for text
215 return boxsize * (0.5 * (1 - sz));
218 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
220 vector line_dim = '0 0 0';
222 // left and right lines
224 line_dim.x = thickness;
226 drawfill(pos, line_dim, color, theAlpha, drawflag);
227 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
229 // upper and lower lines
231 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
232 line_dim.y = thickness;
233 drawfill(pos, line_dim, color, theAlpha, drawflag);
234 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
237 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
239 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
240 end_pos = pos + area;
242 current_pos.y = pos.y;
243 while (current_pos.y < end_pos.y)
245 current_pos.x = pos.x;
246 while (current_pos.x < end_pos.x)
248 new_size.x = min(sz.x, end_pos.x - current_pos.x);
249 new_size.y = min(sz.y, end_pos.y - current_pos.y);
250 ratio.x = new_size.x / sz.x;
251 ratio.y = new_size.y / sz.y;
252 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
253 current_pos.x += sz.x;
255 current_pos.y += sz.y;
259 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
262 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
264 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
267 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
269 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
270 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
273 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
274 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
275 SET_POS_AND_SZ_Y_ASPECT(false);
276 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
279 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
280 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
281 SET_POS_AND_SZ_Y_ASPECT(true);
282 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
285 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
288 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
290 drawfontscale = sz * '1 1 0';
291 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
292 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);
294 // (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
296 drawfontscale = '1 1 0';
299 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
300 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
301 SET_POS_AND_SZ_Y_ASPECT(false);
302 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
305 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
308 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
310 drawfontscale = sz * '1 1 0';
311 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
312 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);
313 drawfontscale = '1 1 0';
316 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
317 SET_POS_AND_SZ_Y_ASPECT(true);
318 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
321 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
322 float PolyDrawModelSurface(entity e, float i_s)
328 tex = getsurfacetexture(e, i_s);
330 return 0; // this is beyond the last one
331 n_t = getsurfacenumtriangles(e, i_s);
332 for(i_t = 0; i_t < n_t; ++i_t)
334 tri = getsurfacetriangle(e, i_s, i_t);
335 R_BeginPolygon(tex, 0);
336 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
337 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
338 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
343 void PolyDrawModel(entity e)
346 for(i_s = 0; ; ++i_s)
347 if(!PolyDrawModelSurface(e, i_s))
351 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
354 vector ringsize, v, t;
355 ringsize = radi * '1 1 0';
357 x = cos(f * 2 * M_PI);
358 y = sin(f * 2 * M_PI);
359 q = fabs(x) + fabs(y);
365 // draw full rectangle
366 R_BeginPolygon(pic, drawflag);
367 v = centre; t = '0.5 0.5 0';
368 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
369 R_PolygonVertex(v, t, rgb, a);
371 v = centre; t = '0.5 0.5 0';
372 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
373 R_PolygonVertex(v, t, rgb, a);
375 v = centre; t = '0.5 0.5 0';
376 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
377 R_PolygonVertex(v, t, rgb, a);
379 v = centre; t = '0.5 0.5 0';
380 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
381 R_PolygonVertex(v, t, rgb, a);
387 R_BeginPolygon(pic, drawflag);
388 v = centre; t = '0.5 0.5 0';
389 R_PolygonVertex(v, t, rgb, a);
391 v = centre; t = '0.5 0.5 0';
392 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
393 R_PolygonVertex(v, t, rgb, a);
398 // draw upper and first triangle
399 R_BeginPolygon(pic, drawflag);
400 v = centre; t = '0.5 0.5 0';
401 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
402 R_PolygonVertex(v, t, rgb, a);
404 v = centre; t = '0.5 0.5 0';
405 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
406 R_PolygonVertex(v, t, rgb, a);
408 v = centre; t = '0.5 0.5 0';
409 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
410 R_PolygonVertex(v, t, rgb, a);
412 R_BeginPolygon(pic, drawflag);
413 v = centre; t = '0.5 0.5 0';
414 R_PolygonVertex(v, t, rgb, a);
416 v = centre; t = '0.5 0.5 0';
417 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
418 R_PolygonVertex(v, t, rgb, a);
420 v = centre; t = '0.5 0.5 0';
421 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
422 R_PolygonVertex(v, t, rgb, a);
430 // draw upper triangle
431 R_BeginPolygon(pic, drawflag);
432 v = centre; t = '0.5 0.5 0';
433 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
434 R_PolygonVertex(v, t, rgb, a);
436 v = centre; t = '0.5 0.5 0';
437 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
438 R_PolygonVertex(v, t, rgb, a);
440 v = centre; t = '0.5 0.5 0';
441 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
442 R_PolygonVertex(v, t, rgb, a);
448 R_BeginPolygon(pic, drawflag);
449 v = centre; t = '0.5 0.5 0';
450 R_PolygonVertex(v, t, rgb, a);
452 v = centre; t = '0.5 0.5 0';
453 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
454 R_PolygonVertex(v, t, rgb, a);
459 // draw first triangle
460 R_BeginPolygon(pic, drawflag);
461 v = centre; t = '0.5 0.5 0';
462 R_PolygonVertex(v, t, rgb, a);
464 v = centre; t = '0.5 0.5 0';
465 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
466 R_PolygonVertex(v, t, rgb, a);
468 v = centre; t = '0.5 0.5 0';
469 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
470 R_PolygonVertex(v, t, rgb, a);
481 R_BeginPolygon(pic, drawflag);
482 v = centre; t = '0.5 0.5 0';
483 R_PolygonVertex(v, t, rgb, a);
485 v = centre; t = '0.5 0.5 0';
486 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
487 R_PolygonVertex(v, t, rgb, a);
493 v = centre; t = '0.5 0.5 0';
494 v.x += x * 0.5 * ringsize.x; t += x * '0.5 0.5 0';
495 v.y += y * 0.5 * ringsize.y; t += y * '0.5 -0.5 0';
496 R_PolygonVertex(v, t, rgb, a);
501 vector getplayerorigin(int pl)
505 e = CSQCModel_server2csqc(pl + 1);
509 e = entcs_receiver[pl];
513 return GETPLAYERORIGIN_ERROR;
516 float getplayeralpha(float pl)
520 e = CSQCModel_server2csqc(pl + 1);
527 vector getcsqcplayercolor(float pl)
531 e = CSQCModel_server2csqc(pl);
535 return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
541 float getplayerisdead(float pl)
545 e = CSQCModel_server2csqc(pl + 1);
547 return e.csqcmodel_isdead;
552 void URI_Get_Callback(int id, float status, string data)
554 if(url_URI_Get_Callback(id, status, data))
558 else if (id == URI_GET_DISCARD)
562 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
565 Curl_URI_Get_Callback(id, status, data);
569 LOG_INFOF("Received HTTP request data for an invalid id %d.\n", id);
573 void draw_beginBoldFont()
575 drawfont = FONT_USER+2;
578 void draw_endBoldFont()
580 drawfont = FONT_USER+1;
583 void Accuracy_LoadLevels()
585 if(autocvar_accuracy_color_levels != acc_color_levels)
588 strunzone(acc_color_levels);
589 acc_color_levels = strzone(autocvar_accuracy_color_levels);
590 acc_levels = tokenize_console(acc_color_levels);
591 if(acc_levels > MAX_ACCURACY_LEVELS)
592 acc_levels = MAX_ACCURACY_LEVELS;
594 LOG_INFO("Warning: accuracy_color_levels must contain at least 2 values\n");
597 for(i = 0; i < acc_levels; ++i)
598 acc_lev[i] = stof(argv(i)) / 100.0;
602 void Accuracy_LoadColors()
604 if(time > acc_col_loadtime)
608 for(i = 0; i < acc_levels; ++i)
609 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
610 acc_col_loadtime = time + 2;
614 vector Accuracy_GetColor(float accuracy)
619 return '0 0 0'; // return black, can't determine the right color
621 // find the max level lower than acc
622 int j = acc_levels-1;
623 while(j && accuracy < acc_lev[j])
626 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
627 factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
629 color = color + factor * (acc_col[j+1] - color);