]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/strafehud.qc
strafehud: make both switch indicator alphas configurable
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / strafehud.qc
1 // Author: Juhu
2
3 #include "strafehud.qh"
4
5 #include <client/autocvars.qh>
6 #include <client/miscfunctions.qh>
7 #include <common/animdecide.qh>
8 #include <common/ent_cs.qh>
9 #include <common/mapinfo.qh>
10 #include <common/physics/movetypes/movetypes.qh>
11 #include <common/physics/player.qh>
12 #include <lib/csqcmodel/cl_player.qh>
13
14 // StrafeHUD (#25)
15
16 void HUD_StrafeHUD_Export(int fh)
17 {
18     // allow saving cvars that aesthetically change the panel into hud skin files
19 }
20
21 bool fwd = true;
22 bool state_fwd = true;
23 bool state_fwd_prev = true;
24 float hidden_width;
25 float demo_angle = -37;
26 float demo_direction = 1;
27 float demo_time = 0;
28 float state_onground_time = 0;
29 float state_strafekeys_time = 0;
30 float state_fwd_time = 0;
31 bool state_onground = false;
32 bool state_strafekeys = false;
33 bool turn = false;
34 float turnangle;
35
36 // provide basic panel cvars to old clients
37 // TODO remove them after a future release (0.8.2+)
38 noref string autocvar_hud_panel_strafehud_pos = "0.320000 0.570000";
39 noref string autocvar_hud_panel_strafehud_size = "0.360000 0.020000";
40 noref string autocvar_hud_panel_strafehud_bg = "0";
41 noref string autocvar_hud_panel_strafehud_bg_color = "";
42 noref string autocvar_hud_panel_strafehud_bg_color_team = "";
43 noref string autocvar_hud_panel_strafehud_bg_alpha = "0.7";
44 noref string autocvar_hud_panel_strafehud_bg_border = "";
45 noref string autocvar_hud_panel_strafehud_bg_padding = "";
46
47 void HUD_StrafeHUD()
48 {
49     entity strafeplayer;
50     bool islocal;
51
52     // generic hud routines
53     if(!autocvar__hud_configure)
54     {
55         if(!autocvar_hud_panel_strafehud ||
56            (spectatee_status == -1 && (autocvar_hud_panel_strafehud == 1 || autocvar_hud_panel_strafehud == 3)) ||
57            (autocvar_hud_panel_strafehud == 3 && !(ISGAMETYPE(RACE) || ISGAMETYPE(CTS)))) return;
58     }
59
60     HUD_Panel_LoadCvars();
61
62     if(autocvar_hud_panel_strafehud_dynamichud)
63     {
64         HUD_Scale_Enable();
65     }
66     else
67     {
68         HUD_Scale_Disable();
69     }
70
71     HUD_Panel_DrawBg();
72
73     if(panel_bg_padding)
74     {
75         panel_pos  += '1 1 0' * panel_bg_padding;
76         panel_size -= '2 2 0' * panel_bg_padding;
77     }
78
79     // find out whether the local csqcmodel entity is valid
80     if(spectatee_status > 0 || isdemo())
81     {
82         islocal = false;
83         strafeplayer = CSQCModel_server2csqc(player_localentnum - 1);
84     }
85     else
86     {
87         islocal = true;
88         strafeplayer = csqcplayer;
89     }
90
91     // draw strafehud
92     if(csqcplayer && strafeplayer)
93     {
94         // physics
95         bool   onground                      = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
96         bool   strafekeys;
97         bool   swimming                      = strafeplayer.waterlevel >= WATERLEVEL_SWIMMING;
98         float  speed                         = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337; // use local csqcmodel entity for this even when spectating, flickers too much otherwise
99         float  maxspeed_crouch_mod           = IS_DUCKED(strafeplayer) && !swimming ? .5 : 1;
100         float  maxspeed_water_mod            = swimming ? .7 : 1; // very simplified water physics, the hud will not work well (and is not supposed to) while swimming
101         float  maxspeed_phys                 = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer);
102         float  maxspeed                      = !autocvar__hud_configure ? maxspeed_phys * maxspeed_crouch_mod * maxspeed_water_mod : 320;
103         float  vel_angle                     = vectoangles(strafeplayer.velocity).y;
104         float  view_angle                    = view_angles.y + 180;
105         float  angle;
106         int    direction;
107         vector movement                      = PHYS_INPUT_MOVEVALUES(strafeplayer);
108         int    keys                          = STAT(PRESSED_KEYS);
109         int    keys_fwd;
110         float  wishangle                     = 0;
111
112         // HUD
113         int    mode                          = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0;
114         float  antiflicker_angle             = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
115         float  antiflicker_speed             = max(0, autocvar_hud_panel_strafehud_antiflicker_speed);
116         float  minspeed;
117         bool   straight_overturn             = false;
118         float  hudangle;
119         float  bar_offset;
120         float  bar_width;
121         vector currentangle_color            = autocvar_hud_panel_strafehud_angle_neutral_color;
122         float  currentangle_offset;
123         vector currentangle_size             = '0 0 0';
124         float  bestangle;
125         bool   bestangle_anywhere            = false;
126         float  bestangle_offset;
127         float  bestangle_width;
128         bool   odd_angles                    = false;
129         float  switch_bestangle_offset;
130         float  odd_bestangle_offset          = 0;
131         float  switch_odd_bestangle_offset   = 0;
132         float  accelzone_offset;
133         float  accelzone_width;
134         float  odd_accelzone_offset;
135         float  odd_accelzone_width;
136         float  overturn_offset;
137         float  overturn_width;
138         float  overturn_width_visible;
139         vector direction_size_vertical       = '0 0 0';
140         vector direction_size_horizontal     = '0 0 0';
141         float  maxangle;
142         float  range_minangle;
143
144         // determine whether the player is pressing forwards or backwards keys
145         if(islocal) // if entity is local player
146         {
147             if(movement.x > 0)
148             {
149                 keys_fwd = 1;
150             }
151             else if(movement.x < 0)
152             {
153                 keys_fwd = -1;
154             }
155             else
156             {
157                 keys_fwd = 0;
158             }
159         }
160         else // alternatively determine direction by querying pressed keys
161         {
162             if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD))
163             {
164                 keys_fwd = 1;
165             }
166             else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD))
167             {
168                 keys_fwd = -1;
169             }
170             else
171             {
172                 keys_fwd = 0;
173             }
174         }
175
176         // determine player wishdir
177         if(islocal) // if entity is local player
178         {
179             if(movement.x == 0)
180             {
181                 if(movement.y < 0)
182                 {
183                     wishangle = -90;
184                 }
185                 else if(movement.y > 0)
186                 {
187                     wishangle = 90;
188                 }
189                 else
190                 {
191                     wishangle = 0;
192                 }
193             }
194             else
195             {
196                 if(movement.y == 0)
197                 {
198                     wishangle = 0;
199                 }
200                 else
201                 {
202                     wishangle = RAD2DEG * atan2(movement.y, movement.x);
203                     // wrap the wish angle if it exceeds ±90°
204                     if(fabs(wishangle) > 90)
205                     {
206                         if(wishangle < 0) wishangle += 180;
207                         else wishangle -= 180;
208                         wishangle = -wishangle;
209                     }
210                 }
211             }
212         }
213         else // alternatively calculate wishdir by querying pressed keys
214         {
215             if(keys & KEY_FORWARD || keys & KEY_BACKWARD)
216             {
217                 wishangle = 45;
218             }
219             else
220             {
221                 wishangle = 90;
222             }
223             if(keys & KEY_LEFT)
224             {
225                 wishangle *= -1;
226             }
227             else if(!(keys & KEY_RIGHT))
228             {
229                 wishangle = 0; // wraps at 180°
230             }
231         }
232
233         strafekeys = fabs(wishangle) == 90;
234
235         // determine minimum required angle to display full strafe range
236         range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree
237         if(range_minangle > 45) // minimum angle range is 45
238         {
239             range_minangle = 45 - fabs(wishangle) % 45;
240         }
241         range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45
242         range_minangle *= 2; // multiply to accommodate for both sides of the hud
243
244         if(autocvar_hud_panel_strafehud_range == 0)
245         {
246             if(autocvar__hud_configure)
247             {
248                 hudangle = 90;
249             }
250             else
251             {
252                 hudangle = range_minangle; // use minimum angle required if dynamically setting hud angle
253             }
254         }
255         else
256         {
257             hudangle = bound(0, fabs(autocvar_hud_panel_strafehud_range), 360); // limit HUD range to 360 degrees, higher values don't make sense
258         }
259
260         // detect air strafe turning
261         if(onground != state_onground)
262         {
263             state_onground_time = time;
264         }
265         state_onground = onground;
266
267         if(strafekeys != state_strafekeys)
268         {
269             state_strafekeys_time = time;
270         }
271         state_strafekeys = strafekeys;
272
273         if((keys & KEY_FORWARD) || (keys & KEY_BACKWARD) || swimming || autocvar__hud_configure)
274         {
275             turn = false;
276         }
277         else if(onground)
278         {
279             if((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_ground) // timeout for strafe jumping in general
280             {
281                 turn = false;
282             }
283         }
284         else // air strafe only
285         {
286             if(strafekeys)
287             {
288                 if(((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_air) || (keys & KEY_JUMP)) // timeout for slick ramps
289                 {
290                     turn = true; // CPMA turning
291                     turnangle = wishangle;
292                 }
293             }
294             else if((time - state_strafekeys_time) >= autocvar_hud_panel_strafehud_timeout_turn) // timeout for jumping with strafe keys only
295             {
296                 turn = false;
297             }
298         }
299         if(turn)
300         {
301             maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no modifiers here because they don't affect air strafing
302             wishangle = turnangle;
303         }
304
305         minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? maxspeed + antiflicker_speed : autocvar_hud_panel_strafehud_switch_minspeed;
306
307         // get current strafing angle ranging from -180° to +180°
308         if(!autocvar__hud_configure)
309         {
310             if(speed > 0)
311             {
312                 // calculate view angle relative to the players current velocity direction
313                 angle = vel_angle - view_angle;
314
315                 // if the angle goes above 180° or below -180° wrap it to the opposite side
316                 if (angle > 180) angle -= 360;
317                 else if(angle < -180) angle += 360;
318
319                 // shift the strafe angle by 180° for hud calculations
320                 if(angle < 0) angle += 180;
321                 else angle -= 180;
322
323                 // determine whether the player is strafing forwards or backwards
324                 // if the player isn't strafe turning use forwards/backwards keys to determine direction
325                 if(!strafekeys)
326                 {
327                     if(keys_fwd > 0)
328                     {
329                         state_fwd = true;
330                     }
331                     else if(keys_fwd < 0)
332                     {
333                         state_fwd = false;
334                     }
335                     else
336                     {
337                         state_fwd = fabs(angle) <= 90;
338                     }
339                 }
340                 // otherwise determine by examining the strafe angle
341                 else
342                 {
343                     if(wishangle < 0) // detect direction since the direction is not yet set
344                     {
345                         state_fwd = angle <= -wishangle;
346                     }
347                     else
348                     {
349                         state_fwd = angle >= -wishangle;
350                     }
351                 }
352
353                 if(state_fwd_prev != state_fwd)
354                 {
355                     state_fwd_time = time;
356                 }
357                 state_fwd_prev = state_fwd;
358
359                 if((time - state_fwd_time) >= autocvar_hud_panel_strafehud_timeout_direction || speed < maxspeed || (strafekeys && mode == 0)) // timeout when changing between forwards and backwards movement
360                 {
361                     fwd = state_fwd;
362                 }
363
364                 // shift the strafe angle by 180° when strafing backwards
365                 if(!fwd)
366                 {
367                     if(angle < 0) angle += 180;
368                     else angle -= 180;
369                 }
370
371                 // don't make the angle indicator switch side too much at ±180° if anti flicker is turned on
372                 if(angle > (180 - antiflicker_angle) || angle < (-180 + antiflicker_angle))
373                 {
374                     straight_overturn = true;
375                 }
376             }
377             else
378             {
379                 angle = 0;
380             }
381         }
382         else // simulate turning for HUD setup
383         {
384             if(autocvar__hud_panel_strafehud_demo && ((time - demo_time) >= .025))
385             {
386                 demo_time = time;
387                 demo_angle += demo_direction;
388                 if(fabs(demo_angle) >= 55)
389                 {
390                     demo_direction = -demo_direction;
391                 }
392             }
393             angle = demo_angle;
394             wishangle = 45 * (demo_angle > 0 ? 1 : -1);
395         }
396
397         // invert the wish angle when strafing backwards
398         if(!fwd)
399         {
400             wishangle = -wishangle;
401         }
402
403         // flip angles if v_flipped is enabled
404         if(autocvar_v_flipped)
405         {
406             angle = -angle;
407             wishangle = -wishangle;
408         }
409
410         // determine whether the player is strafing left or right
411         if(wishangle != 0)
412         {
413             direction = wishangle > 0 ? 1 : -1;
414         }
415         else
416         {
417             direction = (angle > antiflicker_angle && angle < (180 - antiflicker_angle)) ? 1 : (angle < -antiflicker_angle && angle > (-180 + antiflicker_angle)) ? -1 : 0;
418         }
419
420         // decelerating at this angle
421         maxangle = 90 - fabs(wishangle);
422         // best angle to strafe at
423         bestangle = (speed > maxspeed ? acos(maxspeed / speed) : 0) * RAD2DEG * (direction < 0 ? -1 : 1) - wishangle;
424
425         // various offsets and size calculations of hud indicator elements
426         // how much is hidden by the current hud angle
427         hidden_width = (360 - hudangle) / hudangle * panel_size.x;
428         // current angle
429         currentangle_size.x = max(panel_size.x * autocvar_hud_panel_strafehud_angle_width, 1);
430         if(mode == 0)
431         {
432             currentangle_offset = angle/hudangle * panel_size.x;
433         }
434         else
435         {
436             currentangle_offset = bound(-hudangle/2, angle, hudangle/2)/hudangle * panel_size.x + panel_size.x/2;
437         }
438         currentangle_size.y = max(panel_size.y * min(autocvar_hud_panel_strafehud_angle_height, 2), 1);
439         // best strafe acceleration angle
440         bestangle_offset        =  bestangle/hudangle * panel_size.x + panel_size.x/2;
441         switch_bestangle_offset = -bestangle/hudangle * panel_size.x + panel_size.x/2;
442         bestangle_width = max(panel_size.x * autocvar_hud_panel_strafehud_switch_width, 1);
443
444         if(((angle > -wishangle && direction < 0) || (angle < -wishangle && direction > 0)) && (direction != 0))
445         {
446             odd_angles = true;
447             float odd_bestangle = -(bestangle + wishangle) - wishangle;
448             odd_bestangle_offset        = odd_bestangle/hudangle * panel_size.x + panel_size.x/2;
449             switch_odd_bestangle_offset = (odd_bestangle+bestangle*2)/hudangle * panel_size.x + panel_size.x/2;
450         }
451         // direction indicator
452         direction_size_vertical.x = max(panel_size.y * min(autocvar_hud_panel_strafehud_direction_width, .5), 1);
453         direction_size_vertical.y = panel_size.y;
454         direction_size_horizontal.x = max(panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5), direction_size_vertical.x);
455         direction_size_horizontal.y = direction_size_vertical.x;
456         // overturn
457         overturn_width = 180/hudangle * panel_size.x;
458         overturn_width_visible = (hudangle/2 - maxangle) / hudangle * panel_size.x;
459
460         // the neutral zone fills the whole strafe bar
461         if(speed <= (swimming ? antiflicker_speed : 0))
462         {
463             // draw neutral zone
464             if(panel_size.x > 0 && panel_size.y > 0 && autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha > 0)
465             {
466                 switch(autocvar_hud_panel_strafehud_style)
467                 {
468                     default:
469                     case 0:
470                         drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
471                         break;
472
473                     case 1:
474                         HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
475                 }
476             }
477         }
478         else
479         {
480             // calculate various zones of the strafe-o-meter
481             if(direction < 0) // turning left
482             {
483                 // calculate zone in which strafe acceleration happens
484                 accelzone_width = bestangle_offset;
485                 // calculate offset of overturn zone
486                 overturn_offset = overturn_width_visible - overturn_width;
487                 // move/adjust acceleration zone
488                 accelzone_offset = overturn_width_visible;
489                 accelzone_width -= overturn_width_visible;
490                 // calculate zone in which strafe acceleration could also happen without changing wishdir
491                 odd_accelzone_width = accelzone_width;
492                 odd_accelzone_offset = overturn_offset - odd_accelzone_width;
493                 // calculate the neutral zone of the strafe-o-meter
494                 bar_offset = bestangle_offset;
495             }
496             else // turning right or moving forward
497             {
498                 // calculate zone in which strafe acceleration happens
499                 accelzone_offset = bestangle_offset;
500                 accelzone_width = panel_size.x - accelzone_offset;
501                 // calculate offset of overturn zone
502                 overturn_offset = panel_size.x - overturn_width_visible;
503                 // adjust acceleration zone
504                 accelzone_width -= overturn_width_visible;
505                 // calculate zone in which strafe acceleration could also happen without changing wishdir
506                 odd_accelzone_width = accelzone_width;
507                 odd_accelzone_offset = overturn_offset + overturn_width;
508                 // calculate the neutral zone of the strafe-o-meter
509                 bar_offset = odd_accelzone_offset + odd_accelzone_width;
510             }
511             bar_width = 360/hudangle * panel_size.x - accelzone_width - odd_accelzone_width - overturn_width;
512
513             // remove indicator width from offset
514             if(direction < 0)
515             {
516                 bestangle_offset -= bestangle_width;
517                 switch_odd_bestangle_offset -= bestangle_width;
518             }
519             else
520             {
521                 switch_bestangle_offset -= bestangle_width;
522                 odd_bestangle_offset -= bestangle_width;
523             }
524
525             if(mode == 0)
526             {
527                 bar_offset -= currentangle_offset;
528                 accelzone_offset -= currentangle_offset;
529                 odd_accelzone_offset -= currentangle_offset;
530                 overturn_offset -= currentangle_offset;
531                 bestangle_offset -= currentangle_offset;
532                 switch_bestangle_offset -= currentangle_offset;
533                 odd_bestangle_offset -= currentangle_offset;
534                 switch_odd_bestangle_offset -= currentangle_offset;
535             }
536
537             // draw acceleration zone
538             HUD_Panel_DrawStrafeHUD(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style);
539
540             // draw odd acceleration zone
541             HUD_Panel_DrawStrafeHUD(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style);
542
543             // draw overturn zone
544             HUD_Panel_DrawStrafeHUD(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_bar_overturn_color, autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style);
545
546             // draw neutral zone
547             HUD_Panel_DrawStrafeHUD(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style);
548
549             if(direction != 0 && direction_size_vertical.x > 0 && autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha > 0)
550             {
551                 bool indicator_direction = direction < 0;
552                 // invert left/right when strafing backwards or when strafing towards the opposite side indicated by the direction variable
553                 // if both conditions are true then it's inverted twice hence not inverted at all
554                 if(!fwd != odd_angles)
555                 {
556                     indicator_direction = !indicator_direction;
557                 }
558                 // draw the direction indicator caps at the sides of the hud
559                 // vertical line
560                 if(direction_size_vertical.y > 0) drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x), direction_size_vertical, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
561                 // top horizontal line
562                 drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) - eY * direction_size_horizontal.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
563                 // bottom horizontal line
564                 drawfill(panel_pos + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) + eY * panel_size.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
565             }
566
567             if(speed >= minspeed) // only draw indicators if minspeed is reached
568             {
569                 // draw best angles for acceleration
570                 float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset;
571                 float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset;
572                 // both indicators are inactive if no direction can be determined
573                 vector switch_color = direction != 0 ? autocvar_hud_panel_strafehud_switch_active_color : autocvar_hud_panel_strafehud_switch_inactive_color;
574                 float switch_alpha = direction != 0 ? autocvar_hud_panel_strafehud_switch_active_alpha : autocvar_hud_panel_strafehud_switch_inactive_alpha;
575                 // draw the switch indicators
576                 HUD_Panel_DrawStrafeHUD(switch_offset, bestangle_width, autocvar_hud_panel_strafehud_switch_inactive_color, autocvar_hud_panel_strafehud_switch_inactive_alpha * panel_fg_alpha, 0);
577                 HUD_Panel_DrawStrafeHUD(offset, bestangle_width, switch_color, switch_alpha * panel_fg_alpha, 0);
578             }
579         }
580
581         if(speed < (maxspeed + antiflicker_speed) && speed > 0)
582         {
583             bestangle_anywhere = true; // moving forward should suffice to gain speed
584         }
585
586         // draw the actual strafe angle
587         if(!bestangle_anywhere) // player gains speed with strafing
588         {
589             if((direction > 0 && (angle >= bestangle || angle <= -(bestangle + wishangle*2))) ||
590                (direction < 0 && (angle <= bestangle || angle >= -(bestangle + wishangle*2))))
591             currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
592         }
593
594         if(fabs(angle + wishangle) > 90) // player is overturning
595         {
596             currentangle_color = autocvar_hud_panel_strafehud_angle_overturn_color;
597         }
598         else if(bestangle_anywhere) // player gains speed without strafing
599         {
600             currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
601         }
602
603         if(mode == 0 || straight_overturn)
604         {
605             currentangle_offset = panel_size.x/2;
606         }
607         if(currentangle_size.x > 0 && currentangle_size.y > 0 && autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0)
608         {
609             drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
610         }
611     }
612 }
613
614 // functions to make hud elements align perfectly in the hud area
615 void HUD_Panel_DrawStrafeHUD(float offset, float width, vector color, float alpha, int type)
616 {
617     float mirror_offset, mirror_width;
618     vector size = panel_size;
619     vector mirror_size = panel_size;
620
621     if(alpha <= 0 || width <= 0) return;
622
623     if(offset < 0)
624     {
625         mirror_width = min(fabs(offset), width);
626         mirror_offset = panel_size.x + hidden_width - fabs(offset);
627         width += offset;
628         offset = 0;
629     }
630     else
631     {
632         mirror_width = min(offset + width - panel_size.x - hidden_width, width);
633         mirror_offset = max(offset - panel_size.x - hidden_width, 0);
634     }
635     if((offset + width) > panel_size.x)
636     {
637         width = panel_size.x - offset;
638     }
639     if(mirror_offset < 0)
640     {
641         mirror_width += mirror_offset;
642         mirror_offset = 0;
643     }
644     if((mirror_offset + mirror_width) > panel_size.x)
645     {
646         mirror_width = panel_size.x - mirror_offset;
647     }
648
649     size.x = width;
650     mirror_size.x = mirror_width;
651
652     switch(type)
653     {
654         default:
655         case 0:
656             if(mirror_width > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha, DRAWFLAG_NORMAL);
657             if(width > 0) drawfill(panel_pos + eX * offset, size, color, alpha, DRAWFLAG_NORMAL);
658             break;
659
660         case 1:
661             if(mirror_size.x > 0 && mirror_size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * mirror_offset, mirror_size, "progressbar", 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
662             if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
663     }
664 }