From: Mario Date: Fri, 24 Jun 2016 06:32:32 +0000 (+1000) Subject: Show user selected speed unit in the CTS speed awards X-Git-Tag: xonotic-v0.8.2~700^2~134 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ab6972bb67b13140ab0a4b9aacb22289c118918c;p=xonotic%2Fxonotic-data.pk3dir.git Show user selected speed unit in the CTS speed awards --- diff --git a/qcsrc/client/defs.qh b/qcsrc/client/defs.qh index 84bcb2b3d..e62f0704f 100644 --- a/qcsrc/client/defs.qh +++ b/qcsrc/client/defs.qh @@ -47,8 +47,10 @@ string race_penaltyreason; // reason for penalty float race_server_record; // server record float race_speedaward; string race_speedaward_holder; +string race_speedaward_unit; float race_speedaward_alltimebest; string race_speedaward_alltimebest_holder; +string race_speedaward_alltimebest_unit; // RACE float race_mycheckpoint; diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index 371a9f344..af59e378e 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -43,34 +43,8 @@ void HUD_Physics() text_scale = min(autocvar_hud_panel_physics_text_scale, 1); //compute speed - float speed, conversion_factor; - string unit; - - switch(autocvar_hud_panel_physics_speed_unit) - { - default: - case 1: - unit = _(" qu/s"); - conversion_factor = 1.0; - break; - case 2: - unit = _(" m/s"); - conversion_factor = 0.0254; - break; - case 3: - unit = _(" km/h"); - conversion_factor = 0.0254 * 3.6; - break; - case 4: - unit = _(" mph"); - conversion_factor = 0.0254 * 3.6 * 0.6213711922; - break; - case 5: - unit = _(" knots"); - conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h - break; - } - + float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); + string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel); float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 ); diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 963cc9e41..53cf24b53 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -983,6 +983,42 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew) if (!postinit) PostInit(); } +float GetSpeedUnitFactor(int speed_unit) +{ + switch(speed_unit) + { + default: + case 1: + return 1.0; + case 2: + return 0.0254; + case 3: + return 0.0254 * 3.6; + case 4: + return 0.0254 * 3.6 * 0.6213711922; + case 5: + return 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h + } +} + +string GetSpeedUnit(int speed_unit) +{ + switch(speed_unit) + { + default: + case 1: + return _(" qu/s"); + case 2: + return _(" m/s"); + case 3: + return _(" km/h"); + case 4: + return _(" mph"); + case 5: + return _(" knots"); + } +} + NET_HANDLE(TE_CSQC_RACE, bool isNew) { int b = ReadByte(); @@ -1071,16 +1107,22 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_server_record = ReadInt24_t(); break; case RACE_NET_SPEED_AWARD: - race_speedaward = ReadInt24_t(); + race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); if(race_speedaward_holder) strunzone(race_speedaward_holder); race_speedaward_holder = strzone(ReadString()); + if(race_speedaward_unit) + strunzone(race_speedaward_unit); + race_speedaward_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_SPEED_AWARD_BEST: - race_speedaward_alltimebest = ReadInt24_t(); + race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); if(race_speedaward_alltimebest_holder) strunzone(race_speedaward_alltimebest_holder); race_speedaward_alltimebest_holder = strzone(ReadString()); + if(race_speedaward_alltimebest_unit) + strunzone(race_speedaward_alltimebest_unit); + race_speedaward_alltimebest_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_SERVER_RANKINGS: float prevpos, del; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 2fb239ba1..6db4e124f 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -1370,11 +1370,11 @@ void HUD_DrawScoreboard() if(gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE) { if(race_speedaward) { - drawcolorcodedstring(pos, sprintf(_("Speed award: %d ^7(%s^7)"), race_speedaward, race_speedaward_holder), hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL); + drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, race_speedaward_unit, race_speedaward_holder), hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL); pos.y += 1.25 * hud_fontsize.y; } if(race_speedaward_alltimebest) { - drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_holder), hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL); + drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_unit, race_speedaward_alltimebest_holder), hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL); pos.y += 1.25 * hud_fontsize.y; } pos = HUD_DrawScoreboardRankings(pos, playerslots[player_localnum], rgb, bg_size);