Merge branch 'master' into terencehill/dynamic_hud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / hud.qc
1 #include "hud.qh"
2
3 #include "hud_config.qh"
4 #include "../mapvoting.qh"
5 #include "../scoreboard.qh"
6 #include "../teamradar.qh"
7 #include <common/t_items.qh>
8 #include <common/deathtypes/all.qh>
9 #include <common/items/all.qc>
10 #include <common/mapinfo.qh>
11 #include <common/vehicles/all.qh>
12 #include <common/mutators/mutator/waypoints/all.qh>
13 #include <common/stats.qh>
14 #include <lib/csqcmodel/cl_player.qh>
15 #include <server/mutators/mutator/gamemode_ctf.qh> // TODO: remove
16
17
18 /*
19 ==================
20 Misc HUD functions
21 ==================
22 */
23
24 vector HUD_Get_Num_Color (float x, float maxvalue)
25 {
26         float blinkingamt;
27         vector color;
28         if(x >= maxvalue) {
29                 color.x = sin(2*M_PI*time);
30                 color.y = 1;
31                 color.z = sin(2*M_PI*time);
32         }
33         else if(x > maxvalue * 0.75) {
34                 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
35                 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
36                 color.z = 0;
37         }
38         else if(x > maxvalue * 0.5) {
39                 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
40                 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
41                 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
42         }
43         else if(x > maxvalue * 0.25) {
44                 color.x = 1;
45                 color.y = 1;
46                 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
47         }
48         else if(x > maxvalue * 0.1) {
49                 color.x = 1;
50                 color.y = (x-20)*90/27/100; // green value between 0 -> 1
51                 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
52         }
53         else {
54                 color.x = 1;
55                 color.y = 0;
56                 color.z = 0;
57         }
58
59         blinkingamt = (1 - x/maxvalue/0.25);
60         if(blinkingamt > 0)
61         {
62                 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
63                 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
64                 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
65         }
66         return color;
67 }
68
69 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
70 {
71     TC(int, item_count);
72         float aspect = size_y / size_x;
73         return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
74 }
75
76 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
77 {
78     TC(int, item_count);
79         float columns, rows;
80         float ratio, best_ratio = 0;
81         float best_columns = 1, best_rows = 1;
82         bool vertical = (psize.x / psize.y >= item_aspect);
83         if(vertical)
84         {
85                 psize = eX * psize.y + eY * psize.x;
86                 item_aspect = 1 / item_aspect;
87         }
88
89         rows = ceil(sqrt(item_count));
90         columns = ceil(item_count/rows);
91         while(columns >= 1)
92         {
93                 ratio = (psize.x/columns) / (psize.y/rows);
94                 if(ratio > item_aspect)
95                         ratio = item_aspect * item_aspect / ratio;
96
97                 if(ratio <= best_ratio)
98                         break; // ratio starts decreasing by now, skip next configurations
99
100                 best_columns = columns;
101                 best_rows = rows;
102                 best_ratio = ratio;
103
104                 if(columns == 1)
105                         break;
106
107                 --columns;
108                 rows = ceil(item_count/columns);
109         }
110
111         if(vertical)
112                 return eX * best_rows + eY * best_columns;
113         else
114                 return eX * best_columns + eY * best_rows;
115 }
116
117 // return the string of the onscreen race timer
118 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
119 {
120     TC(int, cp);
121         string col;
122         string timestr;
123         string cpname;
124         string lapstr;
125         lapstr = "";
126
127         if(theirtime == 0) // goal hit
128         {
129                 if(mytime > 0)
130                 {
131                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
132                         col = "^1";
133                 }
134                 else if(mytime == 0)
135                 {
136                         timestr = "+0.0";
137                         col = "^3";
138                 }
139                 else
140                 {
141                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
142                         col = "^2";
143                 }
144
145                 if(lapdelta > 0)
146                 {
147                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
148                         col = "^2";
149                 }
150                 else if(lapdelta < 0)
151                 {
152                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
153                         col = "^1";
154                 }
155         }
156         else if(theirtime > 0) // anticipation
157         {
158                 if(mytime >= theirtime)
159                         timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
160                 else
161                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
162                 col = "^3";
163         }
164         else
165         {
166                 col = "^7";
167                 timestr = "";
168         }
169
170         if(cp == 254)
171                 cpname = _("Start line");
172         else if(cp == 255)
173                 cpname = _("Finish line");
174         else if(cp)
175                 cpname = sprintf(_("Intermediate %d"), cp);
176         else
177                 cpname = _("Finish line");
178
179         if(theirtime < 0)
180                 return strcat(col, cpname);
181         else if(theirname == "")
182                 return strcat(col, sprintf("%s (%s)", cpname, timestr));
183         else
184                 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
185 }
186
187 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
188 int race_CheckName(string net_name)
189 {
190         int i;
191         for (i=RANKINGS_CNT-1;i>=0;--i)
192                 if(grecordholder[i] == net_name)
193                         return i+1;
194         return 0;
195 }
196
197 /*
198 ==================
199 HUD panels
200 ==================
201 */
202
203 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
204 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
205 {
206     TC(bool, vertical); TC(int, drawflag);
207         if(!length_ratio || !theAlpha)
208                 return;
209         if(length_ratio > 1)
210                 length_ratio = 1;
211         if (baralign == 3)
212         {
213                 if(length_ratio < -1)
214                         length_ratio = -1;
215         }
216         else if(length_ratio < 0)
217                 return;
218
219         vector square;
220         vector width, height;
221         if(vertical) {
222                 pic = strcat(hud_skin_path, "/", pic, "_vertical");
223                 if(precache_pic(pic) == "") {
224                         pic = "gfx/hud/default/progressbar_vertical";
225                 }
226
227         if (baralign == 1) // bottom align
228                         theOrigin.y += (1 - length_ratio) * theSize.y;
229         else if (baralign == 2) // center align
230             theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
231         else if (baralign == 3) // center align, positive values down, negative up
232                 {
233                         theSize.y *= 0.5;
234                         if (length_ratio > 0)
235                                 theOrigin.y += theSize.y;
236                         else
237                         {
238                                 theOrigin.y += (1 + length_ratio) * theSize.y;
239                                 length_ratio = -length_ratio;
240                         }
241                 }
242                 theSize.y *= length_ratio;
243
244                 vector bH;
245                 width = eX * theSize.x;
246                 height = eY * theSize.y;
247                 if(theSize.y <= theSize.x * 2)
248                 {
249                         // button not high enough
250                         // draw just upper and lower part then
251                         square = eY * theSize.y * 0.5;
252                         bH = eY * (0.25 * theSize.y / (theSize.x * 2));
253                         drawsubpic(theOrigin,          square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
254                         drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
255                 }
256                 else
257                 {
258                         square = eY * theSize.x;
259                         drawsubpic(theOrigin,                   width   +     square, pic, '0 0    0', '1 0.25 0', theColor, theAlpha, drawflag);
260                         drawsubpic(theOrigin +          square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5  0', theColor, theAlpha, drawflag);
261                         drawsubpic(theOrigin + height - square, width   +     square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
262                 }
263         } else {
264                 pic = strcat(hud_skin_path, "/", pic);
265                 if(precache_pic(pic) == "") {
266                         pic = "gfx/hud/default/progressbar";
267                 }
268
269                 if (baralign == 1) // right align
270                         theOrigin.x += (1 - length_ratio) * theSize.x;
271         else if (baralign == 2) // center align
272             theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
273         else if (baralign == 3) // center align, positive values on the right, negative on the left
274                 {
275                         theSize.x *= 0.5;
276                         if (length_ratio > 0)
277                                 theOrigin.x += theSize.x;
278                         else
279                         {
280                                 theOrigin.x += (1 + length_ratio) * theSize.x;
281                                 length_ratio = -length_ratio;
282                         }
283                 }
284                 theSize.x *= length_ratio;
285
286                 vector bW;
287                 width = eX * theSize.x;
288                 height = eY * theSize.y;
289                 if(theSize.x <= theSize.y * 2)
290                 {
291                         // button not wide enough
292                         // draw just left and right part then
293                         square = eX * theSize.x * 0.5;
294                         bW = eX * (0.25 * theSize.x / (theSize.y * 2));
295                         drawsubpic(theOrigin,          square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
296                         drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
297                 }
298                 else
299                 {
300                         square = eX * theSize.y;
301                         drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, drawflag);
302                         drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, drawflag);
303                         drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
304                 }
305         }
306 }
307
308 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
309 {
310     TC(int, drawflag);
311         if(!theAlpha)
312                 return;
313
314         string pic;
315         pic = strcat(hud_skin_path, "/num_leading");
316         if(precache_pic(pic) == "") {
317                 pic = "gfx/hud/default/num_leading";
318         }
319
320         drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
321         if(mySize.x/mySize.y > 2)
322                 drawsubpic(pos + eX * mySize.y, eX * (mySize.x - 2 * mySize.y) + eY * mySize.y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
323         drawsubpic(pos + eX * mySize.x - eX * min(mySize.x * 0.5, mySize.y), eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
324 }
325
326 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
327 {
328     TC(bool, vertical); TC(bool, icon_right_align);
329         vector newPos = '0 0 0', newSize = '0 0 0';
330         vector picpos, numpos;
331
332         if (vertical)
333         {
334                 if(mySize.y/mySize.x > 2)
335                 {
336                         newSize.y = 2 * mySize.x;
337                         newSize.x = mySize.x;
338
339                         newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
340                         newPos.x = myPos.x;
341                 }
342                 else
343                 {
344                         newSize.x = 1/2 * mySize.y;
345                         newSize.y = mySize.y;
346
347                         newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
348                         newPos.y = myPos.y;
349                 }
350
351                 if(icon_right_align)
352                 {
353                         numpos = newPos;
354                         picpos = newPos + eY * newSize.x;
355                 }
356                 else
357                 {
358                         picpos = newPos;
359                         numpos = newPos + eY * newSize.x;
360                 }
361
362                 newSize.y /= 2;
363                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
364                 // make number smaller than icon, it looks better
365                 // reduce only y to draw numbers with different number of digits with the same y size
366                 numpos.y += newSize.y * ((1 - 0.7) / 2);
367                 newSize.y *= 0.7;
368                 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
369                 return;
370         }
371
372         if(mySize.x/mySize.y > 3)
373         {
374                 newSize.x = 3 * mySize.y;
375                 newSize.y = mySize.y;
376
377                 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
378                 newPos.y = myPos.y;
379         }
380         else
381         {
382                 newSize.y = 1/3 * mySize.x;
383                 newSize.x = mySize.x;
384
385                 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
386                 newPos.x = myPos.x;
387         }
388
389         if(icon_right_align) // right align
390         {
391                 numpos = newPos;
392                 picpos = newPos + eX * 2 * newSize.y;
393         }
394         else // left align
395         {
396                 numpos = newPos + eX * newSize.y;
397                 picpos = newPos;
398         }
399
400         // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
401         // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
402         drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
403         drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
404 }
405
406 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
407 {
408     TC(bool, vertical); TC(int, icon_right_align);
409         DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
410 }
411
412 #include "all.inc"
413
414 /*
415 ==================
416 Main HUD system
417 ==================
418 */
419
420 void CSQC_BUMBLE_GUN_HUD();
421
422 void HUD_Vehicle()
423 {
424         if(autocvar__hud_configure) return;
425         if(intermission == 2) return;
426
427         if(hud == HUD_BUMBLEBEE_GUN)
428                 CSQC_BUMBLE_GUN_HUD();
429         else {
430                 Vehicle info = Vehicles_from(hud);
431                 info.vr_hud(info);
432         }
433 }
434
435 bool HUD_Panel_CheckFlags(int showflags)
436 {
437     TC(int, showflags);
438         if ( HUD_Minigame_Showpanels() )
439                 return showflags & PANEL_SHOW_MINIGAME;
440         if(intermission == 2)
441                 return showflags & PANEL_SHOW_MAPVOTE;
442         return showflags & PANEL_SHOW_MAINGAME;
443 }
444
445 void HUD_Panel_Draw(entity panent)
446 {
447         panel = panent;
448         if(autocvar__hud_configure)
449         {
450                 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
451                         panel.panel_draw();
452         }
453         else if(HUD_Panel_CheckFlags(panel.panel_showflags))
454                 panel.panel_draw();
455 }
456
457 void HUD_Reset()
458 {
459         // reset gametype specific icons
460         if(gametype == MAPINFO_TYPE_CTF)
461                 HUD_Mod_CTF_Reset();
462 }
463
464 float autocvar_hud_dynamic_shake;
465 float autocvar_hud_dynamic_shake_damage_max;
466 float autocvar_hud_dynamic_shake_damage_min;
467 float autocvar_hud_dynamic_shake_scale;
468 float hud_dynamic_shake_x[10] = {0,    1, -0.7,  0.5, -0.3,  0.2, -0.1,  0.1,  0.0, 0};
469 float hud_dynamic_shake_y[10] = {0,  0.4,  0.8, -0.2, -0.6,  0.0,  0.3,  0.1, -0.1, 0};
470 bool Hud_Shake_Update()
471 {
472         if(time - hud_dynamic_shake_time < 0)
473                 return false;
474
475         float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
476         float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
477         int i = floor(elapsed_time);
478         if(i >= 9)
479                 return false;
480
481         float f = elapsed_time - i;
482         hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
483         hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
484         hud_dynamic_shake_realofs.z = 0;
485         hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
486         hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
487         hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
488         return true;
489 }
490
491 void calc_followmodel_ofs(entity view);
492 void Hud_Dynamic_Frame()
493 {
494         hud_dynamic_ofs = '0 0 0';
495         if (autocvar_hud_dynamic_follow)
496         {
497                 entity view = CSQCModel_server2csqc(player_localentnum - 1);
498                 calc_followmodel_ofs(view);
499                 hud_dynamic_ofs -= cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
500         }
501
502         if (fabs(hud_dynamic_ofs.x) < 0.001) hud_dynamic_ofs.x = 0;
503         if (fabs(hud_dynamic_ofs.y) < 0.001) hud_dynamic_ofs.y = 0;
504         if (fabs(hud_dynamic_ofs.z) < 0.001) hud_dynamic_ofs.z = 0;
505         hud_dynamic_ofs.x = bound(-0.1, hud_dynamic_ofs.x, 0.1);
506         hud_dynamic_ofs.y = bound(-0.1, hud_dynamic_ofs.y, 0.1);
507         hud_dynamic_ofs.z = bound(-0.1, hud_dynamic_ofs.z, 0.1);
508
509         float health = STAT(HEALTH);
510         if(autocvar_hud_dynamic_shake > 0 && !autocvar__hud_configure && health > 0)
511         {
512                 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
513                         hud_dynamic_shake_factor = 0;
514                 else
515                 {
516                         float new_hud_dynamic_shake_factor = 0;
517                         if(prev_health - health >= autocvar_hud_dynamic_shake_damage_min && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min)
518                         {
519                                 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
520                                 new_hud_dynamic_shake_factor = (prev_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
521                                 if(new_hud_dynamic_shake_factor >= 1)
522                                         new_hud_dynamic_shake_factor = 1;
523                                 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
524                                 {
525                                         hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
526                                         hud_dynamic_shake_time = time;
527                                 }
528                         }
529                         if(hud_dynamic_shake_factor)
530                                 if(!Hud_Shake_Update())
531                                         hud_dynamic_shake_factor = 0;
532                 }
533         }
534 }
535
536 void HUD_Main()
537 {
538         int i;
539         // global hud theAlpha fade
540         if(menu_enabled == 1)
541                 hud_fade_alpha = 1;
542         else
543                 hud_fade_alpha = (1 - autocvar__menu_alpha);
544
545         if(scoreboard_fade_alpha)
546                 hud_fade_alpha = (1 - scoreboard_fade_alpha);
547
548         HUD_Configure_Frame();
549
550         // panels that we want to be active together with the scoreboard
551         // they must fade only when the menu does
552         if(scoreboard_fade_alpha == 1)
553         {
554                 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
555                 return;
556         }
557
558         if(!autocvar__hud_configure && !hud_fade_alpha)
559         {
560                 hud_fade_alpha = 1;
561                 HUD_Panel_Draw(HUD_PANEL(VOTE));
562                 hud_fade_alpha = 0;
563                 return;
564         }
565
566         Hud_Dynamic_Frame();
567
568         // Drawing stuff
569         if (hud_skin_prev != autocvar_hud_skin)
570         {
571                 if (hud_skin_path)
572                         strunzone(hud_skin_path);
573                 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
574                 if (hud_skin_prev)
575                         strunzone(hud_skin_prev);
576                 hud_skin_prev = strzone(autocvar_hud_skin);
577         }
578
579         // draw the dock
580         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
581         {
582                 int f;
583                 vector color;
584                 float hud_dock_color_team = autocvar_hud_dock_color_team;
585                 if((teamplay) && hud_dock_color_team) {
586                         if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
587                                 color = '1 0 0' * hud_dock_color_team;
588                         else
589                                 color = myteamcolors * hud_dock_color_team;
590                 }
591                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
592                         color = '1 0 0' * hud_dock_color_team;
593                 }
594                 else
595                 {
596                         string hud_dock_color = autocvar_hud_dock_color;
597                         if(hud_dock_color == "shirt") {
598                                 f = stof(getplayerkeyvalue(current_player, "colors"));
599                                 color = colormapPaletteColor(floor(f / 16), 0);
600                         }
601                         else if(hud_dock_color == "pants") {
602                                 f = stof(getplayerkeyvalue(current_player, "colors"));
603                                 color = colormapPaletteColor(f % 16, 1);
604                         }
605                         else
606                                 color = stov(hud_dock_color);
607                 }
608
609                 string pic;
610                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
611                 if(precache_pic(pic) == "") {
612                         pic = strcat(hud_skin_path, "/dock_medium");
613                         if(precache_pic(pic) == "") {
614                                 pic = "gfx/hud/default/dock_medium";
615                         }
616                 }
617                 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
618         }
619
620         // cache the panel order into the panel_order array
621         if(autocvar__hud_panelorder != hud_panelorder_prev) {
622                 for(i = 0; i < hud_panels_COUNT; ++i)
623                         panel_order[i] = -1;
624                 string s = "";
625                 int p_num;
626                 bool warning = false;
627                 int argc = tokenize_console(autocvar__hud_panelorder);
628                 if (argc > hud_panels_COUNT)
629                         warning = true;
630                 //first detect wrong/missing panel numbers
631                 for(i = 0; i < hud_panels_COUNT; ++i) {
632                         p_num = stoi(argv(i));
633                         if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
634                                 if (panel_order[p_num] == -1) //found for the first time?
635                                         s = strcat(s, ftos(p_num), " ");
636                                 panel_order[p_num] = 1; //mark as found
637                         }
638                         else
639                                 warning = true;
640                 }
641                 for(i = 0; i < hud_panels_COUNT; ++i) {
642                         if (panel_order[i] == -1) {
643                                 warning = true;
644                                 s = strcat(s, ftos(i), " "); //add missing panel number
645                         }
646                 }
647                 if (warning)
648                         LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
649
650                 cvar_set("_hud_panelorder", s);
651                 if(hud_panelorder_prev)
652                         strunzone(hud_panelorder_prev);
653                 hud_panelorder_prev = strzone(s);
654
655                 //now properly set panel_order
656                 tokenize_console(s);
657                 for(i = 0; i < hud_panels_COUNT; ++i) {
658                         panel_order[i] = stof(argv(i));
659                 }
660         }
661
662         hud_draw_maximized = 0;
663         // draw panels in the order specified by panel_order array
664         for(i = hud_panels_COUNT - 1; i >= 0; --i)
665                 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
666
667         HUD_Vehicle();
668
669         hud_draw_maximized = 1; // panels that may be maximized must check this var
670         // draw maximized panels on top
671         if(hud_panel_radar_maximized)
672                 HUD_Panel_Draw(HUD_PANEL(RADAR));
673         if(autocvar__con_chat_maximized)
674                 HUD_Panel_Draw(HUD_PANEL(CHAT));
675         if(hud_panel_quickmenu)
676                 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
677
678         if (scoreboard_active || intermission == 2)
679                 HUD_Reset();
680
681         HUD_Configure_PostDraw();
682
683         hud_configure_prev = autocvar__hud_configure;
684 }