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