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