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