Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 (bool should_draw)
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.

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 += (mySize - mySize * scale) * 0.5;
56 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) textColor = '0.2 0.95 0';
76 else if (isShadowed) textColor = '0 0 0';
77 else if (ammo < 10) textColor = '0.8 0.04 0';
78 else textColor = '1 1 1';
79
80 float alpha;
81 if (isCurrent)
83 else if (isShadowed)
85 else
87
88 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
89
90 // Draw item
91
92 if (isCurrent)
93 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
94
97
99 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor * 0.6 + ammoType.m_color * 0.4, alpha, DRAWFLAG_NORMAL);
100
101 drawpic_aspect_skin(iconPos, ammoType.m_icon, '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
102}
string m_icon
Definition resources.qh:32
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:109
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78
bool autocvar_hud_panel_ammo_text
Definition ammo.qh:15
bool autocvar_hud_panel_ammo_progressbar
Definition ammo.qh:12
int autocvar_hud_panel_ammo_maxammo
Definition ammo.qh:8
bool autocvar_hud_panel_ammo_iconalign
Definition ammo.qh:7
string autocvar_hud_panel_ammo_progressbar_name
Definition ammo.qh:13
float autocvar_hud_panel_ammo_noncurrent_alpha
Definition ammo.qh:10
float autocvar_hud_panel_ammo_noncurrent_scale
Definition ammo.qh:11
float autocvar_hud_panel_ammo_progressbar_xoffset
Definition ammo.qh:14
float alpha
Definition items.qc:13
const float DRAWFLAG_NORMAL
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:269
float autocvar_hud_progressbar_alpha
Definition hud.qh:204
float panel_fg_alpha
Definition hud.qh:169
bool autocvar__hud_configure
Definition hud_config.qh:3
#define TC(T, sym)
Definition _all.inc:82
float bound(float min, float value, float max)
string ftos(float f)
float scale
Definition projectile.qc:14
vector
Definition self.qh:92
float ammo
Definition sv_turrets.qh:43
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44
int GetAmmoStat(Resource ammotype)
Definition all.qc:211

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(), GetAmmoStat(), HUD_Panel_DrawProgressBar(), Resource::m_icon, panel_fg_alpha, scale, TC, and vector.

Referenced by HUD_Ammo().

◆ DrawNadeProgressBar()

◆ HUD_Ammo()

void HUD_Ammo ( bool should_draw)

Definition at line 108 of file ammo.qc.

109{
110 if (!should_draw)
111 return;
112 if (hud != HUD_NORMAL)
113 return;
115 {
117 return;
118 if (STAT(HEALTH) <= 0 && autocvar_hud_panel_ammo_hide_ondeath)
119 return;
120 }
121
123
125
126 vector pos = panel_pos;
127 vector mySize = panel_size;
128
131 else
135 {
136 pos += '1 1 0' * panel_bg_padding;
137 mySize -= '2 2 0' * panel_bg_padding;
138 }
139
140 int rows = 0, columns, row, column;
141 float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
142 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
143 float nade_statuschange_elapsedtime;
144 int total_ammo_count;
145
146 vector ammo_size;
148 total_ammo_count = 1;
149 else
150 total_ammo_count = AMMO_COUNT;
151
152 if (draw_nades)
153 {
154 ++total_ammo_count;
155 if (nade_cnt != nade_prevframe)
156 {
159 nade_prevframe = nade_cnt;
160 }
161 }
162 else
164
165 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
166 columns = ceil(total_ammo_count / rows);
167 ammo_size = vec2(mySize.x / columns, mySize.y / rows);
168
169 vector offset = '0 0 0';
170 float newSize;
171 if (ammo_size.x / ammo_size.y > 3)
172 {
173 newSize = 3 * ammo_size.y;
174 offset.x = ammo_size.x - newSize;
175 pos.x += offset.x * 0.5;
176 ammo_size.x = newSize;
177 }
178 else
179 {
180 newSize = 1/3 * ammo_size.x;
181 offset.y = ammo_size.y - newSize;
182 pos.y += offset.y * 0.5;
183 ammo_size.y = newSize;
184 }
185
186 entity wepent = viewmodels[0]; // TODO: unhardcode
187
188 Weapon wep = wepent.switchweapon;
189 int i;
190 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
191 row = column = 0;
193 {
195 DrawAmmoItem(pos, ammo_size, RES_ROCKETS, true, false);
196 else
198 pos,
199 ammo_size,
200 wep.ammo_type,
201 true,
202 infinite_ammo
203 );
204
205 ++row;
206 if (row >= rows)
207 {
208 row = 0;
209 ++column;
210 }
211 }
212 else
213 {
214 row = column = 0;
215 IL_EACH(default_order_resources, it.instanceOfAmmoResource && !it.m_hidden,
216 {
217 DrawAmmoItem(
218 pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
219 ammo_size,
220 it,
221 (wep.ammo_type == it),
222 infinite_ammo
223 );
224
225 ++row;
226 if (row >= rows)
227 {
228 row = 0;
229 ++column;
230 }
231 });
232 }
233
234 if (draw_nades)
235 {
236 nade_statuschange_elapsedtime = time - nade_statuschange_time;
237
238 float f = bound(0, nade_statuschange_elapsedtime * 2, 1);
239 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);
240 }
241
243}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
Definition cl_nades.qc:86
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:56
#define draw_beginBoldFont()
Definition draw.qh:4
#define draw_endBoldFont()
Definition draw.qh:5
int nade_prevstatus
Definition ammo.qc:104
void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent, bool isInfinite)
Definition ammo.qc:35
int nade_prevframe
Definition ammo.qc:105
float nade_statuschange_time
Definition ammo.qc:106
bool autocvar_hud_panel_ammo
Definition ammo.qh:4
bool autocvar_hud_panel_ammo_hide_ondeath
Definition ammo.qh:6
bool autocvar_hud_panel_ammo_dynamichud
Definition ammo.qh:5
bool autocvar_hud_panel_ammo_onlycurrent
Definition ammo.qh:9
const int AMMO_COUNT
Definition items.qh:3
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197
int hud
Definition main.qh:173
const int IT_UNLIMITED_AMMO
Definition item.qh:23
const int HUD_NORMAL
Definition constants.qh:47
float time
void HUD_Panel_LoadCvars()
Definition hud.qc:215
float HUD_GetRowCount(int item_count, vector size, float item_aspect)
Definition hud.qc:165
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
vector panel_size
Definition hud.qh:163
float panel_bg_padding
Definition hud.qh:174
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
#define IL_EACH(this, cond, body)
#define STAT(...)
Definition stats.qh:82
float ceil(float f)
IntrusiveList default_order_resources
Definition resources.qh:42
#define vec2(...)
Definition vector.qh:90
entity viewmodels[MAX_WEAPONSLOTS]
Definition view.qh:108

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, ceil(), default_order_resources, draw_beginBoldFont, DrawAmmoItem(), entity(), hud, HUD_GetRowCount(), HUD_NORMAL, HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), IL_EACH, IT_UNLIMITED_AMMO, nade_prevframe, nade_prevstatus, nade_statuschange_time, panel_bg_padding, panel_pos, panel_size, spectatee_status, STAT, time, vec2, vector, and viewmodels.

◆ HUD_Ammo_Export()

void HUD_Ammo_Export ( int fh)

Definition at line 12 of file ammo.qc.

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

References HUD_Write_Cvar.

Variable Documentation

◆ nade_prevframe

int nade_prevframe

Definition at line 105 of file ammo.qc.

Referenced by HUD_Ammo().

◆ nade_prevstatus

int nade_prevstatus

Definition at line 104 of file ammo.qc.

Referenced by HUD_Ammo().

◆ nade_statuschange_time

float nade_statuschange_time

Definition at line 106 of file ammo.qc.

Referenced by HUD_Ammo().