From c750c64372caf2ecacc17a5f9949c131b860e2b8 Mon Sep 17 00:00:00 2001 From: div0 Date: Wed, 18 Apr 2007 14:46:50 +0000 Subject: [PATCH] CTF capture times - two digits please! git-svn-id: svn://svn.icculus.org/nexuiz/trunk/data@2338 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- qcsrc/server/ctf.qc | 11 ++++++---- qcsrc/server/miscfunctions.qc | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/qcsrc/server/ctf.qc b/qcsrc/server/ctf.qc index 9ff5f088c..641f8d858 100644 --- a/qcsrc/server/ctf.qc +++ b/qcsrc/server/ctf.qc @@ -181,6 +181,7 @@ void() FlagTouch = local float t; local entity head; local entity player; + local string s, s0; if (other.classname != "player") return; if (other.health < 1) // ignore dead players @@ -198,20 +199,22 @@ void() FlagTouch = { return; } - t = floor(time - other.flagcarried.flagpickuptime); + t = time - other.flagcarried.flagpickuptime; + s = ftos_decimals(t, 2); + s0 = ftos_decimals(flagcaptimerecord, 2); if (flagcaptimerecord == 0) { - bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), " seconds\n"); + bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n"); flagcaptimerecord = t; } else if (t < flagcaptimerecord) { - bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", breaking the previous record of ", ftos(flagcaptimerecord), " seconds\n"); + bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking the previous record of ", s0, " seconds\n"); flagcaptimerecord = t; } else { - bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", ftos(t), ", failing to break the previous record of ", ftos(flagcaptimerecord), " seconds\n"); + bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break the previous record of ", s0, " seconds\n"); } LogCTF("capture", other.flagcarried.team, other); diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 1d60ca665..cd888f685 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -1,3 +1,44 @@ +// converts a number to a string with the indicated number of decimals +// works for up to 10 decimals! +string ftos_decimals(float number, float decimals) +{ + string result; + string tmp; + float len; + + // if negative, cut off the sign first + if(number < 0) + return strcat("-", ftos_decimals(-number, decimals)); + // it now is always positive! + + // 3.516 -> 352 + number = floor(number * pow(10, decimals) + 0.5); + + // 352 -> "352" + result = ftos(number); + len = strlen(result); + // does it have a decimal point (should not happen)? If there is one, it is always at len-7) + // if ftos had fucked it up, which should never happen: "34278.000000" + if(len >= 7) + if(substring(result, len - 7, 1) == ".") + { + dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n"); + result = substring(result, 0, len - 7); + len -= 7; + } + // "34278" + // is it too short? If yes, insert leading zeroes + if(len <= decimals) + { + result = strcat(substring("0000000000", 0, decimals - len + 1), result); + len = decimals + 1; + } + // and now... INSERT THE POINT! + tmp = substring(result, len - decimals, decimals); + result = strcat(substring(result, 0, len - decimals), ".", tmp); + return result; +} + #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; ) #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL) string STR_PLAYER = "player"; -- 2.39.2