Xonotic
weapons.qc File Reference
#include "weapons.qh"
#include <client/draw.qh>
#include <client/view.qh>
#include <common/wepent.qh>
+ Include dependency graph for weapons.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HUD_WEAPONS_GET_FULL_LAYOUT()
 

Functions

vector Accuracy_GetColor (float accuracy)
 
void Accuracy_LoadColors ()
 
void Accuracy_LoadLevels ()
 
void HUD_Weapons ()
 
void HUD_Weapons_Export (int fh)
 
int weaponorder_cmp (int i, int j, entity pass)
 
void weaponorder_swap (int i, int j, entity pass)
 

Variables

string cl_weaponpriority_old
 
entity weaponorder [REGISTRY_MAX(Weapons)]
 
string weaponorder_cmp_str
 
bool weapons_orderbyimpulse_old
 

Macro Definition Documentation

◆ HUD_WEAPONS_GET_FULL_LAYOUT

#define HUD_WEAPONS_GET_FULL_LAYOUT ( )
Value:
MACRO_BEGIN \
int nHidden = 0; \
FOREACH(Weapons, it != WEP_Null, { \
if (weapons_stat & WepSet_FromWeapon(it)) continue; \
if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) nHidden += 1; \
}); \
vector table_size = HUD_GetTableSize_BestItemAR((REGISTRY_COUNT(Weapons) - 1) - nHidden, panel_size, aspect); \
columns = table_size.x; \
rows = table_size.y; \
weapon_size.x = panel_size.x / columns; \
weapon_size.y = panel_size.y / rows; \
MACRO_END
vector panel_size
Definition: hud.qh:160
vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
Definition: hud.qc:172
const int WEP_FLAG_HIDDEN
Definition: weapon.qh:200
#define REGISTRY_COUNT(id)
Definition: registry.qh:18
const int WEP_FLAG_SPECIALATTACK
Definition: weapon.qh:211
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define WepSet_FromWeapon(it)
Definition: all.qh:38

Definition at line 104 of file weapons.qc.

Referenced by HUD_Weapons().

Function Documentation

◆ Accuracy_GetColor()

vector Accuracy_GetColor ( float  accuracy)

Definition at line 67 of file weapons.qc.

References acc_col, acc_lev, acc_levels, color, and vector().

Referenced by HUD_Weapons().

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 }
vector color
float acc_lev[MAX_ACCURACY_LEVELS]
Definition: weapons.qh:44
entity accuracy
Definition: accuracy.qh:26
int acc_levels
Definition: weapons.qh:47
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector acc_col[MAX_ACCURACY_LEVELS]
Definition: weapons.qh:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Accuracy_LoadColors()

void Accuracy_LoadColors ( )

Definition at line 55 of file weapons.qc.

References acc_col, acc_col_loadtime, acc_levels, cvar_string(), ftos(), stov(), strcat(), and time.

Referenced by HUD_Weapons().

56 {
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 }
float acc_col_loadtime
Definition: weapons.qh:46
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int acc_levels
Definition: weapons.qh:47
vector acc_col[MAX_ACCURACY_LEVELS]
Definition: weapons.qh:45
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Accuracy_LoadLevels()

void Accuracy_LoadLevels ( )

Definition at line 38 of file weapons.qc.

References acc_color_levels, acc_lev, acc_levels, argv(), autocvar_accuracy_color_levels, LOG_INFO, MAX_ACCURACY_LEVELS, stof(), strcpy, and tokenize_console.

39 {
41  {
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 }
float acc_lev[MAX_ACCURACY_LEVELS]
Definition: weapons.qh:44
#define strcpy(this, s)
Definition: string.qh:49
int acc_levels
Definition: weapons.qh:47
string autocvar_accuracy_color_levels
Definition: weapons.qh:40
#define LOG_INFO(...)
Definition: log.qh:70
#define tokenize_console
Definition: dpextensions.qh:24
const int MAX_ACCURACY_LEVELS
Definition: weapons.qh:43
string acc_color_levels
Definition: weapons.qh:48
+ Here is the call graph for this function:

◆ HUD_Weapons()

void HUD_Weapons ( )

Definition at line 119 of file weapons.qc.

References Accuracy_GetColor(), Accuracy_LoadColors(), autocvar__hud_configure, autocvar_cl_weaponpriority, autocvar_hud_panel_weapons, autocvar_hud_panel_weapons_accuracy, autocvar_hud_panel_weapons_ammo, autocvar_hud_panel_weapons_ammo_alpha, autocvar_hud_panel_weapons_ammo_color, autocvar_hud_panel_weapons_ammo_full_cells, autocvar_hud_panel_weapons_ammo_full_fuel, autocvar_hud_panel_weapons_ammo_full_nails, autocvar_hud_panel_weapons_ammo_full_plasma, autocvar_hud_panel_weapons_ammo_full_rockets, autocvar_hud_panel_weapons_ammo_full_shells, autocvar_hud_panel_weapons_aspect, autocvar_hud_panel_weapons_complainbubble, autocvar_hud_panel_weapons_complainbubble_fadetime, autocvar_hud_panel_weapons_complainbubble_time, autocvar_hud_panel_weapons_dynamichud, autocvar_hud_panel_weapons_hide_ondeath, autocvar_hud_panel_weapons_label, autocvar_hud_panel_weapons_label_scale, autocvar_hud_panel_weapons_noncurrent_alpha, autocvar_hud_panel_weapons_noncurrent_scale, autocvar_hud_panel_weapons_onlyowned, autocvar_hud_panel_weapons_orderbyimpulse, autocvar_hud_panel_weapons_selection_radius, autocvar_hud_panel_weapons_selection_speed, autocvar_hud_panel_weapons_timeout, autocvar_hud_panel_weapons_timeout_effect, autocvar_hud_panel_weapons_timeout_fadebgmin, autocvar_hud_panel_weapons_timeout_fadefgmin, autocvar_hud_panel_weapons_timeout_speed_in, autocvar_hud_panel_weapons_timeout_speed_out, bound(), ceil(), cl_weaponpriority_old, color, complain_weapon, complain_weapon_time, complain_weapon_type, cvar(), DRAWFLAG_NORMAL, drawpic_aspect_skin, drawresetcliparea(), drawsetcliparea(), drawstring(), entity(), fabs(), floor(), FOREACH, frametime, ftos(), getcommandkey, heapsort(), hud, hud_configure_menu_open, HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), HUD_WEAPONS_GET_FULL_LAYOUT, max(), min(), NULL, panel_bg_alpha, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, REGISTRY_COUNT, REGISTRY_MAX, spawnflags, spectatee_status, stov(), strcat(), strcpy, string_null, time, vec2, vector(), vid_conheight, vid_conwidth, viewmodels, W_FixWeaponOrder_BuildImpulseList(), W_FixWeaponOrder_ForceComplete(), W_NumberWeaponOrder(), weapon_accuracy, weaponorder, weaponorder_cmp(), weaponorder_cmp_str, weaponorder_swap(), weaponprevtime, weapons_orderbyimpulse_old, weapontime, WEP_FIRST, WEP_FLAG_HIDDEN, WEP_FLAG_MUTATORBLOCKED, WEP_FLAG_SPECIALATTACK, WEP_LAST, and WepSet_FromWeapon.

120 {
121  // declarations
122  WepSet weapons_stat = WepSet_GetFromStat();
123  int i;
124  float f, a;
125  float screen_ar;
126  vector center = '0 0 0';
127  int weapon_count, weapon_id;
128  int row, column, rows = 0, columns = 0;
129  bool vertical_order = true;
130  float aspect = max(0.001, autocvar_hud_panel_weapons_aspect);
131 
132  float timeout = autocvar_hud_panel_weapons_timeout;
133  float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
134  float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
135 
136  vector barsize = '0 0 0', baroffset = '0 0 0';
137  vector ammo_color = '1 0 1';
138  float ammo_alpha = 1;
139 
142 
143  bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
144 
145  vector weapon_pos, weapon_size = '0 0 0';
146  vector color;
147 
148  entity panel_switchweapon = NULL;
149 
150  // check to see if we want to continue
151  if(hud != HUD_NORMAL) return;
152 
154  {
156  return;
157  if(STAT(HEALTH) <= 0 && autocvar_hud_panel_weapons_hide_ondeath)
158  return;
159  if(timeout && time >= weapontime + timeout + timeout_effect_length)
161  {
163  return;
164  }
165  }
166 
167  // update generic hud functions
169 
171  {
176  {
177  weporder = W_FixWeaponOrder_BuildImpulseList(weporder);
178  }
179 
180  weaponorder_cmp_str = strcat(" ", weporder, " ");
181 
182  int weapon_cnt = 0;
183  FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, weaponorder[weapon_cnt++] = it);
184  for(i = weapon_cnt; i < REGISTRY_MAX(Weapons); ++i)
185  weaponorder[i] = NULL;
187 
189  }
190 
193 
194  entity wepent = viewmodels[0]; // TODO: unhardcode
195 
196  if (wepent.switchweapon == WEP_Null)
197  panel_switchweapon = NULL;
198  else if (!panel_switchweapon)
199  panel_switchweapon = wepent.switchweapon;
200 
202  {
203  if(!weapons_stat)
204  {
205  int j = 0;
206  FOREACH(Weapons, it != WEP_Null && it.impulse >= 0 && (it.impulse % 3 != 0) && j < 6, {
207  if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_SPECIALATTACK))
208  {
209  if(!panel_switchweapon || j < 4)
210  panel_switchweapon = it;
211  weapons_stat |= it.m_wepset;
212  ++j;
213  }
214  });
215  }
216 
217  #if 0
218  if(cvar("wep_add"))
220  {
221  int j;
222  int nHidden = 0;
223  FOREACH(Weapons, it != WEP_Null, {
224  if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
225  });
226  weapons_stat = '0 0 0';
227  float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((REGISTRY_COUNT(Weapons) - 1) - nHidden));
228  for(i = 0, j = 0; i <= (REGISTRY_COUNT(Weapons) - 1) && j < countw; ++i)
229  {
231  continue;
232  weapons_stat |= weaponorder[i].m_wepset;
233  ++j;
234  }
235  }
236  #endif
237  }
238 
239  // determine which weapons are going to be shown
241  {
243  {
244  if(hud_configure_menu_open != 2)
245  HUD_Panel_DrawBg(); // also draw the bg of the entire panel
246  }
247 
248  // do we own this weapon?
249  weapon_count = 0;
250  if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
251  {
252  for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
253  if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon)
254  ++weapon_count;
255  }
256  else
257  {
258  for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
259  if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon)
260  ++weapon_count;
261  }
262 
263  // might as well commit suicide now, no reason to live ;)
264  if (weapon_count == 0)
265  return;
266 
267  vector old_panel_size = panel_size;
268  panel_size -= '2 2 0' * panel_bg_padding;
269 
271 
272  // NOTE: although weapons should aways look the same even if onlyowned is enabled,
273  // we enlarge them a bit when possible to better match the desired aspect ratio
274  if(panel_size.x / panel_size.y < aspect)
275  {
276  // maximum number of rows that allows to display items with the desired aspect ratio
277  int max_rows = floor(panel_size.y / (weapon_size.x / aspect));
278  columns = min(columns, ceil(weapon_count / max_rows));
279  rows = ceil(weapon_count / columns);
280  weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
281  weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
282  vertical_order = false;
283  }
284  else
285  {
286  int max_columns = floor(panel_size.x / (weapon_size.y * aspect));
287  rows = min(rows, ceil(weapon_count / max_columns));
288  columns = ceil(weapon_count / rows);
289  weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
290  weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
291  vertical_order = true;
292  }
293 
294  // reduce size of the panel
295  panel_size.x = columns * weapon_size.x;
296  panel_size.y = rows * weapon_size.y;
297  panel_size += '2 2 0' * panel_bg_padding;
298 
299  // center the resized panel, or snap it to the screen edge when close enough
300  if(panel_pos.x > vid_conwidth * 0.001)
301  {
302  if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
303  panel_pos.x += old_panel_size.x - panel_size.x;
304  else
305  panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
306  }
307  else if(old_panel_size.x > vid_conwidth * 0.999)
308  panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
309 
310  if(panel_pos.y > vid_conheight * 0.001)
311  {
312  if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
313  panel_pos.y += old_panel_size.y - panel_size.y;
314  else
315  panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
316  }
317  else if(old_panel_size.y > vid_conheight * 0.999)
318  panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
319  }
320  else
321  weapon_count = (REGISTRY_COUNT(Weapons) - 1);
322 
323  // animation for fading in/out the panel respectively when not in use
325  {
326  if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
327  {
328  f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
329 
330  // fade the panel alpha
332  {
335  }
337  {
338  panel_bg_alpha *= (1 - f);
339  panel_fg_alpha *= (1 - f);
340  }
341 
342  // move the panel off the screen
344  {
345  f *= f; // for a cooler movement
346  center.x = panel_pos.x + panel_size.x/2;
347  center.y = panel_pos.y + panel_size.y/2;
348  screen_ar = vid_conwidth/vid_conheight;
349  if (center.x/center.y < screen_ar) //bottom left
350  {
351  if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
352  panel_pos.y += f * (vid_conheight - panel_pos.y);
353  else //left
354  panel_pos.x -= f * (panel_pos.x + panel_size.x);
355  }
356  else //top right
357  {
358  if ((vid_conwidth - center.x)/center.y < screen_ar) //right
359  panel_pos.x += f * (vid_conwidth - panel_pos.x);
360  else //top
361  panel_pos.y -= f * (panel_pos.y + panel_size.y);
362  }
363  if(f == 1)
364  center.x = -1; // mark the panel as off screen
365  }
366  weaponprevtime = time - (1 - f) * timein_effect_length;
367  }
368  else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
369  {
370  f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
371 
372  // fade the panel alpha
374  {
377  }
379  {
380  panel_bg_alpha *= (f);
381  panel_fg_alpha *= (f);
382  }
383 
384  // move the panel back on screen
386  {
387  f *= f; // for a cooler movement
388  f = 1 - f;
389  center.x = panel_pos.x + panel_size.x/2;
390  center.y = panel_pos.y + panel_size.y/2;
391  screen_ar = vid_conwidth/vid_conheight;
392  if (center.x/center.y < screen_ar) //bottom left
393  {
394  if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
395  panel_pos.y += f * (vid_conheight - panel_pos.y);
396  else //left
397  panel_pos.x -= f * (panel_pos.x + panel_size.x);
398  }
399  else //top right
400  {
401  if ((vid_conwidth - center.x)/center.y < screen_ar) //right
402  panel_pos.x += f * (vid_conwidth - panel_pos.x);
403  else //top
404  panel_pos.y -= f * (panel_pos.y + panel_size.y);
405  }
406  }
407  }
408  }
409 
410  // draw the background, then change the virtual size of it to better fit other items inside
413  else
416 
417  if(center.x == -1)
418  return; // panel has gone off screen
419 
420  if(panel_bg_padding)
421  {
422  panel_pos += '1 1 0' * panel_bg_padding;
423  panel_size -= '2 2 0' * panel_bg_padding;
424  }
425 
426  // after the sizing and animations are done, update the other values
427 
428  if(!rows) // if rows is > 0 onlyowned code has already updated these vars
429  {
431  vertical_order = (panel_size.x / panel_size.y >= aspect);
432  }
433 
434  // calculate position/size for visual bar displaying ammount of ammo status
435  if (!infinite_ammo && autocvar_hud_panel_weapons_ammo)
436  {
439 
440  if(weapon_size.x/weapon_size.y > aspect)
441  {
442  barsize.x = aspect * weapon_size.y;
443  barsize.y = weapon_size.y;
444  baroffset.x = (weapon_size.x - barsize.x) / 2;
445  }
446  else
447  {
448  barsize.y = 1/aspect * weapon_size.x;
449  barsize.x = weapon_size.x;
450  baroffset.y = (weapon_size.y - barsize.y) / 2;
451  }
452  }
455 
456  // draw items
457  row = column = 0;
458  vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
459  vector noncurrent_size = weapon_size * bound(0.01, autocvar_hud_panel_weapons_noncurrent_scale, 1);
460  float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
461  static vector weapon_pos_current = '-1 0 0';
462  if(weapon_pos_current.x == -1)
463  weapon_pos_current = panel_pos;
464 
465  float switch_speed;
467  switch_speed = 999;
468  else
470  vector radius_size = weapon_size * (autocvar_hud_panel_weapons_selection_radius + 1);
471 
472  // draw background behind currently selected weapon
473  // do it earlier to make sure bg is drawn behind every weapon icons while it's moving
474  if(panel_switchweapon)
475  drawpic_aspect_skin(weapon_pos_current, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
476 
477  for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
478  {
479  // retrieve information about the current weapon to be drawn
480  entity it = weaponorder[i];
481  weapon_id = it.impulse;
482 
483  // skip if this weapon doesn't exist
484  if(!it || weapon_id < 0) { continue; }
485 
486  // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
488  {
489  if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
490  {
491  if (!(it == panel_switchweapon || it == complain_weapon))
492  continue;
493  }
494  else
495  {
496  if (!((weapons_stat & WepSet_FromWeapon(it)) || (it == complain_weapon)))
497  continue;
498  }
499  }
500  else
501  {
503  && !(weapons_stat & WepSet_FromWeapon(it)))
504  {
505  continue;
506  }
507  }
508 
509  // figure out the drawing position of weapon
510  weapon_pos = panel_pos + vec2(column * weapon_size.x, row * weapon_size.y);
511 
512  // update position of the currently selected weapon
513  if(it == panel_switchweapon)
514  {
515  if(weapon_pos_current.y > weapon_pos.y)
516  weapon_pos_current.y = max(weapon_pos.y, weapon_pos_current.y - switch_speed * (weapon_pos_current.y - weapon_pos.y));
517  else if(weapon_pos_current.y < weapon_pos.y)
518  weapon_pos_current.y = min(weapon_pos.y, weapon_pos_current.y + switch_speed * (weapon_pos.y - weapon_pos_current.y));
519  if(weapon_pos_current.x > weapon_pos.x)
520  weapon_pos_current.x = max(weapon_pos.x, weapon_pos_current.x - switch_speed * (weapon_pos_current.x - weapon_pos.x));
521  else if(weapon_pos_current.x < weapon_pos.x)
522  weapon_pos_current.x = min(weapon_pos.x, weapon_pos_current.x + switch_speed * (weapon_pos.x - weapon_pos_current.x));
523  }
524 
525  // draw the weapon accuracy
527  {
528  float panel_weapon_accuracy = weapon_accuracy[it.m_id-WEP_FIRST];
529  if(panel_weapon_accuracy >= 0)
530  {
531  color = Accuracy_GetColor(panel_weapon_accuracy);
532  drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
533  }
534  }
535 
536  vector weapon_size_real = noncurrent_size;
537  float weapon_alpha_real = noncurrent_alpha;
538  float radius_factor_x = 1 - bound(0, fabs(weapon_pos.x - weapon_pos_current.x) / radius_size.x, 1);
539  float radius_factor_y = 1 - bound(0, fabs(weapon_pos.y - weapon_pos_current.y) / radius_size.y, 1);
540  if(radius_factor_x || radius_factor_y)
541  {
542  weapon_size_real.x += (weapon_size.x - noncurrent_size.x) * radius_factor_x;
543  weapon_size_real.y += (weapon_size.y - noncurrent_size.y) * radius_factor_y;
544  weapon_alpha_real += (panel_fg_alpha - noncurrent_alpha) * min(radius_factor_x, radius_factor_y);
545  }
546 
547  vector weapon_pos_real = weapon_pos;
548  weapon_pos_real.x = weapon_pos.x + (weapon_size.x - weapon_size_real.x) / 2;
549  weapon_pos_real.y = weapon_pos.y + (weapon_size.y - weapon_size_real.y) / 2;
550 
551  // drawing all the weapon items
552  if(weapons_stat & WepSet_FromWeapon(it))
553  {
554  // draw the weapon image
555  drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '1 1 1', weapon_alpha_real, DRAWFLAG_NORMAL);
556 
557  // draw weapon label string
559  {
560  case 1: // weapon number
561  drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
562  break;
563 
564  case 2: // bind
565  drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
566  break;
567 
568  case 3: // weapon name
569  drawstring(weapon_pos, strtolower(it.m_name), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
570  break;
571 
572  default: // nothing
573  break;
574  }
575 
576  // draw ammo status bar
577  if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE))
578  {
579  float ammo_full;
580  a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have?
581 
582  if(a > 0)
583  {
584  // TODO: registry handles
585  switch (it.ammo_type)
586  {
587  case RES_SHELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
588  case RES_BULLETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
589  case RES_ROCKETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
590  case RES_CELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
591  case RES_PLASMA: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
592  case RES_FUEL: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
593  default: ammo_full = 60;
594  }
595 
597  weapon_pos.x + baroffset.x,
598  weapon_pos.y + baroffset.y,
599  barsize.x * bound(0, a/ammo_full, 1),
600  barsize.y
601  );
602 
604  weapon_pos,
605  "weapon_ammo",
606  weapon_size,
607  ammo_color,
608  ammo_alpha,
610  );
611 
613  }
614  }
615  }
616  else // draw a "ghost weapon icon" if you don't have the weapon
617  {
618  drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '0.2 0.2 0.2', weapon_alpha_real * 0.5, DRAWFLAG_NORMAL);
619  }
620 
621  // draw the complain message
622  if(it == complain_weapon)
623  {
624  if(fadetime)
625  a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
626  else
627  a = ((complain_weapon_time + when > time) ? 1 : 0);
628 
629  string s;
630  if(complain_weapon_type == 0) {
631  s = _("Out of ammo");
633  }
634  else if(complain_weapon_type == 1) {
635  s = _("Don't have");
637  }
638  else {
639  s = _("Unavailable");
641  }
643  drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
644  drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
645  }
646 
647  #if 0
650  {
651  drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
652  drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
653  }
654  #endif
655 
656  // continue with new position for the next weapon
657  if(vertical_order)
658  {
659  ++column;
660  if(column >= columns)
661  {
662  column = 0;
663  ++row;
664  }
665  }
666  else
667  {
668  ++row;
669  if(row >= rows)
670  {
671  row = 0;
672  ++column;
673  }
674  }
675  }
676 }
vector color
vector WepSet
Definition: weapon.qh:11
float vid_conheight
int autocvar_hud_panel_weapons_label
Definition: weapons.qh:25
float panel_fg_alpha
Definition: hud.qh:166
string string_null
Definition: nil.qh:9
int autocvar_hud_panel_weapons_ammo_full_rockets
Definition: weapons.qh:13
int autocvar_hud_panel_weapons_ammo_full_fuel
Definition: weapons.qh:11
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
const int WEP_FIRST
Definition: all.qh:304
int autocvar_hud_panel_weapons_ammo_full_plasma
Definition: weapons.qh:10
float autocvar_hud_panel_weapons_aspect
Definition: weapons.qh:15
bool autocvar_hud_panel_weapons_accuracy
Definition: weapons.qh:5
int weaponorder_cmp(int i, int j, entity pass)
Definition: weapons.qc:96
bool autocvar__hud_configure
Definition: hud_config.qh:3
float weapontime
Definition: hud.qh:121
float autocvar_hud_panel_weapons_complainbubble_fadetime
Definition: weapons.qh:20
bool autocvar_hud_panel_weapons_complainbubble
Definition: weapons.qh:16
entity viewmodels[MAX_WEAPONSLOTS]
Definition: view.qh:104
bool autocvar_hud_panel_weapons_hide_ondeath
Definition: weapons.qh:24
vector panel_size
Definition: hud.qh:160
entity() spawn
#define getcommandkey(cmd_name, command)
Definition: main.qh:108
string autocvar_hud_panel_weapons_complainbubble_color_donthave
Definition: weapons.qh:17
float autocvar_hud_panel_weapons_selection_radius
Definition: weapons.qh:30
int autocvar_hud_panel_weapons_ammo_full_cells
Definition: weapons.qh:9
float autocvar_hud_panel_weapons_ammo_alpha
Definition: weapons.qh:7
ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass)
Definition: sort.qh:9
void HUD_Scale_Disable()
Definition: hud.qc:83
#define WEP_LAST
Definition: all.qh:305
int autocvar_hud_panel_weapons_ammo_full_shells
Definition: weapons.qh:14
const int WEP_FLAG_HIDDEN
Definition: weapon.qh:200
float vid_conwidth
bool autocvar_hud_panel_weapons_orderbyimpulse
Definition: weapons.qh:34
string cl_weaponpriority_old
Definition: weapons.qc:117
string W_FixWeaponOrder_ForceComplete(string order)
Definition: all.qc:182
float spawnflags
Definition: progsdefs.qc:191
entity complain_weapon
Definition: hud.qh:112
#define strcpy(this, s)
Definition: string.qh:49
float autocvar_hud_panel_weapons_noncurrent_alpha
Definition: weapons.qh:28
void weaponorder_swap(int i, int j, entity pass)
Definition: weapons.qc:87
#define REGISTRY_COUNT(id)
Definition: registry.qh:18
float autocvar_hud_panel_weapons_timeout_fadefgmin
Definition: weapons.qh:36
string W_NumberWeaponOrder(string order)
Definition: all.qc:136
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
float autocvar_hud_panel_weapons_timeout
Definition: weapons.qh:32
void HUD_Scale_Enable()
Definition: hud.qc:90
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
float complain_weapon_time
Definition: hud.qh:114
int autocvar_hud_panel_weapons_ammo_full_nails
Definition: weapons.qh:12
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
bool weapons_orderbyimpulse_old
Definition: weapons.qc:118
string W_FixWeaponOrder_BuildImpulseList(string o)
Definition: all.qc:162
string autocvar_cl_weaponpriority
Definition: weapons.qh:41
float autocvar_hud_panel_weapons_noncurrent_scale
Definition: weapons.qh:29
float panel_bg_alpha
Definition: hud.qh:167
string weaponorder_cmp_str
Definition: weapons.qc:95
#define NULL
Definition: post.qh:17
float frametime
Definition: csprogsdefs.qc:17
bool autocvar_hud_panel_weapons_ammo
Definition: weapons.qh:6
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
string autocvar_hud_panel_weapons_complainbubble_color_unavailable
Definition: weapons.qh:19
vector panel_pos
Definition: hud.qh:159
#define REGISTRY_MAX(id)
Definition: registry.qh:17
float autocvar_hud_panel_weapons_label_scale
Definition: weapons.qh:26
float autocvar_hud_panel_weapons_timeout_fadebgmin
Definition: weapons.qh:35
#define HUD_WEAPONS_GET_FULL_LAYOUT()
Definition: weapons.qc:104
vector(float skel, float bonenum) _skel_get_boneabs_hidden
entity weaponorder[REGISTRY_MAX(Weapons)]
Definition: weapons.qc:86
int autocvar_hud_panel_weapons_onlyowned
Definition: weapons.qh:27
int complain_weapon_type
Definition: hud.qh:113
float spectatee_status
Definition: main.qh:166
const int WEP_FLAG_SPECIALATTACK
Definition: weapon.qh:211
bool autocvar_hud_panel_weapons
Definition: weapons.qh:4
float autocvar_hud_panel_weapons_complainbubble_padding
Definition: weapons.qh:21
float autocvar_hud_panel_weapons_timeout_speed_in
Definition: weapons.qh:37
#define vec2(...)
Definition: vector.qh:90
float autocvar_hud_panel_weapons_complainbubble_time
Definition: weapons.qh:22
float hud_configure_menu_open
Definition: hud_config.qh:21
int autocvar_hud_panel_weapons_timeout_effect
Definition: weapons.qh:33
bool autocvar_hud_panel_weapons_dynamichud
Definition: weapons.qh:23
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define WepSet_FromWeapon(it)
Definition: all.qh:38
string autocvar_hud_panel_weapons_complainbubble_color_outofammo
Definition: weapons.qh:18
void Accuracy_LoadColors()
Definition: weapons.qc:55
float time
Definition: csprogsdefs.qc:16
float autocvar_hud_panel_weapons_selection_speed
Definition: weapons.qh:31
vector Accuracy_GetColor(float accuracy)
Definition: weapons.qc:67
#define FOREACH(list, cond, body)
Definition: iter.qh:19
string autocvar_hud_panel_weapons_ammo_color
Definition: weapons.qh:8
int weapon_accuracy[REGISTRY_MAX(Weapons)]
Definition: hud.qh:110
float autocvar_hud_panel_weapons_timeout_speed_out
Definition: weapons.qh:38
float weaponprevtime
Definition: hud.qh:122
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171
int hud
Definition: main.qh:142
+ Here is the call graph for this function:

◆ HUD_Weapons_Export()

void HUD_Weapons_Export ( int  fh)

Definition at line 9 of file weapons.qc.

References HUD_Write_Cvar.

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 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38

◆ weaponorder_cmp()

int weaponorder_cmp ( int  i,
int  j,
entity  pass 
)

Definition at line 96 of file weapons.qc.

References m_id, strstrofs, TC, weaponorder, and weaponorder_cmp_str.

Referenced by HUD_Weapons().

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 }
int m_id
Definition: effect.qh:19
string weaponorder_cmp_str
Definition: weapons.qc:95
#define TC(T, sym)
Definition: _all.inc:82
#define strstrofs
Definition: dpextensions.qh:42
entity weaponorder[REGISTRY_MAX(Weapons)]
Definition: weapons.qc:86
+ Here is the caller graph for this function:

◆ weaponorder_swap()

void weaponorder_swap ( int  i,
int  j,
entity  pass 
)

Definition at line 87 of file weapons.qc.

References entity(), TC, and weaponorder.

Referenced by HUD_Weapons().

88 {
89  TC(int, i); TC(int, j);
90  entity h = weaponorder[i];
91  weaponorder[i] = weaponorder[j];
92  weaponorder[j] = h;
93 }
entity() spawn
#define TC(T, sym)
Definition: _all.inc:82
entity weaponorder[REGISTRY_MAX(Weapons)]
Definition: weapons.qc:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ cl_weaponpriority_old

string cl_weaponpriority_old

Definition at line 117 of file weapons.qc.

Referenced by HUD_Weapons().

◆ weaponorder

entity weaponorder[REGISTRY_MAX(Weapons)]

Definition at line 86 of file weapons.qc.

Referenced by HUD_Weapons(), W_GetCycleWeapon(), weaponorder_cmp(), and weaponorder_swap().

◆ weaponorder_cmp_str

string weaponorder_cmp_str

Definition at line 95 of file weapons.qc.

Referenced by HUD_Weapons(), and weaponorder_cmp().

◆ weapons_orderbyimpulse_old

bool weapons_orderbyimpulse_old

Definition at line 118 of file weapons.qc.

Referenced by HUD_Weapons().