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)
62 panel_pos += '1 1 0' * panel_bg_padding;
63 panel_size -= '2 2 0' * panel_bg_padding;
66 // find out whether the local csqcmodel entity is valid
67 if(spectatee_status > 0 || isdemo())
70 strafeplayer = CSQCModel_server2csqc(player_localentnum - 1);
75 strafeplayer = csqcplayer;
79 if(csqcplayer && strafeplayer)
81 float strafe_waterlevel;
83 // check the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled
86 void old_contentstransition(int, int) = strafeplayer.contentstransition;
87 float old_watertype = strafeplayer.watertype;
88 float old_waterlevel = strafeplayer.waterlevel;
90 strafeplayer.contentstransition = func_null; // unset the contentstransition function if present
91 _Movetype_CheckWater(strafeplayer);
92 strafe_waterlevel = strafeplayer.waterlevel; // store the player waterlevel
95 strafeplayer.contentstransition = old_contentstransition;
96 strafeplayer.watertype = old_watertype;
97 strafeplayer.waterlevel = old_waterlevel;
101 static float onground_lasttime = 0;
102 static bool onslick_last = false;
103 static float turn_lasttime = 0;
104 static bool turn = false;
105 static float turnangle;
106 static float dt_update = 0;
107 static int dt_time = 0;
108 static float dt_sum = 0;
112 int keys = STAT(PRESSED_KEYS);
113 bool jumpheld = islocal ? (PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) : (keys & KEY_JUMP); // doesn't work in spectator mode if spectated player uses +jetpack
114 bool real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR); // doesn't get changed by ground timeout and isn't affected by jump input
115 bool real_onslick = false; // doesn't get changed by ground timeout
116 bool onground = real_onground && !jumpheld; // if jump is held assume we are in air
117 bool onslick = real_onslick;
118 bool onground_expired;
120 bool swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING; // the hud will not work well while swimming
121 float speed = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337; // use local csqcmodel entity for this even when spectating, flickers too much otherwise
122 float maxspeed_mod = IS_DUCKED(csqcplayer) ? .5 : 1; // only the local csqcplayer entity contains this information even when spectating
123 float maxspeed_phys = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer);
124 float maxspeed = !autocvar__hud_configure ? maxspeed_phys * maxspeed_mod : 320;
127 float maxaccel_phys = onground ? PHYS_ACCELERATE(strafeplayer) : PHYS_AIRACCELERATE(strafeplayer);
128 float maxaccel = !autocvar__hud_configure ? maxaccel_phys : 1;
129 float vel_angle = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0); // change the range from 0° - 360° to -180° - 180° to match how view_angle represents angles
130 float view_angle = PHYS_INPUT_ANGLES(strafeplayer).y;
132 vector movement = PHYS_INPUT_MOVEVALUES(strafeplayer);
139 int mode = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : STRAFEHUD_MODE_VIEW_CENTERED;
140 float speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_strafehud_unit);
141 float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_panel_strafehud_unit);
142 int length_decimals = autocvar_hud_panel_strafehud_unit >= 3 && autocvar_hud_panel_strafehud_unit <= 5 ? 6 : 2; // use more decimals when displaying km or miles
143 float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
145 float shift_offset = 0;
146 bool straight_overturn = false;
147 bool immobile = speed <= 0;
150 float neutral_offset;
152 vector currentangle_color = autocvar_hud_panel_strafehud_angle_neutral_color;
153 float currentangle_offset;
154 vector currentangle_size;
155 float real_bestangle; // positive with no wishangle offset
156 float real_prebestangle; // positive with no wishangle offset
160 float bestangle_offset;
161 float switch_bestangle_offset;
162 bool odd_angles = false;
163 float odd_bestangle_offset = 0;
164 float switch_odd_bestangle_offset = 0;
165 float bestangle_width;
166 float accelzone_left_offset;
167 float accelzone_right_offset;
168 float accelzone_width;
169 float preaccelzone_left_offset;
170 float preaccelzone_right_offset;
171 float preaccelzone_width;
172 float overturn_offset;
173 float overturn_width;
174 float slickdetector_height;
175 vector direction_size_vertical;
176 vector direction_size_horizontal;
177 float range_minangle;
178 float arrow_size = max(panel_size.y * min(autocvar_hud_panel_strafehud_angle_arrow_size, 10), 0); // there's only one size cvar for the arrows, they will always have a 45° angle to ensure proper rendering without antialiasing
182 if(PHYS_FRICTION(strafeplayer) == 0) {
185 else { // don't use IS_ONSLICK(), it only works for the local player and only if client prediction is enabled
186 trace_dphitq3surfaceflags = 0;
187 tracebox(strafeplayer.origin, strafeplayer.mins, strafeplayer.maxs, strafeplayer.origin - '0 0 1', MOVE_NOMONSTERS, strafeplayer);
188 onslick = trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK;
190 real_onslick = onslick;
192 onground_lasttime = time;
193 onslick_last = onslick;
195 else if(jumpheld || swimming) onground_lasttime = 0;
197 if(onground_lasttime == 0)
198 onground_expired = true;
200 onground_expired = (time - onground_lasttime) >= autocvar_hud_panel_strafehud_timeout_ground; // timeout for slick ramps
202 if(!onground && !onground_expired) // if ground timeout hasn't expired yet use ground physics
205 onslick = onslick_last;
207 if(!autocvar__hud_configure)
209 maxspeed = PHYS_MAXSPEED(strafeplayer) * maxspeed_mod;
210 maxaccel = PHYS_ACCELERATE(strafeplayer);
214 movespeed = vlen(vec2(movement));
215 if(movespeed == 0) movespeed = maxspeed;
216 else movespeed = min(movespeed, maxspeed);
218 if(!autocvar_hud_panel_strafehud_uncapped)
219 arrow_size = max(arrow_size, 1);
221 // determine frametime
222 if((csqcplayer_status == CSQCPLAYERSTATUS_PREDICTED) && (input_timelength > 0))
224 float dt_client = input_timelength;
226 if(dt_client > .05) // server splits frames longer than 50 ms into two moves
227 dt_client /= 2; // doesn't ensure frames are smaller than 50 ms, just splits large frames in half, matches server behaviour
229 // calculate average frametime
230 dt_sum += dt_client*dt_client;
231 dt_time += dt_client;
233 if(((time - dt_update) > autocvar_hud_panel_strafehud_fps_update) || (dt_update == 0))
235 dt = dt_sum / dt_time;
237 dt_time = dt_sum = 0;
240 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
243 dt_update = dt_time = dt_sum = 0;
246 // determine whether the player is pressing forwards or backwards keys
247 if(islocal) // if entity is local player
251 keys_fwd = STRAFEHUD_KEYS_FORWARD;
253 else if(movement.x < 0)
255 keys_fwd = STRAFEHUD_KEYS_BACKWARD;
259 keys_fwd = STRAFEHUD_KEYS_NONE;
262 else // alternatively determine direction by querying pressed keys
264 if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD))
266 keys_fwd = STRAFEHUD_KEYS_FORWARD;
268 else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD))
270 keys_fwd = STRAFEHUD_KEYS_BACKWARD;
274 keys_fwd = STRAFEHUD_KEYS_NONE;
278 // determine player wishdir
279 if(islocal) // if entity is local player
287 else if(movement.y > 0)
304 wishangle = RAD2DEG * atan2(movement.y, movement.x);
305 // wrap the wish angle if it exceeds ±90°
306 if(fabs(wishangle) > 90)
308 if(wishangle < 0) wishangle += 180;
309 else wishangle -= 180;
310 wishangle = -wishangle;
315 else // alternatively calculate wishdir by querying pressed keys
317 if(keys & KEY_FORWARD || keys & KEY_BACKWARD)
329 else if(!(keys & KEY_RIGHT))
331 wishangle = 0; // wraps at 180°
335 strafekeys = fabs(wishangle) > 45;
337 // determine minimum required angle to display full strafe range
338 range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree
339 if(range_minangle > 45) // minimum angle range is 45
341 range_minangle = 45 - fabs(wishangle) % 45;
343 range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45
344 range_minangle *= 2; // multiply to accommodate for both sides of the hud
346 if(autocvar_hud_panel_strafehud_range == 0)
348 if(autocvar__hud_configure)
354 hudangle = range_minangle; // use minimum angle required if dynamically setting hud angle
359 hudangle = bound(0, fabs(autocvar_hud_panel_strafehud_range), 360); // limit HUD range to 360 degrees, higher values don't make sense
362 // detect air strafe turning
363 if((!strafekeys && vlen(vec2(movement)) > 0) || onground || autocvar__hud_configure)
367 else // air strafe only
369 bool turn_expired = (time - turn_lasttime) >= autocvar_hud_panel_strafehud_timeout_turn; // timeout for jumping with strafe keys only
373 else if(turn_expired)
376 if(turn) // CPMA turning
380 turn_lasttime = time;
381 turnangle = wishangle;
383 else // retain last state until strafe turning times out
385 wishangle = turnangle;
388 // calculate the maximum air strafe speed and acceleration
389 float strafity = 1 - (90 - fabs(wishangle)) / 45;
391 if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0)
393 maxspeed = min(maxspeed, GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer)));
395 movespeed = min(movespeed, maxspeed);
397 if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0)
399 maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer));
404 maxaccel *= dt * movespeed;
405 bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration
407 float frictionspeed; // speed lost from friction
408 float strafespeed; // speed minus friction
410 if((speed > 0) && onground)
412 float strafefriction = onslick ? PHYS_FRICTION_SLICK(strafeplayer) : PHYS_FRICTION(strafeplayer);
414 frictionspeed = speed * dt * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / speed, 1);
415 strafespeed = max(speed - frictionspeed, 0);
423 minspeed = autocvar_hud_panel_strafehud_switch_minspeed;
424 if(minspeed < 0) minspeed = bestspeed + frictionspeed;
426 // get current strafing angle ranging from -180° to +180°
427 if(!autocvar__hud_configure)
431 // calculate view angle relative to the players current velocity direction
432 angle = vel_angle - view_angle;
434 // if the angle goes above 180° or below -180° wrap it to the opposite side since we want the interior angle
435 if (angle > 180) angle -= 360;
436 else if(angle < -180) angle += 360;
438 // determine whether the player is strafing forwards or backwards
439 // if the player isn't strafe turning use forwards/backwards keys to determine direction
440 if(fabs(wishangle) != 90)
442 if(keys_fwd == STRAFEHUD_KEYS_FORWARD)
446 else if(keys_fwd == STRAFEHUD_KEYS_BACKWARD)
452 fwd = fabs(angle) <= 90;
455 // otherwise determine by examining the strafe angle
458 if(wishangle < 0) // detect direction using wishangle since the direction is not yet set
460 fwd = angle <= -wishangle;
464 fwd = angle >= -wishangle;
468 // shift the strafe angle by 180° when strafing backwards
471 if(angle < 0) angle += 180;
475 // don't make the angle indicator switch side too much at ±180° if anti flicker is turned on
476 if(angle > (180 - antiflicker_angle) || angle < (-180 + antiflicker_angle))
478 straight_overturn = true;
487 else // simulate turning for HUD setup
489 const float demo_maxangle = 55; // maximum angle before changing direction
490 const float demo_turnspeed = 40; // turning speed in degrees per second
492 static float demo_position = -37 / demo_maxangle; // current positioning value between -1 and +1
494 if(autocvar__hud_panel_strafehud_demo)
496 float demo_dt = time - hud_lasttime;
497 float demo_step = (demo_turnspeed / demo_maxangle) * demo_dt;
498 demo_position = ((demo_position + demo_step) % 4 + 4) % 4;
501 // triangle wave function
502 if(demo_position > 3)
503 angle = -1 + (demo_position - 3);
504 else if(demo_position > 1)
505 angle = +1 - (demo_position - 1);
507 angle = demo_position;
508 angle *= demo_maxangle;
512 if(angle < 0) wishangle *= -1;
515 // invert the wish angle when strafing backwards
518 wishangle = -wishangle;
521 // flip angles if v_flipped is enabled
522 if(autocvar_v_flipped)
525 wishangle = -wishangle;
528 // determine whether the player is strafing left or right
531 direction = STRAFEHUD_DIRECTION_RIGHT;
533 else if(wishangle < 0)
535 direction = STRAFEHUD_DIRECTION_LEFT;
539 if(angle > antiflicker_angle && angle < (180 - antiflicker_angle))
540 direction = STRAFEHUD_DIRECTION_RIGHT;
541 else if(angle < -antiflicker_angle && angle > (-180 + antiflicker_angle))
542 direction = STRAFEHUD_DIRECTION_LEFT;
544 direction = STRAFEHUD_DIRECTION_NONE;
547 // best angle to strafe at
548 // in case of ground friction we may decelerate if the acceleration is smaller than the speed loss from friction
549 real_bestangle = bestangle = (strafespeed > bestspeed ? acos(bestspeed / strafespeed) * RAD2DEG : 0);
550 real_prebestangle = prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG : 0);
551 if(direction == STRAFEHUD_DIRECTION_LEFT) // the angle becomes negative in case we strafe left
556 odd_bestangle = -bestangle - wishangle;
557 bestangle -= wishangle;
558 prebestangle -= wishangle;
560 // various offsets and size calculations of hud indicator elements
561 // how much is hidden by the current hud angle
562 hidden_width = (360 - hudangle) / hudangle * panel_size.x;
564 currentangle_size.x = autocvar_hud_panel_strafehud_angle_width;
565 currentangle_size.y = autocvar_hud_panel_strafehud_angle_height;
566 currentangle_size.z = 0;
567 if(!autocvar_hud_panel_strafehud_uncapped)
569 currentangle_size.x = min(currentangle_size.x, 10);
570 currentangle_size.y = min(currentangle_size.y, 10);
572 currentangle_size.x *= panel_size.x;
573 currentangle_size.y *= panel_size.y;
574 if(!autocvar_hud_panel_strafehud_uncapped)
576 currentangle_size.x = max(currentangle_size.x, 1);
577 currentangle_size.y = max(currentangle_size.y, 1);
581 currentangle_size.y = max(currentangle_size.y, 0);
583 if(mode == STRAFEHUD_MODE_VIEW_CENTERED)
585 currentangle_offset = angle/hudangle * panel_size.x;
589 currentangle_offset = bound(-hudangle/2, angle, hudangle/2)/hudangle * panel_size.x + panel_size.x/2;
591 // best strafe acceleration angle
592 bestangle_offset = bestangle/hudangle * panel_size.x + panel_size.x/2;
593 switch_bestangle_offset = -bestangle/hudangle * panel_size.x + panel_size.x/2;
594 bestangle_width = panel_size.x * autocvar_hud_panel_strafehud_switch_width;
595 if(!autocvar_hud_panel_strafehud_uncapped)
596 bestangle_width = max(bestangle_width, 1);
598 if((angle > -wishangle && direction == STRAFEHUD_DIRECTION_LEFT) || (angle < -wishangle && direction == STRAFEHUD_DIRECTION_RIGHT))
601 odd_bestangle_offset = odd_bestangle/hudangle * panel_size.x + panel_size.x/2;
602 switch_odd_bestangle_offset = (odd_bestangle+bestangle*2)/hudangle * panel_size.x + panel_size.x/2;
604 // direction indicator
605 direction_size_vertical.x = autocvar_hud_panel_strafehud_direction_width;
606 if(!autocvar_hud_panel_strafehud_uncapped)
607 direction_size_vertical.x = min(direction_size_vertical.x, 1);
608 direction_size_vertical.x *= panel_size.y;
609 if(!autocvar_hud_panel_strafehud_uncapped)
610 direction_size_vertical.x = max(direction_size_vertical.x, 1);
611 direction_size_vertical.y = panel_size.y + direction_size_vertical.x*2;
612 direction_size_vertical.z = 0;
613 direction_size_horizontal.x = panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5);
614 direction_size_horizontal.y = direction_size_vertical.x;
615 direction_size_horizontal.z = 0;
617 // the neutral zone fills the whole strafe bar
621 if(panel_size.x > 0 && panel_size.y > 0 && autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha > 0)
623 switch(autocvar_hud_panel_strafehud_style)
626 case STRAFEHUD_STYLE_DRAWFILL:
627 drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
630 case STRAFEHUD_STYLE_PROGRESSBAR:
631 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);
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 neutral_offset = direction == STRAFEHUD_DIRECTION_LEFT ? current_offset : -neutral_width; // the wrapping code may struggle if we always append it on the right side
666 // shift hud if operating in view angle centered mode
667 if(mode == STRAFEHUD_MODE_VIEW_CENTERED)
669 shift_offset = -currentangle_offset;
670 bestangle_offset += shift_offset;
671 switch_bestangle_offset += shift_offset;
672 odd_bestangle_offset += shift_offset;
673 switch_odd_bestangle_offset += shift_offset;
675 if(direction == STRAFEHUD_DIRECTION_LEFT) shift_offset += -360/hudangle * panel_size.x;
676 // calculate how far off-center the strafe zones currently are
677 shift_offset += (panel_size.x + neutral_width)/2 - wishangle/hudangle * panel_size.x;
678 // shift strafe zones into correct place
679 neutral_offset += shift_offset;
680 accelzone_left_offset += shift_offset;
681 accelzone_right_offset += shift_offset;
682 preaccelzone_left_offset += shift_offset;
683 preaccelzone_right_offset += shift_offset;
684 overturn_offset += shift_offset;
686 // draw left acceleration zone
687 HUD_Panel_DrawStrafeHUD(accelzone_left_offset, accelzone_width, hidden_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT);
688 if(autocvar_hud_panel_strafehud_bar_preaccel)
689 HUD_Panel_DrawStrafeHUD(preaccelzone_left_offset, preaccelzone_width, hidden_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT);
691 // draw right acceleration zone
692 HUD_Panel_DrawStrafeHUD(accelzone_right_offset, accelzone_width, hidden_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT);
693 if(autocvar_hud_panel_strafehud_bar_preaccel)
694 HUD_Panel_DrawStrafeHUD(preaccelzone_right_offset, preaccelzone_width, hidden_width, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT);
696 // draw overturn zone (technically incorrect, acceleration decreases at 90 degrees but speed loss happens a little bit after 90 degrees, however due to sv_airstopaccelerate that's hard to calculate)
697 HUD_Panel_DrawStrafeHUD(overturn_offset, overturn_width, hidden_width, autocvar_hud_panel_strafehud_bar_overturn_color, autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_BOTH);
700 HUD_Panel_DrawStrafeHUD(neutral_offset, neutral_width, hidden_width, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_NONE);
702 if(speed >= minspeed && bestangle_width > 0 && autocvar_hud_panel_strafehud_switch_alpha > 0) // only draw indicators if minspeed is reached
704 // draw the switch indicator(s)
705 float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset;
706 float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset;
708 // remove switch indicator width from offset
709 if(direction == STRAFEHUD_DIRECTION_LEFT)
712 offset -= bestangle_width;
714 switch_offset -= bestangle_width;
719 switch_offset -= bestangle_width;
721 offset -= bestangle_width;
724 HUD_Panel_DrawStrafeHUD(switch_offset, bestangle_width, hidden_width, autocvar_hud_panel_strafehud_switch_color, autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha, STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE);
725 if(direction == STRAFEHUD_DIRECTION_NONE) HUD_Panel_DrawStrafeHUD(offset, bestangle_width, hidden_width, autocvar_hud_panel_strafehud_switch_color, autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha, STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE);
730 slickdetector_height = max(autocvar_hud_panel_strafehud_slickdetector_height, 0);
731 if(!autocvar_hud_panel_strafehud_uncapped)
732 slickdetector_height = min(slickdetector_height, 1);
733 slickdetector_height *= panel_size.y;
734 if(autocvar_hud_panel_strafehud_slickdetector_range > 0 && autocvar_hud_panel_strafehud_slickdetector_alpha > 0 && slickdetector_height > 0 && panel_size.x > 0)
736 float slicksteps = max(autocvar_hud_panel_strafehud_slickdetector_granularity, 0);
737 bool slickdetected = false;
739 if(!autocvar_hud_panel_strafehud_uncapped)
740 slicksteps = min(slicksteps, 4);
741 slicksteps = 90 / 2 ** slicksteps;
743 slickdetected = real_onslick; // don't need to traceline if already touching slick
745 // traceline into every direction
746 trace_dphitq3surfaceflags = 0;
747 vector traceorigin = strafeplayer.origin + eZ * strafeplayer.mins.z;
748 for(float i = 0; i < 360 && !slickdetected; i += slicksteps)
752 slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
753 slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
754 if(i != 0 && i != 180)
756 for(float j = 0; j < 180 && !slickdetected; j += slicksteps)
758 slickoffset.x = sin(j * DEG2RAD) * slickrotate;
759 slickoffset.y = cos(j * DEG2RAD) * slickrotate;
761 traceline(traceorigin, traceorigin + slickoffset, MOVE_NOMONSTERS, strafeplayer);
762 if((PHYS_FRICTION(strafeplayer) == 0 && trace_fraction < 1) || trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
767 slickoffset.x = slickoffset.y = 0;
768 traceline(traceorigin, traceorigin + slickoffset, MOVE_NOMONSTERS, strafeplayer);
769 if((PHYS_FRICTION(strafeplayer) == 0 && trace_fraction < 1) || trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
773 // if a traceline hit a slick surface
776 vector slickdetector_size = panel_size;
777 slickdetector_size.y = slickdetector_height;
778 // top horizontal line
779 drawfill(panel_pos - eY * slickdetector_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
780 // bottom horizontal line
781 drawfill(panel_pos + eY * panel_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
785 if(direction != STRAFEHUD_DIRECTION_NONE && direction_size_vertical.x > 0 && autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha > 0)
787 bool indicator_direction = direction == STRAFEHUD_DIRECTION_LEFT;
788 // invert left/right when strafing backwards or when strafing towards the opposite side indicated by the direction variable
789 // if both conditions are true then it's inverted twice hence not inverted at all
790 if(!fwd != odd_angles)
792 indicator_direction = !indicator_direction;
794 // draw the direction indicator caps at the sides of the hud
796 if(direction_size_vertical.y > 0) drawfill(panel_pos - eY * direction_size_horizontal.y + 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);
797 // top horizontal line
798 drawfill(panel_pos + eX * (indicator_direction ? 0 : panel_size.x - direction_size_horizontal.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);
799 // bottom horizontal line
800 drawfill(panel_pos + eX * (indicator_direction ? 0 : panel_size.x - direction_size_horizontal.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);
803 // draw the actual strafe angle
805 float moveangle = fabs(angle + wishangle);
806 float strafe_ratio = 0;
808 // player is overturning
811 currentangle_color = autocvar_hud_panel_strafehud_angle_overturn_color;
812 strafe_ratio = (moveangle - 90) / 90;
813 if(strafe_ratio > 1) strafe_ratio = 2 - strafe_ratio;
816 // player gains speed by strafing
817 else if(moveangle >= real_bestangle)
819 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
820 strafe_ratio = (90 - moveangle) / (90 - real_bestangle);
822 else if(moveangle >= real_prebestangle)
824 if(autocvar_hud_panel_strafehud_bar_preaccel)
825 currentangle_color = autocvar_hud_panel_strafehud_angle_accel_color;
826 strafe_ratio = (moveangle - real_prebestangle) / (real_bestangle - real_prebestangle);
829 if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT)
831 currentangle_color = StrafeHUD_mixColors(autocvar_hud_panel_strafehud_angle_neutral_color, currentangle_color, fabs(strafe_ratio));
835 if(mode == STRAFEHUD_MODE_VIEW_CENTERED || straight_overturn)
837 currentangle_offset = panel_size.x/2;
840 float angleheight_offset = currentangle_size.y;
841 float ghost_offset = 0;
842 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE)
844 ghost_offset = bound(0, (odd_angles ? odd_bestangle_offset : bestangle_offset), panel_size.x);
847 switch(autocvar_hud_panel_strafehud_angle_style)
849 case STRAFEHUD_INDICATOR_SOLID:
850 if(currentangle_size.x > 0 && currentangle_size.y > 0)
852 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE) drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (ghost_offset - currentangle_size.x/2), currentangle_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
853 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);
856 case STRAFEHUD_INDICATOR_DASHED:
857 if(currentangle_size.x > 0 && currentangle_size.y > 0)
859 vector line_size = currentangle_size;
860 line_size.y = currentangle_size.y / (bound(2, autocvar_hud_panel_strafehud_angle_dashes, currentangle_size.y)*2-1);
861 for(float i = 0; i < currentangle_size.y; i += line_size.y*2)
863 if(i + line_size.y*2 >= currentangle_size.y) line_size.y = currentangle_size.y - i;
864 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE) drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (ghost_offset - line_size.x/2), line_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
865 drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (currentangle_offset - line_size.x/2), line_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
869 case STRAFEHUD_INDICATOR_NONE:
871 // don't offset text and arrows if the angle indicator line isn't drawn
872 angleheight_offset = panel_size.y;
875 if(autocvar_hud_panel_strafehud_angle_arrow > 0)
879 if(autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3)
881 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE) StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * ghost_offset, arrow_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, true);
882 StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, true);
884 if(autocvar_hud_panel_strafehud_angle_arrow >= 2)
886 if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE) StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * ghost_offset, arrow_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, false);
887 StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, false);
892 draw_beginBoldFont();
893 // show speed when crossing the start trigger
894 if(autocvar_hud_panel_strafehud_startspeed_fade > 0 && autocvar_hud_panel_strafehud_startspeed_size > 0)
896 static float startspeed = 0, starttime = 0; // displayed value and timestamp for fade out
898 if((race_nextcheckpoint == 1) || (race_checkpoint == 254 && race_nextcheckpoint == 255)) // check if the start trigger was hit (will also trigger if the finish trigger was hit if those have the same ID)
900 if((race_checkpointtime > 0) && (starttime != race_checkpointtime))
902 starttime = race_checkpointtime;
907 if((starttime > 0) && ((time - starttime) <= autocvar_hud_panel_strafehud_startspeed_fade))
909 float text_alpha = cos(((time - starttime) / autocvar_hud_panel_strafehud_startspeed_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
910 vector startspeed_size = panel_size;
911 startspeed_size.y = autocvar_hud_panel_strafehud_startspeed_size;
912 if(!autocvar_hud_panel_strafehud_uncapped)
913 startspeed_size.y = min(startspeed_size.y, 10);
914 startspeed_size.y *= panel_size.y;
915 if(!autocvar_hud_panel_strafehud_uncapped)
916 startspeed_size.y = max(startspeed_size.y, 1);
918 float text_offset = 0;
919 if((autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0) || (autocvar_hud_panel_strafehud_bestangle && autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha > 0))
921 text_offset = (angleheight_offset - panel_size.y) / 2;
922 if(arrow_size > 0 && autocvar_hud_panel_strafehud_angle_arrow >= 2)
923 text_offset += arrow_size;
924 // make sure text doesn't draw inside the strafehud bar
925 text_offset = max(text_offset, 0);
928 string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit);
929 drawstring_aspect(panel_pos + eY * (panel_size.y + text_offset), strcat(ftos_decimals(startspeed * speed_conversion_factor, 2), autocvar_hud_panel_strafehud_unit_show ? speed_unit : ""), startspeed_size, autocvar_hud_panel_strafehud_startspeed_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
937 // show height achieved by a single jump
938 // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc) but using velocity to calculate jump height would be
939 // inaccurate in hud code (possibly different tick rate than physics, doesn't run when hud isn't drawn, rounding errors)
940 if(autocvar_hud_panel_strafehud_jumpheight_fade > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
942 static float height_min = 0, height_max = 0; // ground and peak of jump z coordinates
943 static float jumpheight = 0, jumptime = 0; // displayed value and timestamp for fade out
945 // tries to catch kill and spectate but those are not reliable
946 if((strafeplayer.velocity.z <= 0) || real_onground || swimming || IS_DEAD(strafeplayer) || !IS_PLAYER(strafeplayer))
948 height_min = height_max = strafeplayer.origin.z;
950 else if(strafeplayer.origin.z > height_max)
952 height_max = strafeplayer.origin.z;
953 float jumpheight_new = height_max - height_min;
955 if((jumpheight_new * length_conversion_factor) > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
957 jumpheight = jumpheight_new;
962 if((jumptime > 0) && ((time - jumptime) <= autocvar_hud_panel_strafehud_jumpheight_fade))
964 float text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
965 vector jumpheight_size = panel_size;
966 jumpheight_size.y = autocvar_hud_panel_strafehud_jumpheight_size;
967 if(!autocvar_hud_panel_strafehud_uncapped)
968 jumpheight_size.y = min(jumpheight_size.y, 10);
969 jumpheight_size.y *= panel_size.y;
970 if(!autocvar_hud_panel_strafehud_uncapped)
971 jumpheight_size.y = max(jumpheight_size.y, 1);
973 float text_offset = 0;
974 if((autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0) || (autocvar_hud_panel_strafehud_bestangle && autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha > 0))
976 text_offset = (angleheight_offset - panel_size.y) / 2;
977 if(arrow_size > 0 && autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3)
978 text_offset += arrow_size;
979 // make sure text doesn't draw inside the strafehud bar
980 text_offset = max(text_offset, 0);
983 string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit);
984 drawstring_aspect(panel_pos - eY * (jumpheight_size.y + text_offset), strcat(ftos_decimals(jumpheight * length_conversion_factor, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
996 // functions to make hud elements align perfectly in the hud area
997 void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vector color, float alpha, int type, int gradientType)
999 float mirror_offset, mirror_width;
1000 vector size = panel_size;
1001 vector mirror_size = panel_size;
1002 float overflow_width = 0, overflow_mirror_width = 0;
1003 float original_width = width; // required for gradient
1005 if(type == STRAFEHUD_STYLE_GRADIENT && gradientType == STRAFEHUD_GRADIENT_NONE) type = STRAFEHUD_STYLE_DRAWFILL;
1007 if(alpha <= 0 && type != STRAFEHUD_STYLE_GRADIENT || width <= 0) return;
1011 mirror_width = min(fabs(offset), width);
1012 mirror_offset = panel_size.x + hidden_width - fabs(offset);
1018 mirror_width = min(offset + width - panel_size.x - hidden_width, width);
1019 mirror_offset = max(offset - panel_size.x - hidden_width, 0);
1022 width = max(width, 0);
1023 if((offset + width) > panel_size.x)
1025 overflow_width = (offset + width) - panel_size.x;
1026 width = panel_size.x - offset;
1030 if(mirror_offset < 0)
1032 mirror_width += mirror_offset;
1036 mirror_width = max(mirror_width, 0);
1037 if((mirror_offset + mirror_width) > panel_size.x)
1039 overflow_mirror_width = (mirror_offset + mirror_width) - panel_size.x;
1040 mirror_width = panel_size.x - mirror_offset;
1042 mirror_size.x = mirror_width;
1047 case STRAFEHUD_STYLE_DRAWFILL: // no styling (drawfill)
1048 if(mirror_size.x > 0 && mirror_size.y > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha, DRAWFLAG_NORMAL);
1049 if(size.x > 0 && size.y > 0) drawfill(panel_pos + eX * offset, size, color, alpha, DRAWFLAG_NORMAL);
1052 case STRAFEHUD_STYLE_PROGRESSBAR: // progress bar style
1053 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);
1054 if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
1057 case STRAFEHUD_STYLE_GRADIENT: // gradient style (types: 1 = left, 2 = right, 3 = both)
1058 // determine whether the gradient starts in the mirrored or the non-mirrored area
1060 float gradient_offset, gradient_mirror_offset;
1062 if(offset == 0 && mirror_offset == 0) gradient_start = width > mirror_width ? 2 : 1;
1063 else if(offset == 0) gradient_start = 2;
1064 else if(mirror_offset == 0) gradient_start = 1;
1065 else gradient_start = 0;
1067 switch(gradient_start)
1070 case 0: // no offset required
1071 gradient_offset = gradient_mirror_offset = 0;
1073 case 1: // offset starts in non-mirrored area, mirrored area requires offset
1074 gradient_offset = 0;
1075 gradient_mirror_offset = original_width - (mirror_width + overflow_mirror_width);
1077 case 2: // offset starts in mirrored area, non-mirrored area requires offset
1078 gradient_offset = original_width - (width + overflow_width);
1079 gradient_mirror_offset = 0;
1082 StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, mirror_size, original_width, mirror_offset, alpha, gradient_mirror_offset, gradientType);
1083 StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, size, original_width, offset, alpha, gradient_offset, gradientType);
1087 vector StrafeHUD_mixColors(vector color1, vector color2, float ratio)
1090 if(ratio <= 0) return color1;
1091 if(ratio >= 1) return color2;
1092 mixedColor.x = color1.x + (color2.x - color1.x) * ratio;
1093 mixedColor.y = color1.y + (color2.y - color1.y) * ratio;
1094 mixedColor.z = color1.z + (color2.z - color1.z) * ratio;
1098 void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradientOffset, int gradientType)
1100 float color_ratio, alpha1, alpha2;
1101 vector segment_size = size;
1102 alpha1 = bound(0, alpha, 1);
1103 alpha2 = bound(0, autocvar_hud_panel_strafehud_bar_neutral_alpha, 1);
1104 if((alpha1+alpha2) == 0) return;
1105 color_ratio = alpha1/(alpha1+alpha2);
1106 for(int i = 0; i < size.x; ++i)
1108 float ratio, alpha_ratio, combine_ratio1, combine_ratio2;
1109 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
1110 ratio = (i + gradientOffset) / original_width * (gradientType == STRAFEHUD_GRADIENT_BOTH ? 2 : 1);
1111 if(ratio > 1) ratio = 2 - ratio;
1112 if(gradientType != STRAFEHUD_GRADIENT_RIGHT) ratio = 1 - ratio;
1113 alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio;
1114 combine_ratio1 = ratio*(1-color_ratio);
1115 combine_ratio2 = (1-ratio)*color_ratio;
1116 ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1/(combine_ratio1 + combine_ratio2);
1117 if(alpha_ratio > 0) drawfill(panel_pos + eX * (offset + i), segment_size, StrafeHUD_mixColors(color1, color2, ratio), alpha_ratio, DRAWFLAG_NORMAL);
1121 // draw the strafe arrows (inspired by drawspritearrow() in common/mutators/mutator/waypoints/waypointsprites.qc)
1122 void StrafeHUD_drawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped)
1124 origin = HUD_Shift(origin);
1125 size = HUD_ScaleX(size);
1126 if(flipped) origin -= size*eY;
1127 R_BeginPolygon("", DRAWFLAG_NORMAL, true);
1128 R_PolygonVertex(origin + (flipped ? size*eY : '0 0 0') , '0 0 0', color, alpha);
1129 R_PolygonVertex(origin + (flipped ? '0 0 0' : size*eY) - size*eX, '0 0 0', color, alpha);
1130 R_PolygonVertex(origin + (flipped ? '0 0 0' : size*eY) + size*eX, '0 0 0', color, alpha);
1134 // length unit conversion (km and miles are only included to match the GetSpeedUnit* functions)
1135 float GetLengthUnitFactor(int length_unit)
1141 case 2: return 0.0254;
1142 case 3: return 0.0254 * 0.001;
1143 case 4: return 0.0254 * 0.001 * 0.6213711922;
1144 case 5: return 0.0254 * 0.001 * 0.5399568035;
1148 string GetLengthUnit(int length_unit)
1152 // translator-friendly strings without the initial space
1154 case 1: return strcat(" ", _("qu"));
1155 case 2: return strcat(" ", _("m"));
1156 case 3: return strcat(" ", _("km"));
1157 case 4: return strcat(" ", _("mi"));
1158 case 5: return strcat(" ", _("nmi"));