added amb1119 - sm_revote command
authorDavid Anderson <dvander@alliedmods.net>
Sat May 17 05:12:52 2008 +0000 (2008-05-17)
changeset 2056f1fcde46ac7c
parent 2055 e94e6fcd3f0e
child 2057 653c280c07dc
added amb1119 - sm_revote command
core/MenuManager.cpp
core/MenuManager.h
core/MenuVoting.cpp
core/MenuVoting.h
core/smn_menus.cpp
plugins/include/menus.inc
public/IMenuManager.h
translations/common.phrases.txt
     1.1 --- a/core/MenuManager.cpp	Sat May 17 05:10:36 2008 +0000
     1.2 +++ b/core/MenuManager.cpp	Sat May 17 05:12:52 2008 +0000
     1.3 @@ -790,3 +790,13 @@
     1.4  {
     1.5  	return s_VoteHandler.GetRemainingVoteDelay();
     1.6  }
     1.7 +
     1.8 +bool MenuManager::IsClientInVotePool(int client)
     1.9 +{
    1.10 +	return s_VoteHandler.IsClientInVotePool(client);
    1.11 +}
    1.12 +
    1.13 +bool MenuManager::RedrawClientVoteMenu(int client)
    1.14 +{
    1.15 +	return s_VoteHandler.RedrawToClient(client);
    1.16 +}
     2.1 --- a/core/MenuManager.h	Sat May 17 05:10:36 2008 +0000
     2.2 +++ b/core/MenuManager.h	Sat May 17 05:12:52 2008 +0000
     2.3 @@ -89,6 +89,8 @@
     2.4  	bool IsVoteInProgress();
     2.5  	void CancelVoting();
     2.6  	unsigned int GetRemainingVoteDelay();
     2.7 +	bool IsClientInVotePool(int client);
     2.8 +	bool RedrawClientVoteMenu(int client);
     2.9  public: //IHandleTypeDispatch
    2.10  	void OnHandleDestroy(HandleType_t type, void *object);
    2.11  	bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
     3.1 --- a/core/MenuVoting.cpp	Sat May 17 05:10:36 2008 +0000
     3.2 +++ b/core/MenuVoting.cpp	Sat May 17 05:12:52 2008 +0000
     3.3 @@ -113,14 +113,19 @@
     3.4  		return;
     3.5  	}
     3.6  
     3.7 -	/* Wipe out their vote if they had one */
     3.8 +	/* Wipe out their vote if they had one.  We have to make sure the the the
     3.9 +	 * newly connected client is not allowed to vote. 
    3.10 +	 */
    3.11  	int item;
    3.12 -	if ((item = m_ClientVotes[client]) >= 0)
    3.13 +	if ((item = m_ClientVotes[client]) >= -1)
    3.14  	{
    3.15 -		assert((unsigned)item < m_Items);
    3.16 -		assert(m_Votes[item] > 0);
    3.17 -		m_Votes[item]--;
    3.18 -		m_ClientVotes[client] = -1;
    3.19 +		if (item >= 0)
    3.20 +		{
    3.21 +			assert((unsigned)item < m_Items);
    3.22 +			assert(m_Votes[item] > 0);
    3.23 +			m_Votes[item]--;
    3.24 +		}
    3.25 +		m_ClientVotes[client] = -2;
    3.26  	}
    3.27  }
    3.28  
    3.29 @@ -129,18 +134,28 @@
    3.30  	return (m_pCurMenu != NULL);
    3.31  }
    3.32  
    3.33 -bool VoteMenuHandler::StartVote(IBaseMenu *menu, unsigned int num_clients, int clients[], unsigned int max_time, unsigned int flags/* =0 */)
    3.34 +bool VoteMenuHandler::StartVote(IBaseMenu *menu,
    3.35 +								unsigned int num_clients,
    3.36 +								int clients[],
    3.37 +								unsigned int max_time,
    3.38 +								unsigned int flags/* =0 */)
    3.39  {
    3.40  	if (!InitializeVoting(menu, menu->GetHandler(), max_time, flags))
    3.41  	{
    3.42  		return false;
    3.43  	}
    3.44  
    3.45 +	/* Note: we can use game time and not universal time because 
    3.46 +	 * if we're voting then players are in-game.
    3.47 +	 */
    3.48 +
    3.49  	float fVoteDelay = sm_vote_delay.GetFloat();
    3.50  	if (fVoteDelay < 1.0)
    3.51  	{
    3.52  		g_next_vote = 0.0;
    3.53 -	} else {
    3.54 +	}
    3.55 +	else
    3.56 +	{
    3.57  		/* This little trick breaks for infinite votes!
    3.58  		 * However, we just ignore that since those 1) shouldn't exist and 
    3.59  		 * 2) people must be checking IsVoteInProgress() beforehand anyway.
    3.60 @@ -148,8 +163,15 @@
    3.61  		g_next_vote = gpGlobals->curtime + fVoteDelay + (float)max_time;
    3.62  	}
    3.63  
    3.64 +	m_fStartTime = gpGlobals->curtime;
    3.65 +	m_nMenuTime = max_time;
    3.66 +
    3.67  	for (unsigned int i=0; i<num_clients; i++)
    3.68  	{
    3.69 +		if (clients[i] < 1 || clients[i] > 256)
    3.70 +		{
    3.71 +			continue;
    3.72 +		}
    3.73  		menu->Display(clients[i], max_time, this);
    3.74  	}
    3.75  
    3.76 @@ -158,6 +180,58 @@
    3.77  	return true;
    3.78  }
    3.79  
    3.80 +bool VoteMenuHandler::IsClientInVotePool(int client)
    3.81 +{
    3.82 +	if (client < 1 
    3.83 +		|| client > g_Players.MaxClients() 
    3.84 +		|| m_pCurMenu == NULL)
    3.85 +	{
    3.86 +		return false;
    3.87 +	}
    3.88 +
    3.89 +	return (m_ClientVotes[client] > -2);
    3.90 +}
    3.91 +
    3.92 +bool VoteMenuHandler::GetClientVoteChoice(int client, unsigned int *pItem)
    3.93 +{
    3.94 +	if (!IsClientInVotePool(client)
    3.95 +		|| m_ClientVotes[client] == -1)
    3.96 +	{
    3.97 +		return false;
    3.98 +	}
    3.99 +
   3.100 +	*pItem = m_ClientVotes[client];
   3.101 +
   3.102 +	return true;
   3.103 +}
   3.104 +
   3.105 +bool VoteMenuHandler::RedrawToClient(int client)
   3.106 +{
   3.107 +	unsigned int time_limit;
   3.108 +
   3.109 +	if (!IsClientInVotePool(client))
   3.110 +	{
   3.111 +		return false;
   3.112 +	}
   3.113 +
   3.114 +	if (m_nMenuTime == MENU_TIME_FOREVER)
   3.115 +	{
   3.116 +		time_limit = m_nMenuTime;
   3.117 +	}
   3.118 +	else
   3.119 +	{
   3.120 +		time_limit = (int)((float)m_nMenuTime - (gpGlobals->curtime - m_fStartTime));
   3.121 +		
   3.122 +		/* Make sure this doesn't round to zero */
   3.123 +		if (time_limit == MENU_TIME_FOREVER)
   3.124 +		{
   3.125 +			time_limit = 1;
   3.126 +		}
   3.127 +	}
   3.128 +
   3.129 +	return m_pCurMenu->Display(client, time_limit, this);
   3.130 +}
   3.131 +
   3.132  bool VoteMenuHandler::InitializeVoting(IBaseMenu *menu, 
   3.133  									   IMenuHandler *handler,
   3.134  									   unsigned int time,
   3.135 @@ -187,7 +261,9 @@
   3.136  			m_Votes[i] = 0;
   3.137  		}
   3.138  		m_Votes.resize(m_Items, 0);
   3.139 -	} else {
   3.140 +	}
   3.141 +	else
   3.142 +	{
   3.143  		for (unsigned int i=0; i<m_Items; i++)
   3.144  		{
   3.145  			m_Votes[i] = 0;
   3.146 @@ -252,7 +328,9 @@
   3.147  	if (fVoteDelay < 1.0)
   3.148  	{
   3.149  		g_next_vote = 0.0;
   3.150 -	} else {
   3.151 +	}
   3.152 +	else
   3.153 +	{
   3.154  		g_next_vote = gpGlobals->curtime + fVoteDelay;
   3.155  	}
   3.156  
     4.1 --- a/core/MenuVoting.h	Sat May 17 05:10:36 2008 +0000
     4.2 +++ b/core/MenuVoting.h	Sat May 17 05:12:52 2008 +0000
     4.3 @@ -72,6 +72,9 @@
     4.4  	IBaseMenu *GetCurrentMenu();
     4.5  	bool IsCancelling();
     4.6  	unsigned int GetRemainingVoteDelay();
     4.7 +	bool IsClientInVotePool(int client);
     4.8 +	bool GetClientVoteChoice(int client, unsigned int *pItem);
     4.9 +	bool RedrawToClient(int client);
    4.10  private:
    4.11  	void Reset(IMenuHandler *mh);
    4.12  	void DecrementPlayerCount();
    4.13 @@ -93,6 +96,8 @@
    4.14  	unsigned int m_NumVotes;
    4.15  	unsigned int m_VoteTime;
    4.16  	unsigned int m_VoteFlags;
    4.17 +	float m_fStartTime;
    4.18 +	unsigned int m_nMenuTime;
    4.19  	int m_ClientVotes[256+1];
    4.20  };
    4.21  
     5.1 --- a/core/smn_menus.cpp	Sat May 17 05:10:36 2008 +0000
     5.2 +++ b/core/smn_menus.cpp	Sat May 17 05:12:52 2008 +0000
     5.3 @@ -1405,6 +1405,49 @@
     5.4  	return *s_CurSelectPosition;
     5.5  }
     5.6  
     5.7 +static cell_t IsClientInVotePool(IPluginContext *pContext, const cell_t *params)
     5.8 +{
     5.9 +	int client;
    5.10 +	IGamePlayer *pPlayer;
    5.11 +
    5.12 +	client = params[1];
    5.13 +	if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
    5.14 +	{
    5.15 +		return pContext->ThrowNativeError("Invalid client index %d", client);
    5.16 +	}
    5.17 +
    5.18 +	if (!g_Menus.IsVoteInProgress())
    5.19 +	{
    5.20 +		return pContext->ThrowNativeError("No vote is in progress");
    5.21 +	}
    5.22 +
    5.23 +	return g_Menus.IsClientInVotePool(client) ? 1 : 0;
    5.24 +}
    5.25 +
    5.26 +static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *params)
    5.27 +{
    5.28 +	int client;
    5.29 +	IGamePlayer *pPlayer;
    5.30 +
    5.31 +	client = params[1];
    5.32 +	if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
    5.33 +	{
    5.34 +		return pContext->ThrowNativeError("Invalid client index %d", client);
    5.35 +	}
    5.36 +
    5.37 +	if (!g_Menus.IsVoteInProgress())
    5.38 +	{
    5.39 +		return pContext->ThrowNativeError("No vote is in progress");
    5.40 +	}
    5.41 +
    5.42 +	if (!g_Menus.IsClientInVotePool(client))
    5.43 +	{
    5.44 +		return pContext->ThrowNativeError("Client is not in the voting pool");
    5.45 +	}
    5.46 +
    5.47 +	return g_Menus.RedrawClientVoteMenu(client) ? 1 : 0;
    5.48 +}
    5.49 +
    5.50  class EmptyMenuHandler : public IMenuHandler
    5.51  {
    5.52  public:
    5.53 @@ -1505,7 +1548,9 @@
    5.54  	{"GetPanelStyle",			GetPanelStyle},
    5.55  	{"InsertMenuItem",			InsertMenuItem},
    5.56  	{"InternalShowMenu",		InternalShowMenu},
    5.57 +	{"IsClientInVotePool",		IsClientInVotePool},
    5.58  	{"IsVoteInProgress",		IsVoteInProgress},
    5.59 +	{"RedrawClientVoteMenu",	RedrawClientVoteMenu},
    5.60  	{"RedrawMenuItem",			RedrawMenuItem},
    5.61  	{"RemoveAllMenuItems",		RemoveAllMenuItems},
    5.62  	{"RemoveMenuItem",			RemoveMenuItem},
     6.1 --- a/plugins/include/menus.inc	Sat May 17 05:10:36 2008 +0000
     6.2 +++ b/plugins/include/menus.inc	Sat May 17 05:12:52 2008 +0000
     6.3 @@ -541,6 +541,28 @@
     6.4  native CheckVoteDelay();
     6.5  
     6.6  /**
     6.7 + * Returns whether a client is in the pool of clients allowed 
     6.8 + * to participate in the current vote.  This is determined by 
     6.9 + * the client list passed to StartVote().
    6.10 + *
    6.11 + * @param client			Client index.
    6.12 + * @return					True if client is allowed to vote, false otherwise.
    6.13 + * @error					If no vote is in progress or client index is invalid.
    6.14 + */
    6.15 +native bool:IsClientInVotePool(client);
    6.16 +
    6.17 +/**
    6.18 + * Redraws the current vote menu to a client in the voting pool.
    6.19 + *
    6.20 + * @param client			Client index.
    6.21 + * @return					True on success, false if the client is in the vote pool 
    6.22 + *							but cannot vote again.
    6.23 + * @error					No vote in progress, client is not in the voting pool, 
    6.24 + *							or client index is invalid.
    6.25 + */
    6.26 +native bool:RedrawClientVoteMenu(client);
    6.27 +
    6.28 +/**
    6.29   * Returns a style's global Handle.
    6.30   *
    6.31   * @param style			Menu Style.
     7.1 --- a/public/IMenuManager.h	Sat May 17 05:10:36 2008 +0000
     7.2 +++ b/public/IMenuManager.h	Sat May 17 05:12:52 2008 +0000
     7.3 @@ -36,7 +36,7 @@
     7.4  #include <IHandleSys.h>
     7.5  
     7.6  #define SMINTERFACE_MENUMANAGER_NAME		"IMenuManager"
     7.7 -#define SMINTERFACE_MENUMANAGER_VERSION		14
     7.8 +#define SMINTERFACE_MENUMANAGER_VERSION		15
     7.9  
    7.10  /**
    7.11   * @file IMenuManager.h
    7.12 @@ -897,6 +897,23 @@
    7.13  		 * @return				Number of seconds to wait.
    7.14  		 */
    7.15  		virtual unsigned int GetRemainingVoteDelay() =0;
    7.16 +
    7.17 +		/**
    7.18 +		 * @brief Returns whether a client is in the "allowed to vote" pool determined 
    7.19 +		 * by the initial call to StartVote().
    7.20 +		 *
    7.21 +		 * @param client		Client index.
    7.22 +		 * @return				True if client is allowed to vote, false on failure.
    7.23 +		 */
    7.24 +		virtual bool IsClientInVotePool(int client) =0;
    7.25 +
    7.26 +		/**
    7.27 +		 * @brief Redraws the current vote menu to a client in the voting pool.
    7.28 +		 *
    7.29 +		 * @param client		Client index.
    7.30 +		 * @return				True on success, false if client is not allowed to vote.
    7.31 +		 */
    7.32 +		virtual bool RedrawClientVoteMenu(int client) =0;
    7.33  	};
    7.34  }
    7.35  
     8.1 --- a/translations/common.phrases.txt	Sat May 17 05:10:36 2008 +0000
     8.2 +++ b/translations/common.phrases.txt	Sat May 17 05:12:52 2008 +0000
     8.3 @@ -222,32 +222,14 @@
     8.4  		"en"			"The given player is not fully in-game yet."
     8.5  	}
     8.6  	
     8.7 -	/* :UNUSED: */
     8.8 -	"Played Sound"
     8.9 +	"Cannot participate in vote"
    8.10  	{
    8.11 -		"#format"		"{1:s}"
    8.12 -		"en"			"Played sound on player '{1}'"
    8.13 +		"en"			"You cannot participate in this vote."
    8.14  	}
    8.15  	
    8.16 -	/* :UNUSED: */
    8.17 -	"Slapped player"
    8.18 -	{
    8.19 -		"#format"		"{1:s}"
    8.20 -		"en"			"Slapped player '{1}'"
    8.21 -	}
    8.22 -	
    8.23 -	/* :UNUSED: */
    8.24 -	"Slayed player"
    8.25 +	"Cannot change vote"
    8.26  	{
    8.27 -		"#format"		"{1:s}"
    8.28 -		"en"			"Slayed player '{1}'"
    8.29 -	}
    8.30 -	
    8.31 -	/* :UNUSED: */
    8.32 -	"Kicked player"
    8.33 -	{
    8.34 -		"#format"		"{1:s}"
    8.35 -		"en"			"Kicked player '{1}'"
    8.36 +		"en"			"You cannot change your selection for this vote."
    8.37  	}
    8.38  	"On"
    8.39  	{