From 3fb88f9178315171968b2f9bae3f748f1f5d0285 Mon Sep 17 00:00:00 2001 From: Michael McKoy Date: Mon, 8 Oct 2007 21:55:20 +0000 Subject: [PATCH] Removed nondeterministic loop in mapchooser.sp --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401539 --- plugins/mapchooser.sp | 51 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 3e795add..e7efb9d1 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -500,30 +500,41 @@ CreateNextVote() if(g_NextMapList != INVALID_HANDLE) { ClearArray(g_NextMapList); - } - - decl String:map[32]; - new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(g_MapList) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(g_MapList)); - - new bool:oldMaps = false; - if (limit > GetConVarInt(g_Cvar_ExcludeMaps)) - { - limit -= GetArraySize(g_OldMapList); - oldMaps = true; } + new Handle:tempMaps = CreateArray(33); + decl String:map[32]; + for (new i = 0; i < GetArraySize(g_MapList); i++) + { + GetArrayString(g_MapList, i, map, sizeof(map)); + PushArrayString(tempMaps, map); + } + + if (GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) + { + for (new i = 0; i < GetArraySize(g_OldMapList); i++) + { + GetArrayString(g_OldMapList, i, map, sizeof(map)); + for (new j = 0; j < GetArraySize(tempMaps); j++) + { + decl String:temp[32]; + GetArrayString(tempMaps, j, temp, sizeof(temp)); + if (strcmp(temp, map) == 0) + { + RemoveFromArray(tempMaps, j); + break; + } + } + } + } + + new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps)); for (new i = 0; i < limit; i++) { - new b = GetRandomInt(0, GetArraySize(g_MapList) - 1); - GetArrayString(g_MapList, b, map, sizeof(map)); - - while (IsStringInArray(g_NextMapList, map) || (oldMaps && IsStringInArray(g_OldMapList, map))) - { - b = GetRandomInt(0, GetArraySize(g_MapList) - 1); - GetArrayString(g_MapList, b, map, sizeof(map)); - } - - PushArrayString(g_NextMapList, map); + new b = GetRandomInt(0, GetArraySize(tempMaps) - 1); + GetArrayString(tempMaps, b, map, sizeof(map)); + PushArrayString(g_NextMapList, map); + RemoveFromArray(tempMaps, b); } }