]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qc
fix a load of things concerning the scoreboard, leftalign scoreboard, make centerprin...
[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(self, CHAN_VOICE, strcat("announcer/", cvar_string("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(self, CHAN_VOICE, strcat("announcer/", cvar_string("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(strcat("^1Game starts in ", ftos(countdown_rounded), " seconds"));
35
36                 if(countdown_rounded <= 3 && countdown_rounded >= 1) {
37                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("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 = cvar("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 (cvar("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                         //dprint("i will play the sound, I promise!\n");
75                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/5minutesremain.wav"), VOL_BASEVOICE, ATTN_NONE);
76                 }
77     }
78
79     //1 minute check
80     if (cvar("cl_sound_maptime_warning") == 1 || cvar("cl_sound_maptime_warning") == 3) {
81         if (announcer_1min)
82         {
83                         if(((!warmup_stage || warmuplimit == 0) && timeleft > 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft > 60))
84                                 announcer_1min = FALSE;
85         }
86         else if (((!warmup_stage || warmuplimit == 0) && timelimit > 0 && timeleft < 60) || (warmup_stage && warmuplimit > 0 && warmuptimeleft < 60))
87         //if we're in warmup mode, check whether there's a warmup timelimit
88         if not (warmuplimit == -1 && warmup_stage) {
89                         announcer_1min = TRUE;
90                         sound(self, CHAN_VOICE, strcat("announcer/", cvar_string("cl_announcer"), "/1minuteremains.wav"), VOL_BASEVOICE, ATTN_NONE);
91         }
92         }
93 }
94
95  /**
96  * Announce carried items (e.g. flags in CTF).
97  */
98 float redflag_prev;
99 float blueflag_prev;
100 void carrierAnnouncer() {
101         float stat_items, redflag, blueflag;
102         float pickup;
103         string item;
104
105         if not(cvar("cl_notify_carried_items"))
106                 return;
107
108         stat_items = getstati(STAT_ITEMS);
109
110         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
111         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
112
113         if (redflag == 3 && redflag != redflag_prev) {
114                 item = "^1RED^7 flag";
115                 pickup = (redflag_prev == 2);
116         }
117
118         if (blueflag == 3 && blueflag != blueflag_prev) {
119                 item = "^4BLUE^7 flag";
120                 pickup = (blueflag_prev == 2);
121         }
122
123         if (item)
124         {
125                 if (pickup) {
126                         if (cvar("cl_notify_carried_items") & 2)
127                                 centerprint(strcat("You picked up the ", item, "!"));
128                 }
129                 else {
130                         if (cvar("cl_notify_carried_items") & 1)
131                                 centerprint(strcat("You got the ", item, "!"));
132                 }
133         }
134
135         blueflag_prev = blueflag;
136         redflag_prev = redflag;
137 }
138
139 /**
140  * Add all future announcer sounds precaches here.
141  * TODO: announcer queues
142  */
143 void Announcer_Precache () {
144         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1minuteremains.wav"));
145         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/5minutesremain.wav"));
146
147         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/electrobitch.wav"));
148         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/airshot.wav"));
149         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/03kills.wav"));
150         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/05kills.wav"));
151         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/10kills.wav"));
152         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/15kills.wav"));
153         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/20kills.wav"));
154         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/25kills.wav"));
155         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/30kills.wav"));
156         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/botlike.wav"));
157         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/yoda.wav"));
158         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/amazing.wav"));
159         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/awesome.wav"));
160         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/headshot.wav"));
161         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/impressive.wav"));
162
163         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/prepareforbattle.wav"));
164         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/begin.wav"));
165         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/timeoutcalled.wav"));
166         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1fragleft.wav"));
167         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/2fragsleft.wav"));
168         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/3fragsleft.wav"));
169         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/terminated.wav"));
170
171         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/1.wav"));
172         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/2.wav"));
173         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/3.wav"));
174         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/4.wav"));
175         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/5.wav"));
176         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/6.wav"));
177         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/7.wav"));
178         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/8.wav"));
179         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/9.wav"));
180         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/10.wav"));
181
182         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/lastsecond.wav"));
183         precache_sound (strcat("announcer/", cvar_string("cl_announcer"), "/narrowly.wav"));
184 }
185
186 void AuditLists()
187 {
188         entity e;
189         entity prev;
190
191         prev = players;
192         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
193         {
194                 if(prev != e.sort_prev)
195                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
196         }
197
198         prev = teams;
199         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
200         {
201                 if(prev != e.sort_prev)
202                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
203         }
204 }
205
206
207 float RegisterPlayer(entity player)
208 {
209         entity pl;
210         AuditLists();
211         for(pl = players.sort_next; pl; pl = pl.sort_next)
212                 if(pl == player)
213                         error("Player already registered!");
214         player.sort_next = players.sort_next;
215         player.sort_prev = players;
216         if(players.sort_next)
217                 players.sort_next.sort_prev = player;
218         players.sort_next = player;
219         AuditLists();
220         return true;
221 }
222
223 void RemovePlayer(entity player)
224 {
225         entity pl, parent;
226         AuditLists();
227         parent = players;
228         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
229                 parent = pl;
230
231         if(!pl)
232         {
233                 error("Trying to remove a player which is not in the playerlist!");
234                 return;
235         }
236         parent.sort_next = player.sort_next;
237         if(player.sort_next)
238                 player.sort_next.sort_prev = parent;
239         AuditLists();
240 }
241
242 void MoveToLast(entity e)
243 {
244         AuditLists();
245         other = e.sort_next;
246         while(other)
247         {
248                 SORT_SWAP(other, e);
249                 other = e.sort_next;
250         }
251         AuditLists();
252 }
253
254 float RegisterTeam(entity Team)
255 {
256         entity tm;
257         AuditLists();
258         for(tm = teams.sort_next; tm; tm = tm.sort_next)
259                 if(tm == Team)
260                         error("Team already registered!");
261         Team.sort_next = teams.sort_next;
262         Team.sort_prev = teams;
263         if(teams.sort_next)
264                 teams.sort_next.sort_prev = Team;
265         teams.sort_next = Team;
266         AuditLists();
267         return true;
268 }
269
270 void RemoveTeam(entity Team)
271 {
272         entity tm, parent;
273         AuditLists();
274         parent = teams;
275         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
276                 parent = tm;
277
278         if(!tm)
279         {
280                 print("Trying to remove a team which is not in the teamlist!");
281                 return;
282         }
283         parent.sort_next = Team.sort_next;
284         if(Team.sort_next)
285                 Team.sort_next.sort_prev = parent;
286         AuditLists();
287 }
288
289 entity GetTeam(float Team, float add)
290 {
291         float num;
292         entity tm;
293         num = (Team == COLOR_SPECTATOR) ? 16 : Team;
294         if(teamslots[num])
295                 return teamslots[num];
296         if not(add)
297                 return NULL;
298         tm = spawn();
299         tm.team = Team;
300         teamslots[num] = tm;
301         RegisterTeam(tm);
302         return tm;
303 }
304
305 void CSQC_CheckEngine()
306 {
307         hud_font = FONT_USER+1;
308         hud_bigfont = FONT_USER+2;
309 }
310
311 vector HUD_GetFontsize(string cvarname)
312 {
313         vector v;
314         v = stov(cvar_string(cvarname));
315         if(v_x == 0)
316                 v = '8 8 0';
317         if(v_y == 0)
318                 v_y = v_x;
319         v_z = 0;
320         return v;
321 }
322
323 float PreviewExists(string name)
324 {
325         float f;
326         string file;
327
328         if(cvar("cl_readpicture_force"))
329                 return false;
330
331         file = strcat(name, ".tga");
332         f = fopen(file, FILE_READ);
333         if(f >= 0)
334         {
335                 fclose(f);
336                 return true;
337         }
338         file = strcat(name, ".png");
339         f = fopen(file, FILE_READ);
340         if(f >= 0)
341         {
342                 fclose(f);
343                 return true;
344         }
345         file = strcat(name, ".jpg");
346         f = fopen(file, FILE_READ);
347         if(f >= 0)
348         {
349                 fclose(f);
350                 return true;
351         }
352         file = strcat(name, ".pcx");
353         f = fopen(file, FILE_READ);
354         if(f >= 0)
355         {
356                 fclose(f);
357                 return true;
358         }
359         return false;
360 }
361
362 vector rotate(vector v, float a)
363 {
364         vector w;
365         // FTEQCC SUCKS AGAIN
366         w_x =      v_x * cos(a) + v_y * sin(a);
367         w_y = -1 * v_x * sin(a) + v_y * cos(a);
368         return w;
369 }
370
371 float ColorTranslateMode;
372
373 string ColorTranslateRGB(string s)
374 {
375         if(ColorTranslateMode & 1)
376                 return strdecolorize(s);
377         else
378                 return s;
379 }
380
381 float cvar_or(string cv, float v)
382 {
383         string s;
384         s = cvar_string(cv);
385         if(s == "")
386                 return v;
387         else
388                 return stof(s);
389 }
390
391 vector project_3d_to_2d(vector vec)
392 {
393         vec = cs_project(vec);
394         if(cs_project_is_b0rked > 0)
395         {
396                 vec_x *= vid_conwidth / vid_width;
397                 vec_y *= vid_conheight / vid_height;
398         }
399         return vec;
400 }
401
402 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
403 {
404 }
405
406 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
407 {
408         return 1.2 / (1.2 - fadelerp);
409 }
410
411 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
412 {
413         boxsize_x *= boxxsizefactor; // easier interface for text
414         return boxsize * (0.5 * (1 - sz));
415 }
416
417 void drawborderlines(float thickness, vector pos, vector dim, vector color, float alpha, float drawflag)
418 {
419         vector line_dim;
420
421         // left and right lines
422         pos_x -= thickness;
423         line_dim_x = thickness;
424         line_dim_y = dim_y;
425         drawfill(pos, line_dim, color, alpha, drawflag);
426         drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, alpha, drawflag);
427
428         // upper and lower lines
429         pos_y -= thickness;
430         line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
431         line_dim_y = thickness;
432         drawfill(pos, line_dim, color, alpha, drawflag);
433         drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, alpha, drawflag);
434 }
435
436 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float alpha, float drawflag)
437 {
438         vector current_pos, end_pos, new_size, ratio;
439         end_pos = pos + area;
440
441         current_pos_y = pos_y;
442         while (current_pos_y < end_pos_y)
443         {
444                 current_pos_x = pos_x;
445                 while (current_pos_x < end_pos_x)
446                 {
447                         new_size_x = min(sz_x, end_pos_x - current_pos_x);
448                         new_size_y = min(sz_y, end_pos_y - current_pos_y);
449                         ratio_x = new_size_x / sz_x;
450                         ratio_y = new_size_y / sz_y;
451                         drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, alpha, drawflag);
452                         current_pos_x += sz_x;
453                 }
454                 current_pos_y += sz_y;
455         }
456 }
457
458 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
459 var float imgaspect;
460 var float aspect;
461 #define drawpic_aspect(pos,pic,mySize,color,alpha,drawflag)\
462 do {\
463         vector imgsize;\
464         imgsize = drawgetimagesize(pic);\
465         imgaspect = imgsize_x/imgsize_y;\
466         vector oldsz, sz;\
467         oldsz = sz = mySize;\
468         aspect = sz_x/sz_y;\
469         if(aspect > imgaspect) {\
470                 sz_x = sz_y * imgaspect;\
471                 drawpic(pos + eX * (oldsz_x - sz_x) * 0.5, pic, sz, color, alpha, drawflag);\
472         } else {\
473                 sz_y = sz_x / imgaspect;\
474                 drawpic(pos + eY * (oldsz_y - sz_y) * 0.5, pic, sz, color, alpha, drawflag);\
475         }\
476 } while(0)
477
478 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
479 #define drawpic_aspect_skin(pos,pic,sz,color,alpha,drawflag)\
480 do{\
481         picpath = strcat(hud_skin_path, "/", pic);\
482         if(precache_pic(picpath) == "") {\
483                 picpath = strcat("gfx/hud/default/", pic);\
484         }\
485         drawpic_aspect(pos, picpath, sz, color, alpha, drawflag);\
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         picpath = strcat(hud_skin_path, "/", pic);\
492         if(precache_pic(picpath) == "") {\
493                 picpath = strcat("gfx/hud/default/", pic);\
494         }\
495         drawpic(pos, picpath, sz, color, alpha, drawflag);\
496 } while(0)
497
498 void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
499 {
500         float sz;
501         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
502
503         drawpic_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, alpha * (1 - fadelerp), flag);
504 }
505
506 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float alpha, float flag, float fadelerp)
507 {
508         drawpic_aspect_skin_expanding(position, pic, scale, rgb, alpha, flag, fadelerp);
509         drawpic_skin(position, pic, scale, rgb, alpha * fadelerp, flag);
510 }
511
512 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
513 void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {
514         vector textsize;
515         textsize = eX * stringwidth(text, FALSE, '1 1 1' * sz_y) + eY * sz_y;
516         
517         float textaspect;
518         textaspect = textsize_x/textsize_y;
519
520         vector oldsz;
521         oldsz = sz;
522         float aspect;
523         aspect = sz_x/sz_y;
524
525         if(aspect > textaspect) {
526                 sz_x = sz_y * textaspect;
527                 drawstring(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
528         } else {
529                 sz_y = sz_x / textaspect; 
530                 drawstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
531         }
532 }
533
534 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
535 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float alpha, float drawflag) {
536         vector textsize;
537         textsize = eX * stringwidth(text, TRUE, '1 1 1' * sz_y) + eY * sz_y;
538         
539         float textaspect;
540         textaspect = textsize_x/textsize_y;
541
542         vector oldsz;
543         oldsz = sz;
544         float aspect;
545         aspect = sz_x/sz_y;
546
547         if(aspect > textaspect) {
548                 sz_x = sz_y * textaspect;
549                 drawcolorcodedstring(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
550         } else {
551                 sz_y = sz_x / textaspect; 
552                 drawcolorcodedstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
553         }
554 }
555
556 vector drawfontscale;
557 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
558 {
559         float sz;
560         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
561
562         drawfontscale = sz * '1 1 0';
563         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
564         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);
565         // width parameter:
566         //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
567         //    SIZE1
568         drawfontscale = '1 1 0';
569 }
570
571 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
572 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float alpha, float drawflag, float fadelerp) {
573         vector textsize;
574         textsize = eX * stringwidth(text, FALSE, '1 1 1' * sz_y) + eY * sz_y;
575         
576         float textaspect;
577         textaspect = textsize_x/textsize_y;
578
579         vector oldsz;
580         oldsz = sz;
581         float aspect;
582         aspect = sz_x/sz_y;
583
584         if(aspect > textaspect) {
585                 sz_x = sz_y * textaspect;
586                 drawstring_expanding(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
587         } else {
588                 sz_y = sz_x / textaspect; 
589                 drawstring_expanding(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag, fadelerp);
590         }
591 }
592
593 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
594 {
595         float sz;
596         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
597
598         drawfontscale = sz * '1 1 0';
599         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
600         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);
601         drawfontscale = '1 1 0';
602 }
603
604 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float alpha, float drawflag, float fadelerp) {
605         vector textsize;
606         textsize = eX * stringwidth(text, TRUE, '1 1 1' * sz_y) + eY * sz_y;
607         
608         float textaspect;
609         textaspect = textsize_x/textsize_y;
610
611         vector oldsz;
612         oldsz = sz;
613         float aspect;
614         aspect = sz_x/sz_y;
615
616         if(aspect > textaspect) {
617                 sz_x = sz_y * textaspect;
618                 drawcolorcodedstring_expanding(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
619         } else {
620                 sz_y = sz_x / textaspect; 
621                 drawcolorcodedstring_expanding(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag, fadelerp);
622         }
623 }
624
625 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
626 void PolyDrawModel(entity e)
627 {
628         float i_s, i_t;
629         float n_t;
630         vector tri;
631         string tex;
632         for(i_s = 0; ; ++i_s)
633         {
634                 tex = getsurfacetexture(e, i_s);
635                 if not(tex)
636                         break; // this is beyond the last one
637                 n_t = getsurfacenumtriangles(e, i_s);
638                 for(i_t = 0; i_t < n_t; ++i_t)
639                 {
640                         tri = getsurfacetriangle(e, i_s, i_t);
641                         R_BeginPolygon(tex, 0);
642                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
643                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
644                         R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
645                         R_EndPolygon();
646                 }
647         }
648 }