2008-07-01 03:18:52 +02:00
/ * *
* vim : set ts = 4 :
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* SourceMod Rock The Vote Plugin
* Creates a map vote when the required number of players have requested one .
*
2014-12-17 17:53:02 +01:00
* SourceMod ( C ) 2004 - 2014 AlliedModders LLC . All rights reserved .
2008-07-01 03:18:52 +02:00
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License , version 3.0 , as published by the
* Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License along with
* this program . If not , see < http : //www.gnu.org/licenses/>.
*
* As a special exception , AlliedModders LLC gives you permission to link the
* code of this program ( as well as its derivative works ) to " Half-Life 2, " the
* " Source Engine, " the " SourcePawn JIT, " and any Game MODs that run on software
* by the Valve Corporation . You must obey the GNU General Public License in
* all respects for all other code used . Additionally , AlliedModders LLC grants
* this exception to all derivative works . AlliedModders LLC defines further
* exceptions , found in LICENSE . txt ( as of this writing , version JULY - 31 - 2007 ) ,
* or < http : //www.sourcemod.net/license.php>.
*
* Version : $ Id $
* /
# include <sourcemod>
# include <mapchooser>
# pragma semicolon 1
2014-07-05 23:00:52 +02:00
# pragma newdecls required
2008-07-01 03:18:52 +02:00
2014-07-05 23:00:52 +02:00
public Plugin myinfo =
2008-07-01 03:18:52 +02:00
{
name = " Map Nominations " ,
author = " AlliedModders LLC " ,
description = " Provides Map Nominations " ,
version = SOURCEMOD_VERSION ,
url = " http://www.sourcemod.net/ "
} ;
2014-11-10 01:11:36 +01:00
ConVar g_Cvar_ExcludeOld ;
ConVar g_Cvar_ExcludeCurrent ;
2008-07-01 03:18:52 +02:00
2014-07-05 23:00:52 +02:00
Menu g_MapMenu = null ;
2014-12-16 20:16:06 +01:00
ArrayList g_MapList = null ;
2014-07-05 23:00:52 +02:00
int g_mapFileSerial = - 1 ;
2008-07-01 03:18:52 +02:00
2008-10-09 03:24:30 +02:00
# define MAPSTATUS_ENABLED (1<<0)
# define MAPSTATUS_DISABLED (1<<1)
# define MAPSTATUS_EXCLUDE_CURRENT (1<<2)
# define MAPSTATUS_EXCLUDE_PREVIOUS (1<<3)
# define MAPSTATUS_EXCLUDE_NOMINATED (1<<4)
2014-07-05 23:00:52 +02:00
StringMap g_mapTrie = null ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
public void OnPluginStart ( )
2008-07-01 03:18:52 +02:00
{
LoadTranslations ( " common.phrases " ) ;
LoadTranslations ( " nominations.phrases " ) ;
2014-12-16 20:16:06 +01:00
int arraySize = ByteCountToCells ( PLATFORM_MAX_PATH ) ;
g_MapList = new ArrayList ( arraySize ) ;
2008-07-01 03:18:52 +02:00
g_Cvar_ExcludeOld = CreateConVar ( " sm_nominate_excludeold " , " 1 " , " Specifies if the current map should be excluded from the Nominations list " , 0 , true , 0.00 , true , 1.0 ) ;
g_Cvar_ExcludeCurrent = CreateConVar ( " sm_nominate_excludecurrent " , " 1 " , " Specifies if the MapChooser excluded maps should also be excluded from Nominations " , 0 , true , 0.00 , true , 1.0 ) ;
RegConsoleCmd ( " sm_nominate " , Command_Nominate ) ;
RegAdminCmd ( " sm_nominate_addmap " , Command_Addmap , ADMFLAG_CHANGEMAP , " sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote. " ) ;
2008-10-09 03:24:30 +02:00
2014-12-01 03:57:38 +01:00
g_mapTrie = new StringMap ( ) ;
2008-07-01 03:18:52 +02:00
}
2014-07-05 23:00:52 +02:00
public void OnConfigsExecuted ( )
2008-07-01 03:18:52 +02:00
{
if ( ReadMapList ( g_MapList ,
g_mapFileSerial ,
" nominations " ,
MAPLIST_FLAG_CLEARARRAY | MAPLIST_FLAG_MAPSFOLDER )
2014-11-16 01:30:45 +01:00
= = null )
2008-07-01 03:18:52 +02:00
{
if ( g_mapFileSerial = = - 1 )
{
SetFailState ( " Unable to create a valid map list. " ) ;
}
}
BuildMapMenu ( ) ;
}
2014-07-07 08:59:15 +02:00
public void OnNominationRemoved ( const char [ ] map , int owner )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
int status ;
2008-10-09 03:24:30 +02:00
/* Is the map in our list? */
2014-07-05 23:00:52 +02:00
if ( ! g_mapTrie . GetValue ( map , status ) )
2008-10-09 03:24:30 +02:00
{
return ;
}
/* Was the map disabled due to being nominated */
if ( ( status & MAPSTATUS_EXCLUDE_NOMINATED ) ! = MAPSTATUS_EXCLUDE_NOMINATED )
{
return ;
}
2014-07-05 23:00:52 +02:00
g_mapTrie . SetValue ( map , MAPSTATUS_ENABLED ) ;
2008-07-01 03:18:52 +02:00
}
2014-07-05 23:00:52 +02:00
public Action Command_Addmap ( int client , int args )
2008-07-01 03:18:52 +02:00
{
if ( args < 1 )
{
ReplyToCommand ( client , " [SM] Usage: sm_nominate_addmap <mapname> " ) ;
return Plugin_Handled ;
}
2014-12-16 20:16:06 +01:00
char mapname [ PLATFORM_MAX_PATH ] ;
2008-07-01 03:18:52 +02:00
GetCmdArg ( 1 , mapname , sizeof ( mapname ) ) ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
int status ;
if ( ! g_mapTrie . GetValue ( mapname , status ) )
2008-07-01 03:18:52 +02:00
{
ReplyToCommand ( client , " %t " , " Map was not found " , mapname ) ;
2008-10-09 03:24:30 +02:00
return Plugin_Handled ;
2008-07-01 03:18:52 +02:00
}
2014-07-05 23:00:52 +02:00
NominateResult result = NominateMap ( mapname , true , 0 ) ;
2008-07-01 03:18:52 +02:00
if ( result > Nominate_Replaced )
{
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it can't be full */
ReplyToCommand ( client , " %t " , " Map Already In Vote " , mapname ) ;
return Plugin_Handled ;
}
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
g_mapTrie . SetValue ( mapname , MAPSTATUS_DISABLED | MAPSTATUS_EXCLUDE_NOMINATED ) ;
2008-10-09 03:24:30 +02:00
2008-07-01 03:18:52 +02:00
ReplyToCommand ( client , " %t " , " Map Inserted " , mapname ) ;
LogAction ( client , - 1 , " \" %L \" inserted map \" %s \" . " , client , mapname ) ;
return Plugin_Handled ;
}
2014-07-05 23:00:52 +02:00
public void OnClientSayCommand_Post ( int client , const char [ ] command , const char [ ] sArgs )
2008-07-01 03:18:52 +02:00
{
if ( ! client )
{
2014-03-25 16:57:00 +01:00
return ;
2008-07-01 03:18:52 +02:00
}
2014-03-25 16:57:00 +01:00
if ( strcmp ( sArgs , " nominate " , false ) = = 0 )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
ReplySource old = SetCmdReplySource ( SM_REPLY_TO_CHAT ) ;
2014-03-25 16:57:00 +01:00
2008-07-01 03:18:52 +02:00
AttemptNominate ( client ) ;
2014-03-25 16:57:00 +01:00
SetCmdReplySource ( old ) ;
2008-07-01 03:18:52 +02:00
}
}
2014-07-05 23:00:52 +02:00
public Action Command_Nominate ( int client , int args )
2008-07-01 03:18:52 +02:00
{
if ( ! client )
{
2011-01-17 02:00:44 +01:00
return Plugin_Handled ;
2008-07-01 03:18:52 +02:00
}
if ( args = = 0 )
{
AttemptNominate ( client ) ;
2011-01-17 02:00:44 +01:00
return Plugin_Handled ;
2008-07-01 03:18:52 +02:00
}
2014-12-16 20:16:06 +01:00
char mapname [ PLATFORM_MAX_PATH ] ;
2008-07-01 03:18:52 +02:00
GetCmdArg ( 1 , mapname , sizeof ( mapname ) ) ;
2014-07-05 23:00:52 +02:00
int status ;
if ( ! g_mapTrie . GetValue ( mapname , status ) )
2008-10-09 02:24:44 +02:00
{
2008-10-09 03:24:30 +02:00
ReplyToCommand ( client , " %t " , " Map was not found " , mapname ) ;
return Plugin_Handled ;
}
2008-10-08 09:58:25 +02:00
2008-10-09 03:24:30 +02:00
if ( ( status & MAPSTATUS_DISABLED ) = = MAPSTATUS_DISABLED )
{
if ( ( status & MAPSTATUS_EXCLUDE_CURRENT ) = = MAPSTATUS_EXCLUDE_CURRENT )
{
ReplyToCommand ( client , " [SM] %t " , " Can't Nominate Current Map " ) ;
}
if ( ( status & MAPSTATUS_EXCLUDE_PREVIOUS ) = = MAPSTATUS_EXCLUDE_PREVIOUS )
{
ReplyToCommand ( client , " [SM] %t " , " Map in Exclude List " ) ;
}
if ( ( status & MAPSTATUS_EXCLUDE_NOMINATED ) = = MAPSTATUS_EXCLUDE_NOMINATED )
{
ReplyToCommand ( client , " [SM] %t " , " Map Already Nominated " ) ;
}
return Plugin_Handled ;
}
2008-10-09 02:24:44 +02:00
2014-07-05 23:00:52 +02:00
NominateResult result = NominateMap ( mapname , false , client ) ;
2008-10-09 02:24:44 +02:00
2008-10-09 03:24:30 +02:00
if ( result > Nominate_Replaced )
{
if ( result = = Nominate_AlreadyInVote )
{
ReplyToCommand ( client , " %t " , " Map Already In Vote " , mapname ) ;
}
else
{
ReplyToCommand ( client , " [SM] %t " , " Map Already Nominated " ) ;
}
return Plugin_Handled ;
2008-10-09 02:33:47 +02:00
}
2008-10-09 02:24:44 +02:00
2008-10-09 03:24:30 +02:00
/* Map was nominated! - Disable the menu item and update the trie */
2014-07-05 23:00:52 +02:00
g_mapTrie . SetValue ( mapname , MAPSTATUS_DISABLED | MAPSTATUS_EXCLUDE_NOMINATED ) ;
2008-10-09 03:24:30 +02:00
2015-06-04 04:40:43 +02:00
char name [ MAX_NAME_LENGTH ] ;
2008-10-09 03:24:30 +02:00
GetClientName ( client , name , sizeof ( name ) ) ;
PrintToChatAll ( " [SM] %t " , " Map Nominated " , name , mapname ) ;
return Plugin_Continue ;
2008-07-01 03:18:52 +02:00
}
2014-07-05 23:00:52 +02:00
void AttemptNominate ( int client )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
g_MapMenu . SetTitle ( " %T " , " Nominate Title " , client ) ;
g_MapMenu . Display ( client , MENU_TIME_FOREVER ) ;
2008-07-01 03:18:52 +02:00
return ;
}
2014-07-05 23:00:52 +02:00
void BuildMapMenu ( )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
delete g_MapMenu ;
2008-07-01 03:18:52 +02:00
2014-07-05 23:00:52 +02:00
g_mapTrie . Clear ( ) ;
2008-10-09 03:24:30 +02:00
2014-12-01 03:57:38 +01:00
g_MapMenu = new Menu ( Handler_MapSelectMenu , MENU_ACTIONS_DEFAULT | MenuAction_DrawItem | MenuAction_DisplayItem ) ;
2008-07-01 03:18:52 +02:00
2014-12-16 20:16:06 +01:00
char map [ PLATFORM_MAX_PATH ] ;
2008-07-01 03:18:52 +02:00
2014-07-05 23:00:52 +02:00
ArrayList excludeMaps ;
2014-12-16 20:16:06 +01:00
char currentMap [ PLATFORM_MAX_PATH ] ;
2008-07-01 03:18:52 +02:00
2014-11-10 01:11:36 +01:00
if ( g_Cvar_ExcludeOld . BoolValue )
2008-07-01 03:18:52 +02:00
{
2014-12-16 20:16:06 +01:00
excludeMaps = new ArrayList ( ByteCountToCells ( PLATFORM_MAX_PATH ) ) ;
2008-07-01 03:18:52 +02:00
GetExcludeMapList ( excludeMaps ) ;
}
2014-11-10 01:11:36 +01:00
if ( g_Cvar_ExcludeCurrent . BoolValue )
2008-07-01 03:18:52 +02:00
{
GetCurrentMap ( currentMap , sizeof ( currentMap ) ) ;
}
2008-10-09 03:24:30 +02:00
2014-12-16 20:16:06 +01:00
for ( int i = 0 ; i < g_MapList . Length ; i + + )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
int status = MAPSTATUS_ENABLED ;
2008-10-09 03:24:30 +02:00
2014-12-16 20:16:06 +01:00
g_MapList . GetString ( i , map , sizeof ( map ) ) ;
2008-07-01 03:18:52 +02:00
2014-11-10 01:11:36 +01:00
if ( g_Cvar_ExcludeCurrent . BoolValue )
2008-07-01 03:18:52 +02:00
{
2008-10-09 03:24:30 +02:00
if ( StrEqual ( map , currentMap ) )
2008-07-01 03:18:52 +02:00
{
2008-10-09 03:24:30 +02:00
status = MAPSTATUS_DISABLED | MAPSTATUS_EXCLUDE_CURRENT ;
2008-07-01 03:18:52 +02:00
}
}
2008-10-09 03:24:30 +02:00
/* Dont bother with this check if the current map check passed */
2014-11-10 01:11:36 +01:00
if ( g_Cvar_ExcludeOld . BoolValue & & status = = MAPSTATUS_ENABLED )
2008-07-01 03:18:52 +02:00
{
2014-07-05 23:00:52 +02:00
if ( excludeMaps . FindString ( map ) ! = - 1 )
2008-07-01 03:18:52 +02:00
{
2008-10-09 03:24:30 +02:00
status = MAPSTATUS_DISABLED | MAPSTATUS_EXCLUDE_PREVIOUS ;
2008-07-01 03:18:52 +02:00
}
}
2014-07-05 23:00:52 +02:00
g_MapMenu . AddItem ( map , map ) ;
g_mapTrie . SetValue ( map , status ) ;
2008-07-01 03:18:52 +02:00
}
2014-07-07 08:59:15 +02:00
g_MapMenu . ExitButton = true ;
2009-11-19 00:44:51 +01:00
2014-07-05 23:00:52 +02:00
delete excludeMaps ;
2008-07-01 03:18:52 +02:00
}
2014-07-05 23:00:52 +02:00
public int Handler_MapSelectMenu ( Menu menu , MenuAction action , int param1 , int param2 )
2008-07-01 03:18:52 +02:00
{
switch ( action )
{
case MenuAction_Select :
{
2015-06-04 04:40:43 +02:00
char map [ PLATFORM_MAX_PATH ] , name [ MAX_NAME_LENGTH ] ;
2014-07-05 23:00:52 +02:00
menu . GetItem ( param2 , map , sizeof ( map ) ) ;
2008-07-01 03:18:52 +02:00
2014-12-16 20:16:06 +01:00
GetClientName ( param1 , name , sizeof ( name ) ) ;
2008-07-01 03:18:52 +02:00
2014-07-05 23:00:52 +02:00
NominateResult result = NominateMap ( map , false , param1 ) ;
2008-07-01 03:18:52 +02:00
/* Don't need to check for InvalidMap because the menu did that already */
if ( result = = Nominate_AlreadyInVote )
{
PrintToChat ( param1 , " [SM] %t " , " Map Already Nominated " ) ;
2008-10-09 03:24:30 +02:00
return 0 ;
2008-07-01 03:18:52 +02:00
}
else if ( result = = Nominate_VoteFull )
{
PrintToChat ( param1 , " [SM] %t " , " Max Nominations " ) ;
2008-10-09 03:24:30 +02:00
return 0 ;
2008-07-01 03:18:52 +02:00
}
2008-10-09 02:33:47 +02:00
2014-07-05 23:00:52 +02:00
g_mapTrie . SetValue ( map , MAPSTATUS_DISABLED | MAPSTATUS_EXCLUDE_NOMINATED ) ;
2008-10-09 03:24:30 +02:00
2008-07-01 03:18:52 +02:00
if ( result = = Nominate_Replaced )
{
PrintToChatAll ( " [SM] %t " , " Map Nomination Changed " , name , map ) ;
2008-10-09 03:24:30 +02:00
return 0 ;
2008-07-01 03:18:52 +02:00
}
PrintToChatAll ( " [SM] %t " , " Map Nominated " , name , map ) ;
}
2008-10-09 03:24:30 +02:00
case MenuAction_DrawItem :
{
2014-12-16 20:16:06 +01:00
char map [ PLATFORM_MAX_PATH ] ;
2014-07-05 23:00:52 +02:00
menu . GetItem ( param2 , map , sizeof ( map ) ) ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
int status ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
if ( ! g_mapTrie . GetValue ( map , status ) )
2008-10-09 03:24:30 +02:00
{
LogError ( " Menu selection of item not in trie. Major logic problem somewhere. " ) ;
return ITEMDRAW_DEFAULT ;
}
if ( ( status & MAPSTATUS_DISABLED ) = = MAPSTATUS_DISABLED )
{
return ITEMDRAW_DISABLED ;
}
return ITEMDRAW_DEFAULT ;
}
case MenuAction_DisplayItem :
{
2014-12-16 20:16:06 +01:00
char map [ PLATFORM_MAX_PATH ] ;
2014-07-05 23:00:52 +02:00
menu . GetItem ( param2 , map , sizeof ( map ) ) ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
int status ;
2008-10-09 03:24:30 +02:00
2014-07-05 23:00:52 +02:00
if ( ! g_mapTrie . GetValue ( map , status ) )
2008-10-09 03:24:30 +02:00
{
LogError ( " Menu selection of item not in trie. Major logic problem somewhere. " ) ;
return 0 ;
}
2014-12-16 20:16:06 +01:00
char display [ PLATFORM_MAX_PATH + 64 ] ;
2008-10-09 03:24:30 +02:00
if ( ( status & MAPSTATUS_DISABLED ) = = MAPSTATUS_DISABLED )
{
if ( ( status & MAPSTATUS_EXCLUDE_CURRENT ) = = MAPSTATUS_EXCLUDE_CURRENT )
{
Format ( display , sizeof ( display ) , " %s (%T) " , map , " Current Map " , param1 ) ;
return RedrawMenuItem ( display ) ;
}
if ( ( status & MAPSTATUS_EXCLUDE_PREVIOUS ) = = MAPSTATUS_EXCLUDE_PREVIOUS )
{
Format ( display , sizeof ( display ) , " %s (%T) " , map , " Recently Played " , param1 ) ;
return RedrawMenuItem ( display ) ;
}
if ( ( status & MAPSTATUS_EXCLUDE_NOMINATED ) = = MAPSTATUS_EXCLUDE_NOMINATED )
{
Format ( display , sizeof ( display ) , " %s (%T) " , map , " Nominated " , param1 ) ;
return RedrawMenuItem ( display ) ;
}
}
return 0 ;
}
2008-07-01 03:18:52 +02:00
}
2008-10-09 03:24:30 +02:00
return 0 ;
2009-11-19 00:44:51 +01:00
}