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