]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/racetimer.qc
Merge branch 'master' into Mario/target_teleporter_v2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
index 2f54e2a37981bfa42c166fbe8ea18f1d7a5b7c42..6a190f2ca5f7c9b14c90590ed81f5227acc56bf0 100644 (file)
@@ -1,18 +1,19 @@
 #include "racetimer.qh"
 
+#include <client/autocvars.qh>
+#include <client/defs.qh>
+#include <client/miscfunctions.qh>
 #include <common/mapinfo.qh>
 
 // Race timer (#6)
 
 // return the string of the onscreen race timer
-string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
+string MakeRaceString(int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname)
 {
        TC(int, cp);
-       string col;
-       string timestr;
-       string cpname;
-       string lapstr;
-       lapstr = "";
+       string cpname, lapstr = "", timestr = "", col = "^7", othercol = "^7", othertimestr = "";
+       if(theirname == "" || !autocvar_cl_race_cptimes_showself)
+               othertime = 0; // don't count personal time
 
        if(theirtime == 0) // goal hit
        {
@@ -32,6 +33,22 @@ string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, str
                        col = "^2";
                }
 
+               if(othertime > 0)
+               {
+                       othertimestr = strcat("+", ftos_decimals(+othertime, TIME_DECIMALS));
+                       othercol = "^1";
+               }
+               else if(othertime == 0)
+               {
+                       othertimestr = "+0.0";
+                       othercol = "^3";
+               }
+               else
+               {
+                       othertimestr = strcat("-", ftos_decimals(-othertime, TIME_DECIMALS));
+                       othercol = "^2";
+               }
+
                if(lapdelta > 0)
                {
                        lapstr = sprintf(_(" (-%dL)"), lapdelta);
@@ -50,11 +67,11 @@ string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, str
                else
                        timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
                col = "^3";
-       }
-       else
-       {
-               col = "^7";
-               timestr = "";
+               if(mytime >= othertime)
+                       othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
+               else
+                       othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime));
+               othercol = "^7";
        }
 
        if(cp == 254)
@@ -70,6 +87,8 @@ string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, str
                return strcat(col, cpname);
        else if(theirname == "")
                return strcat(col, sprintf("%s (%s)", cpname, timestr));
+       else if(othertime)
+               return strcat(col, sprintf("%s %s(%s)%s (%s %s)", cpname, othercol, othertimestr, col, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
        else
                return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
 }
@@ -146,20 +165,24 @@ void HUD_RaceTimer ()
                        if(race_checkpoint != 254)
                        {
                                if(race_time && race_previousbesttime)
-                                       s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
+                                       s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, ((race_mypreviousbesttime) ? TIME_DECODE(race_time) - TIME_DECODE(race_mypreviousbesttime) : 0), 0, race_previousbestname);
                                else
-                                       s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
+                                       s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
                                if(race_time)
                                        forcetime = TIME_ENCODED_TOSTRING(race_time);
                        }
                }
                else
                {
-                       if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
+                       if(race_laptime && race_nextcheckpoint != 254)
                        {
-                               a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
-                               if(a > 0) // next one?
-                                       s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
+                               if(race_nextbesttime)
+                               {
+                                       a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
+                                       float a2 = ((race_mybesttime) ? bound(0, 2 - ((race_laptime + TIME_DECODE(race_mybesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1) : 0);
+                                       if(a > 0) // next one?
+                                               s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), ((a2 > 0) ? TIME_DECODE(race_mybesttime) : 0), 0, race_nextbestname);
+                               }
                        }
                }
 
@@ -205,14 +228,14 @@ void HUD_RaceTimer ()
                if(race_mycheckpointtime)
                {
                        a = bound(0, 2 - (time - race_mycheckpointtime), 1);
-                       s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
+                       s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), 0, race_mycheckpointlapsdelta, race_mycheckpointenemy);
                        str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
                        drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
                }
                if(race_othercheckpointtime && race_othercheckpointenemy != "")
                {
                        a = bound(0, 2 - (time - race_othercheckpointtime), 1);
-                       s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
+                       s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), 0, race_othercheckpointlapsdelta, race_othercheckpointenemy);
                        str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
                        drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
                }