Xonotic
ammo.qc File Reference
+ Include dependency graph for ammo.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void DrawAmmoItem (vector myPos, vector mySize, Resource ammoType, bool isCurrent, bool isInfinite)
 
void DrawNadeProgressBar (vector myPos, vector mySize, float progress, vector color)
 
void HUD_Ammo ()
 
void HUD_Ammo_Export (int fh)
 

Variables

int nade_prevframe
 
int nade_prevstatus
 
float nade_statuschange_time
 

Function Documentation

◆ DrawAmmoItem()

void DrawAmmoItem ( vector  myPos,
vector  mySize,
Resource  ammoType,
bool  isCurrent,
bool  isInfinite 
)

Definition at line 35 of file ammo.qc.

References alpha, ammo, autocvar__hud_configure, autocvar_hud_panel_ammo_iconalign, autocvar_hud_panel_ammo_maxammo, autocvar_hud_panel_ammo_noncurrent_alpha, autocvar_hud_panel_ammo_noncurrent_scale, autocvar_hud_panel_ammo_progressbar, autocvar_hud_panel_ammo_progressbar_name, autocvar_hud_panel_ammo_progressbar_xoffset, autocvar_hud_panel_ammo_text, autocvar_hud_progressbar_alpha, bound(), DRAWFLAG_NORMAL, drawpic_aspect_skin, drawstring_aspect(), eX, eY, ftos(), GetAmmoPicture(), HUD_Panel_DrawProgressBar(), panel_fg_alpha, scale, TC, and vector().

Referenced by HUD_Ammo().

36 {
37  TC(bool, isCurrent); TC(bool, isInfinite);
38  if(ammoType == RES_NONE)
39  return;
40 
41  // Initialize variables
42 
43  int ammo;
45  {
46  isCurrent = (ammoType == RES_ROCKETS); // Rockets always current
47  ammo = 60;
48  }
49  else
50  ammo = getstati(GetAmmoStat(ammoType));
51 
52  if(!isCurrent)
53  {
55  myPos = myPos + (mySize - mySize * scale) * 0.5;
56  mySize = mySize * scale;
57  }
58 
59  vector iconPos, textPos;
61  {
62  iconPos = myPos + eX * 2 * mySize.y;
63  textPos = myPos;
64  }
65  else
66  {
67  iconPos = myPos;
68  textPos = myPos + eX * mySize.y;
69  }
70 
71  bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
72 
73  vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
74  vector textColor;
75  if(isInfinite)
76  textColor = '0.2 0.95 0';
77  else if(isShadowed)
78  textColor = '0 0 0';
79  else if(ammo < 10)
80  textColor = '0.8 0.04 0';
81  else
82  textColor = '1 1 1';
83 
84  float alpha;
85  if(isCurrent)
86  alpha = panel_fg_alpha;
87  else if(isShadowed)
89  else
91 
92  string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
93 
94  // Draw item
95 
96  if(isCurrent)
97  drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
98 
100  HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, autocvar_hud_panel_ammo_progressbar_name, ammo/autocvar_hud_panel_ammo_maxammo, 0, 0, textColor, autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL);
101 
103  drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
104 
105  drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
106 }
bool autocvar_hud_panel_ammo_progressbar
Definition: ammo.qh:12
bool autocvar_hud_panel_ammo_iconalign
Definition: ammo.qh:7
float alpha
Definition: items.qc:14
float panel_fg_alpha
Definition: hud.qh:166
void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
Definition: hud.qc:270
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
const vector eY
Definition: vector.qh:45
string GetAmmoPicture(Resource ammotype)
Definition: all.qc:206
bool autocvar__hud_configure
Definition: hud_config.qh:3
bool autocvar_hud_panel_ammo_text
Definition: ammo.qh:15
float autocvar_hud_panel_ammo_progressbar_xoffset
Definition: ammo.qh:14
float ammo
Definition: sv_turrets.qh:44
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
#define TC(T, sym)
Definition: _all.inc:82
int autocvar_hud_panel_ammo_maxammo
Definition: ammo.qh:8
float scale
Definition: projectile.qc:14
vector(float skel, float bonenum) _skel_get_boneabs_hidden
string autocvar_hud_panel_ammo_progressbar_name
Definition: ammo.qh:13
const vector eX
Definition: vector.qh:44
float autocvar_hud_panel_ammo_noncurrent_alpha
Definition: ammo.qh:10
float autocvar_hud_progressbar_alpha
Definition: hud.qh:201
float autocvar_hud_panel_ammo_noncurrent_scale
Definition: ammo.qh:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawNadeProgressBar()

void DrawNadeProgressBar ( vector  myPos,
vector  mySize,
float  progress,
vector  color 
)

Definition at line 25 of file ammo.qc.

References autocvar_hud_panel_ammo_progressbar_name, autocvar_hud_panel_ammo_progressbar_xoffset, autocvar_hud_progressbar_alpha, DRAWFLAG_NORMAL, eX, HUD_Panel_DrawProgressBar(), and panel_fg_alpha.

26 {
29  mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
31  progress, 0, 0, color,
33 }
vector color
float panel_fg_alpha
Definition: hud.qh:166
void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
Definition: hud.qc:270
float autocvar_hud_panel_ammo_progressbar_xoffset
Definition: ammo.qh:14
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
string autocvar_hud_panel_ammo_progressbar_name
Definition: ammo.qh:13
const vector eX
Definition: vector.qh:44
float autocvar_hud_progressbar_alpha
Definition: hud.qh:201
+ Here is the call graph for this function:

◆ HUD_Ammo()

void HUD_Ammo ( )

Definition at line 112 of file ammo.qc.

References AMMO_COUNT, Weapon::ammo_type, autocvar__hud_configure, autocvar_hud_panel_ammo, autocvar_hud_panel_ammo_dynamichud, autocvar_hud_panel_ammo_hide_ondeath, autocvar_hud_panel_ammo_onlycurrent, bound(), ceil(), draw_beginBoldFont, draw_endBoldFont, DrawAmmoItem(), entity(), hud, HUD_GetRowCount(), HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), nade_prevframe, nade_prevstatus, nade_statuschange_time, panel_bg_padding, panel_pos, panel_size, spectatee_status, time, vec2, vector(), and viewmodels.

113 {
114  if(hud != HUD_NORMAL) return;
116  {
117  if((!autocvar_hud_panel_ammo) || (spectatee_status == -1))
118  return;
119  if(STAT(HEALTH) <= 0 && autocvar_hud_panel_ammo_hide_ondeath)
120  return;
121  }
122 
124 
126 
127  vector pos, mySize;
128  pos = panel_pos;
129  mySize = panel_size;
130 
133  else
136  if(panel_bg_padding)
137  {
138  pos += '1 1 0' * panel_bg_padding;
139  mySize -= '2 2 0' * panel_bg_padding;
140  }
141 
142  int rows = 0, columns, row, column;
143  float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
144  bool draw_nades = (nade_cnt > 0 || nade_score > 0);
145  float nade_statuschange_elapsedtime;
146  int total_ammo_count;
147 
148  vector ammo_size;
150  total_ammo_count = 1;
151  else
152  total_ammo_count = AMMO_COUNT;
153 
154  if(draw_nades)
155  {
156  ++total_ammo_count;
157  if (nade_cnt != nade_prevframe)
158  {
161  nade_prevframe = nade_cnt;
162  }
163  }
164  else
166 
167  rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
168  columns = ceil((total_ammo_count)/rows);
169  ammo_size = vec2(mySize.x / columns, mySize.y / rows);
170 
171  vector offset = '0 0 0';
172  float newSize;
173  if(ammo_size.x/ammo_size.y > 3)
174  {
175  newSize = 3 * ammo_size.y;
176  offset.x = ammo_size.x - newSize;
177  pos.x += offset.x/2;
178  ammo_size.x = newSize;
179  }
180  else
181  {
182  newSize = 1/3 * ammo_size.x;
183  offset.y = ammo_size.y - newSize;
184  pos.y += offset.y/2;
185  ammo_size.y = newSize;
186  }
187 
188  entity wepent = viewmodels[0]; // TODO: unhardcode
189 
190  Weapon wep = wepent.switchweapon;
191  int i;
192  bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
193  row = column = 0;
195  {
197  {
198  DrawAmmoItem(pos, ammo_size, RES_ROCKETS, true, false);
199  }
200  else
201  {
202  DrawAmmoItem(
203  pos,
204  ammo_size,
205  wep.ammo_type,
206  true,
207  infinite_ammo
208  );
209  }
210 
211  ++row;
212  if(row >= rows)
213  {
214  row = 0;
215  column = column + 1;
216  }
217  }
218  else
219  {
220  row = column = 0;
221  // disabling new-style loop for now to restore original order of ammo types
222  //FOREACH(Resources, it.instanceOfAmmoResource && !it.m_hidden,
223  for(int j = 0; j < AMMO_COUNT; ++j)
224  {
225  Resource ammotype = GetAmmoTypeFromNum(j);
226  DrawAmmoItem(
227  pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
228  ammo_size,
229  ammotype,
230  (wep.ammo_type == ammotype),
231  infinite_ammo
232  );
233 
234  ++row;
235  if(row >= rows)
236  {
237  row = 0;
238  column = column + 1;
239  }
240  }
241  }
242 
243  if (draw_nades)
244  {
245  nade_statuschange_elapsedtime = time - nade_statuschange_time;
246 
247  float f = bound(0, nade_statuschange_elapsedtime*2, 1);
248 
249  DrawAmmoNades(pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)), ammo_size, nade_prevstatus < nade_cnt && nade_cnt != 0 && f < 1, f);
250  }
251 
253 }
bool autocvar_hud_panel_ammo_onlycurrent
Definition: ammo.qh:9
#define draw_endBoldFont()
Definition: draw.qh:5
bool autocvar_hud_panel_ammo
Definition: ammo.qh:4
float HUD_GetRowCount(int item_count, vector size, float item_aspect)
Definition: hud.qc:165
bool autocvar__hud_configure
Definition: hud_config.qh:3
#define draw_beginBoldFont()
Definition: draw.qh:4
entity viewmodels[MAX_WEAPONSLOTS]
Definition: view.qh:104
vector panel_size
Definition: hud.qh:160
entity() spawn
void HUD_Scale_Disable()
Definition: hud.qc:83
bool autocvar_hud_panel_ammo_hide_ondeath
Definition: ammo.qh:6
const int AMMO_COUNT
Definition: items.qh:3
bool autocvar_hud_panel_ammo_dynamichud
Definition: ammo.qh:5
int nade_prevframe
Definition: ammo.qc:109
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
void HUD_Scale_Enable()
Definition: hud.qc:90
int nade_prevstatus
Definition: ammo.qc:108
Resource ammo_type
M: ammotype : main ammo type.
Definition: weapon.qh:48
void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent, bool isInfinite)
Definition: ammo.qc:35
vector panel_pos
Definition: hud.qh:159
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float nade_statuschange_time
Definition: ammo.qc:110
float spectatee_status
Definition: main.qh:166
#define vec2(...)
Definition: vector.qh:90
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
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_Ammo_Export()

void HUD_Ammo_Export ( int  fh)

Definition at line 12 of file ammo.qc.

References HUD_Write_Cvar.

13 {
14  // allow saving cvars that aesthetically change the panel into hud skin files
15  HUD_Write_Cvar("hud_panel_ammo_onlycurrent");
16  HUD_Write_Cvar("hud_panel_ammo_noncurrent_alpha");
17  HUD_Write_Cvar("hud_panel_ammo_noncurrent_scale");
18  HUD_Write_Cvar("hud_panel_ammo_iconalign");
19  HUD_Write_Cvar("hud_panel_ammo_progressbar");
20  HUD_Write_Cvar("hud_panel_ammo_progressbar_name");
21  HUD_Write_Cvar("hud_panel_ammo_progressbar_xoffset");
22  HUD_Write_Cvar("hud_panel_ammo_text");
23 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38

Variable Documentation

◆ nade_prevframe

int nade_prevframe

Definition at line 109 of file ammo.qc.

Referenced by HUD_Ammo().

◆ nade_prevstatus

int nade_prevstatus

Definition at line 108 of file ammo.qc.

Referenced by HUD_Ammo().

◆ nade_statuschange_time

float nade_statuschange_time

Definition at line 110 of file ammo.qc.

Referenced by HUD_Ammo().