Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
weapons.qh File Reference
#include "../panel.qh"
Include dependency graph for weapons.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vector Accuracy_GetColor (float accuracy)
void Accuracy_LoadColors ()
void Accuracy_LoadLevels ()
void Weapons_Draw (entity, WepSet, vector, vector, float, float, int, int, float, bool)
void Weapons_Fade (vector)

Variables

vector acc_col [MAX_ACCURACY_LEVELS]
float acc_col_loadtime
string acc_color_levels
float acc_lev [MAX_ACCURACY_LEVELS]
int acc_levels
string autocvar_accuracy_color_levels
string autocvar_cl_weaponpriority
bool autocvar_hud_panel_weapons
bool autocvar_hud_panel_weapons_accuracy
bool autocvar_hud_panel_weapons_ammo
float autocvar_hud_panel_weapons_ammo_alpha
string autocvar_hud_panel_weapons_ammo_color
int autocvar_hud_panel_weapons_ammo_full_cells
int autocvar_hud_panel_weapons_ammo_full_fuel
int autocvar_hud_panel_weapons_ammo_full_nails
int autocvar_hud_panel_weapons_ammo_full_rockets
int autocvar_hud_panel_weapons_ammo_full_shells
float autocvar_hud_panel_weapons_aspect
bool autocvar_hud_panel_weapons_complainbubble
string autocvar_hud_panel_weapons_complainbubble_color_donthave
string autocvar_hud_panel_weapons_complainbubble_color_outofammo
string autocvar_hud_panel_weapons_complainbubble_color_unavailable
float autocvar_hud_panel_weapons_complainbubble_fadetime
float autocvar_hud_panel_weapons_complainbubble_padding
float autocvar_hud_panel_weapons_complainbubble_time
bool autocvar_hud_panel_weapons_dynamichud = true
bool autocvar_hud_panel_weapons_hide_ondeath = false
int autocvar_hud_panel_weapons_label
float autocvar_hud_panel_weapons_label_scale = 0.5
float autocvar_hud_panel_weapons_noncurrent_alpha = 1
float autocvar_hud_panel_weapons_noncurrent_scale = 1
int autocvar_hud_panel_weapons_onlyowned
bool autocvar_hud_panel_weapons_orderbyimpulse = true
float autocvar_hud_panel_weapons_selection_radius = 0
float autocvar_hud_panel_weapons_selection_speed = 10
float autocvar_hud_panel_weapons_timeout
int autocvar_hud_panel_weapons_timeout_effect
float autocvar_hud_panel_weapons_timeout_fadebgmin
float autocvar_hud_panel_weapons_timeout_fadefgmin
float autocvar_hud_panel_weapons_timeout_speed_in = 0.25
float autocvar_hud_panel_weapons_timeout_speed_out = 0.75
const int MAX_ACCURACY_LEVELS = 10

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
vector
Definition self.qh:92
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().

◆ Weapons_Draw()

void Weapons_Draw ( entity ,
WepSet ,
vector ,
vector ,
float ,
float ,
int ,
int ,
float ,
bool  )

References entity(), and vector.

◆ Weapons_Fade()

void Weapons_Fade ( vector center)

Definition at line 314 of file weapons.qc.

315{
317 return;
318
320 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
321 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
322
323 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
324 {
325 float f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
326
327 // fade the panel alpha
329 {
332 }
334 {
335 panel_bg_alpha *= (1 - f);
336 panel_fg_alpha *= (1 - f);
337 }
338
339 // move the panel off the screen
342 {
343 f *= f; // for a cooler movement
344 center.x = panel_pos.x + panel_size.x / 2;
345 center.y = panel_pos.y + panel_size.y / 2;
346 float screen_ar = vid_conwidth / vid_conheight;
347 if (center.x / center.y < screen_ar) // bottom left
348 {
349 if ((vid_conwidth - center.x) / center.y < screen_ar) // bottom
350 panel_pos.y += f * (vid_conheight - panel_pos.y);
351 else // left
352 panel_pos.x -= f * (panel_pos.x + panel_size.x);
353 }
354 else // top right
355 {
356 if ((vid_conwidth - center.x) / center.y < screen_ar) // right
357 panel_pos.x += f * (vid_conwidth - panel_pos.x);
358 else // top
359 panel_pos.y -= f * (panel_pos.y + panel_size.y);
360 }
361 if (f == 1)
362 center.x = -1; // mark the panel as off screen
363 }
364 weaponprevtime = time - (1 - f) * timein_effect_length;
365 }
366 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
367 {
368 float f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
369
370 // fade the panel alpha
372 {
375 }
377 {
378 panel_bg_alpha *= f;
379 panel_fg_alpha *= f;
380 }
381
382 // move the panel back on screen
385 {
386 f *= f; // for a cooler movement
387 f = 1 - f;
388 center.x = panel_pos.x + panel_size.x / 2;
389 center.y = panel_pos.y + panel_size.y / 2;
390 float screen_ar = vid_conwidth / vid_conheight;
391 if (center.x / center.y < screen_ar) // bottom left
392 {
393 if ((vid_conwidth - center.x) / center.y < screen_ar) // bottom
394 panel_pos.y += f * (vid_conheight - panel_pos.y);
395 else // left
396 panel_pos.x -= f * (panel_pos.x + panel_size.x);
397 }
398 else // top right
399 {
400 if ((vid_conwidth - center.x) / center.y < screen_ar) // right
401 panel_pos.x += f * (vid_conwidth - panel_pos.x);
402 else // top
403 panel_pos.y -= f * (panel_pos.y + panel_size.y);
404 }
405 }
406 }
407}
vector panel_size
Definition hud.qh:163
float panel_fg_alpha
Definition hud.qh:169
float weaponprevtime
Definition hud.qh:123
vector panel_pos
Definition hud.qh:162
float panel_bg_alpha
Definition hud.qh:170
float weapontime
Definition hud.qh:122
bool autocvar__hud_configure
Definition hud_config.qh:3
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
float bound(float min, float value, float max)
float autocvar_hud_panel_weapons_timeout_fadefgmin
Definition weapons.qh:35
float autocvar_hud_panel_weapons_timeout_fadebgmin
Definition weapons.qh:34
float autocvar_hud_panel_weapons_timeout_speed_out
Definition weapons.qh:37
int autocvar_hud_panel_weapons_timeout_effect
Definition weapons.qh:32
float autocvar_hud_panel_weapons_timeout_speed_in
Definition weapons.qh:36
float autocvar_hud_panel_weapons_timeout
Definition weapons.qh:31

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

◆ acc_col

Definition at line 44 of file weapons.qh.

Referenced by Accuracy_GetColor(), and Accuracy_LoadColors().

◆ acc_col_loadtime

float acc_col_loadtime

Definition at line 45 of file weapons.qh.

Referenced by Accuracy_LoadColors().

◆ acc_color_levels

string acc_color_levels

Definition at line 47 of file weapons.qh.

Referenced by Accuracy_LoadLevels().

◆ acc_lev

Definition at line 43 of file weapons.qh.

Referenced by Accuracy_GetColor(), and Accuracy_LoadLevels().

◆ acc_levels

int acc_levels

Definition at line 46 of file weapons.qh.

Referenced by Accuracy_GetColor(), Accuracy_LoadColors(), and Accuracy_LoadLevels().

◆ autocvar_accuracy_color_levels

string autocvar_accuracy_color_levels

Definition at line 39 of file weapons.qh.

Referenced by Accuracy_LoadLevels().

◆ autocvar_cl_weaponpriority

string autocvar_cl_weaponpriority

Definition at line 40 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons

bool autocvar_hud_panel_weapons

Definition at line 4 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_accuracy

bool autocvar_hud_panel_weapons_accuracy

Definition at line 5 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo

bool autocvar_hud_panel_weapons_ammo

Definition at line 6 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_alpha

float autocvar_hud_panel_weapons_ammo_alpha

Definition at line 7 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_color

string autocvar_hud_panel_weapons_ammo_color

Definition at line 8 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_full_cells

int autocvar_hud_panel_weapons_ammo_full_cells

Definition at line 9 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_full_fuel

int autocvar_hud_panel_weapons_ammo_full_fuel

Definition at line 10 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_full_nails

int autocvar_hud_panel_weapons_ammo_full_nails

Definition at line 11 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_full_rockets

int autocvar_hud_panel_weapons_ammo_full_rockets

Definition at line 12 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_ammo_full_shells

int autocvar_hud_panel_weapons_ammo_full_shells

Definition at line 13 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_aspect

float autocvar_hud_panel_weapons_aspect

Definition at line 14 of file weapons.qh.

Referenced by Scoreboard_AccuracyStats_Draw().

◆ autocvar_hud_panel_weapons_complainbubble

bool autocvar_hud_panel_weapons_complainbubble

Definition at line 15 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_complainbubble_color_donthave

string autocvar_hud_panel_weapons_complainbubble_color_donthave

Definition at line 16 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_complainbubble_color_outofammo

string autocvar_hud_panel_weapons_complainbubble_color_outofammo

Definition at line 17 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_complainbubble_color_unavailable

string autocvar_hud_panel_weapons_complainbubble_color_unavailable

Definition at line 18 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_complainbubble_fadetime

float autocvar_hud_panel_weapons_complainbubble_fadetime

Definition at line 19 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_complainbubble_padding

float autocvar_hud_panel_weapons_complainbubble_padding

Definition at line 20 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_complainbubble_time

float autocvar_hud_panel_weapons_complainbubble_time

Definition at line 21 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_dynamichud

bool autocvar_hud_panel_weapons_dynamichud = true

Definition at line 22 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_hide_ondeath

bool autocvar_hud_panel_weapons_hide_ondeath = false

Definition at line 23 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_label

int autocvar_hud_panel_weapons_label

Definition at line 24 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_label_scale

float autocvar_hud_panel_weapons_label_scale = 0.5

Definition at line 25 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_noncurrent_alpha

float autocvar_hud_panel_weapons_noncurrent_alpha = 1

Definition at line 27 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_noncurrent_scale

float autocvar_hud_panel_weapons_noncurrent_scale = 1

Definition at line 28 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_onlyowned

int autocvar_hud_panel_weapons_onlyowned

Definition at line 26 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_orderbyimpulse

bool autocvar_hud_panel_weapons_orderbyimpulse = true

Definition at line 33 of file weapons.qh.

Referenced by HUD_Weapons().

◆ autocvar_hud_panel_weapons_selection_radius

float autocvar_hud_panel_weapons_selection_radius = 0

Definition at line 29 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_selection_speed

float autocvar_hud_panel_weapons_selection_speed = 10

Definition at line 30 of file weapons.qh.

Referenced by Weapons_Draw().

◆ autocvar_hud_panel_weapons_timeout

float autocvar_hud_panel_weapons_timeout

Definition at line 31 of file weapons.qh.

Referenced by HUD_Weapons(), and Weapons_Fade().

◆ autocvar_hud_panel_weapons_timeout_effect

int autocvar_hud_panel_weapons_timeout_effect

Definition at line 32 of file weapons.qh.

Referenced by HUD_Weapons(), and Weapons_Fade().

◆ autocvar_hud_panel_weapons_timeout_fadebgmin

float autocvar_hud_panel_weapons_timeout_fadebgmin

Definition at line 34 of file weapons.qh.

Referenced by HUD_Weapons(), and Weapons_Fade().

◆ autocvar_hud_panel_weapons_timeout_fadefgmin

float autocvar_hud_panel_weapons_timeout_fadefgmin

Definition at line 35 of file weapons.qh.

Referenced by HUD_Weapons(), and Weapons_Fade().

◆ autocvar_hud_panel_weapons_timeout_speed_in

float autocvar_hud_panel_weapons_timeout_speed_in = 0.25

Definition at line 36 of file weapons.qh.

Referenced by Weapons_Fade().

◆ autocvar_hud_panel_weapons_timeout_speed_out

float autocvar_hud_panel_weapons_timeout_speed_out = 0.75

Definition at line 37 of file weapons.qh.

Referenced by HUD_Weapons(), and Weapons_Fade().

◆ MAX_ACCURACY_LEVELS

const int MAX_ACCURACY_LEVELS = 10

Definition at line 42 of file weapons.qh.

Referenced by Accuracy_LoadLevels().