plugins/mapchooser.sp
author David Anderson <dvander@alliedmods.net>
Sun Apr 06 08:20:02 2008 +0000 (2008-04-06)
changeset 1970 316eff8d8164
parent 1952 b7aa2b626807
child 2032 444fe6d52e25
permissions -rw-r--r--
added regex versioning to windows
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Mapchooser Plugin
ds@1952
     5
 * Creates a map vote at appropriate times, setting sm_nextmap to the winning
ds@1952
     6
 * vote
ds@1952
     7
 *
ds@1952
     8
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     9
 * =============================================================================
ds@1952
    10
 *
ds@1952
    11
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    12
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    13
 * Free Software Foundation.
ds@1952
    14
 * 
ds@1952
    15
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    16
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    17
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    18
 * details.
ds@1952
    19
 *
ds@1952
    20
 * You should have received a copy of the GNU General Public License along with
ds@1952
    21
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    22
 *
ds@1952
    23
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    24
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    25
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    26
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    27
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    28
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    29
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    30
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    31
 *
ds@1952
    32
 * Version: $Id$
ds@1952
    33
 */
ds@1952
    34
ds@1952
    35
#pragma semicolon 1
ds@1952
    36
#include <sourcemod>
ds@1952
    37
ds@1952
    38
public Plugin:myinfo =
ds@1952
    39
{
ds@1952
    40
	name = "MapChooser",
ds@1952
    41
	author = "AlliedModders LLC",
ds@1952
    42
	description = "Automated Map Voting",
ds@1952
    43
	version = SOURCEMOD_VERSION,
ds@1952
    44
	url = "http://www.sourcemod.net/"
ds@1952
    45
};
ds@1952
    46
ds@1952
    47
new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
ds@1952
    48
new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
ds@1952
    49
new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
ds@1952
    50
ds@1952
    51
new Handle:g_Cvar_Nextmap = INVALID_HANDLE;
ds@1952
    52
ds@1952
    53
new Handle:g_Cvar_StartTime = INVALID_HANDLE;
ds@1952
    54
new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
ds@1952
    55
new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
ds@1952
    56
new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
ds@1952
    57
new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
ds@1952
    58
new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
ds@1952
    59
new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
ds@1952
    60
new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
ds@1952
    61
new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
ds@1952
    62
new Handle:g_Cvar_Extend = INVALID_HANDLE;
ds@1952
    63
ds@1952
    64
new Handle:g_VoteTimer = INVALID_HANDLE;
ds@1952
    65
new Handle:g_RetryTimer = INVALID_HANDLE;
ds@1952
    66
ds@1952
    67
new Handle:g_MapList = INVALID_HANDLE;
ds@1952
    68
new Handle:g_OldMapList = INVALID_HANDLE;
ds@1952
    69
new Handle:g_NextMapList = INVALID_HANDLE;
ds@1952
    70
new Handle:g_TeamScores = INVALID_HANDLE;
ds@1952
    71
new Handle:g_VoteMenu = INVALID_HANDLE;
ds@1952
    72
ds@1952
    73
new g_Extends;
ds@1952
    74
new g_TotalRounds;
ds@1952
    75
new bool:g_HasVoteStarted;
ds@1952
    76
new g_mapFileSerial = -1;
ds@1952
    77
ds@1952
    78
#define VOTE_EXTEND "##extend##"
ds@1952
    79
ds@1952
    80
public OnPluginStart()
ds@1952
    81
{
ds@1952
    82
	LoadTranslations("mapchooser.phrases");
ds@1952
    83
	
ds@1952
    84
	new arraySize = ByteCountToCells(33);
ds@1952
    85
	g_MapList = CreateArray(arraySize);
ds@1952
    86
	g_OldMapList = CreateArray(arraySize);
ds@1952
    87
	g_NextMapList = CreateArray(arraySize);
ds@1952
    88
ds@1952
    89
	g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
ds@1952
    90
	g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining.", _, true, 1.0);
ds@1952
    91
	g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
ds@1952
    92
	g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
ds@1952
    93
	g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 5.0);
ds@1952
    94
	g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);	
ds@1952
    95
	g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
ds@1952
    96
	g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0);
ds@1952
    97
	g_Cvar_NoVoteMode = CreateConVar("sm_mapvote_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
ds@1952
    98
	g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
ds@1952
    99
ds@1952
   100
	RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
ds@1952
   101
ds@1952
   102
	g_Cvar_Winlimit = FindConVar("mp_winlimit");
ds@1952
   103
	g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
ds@1952
   104
	g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
ds@1952
   105
	
ds@1952
   106
	if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   107
	{
ds@1952
   108
		HookEvent("round_end", Event_RoundEnd);
ds@1952
   109
	}
ds@1952
   110
	
ds@1952
   111
	if (g_Cvar_Fraglimit != INVALID_HANDLE)
ds@1952
   112
	{
ds@1952
   113
		HookEvent("player_death", Event_PlayerDeath);		
ds@1952
   114
	}
ds@1952
   115
	
ds@1952
   116
	AutoExecConfig(true, "mapchooser");
ds@1952
   117
}
ds@1952
   118
ds@1952
   119
public OnConfigsExecuted()
ds@1952
   120
{
ds@1952
   121
	g_Cvar_Nextmap = FindConVar("sm_nextmap");
ds@1952
   122
ds@1952
   123
	if (g_Cvar_Nextmap == INVALID_HANDLE)
ds@1952
   124
	{
ds@1952
   125
		LogError("FATAL: Cannot find sm_nextmap cvar. Mapchooser not loaded.");
ds@1952
   126
		SetFailState("sm_nextmap not found");
ds@1952
   127
	}
ds@1952
   128
	
ds@1952
   129
	if (ReadMapList(g_MapList,
ds@1952
   130
					 g_mapFileSerial, 
ds@1952
   131
					 "mapchooser",
ds@1952
   132
					 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
ds@1952
   133
		!= INVALID_HANDLE)
ds@1952
   134
		
ds@1952
   135
	{
ds@1952
   136
		if (g_mapFileSerial == -1)
ds@1952
   137
		{
ds@1952
   138
			LogError("Unable to create a valid map list.");
ds@1952
   139
		}
ds@1952
   140
	}
ds@1952
   141
	
ds@1952
   142
	CreateNextVote();
ds@1952
   143
	SetupTimeleftTimer();
ds@1952
   144
	SetConVarString(g_Cvar_Nextmap, "Pending Vote");
ds@1952
   145
	
ds@1952
   146
	if (g_TeamScores != INVALID_HANDLE)
ds@1952
   147
	{
ds@1952
   148
		CloseHandle(g_TeamScores);
ds@1952
   149
	}
ds@1952
   150
	
ds@1952
   151
	g_TeamScores = CreateArray(2);
ds@1952
   152
	g_TotalRounds = 0;
ds@1952
   153
	
ds@1952
   154
	g_Extends = 0;
ds@1952
   155
}
ds@1952
   156
ds@1952
   157
public OnMapEnd()
ds@1952
   158
{
ds@1952
   159
	g_HasVoteStarted = false;
ds@1952
   160
	
ds@1952
   161
	if (g_VoteTimer != INVALID_HANDLE)
ds@1952
   162
	{
ds@1952
   163
		KillTimer(g_VoteTimer);
ds@1952
   164
		g_VoteTimer = INVALID_HANDLE;
ds@1952
   165
	}
ds@1952
   166
	
ds@1952
   167
	if (g_RetryTimer != INVALID_HANDLE)
ds@1952
   168
	{
ds@1952
   169
		KillTimer(g_RetryTimer);
ds@1952
   170
		g_RetryTimer = INVALID_HANDLE;
ds@1952
   171
	}
ds@1952
   172
}
ds@1952
   173
ds@1952
   174
public OnMapTimeLeftChanged()
ds@1952
   175
{
ds@1952
   176
	if (GetArraySize(g_MapList))
ds@1952
   177
	{
ds@1952
   178
		SetupTimeleftTimer();
ds@1952
   179
	}
ds@1952
   180
}
ds@1952
   181
ds@1952
   182
SetupTimeleftTimer()
ds@1952
   183
{
ds@1952
   184
	new time;
ds@1952
   185
	if (GetMapTimeLeft(time) && time > 0)
ds@1952
   186
	{
ds@1952
   187
		new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
ds@1952
   188
		if (time - startTime < 0)
ds@1952
   189
		{
ds@1952
   190
			InitiateVote();		
ds@1952
   191
		}
ds@1952
   192
		else
ds@1952
   193
		{
ds@1952
   194
			if (g_VoteTimer != INVALID_HANDLE)
ds@1952
   195
			{
ds@1952
   196
				KillTimer(g_VoteTimer);
ds@1952
   197
				g_VoteTimer = INVALID_HANDLE;
ds@1952
   198
			}	
ds@1952
   199
			
ds@1952
   200
			g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote);
ds@1952
   201
		}		
ds@1952
   202
	}
ds@1952
   203
}
ds@1952
   204
ds@1952
   205
public Action:Timer_StartMapVote(Handle:timer)
ds@1952
   206
{
ds@1952
   207
	if (!GetArraySize(g_MapList))
ds@1952
   208
	{
ds@1952
   209
		return Plugin_Stop;
ds@1952
   210
	}		
ds@1952
   211
	
ds@1952
   212
	if (timer == g_RetryTimer)
ds@1952
   213
	{
ds@1952
   214
		g_RetryTimer = INVALID_HANDLE;
ds@1952
   215
	}
ds@1952
   216
	else
ds@1952
   217
	{
ds@1952
   218
		g_VoteTimer = INVALID_HANDLE;
ds@1952
   219
	}
ds@1952
   220
ds@1952
   221
	InitiateVote();
ds@1952
   222
ds@1952
   223
	return Plugin_Stop;
ds@1952
   224
}
ds@1952
   225
ds@1952
   226
/* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
ds@1952
   227
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   228
{
ds@1952
   229
	if (!GetArraySize(g_MapList) || g_HasVoteStarted)
ds@1952
   230
	{
ds@1952
   231
		return;
ds@1952
   232
	}
ds@1952
   233
ds@1952
   234
	new winner = GetEventInt(event, "winner");
ds@1952
   235
	
ds@1952
   236
	if (winner == 0 || winner == 1)
ds@1952
   237
	{
ds@1952
   238
		return;
ds@1952
   239
	}
ds@1952
   240
ds@1952
   241
	g_TotalRounds++;
ds@1952
   242
	
ds@1952
   243
	new team[2], teamPos = -1;
ds@1952
   244
	for (new i; i < GetArraySize(g_TeamScores); i++)
ds@1952
   245
	{
ds@1952
   246
		GetArrayArray(g_TeamScores, i, team);
ds@1952
   247
		if (team[0] == winner)
ds@1952
   248
		{
ds@1952
   249
			teamPos = i;
ds@1952
   250
			break;
ds@1952
   251
		}		
ds@1952
   252
	}
ds@1952
   253
	
ds@1952
   254
	if (teamPos == -1)
ds@1952
   255
	{
ds@1952
   256
		team[0] = winner;
ds@1952
   257
		team[1] = 1;
ds@1952
   258
		PushArrayArray(g_TeamScores, team);
ds@1952
   259
	}
ds@1952
   260
	else
ds@1952
   261
	{
ds@1952
   262
		team[1]++;
ds@1952
   263
		SetArrayArray(g_TeamScores, teamPos, team);
ds@1952
   264
	}	
ds@1952
   265
	
ds@1952
   266
	if (g_Cvar_Winlimit != INVALID_HANDLE)
ds@1952
   267
	{
ds@1952
   268
		new winlimit = GetConVarInt(g_Cvar_Winlimit);
ds@1952
   269
		if (winlimit)
ds@1952
   270
		{
ds@1952
   271
			if (team[1] >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   272
			{
ds@1952
   273
				InitiateVote();
ds@1952
   274
			}
ds@1952
   275
		}
ds@1952
   276
	}
ds@1952
   277
	
ds@1952
   278
	if (g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   279
	{
ds@1952
   280
		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
ds@1952
   281
		if (maxrounds)
ds@1952
   282
		{
ds@1952
   283
			if (g_TotalRounds >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   284
			{
ds@1952
   285
				InitiateVote();
ds@1952
   286
			}			
ds@1952
   287
		}
ds@1952
   288
	}
ds@1952
   289
}
ds@1952
   290
ds@1952
   291
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   292
{
ds@1952
   293
	if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
ds@1952
   294
	{
ds@1952
   295
		return;
ds@1952
   296
	}
ds@1952
   297
	
ds@1952
   298
	if (!GetConVarInt(g_Cvar_Fraglimit))
ds@1952
   299
	{
ds@1952
   300
		return;
ds@1952
   301
	}
ds@1952
   302
ds@1952
   303
	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
ds@1952
   304
	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
ds@1952
   305
	{
ds@1952
   306
		InitiateVote();
ds@1952
   307
	}
ds@1952
   308
}
ds@1952
   309
ds@1952
   310
public Action:Command_Mapvote(client, args)
ds@1952
   311
{
ds@1952
   312
	InitiateVote();
ds@1952
   313
ds@1952
   314
	return Plugin_Handled;	
ds@1952
   315
}
ds@1952
   316
ds@1952
   317
InitiateVote()
ds@1952
   318
{
ds@1952
   319
	if (g_HasVoteStarted || g_RetryTimer != INVALID_HANDLE)
ds@1952
   320
	{
ds@1952
   321
		return;
ds@1952
   322
	}
ds@1952
   323
	
ds@1952
   324
	if (IsVoteInProgress())
ds@1952
   325
	{
ds@1952
   326
		// Can't start a vote, try again in 5 seconds.
ds@1952
   327
		g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote);
ds@1952
   328
		return;
ds@1952
   329
	}		
ds@1952
   330
	
ds@1952
   331
	g_HasVoteStarted = true;
ds@1952
   332
	g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
ds@1952
   333
	SetMenuTitle(g_VoteMenu, "Vote Nextmap");
ds@1952
   334
ds@1952
   335
	decl String:map[32];
ds@1952
   336
	for (new i = 0; i < GetArraySize(g_NextMapList); i++)
ds@1952
   337
	{
ds@1952
   338
		GetArrayString(g_NextMapList, i, map, sizeof(map));
ds@1952
   339
		AddMenuItem(g_VoteMenu, map, map);
ds@1952
   340
	}
ds@1952
   341
ds@1952
   342
	if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
ds@1952
   343
	{
ds@1952
   344
		AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
ds@1952
   345
	}
ds@1952
   346
ds@1952
   347
	SetMenuExitButton(g_VoteMenu, false);
ds@1952
   348
	VoteMenuToAll(g_VoteMenu, 20);
ds@1952
   349
ds@1952
   350
	LogMessage("Voting for next map has started.");
ds@1952
   351
	PrintToChatAll("[SM] %t", "Nextmap Voting Started");
ds@1952
   352
}
ds@1952
   353
ds@1952
   354
public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   355
{
ds@1952
   356
	switch (action)
ds@1952
   357
	{
ds@1952
   358
		case MenuAction_End:
ds@1952
   359
		{
ds@1952
   360
			g_VoteMenu = INVALID_HANDLE;
ds@1952
   361
			CloseHandle(menu);
ds@1952
   362
		}
ds@1952
   363
		
ds@1952
   364
		case MenuAction_Display:
ds@1952
   365
		{
ds@1952
   366
	 		decl String:buffer[255];
ds@1952
   367
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
ds@1952
   368
ds@1952
   369
			new Handle:panel = Handle:param2;
ds@1952
   370
			SetPanelTitle(panel, buffer);
ds@1952
   371
		}		
ds@1952
   372
		
ds@1952
   373
		case MenuAction_DisplayItem:
ds@1952
   374
		{
ds@1952
   375
			if (GetMenuItemCount(menu) - 1 == param2)
ds@1952
   376
			{
ds@1952
   377
				decl String:map[64], String:buffer[255];
ds@1952
   378
				GetMenuItem(menu, param2, map, sizeof(map));
ds@1952
   379
				if (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   380
				{
ds@1952
   381
					Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
ds@1952
   382
					return RedrawMenuItem(buffer);
ds@1952
   383
				}
ds@1952
   384
			}
ds@1952
   385
		}		
ds@1952
   386
ds@1952
   387
		// Why am I commented out? Because BAIL hasn't decided yet if
ds@1952
   388
		// vote notification will be built into the Vote API.
ds@1952
   389
		/*case MenuAction_Select:
ds@1952
   390
		{
ds@1952
   391
			decl String:Name[32], String:Map[32];
ds@1952
   392
			GetClientName(param1, Name, sizeof(Name));
ds@1952
   393
			GetMenuItem(menu, param2, Map, sizeof(Map));
ds@1952
   394
ds@1952
   395
			PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map);
ds@1952
   396
		}*/
ds@1952
   397
		
ds@1952
   398
		case MenuAction_VoteCancel:
ds@1952
   399
		{
ds@1952
   400
			// If we receive 0 votes, pick at random.
ds@1952
   401
			if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
ds@1952
   402
			{
ds@1952
   403
				new count = GetMenuItemCount(menu);
ds@1952
   404
				new item = GetRandomInt(0, count - 1);
ds@1952
   405
				decl String:map[32];
ds@1952
   406
				GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   407
				
ds@1952
   408
				while (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   409
				{
ds@1952
   410
					item = GetRandomInt(0, count - 1);
ds@1952
   411
					GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   412
				}
ds@1952
   413
				
ds@1952
   414
				SetNextMap(map);			
ds@1952
   415
			}
ds@1952
   416
			else
ds@1952
   417
			{
ds@1952
   418
				// We were actually cancelled. What should we do?
ds@1952
   419
			}
ds@1952
   420
		}
ds@1952
   421
ds@1952
   422
		case MenuAction_VoteEnd:
ds@1952
   423
		{
ds@1952
   424
			decl String:map[32];
ds@1952
   425
			GetMenuItem(menu, param1, map, sizeof(map));
ds@1952
   426
ds@1952
   427
			if (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   428
			{
ds@1952
   429
				g_Extends++;
ds@1952
   430
				
ds@1952
   431
				new time;
ds@1952
   432
				if (GetMapTimeLimit(time))
ds@1952
   433
				{
ds@1952
   434
					if (time > 0)
ds@1952
   435
					{
ds@1952
   436
						ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);						
ds@1952
   437
					}
ds@1952
   438
				}
ds@1952
   439
				
ds@1952
   440
				if (g_Cvar_Winlimit != INVALID_HANDLE)
ds@1952
   441
				{
ds@1952
   442
					new winlimit = GetConVarInt(g_Cvar_Winlimit);
ds@1952
   443
					if (winlimit)
ds@1952
   444
					{
ds@1952
   445
						SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
ds@1952
   446
					}					
ds@1952
   447
				}
ds@1952
   448
				
ds@1952
   449
				if (g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   450
				{
ds@1952
   451
					new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
ds@1952
   452
					if (maxrounds)
ds@1952
   453
					{
ds@1952
   454
						SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
ds@1952
   455
					}
ds@1952
   456
				}
ds@1952
   457
				
ds@1952
   458
				if (g_Cvar_Fraglimit != INVALID_HANDLE)
ds@1952
   459
				{
ds@1952
   460
					new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
ds@1952
   461
					if (fraglimit)
ds@1952
   462
					{
ds@1952
   463
						SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));						
ds@1952
   464
					}
ds@1952
   465
				}
ds@1952
   466
ds@1952
   467
				PrintToChatAll("[SM] %t", "Current Map Extended");
ds@1952
   468
				LogMessage("Voting for next map has finished. The current map has been extended.");
ds@1952
   469
				
ds@1952
   470
				// We extended, so we'll have to vote again.
ds@1952
   471
				g_HasVoteStarted = false;
ds@1952
   472
				CreateNextVote();
ds@1952
   473
				SetupTimeleftTimer();
ds@1952
   474
			}
ds@1952
   475
			else
ds@1952
   476
			{
ds@1952
   477
				SetNextMap(map);
ds@1952
   478
			}
ds@1952
   479
		}
ds@1952
   480
	}
ds@1952
   481
	
ds@1952
   482
	return 0;
ds@1952
   483
}
ds@1952
   484
ds@1952
   485
SetNextMap(const String:map[])
ds@1952
   486
{
ds@1952
   487
	SetConVarString(g_Cvar_Nextmap, map);
ds@1952
   488
	PushArrayString(g_OldMapList, map);
ds@1952
   489
				
ds@1952
   490
	if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
ds@1952
   491
	{
ds@1952
   492
		RemoveFromArray(g_OldMapList, 0);
ds@1952
   493
	}
ds@1952
   494
		
ds@1952
   495
	PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map);
ds@1952
   496
	LogMessage("Voting for next map has finished. Nextmap: %s.", map);	
ds@1952
   497
}
ds@1952
   498
ds@1952
   499
CreateNextVote()
ds@1952
   500
{
ds@1952
   501
	if(g_NextMapList != INVALID_HANDLE)
ds@1952
   502
	{
ds@1952
   503
		ClearArray(g_NextMapList);
ds@1952
   504
	}
ds@1952
   505
	
ds@1952
   506
	decl String:map[32];
ds@1952
   507
	new index, Handle:tempMaps  = CloneArray(g_MapList);
ds@1952
   508
	
ds@1952
   509
	GetCurrentMap(map, sizeof(map));
ds@1952
   510
	index = FindStringInArray(tempMaps, map);
ds@1952
   511
	if (index != -1)
ds@1952
   512
	{
ds@1952
   513
		RemoveFromArray(tempMaps, index);
ds@1952
   514
	}	
ds@1952
   515
	
ds@1952
   516
	if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
ds@1952
   517
	{
ds@1952
   518
		for (new i = 0; i < GetArraySize(g_OldMapList); i++)
ds@1952
   519
		{
ds@1952
   520
			GetArrayString(g_OldMapList, i, map, sizeof(map));
ds@1952
   521
			index = FindStringInArray(tempMaps, map);
ds@1952
   522
			if (index != -1)
ds@1952
   523
			{
ds@1952
   524
				RemoveFromArray(tempMaps, index);
ds@1952
   525
			}
ds@1952
   526
		}	
ds@1952
   527
	}
ds@1952
   528
ds@1952
   529
	new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
ds@1952
   530
	for (new i = 0; i < limit; i++)
ds@1952
   531
	{
ds@1952
   532
		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
ds@1952
   533
		GetArrayString(tempMaps, b, map, sizeof(map));		
ds@1952
   534
		PushArrayString(g_NextMapList, map);
ds@1952
   535
		RemoveFromArray(tempMaps, b);
ds@1952
   536
	}
ds@1952
   537
	
ds@1952
   538
	CloseHandle(tempMaps);
ds@1952
   539
}