fcc248220d4af90ecdb4ad3131f66151e931d6c5
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
1 entity players;
2 entity teams;
3 float team_count; // real teams
4
5 void AuditLists()
6 {
7         entity e;
8         entity prev;
9
10         prev = players;
11         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
12         {
13                 if(prev != e.sort_prev)
14                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
15         }
16
17         prev = teams;
18         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
19         {
20                 if(prev != e.sort_prev)
21                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
22         }
23 }
24
25
26 float RegisterPlayer(entity player)
27 {
28         entity pl;
29         AuditLists();
30         for(pl = players.sort_next; pl; pl = pl.sort_next)
31                 if(pl == player)
32                         error("Player already registered!");
33         player.sort_next = players.sort_next;
34         player.sort_prev = players;
35         if(players.sort_next)
36                 players.sort_next.sort_prev = player;
37         players.sort_next = player;
38         AuditLists();
39         return true;
40 }
41
42 void RemovePlayer(entity player)
43 {
44         entity pl, parent;
45         AuditLists();
46         parent = players;
47         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
48                 parent = pl;
49
50         if(!pl)
51         {
52                 error("Trying to remove a player which is not in the playerlist!");
53                 return;
54         }
55         parent.sort_next = player.sort_next;
56         if(player.sort_next)
57                 player.sort_next.sort_prev = parent;
58         AuditLists();
59 }
60
61 void MoveToLast(entity e)
62 {
63         AuditLists();
64         other = e.sort_next;
65         while(other)
66         {
67                 SORT_SWAP(other, e);
68                 other = e.sort_next;
69         }
70         AuditLists();
71 }
72
73 float RegisterTeam(entity Team)
74 {
75         entity tm;
76         AuditLists();
77         for(tm = teams.sort_next; tm; tm = tm.sort_next)
78                 if(tm == Team)
79                         error("Team already registered!");
80         Team.sort_next = teams.sort_next;
81         Team.sort_prev = teams;
82         if(teams.sort_next)
83                 teams.sort_next.sort_prev = Team;
84         teams.sort_next = Team;
85         if(Team.team && Team.team != NUM_SPECTATOR)
86                 ++team_count;
87         AuditLists();
88         return true;
89 }
90
91 void RemoveTeam(entity Team)
92 {
93         entity tm, parent;
94         AuditLists();
95         parent = teams;
96         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
97                 parent = tm;
98
99         if(!tm)
100         {
101                 print(_("Trying to remove a team which is not in the teamlist!"));
102                 return;
103         }
104         parent.sort_next = Team.sort_next;
105         if(Team.sort_next)
106                 Team.sort_next.sort_prev = parent;
107         if(Team.team && Team.team != NUM_SPECTATOR)
108                 --team_count;
109         AuditLists();
110 }
111
112 entity GetTeam(int Team, bool add)
113 {
114         float num;
115         entity tm;
116         num = (Team == NUM_SPECTATOR) ? 16 : Team;
117         if(teamslots[num])
118                 return teamslots[num];
119         if (!add)
120                 return world;
121         tm = spawn();
122         tm.team = Team;
123         teamslots[num] = tm;
124         RegisterTeam(tm);
125         return tm;
126 }
127
128 vector HUD_GetFontsize(string cvarname)
129 {
130         vector v;
131         v = stov(cvar_string(cvarname));
132         if(v_x == 0)
133                 v = '8 8 0';
134         if(v_y == 0)
135                 v_y = v.x;
136         v_z = 0;
137         return v;
138 }
139
140 float PreviewExists(string name)
141 {
142         if(autocvar_cl_readpicture_force)
143                 return false;
144
145         if (fexists(strcat(name, ".tga"))) return true;
146         if (fexists(strcat(name, ".png"))) return true;
147         if (fexists(strcat(name, ".jpg"))) return true;
148         if (fexists(strcat(name, ".pcx"))) return true;
149
150         return false;
151 }
152
153 vector rotate(vector v, float a)
154 {
155         vector w = '0 0 0';
156         // FTEQCC SUCKS AGAIN
157         w_x =      v.x * cos(a) + v.y * sin(a);
158         w_y = -1 * v.x * sin(a) + v.y * cos(a);
159         return w;
160 }
161
162 int ColorTranslateMode;
163
164 string ColorTranslateRGB(string s)
165 {
166         if(ColorTranslateMode & 1)
167                 return strdecolorize(s);
168         else
169                 return s;
170 }
171
172 // decolorizes and team colors the player name when needed
173 string playername(string thename, float teamid)
174 {
175     string t;
176     if (teamplay)
177     {
178         t = Team_ColorCode(teamid);
179         return strcat(t, strdecolorize(thename));
180     }
181     else
182         return strdecolorize(thename);
183 }
184
185 float cvar_or(string cv, float v)
186 {
187         string s;
188         s = cvar_string(cv);
189         if(s == "")
190                 return v;
191         else
192                 return stof(s);
193 }
194
195 vector project_3d_to_2d(vector vec)
196 {
197         vec = cs_project(vec);
198         if(cs_project_is_b0rked > 0)
199         {
200                 vec.x *= vid_conwidth / vid_width;
201                 vec.y *= vid_conheight / vid_height;
202         }
203         return vec;
204 }
205
206 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
207 {
208 }
209
210 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
211 {
212         return 1.2 / (1.2 - fadelerp);
213 }
214
215 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
216 {
217         boxsize.x *= boxxsizefactor; // easier interface for text
218         return boxsize * (0.5 * (1 - sz));
219 }
220
221 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
222 {
223         vector line_dim = '0 0 0';
224
225         // left and right lines
226         pos.x -= thickness;
227         line_dim_x = thickness;
228         line_dim_y = dim.y;
229         drawfill(pos, line_dim, color, theAlpha, drawflag);
230         drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
231
232         // upper and lower lines
233         pos.y -= thickness;
234         line_dim_x = dim.x + thickness * 2; // make upper and lower lines longer
235         line_dim_y = thickness;
236         drawfill(pos, line_dim, color, theAlpha, drawflag);
237         drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
238 }
239
240 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
241 {
242         vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
243         end_pos = pos + area;
244
245         current_pos_y = pos.y;
246         while (current_pos.y < end_pos.y)
247         {
248                 current_pos_x = pos.x;
249                 while (current_pos.x < end_pos.x)
250                 {
251                         new_size_x = min(sz.x, end_pos.x - current_pos.x);
252                         new_size_y = min(sz.y, end_pos.y - current_pos.y);
253                         ratio_x = new_size.x / sz.x;
254                         ratio_y = new_size.y / sz.y;
255                         drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
256                         current_pos.x += sz.x;
257                 }
258                 current_pos.y += sz.y;
259         }
260 }
261
262 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
263 float _drawpic_imgaspect;
264 vector _drawpic_imgsize;
265 vector _drawpic_sz;
266 float _drawpic_oldsz;
267 string _drawpic_picpath;
268 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
269         do {\
270                 _drawpic_imgsize = draw_getimagesize(pic);\
271                 if(_drawpic_imgsize != '0 0 0') {\
272                         _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
273                         _drawpic_sz = mySize;\
274                         if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
275                                 _drawpic_oldsz = _drawpic_sz.x;\
276                                 _drawpic_sz_x = _drawpic_sz.y * _drawpic_imgaspect;\
277                                 if(_drawpic_sz.x)\
278                                         drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
279                         } else {\
280                                 _drawpic_oldsz = _drawpic_sz.y;\
281                                 _drawpic_sz_y = _drawpic_sz.x / _drawpic_imgaspect;\
282                                 if(_drawpic_sz.y)\
283                                         drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
284                         }\
285                 }\
286         } while(0)
287
288 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
289 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
290         do{\
291                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
292                 if(precache_pic(_drawpic_picpath) == "") {\
293                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
294                 }\
295                 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
296                 _drawpic_picpath = string_null;\
297         } while(0)
298
299 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
300 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
301         do{\
302                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
303                 if(precache_pic(_drawpic_picpath) == "") {\
304                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
305                 }\
306                 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
307                 _drawpic_picpath = string_null;\
308         } while(0)
309
310 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
311 {
312         float sz;
313         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
314
315         drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
316 }
317
318 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
319 {
320         drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
321         drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
322 }
323 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do {                                                                                                                                      \
324         float textaspect, oldsz;                                                                                                                                                                                \
325         textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
326         if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
327                 oldsz = sz.x;                                                                                                                                                                                           \
328                 sz_x = sz.y * textaspect;                                                                                                                                                                       \
329                 pos.x += (oldsz - sz.x) * 0.5;                                                                                                                                                          \
330         } else {                                                                                                                                                                                                                \
331                 oldsz = sz.y;                                                                                                                                                                                           \
332                 sz_y = sz.x / textaspect;                                                                                                                                                                       \
333                 pos.y += (oldsz - sz.y) * 0.5;                                                                                                                                                          \
334         }                                                                                                                                                                                                                               \
335 } while(0)
336
337 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
338 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
339         SET_POS_AND_SZ_Y_ASPECT(false);
340         drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
341 }
342
343 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
344 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
345         SET_POS_AND_SZ_Y_ASPECT(true);
346         drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
347 }
348
349 vector drawfontscale;
350 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
351 {
352         float sz;
353         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
354
355         drawfontscale = sz * '1 1 0';
356         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
357         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);
358         // width parameter:
359         //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
360         //    SIZE1
361         drawfontscale = '1 1 0';
362 }
363
364 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
365 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
366         SET_POS_AND_SZ_Y_ASPECT(false);
367         drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
368 }
369
370 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
371 {
372         float sz;
373         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
374
375         drawfontscale = sz * '1 1 0';
376         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
377         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);
378         drawfontscale = '1 1 0';
379 }
380
381 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
382         SET_POS_AND_SZ_Y_ASPECT(true);
383         drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
384 }
385
386 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
387 float PolyDrawModelSurface(entity e, float i_s)
388 {
389         float i_t;
390         float n_t;
391         vector tri;
392         string tex;
393         tex = getsurfacetexture(e, i_s);
394         if (!tex)
395                 return 0; // this is beyond the last one
396         n_t = getsurfacenumtriangles(e, i_s);
397         for(i_t = 0; i_t < n_t; ++i_t)
398         {
399                 tri = getsurfacetriangle(e, i_s, i_t);
400                 R_BeginPolygon(tex, 0);
401                 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
402                 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
403                 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
404                 R_EndPolygon();
405         }
406         return 1;
407 }
408 void PolyDrawModel(entity e)
409 {
410         float i_s;
411         for(i_s = 0; ; ++i_s)
412                 if(!PolyDrawModelSurface(e, i_s))
413                         break;
414 }
415
416 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
417 {
418         float x, y, q, d;
419         vector ringsize, v, t;
420         ringsize = radius * '1 1 0';
421
422         x = cos(f * 2 * M_PI);
423         y = sin(f * 2 * M_PI);
424         q = fabs(x) + fabs(y);
425         x /= q;
426         y /= q;
427
428         if(f >= 1)
429         {
430                 // draw full rectangle
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);
435
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);
439
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);
443
444                         v = centre;                     t = '0.5 0.5 0';
445                         v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
446                         R_PolygonVertex(v, t, rgb, a);
447                 R_EndPolygon();
448
449                 d = q - 1;
450                 if(d > 0)
451                 {
452                         R_BeginPolygon(pic, drawflag);
453                                 v = centre;                     t = '0.5 0.5 0';
454                                 R_PolygonVertex(v, t, rgb, a);
455
456                                 v = centre;                     t = '0.5 0.5 0';
457                                 v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
458                                 R_PolygonVertex(v, t, rgb, a);
459                 }
460         }
461         else if(f > 0.75)
462         {
463                 // draw upper and first triangle
464                 R_BeginPolygon(pic, drawflag);
465                         v = centre;                     t = '0.5 0.5 0';
466                         v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
467                         R_PolygonVertex(v, t, rgb, a);
468
469                         v = centre;                     t = '0.5 0.5 0';
470                         v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
471                         R_PolygonVertex(v, t, rgb, a);
472
473                         v = centre;                     t = '0.5 0.5 0';
474                         v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
475                         R_PolygonVertex(v, t, rgb, a);
476                 R_EndPolygon();
477                 R_BeginPolygon(pic, drawflag);
478                         v = centre;                     t = '0.5 0.5 0';
479                         R_PolygonVertex(v, t, rgb, a);
480
481                         v = centre;                     t = '0.5 0.5 0';
482                         v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
483                         R_PolygonVertex(v, t, rgb, a);
484
485                         v = centre;                     t = '0.5 0.5 0';
486                         v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
487                         R_PolygonVertex(v, t, rgb, a);
488
489                 d = q - 0.75;
490                 if(d <= 0)
491                         R_EndPolygon();
492         }
493         else if(f > 0.5)
494         {
495                 // draw upper triangle
496                 R_BeginPolygon(pic, drawflag);
497                         v = centre;                     t = '0.5 0.5 0';
498                         v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
499                         R_PolygonVertex(v, t, rgb, a);
500
501                         v = centre;                     t = '0.5 0.5 0';
502                         v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
503                         R_PolygonVertex(v, t, rgb, a);
504
505                         v = centre;                     t = '0.5 0.5 0';
506                         v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
507                         R_PolygonVertex(v, t, rgb, a);
508                 R_EndPolygon();
509
510                 d = q - 0.5;
511                 if(d > 0)
512                 {
513                         R_BeginPolygon(pic, drawflag);
514                                 v = centre;                     t = '0.5 0.5 0';
515                                 R_PolygonVertex(v, t, rgb, a);
516
517                                 v = centre;                     t = '0.5 0.5 0';
518                                 v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
519                                 R_PolygonVertex(v, t, rgb, a);
520                 }
521         }
522         else if(f > 0.25)
523         {
524                 // draw first triangle
525                 R_BeginPolygon(pic, drawflag);
526                         v = centre;                     t = '0.5 0.5 0';
527                         R_PolygonVertex(v, t, rgb, a);
528
529                         v = centre;                     t = '0.5 0.5 0';
530                         v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
531                         R_PolygonVertex(v, t, rgb, a);
532
533                         v = centre;                     t = '0.5 0.5 0';
534                         v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
535                         R_PolygonVertex(v, t, rgb, a);
536
537                 d = q - 0.25;
538                 if(d <= 0)
539                         R_EndPolygon();
540         }
541         else
542         {
543                 d = q;
544                 if(d > 0)
545                 {
546                         R_BeginPolygon(pic, drawflag);
547                                 v = centre;                     t = '0.5 0.5 0';
548                                 R_PolygonVertex(v, t, rgb, a);
549
550                                 v = centre;                     t = '0.5 0.5 0';
551                                 v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
552                                 R_PolygonVertex(v, t, rgb, a);
553                 }
554         }
555
556         if(d > 0)
557         {
558                         v = centre;                     t = '0.5 0.5 0';
559                         v.x += x * 0.5 * ringsize.x;    t += x * '0.5 0.5 0';
560                         v.y += y * 0.5 * ringsize.y;    t += y * '0.5 -0.5 0';
561                         R_PolygonVertex(v, t, rgb, a);
562                 R_EndPolygon();
563         }
564 }
565
566 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
567 vector getplayerorigin(int pl)
568 {
569         entity e;
570
571         e = CSQCModel_server2csqc(pl + 1);
572         if(e)
573                 return e.origin;
574
575         e = entcs_receiver[pl];
576         if(e)
577                 return e.origin;
578
579         return GETPLAYERORIGIN_ERROR;
580 }
581
582 float getplayeralpha(float pl)
583 {
584         entity e;
585
586         e = CSQCModel_server2csqc(pl + 1);
587         if(e)
588                 return e.alpha;
589
590         return 1;
591 }
592
593 vector getcsqcplayercolor(float pl)
594 {
595         entity e;
596
597         e = CSQCModel_server2csqc(pl);
598         if(e)
599         {
600                 if(e.colormap > 0)
601                         return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
602         }
603
604         return '1 1 1';
605 }
606
607 float getplayerisdead(float pl)
608 {
609         entity e;
610
611         e = CSQCModel_server2csqc(pl + 1);
612         if(e)
613                 return e.csqcmodel_isdead;
614
615         return false;
616 }
617
618 void URI_Get_Callback(float id, float status, string data)
619 {
620         if(url_URI_Get_Callback(id, status, data))
621         {
622                 // handled
623         }
624         else if (id == URI_GET_DISCARD)
625         {
626                 // discard
627         }
628         else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
629         {
630                 // sv_cmd curl
631                 Curl_URI_Get_Callback(id, status, data);
632         }
633         else
634         {
635                 printf("Received HTTP request data for an invalid id %d.\n", id);
636         }
637 }
638
639 void draw_beginBoldFont()
640 {
641         drawfont = FONT_USER+2;
642 }
643
644 void draw_endBoldFont()
645 {
646         drawfont = FONT_USER+1;
647 }
648
649
650 const float MAX_ACCURACY_LEVELS = 10;
651 float acc_lev[MAX_ACCURACY_LEVELS];
652 vector acc_col[MAX_ACCURACY_LEVELS];
653 float acc_col_loadtime;
654 int acc_levels;
655 string acc_color_levels;
656 void Accuracy_LoadLevels()
657 {
658         if(autocvar_accuracy_color_levels != acc_color_levels)
659         {
660                 if(acc_color_levels)
661                         strunzone(acc_color_levels);
662                 acc_color_levels = strzone(autocvar_accuracy_color_levels);
663                 acc_levels = tokenize_console(acc_color_levels);
664                 if(acc_levels > MAX_ACCURACY_LEVELS)
665                         acc_levels = MAX_ACCURACY_LEVELS;
666                 if(acc_levels < 2)
667                         print("Warning: accuracy_color_levels must contain at least 2 values\n");
668
669                 int i;
670                 for(i = 0; i < acc_levels; ++i)
671                         acc_lev[i] = stof(argv(i)) / 100.0;
672         }
673 }
674
675 void Accuracy_LoadColors()
676 {
677         if(time > acc_col_loadtime)
678         if(acc_levels >= 2)
679         {
680                 int i;
681                 for(i = 0; i < acc_levels; ++i)
682                         acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
683                 acc_col_loadtime = time + 2;
684         }
685 }
686
687 vector Accuracy_GetColor(float accuracy)
688 {
689         float factor;
690         vector color;
691         if(acc_levels < 2)
692                 return '0 0 0'; // return black, can't determine the right color
693
694         // find the max level lower than acc
695         int j = acc_levels-1;
696         while(j && accuracy < acc_lev[j])
697                 --j;
698
699         // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
700         factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
701         color = acc_col[j];
702         color = color + factor * (acc_col[j+1] - color);
703         return color;
704 }
705