plugins/mapmanager/votes.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/mapmanager/votes.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,318 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Map Manager Plugin
     1.8 - * Contains vote callbacks
     1.9 - *
    1.10 - * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
    1.11 - * =============================================================================
    1.12 - *
    1.13 - * This program is free software; you can redistribute it and/or modify it under
    1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 - * Free Software Foundation.
    1.16 - * 
    1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 - * details.
    1.21 - *
    1.22 - * You should have received a copy of the GNU General Public License along with
    1.23 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 - *
    1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 - * or <http://www.sourcemod.net/license.php>.
    1.33 - *
    1.34 - * Version: $Id$
    1.35 - */
    1.36 -
    1.37 -// sm_votemap
    1.38 -public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)
    1.39 -{
    1.40 -	if (action == MenuAction_End)
    1.41 -	{
    1.42 -		CloseHandle(menu);
    1.43 -	}
    1.44 -	else if (action == MenuAction_Display)
    1.45 -	{
    1.46 -	 	decl String:title[64];
    1.47 -		GetMenuTitle(menu, title, sizeof(title));
    1.48 -			
    1.49 -		decl String:map[64];
    1.50 -		GetMenuItem(menu, 1, map, sizeof(map));
    1.51 -		
    1.52 - 		decl String:buffer[255];
    1.53 -		Format(buffer, sizeof(buffer), "%T", title, param1, map);
    1.54 -
    1.55 -		new Handle:panel = Handle:param2;
    1.56 -		SetPanelTitle(panel, buffer);
    1.57 -	}
    1.58 -	else if (action == MenuAction_DisplayItem)
    1.59 -	{
    1.60 -		decl String:display[64];
    1.61 -		GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
    1.62 -	 
    1.63 -	 	if (strcmp(display, "No") == 0 || strcmp(display, "Yes") == 0)
    1.64 -	 	{
    1.65 -			decl String:buffer[255];
    1.66 -			Format(buffer, sizeof(buffer), "%T", display, param1);
    1.67 -
    1.68 -			return RedrawMenuItem(buffer);
    1.69 -		}
    1.70 -	}
    1.71 -	else if (action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
    1.72 -	{
    1.73 -		PrintToChatAll("[SM] %t", "No Votes Cast");
    1.74 -	}	
    1.75 -	else if (action == MenuAction_VoteEnd)
    1.76 -	{
    1.77 -		decl String:item[64], String:display[64];
    1.78 -		new Float:percent, Float:limit, votes, totalVotes;
    1.79 -
    1.80 -		GetMenuVoteInfo(param2, votes, totalVotes);
    1.81 -		GetMenuItem(menu, param1, item, sizeof(item), _, display, sizeof(display));
    1.82 -		
    1.83 -		if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
    1.84 -		{
    1.85 -			votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
    1.86 -		}
    1.87 -		
    1.88 -		percent = GetVotePercent(votes, totalVotes);
    1.89 -		
    1.90 -		limit = GetConVarFloat(g_Cvar_VoteMap);
    1.91 -		
    1.92 -		// A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
    1.93 -		if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
    1.94 -		{
    1.95 -			LogAction(-1, -1, "Vote failed.");
    1.96 -			PrintToChatAll("[SM] %t", "Votemap Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
    1.97 -		}
    1.98 -		else
    1.99 -		{
   1.100 -			PrintToChatAll("[SM] %t", "Votemap Successful", RoundToNearest(100.0*percent), totalVotes);
   1.101 -
   1.102 -			if (g_VoteMapInUse && IsClientInGame(g_VoteMapInUse))
   1.103 -			{
   1.104 -				DisplayAcceptVoteMenu(item);
   1.105 -			}
   1.106 -			else
   1.107 -			{
   1.108 -				LogAction(-1, -1, "Changing map to %s due to vote.", item);
   1.109 -				PrintToChatAll("[SM] %t", "Changing map", item);
   1.110 -				SetMapChange(0, item, g_Client_Data[g_VoteMapInUse][0])
   1.111 -			}	
   1.112 -		}
   1.113 -	}
   1.114 -	
   1.115 -	return 0;
   1.116 -}
   1.117 -
   1.118 -public Handler_MapMapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
   1.119 -{
   1.120 -	switch (action)
   1.121 -	{
   1.122 -		case MenuAction_End:
   1.123 -		{
   1.124 -			CloseHandle(menu);
   1.125 -		}
   1.126 -		
   1.127 -		case MenuAction_Display:
   1.128 -		{
   1.129 -	 		decl String:oldTitle[255], String:buffer[255];
   1.130 -			GetMenuTitle(menu, oldTitle, sizeof(oldTitle));
   1.131 -			Format(buffer, sizeof(buffer), "%T", oldTitle, param1);
   1.132 -
   1.133 -			new Handle:panel = Handle:param2;
   1.134 -			SetPanelTitle(panel, buffer);
   1.135 -		}
   1.136 -		
   1.137 -		case MenuAction_DisplayItem:
   1.138 -		{
   1.139 -			if (GetMenuItemCount(menu) - 1 == param2)
   1.140 -			{
   1.141 -				decl String:buffer[255];
   1.142 -				Format(buffer, sizeof(buffer), "%T", "Don't Change", param1);
   1.143 -				return RedrawMenuItem(buffer);
   1.144 -			}
   1.145 -		}		
   1.146 -
   1.147 -		// Why am I commented out? Because BAIL hasn't decided yet if
   1.148 -		// vote notification will be built into the Vote API.
   1.149 -		/*case MenuAction_Select:
   1.150 -		{
   1.151 -			decl String:Name[32], String:Map[32];
   1.152 -			GetClientName(param1, Name, sizeof(Name));
   1.153 -			GetMenuItem(menu, param2, Map, sizeof(Map));
   1.154 -
   1.155 -			PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map);
   1.156 -		}*/
   1.157 -		
   1.158 -		case MenuAction_VoteCancel:
   1.159 -		{
   1.160 -			if (param1 == VoteCancel_NoVotes)
   1.161 -			{
   1.162 -				PrintToChatAll("[SM] %t", "No Votes");
   1.163 -				g_RTVEnded = true;
   1.164 -			}
   1.165 -		}
   1.166 -
   1.167 -		case MenuAction_VoteEnd:
   1.168 -		{
   1.169 -			new String:map[64];
   1.170 -			
   1.171 -			GetMenuItem(menu, param1, map, sizeof(map));
   1.172 -			
   1.173 -			if (GetMenuItemCount(menu) - 1 == param1) // This should always match the "Keep Current" option
   1.174 -			{
   1.175 -				PrintToChatAll("[SM] %t", "Current Map Stays");
   1.176 -				LogMessage("[SM] Rockthevote has ended, current map kept.");
   1.177 -			}
   1.178 -			else
   1.179 -			{
   1.180 -				PrintToChatAll("[SM] %t", "Changing Maps", map);
   1.181 -				LogMessage("[SM] Rockthevote has ended, changing to map %s.", map);
   1.182 -				new Handle:dp;
   1.183 -				CreateDataTimer(5.0, Timer_ChangeMap, dp);
   1.184 -				WritePackString(dp, map);
   1.185 -			}
   1.186 -			
   1.187 -			g_RTVEnded = true;
   1.188 -		}
   1.189 -	}
   1.190 -	
   1.191 -	return 0;
   1.192 -}
   1.193 -
   1.194 -public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
   1.195 -{
   1.196 -	switch (action)
   1.197 -	{
   1.198 -		case MenuAction_End:
   1.199 -		{
   1.200 -			g_VoteMenu = INVALID_HANDLE;
   1.201 -			CloseHandle(menu);
   1.202 -		}
   1.203 -		
   1.204 -		case MenuAction_Display:
   1.205 -		{
   1.206 -	 		decl String:buffer[255];
   1.207 -			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
   1.208 -
   1.209 -			new Handle:panel = Handle:param2;
   1.210 -			SetPanelTitle(panel, buffer);
   1.211 -		}		
   1.212 -		
   1.213 -		case MenuAction_DisplayItem:
   1.214 -		{
   1.215 -			if (GetMenuItemCount(menu) - 1 == param2)
   1.216 -			{
   1.217 -				decl String:map[64], String:buffer[255];
   1.218 -				GetMenuItem(menu, param2, map, sizeof(map));
   1.219 -				if (strcmp(map, VOTE_EXTEND, false) == 0)
   1.220 -				{
   1.221 -					Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
   1.222 -					return RedrawMenuItem(buffer);
   1.223 -				}
   1.224 -			}
   1.225 -		}		
   1.226 -
   1.227 -		// Why am I commented out? Because BAIL hasn't decided yet if
   1.228 -		// vote notification will be built into the Vote API.
   1.229 -		/*case MenuAction_Select:
   1.230 -		{
   1.231 -			decl String:Name[32], String:Map[32];
   1.232 -			GetClientName(param1, Name, sizeof(Name));
   1.233 -			GetMenuItem(menu, param2, Map, sizeof(Map));
   1.234 -
   1.235 -			PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map);
   1.236 -		}*/
   1.237 -		
   1.238 -		case MenuAction_VoteCancel:
   1.239 -		{
   1.240 -			// If we receive 0 votes, pick at random.
   1.241 -			if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
   1.242 -			{
   1.243 -				new count = GetMenuItemCount(menu);
   1.244 -				new item = GetRandomInt(0, count - 1);
   1.245 -				decl String:map[32];
   1.246 -				GetMenuItem(menu, item, map, sizeof(map));
   1.247 -				
   1.248 -				while (strcmp(map, VOTE_EXTEND, false) == 0)
   1.249 -				{
   1.250 -					item = GetRandomInt(0, count - 1);
   1.251 -					GetMenuItem(menu, item, map, sizeof(map));
   1.252 -				}
   1.253 -				
   1.254 -				SetNextMap(map);			
   1.255 -			}
   1.256 -			else
   1.257 -			{
   1.258 -				// We were actually cancelled. What should we do?
   1.259 -			}
   1.260 -		}
   1.261 -
   1.262 -		case MenuAction_VoteEnd:
   1.263 -		{
   1.264 -			decl String:map[32];
   1.265 -			GetMenuItem(menu, param1, map, sizeof(map));
   1.266 -
   1.267 -			if (strcmp(map, VOTE_EXTEND, false) == 0)
   1.268 -			{
   1.269 -				new time;
   1.270 -				if (GetMapTimeLimit(time))
   1.271 -				{
   1.272 -					if (time > 0 && time < GetConVarInt(g_Cvar_ExtendTimeMax))
   1.273 -					{
   1.274 -						ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);						
   1.275 -					}
   1.276 -				}
   1.277 -				
   1.278 -				if (g_Cvar_Winlimit != INVALID_HANDLE)
   1.279 -				{
   1.280 -					new winlimit = GetConVarInt(g_Cvar_Winlimit);
   1.281 -					if (winlimit && winlimit < GetConVarInt(g_Cvar_ExtendRoundMax))
   1.282 -					{
   1.283 -						SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
   1.284 -					}					
   1.285 -				}
   1.286 -				
   1.287 -				if (g_Cvar_Maxrounds != INVALID_HANDLE)
   1.288 -				{
   1.289 -					new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
   1.290 -					if (maxrounds && maxrounds < GetConVarInt(g_Cvar_ExtendRoundMax))
   1.291 -					{
   1.292 -						SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
   1.293 -					}
   1.294 -				}
   1.295 -				
   1.296 -				if (g_Cvar_Fraglimit != INVALID_HANDLE)
   1.297 -				{
   1.298 -					new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
   1.299 -					if (fraglimit && fraglimit < GetConVarInt(g_Cvar_ExtendFragMax))
   1.300 -					{
   1.301 -						SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));						
   1.302 -					}
   1.303 -				}
   1.304 -
   1.305 -				PrintToChatAll("[SM] %t", "Current Map Extended");
   1.306 -				LogMessage("Voting for next map has finished. The current map has been extended.");
   1.307 -				
   1.308 -				// We extended, so we'll have to vote again.
   1.309 -				g_HasVoteStarted = false;
   1.310 -				CreateNextVote();
   1.311 -				SetupTimeleftTimer();
   1.312 -			}
   1.313 -			else
   1.314 -			{
   1.315 -				SetNextMap(map);
   1.316 -			}
   1.317 -		}
   1.318 -	}
   1.319 -	
   1.320 -	return 0;
   1.321 -}
   1.322 \ No newline at end of file