1 #include "healtharmor.qh"
3 #include <client/defs.qh>
4 #include <client/miscfunctions.qh>
6 #include <common/deathtypes/all.qh>
10 void HUD_HealthArmor()
12 int armor, health, fuel, air_time;
13 if(!autocvar__hud_configure)
15 if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1))
17 if(hud != HUD_NORMAL) return;
19 health = STAT(HEALTH);
24 if(autocvar_hud_panel_healtharmor_hide_ondeath)
29 // code to check for spectatee_status changes is in ENT_CLIENT_CLIENTDATA
30 // prev_p_health and prev_health can be set to -1 there
32 if (prev_p_health == -1)
35 health_beforedamage = 0;
36 armor_beforedamage = 0;
37 health_damagetime = 0;
41 old_p_health = health;
43 prev_p_health = health;
46 else if (prev_health == -1)
48 //start the load effect
49 health_damagetime = 0;
55 air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
65 HUD_Panel_LoadCvars();
73 if (autocvar_hud_panel_healtharmor_dynamichud)
80 pos += '1 1 0' * panel_bg_padding;
81 mySize -= '2 2 0' * panel_bg_padding;
85 if (STAT(AIR_FINISHED) && time > STAT(AIR_FINISHED))
87 air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1);
91 int baralign = autocvar_hud_panel_healtharmor_baralign;
92 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
94 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
95 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
96 if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
98 vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
99 float hp = floor(v.x + 1);
101 float maxtotal = maxhealth + maxarmor;
103 if(v.z) // NOT fully armored
105 biggercount = "health";
106 if(autocvar_hud_panel_healtharmor_progressbar)
107 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
108 if(armor && autocvar_hud_panel_healtharmor_text)
109 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);
113 biggercount = "armor";
114 if(autocvar_hud_panel_healtharmor_progressbar)
115 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
116 if(health && autocvar_hud_panel_healtharmor_text)
117 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);
119 if(autocvar_hud_panel_healtharmor_text)
120 DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal), 1);
123 HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
125 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);
129 float panel_ar = mySize.x/mySize.y;
130 bool is_vertical = (panel_ar < 1);
131 vector health_offset = '0 0 0', armor_offset = '0 0 0';
132 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
135 if (autocvar_hud_panel_healtharmor_flip)
136 health_offset.x = mySize.x;
138 armor_offset.x = mySize.x;
143 if (autocvar_hud_panel_healtharmor_flip)
144 health_offset.y = mySize.y;
146 armor_offset.y = mySize.y;
149 bool health_baralign, armor_baralign, fuel_baralign, air_align;
150 bool health_iconalign, armor_iconalign;
151 if (autocvar_hud_panel_healtharmor_flip)
153 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
154 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
155 air_align = fuel_baralign = health_baralign;
156 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
157 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
161 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
162 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
163 air_align = fuel_baralign = armor_baralign;
164 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
165 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
170 if(autocvar_hud_panel_healtharmor_progressbar)
172 float p_health, pain_health_alpha;
174 pain_health_alpha = 1;
175 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
177 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
179 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
181 if (time - old_p_healthtime < 1)
182 old_p_health = prev_p_health;
184 old_p_health = prev_health;
185 old_p_healthtime = time;
187 if (time - old_p_healthtime < 1)
189 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
190 prev_p_health = p_health;
193 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
195 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
197 if (time - health_damagetime >= 1)
198 health_beforedamage = prev_health;
199 health_damagetime = time;
201 if (time - health_damagetime < 1)
203 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
204 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
207 prev_health = health;
209 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
211 pain_health_alpha = blink(0.85, 0.15, 9);
214 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);
216 if(autocvar_hud_panel_healtharmor_text)
217 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
222 float p_armor = armor;
223 if(autocvar_hud_panel_healtharmor_progressbar)
225 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
227 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
229 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
231 if (time - old_p_armortime < 1)
232 old_p_armor = prev_p_armor;
234 old_p_armor = prev_armor;
235 old_p_armortime = time;
237 if (time - old_p_armortime < 1)
239 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
240 prev_p_armor = p_armor;
243 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
245 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
247 if (time - armor_damagetime >= 1)
248 armor_beforedamage = prev_armor;
249 armor_damagetime = time;
251 if (time - armor_damagetime < 1)
253 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
254 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
260 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
262 if(!autocvar_hud_panel_healtharmor_progressbar || p_armor)
263 if(autocvar_hud_panel_healtharmor_text)
264 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
267 vector cell_size = mySize;
268 if (fuel || air_time)
271 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
275 mySize.x *= 2; //restore full panel size
276 else if (panel_ar < 1/4)
277 mySize.y *= 2; //restore full panel size
279 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
282 if (panel_ar > 1 && panel_ar < 4)
283 pos.y += cell_size.y;
284 else if (panel_ar > 1/4 && panel_ar <= 1)
285 pos.x += cell_size.x;
287 pos.x += cell_size.x - mySize.x;
289 pos.y += cell_size.y - mySize.y;
290 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);