]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qc
Merge branch 'master' of ssh://git.xonotic.org/xonotic-data.pk3dir into savagex/plat...
[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 float cvar_or(string cv, float v)
379 {
380         string s;
381         s = cvar_string(cv);
382         if(s == "")
383                 return v;
384         else
385                 return stof(s);
386 }
387
388 vector project_3d_to_2d(vector vec)
389 {
390         vec = cs_project(vec);
391         if(cs_project_is_b0rked > 0)
392         {
393                 vec_x *= vid_conwidth / vid_width;
394                 vec_y *= vid_conheight / vid_height;
395         }
396         return vec;
397 }
398
399 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
400 {
401 }
402
403 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
404 {
405         return 1.2 / (1.2 - fadelerp);
406 }
407
408 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
409 {
410         boxsize_x *= boxxsizefactor; // easier interface for text
411         return boxsize * (0.5 * (1 - sz));
412 }
413
414 void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)
415 {
416         vector line_dim;
417
418         // left and right lines
419         pos_x -= thickness;
420         line_dim_x = thickness;
421         line_dim_y = dim_y;
422         drawfill(pos, line_dim, color, alpha, drawflag);
423         drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);
424
425         // upper and lower lines
426         pos_y -= thickness;
427         line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
428         line_dim_y = thickness;
429         drawfill(pos, line_dim, color, alpha, drawflag);
430         drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);
431 }
432
433 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)
434 {
435         vector current_pos, end_pos, new_size, ratio;
436         end_pos = pos + area;
437
438         current_pos_y = pos_y;
439         while (current_pos_y < end_pos_y)
440         {
441                 current_pos_x = pos_x;
442                 while (current_pos_x < end_pos_x)
443                 {
444                         new_size_x = min(sz_x, end_pos_x - current_pos_x);
445                         new_size_y = min(sz_y, end_pos_y - current_pos_y);
446                         ratio_x = new_size_x / sz_x;
447                         ratio_y = new_size_y / sz_y;
448                         drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);
449                         current_pos_x += sz_x;
450                 }
451                 current_pos_y += sz_y;
452         }
453 }
454
455 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
456 var float _drawpic_imgaspect;
457 var float _drawpic_aspect;
458 var vector _drawpic_imgsize;
459 var vector _drawpic_sz;
460 var vector _drawpic_oldsz;
461 var string _drawpic_picpath;
462 #define drawpic_aspect(pos,pic,mySize,color,alpha,drawflag)\
463         do {\
464                 _drawpic_imgsize = drawgetimagesize(pic);\
465                 _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
466                 _drawpic_oldsz = _drawpic_sz = mySize;\
467                 _drawpic_aspect = _drawpic_sz_x/_drawpic_sz_y;\
468                 if(_drawpic_aspect > _drawpic_imgaspect) {\
469                         _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
470                         drawpic(pos + eX * (_drawpic_oldsz_x - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
471                 } else {\
472                         _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
473                         drawpic(pos + eY * (_drawpic_oldsz_y - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, alpha, drawflag);\
474                 }\
475         } while(0)
476
477 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
478 #define drawpic_aspect_skin(pos,pic,sz,color,alpha,drawflag)\
479         do{\
480                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
481                 if(precache_pic(_drawpic_picpath) == "") {\
482                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
483                 }\
484                 drawpic_aspect(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
485                 _drawpic_picpath = string_null;\
486         } while(0)
487
488 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
489 #define drawpic_skin(pos,pic,sz,color,alpha,drawflag)\
490         do{\
491                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
492                 if(precache_pic(_drawpic_picpath) == "") {\
493                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
494                 }\
495                 drawpic(pos, _drawpic_picpath, sz, color, alpha, drawflag);\
496                 _drawpic_picpath = string_null;\
497         } while(0)
498
499 void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
500 {
501         float sz;
502         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
503
504         drawpic_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
505 }
506
507 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
508 {
509         drawpic_aspect_skin_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
510         drawpic_skin(position, pic, scale, rgb, alpha * fadelerp, flag);
511 }
512
513 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
514 void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {
515         vector textsize;
516         textsize = eX * stringwidth(text, FALSE, '1 1 1' * sz_y) + eY * sz_y;
517
518         float textaspect;
519         textaspect = textsize_x/textsize_y;
520
521         vector oldsz;
522         oldsz = sz;
523         float aspect;
524         aspect = sz_x/sz_y;
525
526         if(aspect > textaspect) {
527                 sz_x = sz_y * textaspect;
528                 drawstring(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
529         } else {
530                 sz_y = sz_x / textaspect; 
531                 drawstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
532         }
533 }
534
535 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
536 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float alpha, float drawflag) {
537         vector textsize;
538         textsize = eX * stringwidth(text, TRUE, '1 1 1' * sz_y) + eY * sz_y;
539
540         float textaspect;
541         textaspect = textsize_x/textsize_y;
542
543         vector oldsz;
544         oldsz = sz;
545         float aspect;
546         aspect = sz_x/sz_y;
547
548         if(aspect > textaspect) {
549                 sz_x = sz_y * textaspect;
550                 drawcolorcodedstring(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
551         } else {
552                 sz_y = sz_x / textaspect; 
553                 drawcolorcodedstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
554         }
555 }
556
557 vector drawfontscale;
558 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
559 {
560         float sz;
561         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
562
563         drawfontscale = sz * '1 1 0';
564         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
565         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);
566         // width parameter:
567         //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
568         //    SIZE1
569         drawfontscale = '1 1 0';
570 }
571
572 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
573 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float alpha, float drawflag, float fadelerp) {
574         vector textsize;
575         textsize = eX * stringwidth(text, FALSE, '1 1 1' * sz_y) + eY * sz_y;
576
577         float textaspect;
578         textaspect = textsize_x/textsize_y;
579
580         vector oldsz;
581         oldsz = sz;
582         float aspect;
583         aspect = sz_x/sz_y;
584
585         if(aspect > textaspect) {
586                 sz_x = sz_y * textaspect;
587                 drawstring_expanding(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
588         } else {
589                 sz_y = sz_x / textaspect; 
590                 drawstring_expanding(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
591         }
592 }
593
594 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
595 {
596         float sz;
597         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
598
599         drawfontscale = sz * '1 1 0';
600         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
601         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);
602         drawfontscale = '1 1 0';
603 }
604
605 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float alpha, float drawflag, float fadelerp) {
606         vector textsize;
607         textsize = eX * stringwidth(text, TRUE, '1 1 1' * sz_y) + eY * sz_y;
608         
609         float textaspect;
610         textaspect = textsize_x/textsize_y;
611
612         vector oldsz;
613         oldsz = sz;
614         float aspect;
615         aspect = sz_x/sz_y;
616
617         if(aspect > textaspect) {
618                 sz_x = sz_y * textaspect;
619                 drawcolorcodedstring_expanding(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
620         } else {
621                 sz_y = sz_x / textaspect; 
622                 drawcolorcodedstring_expanding(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
623         }
624 }
625
626 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
627 float PolyDrawModelSurface(entity e, float i_s)
628 {
629         float i_t;
630         float n_t;
631         vector tri;
632         string tex;
633         tex = getsurfacetexture(e, i_s);
634         if not(tex)
635                 return 0; // this is beyond the last one
636         n_t = getsurfacenumtriangles(e, i_s);
637         for(i_t = 0; i_t < n_t; ++i_t)
638         {
639                 tri = getsurfacetriangle(e, i_s, i_t);
640                 R_BeginPolygon(tex, 0);
641                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
642                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
643                 R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
644                 R_EndPolygon();
645         }
646         return 1;
647 }
648 void PolyDrawModel(entity e)
649 {
650         float i_s;
651         for(i_s = 0; ; ++i_s)
652                 if(!PolyDrawModelSurface(e, i_s))
653                         break;
654 }
655
656 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag)
657 {
658         float x, y, q, d;
659         vector ringsize, v, t;
660         ringsize = radius * '1 1 0';
661
662         x = cos(f * 2 * M_PI);
663         y = sin(f * 2 * M_PI);
664         q = fabs(x) + fabs(y);
665         x /= q;
666         y /= q;
667
668         if(f >= 1)
669         {
670                 // draw full rectangle
671                 R_BeginPolygon(pic, drawflag);
672                         v = centre;                     t = '0.5 0.5 0';
673                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
674                         R_PolygonVertex(v, t, rgb, a);
675
676                         v = centre;                     t = '0.5 0.5 0';
677                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
678                         R_PolygonVertex(v, t, rgb, a);
679
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                 R_EndPolygon();
688
689                 d = q - 1;
690                 if(d > 0)
691                 {
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         }
701         else if(f > 0.75)
702         {
703                 // draw upper and first triangle
704                 R_BeginPolygon(pic, drawflag);
705                         v = centre;                     t = '0.5 0.5 0';
706                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
707                         R_PolygonVertex(v, t, rgb, a);
708
709                         v = centre;                     t = '0.5 0.5 0';
710                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
711                         R_PolygonVertex(v, t, rgb, a);
712
713                         v = centre;                     t = '0.5 0.5 0';
714                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
715                         R_PolygonVertex(v, t, rgb, a);
716                 R_EndPolygon();
717                 R_BeginPolygon(pic, drawflag);
718                         v = centre;                     t = '0.5 0.5 0';
719                         R_PolygonVertex(v, t, rgb, a);
720
721                         v = centre;                     t = '0.5 0.5 0';
722                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
723                         R_PolygonVertex(v, t, rgb, a);
724
725                         v = centre;                     t = '0.5 0.5 0';
726                         v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';
727                         R_PolygonVertex(v, t, rgb, a);
728
729                 d = q - 0.75;
730                 if(d <= 0)
731                         R_EndPolygon();
732         }
733         else if(f > 0.5)
734         {
735                 // draw upper triangle
736                 R_BeginPolygon(pic, drawflag);
737                         v = centre;                     t = '0.5 0.5 0';
738                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
739                         R_PolygonVertex(v, t, rgb, a);
740
741                         v = centre;                     t = '0.5 0.5 0';
742                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
743                         R_PolygonVertex(v, t, rgb, a);
744
745                         v = centre;                     t = '0.5 0.5 0';
746                         v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
747                         R_PolygonVertex(v, t, rgb, a);
748                 R_EndPolygon();
749
750                 d = q - 0.5;
751                 if(d > 0)
752                 {
753                         R_BeginPolygon(pic, drawflag);
754                                 v = centre;                     t = '0.5 0.5 0';
755                                 R_PolygonVertex(v, t, rgb, a);
756
757                                 v = centre;                     t = '0.5 0.5 0';
758                                 v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
759                                 R_PolygonVertex(v, t, rgb, a);
760                 }
761         }
762         else if(f > 0.25)
763         {
764                 // draw first triangle
765                 R_BeginPolygon(pic, drawflag);
766                         v = centre;                     t = '0.5 0.5 0';
767                         R_PolygonVertex(v, t, rgb, a);
768
769                         v = centre;                     t = '0.5 0.5 0';
770                         v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
771                         R_PolygonVertex(v, t, rgb, a);
772
773                         v = centre;                     t = '0.5 0.5 0';
774                         v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
775                         R_PolygonVertex(v, t, rgb, a);
776
777                 d = q - 0.25;
778                 if(d <= 0)
779                         R_EndPolygon();
780         }
781         else
782         {
783                 d = q;
784                 if(d > 0)
785                 {
786                         R_BeginPolygon(pic, drawflag);
787                                 v = centre;                     t = '0.5 0.5 0';
788                                 R_PolygonVertex(v, t, rgb, a);
789
790                                 v = centre;                     t = '0.5 0.5 0';
791                                 v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
792                                 R_PolygonVertex(v, t, rgb, a);
793                 }
794         }
795
796         if(d > 0)
797         {
798                         v = centre;                     t = '0.5 0.5 0';
799                         v_x += x * 0.5 * ringsize_x;    t += x * '0.5 0.5 0';
800                         v_y += y * 0.5 * ringsize_y;    t += y * '0.5 -0.5 0';
801                         R_PolygonVertex(v, t, rgb, a);
802                 R_EndPolygon();
803         }
804 }