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