r1768 - branches/nexuiz-2.0/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Jul 22 16:36:35 EDT 2006


Author: div0
Date: 2006-07-22 16:36:34 -0400 (Sat, 22 Jul 2006)
New Revision: 1768

Modified:
   branches/nexuiz-2.0/data/qcsrc/server/g_world.qc
Log:
[backport] fixed winning condition, map size restriction can be set by admin using .sizes files


Modified: branches/nexuiz-2.0/data/qcsrc/server/g_world.qc
===================================================================
--- branches/nexuiz-2.0/data/qcsrc/server/g_world.qc	2006-07-22 20:35:49 UTC (rev 1767)
+++ branches/nexuiz-2.0/data/qcsrc/server/g_world.qc	2006-07-22 20:36:34 UTC (rev 1768)
@@ -416,6 +416,36 @@
 	return cvar("g_maplist_index");
 }
 
+float MapHasRightSize(string map)
+{
+	// open map size restriction file
+	float fh;
+	dprint("opensize "); dprint(map);
+	fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
+	if(fh >= 0)
+	{
+		float mapmin, mapmax;
+		dprint(": ok, ");
+		mapmin = stof(fgets(fh));
+		mapmax = stof(fgets(fh));
+		fclose(fh);
+		if(player_count < mapmin)
+		{
+			dprint("not enough\n");
+			return FALSE;
+		}
+		if(player_count > mapmax)
+		{
+			dprint("too many\n");
+			return FALSE;
+		}
+		dprint("right size\n");
+		return TRUE;
+	}
+	dprint(": not found\n");
+	return TRUE;
+}
+
 void() GotoNextMap =
 {
 	//local string nextmap;
@@ -463,6 +493,8 @@
 		local float lOldCurrent;
 		local float lBeforeCurrent;
 		local float pass;
+		local float found_but_wrong_size;
+		found_but_wrong_size = FALSE;
 
 		if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
 		{
@@ -513,9 +545,16 @@
 					// we couldn't find a valid map at all
 					if (pass == 1)
 					{
-						bprint( "Maplist is bad/messed up. Not one good mapcfg can be found in it!  Resetting it to default map list.\n" );
-						cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
-						// let the loop restart with the default list now
+						if(!found_but_wrong_size)
+						{
+							bprint( "Maplist is bad/messed up. Not one good mapcfg can be found in it!  Resetting it to default map list.\n" );
+							cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
+							// let the loop restart with the default list now
+						}
+						else
+						{
+							dprint("wrong size, now trying all\n");
+						}
 					}
 					else
 					{
@@ -525,16 +564,22 @@
 					break;
 				}
 
-				cvar_set( "g_maplist_index", ftos( lCurrent ) );
-
-				lFilename = strcat( "maps/", argv( lCurrent ), ".mapcfg" );
+				lFilename = strzone(strcat( "maps/", argv( lCurrent ), ".mapcfg" ));
 				if( TryFile( lFilename ) ) {
-					localcmd(strcat("exec \"", lFilename ,"\"\n"));
-					pass = 2; // exit the outer loop
-					break;
+					if((pass == 2) || MapHasRightSize(argv(lCurrent)))
+					{
+						cvar_set( "g_maplist_index", ftos( lCurrent ) );
+						localcmd(strcat("exec \"", lFilename ,"\"\n"));
+						strunzone(lFilename);
+						pass = 2; // exit the outer loop
+						break;
+					}
+					else
+						found_but_wrong_size = TRUE;
 				} else {
 					dprint( "Couldn't find '", lFilename, "'..\n" );
 				}
+				strunzone(lFilename);
 				//changelevel( argv( lCurrent ) );
 			}
 			strunzone(temp);
@@ -1238,7 +1283,10 @@
 
 	if(checkrules_overtimeend)
 		if(status != WINNING_NEVER)
+		{
+			ClearWinners();
 			status = WINNING_YES;
+		}
 
 	if(status == WINNING_YES)
 		NextLevel();




More information about the nexuiz-commits mailing list