]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qc
Merge remote-tracking branch 'origin/terencehill/big_close_button_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
1 var float(string text, float handleColors, vector fontSize) stringwidth;
2
3 entity players;
4 entity teams;
5
6 void serverAnnouncer()
7 {
8         // check for pending announcement, play it and remove it
9         if(announce_snd != "")
10         {
11                 sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/", announce_snd, ".wav"), VOL_BASEVOICE, ATTN_NONE);
12                 strunzone(announce_snd);
13                 announce_snd = "";
14         }
15 }
16
17 void restartAnnouncer_Think() {
18         float countdown_rounded, countdown;
19         countdown = getstatf(STAT_GAMESTARTTIME) - time;
20         countdown_rounded = floor(0.5 + countdown);
21         if(countdown <= 0) {
22                 if (!spectatee_status) //do cprint only for players
23                         centerprint(_("^1Begin!"));
24
25                 sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/begin.wav"), VOL_BASEVOICE, ATTN_NONE);
26                 //reset maptime announcers now as well
27                 announcer_5min = announcer_1min = FALSE;
28
29                 remove(self);
30                 return;
31         }
32         else {
33                 if (!spectatee_status) //do cprint only for players
34                         centerprint(sprintf(_("^1Game starts in %d seconds"), countdown_rounded));
35
36                 if(countdown_rounded <= 3 && countdown_rounded >= 1) {
37                         sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/", ftos(countdown_rounded), ".wav"), VOL_BASEVOICE, ATTN_NONE);
38                 }
39
40                 self.nextthink = getstatf(STAT_GAMESTARTTIME) - (countdown - 1);
41         }
42 }
43
44 /**
45  * Plays the 1minute or 5 minutes (of maptime) remaining sound, if client wants it
46  */
47 void maptimeAnnouncer() {
48         float timelimit;
49         timelimit = getstatf(STAT_TIMELIMIT);
50         float timeleft;
51         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
52
53         float warmuplimit;
54         float warmuptimeleft;
55         if(warmup_stage) {
56                 warmuplimit = autocvar_g_warmup_limit;
57                 if(warmuplimit > 0) {
58                         warmuptimeleft = max(0, warmuplimit + getstatf(STAT_GAMESTARTTIME) - time); 
59                 }
60         }
61
62         //5 minute check
63         if (autocvar_cl_sound_maptime_warning >= 2) {
64                 //make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
65                 if(announcer_5min)
66                 {
67                         if(((!warmup_stage || warmuplimit == 0) && timeleft > 300) || (warmup_stage && warmuplimit > 0 && warmuptimeleft > 300))
68                                 announcer_5min = FALSE;
69                 }
70                 else if (((!warmup_stage || warmuplimit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299) || (warmup_stage && warmuplimit > 0 && warmuptimeleft < 300 && warmuptimeleft > 299))
71                         //if we're in warmup mode, check whether there's a warmup timelimit
72                         if not (warmuplimit == -1 && warmup_stage) {
73                                 announcer_5min = TRUE;
74                                 sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/5minutesremain.wav"), VOL_BASEVOICE, ATTN_NONE);
75                         }
76         }
77
78         //1 minute check
79         if (autocvar_cl_sound_maptime_warning == 1 || autocvar_cl_sound_maptime_warning == 3) {
80                 if (announcer_1min)
81                 {
82                         if(((!warmup_stage || warmuplimit == 0) && timeleft > 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft > 60))
83                                 announcer_1min = FALSE;
84                 }
85                 else if (((!warmup_stage || warmuplimit == 0) && timelimit > 0 && timeleft < 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft < 60))
86                         //if we're in warmup mode, check whether there's a warmup timelimit
87                         if not (warmuplimit == -1 && warmup_stage) {
88                                 announcer_1min = TRUE;
89                                 sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/1minuteremains.wav"), VOL_BASEVOICE, ATTN_NONE);
90                         }
91         }
92 }
93
94 /**
95  * Announce carried items (e.g. flags in CTF).
96  */
97 float redflag_prev;
98 float blueflag_prev;
99 void carrierAnnouncer() {
100         float stat_items, redflag, blueflag;
101         float pickup;
102         string item;
103
104         if not(autocvar_cl_notify_carried_items)
105                 return;
106
107         stat_items = getstati(STAT_ITEMS);
108
109         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
110         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
111
112         if (redflag == 3 && redflag != redflag_prev) {
113                 item = _("^1RED^7 flag");
114                 pickup = (redflag_prev == 2);
115         }
116
117         if (blueflag == 3 && blueflag != blueflag_prev) {
118                 item = _("^4BLUE^7 flag");
119                 pickup = (blueflag_prev == 2);
120         }
121
122         if (item)
123         {
124                 if (pickup) {
125                         if (autocvar_cl_notify_carried_items & 2)
126                                 centerprint(sprintf(_("You picked up the %s!"), item));
127                 }
128                 else {
129                         if (autocvar_cl_notify_carried_items & 1)
130                                 centerprint(sprintf(_("You got the %s!"), item));
131                 }
132         }
133
134         blueflag_prev = blueflag;
135         redflag_prev = redflag;
136 }
137
138 /**
139  * Add all future announcer sounds precaches here.
140  * TODO: announcer queues
141  */
142 void Announcer_Precache () {
143         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1minuteremains.wav"));
144         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/5minutesremain.wav"));
145
146         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/electrobitch.wav"));
147         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/airshot.wav"));
148         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/03kills.wav"));
149         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/05kills.wav"));
150         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/10kills.wav"));
151         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/15kills.wav"));
152         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/20kills.wav"));
153         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/25kills.wav"));
154         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/30kills.wav"));
155         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/botlike.wav"));
156         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/yoda.wav"));
157         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/amazing.wav"));
158         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/awesome.wav"));
159         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/headshot.wav"));
160         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/impressive.wav"));
161
162         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/prepareforbattle.wav"));
163         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/begin.wav"));
164         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/timeoutcalled.wav"));
165         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1fragleft.wav"));
166         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/2fragsleft.wav"));
167         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/3fragsleft.wav"));
168         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/terminated.wav"));
169
170         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1.wav"));
171         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/2.wav"));
172         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/3.wav"));
173         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/4.wav"));
174         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/5.wav"));
175         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/6.wav"));
176         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/7.wav"));
177         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/8.wav"));
178         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/9.wav"));
179         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/10.wav"));
180
181         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/lastsecond.wav"));
182         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/narrowly.wav"));
183
184         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/voteaccept.wav"));
185         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/votecall.wav"));
186         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/votefail.wav"));
187 }
188
189 void AuditLists()
190 {
191         entity e;
192         entity prev;
193
194         prev = players;
195         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
196         {
197                 if(prev != e.sort_prev)
198                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
199         }
200
201         prev = teams;
202         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
203         {
204                 if(prev != e.sort_prev)
205                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
206         }
207 }
208
209
210 float RegisterPlayer(entity player)
211 {
212         entity pl;
213         AuditLists();
214         for(pl = players.sort_next; pl; pl = pl.sort_next)
215                 if(pl == player)
216                         error("Player already registered!");
217         player.sort_next = players.sort_next;
218         player.sort_prev = players;
219         if(players.sort_next)
220                 players.sort_next.sort_prev = player;
221         players.sort_next = player;
222         AuditLists();
223         return true;
224 }
225
226 void RemovePlayer(entity player)
227 {
228         entity pl, parent;
229         AuditLists();
230         parent = players;
231         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
232                 parent = pl;
233
234         if(!pl)
235         {
236                 error("Trying to remove a player which is not in the playerlist!");
237                 return;
238         }
239         parent.sort_next = player.sort_next;
240         if(player.sort_next)
241                 player.sort_next.sort_prev = parent;
242         AuditLists();
243 }
244
245 void MoveToLast(entity e)
246 {
247         AuditLists();
248         other = e.sort_next;
249         while(other)
250         {
251                 SORT_SWAP(other, e);
252                 other = e.sort_next;
253         }
254         AuditLists();
255 }
256
257 float RegisterTeam(entity Team)
258 {
259         entity tm;
260         AuditLists();
261         for(tm = teams.sort_next; tm; tm = tm.sort_next)
262                 if(tm == Team)
263                         error("Team already registered!");
264         Team.sort_next = teams.sort_next;
265         Team.sort_prev = teams;
266         if(teams.sort_next)
267                 teams.sort_next.sort_prev = Team;
268         teams.sort_next = Team;
269         AuditLists();
270         return true;
271 }
272
273 void RemoveTeam(entity Team)
274 {
275         entity tm, parent;
276         AuditLists();
277         parent = teams;
278         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
279                 parent = tm;
280
281         if(!tm)
282         {
283                 print(_("Trying to remove a team which is not in the teamlist!"));
284                 return;
285         }
286         parent.sort_next = Team.sort_next;
287         if(Team.sort_next)
288                 Team.sort_next.sort_prev = parent;
289         AuditLists();
290 }
291
292 entity GetTeam(float Team, float add)
293 {
294         float num;
295         entity tm;
296         num = (Team == COLOR_SPECTATOR) ? 16 : Team;
297         if(teamslots[num])
298                 return teamslots[num];
299         if not(add)
300                 return NULL;
301         tm = spawn();
302         tm.team = Team;
303         teamslots[num] = tm;
304         RegisterTeam(tm);
305         return tm;
306 }
307
308 vector HUD_GetFontsize(string cvarname)
309 {
310         vector v;
311         v = stov(cvar_string(cvarname));
312         if(v_x == 0)
313                 v = '8 8 0';
314         if(v_y == 0)
315                 v_y = v_x;
316         v_z = 0;
317         return v;
318 }
319
320 float PreviewExists(string name)
321 {
322         float f;
323         string file;
324
325         if(autocvar_cl_readpicture_force)
326                 return false;
327
328         file = strcat(name, ".tga");
329         f = fopen(file, FILE_READ);
330         if(f >= 0)
331         {
332                 fclose(f);
333                 return true;
334         }
335         file = strcat(name, ".png");
336         f = fopen(file, FILE_READ);
337         if(f >= 0)
338         {
339                 fclose(f);
340                 return true;
341         }
342         file = strcat(name, ".jpg");
343         f = fopen(file, FILE_READ);
344         if(f >= 0)
345         {
346                 fclose(f);
347                 return true;
348         }
349         file = strcat(name, ".pcx");
350         f = fopen(file, FILE_READ);
351         if(f >= 0)
352         {
353                 fclose(f);
354                 return true;
355         }
356         return false;
357 }
358
359 vector rotate(vector v, float a)
360 {
361         vector w;
362         // FTEQCC SUCKS AGAIN
363         w_x =      v_x * cos(a) + v_y * sin(a);
364         w_y = -1 * v_x * sin(a) + v_y * cos(a);
365         return w;
366 }
367
368 float ColorTranslateMode;
369
370 string ColorTranslateRGB(string s)
371 {
372         if(ColorTranslateMode & 1)
373                 return strdecolorize(s);
374         else
375                 return s;
376 }
377
378 string Team_ColorCode(float teamid)
379 {
380     if (teamid == COLOR_TEAM1)
381         return "^1";
382     else if (teamid == COLOR_TEAM2)
383         return "^4";
384     else if (teamid == COLOR_TEAM3)
385         return "^3";
386     else if (teamid == COLOR_TEAM4)
387         return "^6";
388     else
389         return "^7";
390 }
391
392 // decolorizes and team colors the player name when needed
393 string playername(string thename, float teamid)
394 {
395     string t;
396     if (teamplay)
397     {
398         t = Team_ColorCode(teamid);
399         return strcat(t, strdecolorize(thename));
400     }
401     else
402         return strdecolorize(thename);
403 }
404
405 float cvar_or(string cv, float v)
406 {
407         string s;
408         s = cvar_string(cv);
409         if(s == "")
410                 return v;
411         else
412                 return stof(s);
413 }
414
415 vector project_3d_to_2d(vector vec)
416 {
417         vec = cs_project(vec);
418         if(cs_project_is_b0rked > 0)
419         {
420                 vec_x *= vid_conwidth / vid_width;
421                 vec_y *= vid_conheight / vid_height;
422         }
423         return vec;
424 }
425
426 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
427 {
428 }
429
430 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
431 {
432         return 1.2 / (1.2 - fadelerp);
433 }
434
435 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
436 {
437         boxsize_x *= boxxsizefactor; // easier interface for text
438         return boxsize * (0.5 * (1 - sz));
439 }
440
441 void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)
442 {
443         vector line_dim;
444
445         // left and right lines
446         pos_x -= thickness;
447         line_dim_x = thickness;
448         line_dim_y = dim_y;
449         drawfill(pos, line_dim, color, alpha, drawflag);
450         drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);
451
452         // upper and lower lines
453         pos_y -= thickness;
454         line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
455         line_dim_y = thickness;
456         drawfill(pos, line_dim, color, alpha, drawflag);
457         drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);
458 }
459
460 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)
461 {
462         vector current_pos, end_pos, new_size, ratio;
463         end_pos = pos + area;
464
465         current_pos_y = pos_y;
466         while (current_pos_y < end_pos_y)
467         {
468                 current_pos_x = pos_x;
469                 while (current_pos_x < end_pos_x)
470                 {
471                         new_size_x = min(sz_x, end_pos_x - current_pos_x);
472                         new_size_y = min(sz_y, end_pos_y - current_pos_y);
473                         ratio_x = new_size_x / sz_x;
474                         ratio_y = new_size_y / sz_y;
475                         drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);
476                         current_pos_x += sz_x;
477                 }
478                 current_pos_y += sz_y;
479         }
480 }
481
482 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
483 var float _drawpic_imgaspect;
484 var vector _drawpic_imgsize;
485 var vector _drawpic_sz;
486 var float _drawpic_oldsz;
487 var string _drawpic_picpath;
488 #define drawpic_aspect(pos,pic,mySize,color,alpha,drawflag)\
489         do {\
490                 _drawpic_imgsize = drawgetimagesize(pic);\
491                 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
492                 _drawpic_sz = mySize;\
493                 if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
494                         _drawpic_oldsz = _drawpic_sz_x;\
495                         _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
496                         drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
497                 } else {\
498                         _drawpic_oldsz = _drawpic_sz_y;\
499                         _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
500                         drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
501                 }\
502         } while(0)
503
504 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
505 #define drawpic_aspect_skin(pos,pic,sz,color,alpha,drawflag)\
506         do{\
507                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
508                 if(precache_pic(_drawpic_picpath) == "") {\
509                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
510                 }\
511                 drawpic_aspect(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
512                 _drawpic_picpath = string_null;\
513         } while(0)
514
515 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
516 #define drawpic_skin(pos,pic,sz,color,alpha,drawflag)\
517         do{\
518                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
519                 if(precache_pic(_drawpic_picpath) == "") {\
520                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
521                 }\
522                 drawpic(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
523                 _drawpic_picpath = string_null;\
524         } while(0)
525
526 void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
527 {
528         float sz;
529         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
530
531         drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
532 }
533
534 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
535 {
536         drawpic_aspect_skin_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
537         drawpic_skin(position, pic, scale, rgb, alpha * fadelerp, flag);
538 }
539 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
540         float textaspect, oldsz;\
541         textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
542         if(sz_x/sz_y > textaspect) {\
543                 oldsz = sz_x;\
544                 sz_x = sz_y * textaspect;\
545                 pos_x += (oldsz - sz_x) * 0.5;\
546         } else {\
547                 oldsz = sz_y;\
548                 sz_y = sz_x / textaspect; \
549                 pos_y += (oldsz - sz_y) * 0.5;\
550         }
551
552 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
553 void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {
554         SET_POS_AND_SZ_Y_ASPECT(FALSE)
555         drawstring(pos, text, '1 1 0' * sz_y, color, alpha, drawflag);
556 }
557
558 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
559 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float alpha, float drawflag) {
560         SET_POS_AND_SZ_Y_ASPECT(TRUE)
561         drawcolorcodedstring(pos, text, '1 1 0' * sz_y, alpha, drawflag);
562 }
563
564 vector drawfontscale;
565 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
566 {
567         float sz;
568         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
569
570         drawfontscale = sz * '1 1 0';
571         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
572         drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, alpha * (1 - fadelerp), flag);
573         // width parameter:
574         //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
575         //    SIZE1
576         drawfontscale = '1 1 0';
577 }
578
579 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
580 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float alpha, float drawflag, float fadelerp) {
581         SET_POS_AND_SZ_Y_ASPECT(FALSE)
582         drawstring_expanding(pos, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
583 }
584
585 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
586 {
587         float sz;
588         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
589
590         drawfontscale = sz * '1 1 0';
591         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
592         drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), alpha * (1 - fadelerp), flag);
593         drawfontscale = '1 1 0';
594 }
595
596 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float alpha, float drawflag, float fadelerp) {
597         SET_POS_AND_SZ_Y_ASPECT(TRUE)
598         drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
599 }
600
601 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
602 float PolyDrawModelSurface(entity e, float i_s)
603 {
604         float i_t;
605         float n_t;
606         vector tri;
607         string tex;
608         tex = getsurfacetexture(e, i_s);
609         if not(tex)
610                 return 0; // this is beyond the last one
611         n_t = getsurfacenumtriangles(e, i_s);
612         for(i_t = 0; i_t < n_t; ++i_t)
613         {
614                 tri = getsurfacetriangle(e, i_s, i_t);
615                 R_BeginPolygon(tex, 0);
616                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
617                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
618                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
619                 R_EndPolygon();
620         }
621         return 1;
622 }
623 void PolyDrawModel(entity e)
624 {
625         float i_s;
626         for(i_s = 0; ; ++i_s)
627                 if(!PolyDrawModelSurface(e, i_s))
628                         break;
629 }
630
631 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
632 {
633         float x, y, q, d;
634         vector ringsize, v, t;
635         ringsize = radius * '1 1 0';
636
637         x = cos(f * 2 * M_PI);
638         y = sin(f * 2 * M_PI);
639         q = fabs(x) + fabs(y);
640         x /= q;
641         y /= q;
642
643         if(f >= 1)
644         {
645                 // draw full rectangle
646                 R_BeginPolygon(pic, drawflag);
647                         v = centre;                     t = '0.5 0.5 0';
648                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
649                         R_PolygonVertex(v, t, rgb, a);
650
651                         v = centre;                     t = '0.5 0.5 0';
652                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
653                         R_PolygonVertex(v, t, rgb, a);
654
655                         v = centre;                     t = '0.5 0.5 0';
656                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
657                         R_PolygonVertex(v, t, rgb, a);
658
659                         v = centre;                     t = '0.5 0.5 0';
660                         v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';
661                         R_PolygonVertex(v, t, rgb, a);
662                 R_EndPolygon();
663
664                 d = q - 1;
665                 if(d > 0)
666                 {
667                         R_BeginPolygon(pic, drawflag);
668                                 v = centre;                     t = '0.5 0.5 0';
669                                 R_PolygonVertex(v, t, rgb, a);
670
671                                 v = centre;                     t = '0.5 0.5 0';
672                                 v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
673                                 R_PolygonVertex(v, t, rgb, a);
674                 }
675         }
676         else if(f > 0.75)
677         {
678                 // draw upper and first triangle
679                 R_BeginPolygon(pic, drawflag);
680                         v = centre;                     t = '0.5 0.5 0';
681                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
682                         R_PolygonVertex(v, t, rgb, a);
683
684                         v = centre;                     t = '0.5 0.5 0';
685                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
686                         R_PolygonVertex(v, t, rgb, a);
687
688                         v = centre;                     t = '0.5 0.5 0';
689                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
690                         R_PolygonVertex(v, t, rgb, a);
691                 R_EndPolygon();
692                 R_BeginPolygon(pic, drawflag);
693                         v = centre;                     t = '0.5 0.5 0';
694                         R_PolygonVertex(v, t, rgb, a);
695
696                         v = centre;                     t = '0.5 0.5 0';
697                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
698                         R_PolygonVertex(v, t, rgb, a);
699
700                         v = centre;                     t = '0.5 0.5 0';
701                         v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';
702                         R_PolygonVertex(v, t, rgb, a);
703
704                 d = q - 0.75;
705                 if(d <= 0)
706                         R_EndPolygon();
707         }
708         else if(f > 0.5)
709         {
710                 // draw upper triangle
711                 R_BeginPolygon(pic, drawflag);
712                         v = centre;                     t = '0.5 0.5 0';
713                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
714                         R_PolygonVertex(v, t, rgb, a);
715
716                         v = centre;                     t = '0.5 0.5 0';
717                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
718                         R_PolygonVertex(v, t, rgb, a);
719
720                         v = centre;                     t = '0.5 0.5 0';
721                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
722                         R_PolygonVertex(v, t, rgb, a);
723                 R_EndPolygon();
724
725                 d = q - 0.5;
726                 if(d > 0)
727                 {
728                         R_BeginPolygon(pic, drawflag);
729                                 v = centre;                     t = '0.5 0.5 0';
730                                 R_PolygonVertex(v, t, rgb, a);
731
732                                 v = centre;                     t = '0.5 0.5 0';
733                                 v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
734                                 R_PolygonVertex(v, t, rgb, a);
735                 }
736         }
737         else if(f > 0.25)
738         {
739                 // draw first triangle
740                 R_BeginPolygon(pic, drawflag);
741                         v = centre;                     t = '0.5 0.5 0';
742                         R_PolygonVertex(v, t, rgb, a);
743
744                         v = centre;                     t = '0.5 0.5 0';
745                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
746                         R_PolygonVertex(v, t, rgb, a);
747
748                         v = centre;                     t = '0.5 0.5 0';
749                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
750                         R_PolygonVertex(v, t, rgb, a);
751
752                 d = q - 0.25;
753                 if(d <= 0)
754                         R_EndPolygon();
755         }
756         else
757         {
758                 d = q;
759                 if(d > 0)
760                 {
761                         R_BeginPolygon(pic, drawflag);
762                                 v = centre;                     t = '0.5 0.5 0';
763                                 R_PolygonVertex(v, t, rgb, a);
764
765                                 v = centre;                     t = '0.5 0.5 0';
766                                 v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
767                                 R_PolygonVertex(v, t, rgb, a);
768                 }
769         }
770
771         if(d > 0)
772         {
773                         v = centre;                     t = '0.5 0.5 0';
774                         v_x += x * 0.5 * ringsize_x;    t += x * '0.5 0.5 0';
775                         v_y += y * 0.5 * ringsize_y;    t += y * '0.5 -0.5 0';
776                         R_PolygonVertex(v, t, rgb, a);
777                 R_EndPolygon();
778         }
779 }