r1974 - in branches/nexuiz-2.0/data: . qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Dec 3 07:53:52 EST 2006


Author: div0
Date: 2006-12-03 07:53:52 -0500 (Sun, 03 Dec 2006)
New Revision: 1974

Modified:
   branches/nexuiz-2.0/data/default.cfg
   branches/nexuiz-2.0/data/qcsrc/server/g_world.qc
Log:
"shuffle now" command
prevent same map from being selected immediately again


Modified: branches/nexuiz-2.0/data/default.cfg
===================================================================
--- branches/nexuiz-2.0/data/default.cfg	2006-12-03 12:52:23 UTC (rev 1973)
+++ branches/nexuiz-2.0/data/default.cfg	2006-12-03 12:53:52 UTC (rev 1974)
@@ -743,3 +743,4 @@
 set sv_allow_shownames 1
 
 alias teamstatus "set _scoreboard 1"
+alias g_maplist_shufflenow "set _g_maplist_shufflenow 1"

Modified: branches/nexuiz-2.0/data/qcsrc/server/g_world.qc
===================================================================
--- branches/nexuiz-2.0/data/qcsrc/server/g_world.qc	2006-12-03 12:52:23 UTC (rev 1973)
+++ branches/nexuiz-2.0/data/qcsrc/server/g_world.qc	2006-12-03 12:53:52 UTC (rev 1974)
@@ -519,20 +519,23 @@
 
 	imax = 42;
 
+	if(Map_Count <= 1)
+		return 0; // only one map, then always play this one
+
 	for(i = 0; i <= imax; ++i)
 	{
 		string newlist;
 
 		// now reinsert this at another position
-		insertpos = pow(Map_Count, exponent);
-		insertpos = random() * insertpos;              // ]0, (Map_Count)^exponent]
-		insertpos = pow(insertpos, 1 / exponent);      // ]0, Map_Count]
-		insertpos = ceil(insertpos);                   // {1, 2, 3, ..., Map_Count}
+		insertpos = pow(Map_Count - 1, exponent);
+		insertpos = random() * insertpos;              // ]0, (Map_Count - 1)^exponent]
+		insertpos = pow(insertpos, 1 / exponent);      // ]0, Map_Count - 1]
+		insertpos = ceil(insertpos) + 1;               // {2, 3, 4, ..., Map_Count}
 		dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
 
 		// insert the current map there
 		newlist = "";
-		for(j = 1; j < insertpos; ++j)                 // i == 1: no loop, will be inserted as first
+		for(j = 1; j < insertpos; ++j)                 // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
 			newlist = strcat(newlist, "'", argv(j), "'");
 		newlist = strcat(newlist, "'", argv(0), "'");  // now insert the just selected map
 		for(j = insertpos; j < Map_Count; ++j)         // i == Map_Count: no loop, has just been inserted as last
@@ -1206,7 +1209,40 @@
 	ServerConsoleEcho(".", FALSE);
 }
 
+void ShuffleMaplist()
+{
+	string result;
+	float start;
+	float items;
+	float selected;
+	float i;
 
+	result = cvar_string("g_maplist");
+	items = tokenize(result);
+
+	for(start = 0; start < items - 1; ++start)
+	{
+		result = "";
+
+		// select a random item
+		selected = ceil(random() * (items - start) + start) - 1;
+
+		// shift this item to the place start
+		for(i = 0; i < start; ++i)
+			result = strcat(result, "'", argv(i), "'");
+		result = strcat(result, "'", argv(selected), "'");
+		for(i = start; i < items; ++i)
+			if(i != selected)
+				result = strcat(result, "'", argv(i), "'");
+
+		items = tokenize(result);
+
+		dprint(result, "\n");
+	}
+
+	cvar_set("g_maplist", result);
+}
+
 /*
 ============
 CheckRules_World
@@ -1242,6 +1278,12 @@
 		PrintScoreboard();
 	}
 
+	if(cvar("_g_maplist_shufflenow"))
+	{
+		cvar_set("_g_maplist_shufflenow", "0");
+		ShuffleMaplist();
+	}
+
 	timelimit = cvar("timelimit") * 60;
 	fraglimit = cvar("fraglimit");
 




More information about the nexuiz-commits mailing list