r2338 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Apr 18 10:46:52 EDT 2007


Author: div0
Date: 2007-04-18 10:46:50 -0400 (Wed, 18 Apr 2007)
New Revision: 2338

Modified:
   trunk/data/qcsrc/server/ctf.qc
   trunk/data/qcsrc/server/miscfunctions.qc
Log:
CTF capture times - two digits please!


Modified: trunk/data/qcsrc/server/ctf.qc
===================================================================
--- trunk/data/qcsrc/server/ctf.qc	2007-04-18 13:09:06 UTC (rev 2337)
+++ trunk/data/qcsrc/server/ctf.qc	2007-04-18 14:46:50 UTC (rev 2338)
@@ -181,6 +181,7 @@
 	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 @@
 		{
 			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);

Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc	2007-04-18 13:09:06 UTC (rev 2337)
+++ trunk/data/qcsrc/server/miscfunctions.qc	2007-04-18 14:46:50 UTC (rev 2338)
@@ -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";




More information about the nexuiz-commits mailing list