Purge client/defs.qh
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / weapons.qc
1 #include "weapons.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/main.qh>
5 #include <client/miscfunctions.qh>
6 #include <client/view.qh>
7 #include <common/wepent.qh>
8
9 // Weapons (#0)
10
11 void HUD_Weapons_Export(int fh)
12 {
13         HUD_Write_Cvar("hud_panel_weapons_accuracy");
14         HUD_Write_Cvar("hud_panel_weapons_label");
15         HUD_Write_Cvar("hud_panel_weapons_label_scale");
16         HUD_Write_Cvar("hud_panel_weapons_complainbubble");
17         HUD_Write_Cvar("hud_panel_weapons_complainbubble_padding");
18         HUD_Write_Cvar("hud_panel_weapons_complainbubble_time");
19         HUD_Write_Cvar("hud_panel_weapons_complainbubble_fadetime");
20         HUD_Write_Cvar("hud_panel_weapons_complainbubble_color_outofammo");
21         HUD_Write_Cvar("hud_panel_weapons_complainbubble_color_donthave");
22         HUD_Write_Cvar("hud_panel_weapons_complainbubble_color_unavailable");
23         HUD_Write_Cvar("hud_panel_weapons_ammo");
24         HUD_Write_Cvar("hud_panel_weapons_ammo_color");
25         HUD_Write_Cvar("hud_panel_weapons_ammo_alpha");
26         HUD_Write_Cvar("hud_panel_weapons_aspect");
27         HUD_Write_Cvar("hud_panel_weapons_timeout");
28         HUD_Write_Cvar("hud_panel_weapons_timeout_effect");
29         HUD_Write_Cvar("hud_panel_weapons_timeout_fadebgmin");
30         HUD_Write_Cvar("hud_panel_weapons_timeout_fadefgmin");
31         HUD_Write_Cvar("hud_panel_weapons_timeout_speed_in");
32         HUD_Write_Cvar("hud_panel_weapons_timeout_speed_out");
33         HUD_Write_Cvar("hud_panel_weapons_onlyowned");
34         HUD_Write_Cvar("hud_panel_weapons_noncurrent_alpha");
35         HUD_Write_Cvar("hud_panel_weapons_noncurrent_scale");
36         HUD_Write_Cvar("hud_panel_weapons_selection_radius");
37         HUD_Write_Cvar("hud_panel_weapons_selection_speed");
38 }
39
40 entity weaponorder[REGISTRY_MAX(Weapons)];
41 void weaponorder_swap(int i, int j, entity pass)
42 {
43         TC(int, i); TC(int, j);
44         entity h = weaponorder[i];
45         weaponorder[i] = weaponorder[j];
46         weaponorder[j] = h;
47 }
48
49 string weaponorder_cmp_str;
50 int weaponorder_cmp(int i, int j, entity pass)
51 {
52         TC(int, i); TC(int, j);
53         int ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].m_id), 0);
54         int aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].m_id), 0);
55         return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
56 }
57
58 #define HUD_WEAPONS_GET_FULL_LAYOUT() MACRO_BEGIN \
59         int nHidden = 0; \
60         FOREACH(Weapons, it != WEP_Null, { \
61                 if (weapons_stat & WepSet_FromWeapon(it)) continue; \
62                 if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) nHidden += 1; \
63         }); \
64         vector table_size = HUD_GetTableSize_BestItemAR((REGISTRY_COUNT(Weapons) - 1) - nHidden, panel_size, aspect); \
65         columns = table_size.x; \
66         rows = table_size.y; \
67         weapon_size.x = panel_size.x / columns; \
68         weapon_size.y = panel_size.y / rows; \
69 MACRO_END
70
71 string cl_weaponpriority_old;
72 bool weapons_orderbyimpulse_old;
73 void HUD_Weapons()
74 {
75         // declarations
76         WepSet weapons_stat = WepSet_GetFromStat();
77         int i;
78         float f, a;
79         float screen_ar;
80         vector center = '0 0 0';
81         int weapon_count, weapon_id;
82         int row, column, rows = 0, columns = 0;
83         bool vertical_order = true;
84         float aspect = autocvar_hud_panel_weapons_aspect;
85
86         float timeout = autocvar_hud_panel_weapons_timeout;
87         float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
88         float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
89
90         vector barsize = '0 0 0', baroffset = '0 0 0';
91         vector ammo_color = '1 0 1';
92         float ammo_alpha = 1;
93
94         float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
95         float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
96
97         bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
98
99         vector weapon_pos, weapon_size = '0 0 0';
100         vector color;
101
102         entity panel_switchweapon = NULL;
103
104         // check to see if we want to continue
105         if(hud != HUD_NORMAL) return;
106
107         if(!autocvar__hud_configure)
108         {
109                 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
110                         return;
111                 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_weapons_hide_ondeath)
112                         return;
113                 if(timeout && time >= weapontime + timeout + timeout_effect_length)
114                 if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
115                 {
116                         weaponprevtime = time;
117                         return;
118                 }
119         }
120
121         // update generic hud functions
122         HUD_Panel_LoadCvars();
123
124         if(cl_weaponpriority_old != autocvar_cl_weaponpriority || weapons_orderbyimpulse_old != autocvar_hud_panel_weapons_orderbyimpulse || weaponorder[0] == NULL)
125         {
126                 weapons_orderbyimpulse_old = autocvar_hud_panel_weapons_orderbyimpulse;
127                 strcpy(cl_weaponpriority_old, autocvar_cl_weaponpriority);
128                 string weporder = W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(cl_weaponpriority_old));
129                 if(autocvar_hud_panel_weapons_orderbyimpulse)
130                 {
131                         weporder = W_FixWeaponOrder_BuildImpulseList(weporder);
132                 }
133
134                 weaponorder_cmp_str = strcat(" ", weporder, " ");
135
136                 int weapon_cnt = 0;
137                 FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, weaponorder[weapon_cnt++] = it);
138                 for(i = weapon_cnt; i < REGISTRY_MAX(Weapons); ++i)
139                         weaponorder[i] = NULL;
140                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, NULL);
141
142                 weaponorder_cmp_str = string_null;
143         }
144
145         if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
146                 complain_weapon = NULL;
147
148         entity wepent = viewmodels[0]; // TODO: unhardcode
149
150         if (wepent.switchweapon == WEP_Null)
151                 panel_switchweapon = NULL;
152         else if (!panel_switchweapon)
153                 panel_switchweapon = wepent.switchweapon;
154
155         if(autocvar__hud_configure)
156         {
157                 if(!weapons_stat)
158                 {
159                         int j = 0;
160                         FOREACH(Weapons, it != WEP_Null && it.impulse >= 0 && (it.impulse % 3 != 0) && j < 6, {
161                                 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_SPECIALATTACK))
162                                 {
163                                         if(!panel_switchweapon || j < 4)
164                                                 panel_switchweapon = it;
165                                         weapons_stat |= it.m_wepset;
166                                         ++j;
167                                 }
168                         });
169                 }
170
171                 #if 0
172                 /// debug code
173                 if(cvar("wep_add"))
174                 {
175                         int j;
176                         int nHidden = 0;
177                         FOREACH(Weapons, it != WEP_Null, {
178                                 if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
179                         });
180                         weapons_stat = '0 0 0';
181                         float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((REGISTRY_COUNT(Weapons) - 1) - nHidden));
182                         for(i = 0, j = 0; i <= (REGISTRY_COUNT(Weapons) - 1) && j < countw; ++i)
183                         {
184                                 if(weaponorder[i].spawnflags & WEP_FLAG_MUTATORBLOCKED)
185                                         continue;
186                                 weapons_stat |= weaponorder[i].m_wepset;
187                                 ++j;
188                         }
189                 }
190                 #endif
191         }
192
193         // determine which weapons are going to be shown
194         if (autocvar_hud_panel_weapons_onlyowned)
195         {
196                 if(autocvar__hud_configure)
197                 {
198                         if(hud_configure_menu_open != 2)
199                                 HUD_Panel_DrawBg(); // also draw the bg of the entire panel
200                 }
201
202                 // do we own this weapon?
203                 weapon_count = 0;
204                 if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
205                 {
206                         for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
207                                 if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon)
208                                         ++weapon_count;
209                 }
210                 else
211                 {
212                         for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
213                                 if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon)
214                                         ++weapon_count;
215                 }
216
217                 // might as well commit suicide now, no reason to live ;)
218                 if (weapon_count == 0)
219                         return;
220
221                 vector old_panel_size = panel_size;
222                 panel_size -= '2 2 0' * panel_bg_padding;
223
224                 HUD_WEAPONS_GET_FULL_LAYOUT();
225
226                 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
227                 // we enlarge them a bit when possible to better match the desired aspect ratio
228                 if(panel_size.x / panel_size.y < aspect)
229                 {
230                         // maximum number of rows that allows to display items with the desired aspect ratio
231                         int max_rows = floor(panel_size.y / (weapon_size.x / aspect));
232                         columns = min(columns, ceil(weapon_count / max_rows));
233                         rows = ceil(weapon_count / columns);
234                         weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
235                         weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
236                         vertical_order = false;
237                 }
238                 else
239                 {
240                         int max_columns = floor(panel_size.x / (weapon_size.y * aspect));
241                         rows = min(rows, ceil(weapon_count / max_columns));
242                         columns = ceil(weapon_count / rows);
243                         weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
244                         weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
245                         vertical_order = true;
246                 }
247
248                 // reduce size of the panel
249                 panel_size.x = columns * weapon_size.x;
250                 panel_size.y = rows * weapon_size.y;
251                 panel_size += '2 2 0' * panel_bg_padding;
252
253                 // center the resized panel, or snap it to the screen edge when close enough
254                 if(panel_pos.x > vid_conwidth * 0.001)
255                 {
256                         if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
257                                 panel_pos.x += old_panel_size.x - panel_size.x;
258                         else
259                                 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
260                 }
261                 else if(old_panel_size.x > vid_conwidth * 0.999)
262                         panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
263
264                 if(panel_pos.y > vid_conheight * 0.001)
265                 {
266                         if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
267                                 panel_pos.y += old_panel_size.y - panel_size.y;
268                         else
269                                 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
270                 }
271                 else if(old_panel_size.y > vid_conheight * 0.999)
272                         panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
273         }
274         else
275                 weapon_count = (REGISTRY_COUNT(Weapons) - 1);
276
277         // animation for fading in/out the panel respectively when not in use
278         if(!autocvar__hud_configure)
279         {
280                 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
281                 {
282                         f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
283
284                         // fade the panel alpha
285                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
286                         {
287                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
288                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
289                         }
290                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
291                         {
292                                 panel_bg_alpha *= (1 - f);
293                                 panel_fg_alpha *= (1 - f);
294                         }
295
296                         // move the panel off the screen
297                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
298                         {
299                                 f *= f; // for a cooler movement
300                                 center.x = panel_pos.x + panel_size.x/2;
301                                 center.y = panel_pos.y + panel_size.y/2;
302                                 screen_ar = vid_conwidth/vid_conheight;
303                                 if (center.x/center.y < screen_ar) //bottom left
304                                 {
305                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
306                                                 panel_pos.y += f * (vid_conheight - panel_pos.y);
307                                         else //left
308                                                 panel_pos.x -= f * (panel_pos.x + panel_size.x);
309                                 }
310                                 else //top right
311                                 {
312                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //right
313                                                 panel_pos.x += f * (vid_conwidth - panel_pos.x);
314                                         else //top
315                                                 panel_pos.y -= f * (panel_pos.y + panel_size.y);
316                                 }
317                                 if(f == 1)
318                                         center.x = -1; // mark the panel as off screen
319                         }
320                         weaponprevtime = time - (1 - f) * timein_effect_length;
321                 }
322                 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
323                 {
324                         f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
325
326                         // fade the panel alpha
327                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
328                         {
329                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
330                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
331                         }
332                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
333                         {
334                                 panel_bg_alpha *= (f);
335                                 panel_fg_alpha *= (f);
336                         }
337
338                         // move the panel back on screen
339                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
340                         {
341                                 f *= f; // for a cooler movement
342                                 f = 1 - f;
343                                 center.x = panel_pos.x + panel_size.x/2;
344                                 center.y = panel_pos.y + panel_size.y/2;
345                                 screen_ar = vid_conwidth/vid_conheight;
346                                 if (center.x/center.y < screen_ar) //bottom left
347                                 {
348                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
349                                                 panel_pos.y += f * (vid_conheight - panel_pos.y);
350                                         else //left
351                                                 panel_pos.x -= f * (panel_pos.x + panel_size.x);
352                                 }
353                                 else //top right
354                                 {
355                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //right
356                                                 panel_pos.x += f * (vid_conwidth - panel_pos.x);
357                                         else //top
358                                                 panel_pos.y -= f * (panel_pos.y + panel_size.y);
359                                 }
360                         }
361                 }
362         }
363
364         // draw the background, then change the virtual size of it to better fit other items inside
365         if (autocvar_hud_panel_weapons_dynamichud)
366                 HUD_Scale_Enable();
367         else
368                 HUD_Scale_Disable();
369         HUD_Panel_DrawBg();
370
371         if(center.x == -1)
372                 return; // panel has gone off screen
373
374         if(panel_bg_padding)
375         {
376                 panel_pos += '1 1 0' * panel_bg_padding;
377                 panel_size -= '2 2 0' * panel_bg_padding;
378         }
379
380         // after the sizing and animations are done, update the other values
381
382         if(!rows) // if rows is > 0 onlyowned code has already updated these vars
383         {
384                 HUD_WEAPONS_GET_FULL_LAYOUT();
385                 vertical_order = (panel_size.x / panel_size.y >= aspect);
386         }
387
388         // calculate position/size for visual bar displaying ammount of ammo status
389         if (!infinite_ammo && autocvar_hud_panel_weapons_ammo)
390         {
391                 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
392                 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
393
394                 if(weapon_size.x/weapon_size.y > aspect)
395                 {
396                         barsize.x = aspect * weapon_size.y;
397                         barsize.y = weapon_size.y;
398                         baroffset.x = (weapon_size.x - barsize.x) / 2;
399                 }
400                 else
401                 {
402                         barsize.y = 1/aspect * weapon_size.x;
403                         barsize.x = weapon_size.x;
404                         baroffset.y = (weapon_size.y - barsize.y) / 2;
405                 }
406         }
407         if(autocvar_hud_panel_weapons_accuracy)
408                 Accuracy_LoadColors();
409
410         // draw items
411         row = column = 0;
412         vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
413         vector noncurrent_size = weapon_size * bound(0.01, autocvar_hud_panel_weapons_noncurrent_scale, 1);
414         float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
415         static vector weapon_pos_current = '-1 0 0';
416         if(weapon_pos_current.x == -1)
417                 weapon_pos_current = panel_pos;
418
419         float switch_speed;
420         if(autocvar_hud_panel_weapons_selection_speed <= 0 || autocvar__hud_configure)
421                 switch_speed = 999;
422         else
423                 switch_speed = frametime * autocvar_hud_panel_weapons_selection_speed;
424         vector radius_size = weapon_size * (autocvar_hud_panel_weapons_selection_radius + 1);
425
426         // draw background behind currently selected weapon
427         // do it earlier to make sure bg is drawn behind every weapon icons while it's moving
428         if(panel_switchweapon)
429                 drawpic_aspect_skin(weapon_pos_current, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
430
431         for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
432         {
433                 // retrieve information about the current weapon to be drawn
434                 entity it = weaponorder[i];
435                 weapon_id = it.impulse;
436
437                 // skip if this weapon doesn't exist
438                 if(!it || weapon_id < 0) { continue; }
439
440                 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
441                 if (autocvar_hud_panel_weapons_onlyowned)
442                 {
443                         if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
444                         {
445                                 if (!(it == panel_switchweapon || it == complain_weapon))
446                                         continue;
447                         }
448                         else
449                         {
450                                 if (!((weapons_stat & WepSet_FromWeapon(it)) || (it == complain_weapon)))
451                                         continue;
452                         }
453                 }
454                 else
455                 {
456                         if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)
457                                 && !(weapons_stat & WepSet_FromWeapon(it)))
458                         {
459                                 continue;
460                         }
461                 }
462
463                 // figure out the drawing position of weapon
464                 weapon_pos = panel_pos + vec2(column * weapon_size.x, row * weapon_size.y);
465
466                 // update position of the currently selected weapon
467                 if(it == panel_switchweapon)
468                 {
469                         if(weapon_pos_current.y > weapon_pos.y)
470                                 weapon_pos_current.y = max(weapon_pos.y, weapon_pos_current.y - switch_speed * (weapon_pos_current.y - weapon_pos.y));
471                         else if(weapon_pos_current.y < weapon_pos.y)
472                                 weapon_pos_current.y = min(weapon_pos.y, weapon_pos_current.y + switch_speed * (weapon_pos.y - weapon_pos_current.y));
473                         if(weapon_pos_current.x > weapon_pos.x)
474                                 weapon_pos_current.x = max(weapon_pos.x, weapon_pos_current.x - switch_speed * (weapon_pos_current.x - weapon_pos.x));
475                         else if(weapon_pos_current.x < weapon_pos.x)
476                                 weapon_pos_current.x = min(weapon_pos.x, weapon_pos_current.x + switch_speed * (weapon_pos.x - weapon_pos_current.x));
477                 }
478
479                 // draw the weapon accuracy
480                 if(autocvar_hud_panel_weapons_accuracy)
481                 {
482                         float panel_weapon_accuracy = weapon_accuracy[it.m_id-WEP_FIRST];
483                         if(panel_weapon_accuracy >= 0)
484                         {
485                                 color = Accuracy_GetColor(panel_weapon_accuracy);
486                                 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
487                         }
488                 }
489
490                 vector weapon_size_real = noncurrent_size;
491                 float weapon_alpha_real = noncurrent_alpha;
492                 float radius_factor_x = 1 - bound(0, fabs(weapon_pos.x - weapon_pos_current.x) / radius_size.x, 1);
493                 float radius_factor_y = 1 - bound(0, fabs(weapon_pos.y - weapon_pos_current.y) / radius_size.y, 1);
494                 if(radius_factor_x || radius_factor_y)
495                 {
496                         weapon_size_real.x += (weapon_size.x - noncurrent_size.x) * radius_factor_x;
497                         weapon_size_real.y += (weapon_size.y - noncurrent_size.y) * radius_factor_y;
498                         weapon_alpha_real += (panel_fg_alpha - noncurrent_alpha) * min(radius_factor_x, radius_factor_y);
499                 }
500
501                 vector weapon_pos_real = weapon_pos;
502                 weapon_pos_real.x = weapon_pos.x + (weapon_size.x - weapon_size_real.x) / 2;
503                 weapon_pos_real.y = weapon_pos.y + (weapon_size.y - weapon_size_real.y) / 2;
504
505                 // drawing all the weapon items
506                 if(weapons_stat & WepSet_FromWeapon(it))
507                 {
508                         // draw the weapon image
509                         drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '1 1 1', weapon_alpha_real, DRAWFLAG_NORMAL);
510
511                         // draw weapon label string
512                         switch(autocvar_hud_panel_weapons_label)
513                         {
514                                 case 1: // weapon number
515                                         drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
516                                         break;
517
518                                 case 2: // bind
519                                         drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
520                                         break;
521
522                                 case 3: // weapon name
523                                         drawstring(weapon_pos, strtolower(it.m_name), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
524                                         break;
525
526                                 default: // nothing
527                                         break;
528                         }
529
530                         // draw ammo status bar
531                         if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE))
532                         {
533                                 float ammo_full;
534                                 a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have?
535
536                                 if(a > 0)
537                                 {
538                                         switch (it.ammo_type)
539                                         {
540                                                 case RES_SHELLS:  ammo_full = autocvar_hud_panel_weapons_ammo_full_shells;  break;
541                                                 case RES_BULLETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails;   break;
542                                                 case RES_ROCKETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
543                                                 case RES_CELLS:   ammo_full = autocvar_hud_panel_weapons_ammo_full_cells;   break;
544                                                 case RES_PLASMA:  ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma;  break;
545                                                 case RES_FUEL:    ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel;    break;
546                                                 default: ammo_full = 60;
547                                         }
548
549                                         drawsetcliparea(
550                                                 weapon_pos.x + baroffset.x,
551                                                 weapon_pos.y + baroffset.y,
552                                                 barsize.x * bound(0, a/ammo_full, 1),
553                                                 barsize.y
554                                         );
555
556                                         drawpic_aspect_skin(
557                                                 weapon_pos,
558                                                 "weapon_ammo",
559                                                 weapon_size,
560                                                 ammo_color,
561                                                 ammo_alpha,
562                                                 DRAWFLAG_NORMAL
563                                         );
564
565                                         drawresetcliparea();
566                                 }
567                         }
568                 }
569                 else // draw a "ghost weapon icon" if you don't have the weapon
570                 {
571                         drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '0.2 0.2 0.2', weapon_alpha_real * 0.5, DRAWFLAG_NORMAL);
572                 }
573
574                 // draw the complain message
575                 if(it == complain_weapon)
576                 {
577                         if(fadetime)
578                                 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
579                         else
580                                 a = ((complain_weapon_time + when > time) ? 1 : 0);
581
582                         string s;
583                         if(complain_weapon_type == 0) {
584                                 s = _("Out of ammo");
585                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
586                         }
587                         else if(complain_weapon_type == 1) {
588                                 s = _("Don't have");
589                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
590                         }
591                         else {
592                                 s = _("Unavailable");
593                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
594                         }
595                         float padding = autocvar_hud_panel_weapons_complainbubble_padding;
596                         drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
597                         drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
598                 }
599
600                 #if 0
601                 /// debug code
602                 if(!autocvar_hud_panel_weapons_onlyowned)
603                 {
604                         drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
605                         drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
606                 }
607                 #endif
608
609                 // continue with new position for the next weapon
610                 if(vertical_order)
611                 {
612                         ++column;
613                         if(column >= columns)
614                         {
615                                 column = 0;
616                                 ++row;
617                         }
618                 }
619                 else
620                 {
621                         ++row;
622                         if(row >= rows)
623                         {
624                                 row = 0;
625                                 ++column;
626                         }
627                 }
628         }
629 }