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