]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/hud.qc
Merge branch 'master' into terencehill/scoreboard_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / hud.qc
1 #include "hud.qh"
2
3 #include "panel/scoreboard.qh"
4 #include "hud_config.qh"
5 #include "../mapvoting.qh"
6 #include "../teamradar.qh"
7 #include <common/t_items.qh>
8 #include <common/deathtypes/all.qh>
9 #include <common/items/_mod.qh>
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 /*
118 ==================
119 HUD panels
120 ==================
121 */
122
123 void HUD_Panel_LoadCvars()
124 {
125         // NOTE: in hud_configure mode cvars must be reloaded every frame
126         if (panel.update_time <= time)
127         {
128                 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos")));
129                 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size")));
130                 HUD_Panel_ScalePosSize();
131                 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg"));
132                 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color"));
133                 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team"));
134                 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha"));
135                 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border"));
136                 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding"));
137                 HUD_Panel_GetBg();
138                 if (panel.current_panel_bg != "0")
139                 {
140                         HUD_Panel_GetBgAlpha();
141                         HUD_Panel_GetBorder();
142                 }
143                 HUD_Panel_GetColorTeam();
144                 HUD_Panel_GetColor();
145                 HUD_Panel_GetFgAlpha();
146                 HUD_Panel_GetPadding();
147                 panel.current_panel_bg_alpha = panel_bg_alpha;
148                 panel.current_panel_fg_alpha = panel_fg_alpha;
149                 if (hud_configure_menu_open == 2 && panel == highlightedPanel)
150                         HUD_Panel_UpdatePosSize_ForMenu();
151                 else
152                 {
153                         panel_bg_alpha *= hud_fade_alpha * panel_fade_alpha;
154                         panel_fg_alpha *= hud_fade_alpha * panel_fade_alpha;
155                 }
156                 panel.current_panel_pos = panel_pos;
157                 panel.current_panel_size = panel_size;
158                 panel.current_panel_bg_border = panel_bg_border;
159                 panel.current_panel_bg_color = panel_bg_color;
160                 panel.current_panel_bg_color_team = panel_bg_color_team;
161                 panel.current_panel_bg_padding = panel_bg_padding;
162                 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval;
163                 return;
164         }
165
166         panel_pos = panel.current_panel_pos;
167         panel_size = panel.current_panel_size;
168         panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha * panel_fade_alpha;
169         panel_bg_border = panel.current_panel_bg_border;
170         panel_bg_color = panel.current_panel_bg_color;
171         panel_bg_color_team = panel.current_panel_bg_color_team;
172         panel_bg_padding = panel.current_panel_bg_padding;
173         panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha * panel_fade_alpha;
174 }
175
176 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
177 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
178 {
179     TC(bool, vertical); TC(int, drawflag);
180         if(!length_ratio || !theAlpha)
181                 return;
182         if(length_ratio > 1)
183                 length_ratio = 1;
184         if (baralign == 3)
185         {
186                 if(length_ratio < -1)
187                         length_ratio = -1;
188         }
189         else if(length_ratio < 0)
190                 return;
191
192         theOrigin = HUD_Shift(theOrigin);
193         theSize = HUD_Scale(theSize);
194
195         vector square;
196         vector width, height;
197         if(vertical) {
198                 pic = strcat(hud_skin_path, "/", pic, "_vertical");
199                 if(precache_pic(pic) == "") {
200                         pic = "gfx/hud/default/progressbar_vertical";
201                 }
202
203         if (baralign == 1) // bottom align
204                         theOrigin.y += (1 - length_ratio) * theSize.y;
205         else if (baralign == 2) // center align
206             theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
207         else if (baralign == 3) // center align, positive values down, negative up
208                 {
209                         theSize.y *= 0.5;
210                         if (length_ratio > 0)
211                                 theOrigin.y += theSize.y;
212                         else
213                         {
214                                 theOrigin.y += (1 + length_ratio) * theSize.y;
215                                 length_ratio = -length_ratio;
216                         }
217                 }
218                 theSize.y *= length_ratio;
219
220                 vector bH;
221                 width = eX * theSize.x;
222                 height = eY * theSize.y;
223                 if(theSize.y <= theSize.x * 2)
224                 {
225                         // button not high enough
226                         // draw just upper and lower part then
227                         square = eY * theSize.y * 0.5;
228                         bH = eY * (0.25 * theSize.y / (theSize.x * 2));
229                         drawsubpic(theOrigin,          square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
230                         drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
231                 }
232                 else
233                 {
234                         square = eY * theSize.x;
235                         drawsubpic(theOrigin,                   width   +     square, pic, '0 0    0', '1 0.25 0', theColor, theAlpha, drawflag);
236                         drawsubpic(theOrigin +          square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5  0', theColor, theAlpha, drawflag);
237                         drawsubpic(theOrigin + height - square, width   +     square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
238                 }
239         } else {
240                 pic = strcat(hud_skin_path, "/", pic);
241                 if(precache_pic(pic) == "") {
242                         pic = "gfx/hud/default/progressbar";
243                 }
244
245                 if (baralign == 1) // right align
246                         theOrigin.x += (1 - length_ratio) * theSize.x;
247         else if (baralign == 2) // center align
248             theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
249         else if (baralign == 3) // center align, positive values on the right, negative on the left
250                 {
251                         theSize.x *= 0.5;
252                         if (length_ratio > 0)
253                                 theOrigin.x += theSize.x;
254                         else
255                         {
256                                 theOrigin.x += (1 + length_ratio) * theSize.x;
257                                 length_ratio = -length_ratio;
258                         }
259                 }
260                 theSize.x *= length_ratio;
261
262                 vector bW;
263                 width = eX * theSize.x;
264                 height = eY * theSize.y;
265                 if(theSize.x <= theSize.y * 2)
266                 {
267                         // button not wide enough
268                         // draw just left and right part then
269                         square = eX * theSize.x * 0.5;
270                         bW = eX * (0.25 * theSize.x / (theSize.y * 2));
271                         drawsubpic(theOrigin,          square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
272                         drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
273                 }
274                 else
275                 {
276                         square = eX * theSize.y;
277                         drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, drawflag);
278                         drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, drawflag);
279                         drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
280                 }
281         }
282 }
283
284 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
285 {
286     TC(int, drawflag);
287         if(!theAlpha)
288                 return;
289
290         pos = HUD_Shift(pos);
291         mySize = HUD_Scale(mySize);
292
293         string pic;
294         pic = strcat(hud_skin_path, "/num_leading");
295         if(precache_pic(pic) == "") {
296                 pic = "gfx/hud/default/num_leading";
297         }
298
299         drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
300         if(mySize.x/mySize.y > 2)
301                 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);
302         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);
303 }
304
305 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp)
306 {
307     TC(bool, vertical); TC(int, icon_right_align);
308         vector newPos = '0 0 0', newSize = '0 0 0';
309         vector picpos, numpos;
310
311         if (vertical)
312         {
313                 if(mySize.y/mySize.x > 2)
314                 {
315                         newSize.y = 2 * mySize.x;
316                         newSize.x = mySize.x;
317
318                         newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
319                         newPos.x = myPos.x;
320                 }
321                 else
322                 {
323                         newSize.x = 1/2 * mySize.y;
324                         newSize.y = mySize.y;
325
326                         newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
327                         newPos.y = myPos.y;
328                 }
329
330                 if(icon_right_align)
331                 {
332                         numpos = newPos;
333                         picpos = newPos + eY * newSize.x;
334                 }
335                 else
336                 {
337                         picpos = newPos;
338                         numpos = newPos + eY * newSize.x;
339                 }
340
341                 newSize.y /= 2;
342                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
343                 // make number smaller than icon, it looks better
344                 // reduce only y to draw numbers with different number of digits with the same y size
345                 numpos.y += newSize.y * ((1 - 0.7) / 2);
346                 newSize.y *= 0.7;
347                 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
348                 return;
349         }
350
351         if(mySize.x/mySize.y > 3)
352         {
353                 newSize.x = 3 * mySize.y;
354                 newSize.y = mySize.y;
355
356                 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
357                 newPos.y = myPos.y;
358         }
359         else
360         {
361                 newSize.y = 1/3 * mySize.x;
362                 newSize.x = mySize.x;
363
364                 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
365                 newPos.x = myPos.x;
366         }
367
368         if(icon_right_align) // right align
369         {
370                 numpos = newPos;
371                 picpos = newPos + eX * 2 * newSize.y;
372         }
373         else // left align
374         {
375                 numpos = newPos + eX * newSize.y;
376                 picpos = newPos;
377         }
378
379         // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
380         // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
381         drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
382         drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
383 }
384
385 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
386 {
387     TC(bool, vertical); TC(int, icon_right_align);
388         DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
389 }
390
391 /*
392 ==================
393 Main HUD system
394 ==================
395 */
396
397 void CSQC_BUMBLE_GUN_HUD();
398
399 void HUD_Vehicle()
400 {
401         if(autocvar__hud_configure) return;
402         if(intermission == 2) return;
403
404         if(hud == HUD_BUMBLEBEE_GUN)
405                 CSQC_BUMBLE_GUN_HUD();
406         else {
407                 Vehicle info = Vehicles_from(hud);
408                 info.vr_hud(info);
409         }
410 }
411
412 bool HUD_Minigame_Showpanels();
413
414 void HUD_Panel_Draw(entity panent)
415 {
416         panel = panent;
417         if (autocvar__hud_configure)
418         {
419                 if (!(panel.panel_configflags & PANEL_CONFIG_MAIN))
420                         return;
421                 panel_fade_alpha = 1;
422                 Hud_Panel_GetPanelEnabled();
423                 panel.panel_draw();
424                 return;
425         }
426
427         bool draw_allowed = false;
428         if (HUD_Minigame_Showpanels())
429         {
430                 if (panel.panel_showflags & PANEL_SHOW_MINIGAME)
431                         draw_allowed = true;
432         }
433         else if(intermission == 2)
434         {
435                 if(panel.panel_showflags & PANEL_SHOW_MAPVOTE)
436                         draw_allowed = true;
437         }
438         else if (panel.panel_showflags & PANEL_SHOW_MAINGAME)
439                 draw_allowed = true;
440
441         if (draw_allowed)
442         {
443                 if (panel.panel_showflags & PANEL_SHOW_WITH_SB)
444                         panel_fade_alpha = 1;
445                 else
446                 {
447                         panel_fade_alpha = 1 - scoreboard_fade_alpha;
448                         if(!panel_fade_alpha)
449                                 return;
450                 }
451                 panel.panel_draw();
452         }
453 }
454
455 void HUD_Reset()
456 {
457         // reset gametype specific icons
458         if(gametype.m_modicons_reset)
459                 gametype.m_modicons_reset();
460 }
461
462 float autocvar_hud_dynamic_shake = 1;
463 float autocvar_hud_dynamic_shake_damage_max = 130;
464 float autocvar_hud_dynamic_shake_damage_min = 10;
465 float autocvar_hud_dynamic_shake_scale = 0.2;
466 float hud_dynamic_shake_x[10] = {0,    1, -0.7,  0.5, -0.3,  0.2, -0.1,  0.1,  0.0, 0};
467 float hud_dynamic_shake_y[10] = {0,  0.4,  0.8, -0.2, -0.6,  0.0,  0.3,  0.1, -0.1, 0};
468 bool Hud_Shake_Update()
469 {
470         if(time - hud_dynamic_shake_time < 0)
471                 return false;
472
473         float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
474         float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
475         int i = floor(elapsed_time);
476         if(i >= 9)
477                 return false;
478
479         float f = elapsed_time - i;
480         hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
481         hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
482         hud_dynamic_shake_realofs.z = 0;
483         hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
484         hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
485         hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
486         return true;
487 }
488
489 entity CSQCModel_server2csqc(int i);
490 void calc_followmodel_ofs(entity view);
491 void Hud_Dynamic_Frame()
492 {
493         vector ofs = '0 0 0';
494         hud_scale = '1 1 0';
495         hud_shift = '0 0 0';
496         if (autocvar_hud_dynamic_follow)
497         {
498                 entity view = CSQCModel_server2csqc(player_localentnum - 1);
499                 calc_followmodel_ofs(view);
500                 ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
501                 ofs.x *= autocvar_hud_dynamic_follow_scale_xyz.z;
502                 ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x;
503                 ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y;
504
505                 if (fabs(ofs.x) < 0.001) ofs.x = 0;
506                 if (fabs(ofs.y) < 0.001) ofs.y = 0;
507                 if (fabs(ofs.z) < 0.001) ofs.z = 0;
508                 ofs.x = bound(-0.1, ofs.x, 0.1);
509                 ofs.y = bound(-0.1, ofs.y, 0.1);
510                 ofs.z = bound(-0.1, ofs.z, 0.1);
511
512                 hud_shift.x = ofs.y * vid_conwidth;
513                 hud_shift.y = ofs.z * vid_conheight;
514                 hud_shift.z = ofs.x;
515
516                 hud_scale.x = (1 + hud_shift.z);
517                 hud_scale.y = hud_scale.x;
518         }
519
520         if(autocvar_hud_dynamic_shake > 0)
521         {
522                 static float old_health = 0;
523                 float health = max(-1, STAT(HEALTH));
524                 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
525                 {
526                         hud_dynamic_shake_factor = 0;
527                         old_health = health;
528                 }
529                 else
530                 {
531                         float new_hud_dynamic_shake_factor = 0;
532                         if (old_health - health >= autocvar_hud_dynamic_shake_damage_min
533                                 && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min
534                                 && old_health > 0 && !intermission)
535                         {
536                                 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
537                                 new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
538                                 if(new_hud_dynamic_shake_factor >= 1)
539                                         new_hud_dynamic_shake_factor = 1;
540                                 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
541                                 {
542                                         hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
543                                         hud_dynamic_shake_time = time;
544                                 }
545                         }
546                         old_health = health;
547                         if(hud_dynamic_shake_factor)
548                                 if(!Hud_Shake_Update())
549                                         hud_dynamic_shake_factor = 0;
550                 }
551
552                 if(hud_dynamic_shake_factor > 0)
553                 {
554                         hud_shift.x += hud_dynamic_shake_realofs.x;
555                         hud_shift.y += hud_dynamic_shake_realofs.y;
556                 }
557         }
558
559         hud_scale_center.x = 0.5 * vid_conwidth;
560         hud_scale_center.y = 0.5 * vid_conheight;
561
562         hud_scale_current = hud_scale;
563         hud_shift_current = hud_shift;
564 }
565
566 void HUD_Main()
567 {
568         int i;
569         if(hud_configure_menu_open == 1)
570                 hud_fade_alpha = 1;
571         else
572                 hud_fade_alpha = 1 - autocvar__menu_alpha;
573
574         HUD_Configure_Frame();
575
576         Hud_Dynamic_Frame();
577
578         if(scoreboard_fade_alpha == 1)
579                 if(autocvar__menu_alpha == 1)
580                         return;
581
582         // Drawing stuff
583         if (hud_skin_prev != autocvar_hud_skin)
584         {
585                 if (hud_skin_path)
586                         strunzone(hud_skin_path);
587                 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
588                 if (hud_skin_prev)
589                         strunzone(hud_skin_prev);
590                 hud_skin_prev = strzone(autocvar_hud_skin);
591         }
592
593         // draw the dock
594         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
595         {
596                 int f;
597                 vector color;
598                 float hud_dock_color_team = autocvar_hud_dock_color_team;
599                 if((teamplay) && hud_dock_color_team) {
600                         if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
601                                 color = '1 0 0' * hud_dock_color_team;
602                         else
603                                 color = myteamcolors * hud_dock_color_team;
604                 }
605                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
606                         color = '1 0 0' * hud_dock_color_team;
607                 }
608                 else
609                 {
610                         string hud_dock_color = autocvar_hud_dock_color;
611                         if(hud_dock_color == "shirt") {
612                                 f = entcs_GetClientColors(current_player);
613                                 color = colormapPaletteColor(floor(f / 16), 0);
614                         }
615                         else if(hud_dock_color == "pants") {
616                                 f = entcs_GetClientColors(current_player);
617                                 color = colormapPaletteColor(f % 16, 1);
618                         }
619                         else
620                                 color = stov(hud_dock_color);
621                 }
622
623                 string pic;
624                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
625                 if(precache_pic(pic) == "") {
626                         pic = strcat(hud_skin_path, "/dock_medium");
627                         if(precache_pic(pic) == "") {
628                                 pic = "gfx/hud/default/dock_medium";
629                         }
630                 }
631                 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...
632         }
633
634         // cache the panel order into the panel_order array
635         if(autocvar__hud_panelorder != hud_panelorder_prev) {
636                 for(i = 0; i < hud_panels_COUNT; ++i)
637                         panel_order[i] = -1;
638                 string s = "";
639                 int p_num;
640                 bool warning = false;
641                 int argc = tokenize_console(autocvar__hud_panelorder);
642                 if (argc > hud_panels_COUNT)
643                         warning = true;
644                 //first detect wrong/missing panel numbers
645                 for(i = 0; i < hud_panels_COUNT; ++i) {
646                         p_num = stoi(argv(i));
647                         if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
648                                 if (panel_order[p_num] == -1) //found for the first time?
649                                         s = strcat(s, ftos(p_num), " ");
650                                 panel_order[p_num] = 1; //mark as found
651                         }
652                         else
653                                 warning = true;
654                 }
655                 for(i = 0; i < hud_panels_COUNT; ++i) {
656                         if (panel_order[i] == -1) {
657                                 warning = true;
658                                 s = strcat(s, ftos(i), " "); //add missing panel number
659                         }
660                 }
661                 if (warning)
662                         LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder");
663
664                 cvar_set("_hud_panelorder", s);
665                 if(hud_panelorder_prev)
666                         strunzone(hud_panelorder_prev);
667                 hud_panelorder_prev = strzone(s);
668
669                 //now properly set panel_order
670                 tokenize_console(s);
671                 for(i = 0; i < hud_panels_COUNT; ++i) {
672                         panel_order[i] = stof(argv(i));
673                 }
674         }
675
676         hud_draw_maximized = 0;
677         // draw panels in the order specified by panel_order array
678         for(i = hud_panels_COUNT - 1; i >= 0; --i)
679                 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
680
681         HUD_Vehicle();
682
683         hud_draw_maximized = 1; // panels that may be maximized must check this var
684         // draw maximized panels on top
685         if(hud_panel_radar_maximized)
686                 HUD_Panel_Draw(HUD_PANEL(RADAR));
687         if(autocvar__con_chat_maximized)
688                 HUD_Panel_Draw(HUD_PANEL(CHAT));
689         if(hud_panel_quickmenu)
690                 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
691         HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
692
693         if (intermission == 2)
694                 HUD_Reset();
695
696         HUD_Configure_PostDraw();
697
698         hud_configure_prev = autocvar__hud_configure;
699 }