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