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