r2955 - in trunk/data/qcsrc: common server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Nov 15 10:51:17 EST 2007
Author: div0
Date: 2007-11-15 10:51:16 -0500 (Thu, 15 Nov 2007)
New Revision: 2955
Modified:
trunk/data/qcsrc/common/mapinfo.qc
trunk/data/qcsrc/common/mapinfo.qh
trunk/data/qcsrc/server/g_world.qc
Log:
mapinfo: add a search function to find a map with a given unique prefix
Modified: trunk/data/qcsrc/common/mapinfo.qc
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qc 2007-11-15 14:12:53 UTC (rev 2954)
+++ trunk/data/qcsrc/common/mapinfo.qc 2007-11-15 15:51:16 UTC (rev 2955)
@@ -311,3 +311,39 @@
dprint("Map ", pFilename, " supports no game types, ignored\n");
return 0;
}
+
+string MapInfo_FixName(string s)
+{
+ // if there is exactly one map of prefix s, return it
+ // if not, return the null string
+ // note that DP sorts glob results... so I can use a binary search
+ string match;
+ float l, r, m, cmp;
+ l = 0;
+ r = MapInfo_count;
+ // invariants: r is behind s, l-1 is equal or before
+ while(l != r)
+ {
+ m = floor((l + r) / 2);
+ cmp = strcasecmp(_MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, m)), s);
+ if(cmp == 0)
+ return s; // found and good
+ if(cmp < 0)
+ l = m + 1; // l-1 is before s
+ else
+ r = m; // behind s
+ }
+ // r == l, so: l is behind s, l-1 is before
+ // SO: if there is any, l is the one with the right prefix
+ // and l+1 may be one too
+ if(l == MapInfo_count)
+ return string_null; // no match, behind last item
+ match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l));
+ if(!startsWith(match, s))
+ return string_null; // wrong prefix
+ if(l == MapInfo_count - 1)
+ return match; // last one, nothing can follow => unique
+ if(startsWith(_MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l + 1)), s))
+ return string_null; // ambigous match
+ return match;
+}
Modified: trunk/data/qcsrc/common/mapinfo.qh
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qh 2007-11-15 14:12:53 UTC (rev 2954)
+++ trunk/data/qcsrc/common/mapinfo.qh 2007-11-15 15:51:16 UTC (rev 2955)
@@ -31,3 +31,6 @@
// load info about a map by name into the MapInfo_Map_* globals
float MapInfo_Get_ByName(string s, float allowGenerate); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
+
+// look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
+string MapInfo_FixName(string s);
Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc 2007-11-15 14:12:53 UTC (rev 2954)
+++ trunk/data/qcsrc/server/g_world.qc 2007-11-15 15:51:16 UTC (rev 2955)
@@ -397,17 +397,23 @@
{
string gt;
gt = GetGametype();
+#ifdef MAPINFO
+#else
if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
return TRUE;
return FALSE;
+#endif
}
string getmapname_stored;
string GetMapname()
{
+#ifdef MAPINFO
+#else
if(getmapname_stored == "")
getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
return getmapname_stored;
+#endif
}
float Map_Count, Map_Current;
@@ -465,11 +471,14 @@
return TRUE;
}
+#ifdef MAPINFO
+#else
string Map_Filename(float position)
{
// FIXME unused
return strcat("maps/", argv(position), ".mapcfg");
}
+#endif
string strwords(string s, float w)
{
@@ -509,8 +518,11 @@
if(Map_IsRecent(map_next))
return 0;
}
+#ifdef MAPINFO
+#else
filename = Map_Filename(position);
if(TryFile(filename))
+#endif
{
if(pass == 2)
return 1;
@@ -557,7 +569,10 @@
{
Map_MarkAsRecent(getmapname_stored);
GameResetCfg();
+#ifdef MAPINFO
+#else
localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
+#endif
}
// return codes of map selectors:
@@ -650,7 +665,10 @@
if(Map_Count == 0)
{
bprint( "Maplist is empty! Resetting it to default map list.\n" );
+#ifdef MAPINFO
+#else
cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
+#endif
Map_Count = tokenize(temp);
}
if(Map_Count == 0)
@@ -728,7 +746,10 @@
return TRUE;
}
if(cvar_string("nextmap") != "")
+#ifdef MAPINFO
+#else
if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
+#endif
{
Map_Goto_SetStr(cvar_string("nextmap"));
Map_Goto();
@@ -767,7 +788,10 @@
if(allowReset)
{
bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
+#ifdef MAPINFO
+#else
cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
+#endif
}
else
{
@@ -1738,7 +1762,10 @@
if(Map_IsRecent(m))
return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
+#ifdef MAPINFO
+#else
if(!TryFile(strcat("maps/", m, ".mapcfg")))
+#endif
return "The map you suggested is not available on this server.";
for(i = 0; i < mapvote_suggestion_ptr; ++i)
if(mapvote_suggestions[i] == m)
@@ -1794,7 +1821,10 @@
if(mapvote_count == 0)
{
bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
+#ifdef MAPINFO
+#else
cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
+#endif
for(i = 0; i < 100 && mapvote_count < nmax; ++i)
MapVote_AddVotable(GetNextMap(), FALSE);
}
@@ -2032,7 +2062,10 @@
string GotoMap(string m)
{
+#ifdef MAPINFO
+#else
if(!TryFile(strcat("maps/", m, ".mapcfg")))
+#endif
return "The map you chose is not available on this server.";
cvar_set("nextmap", m);
cvar_set("timelimit", "-1");
More information about the nexuiz-commits
mailing list