1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/mapmanager/timers.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,166 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Map Manager Plugin
1.8 + * Contains timer callbacks
1.9 + *
1.10 + * SourceMod (C)2004-2008 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 +public Action:Timer_ChangeMap(Handle:timer)
1.38 +{
1.39 + ServerCommand("changelevel \"%s\"", g_NextMap);
1.40 + PushArrayString(g_MapHistory, g_NextMap);
1.41 +
1.42 + return Plugin_Stop;
1.43 +}
1.44 +
1.45 +public Action:Timer_RandomizeNextmap(Handle:timer)
1.46 +{
1.47 + decl String:map[64];
1.48 +
1.49 + new exclusion = GetConVarInt(g_Cvar_ExcludeMaps);
1.50 + if (exclusion > GetArraySize(g_MapCycle))
1.51 + {
1.52 + exclusion = GetArraySize(g_MapCycle) - 1;
1.53 + }
1.54 +
1.55 + new b = GetRandomInt(0, GetArraySize(g_MapCycle) - 1);
1.56 + GetArrayString(g_MapCycle, b, map, sizeof(map));
1.57 +
1.58 + while (FindStringInArray(g_MapHistory, map) != -1)
1.59 + {
1.60 + b = GetRandomInt(0, GetArraySize(g_MapCycle) - 1);
1.61 + GetArrayString(g_MapCycle, b, map, sizeof(map));
1.62 + }
1.63 +
1.64 + SetNextmap(map);
1.65 +
1.66 + LogMessage("[MapManager] Randomizer has chosen '%s' as the next map.", map);
1.67 +
1.68 + return Plugin_Stop;
1.69 +}
1.70 +
1.71 +public Action:Timer_DelayRTV(Handle:timer)
1.72 +{
1.73 + g_RTVAllowed = true;
1.74 + g_RTVStarted = false;
1.75 + g_RTVEnded = false;
1.76 +}
1.77 +
1.78 +public Action:Timer_StartRTV(Handle:timer)
1.79 +{
1.80 + if (timer == g_RetryTimer)
1.81 + {
1.82 + g_RetryTimer = INVALID_HANDLE;
1.83 + }
1.84 +
1.85 + if (g_RetryTimer != INVALID_HANDLE)
1.86 + {
1.87 + return;
1.88 + }
1.89 +
1.90 + if (IsVoteInProgress())
1.91 + {
1.92 + // Can't start a vote, try again in 5 seconds.
1.93 + g_RetryTimer = CreateTimer(5.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
1.94 + return;
1.95 + }
1.96 +
1.97 + PrintToChatAll("[SM] %t", "RTV Vote Ready");
1.98 +
1.99 + new Handle:MapVoteMenu = CreateMenu(Handler_MapMapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
1.100 + SetMenuTitle(MapVoteMenu, "Rock The Vote");
1.101 +
1.102 + new Handle:tempMaps = CloneArray(g_MapList);
1.103 + decl String:map[32];
1.104 +
1.105 + GetCurrentMap(map, sizeof(map));
1.106 + new index = FindStringInArray(tempMaps, map);
1.107 + if (index != -1)
1.108 + {
1.109 + RemoveFromArray(tempMaps, index);
1.110 + }
1.111 +
1.112 + // We assume that g_RTVMapList is within the correct limits, based on the logic for nominations
1.113 + for (new i = 0; i < GetArraySize(g_RTVMapList); i++)
1.114 + {
1.115 + GetArrayString(g_RTVMapList, i, map, sizeof(map));
1.116 + AddMenuItem(MapVoteMenu, map, map);
1.117 +
1.118 + index = FindStringInArray(tempMaps, map);
1.119 + if (index != -1)
1.120 + {
1.121 + RemoveFromArray(tempMaps, index);
1.122 + }
1.123 + }
1.124 +
1.125 + new limit = GetConVarInt(g_Cvar_Maps) - GetArraySize(g_RTVMapList);
1.126 + if (limit > GetArraySize(tempMaps))
1.127 + {
1.128 + limit = GetArraySize(tempMaps);
1.129 + }
1.130 +
1.131 + for (new i = 0; i < limit; i++)
1.132 + {
1.133 + new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
1.134 + GetArrayString(tempMaps, b, map, sizeof(map));
1.135 + PushArrayString(g_RTVMapList, map);
1.136 + AddMenuItem(MapVoteMenu, map, map);
1.137 + RemoveFromArray(tempMaps, b);
1.138 + }
1.139 +
1.140 + CloseHandle(tempMaps);
1.141 +
1.142 + AddMenuItem(MapVoteMenu, "Don't Change", "Don't Change");
1.143 +
1.144 + SetMenuExitButton(MapVoteMenu, false);
1.145 + VoteMenuToAll(MapVoteMenu, 20);
1.146 +
1.147 + LogMessage("[SM] Rockthevote was successfully started.");
1.148 +}
1.149 +
1.150 +public Action:Timer_StartMapVote(Handle:timer)
1.151 +{
1.152 + if (!GetArraySize(g_MapList))
1.153 + {
1.154 + return Plugin_Stop;
1.155 + }
1.156 +
1.157 + if (timer == g_RetryTimer)
1.158 + {
1.159 + g_RetryTimer = INVALID_HANDLE;
1.160 + }
1.161 + else
1.162 + {
1.163 + g_VoteTimer = INVALID_HANDLE;
1.164 + }
1.165 +
1.166 + InitiateVote();
1.167 +
1.168 + return Plugin_Stop;
1.169 +}
1.170 \ No newline at end of file