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

Go to the source code of this file.

Functions

void HUD_HealthArmor ()
 
void HUD_HealthArmor_Export (int fh)
 

Function Documentation

◆ HUD_HealthArmor()

void HUD_HealthArmor ( )

Definition at line 23 of file healtharmor.qc.

References armor_beforedamage, armor_damagetime, armorblockpercent, autocvar__hud_configure, autocvar_hud_panel_healtharmor, autocvar_hud_panel_healtharmor_baralign, autocvar_hud_panel_healtharmor_combined, autocvar_hud_panel_healtharmor_dynamichud, autocvar_hud_panel_healtharmor_flip, autocvar_hud_panel_healtharmor_fuelbar_startalpha, autocvar_hud_panel_healtharmor_hide_ondeath, autocvar_hud_panel_healtharmor_iconalign, autocvar_hud_panel_healtharmor_maxarmor, autocvar_hud_panel_healtharmor_maxhealth, autocvar_hud_panel_healtharmor_oxygenbar_startalpha, autocvar_hud_panel_healtharmor_progressbar, autocvar_hud_panel_healtharmor_progressbar_armor, autocvar_hud_panel_healtharmor_progressbar_gfx, autocvar_hud_panel_healtharmor_progressbar_gfx_damage, autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth, autocvar_hud_panel_healtharmor_progressbar_gfx_smooth, autocvar_hud_panel_healtharmor_progressbar_health, autocvar_hud_panel_healtharmor_text, autocvar_hud_progressbar_alpha, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_fuel_color, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_oxygen_color, blink(), blink_synced(), bound(), draw_beginBoldFont, draw_endBoldFont, DRAWFLAG_NORMAL, DrawNumIcon(), drawpic_aspect_skin, eX, eY, fabs(), fade_time, floor(), health, health_beforedamage, health_damagetime, hud, HUD_Get_Num_Color(), HUD_Panel_DrawBg, HUD_Panel_DrawProgressBar(), HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), old_p_armor, old_p_armortime, old_p_health, old_p_healthtime, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, prev_armor, prev_health, prev_p_armor, prev_p_health, spectatee_status, time, v, vec2, and vector().

24 {
25  int armor, health, fuel, air_time;
27  {
29  return;
30  if(hud != HUD_NORMAL) return;
31 
32  health = STAT(HEALTH);
33  if(health <= 0)
34  {
35  health = 0;
36  prev_health = -1;
38  return;
39  }
40  armor = STAT(ARMOR);
41 
42  // code to check for spectatee_status changes is in ENT_CLIENT_CLIENTDATA
43  // prev_p_health and prev_health can be set to -1 there
44 
45  if (prev_p_health == -1)
46  {
47  // no effect
51  armor_damagetime = 0;
53  prev_armor = armor;
55  old_p_armor = armor;
57  prev_p_armor = armor;
58  }
59  else if (prev_health == -1)
60  {
61  //start the load effect
63  armor_damagetime = 0;
64  prev_health = 0;
65  prev_armor = 0;
66  }
67  fuel = STAT(FUEL);
68  air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
69  }
70  else
71  {
72  health = 150;
73  armor = 75;
74  fuel = 20;
75  air_time = 6;
76  }
77 
79 
81 
82  vector pos, mySize;
83  pos = panel_pos;
84  mySize = panel_size;
85 
88  else
92  {
93  pos += '1 1 0' * panel_bg_padding;
94  mySize -= '2 2 0' * panel_bg_padding;
95  }
96 
97  float air_alpha;
98  if (!STAT(AIR_FINISHED))
99  air_alpha = 0;
100  else if (time > STAT(AIR_FINISHED))
101  {
102  air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1);
103  air_time = 10;
104  }
105  else
106  {
107  float fade_time = 10 / 2;
109  float f = (STAT(AIR_FINISHED) - time - fade_time) / fade_time;
110  air_alpha = bound(0, start_alpha + (1 - start_alpha) * (1 - f), 1);
111  }
112 
113  float fuel_alpha;
114  if (!fuel)
115  fuel_alpha = 0;
116  else
117  {
119  float f = (100 - fuel) / 50;
120  fuel_alpha = bound(0, start_alpha + (1 - start_alpha) * f, 1);
121  }
122 
125 
128  if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
129  {
130  vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
131  float hp = floor(v.x + 1);
132 
133  float maxtotal = maxhealth + maxarmor;
134  string biggercount;
135  if(v.z) // NOT fully armored
136  {
137  biggercount = "health";
141  drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "armor", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL);
142  }
143  else
144  {
145  biggercount = "armor";
149  drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "health", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
150  }
152  DrawNumIcon(pos, mySize, hp, biggercount, false, false, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1);
153 
154  if(fuel)
155  HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel / 100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
156  if(air_time)
157  HUD_Panel_DrawProgressBar(pos + eY * 0.8 * mySize.y, vec2(mySize.x, 0.2 * mySize.y), "progressbar", air_time / 10, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_oxygen_color, air_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
158  }
159  else
160  {
161  float panel_ar = mySize.x/mySize.y;
162  bool is_vertical = (panel_ar < 1);
163  vector health_offset = '0 0 0', armor_offset = '0 0 0';
164  if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
165  {
166  mySize.x *= 0.5;
168  health_offset.x = mySize.x;
169  else
170  armor_offset.x = mySize.x;
171  }
172  else
173  {
174  mySize.y *= 0.5;
176  health_offset.y = mySize.y;
177  else
178  armor_offset.y = mySize.y;
179  }
180 
181  bool health_baralign, armor_baralign, fuel_baralign, air_align;
182  bool health_iconalign, armor_iconalign;
184  {
187  air_align = fuel_baralign = health_baralign;
190  }
191  else
192  {
195  air_align = fuel_baralign = armor_baralign;
198  }
199 
200  //if(health)
201  {
203  {
204  float p_health, pain_health_alpha;
205  p_health = health;
206  pain_health_alpha = 1;
208  {
210  {
212  {
213  if (time - old_p_healthtime < 1)
215  else
218  }
219  if (time - old_p_healthtime < 1)
220  {
221  p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
222  prev_p_health = p_health;
223  }
224  }
226  {
228  {
229  if (time - health_damagetime >= 1)
232  }
233  if (time - health_damagetime < 1)
234  {
235  float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
237  }
238  }
240 
242  {
243  pain_health_alpha = blink(0.85, 0.15, 9);
244  }
245  }
246  HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
247  }
249  DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, false, health_iconalign, HUD_Get_Num_Color(health, maxhealth, true), 1);
250  }
251 
252  //if(armor)
253  {
254  float p_armor = armor;
256  {
258  {
260  {
262  {
263  if (time - old_p_armortime < 1)
265  else
268  }
269  if (time - old_p_armortime < 1)
270  {
271  p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
272  prev_p_armor = p_armor;
273  }
274  }
276  {
278  {
279  if (time - armor_damagetime >= 1)
282  }
283  if (time - armor_damagetime < 1)
284  {
285  float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
287  }
288  }
289  prev_armor = armor;
290  }
291  if(p_armor)
293  }
296  DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, false, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor, true), 1);
297  }
298 
299  vector cell_size = mySize;
300  if (fuel || air_time)
301  {
302  if (is_vertical)
303  mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
304  else
305  mySize.y *= 0.2;
306  if (panel_ar >= 4)
307  mySize.x *= 2; //restore full panel size
308  else if (panel_ar < 1/4)
309  mySize.y *= 2; //restore full panel size
310  if (fuel)
311  HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel / 100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
312  if (air_time)
313  {
314  if (panel_ar > 1 && panel_ar < 4)
315  pos.y += cell_size.y;
316  else if (panel_ar > 1/4 && panel_ar <= 1)
317  pos.x += cell_size.x;
318  if (is_vertical)
319  pos.x += cell_size.x - mySize.x;
320  else
321  pos.y += cell_size.y - mySize.y;
322  HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", air_time / 10, is_vertical, air_align, autocvar_hud_progressbar_oxygen_color, air_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
323  }
324  }
325  }
326 
328 }
bool autocvar_hud_panel_healtharmor_dynamichud
Definition: healtharmor.qh:7
#define draw_endBoldFont()
Definition: draw.qh:5
bool autocvar_hud_panel_healtharmor_combined
Definition: healtharmor.qh:6
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
int old_p_health
Definition: hud.qh:242
const vector eY
Definition: vector.qh:45
ERASEABLE float blink(float base, float range, float freq)
Definition: util.qc:2044
vector autocvar_hud_progressbar_armor_color
Definition: healtharmor.qh:24
int armor_beforedamage
Definition: hud.qh:240
bool autocvar_hud_panel_healtharmor_flip
Definition: healtharmor.qh:8
bool autocvar__hud_configure
Definition: hud_config.qh:3
#define draw_beginBoldFont()
Definition: draw.qh:4
vector autocvar_hud_progressbar_oxygen_color
Definition: healtharmor.qh:27
float autocvar_hud_panel_healtharmor_progressbar_gfx_smooth
Definition: healtharmor.qh:21
int old_p_armor
Definition: hud.qh:242
bool autocvar_hud_panel_healtharmor_progressbar_gfx
Definition: healtharmor.qh:18
int autocvar_hud_panel_healtharmor_baralign
Definition: healtharmor.qh:5
vector panel_size
Definition: hud.qh:160
float autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth
Definition: healtharmor.qh:20
void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, bool isInfinite, int icon_right_align, vector color, float theAlpha)
Definition: hud.qc:479
void HUD_Scale_Disable()
Definition: hud.qc:83
int autocvar_hud_panel_healtharmor_iconalign
Definition: healtharmor.qh:10
float old_p_healthtime
Definition: hud.qh:243
float autocvar_hud_panel_healtharmor_fuelbar_startalpha
Definition: healtharmor.qh:13
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
float health_damagetime
Definition: hud.qh:239
float autocvar_hud_panel_healtharmor_oxygenbar_startalpha
Definition: healtharmor.qh:14
void HUD_Scale_Enable()
Definition: hud.qc:90
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
vector autocvar_hud_progressbar_fuel_color
Definition: healtharmor.qh:25
vector autocvar_hud_progressbar_health_color
Definition: healtharmor.qh:26
int prev_health
Definition: hud.qh:238
float autocvar_hud_panel_healtharmor_progressbar_gfx_damage
Definition: healtharmor.qh:19
string autocvar_hud_panel_healtharmor_progressbar_armor
Definition: healtharmor.qh:16
int prev_p_armor
Definition: hud.qh:246
int prev_armor
Definition: hud.qh:238
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
int health_beforedamage
Definition: hud.qh:240
vector panel_pos
Definition: hud.qh:159
int autocvar_hud_panel_healtharmor_maxhealth
Definition: healtharmor.qh:12
ERASEABLE float blink_synced(float base, float range, float freq, float start_time, int start_pos)
Definition: util.qc:2032
vector(float skel, float bonenum) _skel_get_boneabs_hidden
int prev_p_health
Definition: hud.qh:246
vector v
Definition: ent_cs.qc:116
float spectatee_status
Definition: main.qh:166
bool autocvar_hud_panel_healtharmor_progressbar
Definition: healtharmor.qh:15
const vector eX
Definition: vector.qh:44
float fade_time
Definition: common.qh:22
float health
Definition: progsdefs.qc:137
float armor_damagetime
Definition: hud.qh:239
int autocvar_hud_panel_healtharmor_maxarmor
Definition: healtharmor.qh:11
vector HUD_Get_Num_Color(float hp, float maxvalue, bool blink)
Definition: hud.qc:123
#define vec2(...)
Definition: vector.qh:90
string autocvar_hud_panel_healtharmor_progressbar_health
Definition: healtharmor.qh:17
bool autocvar_hud_panel_healtharmor
Definition: healtharmor.qh:4
float autocvar_hud_progressbar_alpha
Definition: hud.qh:201
float time
Definition: csprogsdefs.qc:16
float old_p_armortime
Definition: hud.qh:243
bool autocvar_hud_panel_healtharmor_hide_ondeath
Definition: healtharmor.qh:9
float armorblockpercent
Definition: main.qh:130
int autocvar_hud_panel_healtharmor_text
Definition: healtharmor.qh:22
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_HealthArmor_Export()

void HUD_HealthArmor_Export ( int  fh)

Definition at line 8 of file healtharmor.qc.

References HUD_Write_Cvar.

9 {
10  // allow saving cvars that aesthetically change the panel into hud skin files
11  HUD_Write_Cvar("hud_panel_healtharmor_combined");
12  HUD_Write_Cvar("hud_panel_healtharmor_flip");
13  HUD_Write_Cvar("hud_panel_healtharmor_iconalign");
14  HUD_Write_Cvar("hud_panel_healtharmor_baralign");
15  HUD_Write_Cvar("hud_panel_healtharmor_progressbar");
16  HUD_Write_Cvar("hud_panel_healtharmor_progressbar_health");
17  HUD_Write_Cvar("hud_panel_healtharmor_progressbar_armor");
18  HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx");
19  HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx_smooth");
20  HUD_Write_Cvar("hud_panel_healtharmor_text");
21 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38