plugins/nominations.sp
changeset 2347 e404f826d1f7
parent 2346 44b02986c01b
child 2350 c27e177a39d7
     1.1 --- a/plugins/nominations.sp	Thu Oct 09 13:24:44 2008 +1300
     1.2 +++ b/plugins/nominations.sp	Thu Oct 09 13:33:47 2008 +1300
     1.3 @@ -52,14 +52,6 @@
     1.4  new Handle:g_MapMenu = INVALID_HANDLE;
     1.5  new g_mapFileSerial = -1;
     1.6  
     1.7 -#define MAPSTATUS_ENABLED (1<<0)
     1.8 -#define MAPSTATUS_DISABLED (1<<1)
     1.9 -#define MAPSTATUS_EXCLUDE_CURRENT (1<<2)
    1.10 -#define MAPSTATUS_EXCLUDE_PREVIOUS (1<<3)
    1.11 -#define MAPSTATUS_EXCLUDE_NOMINATED (1<<4)
    1.12 -
    1.13 -new Handle:g_mapTrie;
    1.14 -
    1.15  public OnPluginStart()
    1.16  {
    1.17  	LoadTranslations("common.phrases");
    1.18 @@ -77,8 +69,6 @@
    1.19  	RegConsoleCmd("sm_nominate", Command_Nominate);
    1.20  	
    1.21  	RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote.");
    1.22 -	
    1.23 -	g_mapTrie = CreateTrie();
    1.24  }
    1.25  
    1.26  public OnConfigsExecuted()
    1.27 @@ -98,23 +88,9 @@
    1.28  	BuildMapMenu();
    1.29  }
    1.30  
    1.31 -public OnNominationRemoved(/* const */String:map[], owner)
    1.32 +public OnNominationRemoved(String:map[], owner)
    1.33  {
    1.34 -	new status;
    1.35 -	
    1.36 -	/* Is the map in our list? */
    1.37 -	if (!GetTrieValue(g_mapTrie, map, status))
    1.38 -	{
    1.39 -		return;	
    1.40 -	}
    1.41 -	
    1.42 -	/* Was the map disabled due to being nominated */
    1.43 -	if ((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED)
    1.44 -	{
    1.45 -		return;
    1.46 -	}
    1.47 -	
    1.48 -	SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED);	
    1.49 +	AddMenuItem(g_MapMenu,	map, map);
    1.50  }
    1.51  
    1.52  public Action:Command_Addmap(client, args)
    1.53 @@ -128,12 +104,10 @@
    1.54  	decl String:mapname[64];
    1.55  	GetCmdArg(1, mapname, sizeof(mapname));
    1.56  
    1.57 -	
    1.58 -	new status;
    1.59 -	if (!GetTrieValue(g_mapTrie, mapname, status))
    1.60 +	if (FindStringInArray(g_MapList, mapname) == -1)
    1.61  	{
    1.62  		ReplyToCommand(client, "%t", "Map was not found", mapname);
    1.63 -		return Plugin_Handled;		
    1.64 +		return Plugin_Handled;
    1.65  	}
    1.66  	
    1.67  	new NominateResult:result = NominateMap(mapname, true, 0);
    1.68 @@ -146,9 +120,16 @@
    1.69  		return Plugin_Handled;	
    1.70  	}
    1.71  	
    1.72 -	
    1.73 -	SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
    1.74 -
    1.75 +	decl String:item[64];
    1.76 +	for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++)
    1.77 +	{
    1.78 +		GetMenuItem(g_MapMenu, i, item, sizeof(item));
    1.79 +		if (strcmp(item, mapname) == 0)
    1.80 +		{
    1.81 +			RemoveMenuItem(g_MapMenu, i);
    1.82 +			break;
    1.83 +		}			
    1.84 +	}	
    1.85  	
    1.86  	ReplyToCommand(client, "%t", "Map Inserted", mapname);
    1.87  	LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
    1.88 @@ -204,58 +185,41 @@
    1.89  	decl String:mapname[64];
    1.90  	GetCmdArg(1, mapname, sizeof(mapname));
    1.91  	
    1.92 -	new status;
    1.93 -	if (!GetTrieValue(g_mapTrie, mapname, status))
    1.94 +	decl String:item[64];
    1.95 +	for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++)
    1.96  	{
    1.97 -		ReplyToCommand(client, "%t", "Map was not found", mapname);
    1.98 -		return Plugin_Handled;		
    1.99 +		GetMenuItem(g_MapMenu, i, item, sizeof(item));
   1.100 +		if (strcmp(item, mapname) == 0)
   1.101 +		{
   1.102 +			new NominateResult:result = NominateMap(mapname, false, client);
   1.103 +	
   1.104 +			if (result > Nominate_Replaced)
   1.105 +			{
   1.106 +				if (result == Nominate_AlreadyInVote)
   1.107 +				{
   1.108 +					ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
   1.109 +				}
   1.110 +				else
   1.111 +				{
   1.112 +					ReplyToCommand(client, "[SM] %t", "Map Already Nominated");
   1.113 +				}
   1.114 +				
   1.115 +				return Plugin_Handled;	
   1.116 +			}
   1.117 +			
   1.118 +			RemoveMenuItem(g_MapMenu, i);
   1.119 +			
   1.120 +			decl String:name[64];
   1.121 +			GetClientName(client, name, sizeof(name));
   1.122 +	
   1.123 +			PrintToChatAll("[SM] %t", "Map Nominated", name, mapname);
   1.124 +	
   1.125 +			return Plugin_Continue;
   1.126 +		}			
   1.127  	}
   1.128  	
   1.129 -	if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
   1.130 -	{
   1.131 -		if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
   1.132 -		{
   1.133 -			ReplyToCommand(client, "[SM] %t", "Can't Nominate Current Map");
   1.134 -		}
   1.135 -		
   1.136 -		if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
   1.137 -		{
   1.138 -			ReplyToCommand(client, "[SM] %t", "Map in Exclude List");
   1.139 -		}
   1.140 -		
   1.141 -		if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
   1.142 -		{
   1.143 -			ReplyToCommand(client, "[SM] %t", "Map Already Nominated");
   1.144 -		}
   1.145 -		
   1.146 -		return Plugin_Handled;
   1.147 -	}
   1.148 -	
   1.149 -	new NominateResult:result = NominateMap(mapname, false, client);
   1.150 -	
   1.151 -	if (result > Nominate_Replaced)
   1.152 -	{
   1.153 -		if (result == Nominate_AlreadyInVote)
   1.154 -		{
   1.155 -			ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
   1.156 -		}
   1.157 -		else
   1.158 -		{
   1.159 -			ReplyToCommand(client, "[SM] %t", "Map Already Nominated");
   1.160 -		}
   1.161 -		
   1.162 -		return Plugin_Handled;	
   1.163 -	}
   1.164 -	
   1.165 -	/* Map was nominated! - Disable the menu item and update the trie */
   1.166 -	
   1.167 -	SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
   1.168 -	
   1.169 -	decl String:name[64];
   1.170 -	GetClientName(client, name, sizeof(name));
   1.171 -	PrintToChatAll("[SM] %t", "Map Nominated", name, mapname);
   1.172 -	
   1.173 -	return Plugin_Continue;
   1.174 +	ReplyToCommand(client, "%t", "Map was not found", mapname);
   1.175 +	return Plugin_Handled;
   1.176  }
   1.177  
   1.178  AttemptNominate(client)
   1.179 @@ -274,9 +238,7 @@
   1.180  		g_MapMenu = INVALID_HANDLE;
   1.181  	}
   1.182  	
   1.183 -	ClearTrie(g_mapTrie);
   1.184 -	
   1.185 -	g_MapMenu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
   1.186 +	g_MapMenu = CreateMenu(Handler_MapSelectMenu);
   1.187  
   1.188  	decl String:map[64];
   1.189  	
   1.190 @@ -294,32 +256,27 @@
   1.191  		GetCurrentMap(currentMap, sizeof(currentMap));
   1.192  	}
   1.193  	
   1.194 -		
   1.195  	for (new i = 0; i < GetArraySize(g_MapList); i++)
   1.196  	{
   1.197 -		new status = MAPSTATUS_ENABLED;
   1.198 +		GetArrayString(g_MapList, i, map, sizeof(map));
   1.199  		
   1.200 -		GetArrayString(g_MapList, i, map, sizeof(map));
   1.201 +		if (GetConVarBool(g_Cvar_ExcludeOld))
   1.202 +		{
   1.203 +			if (FindStringInArray(excludeMaps, map) != -1)
   1.204 +			{
   1.205 +				continue;	
   1.206 +			}
   1.207 +		}
   1.208  		
   1.209  		if (GetConVarBool(g_Cvar_ExcludeCurrent))
   1.210  		{
   1.211  			if (StrEqual(map, currentMap))
   1.212  			{
   1.213 -				status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_CURRENT;
   1.214 -			}
   1.215 -		}
   1.216 -		
   1.217 -		/* Dont bother with this check if the current map check passed */
   1.218 -		if (GetConVarBool(g_Cvar_ExcludeOld) && status == MAPSTATUS_ENABLED)
   1.219 -		{
   1.220 -			if (FindStringInArray(excludeMaps, map) != -1)
   1.221 -			{
   1.222 -				status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS;
   1.223 +				continue;
   1.224  			}
   1.225  		}
   1.226  		
   1.227  		AddMenuItem(g_MapMenu, map, map);
   1.228 -		SetTrieValue(g_mapTrie, map, status);
   1.229  	}
   1.230  	
   1.231  	SetMenuExitButton(g_MapMenu, true);
   1.232 @@ -332,96 +289,35 @@
   1.233  		case MenuAction_Select:
   1.234  		{
   1.235  			decl String:map[64], String:name[64];
   1.236 -			GetMenuItem(menu, param2, map, sizeof(map));		
   1.237 +			GetMenuItem(menu, param2, map, sizeof(map));
   1.238 +			
   1.239  			
   1.240  			GetClientName(param1, name, 64);
   1.241  	
   1.242 +			
   1.243  			new NominateResult:result = NominateMap(map, false, param1);
   1.244  			
   1.245  			/* Don't need to check for InvalidMap because the menu did that already */
   1.246  			if (result == Nominate_AlreadyInVote)
   1.247  			{
   1.248  				PrintToChat(param1, "[SM] %t", "Map Already Nominated");
   1.249 -				return 0;
   1.250 +				return;
   1.251  			}
   1.252  			else if (result == Nominate_VoteFull)
   1.253  			{
   1.254  				PrintToChat(param1, "[SM] %t", "Max Nominations");
   1.255 -				return 0;
   1.256 +				return;
   1.257  			}
   1.258 +
   1.259 +			RemoveMenuItem(menu, param2);
   1.260  			
   1.261 -			SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
   1.262 -
   1.263  			if (result == Nominate_Replaced)
   1.264  			{
   1.265  				PrintToChatAll("[SM] %t", "Map Nomination Changed", name, map);
   1.266 -				return 0;	
   1.267 +				return;	
   1.268  			}
   1.269  			
   1.270  			PrintToChatAll("[SM] %t", "Map Nominated", name, map);
   1.271  		}
   1.272 -		
   1.273 -		case MenuAction_DrawItem:
   1.274 -		{
   1.275 -			decl String:map[64];
   1.276 -			GetMenuItem(menu, param2, map, sizeof(map));
   1.277 -			
   1.278 -			new status;
   1.279 -			
   1.280 -			if (!GetTrieValue(g_mapTrie, map, status))
   1.281 -			{
   1.282 -				LogError("Menu selection of item not in trie. Major logic problem somewhere.");
   1.283 -				return ITEMDRAW_DEFAULT;
   1.284 -			}
   1.285 -			
   1.286 -			if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
   1.287 -			{
   1.288 -				return ITEMDRAW_DISABLED;	
   1.289 -			}
   1.290 -			
   1.291 -			return ITEMDRAW_DEFAULT;
   1.292 -						
   1.293 -		}
   1.294 -		
   1.295 -		case MenuAction_DisplayItem:
   1.296 -		{
   1.297 -			decl String:map[64];
   1.298 -			GetMenuItem(menu, param2, map, sizeof(map));
   1.299 -			
   1.300 -			new status;
   1.301 -			
   1.302 -			if (!GetTrieValue(g_mapTrie, map, status))
   1.303 -			{
   1.304 -				LogError("Menu selection of item not in trie. Major logic problem somewhere.");
   1.305 -				return 0;
   1.306 -			}
   1.307 -			
   1.308 -			decl String:display[100];
   1.309 -			
   1.310 -			if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
   1.311 -			{
   1.312 -				if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
   1.313 -				{
   1.314 -					Format(display, sizeof(display), "%s (%T)", map, "Current Map", param1);
   1.315 -					return RedrawMenuItem(display);
   1.316 -				}
   1.317 -				
   1.318 -				if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
   1.319 -				{
   1.320 -					Format(display, sizeof(display), "%s (%T)", map, "Recently Played", param1);
   1.321 -					return RedrawMenuItem(display);
   1.322 -				}
   1.323 -				
   1.324 -				if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
   1.325 -				{
   1.326 -					Format(display, sizeof(display), "%s (%T)", map, "Nominated", param1);
   1.327 -					return RedrawMenuItem(display);
   1.328 -				}
   1.329 -			}
   1.330 -			
   1.331 -			return 0;
   1.332 -		}
   1.333  	}
   1.334 -	
   1.335 -	return 0;
   1.336  }
   1.337 \ No newline at end of file