Removed nondeterministic loop in mapchooser.sp
authorMichael McKoy <ferret99gt@gmail.com>
Mon Oct 08 21:55:20 2007 +0000 (2007-10-08)
changeset 1533cc409bf11f9f
parent 1532 0bf962c36e8b
child 1534 e211617e4514
Removed nondeterministic loop in mapchooser.sp
plugins/mapchooser.sp
     1.1 --- a/plugins/mapchooser.sp	Sun Oct 07 20:50:52 2007 +0000
     1.2 +++ b/plugins/mapchooser.sp	Mon Oct 08 21:55:20 2007 +0000
     1.3 @@ -500,30 +500,41 @@
     1.4  	if(g_NextMapList != INVALID_HANDLE)
     1.5  	{
     1.6  		ClearArray(g_NextMapList);
     1.7 -	}	
     1.8 -	
     1.9 -	decl String:map[32];
    1.10 -	new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(g_MapList) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(g_MapList));
    1.11 +	}
    1.12  	
    1.13 -	new bool:oldMaps = false;
    1.14 -	if (limit > GetConVarInt(g_Cvar_ExcludeMaps))
    1.15 +	new Handle:tempMaps  = CreateArray(33);
    1.16 +	decl String:map[32];
    1.17 +	for (new i = 0; i < GetArraySize(g_MapList); i++)
    1.18  	{
    1.19 -		limit -= GetArraySize(g_OldMapList);
    1.20 -		oldMaps = true;
    1.21 +		GetArrayString(g_MapList, i, map, sizeof(map));
    1.22 +		PushArrayString(tempMaps, map);		
    1.23  	}
    1.24  	
    1.25 +	if (GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
    1.26 +	{
    1.27 +		for (new i = 0; i < GetArraySize(g_OldMapList); i++)
    1.28 +		{
    1.29 +			GetArrayString(g_OldMapList, i, map, sizeof(map));
    1.30 +			for (new j = 0; j < GetArraySize(tempMaps); j++)
    1.31 +			{
    1.32 +				decl String:temp[32];
    1.33 +				GetArrayString(tempMaps, j, temp, sizeof(temp));
    1.34 +				if (strcmp(temp, map) == 0)
    1.35 +				{
    1.36 +					RemoveFromArray(tempMaps, j);
    1.37 +					break;
    1.38 +				}				
    1.39 +			}
    1.40 +		}	
    1.41 +	}
    1.42 +
    1.43 +	new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
    1.44  	for (new i = 0; i < limit; i++)
    1.45  	{
    1.46 -		new b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
    1.47 -		GetArrayString(g_MapList, b, map, sizeof(map));
    1.48 -		
    1.49 -		while (IsStringInArray(g_NextMapList, map) || (oldMaps && IsStringInArray(g_OldMapList, map)))
    1.50 -		{
    1.51 -			b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
    1.52 -			GetArrayString(g_MapList, b, map, sizeof(map));
    1.53 -		}
    1.54 -		
    1.55 -		PushArrayString(g_NextMapList, map);		
    1.56 +		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
    1.57 +		GetArrayString(tempMaps, b, map, sizeof(map));		
    1.58 +		PushArrayString(g_NextMapList, map);
    1.59 +		RemoveFromArray(tempMaps, b);
    1.60  	}
    1.61  }
    1.62