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