1.1 --- a/plugins/mapmanager/functions.sp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,335 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Map Management Plugin
1.8 - * Contains misc functions.
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 -SetNextMap(String:map[])
1.38 -{
1.39 - strcopy(g_NextMap, sizeof(g_NextMap), map);
1.40 - SetConVarString(g_Cvar_Nextmap, map);
1.41 -}
1.42 -
1.43 -SetMapChange(client, map, when, Float:time = 3.0)
1.44 -{
1.45 - g_MapChangeSet = true;
1.46 - g_MapChangeWhen = when[0];
1.47 - SetNextMap(map);
1.48 -
1.49 - if (when[0] == 'r')
1.50 - {
1.51 - ShowActivity2(client, "[SM] ", "%t", "Changing map end of round", map);
1.52 - LogAction(client, -1, "\"%L\" set end of round map change to \"%s\"", client, map);
1.53 - }
1.54 - else if (when[0] == 'e')
1.55 - {
1.56 - ShowActivity2(client, "[SM] ", "%t", "Set nextmap", map);
1.57 - LogAction(client, -1, "\"%L\" set the next map to \"%s\"", client, map);
1.58 - }
1.59 - else
1.60 - {
1.61 - ShowActivity2(client, "[SM] ", "%t", "Change map", map);
1.62 - LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
1.63 -
1.64 - g_MapChanged = true;
1.65 - CreateTimer(3.0, Timer_ChangeMap);
1.66 - }
1.67 -}
1.68 -
1.69 -FindAndSetNextMap()
1.70 -{
1.71 - if (ReadMapList(g_MapList,
1.72 - g_MapListSerial,
1.73 - "mapcyclefile",
1.74 - MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
1.75 - == INVALID_HANDLE)
1.76 - {
1.77 - if (g_MapListSerial == -1)
1.78 - {
1.79 - LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
1.80 - SetFailState("Mapcycle Not Found");
1.81 - }
1.82 - }
1.83 -
1.84 - new mapCount = GetArraySize(g_MapList);
1.85 - decl String:mapName[32];
1.86 -
1.87 - if (g_MapPos == -1)
1.88 - {
1.89 - decl String:current[64];
1.90 - GetCurrentMap(current, 64);
1.91 -
1.92 - for (new i = 0; i < mapCount; i++)
1.93 - {
1.94 - GetArrayString(g_MapList, i, mapName, sizeof(mapName));
1.95 - if (strcmp(current, mapName, false) == 0)
1.96 - {
1.97 - g_MapPos = i;
1.98 - break;
1.99 - }
1.100 - }
1.101 -
1.102 - if (g_MapPos == -1)
1.103 - g_MapPos = 0;
1.104 - }
1.105 -
1.106 - g_MapPos++;
1.107 - if (g_MapPos >= mapCount)
1.108 - g_MapPos = 0;
1.109 -
1.110 - GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
1.111 - SetConVarString(g_Cvar_Nextmap, mapName);
1.112 -}
1.113 -
1.114 -Float:GetVotePercent(votes, totalVotes)
1.115 -{
1.116 - return FloatDiv(float(votes),float(totalVotes));
1.117 -}
1.118 -
1.119 -bool:TestVoteDelay(client)
1.120 -{
1.121 - new delay = CheckVoteDelay();
1.122 -
1.123 - if (delay > 0)
1.124 - {
1.125 - if (delay > 60)
1.126 - {
1.127 - ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
1.128 - }
1.129 - else
1.130 - {
1.131 - ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);
1.132 - }
1.133 -
1.134 - return false;
1.135 - }
1.136 -
1.137 - return true;
1.138 -}
1.139 -
1.140 -BuildMapMenu()
1.141 -{
1.142 - if (g_MapMenu != INVALID_HANDLE)
1.143 - {
1.144 - CloseHandle(g_MapMenu);
1.145 - g_MapMenu = INVALID_HANDLE;
1.146 - }
1.147 -
1.148 - g_MapMenu = CreateMenu(Handler_MapSelectMenu);
1.149 - SetMenuTitle(g_MapMenu, "%t", "Nominate Title");
1.150 -
1.151 - decl String:map[64];
1.152 - for (new i = 0; i < GetArraySize(g_MapList); i++)
1.153 - {
1.154 - GetArrayString(g_MapList, i, map, sizeof(map));
1.155 - AddMenuItem(g_MapMenu, map, map);
1.156 - }
1.157 -
1.158 - SetMenuExitButton(g_MapMenu, false);
1.159 -}
1.160 -
1.161 -SetupTimeleftTimer()
1.162 -{
1.163 - new time;
1.164 - if (GetMapTimeLeft(time) && time > 0)
1.165 - {
1.166 - new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
1.167 - if (time - startTime < 0)
1.168 - {
1.169 - InitiateVote();
1.170 - }
1.171 - else
1.172 - {
1.173 - if (g_VoteTimer != INVALID_HANDLE)
1.174 - {
1.175 - KillTimer(g_VoteTimer);
1.176 - g_VoteTimer = INVALID_HANDLE;
1.177 - }
1.178 -
1.179 - g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote);
1.180 - }
1.181 - }
1.182 -}
1.183 -
1.184 -InitiateVote()
1.185 -{
1.186 - if (g_HasVoteStarted || g_RetryTimer != INVALID_HANDLE)
1.187 - {
1.188 - return;
1.189 - }
1.190 -
1.191 - if (IsVoteInProgress())
1.192 - {
1.193 - // Can't start a vote, try again in 5 seconds.
1.194 - g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote);
1.195 - return;
1.196 - }
1.197 -
1.198 - g_HasVoteStarted = true;
1.199 - g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
1.200 - SetMenuTitle(g_VoteMenu, "Vote Nextmap");
1.201 -
1.202 - decl String:map[32];
1.203 - for (new i = 0; i < GetArraySize(g_NextMapList); i++)
1.204 - {
1.205 - GetArrayString(g_NextMapList, i, map, sizeof(map));
1.206 - AddMenuItem(g_VoteMenu, map, map);
1.207 - }
1.208 -
1.209 - if (GetConVarBool(g_Cvar_Extend))
1.210 - {
1.211 - new bool:allowExtend, time;
1.212 - if (GetMapTimeLimit(time) && time > 0 && time < GetConVarInt(g_Cvar_ExtendTimeMax))
1.213 - {
1.214 - allowExtend = true;
1.215 - }
1.216 -
1.217 - if (g_Cvar_Winlimit != INVALID_HANDLE && GetConVarInt(g_Cvar_Winlimit) < GetConVarInt(g_Cvar_ExtendRoundMax))
1.218 - {
1.219 - allowExtend = true;
1.220 - }
1.221 -
1.222 - if (g_Cvar_Maxrounds != INVALID_HANDLE && GetConVarInt(g_Cvar_Maxrounds) < GetConVarInt(g_Cvar_ExtendRoundMax))
1.223 - {
1.224 - allowExtend = true;
1.225 - }
1.226 -
1.227 - if (g_Cvar_Fraglimit != INVALID_HANDLE && GetConVarInt(g_Cvar_Fraglimit) < GetConVarInt(g_Cvar_ExtendFragMax))
1.228 - {
1.229 - allowExtend = true;
1.230 - }
1.231 -
1.232 - if (allowExtend)
1.233 - {
1.234 - AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
1.235 - }
1.236 - }
1.237 -
1.238 - SetMenuExitButton(g_VoteMenu, false);
1.239 - VoteMenuToAll(g_VoteMenu, 20);
1.240 -
1.241 - LogMessage("Voting for next map has started.");
1.242 - PrintToChatAll("[SM] %t", "Nextmap Voting Started");
1.243 -}
1.244 -
1.245 -SetNextMap(const String:map[])
1.246 -{
1.247 - SetConVarString(g_Cvar_Nextmap, map);
1.248 - PushArrayString(g_OldMapList, map);
1.249 -
1.250 - if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
1.251 - {
1.252 - RemoveFromArray(g_OldMapList, 0);
1.253 - }
1.254 -
1.255 - PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map);
1.256 - LogMessage("Voting for next map has finished. Nextmap: %s.", map);
1.257 -}
1.258 -
1.259 -CreateNextVote()
1.260 -{
1.261 - if(g_NextMapList != INVALID_HANDLE)
1.262 - {
1.263 - ClearArray(g_NextMapList);
1.264 - }
1.265 -
1.266 - decl String:map[32];
1.267 - new index, Handle:tempMaps = CloneArray(g_MapList);
1.268 -
1.269 - GetCurrentMap(map, sizeof(map));
1.270 - index = FindStringInArray(tempMaps, map);
1.271 - if (index != -1)
1.272 - {
1.273 - RemoveFromArray(tempMaps, index);
1.274 - }
1.275 -
1.276 - if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
1.277 - {
1.278 - for (new i = 0; i < GetArraySize(g_OldMapList); i++)
1.279 - {
1.280 - GetArrayString(g_OldMapList, i, map, sizeof(map));
1.281 - index = FindStringInArray(tempMaps, map);
1.282 - if (index != -1)
1.283 - {
1.284 - RemoveFromArray(tempMaps, index);
1.285 - }
1.286 - }
1.287 - }
1.288 -
1.289 - new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
1.290 - for (new i = 0; i < limit; i++)
1.291 - {
1.292 - new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
1.293 - GetArrayString(tempMaps, b, map, sizeof(map));
1.294 - PushArrayString(g_NextMapList, map);
1.295 - RemoveFromArray(tempMaps, b);
1.296 - }
1.297 -
1.298 - CloseHandle(tempMaps);
1.299 -}
1.300 -
1.301 -/*
1.302 -
1.303 -new Handle:g_map_array = INVALID_HANDLE;
1.304 -new g_map_serial = -1;
1.305 -
1.306 -LoadMapList(Handle:menu)
1.307 -{
1.308 - new Handle:map_array;
1.309 -
1.310 - if ((map_array = ReadMapList(g_map_array,
1.311 - g_map_serial,
1.312 - "sm_map menu",
1.313 - MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
1.314 - != INVALID_HANDLE)
1.315 - {
1.316 - g_map_array = map_array;
1.317 - }
1.318 -
1.319 - if (g_map_array == INVALID_HANDLE)
1.320 - {
1.321 - return 0;
1.322 - }
1.323 -
1.324 - RemoveAllMenuItems(menu);
1.325 -
1.326 - decl String:map_name[64];
1.327 - new map_count = GetArraySize(g_map_array);
1.328 -
1.329 - for (new i = 0; i < map_count; i++)
1.330 - {
1.331 - GetArrayString(g_map_array, i, map_name, sizeof(map_name));
1.332 - AddMenuItem(menu, map_name, map_name);
1.333 - }
1.334 -
1.335 - return map_count;
1.336 -}
1.337 -
1.338 -*/
1.339 \ No newline at end of file