plugins/mapmanager/timers.sp
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 17 09:28:46 2008 +0000 (2008-04-17)
changeset 2013 5cf82fea0177
parent 1952 b7aa2b626807
permissions -rw-r--r--
Gah, finalized the revised ILibrarySys::GetFileExtension() code
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Map Manager Plugin
     5  * Contains timer callbacks
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    10  * This program is free software; you can redistribute it and/or modify it under
    11  * the terms of the GNU General Public License, version 3.0, as published by the
    12  * Free Software Foundation.
    13  * 
    14  * This program is distributed in the hope that it will be useful, but WITHOUT
    15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    17  * details.
    18  *
    19  * You should have received a copy of the GNU General Public License along with
    20  * this program.  If not, see <http://www.gnu.org/licenses/>.
    21  *
    22  * As a special exception, AlliedModders LLC gives you permission to link the
    23  * code of this program (as well as its derivative works) to "Half-Life 2," the
    24  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    25  * by the Valve Corporation.  You must obey the GNU General Public License in
    26  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    27  * this exception to all derivative works.  AlliedModders LLC defines further
    28  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    29  * or <http://www.sourcemod.net/license.php>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 public Action:Timer_ChangeMap(Handle:timer)
    35 {
    36 	ServerCommand("changelevel \"%s\"", g_NextMap);
    37 	PushArrayString(g_MapHistory, g_NextMap);
    38 
    39 	return Plugin_Stop;
    40 }
    41 
    42 public Action:Timer_RandomizeNextmap(Handle:timer)
    43 {
    44 	decl String:map[64];
    45 	
    46 	new exclusion = GetConVarInt(g_Cvar_ExcludeMaps);
    47 	if (exclusion > GetArraySize(g_MapCycle))
    48 	{
    49 		exclusion = GetArraySize(g_MapCycle) - 1;
    50 	}
    51 
    52 	new b = GetRandomInt(0, GetArraySize(g_MapCycle) - 1);
    53 	GetArrayString(g_MapCycle, b, map, sizeof(map));
    54 
    55 	while (FindStringInArray(g_MapHistory, map) != -1)
    56 	{
    57 		b = GetRandomInt(0, GetArraySize(g_MapCycle) - 1);
    58 		GetArrayString(g_MapCycle, b, map, sizeof(map));
    59 	}
    60 	
    61 	SetNextmap(map);
    62 
    63 	LogMessage("[MapManager] Randomizer has chosen '%s' as the next map.", map);	
    64 
    65 	return Plugin_Stop;
    66 }
    67 
    68 public Action:Timer_DelayRTV(Handle:timer)
    69 {
    70 	g_RTVAllowed = true;
    71 	g_RTVStarted = false;
    72 	g_RTVEnded = false;	
    73 }
    74 
    75 public Action:Timer_StartRTV(Handle:timer)
    76 {
    77 	if (timer == g_RetryTimer)
    78 	{
    79 		g_RetryTimer = INVALID_HANDLE;
    80 	}
    81 	
    82 	if (g_RetryTimer != INVALID_HANDLE)
    83 	{
    84 		return;
    85 	}
    86 
    87 	if (IsVoteInProgress())
    88 	{
    89 		// Can't start a vote, try again in 5 seconds.
    90 		g_RetryTimer = CreateTimer(5.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
    91 		return;
    92 	}			
    93 	
    94 	PrintToChatAll("[SM] %t", "RTV Vote Ready");
    95 		
    96 	new Handle:MapVoteMenu = CreateMenu(Handler_MapMapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
    97 	SetMenuTitle(MapVoteMenu, "Rock The Vote");
    98 	
    99 	new Handle:tempMaps  = CloneArray(g_MapList);
   100 	decl String:map[32];
   101 
   102 	GetCurrentMap(map, sizeof(map));
   103 	new index = FindStringInArray(tempMaps, map);
   104 	if (index != -1)
   105 	{
   106 		RemoveFromArray(tempMaps, index);
   107 	}	
   108 	
   109 	// We assume that g_RTVMapList is within the correct limits, based on the logic for nominations
   110 	for (new i = 0; i < GetArraySize(g_RTVMapList); i++)
   111 	{
   112 		GetArrayString(g_RTVMapList, i, map, sizeof(map));
   113 		AddMenuItem(MapVoteMenu, map, map);
   114 		
   115 		index = FindStringInArray(tempMaps, map);
   116 		if (index != -1)
   117 		{
   118 			RemoveFromArray(tempMaps, index);
   119 		}
   120 	}
   121 	
   122 	new limit = GetConVarInt(g_Cvar_Maps) - GetArraySize(g_RTVMapList);
   123 	if (limit > GetArraySize(tempMaps))
   124 	{
   125 		limit = GetArraySize(tempMaps);
   126 	}
   127 
   128 	for (new i = 0; i < limit; i++)
   129 	{
   130 		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
   131 		GetArrayString(tempMaps, b, map, sizeof(map));		
   132 		PushArrayString(g_RTVMapList, map);
   133 		AddMenuItem(MapVoteMenu, map, map);			
   134 		RemoveFromArray(tempMaps, b);
   135 	}	
   136 	
   137 	CloseHandle(tempMaps);
   138 	
   139 	AddMenuItem(MapVoteMenu, "Don't Change", "Don't Change");
   140 		
   141 	SetMenuExitButton(MapVoteMenu, false);
   142 	VoteMenuToAll(MapVoteMenu, 20);
   143 		
   144 	LogMessage("[SM] Rockthevote was successfully started.");
   145 }
   146 
   147 public Action:Timer_StartMapVote(Handle:timer)
   148 {
   149 	if (!GetArraySize(g_MapList))
   150 	{
   151 		return Plugin_Stop;
   152 	}		
   153 	
   154 	if (timer == g_RetryTimer)
   155 	{
   156 		g_RetryTimer = INVALID_HANDLE;
   157 	}
   158 	else
   159 	{
   160 		g_VoteTimer = INVALID_HANDLE;
   161 	}
   162 
   163 	InitiateVote();
   164 
   165 	return Plugin_Stop;
   166 }