3 #include "strafehud.qh"
5 #include <client/draw.qh>
6 #include <lib/csqcmodel/cl_player.qh>
7 #include <common/physics/player.qh>
8 #include <common/physics/movetypes/movetypes.qh>
11 #include <client/view.qh> // for v_flipped state
14 #include <common/animdecide.qh> // anim_implicit_state
15 #include <common/ent_cs.qh> // CSQCModel_server2csqc()
18 #include <client/hud/panel/racetimer.qh> // checkpoint information (race_*)
21 #include <lib/csqcmodel/common.qh> // for IS_PLAYER() macro
22 #include <common/resources/cl_resources.qh> // IS_DEAD() macro
26 void HUD_StrafeHUD_Export(int fh)
28 // allow saving cvars that aesthetically change the panel into hud skin files
31 float GeomLerp(float a, float _lerp, float b); // declare GeomLerp here since there's no header file for it
35 static float hud_lasttime = 0;
39 // generic hud routines
40 if(!autocvar__hud_configure)
42 if(!autocvar_hud_panel_strafehud ||
43 (spectatee_status == -1 && (autocvar_hud_panel_strafehud == 1 || autocvar_hud_panel_strafehud == 3)) ||
44 (autocvar_hud_panel_strafehud == 3 && !MUTATOR_CALLHOOK(HUD_StrafeHUD_showoptional))) { hud_lasttime = time; return; }
47 HUD_Panel_LoadCvars();
49 if(autocvar_hud_panel_strafehud_dynamichud)
58 panel_pos += '1 1 0' * panel_bg_padding;
59 panel_size -= '2 2 0' * panel_bg_padding;
62 // find out whether the local csqcmodel entity is valid
63 if(spectatee_status > 0 || isdemo())
66 strafeplayer = CSQCModel_server2csqc(player_localentnum - 1);
71 strafeplayer = csqcplayer;
75 if(csqcplayer && strafeplayer)
77 float strafe_waterlevel;
79 // check the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled
82 void old_contentstransition(int, int) = strafeplayer.contentstransition;
83 float old_watertype = strafeplayer.watertype;
84 float old_waterlevel = strafeplayer.waterlevel;
86 strafeplayer.contentstransition = func_null; // unset the contentstransition function if present
87 _Movetype_CheckWater(strafeplayer);
88 strafe_waterlevel = strafeplayer.waterlevel; // store the player waterlevel
91 strafeplayer.contentstransition = old_contentstransition;
92 strafeplayer.watertype = old_watertype;
93 strafeplayer.waterlevel = old_waterlevel;
96 int keys = STAT(PRESSED_KEYS);
97 // try to ignore if track_canjump is enabled, doesn't work in spectator mode if spectated player uses +jetpack or cl_movement_track_canjump
98 bool jumpheld = false;
101 if((PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) && !PHYS_CL_TRACK_CANJUMP(strafeplayer))
106 if((keys & KEY_JUMP) && !PHYS_TRACK_CANJUMP(strafeplayer))
111 static float onground_lasttime = 0;
112 static bool onslick_last = false;
113 static float turn_lasttime = 0;
114 static bool turn = false;
115 static float turnangle;
116 static float dt_update = 0;
117 static int dt_time = 0;
118 static float dt_sum = 0;
122 // doesn't get changed by ground timeout and isn't affected by jump input
123 bool real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
124 // doesn't get changed by ground timeout
125 bool real_onslick = false;
126 // if jump is held assume we are in air, avoids flickering of the hud when hitting the ground
127 bool onground = real_onground && !jumpheld;
128 bool onslick = real_onslick;
129 bool onground_expired;
131 // the hud will not work well while swimming
132 bool swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING;
133 // use local csqcmodel entity for this even when spectating, flickers too much otherwise
134 float speed = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337;
135 // only the local csqcplayer entity contains this information even when spectating
136 float maxspeed_mod = IS_DUCKED(csqcplayer) ? .5 : 1;
137 float maxspeed_phys = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer);
138 float maxspeed = !autocvar__hud_configure ? maxspeed_phys * maxspeed_mod : 320;
141 float maxaccel_phys = onground ? PHYS_ACCELERATE(strafeplayer) : PHYS_AIRACCELERATE(strafeplayer);
142 float maxaccel = !autocvar__hud_configure ? maxaccel_phys : 1;
143 // change the range from 0° - 360° to -180° - 180° to match how view_angle represents angles
144 float vel_angle = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0);
145 float view_angle = PHYS_INPUT_ANGLES(strafeplayer).y;
147 vector movement = PHYS_INPUT_MOVEVALUES(strafeplayer);
155 float speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit);
156 float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_speed_unit);
157 // use more decimals when displaying km or miles
158 int length_decimals = autocvar_hud_speed_unit >= 3 && autocvar_hud_speed_unit <= 5 ? 6 : 2;
159 float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
161 float shift_offset = 0;
162 bool straight_overturn = false;
163 bool immobile = speed <= 0;
166 float neutral_offset;
168 vector currentangle_color = autocvar_hud_panel_strafehud_angle_neutral_color;
169 float currentangle_offset;
170 vector currentangle_size;
174 float bestangle_offset;
175 float switch_bestangle_offset;
176 bool odd_angles = false;
177 float odd_bestangle_offset = 0;
178 float switch_odd_bestangle_offset = 0;
179 float bestangle_width;
180 float accelzone_left_offset;
181 float accelzone_right_offset;
182 float accelzone_width;
183 float preaccelzone_left_offset;
184 float preaccelzone_right_offset;
185 float preaccelzone_width;
186 float overturn_offset;
187 float overturn_width;
188 float slickdetector_height;
189 vector direction_size_vertical;
190 vector direction_size_horizontal;
191 float range_minangle;
192 float text_offset_top = 0;
193 float text_offset_bottom = 0;
195 // real_* variables which are always positive with no wishangle offset
196 float real_bestangle;
197 float real_prebestangle;
199 if(autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1)
200 mode = autocvar_hud_panel_strafehud_mode;
202 mode = STRAFEHUD_MODE_VIEW_CENTERED;
204 // there's only one size cvar for the arrows, they will always have a 45° angle to ensure proper rendering without antialiasing
205 float arrow_size = max(panel_size.y * min(autocvar_hud_panel_strafehud_angle_arrow_size, 10), 0);
209 if(PHYS_FRICTION(strafeplayer) == 0)
213 else // don't use IS_ONSLICK(), it only works for the local player and only if client prediction is enabled
215 trace_dphitq3surfaceflags = 0;
216 tracebox(strafeplayer.origin, strafeplayer.mins, strafeplayer.maxs, strafeplayer.origin - '0 0 1', MOVE_NOMONSTERS, strafeplayer);
217 onslick = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK);
219 real_onslick = onslick;
221 onground_lasttime = time;
222 onslick_last = onslick;
224 else if(jumpheld || swimming)
226 onground_lasttime = 0;
229 if(onground_lasttime == 0)
230 onground_expired = true;
232 onground_expired = (time - onground_lasttime) >= autocvar_hud_panel_strafehud_timeout_ground; // timeout for slick ramps
234 if(!onground && !onground_expired) // if ground timeout hasn't expired yet use ground physics
237 onslick = onslick_last;
239 if(!autocvar__hud_configure)
241 maxspeed = PHYS_MAXSPEED(strafeplayer) * maxspeed_mod;
242 maxaccel = PHYS_ACCELERATE(strafeplayer);
246 movespeed = vlen(vec2(movement));
248 movespeed = maxspeed;
250 movespeed = min(movespeed, maxspeed);
252 if(!autocvar_hud_panel_strafehud_uncapped)
253 arrow_size = max(arrow_size, 1);
255 // determine frametime
256 if((csqcplayer_status == CSQCPLAYERSTATUS_PREDICTED) && (input_timelength > 0))
258 float dt_client = input_timelength;
260 if(dt_client > .05) // server splits frames longer than 50 ms into two moves
261 dt_client /= 2; // doesn't ensure frames are smaller than 50 ms, just splits large frames in half, matches server behaviour
263 // calculate average frametime
264 dt_sum += dt_client * dt_client;
265 dt_time += dt_client;
267 if(((time - dt_update) > autocvar_hud_panel_strafehud_fps_update) || (dt_update == 0))
269 dt = dt_sum / dt_time;
271 dt_time = dt_sum = 0;
274 else // when spectating other players server ticrate will be used, this may not be accurate but there is no way to find other player's frametime
277 dt_update = dt_time = dt_sum = 0;
280 // determine whether the player is pressing forwards or backwards keys
281 if(islocal) // if entity is local player
284 keys_fwd = STRAFEHUD_KEYS_FORWARD;
285 else if(movement.x < 0)
286 keys_fwd = STRAFEHUD_KEYS_BACKWARD;
288 keys_fwd = STRAFEHUD_KEYS_NONE;
290 else // alternatively determine direction by querying pressed keys
292 if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD))
293 keys_fwd = STRAFEHUD_KEYS_FORWARD;
294 else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD))
295 keys_fwd = STRAFEHUD_KEYS_BACKWARD;
297 keys_fwd = STRAFEHUD_KEYS_NONE;
300 // determine player wishdir
301 if(islocal) // if entity is local player
307 else if(movement.y > 0)
320 wishangle = RAD2DEG * atan2(movement.y, movement.x);
321 // wrap the wish angle if it exceeds ±90°
322 if(fabs(wishangle) > 90)
334 else // alternatively calculate wishdir by querying pressed keys
336 if((keys & KEY_FORWARD) || (keys & KEY_BACKWARD))
342 else if(!(keys & KEY_RIGHT))
343 wishangle = 0; // wraps at 180°
346 strafekeys = fabs(wishangle) > 45;
348 // determine minimum required angle to display full strafe range
349 range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree
350 if(range_minangle > 45) range_minangle = 45 - fabs(wishangle) % 45; // minimum angle range is 45
351 range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45
352 range_minangle *= 2; // multiply to accommodate for both sides of the hud
354 if(autocvar_hud_panel_strafehud_range == 0)
356 if(autocvar__hud_configure)
359 hudangle = range_minangle; // use minimum angle required if dynamically setting hud angle
363 hudangle = bound(0, fabs(autocvar_hud_panel_strafehud_range), 360); // limit HUD range to 360 degrees, higher values don't make sense
366 // detect air strafe turning
367 if((!strafekeys && vlen(vec2(movement)) > 0) || onground || autocvar__hud_configure)
371 else // air strafe only
373 bool turn_expired = (time - turn_lasttime) >= autocvar_hud_panel_strafehud_timeout_turn; // timeout for jumping with strafe keys only
377 else if(turn_expired)
380 if(turn) // CPMA turning
384 turn_lasttime = time;
385 turnangle = wishangle;
387 else // retain last state until strafe turning times out
389 wishangle = turnangle;
392 // calculate the maximum air strafe speed and acceleration
393 float strafity = 1 - (90 - fabs(wishangle)) / 45;
395 if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0)
396 maxspeed = min(maxspeed, GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer)));
398 movespeed = min(movespeed, maxspeed);
400 if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0)
401 maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer));
405 maxaccel *= dt * movespeed;
406 bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration
408 float frictionspeed; // speed lost from friction
409 float strafespeed; // speed minus friction
411 if((speed > 0) && onground)
413 float strafefriction = onslick ? PHYS_FRICTION_SLICK(strafeplayer) : PHYS_FRICTION(strafeplayer);
415 frictionspeed = speed * dt * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / speed, 1);
416 strafespeed = max(speed - frictionspeed, 0);
424 minspeed = autocvar_hud_panel_strafehud_switch_minspeed;
426 minspeed = bestspeed + frictionspeed;
428 // get current strafing angle ranging from -180° to +180°
429 if(!autocvar__hud_configure)
433 // calculate view angle relative to the players current velocity direction
434 angle = vel_angle - view_angle;
436 // if the angle goes above 180° or below -180° wrap it to the opposite side since we want the interior angle
439 else if(angle < -180)
442 // determine whether the player is strafing forwards or backwards
443 // if the player isn't strafe turning use forwards/backwards keys to determine direction
444 if(fabs(wishangle) != 90)
446 if(keys_fwd == STRAFEHUD_KEYS_FORWARD)
448 else if(keys_fwd == STRAFEHUD_KEYS_BACKWARD)
451 fwd = fabs(angle) <= 90;
453 // otherwise determine by examining the strafe angle
456 if(wishangle < 0) // detect direction using wishangle since the direction is not yet set
457 fwd = angle <= -wishangle;
459 fwd = angle >= -wishangle;
462 // shift the strafe angle by 180° when strafing backwards
471 // don't make the angle indicator switch side too much at ±180° if anti flicker is turned on
472 if(angle > (180 - antiflicker_angle) || angle < (-180 + antiflicker_angle))
473 straight_overturn = true;
481 else // simulate turning for HUD setup
483 const float demo_maxangle = 55; // maximum angle before changing direction
484 const float demo_turnspeed = 40; // turning speed in degrees per second
486 static float demo_position = -37 / demo_maxangle; // current positioning value between -1 and +1
488 if(autocvar__hud_panel_strafehud_demo)
490 float demo_dt = time - hud_lasttime;
491 float demo_step = (demo_turnspeed / demo_maxangle) * demo_dt;
492 demo_position = ((demo_position + demo_step) % 4 + 4) % 4;
495 // triangle wave function
496 if(demo_position > 3)
497 angle = -1 + (demo_position - 3);
498 else if(demo_position > 1)
499 angle = +1 - (demo_position - 1);
501 angle = demo_position;
502 angle *= demo_maxangle;
510 // invert the wish angle when strafing backwards
514 // flip angles if v_flipped is enabled
515 if(autocvar_v_flipped)
521 // determine whether the player is strafing left or right
524 direction = STRAFEHUD_DIRECTION_RIGHT;
526 else if(wishangle < 0)
528 direction = STRAFEHUD_DIRECTION_LEFT;
532 if(angle > antiflicker_angle && angle < (180 - antiflicker_angle))
533 direction = STRAFEHUD_DIRECTION_RIGHT;
534 else if(angle < -antiflicker_angle && angle > (-180 + antiflicker_angle))
535 direction = STRAFEHUD_DIRECTION_LEFT;
537 direction = STRAFEHUD_DIRECTION_NONE;
540 // best angle to strafe at
541 // in case of ground friction we may decelerate if the acceleration is smaller than the speed loss from friction
542 real_bestangle = bestangle = (strafespeed > bestspeed ? acos(bestspeed / strafespeed) * RAD2DEG : 0);
543 real_prebestangle = prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG : 0);
544 if(direction == STRAFEHUD_DIRECTION_LEFT) // the angle becomes negative in case we strafe left
549 odd_bestangle = -bestangle - wishangle;
550 bestangle -= wishangle;
551 prebestangle -= wishangle;
553 // various offsets and size calculations of hud indicator elements
554 // how much is hidden by the current hud angle
555 hidden_width = (360 - hudangle) / hudangle * panel_size.x;
558 currentangle_size.x = autocvar_hud_panel_strafehud_angle_width;
559 currentangle_size.y = autocvar_hud_panel_strafehud_angle_height;
560 currentangle_size.z = 0;
561 if(!autocvar_hud_panel_strafehud_uncapped)
563 currentangle_size.x = min(currentangle_size.x, 10);
564 currentangle_size.y = min(currentangle_size.y, 10);
566 currentangle_size.x *= panel_size.x;
567 currentangle_size.y *= panel_size.y;
568 if(!autocvar_hud_panel_strafehud_uncapped)
570 currentangle_size.x = max(currentangle_size.x, 1);
571 currentangle_size.y = max(currentangle_size.y, 1);
575 currentangle_size.y = max(currentangle_size.y, 0);
577 if(mode == STRAFEHUD_MODE_VIEW_CENTERED)
578 currentangle_offset = angle / hudangle * panel_size.x;
581 currentangle_offset = bound(-hudangle / 2, angle, hudangle / 2) / hudangle * panel_size.x + panel_size.x / 2;
583 // best strafe acceleration angle
584 bestangle_offset = bestangle / hudangle * panel_size.x + panel_size.x / 2;
585 switch_bestangle_offset = -bestangle / hudangle * panel_size.x + panel_size.x / 2;
586 bestangle_width = panel_size.x * autocvar_hud_panel_strafehud_switch_width;
587 if(!autocvar_hud_panel_strafehud_uncapped)
588 bestangle_width = max(bestangle_width, 1);
590 if((angle > -wishangle && direction == STRAFEHUD_DIRECTION_LEFT) || (angle < -wishangle && direction == STRAFEHUD_DIRECTION_RIGHT))
593 odd_bestangle_offset = odd_bestangle / hudangle * panel_size.x + panel_size.x / 2;
594 switch_odd_bestangle_offset = (odd_bestangle + bestangle * 2) / hudangle * panel_size.x + panel_size.x / 2;
596 // direction indicator
597 direction_size_vertical.x = autocvar_hud_panel_strafehud_direction_width;
598 if(!autocvar_hud_panel_strafehud_uncapped)
599 direction_size_vertical.x = min(direction_size_vertical.x, 1);
600 direction_size_vertical.x *= panel_size.y;
601 if(!autocvar_hud_panel_strafehud_uncapped)
602 direction_size_vertical.x = max(direction_size_vertical.x, 1);
603 direction_size_vertical.y = panel_size.y + direction_size_vertical.x * 2;
604 direction_size_vertical.z = 0;
605 direction_size_horizontal.x = panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5);
606 direction_size_horizontal.y = direction_size_vertical.x;
607 direction_size_horizontal.z = 0;
609 // the neutral zone fills the whole strafe bar
613 if(panel_size.x > 0 && panel_size.y > 0 && autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha > 0)
615 switch(autocvar_hud_panel_strafehud_style)
618 case STRAFEHUD_STYLE_DRAWFILL:
620 panel_pos, panel_size,
621 autocvar_hud_panel_strafehud_bar_neutral_color,
622 autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha,
626 case STRAFEHUD_STYLE_PROGRESSBAR:
627 HUD_Panel_DrawProgressBar(
628 panel_pos, panel_size, "progressbar", 1, 0, 0,
629 autocvar_hud_panel_strafehud_bar_neutral_color,
630 autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha,
637 // calculate various zones of the strafe-o-meter
638 if(autocvar_hud_panel_strafehud_bar_preaccel)
639 preaccelzone_width = (fabs(bestangle - prebestangle)) / hudangle * panel_size.x;
641 preaccelzone_width = 0;
642 accelzone_width = (90 - fabs(bestangle + wishangle)) / hudangle * panel_size.x;
643 overturn_width = 180 / hudangle * panel_size.x;
644 neutral_width = 360 / hudangle * panel_size.x - accelzone_width * 2 - preaccelzone_width * 2 - overturn_width;
647 float current_offset = 0;
648 preaccelzone_right_offset = current_offset;
649 current_offset += preaccelzone_width;
651 accelzone_right_offset = current_offset;
652 current_offset += accelzone_width;
654 overturn_offset = current_offset;
655 current_offset += overturn_width;
657 accelzone_left_offset = current_offset;
658 current_offset += accelzone_width;
660 preaccelzone_left_offset = current_offset;
661 current_offset += preaccelzone_width;
663 // the wrapping code may struggle if we always append it on the right side
664 neutral_offset = direction == STRAFEHUD_DIRECTION_LEFT ? current_offset : -neutral_width;
667 // shift hud if operating in view angle centered mode
668 if(mode == STRAFEHUD_MODE_VIEW_CENTERED)
670 shift_offset = -currentangle_offset;
671 bestangle_offset += shift_offset;
672 switch_bestangle_offset += shift_offset;
673 odd_bestangle_offset += shift_offset;
674 switch_odd_bestangle_offset += shift_offset;
676 if(direction == STRAFEHUD_DIRECTION_LEFT)
677 shift_offset += -360 / hudangle * panel_size.x;
679 // calculate how far off-center the strafe zones currently are
680 shift_offset += (panel_size.x + neutral_width) / 2 - wishangle / hudangle * panel_size.x;
682 // shift strafe zones into correct place
683 neutral_offset += shift_offset;
684 accelzone_left_offset += shift_offset;
685 accelzone_right_offset += shift_offset;
686 preaccelzone_left_offset += shift_offset;
687 preaccelzone_right_offset += shift_offset;
688 overturn_offset += shift_offset;
690 // draw left acceleration zone
691 HUD_Panel_DrawStrafeHUD(
692 accelzone_left_offset, accelzone_width, hidden_width,
693 autocvar_hud_panel_strafehud_bar_accel_color,
694 autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha,
695 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT);
697 if(autocvar_hud_panel_strafehud_bar_preaccel)
698 HUD_Panel_DrawStrafeHUD(
699 preaccelzone_left_offset, preaccelzone_width, hidden_width,
700 autocvar_hud_panel_strafehud_bar_accel_color,
701 autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha,
702 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT);
704 // draw right acceleration zone
705 HUD_Panel_DrawStrafeHUD(
706 accelzone_right_offset, accelzone_width, hidden_width,
707 autocvar_hud_panel_strafehud_bar_accel_color,
708 autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha,
709 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT);
711 if(autocvar_hud_panel_strafehud_bar_preaccel)
712 HUD_Panel_DrawStrafeHUD(
713 preaccelzone_right_offset, preaccelzone_width, hidden_width,
714 autocvar_hud_panel_strafehud_bar_accel_color,
715 autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha,
716 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT);
718 // draw overturn zone
719 // this is technically incorrect
720 // acceleration decreases at 90 degrees but speed loss happens a little bit after 90 degrees,
721 // however due to sv_airstopaccelerate that's hard to calculate
722 HUD_Panel_DrawStrafeHUD(
723 overturn_offset, overturn_width, hidden_width,
724 autocvar_hud_panel_strafehud_bar_overturn_color,
725 autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha,
726 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_BOTH);
729 HUD_Panel_DrawStrafeHUD(
730 neutral_offset, neutral_width, hidden_width,
731 autocvar_hud_panel_strafehud_bar_neutral_color,
732 autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha,
733 autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_NONE);
735 // only draw indicators if minspeed is reached
736 if(autocvar_hud_panel_strafehud_switch && speed >= minspeed && bestangle_width > 0 && autocvar_hud_panel_strafehud_switch_alpha > 0)
738 // draw the switch indicator(s)
739 float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset;
740 float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset;
742 // remove switch indicator width from offset
743 if(direction == STRAFEHUD_DIRECTION_LEFT)
746 offset -= bestangle_width;
748 switch_offset -= bestangle_width;
753 switch_offset -= bestangle_width;
755 offset -= bestangle_width;
758 HUD_Panel_DrawStrafeHUD(
759 switch_offset, bestangle_width, hidden_width,
760 autocvar_hud_panel_strafehud_switch_color,
761 autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha,
762 STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE);
764 if(direction == STRAFEHUD_DIRECTION_NONE)
765 HUD_Panel_DrawStrafeHUD(
766 offset, bestangle_width, hidden_width,
767 autocvar_hud_panel_strafehud_switch_color,
768 autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha,
769 STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE);
774 slickdetector_height = max(autocvar_hud_panel_strafehud_slickdetector_height, 0);
775 if(!autocvar_hud_panel_strafehud_uncapped)
776 slickdetector_height = min(slickdetector_height, 1);
777 slickdetector_height *= panel_size.y;
778 if(autocvar_hud_panel_strafehud_slickdetector &&
779 autocvar_hud_panel_strafehud_slickdetector_range > 0 &&
780 autocvar_hud_panel_strafehud_slickdetector_alpha > 0 &&
781 slickdetector_height > 0 &&
784 float slicksteps = max(autocvar_hud_panel_strafehud_slickdetector_granularity, 0);
785 bool slickdetected = false;
787 if(!autocvar_hud_panel_strafehud_uncapped)
788 slicksteps = min(slicksteps, 4);
789 slicksteps = 90 / 2 ** slicksteps;
791 slickdetected = real_onslick; // don't need to traceline if already touching slick
793 // traceline into every direction
794 trace_dphitq3surfaceflags = 0;
795 vector traceorigin = strafeplayer.origin + eZ * strafeplayer.mins.z;
796 for(float i = 0; i < 90 && !slickdetected; i += slicksteps)
800 slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
801 slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
803 for(float j = 0; j < 360 && !slickdetected; j += slicksteps)
805 slickoffset.x = sin(j * DEG2RAD) * slickrotate;
806 slickoffset.y = cos(j * DEG2RAD) * slickrotate;
808 traceline(traceorigin, traceorigin + slickoffset, MOVE_NOMONSTERS, strafeplayer);
809 if((PHYS_FRICTION(strafeplayer) == 0 && trace_fraction < 1)
810 || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK))
811 slickdetected = true;
817 // if a traceline hit a slick surface
820 vector slickdetector_size = panel_size;
821 slickdetector_size.y = slickdetector_height;
823 // top horizontal line
825 panel_pos - eY * slickdetector_size.y, slickdetector_size,
826 autocvar_hud_panel_strafehud_slickdetector_color,
827 autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha,
830 // bottom horizontal line
832 panel_pos + eY * panel_size.y,
833 slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color,
834 autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha,
838 text_offset_top = text_offset_bottom = slickdetector_height;
841 if(autocvar_hud_panel_strafehud_direction &&
842 direction != STRAFEHUD_DIRECTION_NONE &&
843 direction_size_vertical.x > 0 &&
844 autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha > 0)
846 bool indicator_direction = direction == STRAFEHUD_DIRECTION_LEFT;
847 // invert left/right when strafing backwards or when strafing towards the opposite side indicated by the direction variable
848 // if both conditions are true then it's inverted twice hence not inverted at all
849 if(!fwd != odd_angles)
850 indicator_direction = !indicator_direction;
852 // draw the direction indicator caps at the sides of the hud
854 if(direction_size_vertical.y > 0)
856 panel_pos - eY * direction_size_horizontal.y + eX * (indicator_direction ? -direction_size_vertical.x : panel_size.x),
857 direction_size_vertical, autocvar_hud_panel_strafehud_direction_color,
858 autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha,
861 // top horizontal line
863 panel_pos + eX * (indicator_direction ? 0 : panel_size.x - direction_size_horizontal.x) - eY * direction_size_horizontal.y,
864 direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color,
865 autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha,
868 // bottom horizontal line
870 panel_pos + eX * (indicator_direction ? 0 : panel_size.x - direction_size_horizontal.x) + eY * panel_size.y,
871 direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color,
872 autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha,
876 // draw the actual strafe angle
879 float moveangle = fabs(angle + wishangle);
880 float strafe_ratio = 0;
882 // player is overturning
885 currentangle_color = autocvar_hud_panel_strafehud_angle_overturn_color;
886 strafe_ratio = (moveangle - 90) / 90;
887 if(strafe_ratio > 1) strafe_ratio = 2 - strafe_ratio;
890 // player gains speed by strafing
891 else if(moveangle >= real_bestangle)
893 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
894 strafe_ratio = (90 - moveangle) / (90 - real_bestangle);
896 else if(moveangle >= real_prebestangle)
898 if(autocvar_hud_panel_strafehud_bar_preaccel)
899 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
900 strafe_ratio = (moveangle - real_prebestangle) / (real_bestangle - real_prebestangle);
903 if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT)
904 currentangle_color = StrafeHUD_mixColors(autocvar_hud_panel_strafehud_angle_neutral_color, currentangle_color, fabs(strafe_ratio));
907 if(mode == STRAFEHUD_MODE_VIEW_CENTERED || straight_overturn)
908 currentangle_offset = panel_size.x / 2;
910 float angleheight_offset = currentangle_size.y;
911 float ghost_offset = 0;
912 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
913 ghost_offset = bound(0, (odd_angles ? odd_bestangle_offset : bestangle_offset), panel_size.x);
915 switch(autocvar_hud_panel_strafehud_angle_style)
917 case STRAFEHUD_INDICATOR_SOLID:
918 if(currentangle_size.x > 0 && currentangle_size.y > 0)
920 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
922 panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (ghost_offset - currentangle_size.x / 2),
923 currentangle_size, autocvar_hud_panel_strafehud_bestangle_color,
924 autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha,
927 panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x / 2),
928 currentangle_size, currentangle_color,
929 autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha,
933 case STRAFEHUD_INDICATOR_DASHED:
934 if(currentangle_size.x > 0 && currentangle_size.y > 0)
936 vector line_size = currentangle_size;
937 line_size.y = currentangle_size.y / (bound(2, autocvar_hud_panel_strafehud_angle_dashes, currentangle_size.y) * 2 - 1);
938 for(float i = 0; i < currentangle_size.y; i += line_size.y * 2)
940 if(i + line_size.y * 2 >= currentangle_size.y)
941 line_size.y = currentangle_size.y - i;
942 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
944 panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (ghost_offset - line_size.x / 2),
945 line_size, autocvar_hud_panel_strafehud_bestangle_color,
946 autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
948 panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (currentangle_offset - line_size.x / 2),
949 line_size, currentangle_color,
950 autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
954 case STRAFEHUD_INDICATOR_NONE:
956 // don't offset text and arrows if the angle indicator line isn't drawn
957 angleheight_offset = panel_size.y;
958 currentangle_size = '0 0 0';
961 float angle_offset_top = 0, angle_offset_bottom = 0;
963 // offset text if any angle indicator is drawn
964 if((autocvar_hud_panel_strafehud_angle_alpha > 0) ||
965 (autocvar_hud_panel_strafehud_bestangle && autocvar_hud_panel_strafehud_bestangle_alpha > 0))
967 // offset text by amount the angle indicator extrudes from the strafehud bar
968 angle_offset_top = angle_offset_bottom = (angleheight_offset - panel_size.y) / 2;
971 if(autocvar_hud_panel_strafehud_angle_arrow > 0)
975 if(autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3)
977 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
978 StrafeHUD_drawStrafeArrow(
979 panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * ghost_offset,
980 arrow_size, autocvar_hud_panel_strafehud_bestangle_color,
981 autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, true, currentangle_size.x);
982 StrafeHUD_drawStrafeArrow(
983 panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * currentangle_offset,
984 arrow_size, currentangle_color,
985 autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, true, currentangle_size.x);
987 angle_offset_top += arrow_size; // further offset the top text offset if the top arrow is drawn
989 if(autocvar_hud_panel_strafehud_angle_arrow >= 2)
991 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
992 StrafeHUD_drawStrafeArrow(
993 panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * ghost_offset,
994 arrow_size, autocvar_hud_panel_strafehud_bestangle_color,
995 autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, false, currentangle_size.x);
996 StrafeHUD_drawStrafeArrow(
997 panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * currentangle_offset,
998 arrow_size, currentangle_color,
999 autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, false, currentangle_size.x);
1001 angle_offset_bottom += arrow_size; // further offset the bottom text offset if the bottom arrow is drawn
1006 // make sure text doesn't draw inside the strafehud bar
1007 text_offset_top = max(angle_offset_top, text_offset_top);
1008 text_offset_bottom = max(angle_offset_bottom, text_offset_bottom);
1010 draw_beginBoldFont();
1012 // show speed when crossing the start trigger
1014 static float startspeed = 0, starttime = 0; // displayed value and timestamp for fade out
1016 // check if the start trigger was hit (will also trigger if the finish trigger was hit if those have the same ID)
1017 if((race_nextcheckpoint == 1) || (race_checkpoint == 254 && race_nextcheckpoint == 255))
1019 if((race_checkpointtime > 0) && (starttime != race_checkpointtime))
1021 starttime = race_checkpointtime;
1026 if(autocvar_hud_panel_strafehud_startspeed)
1028 float startspeed_height = autocvar_hud_panel_strafehud_startspeed_size * panel_size.y;
1029 string startspeed_text = ftos_decimals(startspeed * speed_conversion_factor, 2);
1030 if(autocvar_hud_panel_strafehud_unit_show)
1031 startspeed_text = strcat(startspeed_text, GetSpeedUnit(autocvar_hud_speed_unit));
1033 bool was_drawn = StrafeHUD_drawTextIndicator(
1034 startspeed_text, startspeed_height,
1035 autocvar_hud_panel_strafehud_startspeed_color,
1036 autocvar_hud_panel_strafehud_startspeed_fade,
1037 starttime, text_offset_bottom, STRAFEHUD_TEXT_BOTTOM);
1040 text_offset_bottom += startspeed_height;
1044 // show height achieved by a single jump
1045 // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc) but using velocity to calculate jump height would be
1046 // inaccurate in hud code (possibly different tick rate than physics, doesn't run when hud isn't drawn, rounding errors)
1048 static float height_min = 0, height_max = 0; // ground and peak of jump z coordinates
1049 static float jumpheight = 0, jumptime = 0; // displayed value and timestamp for fade out
1051 // tries to catch kill and spectate but those are not reliable
1052 if((strafeplayer.velocity.z <= 0) || real_onground || swimming || IS_DEAD(strafeplayer) || !IS_PLAYER(strafeplayer))
1054 height_min = height_max = strafeplayer.origin.z;
1056 else if(strafeplayer.origin.z > height_max)
1058 height_max = strafeplayer.origin.z;
1059 float jumpheight_new = height_max - height_min;
1061 if((jumpheight_new * length_conversion_factor) > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
1063 jumpheight = jumpheight_new;
1068 if(autocvar_hud_panel_strafehud_jumpheight)
1070 float jumpheight_height = autocvar_hud_panel_strafehud_jumpheight_size * panel_size.y;
1071 string jumpheight_text = ftos_decimals(jumpheight * length_conversion_factor, length_decimals);
1072 if(autocvar_hud_panel_strafehud_unit_show)
1073 jumpheight_text = strcat(jumpheight_text, GetLengthUnit(autocvar_hud_speed_unit));
1075 bool was_drawn = StrafeHUD_drawTextIndicator(
1076 jumpheight_text, jumpheight_height,
1077 autocvar_hud_panel_strafehud_jumpheight_color,
1078 autocvar_hud_panel_strafehud_jumpheight_fade,
1079 jumptime, text_offset_top, STRAFEHUD_TEXT_TOP);
1082 text_offset_top += jumpheight_height;
1088 hud_lasttime = time;
1091 // functions to make hud elements align perfectly in the hud area
1092 void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vector color, float alpha, int type, int gradientType)
1094 float mirror_offset, mirror_width;
1095 vector size = panel_size;
1096 vector mirror_size = panel_size;
1097 float overflow_width = 0, overflow_mirror_width = 0;
1098 float original_width = width; // required for gradient
1100 if(type == STRAFEHUD_STYLE_GRADIENT && gradientType == STRAFEHUD_GRADIENT_NONE)
1101 type = STRAFEHUD_STYLE_DRAWFILL;
1103 if(alpha <= 0 && type != STRAFEHUD_STYLE_GRADIENT || width <= 0)
1108 mirror_width = min(fabs(offset), width);
1109 mirror_offset = panel_size.x + hidden_width - fabs(offset);
1115 mirror_width = min(offset + width - panel_size.x - hidden_width, width);
1116 mirror_offset = max(offset - panel_size.x - hidden_width, 0);
1119 width = max(width, 0);
1120 if((offset + width) > panel_size.x)
1122 overflow_width = (offset + width) - panel_size.x;
1123 width = panel_size.x - offset;
1127 if(mirror_offset < 0)
1129 mirror_width += mirror_offset;
1133 mirror_width = max(mirror_width, 0);
1134 if((mirror_offset + mirror_width) > panel_size.x)
1136 overflow_mirror_width = (mirror_offset + mirror_width) - panel_size.x;
1137 mirror_width = panel_size.x - mirror_offset;
1139 mirror_size.x = mirror_width;
1144 case STRAFEHUD_STYLE_DRAWFILL: // no styling (drawfill)
1145 if(mirror_size.x > 0 && mirror_size.y > 0)
1146 drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha, DRAWFLAG_NORMAL);
1147 if(size.x > 0 && size.y > 0)
1148 drawfill(panel_pos + eX * offset, size, color, alpha, DRAWFLAG_NORMAL);
1151 case STRAFEHUD_STYLE_PROGRESSBAR: // progress bar style
1152 if(mirror_size.x > 0 && mirror_size.y > 0)
1153 HUD_Panel_DrawProgressBar(
1154 panel_pos + eX * mirror_offset,
1155 mirror_size, "progressbar",
1156 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
1157 if(size.x > 0 && size.y > 0)
1158 HUD_Panel_DrawProgressBar(
1159 panel_pos + eX * offset,
1160 size, "progressbar",
1161 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
1164 case STRAFEHUD_STYLE_GRADIENT: // gradient style (types: 1 = left, 2 = right, 3 = both)
1165 // determine whether the gradient starts in the mirrored or the non-mirrored area
1167 float gradient_offset, gradient_mirror_offset;
1169 if(offset == 0 && mirror_offset == 0)
1170 gradient_start = width > mirror_width ? 2 : 1;
1171 else if(offset == 0)
1173 else if(mirror_offset == 0)
1178 switch(gradient_start)
1181 case 0: // no offset required
1182 gradient_offset = gradient_mirror_offset = 0;
1184 case 1: // offset starts in non-mirrored area, mirrored area requires offset
1185 gradient_offset = 0;
1186 gradient_mirror_offset = original_width - (mirror_width + overflow_mirror_width);
1188 case 2: // offset starts in mirrored area, non-mirrored area requires offset
1189 gradient_offset = original_width - (width + overflow_width);
1190 gradient_mirror_offset = 0;
1193 StrafeHUD_drawGradient(
1194 color, autocvar_hud_panel_strafehud_bar_neutral_color,
1195 mirror_size, original_width, mirror_offset,
1196 alpha, gradient_mirror_offset, gradientType);
1198 StrafeHUD_drawGradient(
1199 color, autocvar_hud_panel_strafehud_bar_neutral_color,
1200 size, original_width, offset,
1201 alpha, gradient_offset, gradientType);
1205 vector StrafeHUD_mixColors(vector color1, vector color2, float ratio)
1208 if(ratio <= 0) return color1;
1209 if(ratio >= 1) return color2;
1210 mixedColor.x = color1.x + (color2.x - color1.x) * ratio;
1211 mixedColor.y = color1.y + (color2.y - color1.y) * ratio;
1212 mixedColor.z = color1.z + (color2.z - color1.z) * ratio;
1216 void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradientOffset, int gradientType)
1218 float color_ratio, alpha1, alpha2;
1219 vector segment_size = size;
1220 alpha1 = bound(0, alpha, 1);
1221 alpha2 = bound(0, autocvar_hud_panel_strafehud_bar_neutral_alpha, 1);
1222 if((alpha1 + alpha2) == 0) return;
1223 color_ratio = alpha1 / (alpha1 + alpha2);
1224 for(int i = 0; i < size.x; ++i)
1226 float ratio, alpha_ratio, combine_ratio1, combine_ratio2;
1227 segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining
1228 ratio = (i + segment_size.x / 2 + gradientOffset) / original_width * (gradientType == STRAFEHUD_GRADIENT_BOTH ? 2 : 1);
1229 if(ratio > 1) ratio = 2 - ratio;
1230 if(gradientType != STRAFEHUD_GRADIENT_RIGHT) ratio = 1 - ratio;
1231 alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio;
1232 combine_ratio1 = ratio * (1 - color_ratio);
1233 combine_ratio2 = (1 - ratio) * color_ratio;
1234 ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1 / (combine_ratio1 + combine_ratio2);
1238 panel_pos + eX * (offset + i),
1240 StrafeHUD_mixColors(color1, color2, ratio),
1246 // draw the strafe arrows (inspired by drawspritearrow() in common/mutators/mutator/waypoints/waypointsprites.qc)
1247 void StrafeHUD_drawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped, float connection_width)
1249 origin = HUD_Shift(origin);
1250 float width = HUD_ScaleX(size * 2 + connection_width);
1251 float height = HUD_ScaleY(size);
1252 if(flipped) origin -= size * eY;
1253 R_BeginPolygon("", DRAWFLAG_NORMAL, true);
1254 if(connection_width > 0)
1256 R_PolygonVertex(origin + (connection_width / 2 * eX) + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
1257 R_PolygonVertex(origin - (connection_width / 2 * eX) + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
1261 R_PolygonVertex(origin + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
1263 R_PolygonVertex(origin + (flipped ? '0 0 0' : height * eY) - (width / 2) * eX, '0 0 0', color, alpha);
1264 R_PolygonVertex(origin + (flipped ? '0 0 0' : height * eY) + (width / 2) * eX, '0 0 0', color, alpha);
1268 // draw a fading text indicator above or below the strafe meter, return true if something was displayed
1269 bool StrafeHUD_drawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, float offset, int position)
1271 if((height <= 0) || (lasttime <= 0) || (fadetime <= 0) || ((time - lasttime) >= fadetime))
1274 float alpha = cos(((time - lasttime) / fadetime) * 90 * DEG2RAD); // fade non-linear like the physics panel does
1275 vector size = panel_size;
1280 case STRAFEHUD_TEXT_TOP:
1284 case STRAFEHUD_TEXT_BOTTOM:
1285 offset += panel_size.y;
1289 drawstring_aspect(panel_pos + eY * offset, text, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1293 // length unit conversion (km and miles are only included to match the GetSpeedUnit* functions)
1294 float GetLengthUnitFactor(int length_unit)
1300 case 2: return 0.0254;
1301 case 3: return 0.0254 * 0.001;
1302 case 4: return 0.0254 * 0.001 * 0.6213711922;
1303 case 5: return 0.0254 * 0.001 * 0.5399568035;
1307 string GetLengthUnit(int length_unit)
1311 // translator-friendly strings without the initial space
1313 case 1: return strcat(" ", _("qu"));
1314 case 2: return strcat(" ", _("m"));
1315 case 3: return strcat(" ", _("km"));
1316 case 4: return strcat(" ", _("mi"));
1317 case 5: return strcat(" ", _("nmi"));