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