r2985 - in trunk/data: . qcsrc/common qcsrc/server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Nov 21 13:41:58 EST 2007
Author: div0
Date: 2007-11-21 13:41:57 -0500 (Wed, 21 Nov 2007)
New Revision: 2985
Modified:
trunk/data/default.cfg
trunk/data/qcsrc/common/gamecommand.qc
trunk/data/qcsrc/server/g_world.qc
Log:
fix maplist editing commands for mapinfo
Modified: trunk/data/default.cfg
===================================================================
--- trunk/data/default.cfg 2007-11-21 16:11:45 UTC (rev 2984)
+++ trunk/data/default.cfg 2007-11-21 18:41:57 UTC (rev 2985)
@@ -750,10 +750,10 @@
alias adminmsg "sv_cmd adminmsg $*"
alias teamstatus "sv_cmd teamstatus"
alias printstats "sv_cmd printstats" // print status on demand
-alias g_maplist_add "qc_cmd rpn /maps/$1.mapcfg fexists_assert /g_maplist g_maplist /'$1' union def"
-alias g_maplist_remove "qc_cmd rpn /g_maplist g_maplist /'$1' difference def"
-alias g_maplist_putfirst "qc_cmd rpn /maps/$1.mapcfg fexists_assert /g_maplist /'$1' g_maplist union def"
-alias g_maplist_shufflenow "qc_cmd rpn /g_maplist g_maplist shuffle def"
+alias g_maplist_add "qc_cmd maplist add $*"
+alias g_maplist_remove "qc_cmd maplist remove $*"
+alias g_maplist_putfirst "qc_cmd maplist remove $* ; qc_cmd maplist add $*"
+alias g_maplist_shufflenow "qc_cmd maplist shuffle"
// key hunt
set g_keyhunt 0
Modified: trunk/data/qcsrc/common/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/common/gamecommand.qc 2007-11-21 16:11:45 UTC (rev 2984)
+++ trunk/data/qcsrc/common/gamecommand.qc 2007-11-21 18:41:57 UTC (rev 2985)
@@ -46,6 +46,8 @@
float GameCommand_Generic(string command)
{
float argc;
+ float i, j, f, n;
+ string s, s2;
argc = tokenize(command);
if(argv(0) == "help")
{
@@ -62,18 +64,107 @@
print(" s shuffle -------------------------> s : randomly arrange elements\n");
print(" Set operations operate on 'such''strings' like g_maplist.\n");
print(" Unknown tokens insert their cvar value.\n");
+ print(" maplist add map\n");
+ print(" maplist remove map\n");
+ print(" maplist shuffle\n");
return TRUE;
}
- if(argv(0) == "rpn")
+ if(argv(0) == "maplist")
{
+ if(argv(1) == "add" && argc == 3)
+ {
+#ifdef MAPINFO
+ f = fopen(strcat("maps/", argv(2), ".bsp"), FILE_READ);
+ if(f != -1)
+ fclose(f);
+ else {
+ print("maplist: ERROR: ", argv(2), " does not exist!\n");
+ return TRUE;
+ }
+ if(cvar_string("g_maplist") == "")
+ cvar_set("g_maplist", argv(2));
+ else
+ cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist")));
+#else
+ f = fopen(strcat("maps/", argv(2), ".mapcfg"), FILE_READ);
+ if(f != -1)
+ fclose(f);
+ else {
+ print("maplist: ERROR: ", argv(2), " does not exist!\n");
+ return TRUE;
+ }
+ cvar_set("g_maplist", strcat("'", argv(2), "'", cvar_string("g_maplist")));
+#endif
+ return TRUE;
+ }
+ else if(argv(1) == "remove" && argc == 3)
+ {
+ s = argv(2);
+#ifdef MAPINFO
+ n = tokenizebyseparator(cvar_string("g_maplist"), " ");
+#else
+ n = tokenize(cvar_string("g_maplist"));
+#endif
+ s2 = "";
+ for(i = 0; i < n; ++i)
+ if(argv(i) != s)
+ {
+#ifdef MAPINFO
+ s2 = strcat(s2, " ", argv(i));
+#else
+ s2 = strcat(s2, "'", argv(i), "'");
+#endif
+ }
+#ifdef MAPINFO
+ s2 = substring(s2, 1, strlen(s2) - 1);
+#endif
+ cvar_set("g_maplist", s2);
+ return TRUE;
+ }
+ else if(argv(1) == "shuffle" && argc == 2)
+ {
+ s = cvar_string("g_maplist");
+#ifdef MAPINFO
+ for(i = 1; i < (n = tokenizebyseparator(s, " ")); ++i)
+#else
+ for(i = 1; i < (n = tokenize(s)); ++i)
+#endif
+ {
+ // swap i-th item at a random position from 0 to i
+ // proof for even distribution:
+ // n = 1: obvious
+ // n -> n+1:
+ // item n+1 gets at any position with chance 1/(n+1)
+ // all others will get their 1/n chance reduced by factor n/(n+1)
+ // to be on place n+1, their chance will be 1/(n+1)
+ // 1/n * n/(n+1) = 1/(n+1)
+ // q.e.d.
+ f = ceil(random() * (i + 1)) - 1; // 0 to i
+ if(f == i)
+ continue; // no change
+
+ s2 = "";
+ for(j = 0; j < n; ++j)
+#ifdef MAPINFO
+ s2 = strcat(s2, " ", argv((j == i) ? f : (j == f) ? i : j));
+ s = substring(s2, 1, strlen(s2) - 1);
+#else
+ s2 = strcat(s2, "'", argv((j == i) ? f : (j == f) ? i : j), "'");
+ s = s2;
+#endif
+ }
+ cvar_set("g_maplist", s);
+ return TRUE;
+ }
+ }
+ else if(argv(0) == "rpn")
+ {
if(argc >= 2)
{
float rpnpos;
string rpncmd;
- string s, s2;
- float f, f2;
- float i, j;
+ float f2;
rpn_sp = 0;
rpn_error = FALSE;
for(rpnpos = 1; rpnpos < argc; ++rpnpos)
Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc 2007-11-21 16:11:45 UTC (rev 2984)
+++ trunk/data/qcsrc/server/g_world.qc 2007-11-21 18:41:57 UTC (rev 2985)
@@ -60,7 +60,11 @@
cvar_set("_sv_init", "0");
if(cvar("g_maplist_shuffle"))
ShuffleMaplist();
+#ifdef MAPINFO
+ tokenizebyseparator(cvar_string("g_maplist"), " ");
+#else
tokenize(cvar_string("g_maplist"));
+#endif
if(argv(0) != GetMapname())
{
cvar_set("nextmap", argv(0));
@@ -678,7 +682,11 @@
newlist = strcat(newlist, "'", argv(j), "'");
#endif
cvar_set("g_maplist", newlist);
+#ifdef MAPINFO
+ Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
+#else
Map_Count = tokenize(newlist);
+#endif
// NOTE: the selected map has just been inserted at (insertpos-1)th position
Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
@@ -692,17 +700,22 @@
{
string temp;
temp = cvar_string("g_maplist");
+#ifdef MAPINFO
+ Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
+#else
Map_Count = tokenize(temp);
+#endif
if(Map_Count == 0)
{
bprint( "Maplist is empty! Resetting it to default map list.\n" );
#ifdef MAPINFO
cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
localcmd("\nmenu_cmd sync\n");
+ Map_Count = tokenizebyseparator(temp, " ");
#else
cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
+ Map_Count = tokenize(temp);
#endif
- Map_Count = tokenize(temp);
}
if(Map_Count == 0)
error("empty maplist, cannot select a new map");
@@ -1591,7 +1604,11 @@
float i;
result = cvar_string("g_maplist");
+#ifdef MAPINFO
+ litems = tokenizebyseparator(result, " ");
+#else
litems = tokenize(result);
+#endif
for(start = 0; start < litems - 1; ++start)
{
@@ -1609,6 +1626,8 @@
if(i != selected)
result = strcat(result, " ", argv(i));
result = substring(result, 1, strlen(result) - 1);
+
+ litems = tokenizebyseparator(result, " ");
#else
for(i = 0; i < start; ++i)
result = strcat(result, "'", argv(i), "'");
@@ -1616,9 +1635,9 @@
for(i = start; i < litems; ++i)
if(i != selected)
result = strcat(result, "'", argv(i), "'");
-#endif
litems = tokenize(result);
+#endif
//dprint(result, "\n");
}
More information about the nexuiz-commits
mailing list