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