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