1 #include "healtharmor.qh"
3 #include <common/deathtypes/all.qh>
5 /** Health/armor (#3) */
8 int armor, health, fuel;
9 if(!autocvar__hud_configure)
11 if(!autocvar_hud_panel_healtharmor) return;
12 if(hud != HUD_NORMAL) return;
13 if(spectatee_status == -1) return;
15 health = STAT(HEALTH);
23 // code to check for spectatee_status changes is in Ent_ClientData()
24 // prev_p_health and prev_health can be set to -1 there
26 if (prev_p_health == -1)
29 health_beforedamage = 0;
30 armor_beforedamage = 0;
31 health_damagetime = 0;
35 old_p_health = health;
37 prev_p_health = health;
40 else if (prev_health == -1)
42 //start the load effect
43 health_damagetime = 0;
57 HUD_Panel_UpdateCvars();
68 pos += '1 1 0' * panel_bg_padding;
69 mySize -= '2 2 0' * panel_bg_padding;
72 int baralign = autocvar_hud_panel_healtharmor_baralign;
73 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
75 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
76 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
77 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
80 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
85 float maxtotal = maxhealth + maxarmor;
87 if(v.z) // NOT fully armored
89 biggercount = "health";
90 if(autocvar_hud_panel_healtharmor_progressbar)
91 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
93 if(autocvar_hud_panel_healtharmor_text)
94 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);
98 biggercount = "armor";
99 if(autocvar_hud_panel_healtharmor_progressbar)
100 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
102 if(autocvar_hud_panel_healtharmor_text)
103 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);
105 if(autocvar_hud_panel_healtharmor_text)
106 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
109 HUD_Panel_DrawProgressBar(pos, eX * mySize.x + eY * 0.2 * mySize.y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
113 float panel_ar = mySize.x/mySize.y;
114 bool is_vertical = (panel_ar < 1);
115 vector health_offset = '0 0 0', armor_offset = '0 0 0';
116 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
119 if (autocvar_hud_panel_healtharmor_flip)
120 health_offset.x = mySize.x;
122 armor_offset.x = mySize.x;
127 if (autocvar_hud_panel_healtharmor_flip)
128 health_offset.y = mySize.y;
130 armor_offset.y = mySize.y;
133 bool health_baralign, armor_baralign, fuel_baralign;
134 bool health_iconalign, armor_iconalign;
135 if (autocvar_hud_panel_healtharmor_flip)
137 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
138 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
139 fuel_baralign = health_baralign;
140 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
141 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
145 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
146 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
147 fuel_baralign = armor_baralign;
148 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
149 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
154 if(autocvar_hud_panel_healtharmor_progressbar)
156 float p_health, pain_health_alpha;
158 pain_health_alpha = 1;
159 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
161 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
163 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
165 if (time - old_p_healthtime < 1)
166 old_p_health = prev_p_health;
168 old_p_health = prev_health;
169 old_p_healthtime = time;
171 if (time - old_p_healthtime < 1)
173 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
174 prev_p_health = p_health;
177 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
179 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
181 if (time - health_damagetime >= 1)
182 health_beforedamage = prev_health;
183 health_damagetime = time;
185 if (time - health_damagetime < 1)
187 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
188 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);
191 prev_health = health;
193 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
195 float BLINK_FACTOR = 0.15;
196 float BLINK_BASE = 0.85;
197 float BLINK_FREQ = 9;
198 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
201 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);
203 if(autocvar_hud_panel_healtharmor_text)
204 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
209 if(autocvar_hud_panel_healtharmor_progressbar)
213 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
215 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
217 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
219 if (time - old_p_armortime < 1)
220 old_p_armor = prev_p_armor;
222 old_p_armor = prev_armor;
223 old_p_armortime = time;
225 if (time - old_p_armortime < 1)
227 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
228 prev_p_armor = p_armor;
231 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
233 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
235 if (time - armor_damagetime >= 1)
236 armor_beforedamage = prev_armor;
237 armor_damagetime = time;
239 if (time - armor_damagetime < 1)
241 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
242 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);
247 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);
249 if(autocvar_hud_panel_healtharmor_text)
250 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
256 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
260 mySize.x *= 2; //restore full panel size
261 else if (panel_ar < 1/4)
262 mySize.y *= 2; //restore full panel size
263 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);