Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 (bool should_draw)
void HUD_Weapons_Export (int fh)
int weaponorder_cmp (int i, int j, entity pass)
void weaponorder_swap (int i, int j, entity pass)
void Weapons_Draw (entity panel_switchweapon, WepSet weapons_stat, vector center, vector weapon_size, float aspect, float when, float fadetime, int rows, int columns, bool vertical_order)
void Weapons_Fade (vector center)

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)) \
++nHidden; \
}); \
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; \
Weapons
Definition guide.qh:113
vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
Definition hud.qc:172
vector panel_size
Definition hud.qh:163
#define MACRO_END
Definition macro.qh:7
#define REGISTRY_COUNT(id)
Definition registry.qh:18
vector
Definition self.qh:92
#define WepSet_FromWeapon(it)
Definition all.qh:48
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:261
const int WEP_FLAG_HIDDEN
Definition weapon.qh:258

Definition at line 99 of file weapons.qc.

99#define HUD_WEAPONS_GET_FULL_LAYOUT() MACRO_BEGIN \
100 int nHidden = 0; \
101 FOREACH(Weapons, it != WEP_Null, \
102 { \
103 if (weapons_stat & WepSet_FromWeapon(it)) \
104 continue; \
105 if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED)) \
106 ++nHidden; \
107 }); \
108 vector table_size = HUD_GetTableSize_BestItemAR((REGISTRY_COUNT(Weapons) - 1) - nHidden, panel_size, aspect); \
109 columns = table_size.x; \
110 rows = table_size.y; \
111 weapon_size.x = panel_size.x / columns; \
112 weapon_size.y = panel_size.y / rows; \
113MACRO_END

Referenced by Weapons_Draw().

Function Documentation

◆ Accuracy_GetColor()

vector Accuracy_GetColor ( float accuracy)

Definition at line 64 of file weapons.qc.

65{
66 if (acc_levels < 2)
67 return '0 0 0'; // return black, can't determine the right color
68
69 // find the max level lower than acc
70 int j = acc_levels - 1;
71 while (j && accuracy < acc_lev[j])
72 --j;
73
74 // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
75 float factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
76 vector color = acc_col[j];
77 color += factor * (acc_col[j+1] - color);
78 return color;
79}
entity accuracy
Definition accuracy.qh:26
vector color
Definition dynlight.qc:15
int acc_levels
Definition weapons.qh:46
vector acc_col[MAX_ACCURACY_LEVELS]
Definition weapons.qh:44
float acc_lev[MAX_ACCURACY_LEVELS]
Definition weapons.qh:43

References acc_col, acc_lev, acc_levels, accuracy, color, and vector.

Referenced by Scoreboard_AccuracyStats_Draw(), and Weapons_Draw().

◆ Accuracy_LoadColors()

void Accuracy_LoadColors ( )

Definition at line 54 of file weapons.qc.

55{
56 if (time > acc_col_loadtime && acc_levels >= 2)
57 {
58 for (int i = 0; i < acc_levels; ++i)
59 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
61 }
62}
float time
vector stov(string s)
const string cvar_string(string name)
string ftos(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float acc_col_loadtime
Definition weapons.qh:45

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

Referenced by Scoreboard_AccuracyStats_Draw(), and Weapons_Draw().

◆ Accuracy_LoadLevels()

void Accuracy_LoadLevels ( )

Definition at line 38 of file weapons.qc.

39{
41 {
46 if (acc_levels < 2)
47 LOG_INFO("Warning: accuracy_color_levels must contain at least 2 values");
48
49 for (int i = 0; i < acc_levels; ++i)
50 acc_lev[i] = stof(argv(i)) / 100.0;
51 }
52}
#define tokenize_console
#define LOG_INFO(...)
Definition log.qh:65
float stof(string val,...)
string argv(float n)
#define strcpy(this, s)
Definition string.qh:52
string acc_color_levels
Definition weapons.qh:47
string autocvar_accuracy_color_levels
Definition weapons.qh:39
const int MAX_ACCURACY_LEVELS
Definition weapons.qh:42

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

Referenced by HUD_Draw().

◆ HUD_Weapons()

void HUD_Weapons ( bool should_draw)

Definition at line 117 of file weapons.qc.

118{
119 // check to see if we want to continue
120 if (hud != HUD_NORMAL)
121 return;
122
124 {
126 return;
128 return;
129
131 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
132
133 if (timeout && time >= weapontime + timeout + timeout_effect_length)
136 {
138 return;
139 }
140 }
141 if (!should_draw)
142 return;
143
144 // declarations
145 WepSet weapons_stat = WepSet_GetFromStat();
146 entity panel_switchweapon = NULL;
147 vector center = '0 0 0';
148
151
152 vector weapon_size = '0 0 0';
153
154 // update generic hud functions
156
158 {
163 weporder = W_FixWeaponOrder_BuildImpulseList(weporder);
164
165 weaponorder_cmp_str = strcat(" ", weporder, " ");
166
167 int weapon_cnt = 0;
168 FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, weaponorder[weapon_cnt++] = it);
169 for (int i = weapon_cnt; i < REGISTRY_MAX(Weapons); ++i)
170 weaponorder[i] = NULL;
172
174 }
175
178
179 entity wepent = viewmodels[0]; // TODO: unhardcode
180
181 if (wepent.switchweapon == WEP_Null)
182 panel_switchweapon = NULL;
183 else if (!panel_switchweapon)
184 panel_switchweapon = wepent.switchweapon;
185
187 {
188 if (!weapons_stat)
189 {
190 int j = 0;
191 FOREACH(Weapons, it != WEP_Null && it.impulse >= 0 && (it.impulse % 3 != 0) && j < 6,
192 {
193 if (!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)))
194 {
195 if (!panel_switchweapon || j < 4)
196 panel_switchweapon = it;
197 weapons_stat |= it.m_wepset;
198 ++j;
199 }
200 });
201 }
202
203 #if 0
205 if (cvar("wep_add"))
206 {
207 int nHidden = 0;
208 FOREACH(Weapons, it != WEP_Null && it.spawnflags & WEP_FLAG_MUTATORBLOCKED, ++nHidden);
209 weapons_stat = '0 0 0';
210 float countw = 1 + floor((floor(time * cvar("wep_add"))) % (REGISTRY_COUNT(Weapons) - 1 - nHidden));
211 for (int i = 0, j = 0; i <= REGISTRY_COUNT(Weapons) - 1 && j < countw; ++i)
212 {
214 continue;
215 weapons_stat |= weaponorder[i].m_wepset;
216 ++j;
217 }
218 }
219 #endif
220 }
221
222 // determine which weapons are going to be shown
223 int weapon_count;
224 int rows = 0, columns = 0;
225 bool vertical_order = true;
226 float aspect = max(0.001, autocvar_hud_panel_weapons_aspect);
228 {
230 {
232 HUD_Panel_DrawBg(); // also draw the bg of the entire panel
233 }
234
235 // do we own this weapon?
236 weapon_count = 0;
237 if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
238 {
239 for (int i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
240 if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon)
241 ++weapon_count;
242 }
243 else
244 {
245 for (int i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
246 if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon)
247 ++weapon_count;
248 }
249
250 // might as well commit suicide now, no reason to live ;)
251 if (weapon_count == 0)
252 return;
253
254 vector old_panel_size = panel_size;
255 panel_size -= '2 2 0' * panel_bg_padding;
256
258
259 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
260 // we enlarge them a bit when possible to better match the desired aspect ratio
261 vertical_order = panel_size.x / panel_size.y >= aspect;
262 if (vertical_order)
263 {
264 // maximum number of columns that allows to display items with the desired aspect ratio
265 int max_columns = floor(panel_size.x / (weapon_size.y * aspect));
266 rows = min(rows, ceil(weapon_count / max_columns));
267 columns = ceil(weapon_count / rows);
268 weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
269 weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
270 }
271 else
272 {
273 int max_rows = floor(panel_size.y / (weapon_size.x / aspect));
274 columns = min(columns, ceil(weapon_count / max_rows));
275 rows = ceil(weapon_count / columns);
276 weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
277 weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
278 }
279
280 // reduce size of the panel
281 panel_size.x = columns * weapon_size.x;
282 panel_size.y = rows * weapon_size.y;
283 panel_size += '2 2 0' * panel_bg_padding;
284
285 // center the resized panel, or snap it to the screen edge when close enough
286 if (panel_pos.x > vid_conwidth * 0.001)
287 {
288 if (panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
289 panel_pos.x += old_panel_size.x - panel_size.x;
290 else
291 panel_pos.x += (old_panel_size.x - panel_size.x) * 0.5;
292 }
293 else if (old_panel_size.x > vid_conwidth * 0.999)
294 panel_pos.x += (old_panel_size.x - panel_size.x) * 0.5;
295
296 if (panel_pos.y > vid_conheight * 0.001)
297 {
298 if (panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
299 panel_pos.y += old_panel_size.y - panel_size.y;
300 else
301 panel_pos.y += (old_panel_size.y - panel_size.y) * 0.5;
302 }
303 else if (old_panel_size.y > vid_conheight * 0.999)
304 panel_pos.y += (old_panel_size.y - panel_size.y) * 0.5;
305 }
306 else
307 weapon_count = REGISTRY_COUNT(Weapons) - 1; // unused value
308
309
310 Weapons_Fade(center);
311 Weapons_Draw(panel_switchweapon, weapons_stat, center, weapon_size, aspect, when, fadetime, rows, columns, vertical_order);
312}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197
int hud
Definition main.qh:173
int spawnflags
Definition ammo.qh:15
const int HUD_NORMAL
Definition constants.qh:47
void HUD_Panel_LoadCvars()
Definition hud.qc:215
float weaponprevtime
Definition hud.qh:123
float panel_bg_padding
Definition hud.qh:174
entity complain_weapon
Definition hud.qh:113
float complain_weapon_time
Definition hud.qh:115
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
float weapontime
Definition hud.qh:122
bool autocvar__hud_configure
Definition hud_config.qh:3
float hud_configure_menu_open
Definition hud_config.qh:22
#define FOREACH(list, cond, body)
Definition iter.qh:19
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
#define STAT(...)
Definition stats.qh:82
float ceil(float f)
float cvar(string name)
float min(float f,...)
float floor(float f)
float max(float f,...)
fadetime
string string_null
Definition nil.qh:9
#define NULL
Definition post.qh:14
#define REGISTRY_MAX(id)
Definition registry.qh:17
ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass)
Definition sort.qh:9
entity viewmodels[MAX_WEAPONSLOTS]
Definition view.qh:108
string W_FixWeaponOrder_ForceComplete(string order)
Definition all.qc:171
string W_NumberWeaponOrder(string order)
Definition all.qc:126
string W_FixWeaponOrder_BuildImpulseList(string o)
Definition all.qc:152
WepSet WepSet_GetFromStat()
Definition all.qc:80
#define WEP_LAST
Definition all.qh:343
const int WEP_FIRST
Definition all.qh:342
vector WepSet
Definition weapon.qh:14
string cl_weaponpriority_old
Definition weapons.qc:115
#define HUD_WEAPONS_GET_FULL_LAYOUT()
Definition weapons.qc:99
int weaponorder_cmp(int i, int j, entity pass)
Definition weapons.qc:91
void weaponorder_swap(int i, int j, entity pass)
Definition weapons.qc:82
string weaponorder_cmp_str
Definition weapons.qc:90
bool weapons_orderbyimpulse_old
Definition weapons.qc:116
void Weapons_Draw(entity panel_switchweapon, WepSet weapons_stat, vector center, vector weapon_size, float aspect, float when, float fadetime, int rows, int columns, bool vertical_order)
Definition weapons.qc:411
entity weaponorder[REGISTRY_MAX(Weapons)]
Definition weapons.qc:81
void Weapons_Fade(vector center)
Definition weapons.qc:316
bool autocvar_hud_panel_weapons
Definition weapons.qh:4
int autocvar_hud_panel_weapons_onlyowned
Definition weapons.qh:26
bool autocvar_hud_panel_weapons_complainbubble
Definition weapons.qh:15
float autocvar_hud_panel_weapons_timeout_fadefgmin
Definition weapons.qh:35
float autocvar_hud_panel_weapons_timeout_fadebgmin
Definition weapons.qh:34
bool autocvar_hud_panel_weapons_hide_ondeath
Definition weapons.qh:23
float autocvar_hud_panel_weapons_aspect
Definition weapons.qh:14
float autocvar_hud_panel_weapons_timeout_speed_out
Definition weapons.qh:37
string autocvar_cl_weaponpriority
Definition weapons.qh:40
float autocvar_hud_panel_weapons_complainbubble_time
Definition weapons.qh:21
bool autocvar_hud_panel_weapons_orderbyimpulse
Definition weapons.qh:33
int autocvar_hud_panel_weapons_timeout_effect
Definition weapons.qh:32
float autocvar_hud_panel_weapons_timeout
Definition weapons.qh:31
float autocvar_hud_panel_weapons_complainbubble_fadetime
Definition weapons.qh:19

References autocvar__hud_configure, autocvar_cl_weaponpriority, autocvar_hud_panel_weapons, autocvar_hud_panel_weapons_complainbubble, autocvar_hud_panel_weapons_complainbubble_fadetime, autocvar_hud_panel_weapons_complainbubble_time, autocvar_hud_panel_weapons_hide_ondeath, autocvar_hud_panel_weapons_orderbyimpulse, 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_out, cl_weaponpriority_old, complain_weapon, complain_weapon_time, cvar(), entity(), fadetime, floor(), FOREACH, heapsort(), hud, HUD_NORMAL, HUD_Panel_LoadCvars(), max(), NULL, REGISTRY_COUNT, REGISTRY_MAX, spawnflags, spectatee_status, STAT, strcat(), strcpy, string_null, time, vector, viewmodels, W_FixWeaponOrder_BuildImpulseList(), W_FixWeaponOrder_ForceComplete(), W_NumberWeaponOrder(), weaponorder, weaponorder_cmp(), weaponorder_cmp_str, weaponorder_swap(), weaponprevtime, Weapons, weapons_orderbyimpulse_old, weapontime, WEP_FLAG_MUTATORBLOCKED, and WepSet_GetFromStat().

◆ HUD_Weapons_Export()

void HUD_Weapons_Export ( int fh)

Definition at line 9 of file weapons.qc.

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:40

References HUD_Write_Cvar.

◆ weaponorder_cmp()

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

Definition at line 91 of file weapons.qc.

92{
93 TC(int, i); TC(int, j);
94 int ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].m_id), 0);
95 int aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].m_id), 0);
96 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)
97}
#define strstrofs
int m_id
Definition effect.qh:19
#define TC(T, sym)
Definition _all.inc:82

References entity(), m_id, pass, strstrofs, TC, weaponorder, and weaponorder_cmp_str.

Referenced by HUD_Weapons().

◆ weaponorder_swap()

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

Definition at line 82 of file weapons.qc.

83{
84 TC(int, i); TC(int, j);
85 entity h = weaponorder[i];
87 weaponorder[j] = h;
88}

References entity(), pass, TC, and weaponorder.

Referenced by HUD_Weapons().

◆ Weapons_Draw()

void Weapons_Draw ( entity panel_switchweapon,
WepSet weapons_stat,
vector center,
vector weapon_size,
float aspect,
float when,
float fadetime,
int rows,
int columns,
bool vertical_order )

Definition at line 411 of file weapons.qc.

416{
417 // draw the background, then change the virtual size of it to better fit other items inside
420 else
423
424 if (center.x == -1)
425 return; // panel has gone off screen
426
428 vector barsize = '0 0 0', baroffset = '0 0 0';
429
430 vector ammo_color = '1 0 1';
431 float ammo_alpha = 1;
432 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
433
434 int row = 0, column = 0;
435
437 {
438 panel_pos += '1 1 0' * panel_bg_padding;
439 panel_size -= '2 2 0' * panel_bg_padding;
440 }
441
442 // after the sizing and animations are done, update the other values
443
444 if (!rows) // if rows is > 0 onlyowned code has already updated these vars
445 {
447 vertical_order = panel_size.x / panel_size.y >= aspect;
448 }
449
450 // calculate position/size for visual bar displaying ammount of ammo status
451 if (!infinite_ammo && autocvar_hud_panel_weapons_ammo)
452 {
455
456 if (weapon_size.x / weapon_size.y > aspect)
457 {
458 barsize.x = aspect * weapon_size.y;
459 barsize.y = weapon_size.y;
460 baroffset.x = (weapon_size.x - barsize.x) * 0.5;
461 }
462 else
463 {
464 barsize.y = 1 / aspect * weapon_size.x;
465 barsize.x = weapon_size.x;
466 baroffset.y = (weapon_size.y - barsize.y) * 0.5;
467 }
468 }
471
472 // draw items
473 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
474 vector noncurrent_size = weapon_size * bound(0.01, autocvar_hud_panel_weapons_noncurrent_scale, 1);
475 float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
476 static vector weapon_pos_current = '-1 0 0';
477 if (weapon_pos_current.x == -1)
478 weapon_pos_current = panel_pos;
479
481 ? 999
483 vector radius_size = weapon_size * (autocvar_hud_panel_weapons_selection_radius + 1);
484
485 // draw background behind currently selected weapon
486 // do it earlier to make sure bg is drawn behind every weapon icons while it's moving
487 if (panel_switchweapon)
488 drawpic_aspect_skin(weapon_pos_current, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
489
490 for (int i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
491 {
492 // retrieve information about the current weapon to be drawn
493 entity it = weaponorder[i];
494 int weapon_id = it.impulse;
495
496 // skip if this weapon doesn't exist
497 if (!it || weapon_id < 0)
498 continue;
499
500 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
502 {
503 if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
504 {
505 if (!(it == panel_switchweapon || it == complain_weapon))
506 continue;
507 }
508 else
509 {
510 if (!((weapons_stat & WepSet_FromWeapon(it)) || it == complain_weapon))
511 continue;
512 }
513 }
514 else
515 {
516 if ((it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED))
517 && !(weapons_stat & WepSet_FromWeapon(it)))
518 {
519 continue;
520 }
521 }
522
523 // figure out the drawing position of weapon
524 vector weapon_pos = panel_pos + vec2(column * weapon_size.x, row * weapon_size.y);
525
526 // update position of the currently selected weapon
527 if (it == panel_switchweapon)
528 {
529 if (weapon_pos_current.y > weapon_pos.y)
530 weapon_pos_current.y = max(weapon_pos.y, weapon_pos_current.y - switch_speed * (weapon_pos_current.y - weapon_pos.y));
531 else if (weapon_pos_current.y < weapon_pos.y)
532 weapon_pos_current.y = min(weapon_pos.y, weapon_pos_current.y + switch_speed * (weapon_pos.y - weapon_pos_current.y));
533 if (weapon_pos_current.x > weapon_pos.x)
534 weapon_pos_current.x = max(weapon_pos.x, weapon_pos_current.x - switch_speed * (weapon_pos_current.x - weapon_pos.x));
535 else if (weapon_pos_current.x < weapon_pos.x)
536 weapon_pos_current.x = min(weapon_pos.x, weapon_pos_current.x + switch_speed * (weapon_pos.x - weapon_pos_current.x));
537 }
538
539 // draw the weapon accuracy
541 {
542 float panel_weapon_accuracy = weapon_accuracy[it.m_id-WEP_FIRST];
543 if (autocvar__hud_configure && panel_weapon_accuracy == -1)
544 panel_weapon_accuracy = (it.m_id % 7 - 2) * 0.11 + 0.3; // make up something
545 if (panel_weapon_accuracy >= 0)
546 {
547 color = Accuracy_GetColor(panel_weapon_accuracy);
548 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
549 }
550 }
551
552 vector weapon_size_real = noncurrent_size;
553 float weapon_alpha_real = noncurrent_alpha;
554 float radius_factor_x = 1 - bound(0, fabs(weapon_pos.x - weapon_pos_current.x) / radius_size.x, 1);
555 float radius_factor_y = 1 - bound(0, fabs(weapon_pos.y - weapon_pos_current.y) / radius_size.y, 1);
556 if (radius_factor_x || radius_factor_y)
557 {
558 weapon_size_real.x += (weapon_size.x - noncurrent_size.x) * radius_factor_x;
559 weapon_size_real.y += (weapon_size.y - noncurrent_size.y) * radius_factor_y;
560 weapon_alpha_real += (panel_fg_alpha - noncurrent_alpha) * min(radius_factor_x, radius_factor_y);
561 }
562
563 vector weapon_pos_real = weapon_pos;
564 weapon_pos_real.x = weapon_pos.x + (weapon_size.x - weapon_size_real.x) * 0.5;
565 weapon_pos_real.y = weapon_pos.y + (weapon_size.y - weapon_size_real.y) * 0.5;
566
567 // drawing all the weapon items
568 if (weapons_stat & WepSet_FromWeapon(it))
569 {
570 // draw the weapon image
571 drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '1 1 1', weapon_alpha_real, DRAWFLAG_NORMAL);
572
573 // draw weapon label string
575 {
576 case 1: // weapon number
577 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
578 break;
579
580 case 2: // bind
581 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
582 break;
583
584 case 3: // weapon name
585 drawstring(weapon_pos, strtolower(it.m_name), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
586 break;
587
588 default: // nothing
589 break;
590 }
591
592 // draw ammo status bar
593 if (!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE))
594 {
595 float ammo_full;
596 float a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have?
597
598 if (autocvar__hud_configure && a == 0)
599 a = 60; // make up something
600
601 if (a > 0)
602 {
603 // TODO: registry handles
604 switch (it.ammo_type)
605 {
606 case RES_SHELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
607 case RES_BULLETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
608 case RES_ROCKETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
609 case RES_CELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
610 case RES_FUEL: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
611 default: ammo_full = 60;
612 }
613
615 weapon_pos.x + baroffset.x,
616 weapon_pos.y + baroffset.y,
617 barsize.x * bound(0, a / ammo_full, 1),
618 barsize.y
619 );
620
622 weapon_pos,
623 "weapon_ammo",
624 weapon_size,
625 ammo_color,
626 ammo_alpha,
628 );
629
631 }
632 }
633 }
634 else // draw a "ghost weapon icon" if you don't have the weapon
635 drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '0.2 0.2 0.2', weapon_alpha_real * 0.5, DRAWFLAG_NORMAL);
636
637 // draw the complain message
638 if (it == complain_weapon)
639 {
640 float a = fadetime
641 ? ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1))
642 : ((complain_weapon_time + when > time) ? 1 : 0);
643
644 string s;
645 if (complain_weapon_type == 0)
646 {
647 s = _("Out of ammo");
649 }
650 else if (complain_weapon_type == 1)
651 {
652 s = _("Don't have");
654 }
655 else
656 {
657 s = _("Unavailable");
659 }
661 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
662 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
663 }
664
665 #if 0
668 {
669 drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
670 drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
671 }
672 #endif
673
674 // continue with new position for the next weapon
675 if (vertical_order)
676 {
677 ++column;
678 if (column >= columns)
679 {
680 column = 0;
681 ++row;
682 }
683 }
684 else
685 {
686 ++row;
687 if (row >= rows)
688 {
689 row = 0;
690 ++column;
691 }
692 }
693 }
694}
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:109
#define drawsetcliparea(xposition, yposition, w, h)
Definition draw.qh:39
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
#define getcommandkey(cmd_name, command)
Definition main.qh:137
const int IT_UNLIMITED_AMMO
Definition item.qh:23
string strtolower(string s)
const float DRAWFLAG_NORMAL
float frametime
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
float panel_fg_alpha
Definition hud.qh:169
int complain_weapon_type
Definition hud.qh:114
int weapon_accuracy[REGISTRY_MAX(Weapons)]
Definition hud.qh:111
void drawresetcliparea(void)
float bound(float min, float value, float max)
float fabs(float f)
#define vec2(...)
Definition vector.qh:90
int GetAmmoStat(Resource ammotype)
Definition all.qc:211
vector Accuracy_GetColor(float accuracy)
Definition weapons.qc:64
void Accuracy_LoadColors()
Definition weapons.qc:54
float autocvar_hud_panel_weapons_selection_radius
Definition weapons.qh:29
float autocvar_hud_panel_weapons_ammo_alpha
Definition weapons.qh:7
bool autocvar_hud_panel_weapons_ammo
Definition weapons.qh:6
int autocvar_hud_panel_weapons_ammo_full_nails
Definition weapons.qh:11
int autocvar_hud_panel_weapons_ammo_full_fuel
Definition weapons.qh:10
bool autocvar_hud_panel_weapons_accuracy
Definition weapons.qh:5
float autocvar_hud_panel_weapons_label_scale
Definition weapons.qh:25
string autocvar_hud_panel_weapons_ammo_color
Definition weapons.qh:8
int autocvar_hud_panel_weapons_ammo_full_shells
Definition weapons.qh:13
float autocvar_hud_panel_weapons_complainbubble_padding
Definition weapons.qh:20
int autocvar_hud_panel_weapons_label
Definition weapons.qh:24
string autocvar_hud_panel_weapons_complainbubble_color_outofammo
Definition weapons.qh:17
bool autocvar_hud_panel_weapons_dynamichud
Definition weapons.qh:22
int autocvar_hud_panel_weapons_ammo_full_cells
Definition weapons.qh:9
string autocvar_hud_panel_weapons_complainbubble_color_donthave
Definition weapons.qh:16
float autocvar_hud_panel_weapons_selection_speed
Definition weapons.qh:30
int autocvar_hud_panel_weapons_ammo_full_rockets
Definition weapons.qh:12
float autocvar_hud_panel_weapons_noncurrent_scale
Definition weapons.qh:28
string autocvar_hud_panel_weapons_complainbubble_color_unavailable
Definition weapons.qh:18
float autocvar_hud_panel_weapons_noncurrent_alpha
Definition weapons.qh:27

References Accuracy_GetColor(), Accuracy_LoadColors(), autocvar__hud_configure, 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_rockets, autocvar_hud_panel_weapons_ammo_full_shells, autocvar_hud_panel_weapons_complainbubble_color_donthave, autocvar_hud_panel_weapons_complainbubble_color_outofammo, autocvar_hud_panel_weapons_complainbubble_color_unavailable, autocvar_hud_panel_weapons_complainbubble_padding, autocvar_hud_panel_weapons_dynamichud, 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_selection_radius, autocvar_hud_panel_weapons_selection_speed, bound(), color, complain_weapon, complain_weapon_time, complain_weapon_type, drawfill, DRAWFLAG_NORMAL, drawpic_aspect_skin, drawresetcliparea(), drawsetcliparea, drawstring, drawstring_aspect(), entity(), fabs(), fadetime, frametime, ftos(), GetAmmoStat(), getcommandkey, HUD_Panel_DrawBg, HUD_Scale_Disable(), HUD_Scale_Enable(), HUD_WEAPONS_GET_FULL_LAYOUT, IT_UNLIMITED_AMMO, max(), min(), panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, STAT, stov(), strcat(), strtolower(), time, vec2, vector, weapon_accuracy, weaponorder, WEP_FIRST, WEP_FLAG_HIDDEN, WEP_FLAG_MUTATORBLOCKED, WEP_LAST, and WepSet_FromWeapon.

◆ Weapons_Fade()

void Weapons_Fade ( vector center)

Definition at line 316 of file weapons.qc.

317{
319 return;
320
322 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
323 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
324
325 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
326 {
327 float f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
328
329 // fade the panel alpha
331 {
334 }
336 {
337 panel_bg_alpha *= (1 - f);
338 panel_fg_alpha *= (1 - f);
339 }
340
341 // 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 float 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 float 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
387 {
388 f *= f; // for a cooler movement
389 f = 1 - f;
390 center.x = panel_pos.x + panel_size.x / 2;
391 center.y = panel_pos.y + panel_size.y / 2;
392 float screen_ar = vid_conwidth / vid_conheight;
393 if (center.x / center.y < screen_ar) // bottom left
394 {
395 if ((vid_conwidth - center.x) / center.y < screen_ar) // bottom
396 panel_pos.y += f * (vid_conheight - panel_pos.y);
397 else // left
398 panel_pos.x -= f * (panel_pos.x + panel_size.x);
399 }
400 else // top right
401 {
402 if ((vid_conwidth - center.x) / center.y < screen_ar) // right
403 panel_pos.x += f * (vid_conwidth - panel_pos.x);
404 else // top
405 panel_pos.y -= f * (panel_pos.y + panel_size.y);
406 }
407 }
408 }
409}
float panel_bg_alpha
Definition hud.qh:170
float autocvar_hud_panel_weapons_timeout_speed_in
Definition weapons.qh:36

References autocvar__hud_configure, 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(), panel_bg_alpha, panel_fg_alpha, panel_pos, panel_size, time, vector, vid_conheight, vid_conwidth, weaponprevtime, and weapontime.

Variable Documentation

◆ cl_weaponpriority_old

string cl_weaponpriority_old

Definition at line 115 of file weapons.qc.

Referenced by HUD_Weapons().

◆ weaponorder

◆ weaponorder_cmp_str

string weaponorder_cmp_str

Definition at line 90 of file weapons.qc.

Referenced by HUD_Weapons(), and weaponorder_cmp().

◆ weapons_orderbyimpulse_old

bool weapons_orderbyimpulse_old

Definition at line 116 of file weapons.qc.

Referenced by HUD_Weapons().