plugins/mapchooser.sp
author David Anderson <dvander@alliedmods.net>
Sat Sep 06 09:32:12 2008 +0000 (2008-09-06)
changeset 2258 fe16cb4e09b5
parent 2241 f61a9b513add
child 2289 44045ead61cd
permissions -rw-r--r--
startbuild is now a direct pipe.
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
 *
pred@2032
     8
 * SourceMod (C)2004-2007 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>
pred@2133
    37
#include <mapchooser>
pred@2133
    38
#include <nextmap>
ds@1952
    39
ds@1952
    40
public Plugin:myinfo =
ds@1952
    41
{
ds@1952
    42
	name = "MapChooser",
ds@1952
    43
	author = "AlliedModders LLC",
ds@1952
    44
	description = "Automated Map Voting",
ds@1952
    45
	version = SOURCEMOD_VERSION,
ds@1952
    46
	url = "http://www.sourcemod.net/"
ds@1952
    47
};
ds@1952
    48
pred@2133
    49
/* Valve ConVars */
ds@1952
    50
new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
ds@1952
    51
new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
ds@1952
    52
new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
pred@2133
    53
new Handle:g_Cvar_Bonusroundtime = INVALID_HANDLE;
ds@1952
    54
pred@2133
    55
/* Plugin ConVars */
ds@1952
    56
new Handle:g_Cvar_StartTime = INVALID_HANDLE;
ds@1952
    57
new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
ds@1952
    58
new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
ds@1952
    59
new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
ds@1952
    60
new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
ds@1952
    61
new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
ds@1952
    62
new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
ds@1952
    63
new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
ds@1952
    64
new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
ds@1952
    65
new Handle:g_Cvar_Extend = INVALID_HANDLE;
pred@2133
    66
new Handle:g_Cvar_DontChange = INVALID_HANDLE;
pred@2133
    67
new Handle:g_Cvar_EndOfMapVote = INVALID_HANDLE;
pred@2133
    68
new Handle:g_Cvar_VoteDuration = INVALID_HANDLE;
pred@2178
    69
ds@1952
    70
new Handle:g_VoteTimer = INVALID_HANDLE;
ds@1952
    71
new Handle:g_RetryTimer = INVALID_HANDLE;
ds@1952
    72
pred@2133
    73
/* Data Handles */
ds@1952
    74
new Handle:g_MapList = INVALID_HANDLE;
pred@2133
    75
new Handle:g_NominateList = INVALID_HANDLE;
pred@2133
    76
new Handle:g_NominateOwners = INVALID_HANDLE;
ds@1952
    77
new Handle:g_OldMapList = INVALID_HANDLE;
ds@1952
    78
new Handle:g_NextMapList = INVALID_HANDLE;
ds@1952
    79
new Handle:g_VoteMenu = INVALID_HANDLE;
ds@1952
    80
ds@1952
    81
new g_Extends;
ds@1952
    82
new g_TotalRounds;
ds@1952
    83
new bool:g_HasVoteStarted;
pred@2133
    84
new bool:g_WaitingForVote;
pred@2133
    85
new bool:g_MapVoteCompleted;
pred@2133
    86
new bool:g_ChangeMapAtRoundEnd;
ds@1952
    87
new g_mapFileSerial = -1;
ds@1952
    88
pred@2133
    89
new g_NominateCount = 0;
pred@2133
    90
new MapChange:g_ChangeTime;
pred@2133
    91
pred@2133
    92
new Handle:g_NominationsResetForward = INVALID_HANDLE;
pred@2133
    93
pred@2133
    94
/* Upper bound of how many team there could be */
pred@2133
    95
#define MAXTEAMS 10
pred@2133
    96
new g_winCount[MAXTEAMS];
pred@2133
    97
ds@1952
    98
#define VOTE_EXTEND "##extend##"
pred@2133
    99
#define VOTE_DONTCHANGE "##dontchange##"
ds@1952
   100
ds@1952
   101
public OnPluginStart()
ds@1952
   102
{
ds@1952
   103
	LoadTranslations("mapchooser.phrases");
pred@2215
   104
	LoadTranslations("common.phrases");
ds@1952
   105
	
ds@1952
   106
	new arraySize = ByteCountToCells(33);
ds@1952
   107
	g_MapList = CreateArray(arraySize);
pred@2133
   108
	g_NominateList = CreateArray(arraySize);
pred@2133
   109
	g_NominateOwners = CreateArray(1);
ds@1952
   110
	g_OldMapList = CreateArray(arraySize);
ds@1952
   111
	g_NextMapList = CreateArray(arraySize);
pred@2133
   112
	
pred@2133
   113
	g_Cvar_EndOfMapVote = CreateConVar("sm_mapvote_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0);
ds@1952
   114
ds@1952
   115
	g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
pred@2133
   116
	g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining. Use 0 on TF2 to start vote during bonus round time", _, true, 0.0);
ds@1952
   117
	g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
ds@1952
   118
	g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
pred@2133
   119
	g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
ds@1952
   120
	g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);	
ds@1952
   121
	g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
ds@1952
   122
	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
   123
	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
   124
	g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
pred@2133
   125
	g_Cvar_DontChange = CreateConVar("sm_mapvote_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0);
pred@2241
   126
	g_Cvar_VoteDuration = CreateConVar("sm_mapvote_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0);
pred@2215
   127
	
ds@1952
   128
	RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
pred@2215
   129
	RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
ds@1952
   130
ds@1952
   131
	g_Cvar_Winlimit = FindConVar("mp_winlimit");
ds@1952
   132
	g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
ds@1952
   133
	g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
pred@2133
   134
	g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
ds@1952
   135
	
ds@1952
   136
	if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   137
	{
ds@1952
   138
		HookEvent("round_end", Event_RoundEnd);
pred@2133
   139
		HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
pred@2133
   140
		HookEventEx("teamplay_restart_round", Event_TFRestartRound);
pred@2239
   141
		HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
ds@1952
   142
	}
ds@1952
   143
	
ds@1952
   144
	if (g_Cvar_Fraglimit != INVALID_HANDLE)
ds@1952
   145
	{
ds@1952
   146
		HookEvent("player_death", Event_PlayerDeath);		
ds@1952
   147
	}
ds@1952
   148
	
ds@1952
   149
	AutoExecConfig(true, "mapchooser");
pred@2133
   150
	
pred@2133
   151
	//Change the mp_bonusroundtime max so that we have time to display the vote
pred@2133
   152
	//If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
pred@2133
   153
	if (g_Cvar_Bonusroundtime != INVALID_HANDLE)
pred@2133
   154
	{
pred@2133
   155
		SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);		
pred@2133
   156
	}
pred@2133
   157
	
pred@2133
   158
	g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
pred@2133
   159
}
pred@2133
   160
pred@2133
   161
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
pred@2133
   162
{
pred@2165
   163
	RegPluginLibrary("mapchooser");	
pred@2165
   164
	
pred@2133
   165
	CreateNative("NominateMap", Native_NominateMap);
pred@2133
   166
	CreateNative("InitiateMapChooserVote", Native_InitiateVote);
pred@2133
   167
	CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
pred@2133
   168
	CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
pred@2133
   169
	CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
pred@2223
   170
	CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);
pred@2133
   171
pred@2133
   172
	return true;
pred@2133
   173
}
pred@2133
   174
ds@1952
   175
public OnConfigsExecuted()
ds@1952
   176
{
ds@1952
   177
	if (ReadMapList(g_MapList,
ds@1952
   178
					 g_mapFileSerial, 
ds@1952
   179
					 "mapchooser",
ds@1952
   180
					 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
ds@1952
   181
		!= INVALID_HANDLE)
ds@1952
   182
		
ds@1952
   183
	{
ds@1952
   184
		if (g_mapFileSerial == -1)
ds@1952
   185
		{
ds@1952
   186
			LogError("Unable to create a valid map list.");
ds@1952
   187
		}
ds@1952
   188
	}
ds@1952
   189
	
ds@1952
   190
	CreateNextVote();
ds@1952
   191
	SetupTimeleftTimer();
ds@1952
   192
	
ds@1952
   193
	g_TotalRounds = 0;
ds@1952
   194
	
ds@1952
   195
	g_Extends = 0;
pred@2133
   196
	
pred@2133
   197
	g_MapVoteCompleted = false;
pred@2133
   198
	
pred@2133
   199
	g_NominateCount = 0;
pred@2133
   200
	ClearArray(g_NominateList);
pred@2133
   201
	ClearArray(g_NominateOwners);
pred@2133
   202
	
pred@2133
   203
	for (new i=0; i<MAXTEAMS; i++)
pred@2133
   204
	{
pred@2133
   205
		g_winCount[i] = 0;	
pred@2133
   206
	}
pred@2133
   207
	
pred@2133
   208
pred@2133
   209
	/* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
pred@2133
   210
	if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
pred@2133
   211
	{
pred@2133
   212
		if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
pred@2133
   213
		{
pred@2133
   214
			LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
pred@2133
   215
		}
pred@2133
   216
	}
ds@1952
   217
}
ds@1952
   218
ds@1952
   219
public OnMapEnd()
ds@1952
   220
{
ds@1952
   221
	g_HasVoteStarted = false;
pred@2133
   222
	g_WaitingForVote = false;
pred@2223
   223
	g_ChangeMapAtRoundEnd = false;
ds@1952
   224
	
pred@2178
   225
	g_VoteTimer = INVALID_HANDLE;
pred@2178
   226
	g_RetryTimer = INVALID_HANDLE;
pred@2133
   227
	
pred@2133
   228
	decl String:map[32];
pred@2133
   229
	GetCurrentMap(map, sizeof(map));
pred@2133
   230
	PushArrayString(g_OldMapList, map);
pred@2133
   231
				
pred@2133
   232
	if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
pred@2133
   233
	{
pred@2133
   234
		RemoveFromArray(g_OldMapList, 0);
pred@2133
   235
	}	
pred@2133
   236
}
pred@2133
   237
pred@2133
   238
public OnClientDisconnect(client)
pred@2133
   239
{
pred@2133
   240
	new index = FindValueInArray(g_NominateOwners, client);
pred@2133
   241
	
pred@2133
   242
	if (index == -1)
pred@2133
   243
	{
pred@2133
   244
		return;
pred@2133
   245
	}
pred@2133
   246
	
pred@2133
   247
	new String:oldmap[33];
pred@2133
   248
	GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
pred@2133
   249
	Call_StartForward(g_NominationsResetForward);
pred@2133
   250
	Call_PushString(oldmap);
pred@2133
   251
	Call_PushCell(GetArrayCell(g_NominateOwners, index));
pred@2133
   252
	Call_Finish();
pred@2133
   253
	
pred@2133
   254
	RemoveFromArray(g_NominateOwners, index);
pred@2133
   255
	RemoveFromArray(g_NominateList, index);
pred@2133
   256
	g_NominateCount--;
pred@2133
   257
}
pred@2133
   258
pred@2215
   259
public Action:Command_SetNextmap(client, args)
pred@2133
   260
{
pred@2215
   261
	if (args < 1)
pred@2133
   262
	{
pred@2215
   263
		ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
pred@2215
   264
		return Plugin_Handled;
pred@2133
   265
	}
pred@2215
   266
pred@2215
   267
	decl String:map[64];
pred@2215
   268
	GetCmdArg(1, map, sizeof(map));
pred@2215
   269
pred@2215
   270
	if (!IsMapValid(map))
pred@2133
   271
	{
pred@2215
   272
		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
pred@2215
   273
		return Plugin_Handled;
pred@2133
   274
	}
pred@2215
   275
pred@2215
   276
	ShowActivity(client, "%t", "Changed Next Map", map);
pred@2215
   277
	LogMessage("\"%L\" changed nextmap to \"%s\"", client, map);
pred@2215
   278
pred@2215
   279
	SetNextMap(map);
pred@2215
   280
	g_MapVoteCompleted = true;
pred@2215
   281
pred@2215
   282
	return Plugin_Handled;
ds@1952
   283
}
ds@1952
   284
ds@1952
   285
public OnMapTimeLeftChanged()
ds@1952
   286
{
ds@1952
   287
	if (GetArraySize(g_MapList))
ds@1952
   288
	{
ds@1952
   289
		SetupTimeleftTimer();
ds@1952
   290
	}
ds@1952
   291
}
ds@1952
   292
ds@1952
   293
SetupTimeleftTimer()
ds@1952
   294
{
ds@1952
   295
	new time;
ds@1952
   296
	if (GetMapTimeLeft(time) && time > 0)
ds@1952
   297
	{
ds@1952
   298
		new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
pred@2133
   299
		if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
ds@1952
   300
		{
pred@2133
   301
			InitiateVote(MapChange_MapEnd, INVALID_HANDLE);		
ds@1952
   302
		}
ds@1952
   303
		else
ds@1952
   304
		{
ds@1952
   305
			if (g_VoteTimer != INVALID_HANDLE)
ds@1952
   306
			{
ds@1952
   307
				KillTimer(g_VoteTimer);
ds@1952
   308
				g_VoteTimer = INVALID_HANDLE;
ds@1952
   309
			}	
ds@1952
   310
			
pred@2178
   311
			g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   312
		}		
ds@1952
   313
	}
ds@1952
   314
}
ds@1952
   315
ds@1952
   316
public Action:Timer_StartMapVote(Handle:timer)
ds@1952
   317
{
ds@1952
   318
	if (timer == g_RetryTimer)
ds@1952
   319
	{
pred@2239
   320
		g_WaitingForVote = false;
ds@1952
   321
		g_RetryTimer = INVALID_HANDLE;
ds@1952
   322
	}
ds@1952
   323
	else
ds@1952
   324
	{
ds@1952
   325
		g_VoteTimer = INVALID_HANDLE;
ds@1952
   326
	}
pred@2133
   327
	
pred@2223
   328
	if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
pred@2223
   329
	{
pred@2223
   330
		return Plugin_Stop;
pred@2223
   331
	}		
pred@2223
   332
pred@2133
   333
	InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   334
ds@1952
   335
	return Plugin_Stop;
ds@1952
   336
}
ds@1952
   337
pred@2133
   338
public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
pred@2133
   339
{
pred@2133
   340
	/* Game got restarted - reset our round count tracking */
pred@2133
   341
	g_TotalRounds = 0;	
pred@2133
   342
}
pred@2133
   343
pred@2133
   344
public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
pred@2032
   345
{
pred@2133
   346
	if (g_ChangeMapAtRoundEnd)
pred@2133
   347
	{
pred@2133
   348
		g_ChangeMapAtRoundEnd = false;
pred@2179
   349
		CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
pred@2133
   350
	}
pred@2133
   351
	
pred@2133
   352
	new bluescore = GetEventInt(event, "blue_score");
pred@2133
   353
	new redscore = GetEventInt(event, "red_score");
pred@2240
   354
		
pred@2239
   355
	if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
pred@2239
   356
	{
pred@2239
   357
		g_TotalRounds++;
pred@2239
   358
		
pred@2239
   359
		if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
pred@2239
   360
		{
pred@2239
   361
			return;
pred@2239
   362
		}
pred@2239
   363
		
pred@2241
   364
		CheckMaxRounds(g_TotalRounds);
pred@2241
   365
		
pred@2133
   366
		switch(GetEventInt(event, "winning_team"))
pred@2133
   367
		{
pred@2215
   368
			case 3:
pred@2133
   369
			{
pred@2133
   370
				CheckWinLimit(bluescore);
pred@2133
   371
			}
pred@2215
   372
			case 2:
pred@2133
   373
			{
pred@2133
   374
				CheckWinLimit(redscore);				
pred@2133
   375
			}			
pred@2133
   376
			//We need to do nothing on winning_team == 0 this indicates stalemate.
pred@2133
   377
			default:
pred@2133
   378
			{
pred@2133
   379
				return;
pred@2133
   380
			}			
pred@2133
   381
		}
pred@2032
   382
	}
pred@2032
   383
}
ds@1952
   384
/* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
ds@1952
   385
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   386
{
pred@2133
   387
	if (g_ChangeMapAtRoundEnd)
pred@2133
   388
	{
pred@2133
   389
		g_ChangeMapAtRoundEnd = false;
pred@2179
   390
		CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
pred@2133
   391
	}
pred@2133
   392
	
ds@1952
   393
	new winner = GetEventInt(event, "winner");
ds@1952
   394
	
pred@2133
   395
	if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
ds@1952
   396
	{
ds@1952
   397
		return;
ds@1952
   398
	}
pred@2133
   399
	
pred@2133
   400
	if (winner >= MAXTEAMS)
pred@2133
   401
	{
pred@2133
   402
		SetFailState("Mod exceed maximum team count - Please file a bug report.");	
pred@2133
   403
	}
ds@1952
   404
ds@1952
   405
	g_TotalRounds++;
ds@1952
   406
	
pred@2133
   407
	g_winCount[winner]++;
ds@1952
   408
	
pred@2239
   409
	if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
pred@2239
   410
	{
pred@2239
   411
		return;
pred@2239
   412
	}
pred@2239
   413
	
pred@2133
   414
	CheckWinLimit(g_winCount[winner]);
pred@2133
   415
	CheckMaxRounds(g_TotalRounds);
pred@2133
   416
}
pred@2133
   417
pred@2133
   418
public CheckWinLimit(winner_score)
pred@2133
   419
{	
ds@1952
   420
	if (g_Cvar_Winlimit != INVALID_HANDLE)
ds@1952
   421
	{
ds@1952
   422
		new winlimit = GetConVarInt(g_Cvar_Winlimit);
ds@1952
   423
		if (winlimit)
pred@2133
   424
		{			
pred@2133
   425
			if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   426
			{
pred@2133
   427
				InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   428
			}
ds@1952
   429
		}
ds@1952
   430
	}
pred@2133
   431
}
pred@2133
   432
pred@2133
   433
public CheckMaxRounds(roundcount)
pred@2133
   434
{		
ds@1952
   435
	if (g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   436
	{
ds@1952
   437
		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
ds@1952
   438
		if (maxrounds)
ds@1952
   439
		{
pred@2133
   440
			if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   441
			{
pred@2133
   442
				InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   443
			}			
ds@1952
   444
		}
ds@1952
   445
	}
ds@1952
   446
}
ds@1952
   447
ds@1952
   448
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   449
{
ds@1952
   450
	if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
ds@1952
   451
	{
ds@1952
   452
		return;
ds@1952
   453
	}
ds@1952
   454
	
pred@2133
   455
	if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
ds@1952
   456
	{
ds@1952
   457
		return;
ds@1952
   458
	}
ds@1952
   459
ds@1952
   460
	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
ds@1952
   461
	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
ds@1952
   462
	{
pred@2133
   463
		InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   464
	}
ds@1952
   465
}
ds@1952
   466
ds@1952
   467
public Action:Command_Mapvote(client, args)
ds@1952
   468
{
pred@2133
   469
	InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   470
ds@1952
   471
	return Plugin_Handled;	
ds@1952
   472
}
ds@1952
   473
pred@2133
   474
InitiateVote(MapChange:when, Handle:inputlist)
ds@1952
   475
{
pred@2133
   476
	if (!CanVoteStart())
ds@1952
   477
	{
ds@1952
   478
		return;
ds@1952
   479
	}
ds@1952
   480
	
pred@2133
   481
	g_WaitingForVote = true;
pred@2133
   482
	
ds@1952
   483
	if (IsVoteInProgress())
ds@1952
   484
	{
ds@1952
   485
		// Can't start a vote, try again in 5 seconds.
pred@2178
   486
		g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   487
		return;
pred@2133
   488
	}
ds@1952
   489
	
pred@2133
   490
	g_ChangeTime = when;
pred@2133
   491
	
pred@2133
   492
	g_WaitingForVote = false;
pred@2133
   493
		
ds@1952
   494
	g_HasVoteStarted = true;
ds@1952
   495
	g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
ds@1952
   496
	SetMenuTitle(g_VoteMenu, "Vote Nextmap");
pred@2133
   497
	SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
pred@2133
   498
	
pred@2133
   499
	/**
pred@2133
   500
	 * TODO: Make a proper decision on when to clear the nominations list.
pred@2133
   501
	 * Currently it clears when used, and stays if an external list is provided.
pred@2133
   502
	 * Is this the right thing to do? External lists will probably come from places
pred@2133
   503
	 * like sm_mapvote from the adminmenu in the future.
pred@2133
   504
	 */
pred@2133
   505
	 
ds@1952
   506
	decl String:map[32];
pred@2133
   507
	
pred@2133
   508
	/* No input given - User our internal nominations and maplist */
pred@2133
   509
	if (inputlist == INVALID_HANDLE)
ds@1952
   510
	{
pred@2133
   511
		new nominateCount = GetArraySize(g_NominateList);
pred@2133
   512
		new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
pred@2133
   513
		
pred@2133
   514
		/* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
pred@2133
   515
		new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
pred@2133
   516
		
pred@2133
   517
		
pred@2133
   518
		for (new i=0; i<nominationsToAdd; i++)
pred@2133
   519
		{
pred@2133
   520
			GetArrayString(g_NominateList, i, map, sizeof(map));
pred@2133
   521
			AddMenuItem(g_VoteMenu, map, map);
pred@2133
   522
			
pred@2133
   523
			/* Notify Nominations that this map is now free */
pred@2133
   524
			Call_StartForward(g_NominationsResetForward);
pred@2133
   525
			Call_PushString(map);
pred@2133
   526
			Call_PushCell(GetArrayCell(g_NominateOwners, i));
pred@2133
   527
			Call_Finish();
pred@2133
   528
		}
pred@2133
   529
		
pred@2133
   530
		/* Clear out the rest of the nominations array */
pred@2133
   531
		for (new i=nominationsToAdd; i<nominateCount; i++)
pred@2133
   532
		{
pred@2133
   533
			GetArrayString(g_NominateList, i, map, sizeof(map));
pred@2133
   534
			
pred@2133
   535
			/* Notify Nominations that this map is now free */
pred@2133
   536
			Call_StartForward(g_NominationsResetForward);
pred@2133
   537
			Call_PushString(map);
pred@2133
   538
			Call_PushCell(GetArrayCell(g_NominateOwners, i));
pred@2133
   539
			Call_Finish();			
pred@2133
   540
		}
pred@2133
   541
		
pred@2133
   542
		/* There should currently be 'nominationsToAdd' unique maps in the vote */
pred@2133
   543
		
pred@2133
   544
		new i = nominationsToAdd;
pred@2133
   545
		new count = 0;
pred@2133
   546
		new availableMaps = GetArraySize(g_NextMapList);
pred@2133
   547
		
pred@2133
   548
		while (i < voteSize)
pred@2133
   549
		{
pred@2133
   550
			GetArrayString(g_NextMapList, count, map, sizeof(map));
pred@2133
   551
			count++;
pred@2133
   552
			
pred@2133
   553
			//Check if this map is in the nominate list (and thus already in the vote) */
pred@2133
   554
			if (FindStringInArray(g_NominateList, map) == -1)
pred@2133
   555
			{
pred@2133
   556
				/* Insert the map and increment our count */
pred@2133
   557
				AddMenuItem(g_VoteMenu, map, map);
pred@2133
   558
				i++;
pred@2133
   559
			}
pred@2133
   560
			
pred@2133
   561
			if (count >= availableMaps)
pred@2133
   562
			{
pred@2133
   563
				//Run out of maps, this will have to do.
pred@2133
   564
				break;	
pred@2133
   565
			}
pred@2133
   566
		}
pred@2133
   567
		
pred@2133
   568
		/* Wipe out our nominations list - Nominations have already been informed of this */
pred@2133
   569
		ClearArray(g_NominateOwners);
pred@2133
   570
		ClearArray(g_NominateList);
ds@1952
   571
	}
pred@2133
   572
	else //We were given a list of maps to start the vote with
pred@2133
   573
	{
pred@2133
   574
		new size = GetArraySize(inputlist);
pred@2133
   575
		
pred@2133
   576
		for (new i=0; i<size; i++)
pred@2133
   577
		{
pred@2133
   578
			GetArrayString(inputlist, i, map, sizeof(map));
pred@2133
   579
			
pred@2133
   580
			if (IsMapValid(map))
pred@2133
   581
			{
pred@2133
   582
				AddMenuItem(g_VoteMenu, map, map);
pred@2133
   583
			}	
pred@2133
   584
		}
pred@2133
   585
	}
pred@2133
   586
	
pred@2133
   587
	/* Do we add any special items? */
pred@2133
   588
	if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
pred@2133
   589
	{
pred@2133
   590
		AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
pred@2133
   591
	}
pred@2133
   592
	else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
ds@1952
   593
	{
ds@1952
   594
		AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
ds@1952
   595
	}
pred@2133
   596
	
pred@2133
   597
	new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
ds@1952
   598
ds@1952
   599
	SetMenuExitButton(g_VoteMenu, false);
pred@2133
   600
	VoteMenuToAll(g_VoteMenu, voteDuration);
ds@1952
   601
ds@1952
   602
	LogMessage("Voting for next map has started.");
ds@1952
   603
	PrintToChatAll("[SM] %t", "Nextmap Voting Started");
ds@1952
   604
}
ds@1952
   605
pred@2133
   606
public Handler_MapVoteFinished(Handle:menu,
pred@2133
   607
						   num_votes, 
pred@2133
   608
						   num_clients,
pred@2133
   609
						   const client_info[][2], 
pred@2133
   610
						   num_items,
pred@2133
   611
						   const item_info[][2])
pred@2133
   612
{
pred@2133
   613
	if (num_votes == 0)
pred@2133
   614
	{
pred@2133
   615
		LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
pred@2133
   616
		return;	
pred@2133
   617
	}
pred@2133
   618
	
pred@2133
   619
	decl String:map[32];
pred@2133
   620
	GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
pred@2133
   621
pred@2133
   622
	if (strcmp(map, VOTE_EXTEND, false) == 0)
pred@2133
   623
	{
pred@2133
   624
		g_Extends++;
pred@2133
   625
		
pred@2133
   626
		new time;
pred@2133
   627
		if (GetMapTimeLimit(time))
pred@2133
   628
		{
pred@2133
   629
			if (time > 0)
pred@2133
   630
			{
pred@2133
   631
				ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);						
pred@2133
   632
			}
pred@2133
   633
		}
pred@2133
   634
		
pred@2133
   635
		if (g_Cvar_Winlimit != INVALID_HANDLE)
pred@2133
   636
		{
pred@2133
   637
			new winlimit = GetConVarInt(g_Cvar_Winlimit);
pred@2133
   638
			if (winlimit)
pred@2133
   639
			{
pred@2133
   640
				SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
pred@2133
   641
			}					
pred@2133
   642
		}
pred@2133
   643
		
pred@2133
   644
		if (g_Cvar_Maxrounds != INVALID_HANDLE)
pred@2133
   645
		{
pred@2133
   646
			new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
pred@2133
   647
			if (maxrounds)
pred@2133
   648
			{
pred@2133
   649
				SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
pred@2133
   650
			}
pred@2133
   651
		}
pred@2133
   652
		
pred@2133
   653
		if (g_Cvar_Fraglimit != INVALID_HANDLE)
pred@2133
   654
		{
pred@2133
   655
			new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
pred@2133
   656
			if (fraglimit)
pred@2133
   657
			{
pred@2133
   658
				SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));						
pred@2133
   659
			}
pred@2133
   660
		}
pred@2133
   661
pred@2133
   662
		PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   663
		LogMessage("Voting for next map has finished. The current map has been extended.");
pred@2133
   664
		
pred@2133
   665
		// We extended, so we'll have to vote again.
pred@2133
   666
		g_HasVoteStarted = false;
pred@2133
   667
		CreateNextVote();
pred@2133
   668
		SetupTimeleftTimer();
pred@2133
   669
		
pred@2133
   670
	}
pred@2133
   671
	else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
pred@2133
   672
	{
pred@2133
   673
		PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   674
		LogMessage("Voting for next map has finished. 'No Change' was the winner");
pred@2133
   675
		
pred@2133
   676
		g_HasVoteStarted = false;
pred@2133
   677
		CreateNextVote();
pred@2133
   678
		SetupTimeleftTimer();
pred@2133
   679
	}
pred@2133
   680
	else
pred@2133
   681
	{
pred@2133
   682
		if (g_ChangeTime == MapChange_MapEnd)
pred@2133
   683
		{
pred@2133
   684
			SetNextMap(map);
pred@2133
   685
		}
pred@2133
   686
		else if (g_ChangeTime == MapChange_Instant)
pred@2133
   687
		{
pred@2133
   688
			new Handle:data;
pred@2133
   689
			CreateDataTimer(2.0, Timer_ChangeMap, data);
pred@2133
   690
			WritePackString(data, map);
pred@2133
   691
		}
pred@2133
   692
		else // MapChange_RoundEnd
pred@2133
   693
		{
pred@2133
   694
			SetNextMap(map);
pred@2133
   695
			g_ChangeMapAtRoundEnd = true;
pred@2133
   696
		}
pred@2133
   697
		
pred@2133
   698
		g_HasVoteStarted = false;
pred@2133
   699
		g_MapVoteCompleted = true;
pred@2133
   700
		
pred@2133
   701
		PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   702
		LogMessage("Voting for next map has finished. Nextmap: %s.", map);
pred@2133
   703
	}	
pred@2133
   704
}
pred@2133
   705
ds@1952
   706
public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   707
{
ds@1952
   708
	switch (action)
ds@1952
   709
	{
ds@1952
   710
		case MenuAction_End:
ds@1952
   711
		{
ds@1952
   712
			g_VoteMenu = INVALID_HANDLE;
ds@1952
   713
			CloseHandle(menu);
ds@1952
   714
		}
ds@1952
   715
		
ds@1952
   716
		case MenuAction_Display:
ds@1952
   717
		{
ds@1952
   718
	 		decl String:buffer[255];
ds@1952
   719
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
ds@1952
   720
ds@1952
   721
			new Handle:panel = Handle:param2;
ds@1952
   722
			SetPanelTitle(panel, buffer);
ds@1952
   723
		}		
ds@1952
   724
		
ds@1952
   725
		case MenuAction_DisplayItem:
ds@1952
   726
		{
ds@1952
   727
			if (GetMenuItemCount(menu) - 1 == param2)
ds@1952
   728
			{
ds@1952
   729
				decl String:map[64], String:buffer[255];
ds@1952
   730
				GetMenuItem(menu, param2, map, sizeof(map));
ds@1952
   731
				if (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   732
				{
ds@1952
   733
					Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
ds@1952
   734
					return RedrawMenuItem(buffer);
ds@1952
   735
				}
pred@2133
   736
				else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
pred@2133
   737
				{
pred@2133
   738
					Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
pred@2133
   739
					return RedrawMenuItem(buffer);					
pred@2133
   740
				}
ds@1952
   741
			}
ds@1952
   742
		}		
pred@2133
   743
	
ds@1952
   744
		case MenuAction_VoteCancel:
ds@1952
   745
		{
ds@1952
   746
			// If we receive 0 votes, pick at random.
ds@1952
   747
			if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
ds@1952
   748
			{
ds@1952
   749
				new count = GetMenuItemCount(menu);
ds@1952
   750
				new item = GetRandomInt(0, count - 1);
ds@1952
   751
				decl String:map[32];
ds@1952
   752
				GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   753
				
ds@1952
   754
				while (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   755
				{
ds@1952
   756
					item = GetRandomInt(0, count - 1);
ds@1952
   757
					GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   758
				}
ds@1952
   759
				
ds@1952
   760
				SetNextMap(map);			
ds@1952
   761
			}
ds@1952
   762
			else
ds@1952
   763
			{
pred@2185
   764
				// We were actually cancelled. I guess we do nothing.
ds@1952
   765
			}
pred@2239
   766
			
pred@2239
   767
			g_HasVoteStarted = false;
pred@2239
   768
			g_MapVoteCompleted = true;
ds@1952
   769
		}
ds@1952
   770
	}
ds@1952
   771
	
ds@1952
   772
	return 0;
ds@1952
   773
}
ds@1952
   774
pred@2133
   775
public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
ds@1952
   776
{
pred@2133
   777
	new String:map[65];
pred@2133
   778
	
pred@2133
   779
	if (dp == INVALID_HANDLE)
ds@1952
   780
	{
pred@2133
   781
		if (!GetNextMap(map, sizeof(map)))
pred@2133
   782
		{
pred@2133
   783
			//No passed map and no set nextmap. fail!
pred@2133
   784
			return Plugin_Stop;	
pred@2133
   785
		}
ds@1952
   786
	}
pred@2133
   787
	else
pred@2133
   788
	{
pred@2133
   789
		ResetPack(dp);
pred@2133
   790
		ReadPackString(dp, map, sizeof(map));		
pred@2133
   791
	}
pred@2133
   792
	
pred@2203
   793
	ForceChangeLevel(map, "Map Vote");
pred@2133
   794
	
pred@2133
   795
	return Plugin_Stop;
ds@1952
   796
}
ds@1952
   797
ds@1952
   798
CreateNextVote()
ds@1952
   799
{
ds@1952
   800
	if(g_NextMapList != INVALID_HANDLE)
ds@1952
   801
	{
ds@1952
   802
		ClearArray(g_NextMapList);
ds@1952
   803
	}
ds@1952
   804
	
ds@1952
   805
	decl String:map[32];
ds@1952
   806
	new index, Handle:tempMaps  = CloneArray(g_MapList);
ds@1952
   807
	
ds@1952
   808
	GetCurrentMap(map, sizeof(map));
ds@1952
   809
	index = FindStringInArray(tempMaps, map);
ds@1952
   810
	if (index != -1)
ds@1952
   811
	{
ds@1952
   812
		RemoveFromArray(tempMaps, index);
ds@1952
   813
	}	
ds@1952
   814
	
ds@1952
   815
	if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
ds@1952
   816
	{
ds@1952
   817
		for (new i = 0; i < GetArraySize(g_OldMapList); i++)
ds@1952
   818
		{
ds@1952
   819
			GetArrayString(g_OldMapList, i, map, sizeof(map));
ds@1952
   820
			index = FindStringInArray(tempMaps, map);
ds@1952
   821
			if (index != -1)
ds@1952
   822
			{
ds@1952
   823
				RemoveFromArray(tempMaps, index);
ds@1952
   824
			}
ds@1952
   825
		}	
ds@1952
   826
	}
ds@1952
   827
ds@1952
   828
	new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
ds@1952
   829
	for (new i = 0; i < limit; i++)
ds@1952
   830
	{
ds@1952
   831
		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
ds@1952
   832
		GetArrayString(tempMaps, b, map, sizeof(map));		
ds@1952
   833
		PushArrayString(g_NextMapList, map);
ds@1952
   834
		RemoveFromArray(tempMaps, b);
ds@1952
   835
	}
ds@1952
   836
	
ds@1952
   837
	CloseHandle(tempMaps);
pred@2133
   838
}
pred@2133
   839
pred@2133
   840
bool:CanVoteStart()
pred@2133
   841
{
pred@2133
   842
	if (g_WaitingForVote || g_HasVoteStarted)
pred@2133
   843
	{
pred@2133
   844
		return false;	
pred@2133
   845
	}
pred@2133
   846
	
pred@2133
   847
	return true;
pred@2133
   848
}
pred@2133
   849
pred@2133
   850
NominateResult:InternalNominateMap(String:map[], bool:force, owner)
pred@2133
   851
{
pred@2133
   852
	if (!IsMapValid(map))
pred@2133
   853
	{
pred@2133
   854
		return Nominate_InvalidMap;
pred@2133
   855
	}
pred@2133
   856
	
pred@2133
   857
	new index;
pred@2133
   858
pred@2133
   859
	if ((index = FindValueInArray(g_NominateOwners, owner)) != -1)
pred@2133
   860
	{
pred@2133
   861
		new String:oldmap[33];
pred@2133
   862
		GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
pred@2133
   863
		Call_StartForward(g_NominationsResetForward);
pred@2133
   864
		Call_PushString(oldmap);
pred@2133
   865
		Call_PushCell(owner);
pred@2133
   866
		Call_Finish();
pred@2133
   867
		
pred@2133
   868
		
pred@2133
   869
		SetArrayString(g_NominateList, index, map);
pred@2133
   870
		return Nominate_Replaced;
pred@2133
   871
	}
pred@2133
   872
	
pred@2133
   873
	/* Too many nominated maps. */
pred@2133
   874
	if (g_NominateCount >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
pred@2133
   875
	{
pred@2133
   876
		return Nominate_VoteFull;
pred@2133
   877
	}
pred@2133
   878
	
pred@2133
   879
	/* Map already in the vote */
pred@2133
   880
	if (FindStringInArray(g_NominateList, map) != -1)
pred@2133
   881
	{
pred@2133
   882
		return Nominate_AlreadyInVote;	
pred@2133
   883
	}
pred@2133
   884
	
pred@2133
   885
	
pred@2133
   886
	PushArrayString(g_NominateList, map);
pred@2133
   887
	PushArrayCell(g_NominateOwners, owner);
pred@2133
   888
	g_NominateCount++;
pred@2133
   889
	
pred@2133
   890
	while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
pred@2133
   891
	{
pred@2133
   892
		new String:oldmap[33];
pred@2133
   893
		GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
pred@2133
   894
		Call_StartForward(g_NominationsResetForward);
pred@2133
   895
		Call_PushString(oldmap);
pred@2133
   896
		Call_PushCell(GetArrayCell(g_NominateOwners, 0));
pred@2133
   897
		Call_Finish();
pred@2133
   898
		
pred@2133
   899
		RemoveFromArray(g_NominateList, 0);
pred@2133
   900
		RemoveFromArray(g_NominateOwners, 0);
pred@2133
   901
	}
pred@2133
   902
	
pred@2133
   903
	return Nominate_Added;
pred@2133
   904
}
pred@2133
   905
pred@2133
   906
/* Add natives to allow nominate and initiate vote to be call */
pred@2133
   907
pred@2133
   908
/* native  bool:NominateMap(const String:map[], bool:force, &NominateError:error); */
pred@2133
   909
public Native_NominateMap(Handle:plugin, numParams)
pred@2133
   910
{
pred@2133
   911
	new len;
pred@2133
   912
	GetNativeStringLength(1, len);
pred@2133
   913
	
pred@2133
   914
	if (len <= 0)
pred@2133
   915
	{
pred@2133
   916
	  return false;
pred@2133
   917
	}
pred@2133
   918
	
pred@2133
   919
	new String:map[len+1];
pred@2133
   920
	GetNativeString(1, map, len+1);
pred@2133
   921
	
pred@2133
   922
	return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3));
pred@2133
   923
}
pred@2133
   924
pred@2133
   925
/* native InitiateMapChooserVote(); */
pred@2133
   926
public Native_InitiateVote(Handle:plugin, numParams)
pred@2133
   927
{
pred@2133
   928
	new MapChange:when = MapChange:GetNativeCell(1);
pred@2133
   929
	new Handle:inputarray = Handle:GetNativeCell(2);
pred@2133
   930
	
pred@2133
   931
	LogMessage("Starting map vote because outside request");
pred@2133
   932
	InitiateVote(when, inputarray);
pred@2133
   933
}
pred@2133
   934
pred@2133
   935
public Native_CanVoteStart(Handle:plugin, numParams)
pred@2133
   936
{
pred@2133
   937
	return CanVoteStart();	
pred@2133
   938
}
pred@2133
   939
pred@2133
   940
public Native_CheckVoteDone(Handle:plugin, numParams)
pred@2133
   941
{
pred@2133
   942
	return g_MapVoteCompleted;
pred@2133
   943
}
pred@2133
   944
pred@2223
   945
public Native_EndOfMapVoteEnabled(Handle:plugin, numParams)
pred@2223
   946
{
pred@2223
   947
	return GetConVarBool(g_Cvar_EndOfMapVote);
pred@2223
   948
}
pred@2223
   949
pred@2133
   950
public Native_GetExcludeMapList(Handle:plugin, numParams)
pred@2133
   951
{
pred@2133
   952
	new Handle:array = Handle:GetNativeCell(1);
pred@2133
   953
	
pred@2133
   954
	if (array == INVALID_HANDLE)
pred@2133
   955
	{
pred@2133
   956
		return;	
pred@2133
   957
	}
pred@2133
   958
	
pred@2133
   959
	
pred@2133
   960
	new size = GetArraySize(g_OldMapList);
pred@2133
   961
	decl String:map[33];
pred@2133
   962
	
pred@2133
   963
	for (new i=0; i<size; i++)
pred@2133
   964
	{
pred@2133
   965
		GetArrayString(g_OldMapList, i, map, sizeof(map));
pred@2133
   966
		PushArrayString(array, map);	
pred@2133
   967
	}
pred@2133
   968
	
pred@2133
   969
	return;
ds@1952
   970
}