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