r1973 - in trunk/data: . qcsrc/server

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


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

Modified:
   trunk/data/default.cfg
   trunk/data/qcsrc/server/g_world.qc
Log:
new command g_maplist_shufflenow to randomize the maplist immediately (useful to call in server.cfg after setting g_maplist)


Modified: trunk/data/default.cfg
===================================================================
--- trunk/data/default.cfg	2006-12-03 12:05:46 UTC (rev 1972)
+++ trunk/data/default.cfg	2006-12-03 12:52:23 UTC (rev 1973)
@@ -760,3 +760,4 @@
 set sv_allow_shownames 1
 
 alias teamstatus "set _scoreboard 1"
+alias g_maplist_shufflenow "set _g_maplist_shufflenow 1"

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2006-12-03 12:05:46 UTC (rev 1972)
+++ trunk/data/qcsrc/server/g_world.qc	2006-12-03 12:52:23 UTC (rev 1973)
@@ -1245,7 +1245,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
@@ -1281,6 +1314,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