]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/healtharmor.qc
36e3a8d907656a3ef28489cc324c9e303b70ec7e
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / healtharmor.qc
1 #include "healtharmor.qh"
2
3 #include <client/defs.qh>
4 #include <client/miscfunctions.qh>
5
6 #include <common/deathtypes/all.qh>
7
8 // Health/armor (#3)
9
10 void HUD_HealthArmor()
11 {
12         int armor, health, fuel, air_time;
13         if(!autocvar__hud_configure)
14         {
15                 if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1))
16                         return;
17                 if(hud != HUD_NORMAL) return;
18
19                 health = STAT(HEALTH);
20                 if(health <= 0)
21                 {
22                         health = 0;
23                         prev_health = -1;
24                         if(autocvar_hud_panel_healtharmor_hide_ondeath)
25                                 return;
26                 }
27                 armor = STAT(ARMOR);
28
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
31
32                 if (prev_p_health == -1)
33                 {
34                         // no effect
35                         health_beforedamage = 0;
36                         armor_beforedamage = 0;
37                         health_damagetime = 0;
38                         armor_damagetime = 0;
39                         prev_health = health;
40                         prev_armor = armor;
41                         old_p_health = health;
42                         old_p_armor = armor;
43                         prev_p_health = health;
44                         prev_p_armor = armor;
45                 }
46                 else if (prev_health == -1)
47                 {
48                         //start the load effect
49                         health_damagetime = 0;
50                         armor_damagetime = 0;
51                         prev_health = 0;
52                         prev_armor = 0;
53                 }
54                 fuel = STAT(FUEL);
55                 air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
56         }
57         else
58         {
59                 health = 150;
60                 armor = 75;
61                 fuel = 20;
62                 air_time = 6;
63         }
64
65         HUD_Panel_LoadCvars();
66
67         draw_beginBoldFont();
68
69         vector pos, mySize;
70         pos = panel_pos;
71         mySize = panel_size;
72
73         if (autocvar_hud_panel_healtharmor_dynamichud)
74                 HUD_Scale_Enable();
75         else
76                 HUD_Scale_Disable();
77         HUD_Panel_DrawBg();
78         if(panel_bg_padding)
79         {
80                 pos += '1 1 0' * panel_bg_padding;
81                 mySize -= '2 2 0' * panel_bg_padding;
82         }
83
84         int baralign = autocvar_hud_panel_healtharmor_baralign;
85         int iconalign = autocvar_hud_panel_healtharmor_iconalign;
86
87         int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
88         int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
89         if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
90         {
91                 vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
92                 float hp = floor(v.x + 1);
93
94                 float maxtotal = maxhealth + maxarmor;
95                 string biggercount;
96                 if(v.z) // NOT fully armored
97                 {
98                         biggercount = "health";
99                         if(autocvar_hud_panel_healtharmor_progressbar)
100                                 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);
101                         if(armor && autocvar_hud_panel_healtharmor_text)
102                                 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);
103                 }
104                 else
105                 {
106                         biggercount = "armor";
107                         if(autocvar_hud_panel_healtharmor_progressbar)
108                                 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);
109                         if(health && autocvar_hud_panel_healtharmor_text)
110                                 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);
111                 }
112                 if(autocvar_hud_panel_healtharmor_text)
113                         DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal), 1);
114
115                 if(fuel)
116                         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);
117                 if(air_time)
118                         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, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
119         }
120         else
121         {
122                 float panel_ar = mySize.x/mySize.y;
123                 bool is_vertical = (panel_ar < 1);
124                 vector health_offset = '0 0 0', armor_offset = '0 0 0';
125                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
126                 {
127                         mySize.x *= 0.5;
128                         if (autocvar_hud_panel_healtharmor_flip)
129                                 health_offset.x = mySize.x;
130                         else
131                                 armor_offset.x = mySize.x;
132                 }
133                 else
134                 {
135                         mySize.y *= 0.5;
136                         if (autocvar_hud_panel_healtharmor_flip)
137                                 health_offset.y = mySize.y;
138                         else
139                                 armor_offset.y = mySize.y;
140                 }
141
142                 bool health_baralign, armor_baralign, fuel_baralign, air_align;
143                 bool health_iconalign, armor_iconalign;
144                 if (autocvar_hud_panel_healtharmor_flip)
145                 {
146                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
147                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
148                         air_align = fuel_baralign = health_baralign;
149                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
150                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
151                 }
152                 else
153                 {
154                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
155                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
156                         air_align = fuel_baralign = armor_baralign;
157                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
158                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
159                 }
160
161                 //if(health)
162                 {
163                         if(autocvar_hud_panel_healtharmor_progressbar)
164                         {
165                                 float p_health, pain_health_alpha;
166                                 p_health = health;
167                                 pain_health_alpha = 1;
168                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
169                                 {
170                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
171                                         {
172                                                 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
173                                                 {
174                                                         if (time - old_p_healthtime < 1)
175                                                                 old_p_health = prev_p_health;
176                                                         else
177                                                                 old_p_health = prev_health;
178                                                         old_p_healthtime = time;
179                                                 }
180                                                 if (time - old_p_healthtime < 1)
181                                                 {
182                                                         p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
183                                                         prev_p_health = p_health;
184                                                 }
185                                         }
186                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
187                                         {
188                                                 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
189                                                 {
190                                                         if (time - health_damagetime >= 1)
191                                                                 health_beforedamage = prev_health;
192                                                         health_damagetime = time;
193                                                 }
194                                                 if (time - health_damagetime < 1)
195                                                 {
196                                                         float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
197                                                         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);
198                                                 }
199                                         }
200                                         prev_health = health;
201
202                                         if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
203                                         {
204                                                 float BLINK_FACTOR = 0.15;
205                                                 float BLINK_BASE = 0.85;
206                                                 float BLINK_FREQ = 9;
207                                                 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
208                                         }
209                                 }
210                                 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);
211                         }
212                         if(autocvar_hud_panel_healtharmor_text)
213                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
214                 }
215
216                 //if(armor)
217                 {
218                         float p_armor = armor;
219                         if(autocvar_hud_panel_healtharmor_progressbar)
220                         {
221                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
222                                 {
223                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
224                                         {
225                                                 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
226                                                 {
227                                                         if (time - old_p_armortime < 1)
228                                                                 old_p_armor = prev_p_armor;
229                                                         else
230                                                                 old_p_armor = prev_armor;
231                                                         old_p_armortime = time;
232                                                 }
233                                                 if (time - old_p_armortime < 1)
234                                                 {
235                                                         p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
236                                                         prev_p_armor = p_armor;
237                                                 }
238                                         }
239                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
240                                         {
241                                                 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
242                                                 {
243                                                         if (time - armor_damagetime >= 1)
244                                                                 armor_beforedamage = prev_armor;
245                                                         armor_damagetime = time;
246                                                 }
247                                                 if (time - armor_damagetime < 1)
248                                                 {
249                                                         float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
250                                                         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);
251                                                 }
252                                         }
253                                         prev_armor = armor;
254                                 }
255                                 if(p_armor)
256                                         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);
257                         }
258                         if(!autocvar_hud_panel_healtharmor_progressbar || p_armor)
259                         if(autocvar_hud_panel_healtharmor_text)
260                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
261                 }
262
263                 vector cell_size = mySize;
264                 if (fuel || air_time)
265                 {
266                         if (is_vertical)
267                                 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
268                         else
269                                 mySize.y *= 0.2;
270                         if (panel_ar >= 4)
271                                 mySize.x *= 2; //restore full panel size
272                         else if (panel_ar < 1/4)
273                                 mySize.y *= 2; //restore full panel size
274                         if (fuel)
275                                 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
276                         if (air_time)
277                         {
278                                 if (panel_ar > 1 && panel_ar < 4)
279                                         pos.y += cell_size.y;
280                                 else if (panel_ar > 1/4 && panel_ar <= 1)
281                                         pos.x += cell_size.x;
282                                 if (is_vertical)
283                                         pos.x += cell_size.x - mySize.x;
284                                 else
285                                         pos.y += cell_size.y - mySize.y;
286                                 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", air_time / 10, is_vertical, air_align, autocvar_hud_progressbar_oxygen_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
287                         }
288                 }
289         }
290
291         draw_endBoldFont();
292 }