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